☰
For executing any java program, you need to
Let us look at a simple java program.
class HelloWorld
{
public static void main(String[] args)
{
System.out.println ("Welcome to Hello World program");
}
}
Your first application, HelloWorld, will simply display the greeting " Welcome to Hello World program". To create this program, you will:
A source file contains code, written in the Java programming language, that you and other programmers can understand. The easiest way to write a simple program is with a text editor. So, using the text editor of your choice, create a text file with the following text, and be sure to name the text file HelloWorld.java. Java programs are case sensitive, so if you type the code in yourself, pay particular attention to the capitalization.

A program has to be converted to a form the Java VM can understand so any computer with a Java VM can interpret and run the program. Compiling a Java program means taking the programmer-readable text in your program file (also called source code) and converting it to bytecodes, which are platform-independent instructions for the JVM.
The Java programming language compiler (javac) takes your source file and translates its text into instructions that the Java virtual machine can understand. The instructions contained within this file are known as bytecodes.
The Java compiler is invoked at the command line on Unix and DOS shell operating systems as follows:
javac HelloWorld.java
Once your program successfully compiles into Java bytecodes, you can interpret and run applications on any Java VM, or interpret and run applets in any Web browser with built in JVM.Interpreting and running a Java program means invoking the Java VM byte code interpreter, which converts the Java byte codes to platform-dependent machine codes so your computer can understand and run the program.
The Java application launcher tool (java) uses the Java virtual machine to run your application.
And then when you try to run the byte code(.class file), the following steps are performed at runtime:
The Java interpreter is invoked at the command line on Unix and DOS shell operating systems as follows:
java HelloWorld
At the command line, you should see:
Welcome to Hello World program
Step 1: Open a text editor and write the code as above.
Step 2: Save the file as HelloWorld.java
Step 3: Open command prompt and go to the directory where you saved your first java program.
Step 4: Type 'javac HelloWorld.java' and press Return to compile your code. This command will call the Java
Compiler asking it to compile the specified file. If there are no errors in the code the command prompt will take you to the next line. It will also create a new file called HelloWorld.class .
Step 5: Now type 'java HelloWorld' on command prompt to run your program.
Step 6: You will be able to see Welcome to Hello World program printed on your command prompt.