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
src
folder inside your project. - Select
New
>Class
. - Enter
HelloWorld
as the name of the class. - Check the box for
public static void main(String[] args)
to create amain
method. - Click
Finish
.
- Right-click on the
-
Write the “Hello World” Code
- Inside the
HelloWorld
class, 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
main
method. - 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 Project
orFile
>New
>Project
. - Select
Java
on 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
src
folder inside your project. - Select
New
>Java Class
. - Enter
HelloWorld
as the name of the class and clickOK
.
- Right-click on the
-
Write the “Hello World” Code
- Inside the
HelloWorld
class, 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
main
method. - 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