Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

Java language Hello world program

Posted on November 16, 2017September 18, 2019

Table of Contents

  • Java language Hello world program
    • Display hello world program in different ways in java.

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
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
Java language Hello world program

Output

Hello world

Explanation for program 2
 

 

Java language Hello world program
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
Java language Hello world program

Output

Hello world

Explanation for program 3

Java language Hello world program
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

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes