No announcement
 

First Java Program

Let’s write our first program using Java language. 

Once Eclipse is launched, create a new project by clicking on File > New > Project

New Project

Select Java Project and click Next

New Project Type

Enter project name as FirstProgram and click Finish

Project Name

In the create New module window, click Create

New Module

Now, create a new package by right clicking on src > New > Package 

New Package

Enter package name as: com.codingnous.tutorial and click on Finish

Package Name

Create a new class by right clicking on the package com.codingnous.tutorial then New > Class

New Class

Enter class name as HelloWorld and click on Finish

New Class Name

Type in the code in class HelloWorld

HelloWorld Code

Run the code by clicking on Run button

Run Code
HelloWorld.java

package com.codingnous.tutorial;

public class HelloWorld {

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

}

Output
Hello World

In the above program, the first line is the name of the package, used for categorizing the code. After package declaration we generally have imports. Since this program is very basic, we do not have any imports here.

The third line is the class declaration. Fifth line declares the main method. Main method is the entry point of Java program, i.e., the main method is executed first by the compiler on its own. Sixth line is the print statement. This statement will print a message “Hello World” on the console using the System standard output stream followed by closing curly brackets for main method and class.