First Java Program

A Java program is a set of instruction in text format which is written according to the rules of the Java programming language. These instructions are known as source code. The file that contains these instructions is called source file and has the file extension .java.

Hello Java Example

Let's write Java first program.

class FirstProgram
{
	public static void main(String args[])
	{
		System.out.println("Hello! This is Java first program.");
	}
}

Compiling a Java program

In Java, the compiler compiles the code into bytecode, which is not executable code. Bytecode is somewhere in the middle of source code and executable code. For example, to create the bytecode files from the source file FirstProgram, you run the Java compiler by issuing the following command-

javac FirstProgram.java

The compiler converts the text instructions into bytecode form and places them in files with the .class extension- FirstProgram.class

Executing a Java program

The bytecode in the class files is interpreted by the JVM when you run the program. You can execute a Java program by using the java command. To execute the program in the running example, write the following command-

java FirstProgram

It generates the following output-

Hello! This is Java first program.