Java – Basic Program

Prev     Next

Three things need to be done to make a java program work. They are,

1. Create,
2. Compile, and
3. Run

  • A source file is to be created with .java extension.
  • The source file is then compiled by the java compiler which yields a class file with .class extension
  • This class file is run by the JVM and yields the result.
  • A class file, if it is created in one platform can run and give the same result in another platform, for example, a class file generated in a windows environment can run and give the same result in linux environment. That is why, java is platform independent.

Java Hello World Example Program:


C:\> javac
C:\> java HelloWorld
Hello World

1. Creating a source file:

Type the above program in a notepad and save the file with the name that should match exactly the class name and with .java extension. That is

2. Compiling the source file:

Open command prompt and go to the directory where is located and type the command


The program will be compiled by javac compiler and HelloWorld.class file is created and ready to be executed.

3. Run the program:

Then, type the command.

java HelloWorld

This command will execute the class file and displays the output ‘Hello World’ .

Prev     Next

Share this website !!!
Facebook Twitter Linkedin

1. Online Compilers - Compile & Run your C/C++ programs:

✅ Online Compilers

2. Ask your questions or clarify your/others doubts from,

✅ Online Discussion Forums by

We Support JALLIKATTU !!!
Show Your Support as well. Thanks!