First Java Program - Hello World Example
First Java Program - Hello World Example
First Java Program - Hello World Example
1. Software Requirements
2. Creating Hello Java Example
3. Resolving javac is not recognized
In this page, we will learn how to write the simple program of java. We can write a simple
hello java program easily after installing the JDK.
To create a simple java program, you need to create a class that contains the main method.
Let's understand the requirement first.
1. class Simple{
2. public static void main(String args[]){
3. System.out.println("Hello Java");
4. }
5. }
Test it Now
Compilation Flow:
When we compile Java program using javac tool, java compiler converts the source code
into byte code.
To write the simple program, you need to open notepad by start menu -> All Programs
-> Accessories -> notepad and write a simple program as displayed below:
As displayed in the above diagram, write the simple program of java in notepad and saved it as Simple.j
run this program, you need to open the command prompt by start menu -> All Programs -> Accesso
prompt.
To compile and run the above program, go to your current directory first; my current directory is c:\new
To compile: javac Simple.java
To execute: java Simple
1. static public void main(String args[])
2) The subscript notation in Java array can be used after type, before the variable
or after the variable.
1. public static void main(String[] args)
2. public static void main(String []args)
3. public static void main(String args[])
3) You can provide var-args support to the main method by passing 3 ellipses
(dots)
Let's see the simple code of using var-args in the main method. We will learn about var-
args later in Java New Features chapter.
1. public static void main(String... args)
1. class A{
2. static public void main(String... args){
3. System.out.println("hello java4");
4. }
5. };