Hello world

Java language Hello world program

Java language Hello world program

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.

Java language hello world

Explanation of this program

Save the file using the same class name with extension .java

Open the command prompt and select write path to your program file (drive F: folder loop1)
then compile the program
javac Hello_world.java
Then  run the program
java Hello_world

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”);
}

}


Display hello world program in different ways in java.

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

  1. Open a notepad in text editor.
  2. Declare a class in java with pair of curly brackets({}).
  3. Declare a main method inside the class definition.
  4. Declare a user defined method named hello() inside the class definition.
  5. Write a output statement inside the hello() method definition.
  6. Finally, call the method inside the main method in Java.

Program 2

This is a program that  is using constructor for hello world program.

 

Java language Hello world program

Output

Hello world

Explanation for program 2

 

Java language Hello world program

You can do it

  1. Open a notepad in texteditor.
  2. Declare a class in java with a pair of curly brackets({})
  3. Declare a constructor named hello_1() (same name of class) inside the class definition.
  4. Declare a main method inside the class definition.
  5. Write an output statement inside the hello_1() constructor definition.
  6. Finally create an object inside the main method(when we create object, constructor called automatically )

Program 3

This is a program that is using user defined methods to create objects.

 

Java language Hello world program

Output

Hello world

Explanation for program 3

Java language Hello world program
You can do it
  1. Open a notepad in  texteditor
  2. Declare a class in java with pair of curly brackets({}).
  3. Declare a method named hello() inside the class definition.
  4. Declare a main method inside the class definition.
  5. Write an output statement inside the hello() method definition.
  6. Then create an object inside the main method.
  7. Finally call the method hello() inside the main method.


Related post

Hello world in C                                       Java download and install windows 

Hello worls in C++

Hello world in Python

Karmehavannan

Recent Posts

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

11 months ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

11 months ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

11 months ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

11 months ago

Function/method to convert Celsius into Fahrenheit -Entered by user

Function/method to convert Celsius into Fahrenheit -Entered by user In this article, we will discuss…

11 months ago

Temperature conversion: Celsius into Fahrenheit using function or method

Temperature conversion: Celsius into Fahrenheit using a function or method In this article, we will…

11 months ago

This website uses cookies.