First Java Program ( Hello World Program )

Writing Your First Java Program ( Java Hello World Program )

We break the process of programming in Java into three steps:

  • Create the program by typing it into a text editor program and save it to a file named, say,
  • Compile it by typing “javac” in the command prompt.
  • Run (or execute) it by typing “java HelloWorld” in the command prompt.

The first step creates the program; the second translates it into a intermediate binary code (called bytecode) and puts the result in a file named HelloWorld.class; the third step actually runs or executes the program.

Creating a Java program.

Copy the following code into your text editor and save it into a file named


Compiling a Java program.

To compile type the text below in command prompt. (Here % symbol is used to denote the command prompt, but it may appear different depending on your system.)

Executing a Java program.

After compiling your java program, you can run it.To run the HelloWorld program, type the following in the command prompt:

If all goes well, you should see the following response