Create Java Hello World Program
This tutorial explains you how to create a simple core Java "Hello World" application. The Hello World application will print the text "Hello World" at the console. This example explains you about all the steps in creating Hello World application.
In this section we will discuss about a simple Java program. A HelloWorld application explains you how to start writing of your first Java class.
Example
First we will create here a Hello World Java program then I will explain the terms what are used in this program. This is a basic example of core Java that explains how to write a Java class.
Source Code
public class HelloWorld
{
public static void main(String args[])
{
System.out.println("Hello World");
}
}
Now let's see the brief description of the terms used in the above program. The important thing is to know about the Java programs is that the Java is a case sensitive programming language i.e. the text "Rose" and "rose" written in Java programs is treated differently. So, always be careful about the case sensitivity when writing the Java program. Generally the Java keywords are written into small characters.
The first line of the above program is written as "public class HelloWorld" and can be explained as below :
In the second line a '{' (opening curly brace) is used to confine the class body.
The third line of the above program is written as "public static void main(String[] args)" and can be explained as below :
The third line of the above program is written as "public static void main(String[] args)" and can be explained as below :
This is called a main method in Java. This is a predefined method in Java and this method must be contained by every application as the signature given above.
The method public static void main(String args[]) can be explained as it can be accessed publicly, it is a static method and it does not return any value, the argument of this method explains that this method takes input as an array of elements of String type. The main() method specified as the signature defined above is the entry point of application and it can invoke another methods also.
In the fourth line a '{' (opening curly brace) is used to confine the body of main() method.
The fifth line of the above program is written as "System.out.println("Hello World"); and can be explained as below :
The method System.out.println("Hello World"); can be explained as it is used for writing the output on the console.
In the sixth line a '}' (closing curly brace) is used to close the body of main() method.
In the seventh line a '}' (closing curly brace) is used to close the class body.
How to save Java program
Before saving this program first open a notepad or any other Java editor to write the above Java code and then save this file as File->Save/Save As then go to your directory where you want to save your java file and named this file as the Class name given into the program with .java extension.
How to execute Java program
Before executing the Java program a program is need to be compiled so first compile your Java program.
Open command prompt and go to your directory where you had stored your Java file then write as follows :
javac class_name.java (e.g. javac HelloWorld.java).
If no any error will be found then it will create a class file now you can execute your Java program as follows :
java class_name (e.g. java HelloWorld)
Output
Now if you compiled and execute the above Java program successfully then the output will be as follows :

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Core Java Hello World Example
Post your Comment