Table of Contents
In this tutorial, we will discuss the Java language Hello world program
Hello world is usually the first easy to understand program used to introduce programming language for beginners.
Firstly, we will understand how to write hello world program and then how to compile and run the program with no error.
To successfully compile and run the program, we want text editor (Notepad) or IDE and also make sure java is installed properly.
Open the Notepad Text editor
Write the program as shown below.
Explanation of this program
Save the file using the same class name with extension .java
Hello world program is successfully compiled and run with the expected output.
Output
Ok, let’s learn the above program
//Hello world program in Java
//Your first java program
Here is an explanation for starting the program using comments(single line comment). Comments are intended for users reading the code to understand the purpose and functionality of this program.
Comments are completely ignored by the java compilers
class Hello_world{
……………………….
……………………….
}
Every java program must begin with class declaration in Java. In the program, class is a keyword in java. Hello_world is the name of the class.
public static void main (String args[])
{
// body of main method with Helo world code
}
This is a java main method with method body.Every java program must contain a main method.
System.out.println(“Hello world”);
The above code displays the string(Hello world )inside double quotation marks on your screen.
This statement is inside the main method in java. The main method is inside the class declaration.
class Hello_world{
public static void main (String args[]){
System.out.println(“Hello world”);
}
}
We can write hello world program in different ways in java.
This is a simple hello world program in java that was created using user defined methods.
Program 1
Output
Hello world
Explanation for program 1
You can do it
Program 2
This is a program that is using constructor for hello world program.
Output
Hello world
You can do it
Program 3
This is a program that is using user defined methods to create objects.
Output
Hello world
Explanation for program 3
Related post
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.