Basic

Hello world in Java programming language

Hello world in Java programming language

In this tutorial, we will discuss the hello world in Java programming language.

What is the hello world program

Hello world

The word Hello world cannot be forgotten by programmers as it is the first program learnt by programmers.

Hello world” program is very easy to learn and understand. This program returns the simple output Hello world and is used to introduce programming languages to beginners.

Before you write a code in hello world program, you must ready your system for code writing, compilation and running.

Following are important to initialize hello world program

  1. Java is installed to your system – we will write hello world program in Java language
  2. You must set a path in your system for Java program – if you don’t set a Java path on your system, you cannot compile using Java compiler.
  3. You must have a text editor with IDE to write a java program – you want a platform that is viable for code writing, compiling, debugging and to get perfect output. E.g. text editor – Note pad, Eclipse, Netbeans etc

If you done with the above criteria, you can write your first program in hello world

To begin with, you can learn to write hello world program and how to compile and run the program without error

 

Java hello world program

public class Hello_world{
public static void main(String args[]){
System.out.println("Hello world");
}
}

When the above code is executed, it produces the following results:

Hello world

 

Explanation of Hello word program

//Hello world program in Java
//your first Java program
class Hello_world{ //class declaration named Hello_world

public static void main(String args[]){//main method in Java
//It is predefined method in Java

System.out.println("Hello world");
//Display statement in Java
//It is ended with semicolon

}//end of main method

}//end of class

 

How to save and run this program:

This program is written on the notepad. After you complete the program, find the save button and click save. Then select the folder to save the program in.

Note – when you save the hello world program, class name and file name should be both the same.

Hello world Java

Open the command prompt and select the proper path to your program(drive F: java folder-Hello_world.java file)

Then compile the program using the javac compiler

javac Hello_world.java

Then run the program

java Hello_world
Compiled and run the program

This program is successfully compiled and run with the expected output

Output

Output

Ok, let’s discuss  every segment of this program

 

//Hello world program in Java

//your first Java program

 

This is just an explanation. Starting the program using comment (Single line comment) leads to easy reading, very simple understanding, ease of understanding of functionality as very well.

Because comments are completely ignored by the java compiler

public class Hello_world{
//Statements..
.............
}

public -you can access this class from any classes

Note – In java, every program must begin inside the class declaration in enclosing curly brackets. In this segment of code, the class is a keyword in Java language. Hello_world is a class name.

public static void main(String args[]){
//body of main method with Hello world code
}

This is the main method in Java with method body inside enclosing braces  (curly brackets). Every Java program must contain the main method.

System.out.println(“Hello world”);

The above statements are used to display any string (“Hello world”) inside double quotation marks for display on your screen. In this program, this statement is inside the main method.

class Hello_world{
public static void main(String args[]){
System.out.println("Hello world");
}
}

Suggested for you

Hello world program in C++

Hello world program in C

Hello world program in Python

Introduction of C programming language
Hello world program in Python programming language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago