Site icon TestingDocs.com

Hello World Java Program

Introduction

This post shows you how to create the first java example program “Hello World”. After this post, you will be able to create a Java project and a Java class that will print “Hello world!” in the console when run. So, let’s get started!

Create a New Java project

We need a create a java project. In the main menu, click on the File -> New -> Java Project button as shown in the below figure:

 

 

Enter Project name

Enter the project name for the project name in the dialog box, then click Finish. Give a meaningful name to identify the project. However, you may choose any name of your choice.

Create a New Package

It’s encouraged to specify the package for your class. To create a new package

File -> New -> Package

Packages are folders that hold java classes for better organizing and to avoid naming conflicts. You cannot have the same class more than once in the same package. However, you can have the same class name in a different package.

Create a New Java class

This step is to create a new class. In the main menu, click on the New Java Class button. Enter “HelloWorld” for the class name, then click Finish.

Code the Java Program

Enter the below Java code snippet in the IDE editor for the class :

public class HelloWorld {

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

    }

}

 

Then save your changes File -> Save or by the combination of keys Ctrl + S

Run the Hello World Java application

We can run the java application in many ways. The easiest way is to right-click and run the application as shown below:

 

Program Output

Check the run output of the program in the console window as shown below. To enable the console window in the Eclipse IDE, go to the main toolbar Windows –> Show View –> Console.

That’s it! we have successfully created a Hello World Java application and run it successfully.

Next Step: Understand Java Program Structure

https://www.testingdocs.com/java-program-structure/

Java Tutorials

Java Tutorial on this website:

https://www.testingdocs.com/java-tutorial/

For more information on Java, visit the official website :

https://www.oracle.com/java/

Exit mobile version