1.2 Creating Your First Application

This lesson provides detailed instructions for compiling and running a simple "Hello World!" application.

Your first application will simply display the greeting "Hello world!". To create this program, you will:

  • Create a source file
  • Compile the source file
  • Run the program

The following instructions are for users of Windows 7/8.

Create a source file

Start Notepad. In a new document, type in the following code. When you type the program in, case matters. That means that you must type the uppercase and lowercase characters exactly as they appear in the program.

Create a folder in C: drive with name java (or the name of the folder you wish to create). We’ll save our file in this folder. Save this file FirstProgram.java.

Compile the source file

i. Open Start > Accessories > Command Prompt

ii. Type cd \java

iii. Type javac FirstProgram.java

Run

Now, type java FirstProgram and press enter

Congratulations! Your program works! It displays Hello World! on screen.

 

Behind the Scene of Executing Java Application


When you entered >javac FirstProgram.java

This command run the java compiler and the compiler translated the file to byte code. Byte code of FirstProgram.java then stored in a file with the .class extension, so the byte code stored in FirstProgram.class

To run the program that is stored in the FirstProgram.class file, you entered the following command:
>java FirstProgram

This command runs the Java interpreter (the JVM) and executes the program.

jvm