Get Started: Java First Program

In This Article, You Will Learn to Write First Java Program.

Java First Program – Before moving ahead, let’s know a bit about Java Installation.

Table of Contents

A Java file must have a class and function name to write or run any code in Java. 

The name of the file and class must be the same.

Java First Program “Hello World”

Example: Write a program that returned “Hello World”.

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

				
			

In the above example, the class name is Main and the function name is main.

The file name of the source code is Main.java. 

Note every file should be saved .java extension to run the file. 

The code System.out.println() is used to print the input in the terminal.

Don’t worry! We will discuss the above code in detail in the next lesson. For now, just know to run the code.

Congratulations! You just wrote your very first program in Java called “Hello World”.

If you find anything incorrect in the above-discussed topic and have further questions, please comment below.

Connect on:

Recent Post

Popular Post

Top Articles

Archives
Categories

Share on