On this page
"Hello World" Java program
Java “Hello World” with Eclipse
-
Open Eclipse
- Launch Eclipse IDE.
-
Create a New Java Project
- Go to
File>New>Java Project. - Enter a project name (e.g.,
HelloWorld) and clickFinish.
- Go to
-
Create a Java Class
- Right-click on the
srcfolder inside your project. - Select
New>Class. - Enter
HelloWorldas the name of the class. - Check the box for
public static void main(String[] args)to create amainmethod. - Click
Finish.
- Right-click on the
-
Write the “Hello World” Code
- Inside the
HelloWorldclass, replace the default code with:
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } } - Inside the
-
Save the File
- Press
Ctrl + S(Cmd + S on macOS) to save the file.
- Press
-
Run the Java Program
- Right-click anywhere inside the
mainmethod. - Select
Run As>Java Application.
- Right-click anywhere inside the
-
View Output
- You should see Hello, World! printed in the Console tab at the bottom of Eclipse.
Java “Hello World” with IntelliJ IDEA
-
Open IntelliJ IDEA
- Launch IntelliJ IDEA IDE.
-
Create a New Project
- Click on
Create New ProjectorFile>New>Project. - Select
Javaon the left pane and clickNext. - Enter a project name (e.g.,
HelloWorld) and clickFinish.
- Click on
-
Create a New Java Class
- Right-click on the
srcfolder inside your project. - Select
New>Java Class. - Enter
HelloWorldas the name of the class and clickOK.
- Right-click on the
-
Write the “Hello World” Code
- Inside the
HelloWorldclass, replace the default code with:
public class HelloWorld { public static void s main(String[] args) { System.out.println("Hello, World!"); } } - Inside the
-
Save the File
- Press Ctrl + S (Cmd + S on macOS) to save the file.
-
Run the Java Program
- Right-click anywhere inside the
mainmethod. - Select
Run 'HelloWorld.main()'.
- Right-click anywhere inside the
-
View Output
- You should see
Hello, World!printed in the Run tab at the bottom of IntelliJ IDEA.
- You should see