In this tutorial you will learn about the First Java Program ( Hello World Program ) and its application with practical example.
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 saving it to a file named, say, HelloWorld.java.
- Compile it by typing “javac HelloWorld.java” 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 an 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 HelloWorld.java.
1 2 3 4 5 |
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); } } |
Compiling a Java program.
To compile HelloWorld.java type the text below in the command prompt. (Here % symbol is used to denote the command prompt, but it may appear different depending on your system.)
1 |
% javac HelloWorld.java |
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:
1 |
% java HelloWorld |
If all goes well, you should see the following response
1 |
Hello, World |