Environment to write code:

By environment, we means the setup where we can write and compile our code. To write code, we need a text editor. To compile our code, we need a compiler which will convert our code to machine understandable code.

We need two things to write and compile our code:

  1. Integrated Development Environment (IDE)
  2. Compiler

Compiler:

Compiler is a program that translates instructions written in a high-level programming language into the equivalent machine code. The main purpose of Java compiler is to translate the source code written in High Level Language like Java into bytecode which is then send to Java Virtual Machine for execution.

Flowchart for Java code Compilation:

The flowchart for compilation of Java coe is given below.flowchart

Integrated Development Environment (IDE):

IDE functions as an editor as well as a compiler. There are different IDEs available like:
  • IntelliJ IDEA
  • Eclipse
  • NetBeans
  • Visual Studio Code
  • Oracle JDeveloper
  • and more.

These are all free and you can use any of these to run your code.

Note: There are many Integrated Development Environments (IDEs) which are available online but they have limited functionality. For better experience, download the IDEs listed above.


Writing first Java Code:

After setting up the environment, you have to create a new project or open an existing one by selecting "File" ->"New Project" or "File" -> "Open" from the IntelliJ IDEA menu (if you have a project already). Choose the appropriate project type and follow the prompts. After setting up the environment, you can write the code.


helloworld.java
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

This code will print "Hello World!" on screen.

Components of Java code:

The key components of Java code are given below:
  1. Package
  2. Import Statements
  3. Class declaration
  4. Methods

We will understand this code in the next chapter.
Your code should be free of errors so that it would be executed without any difficulty.