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
Hello World with VS Code
- Install the Extension Pack for Java from Microsoft.
- Open a folder and create
HelloWorld.java. - Click Run above the
mainmethod or press F5. - Output appears in the integrated terminal.
VS Code auto-detects the JDK from JAVA_HOME or prompts you to install one.
Hello World from the Command Line
Without an IDE:
mkdir hello && cd hello
echo 'public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}' > HelloWorld.java
javac HelloWorld.java
java HelloWorld
Single-File Source-Code Programs (Java 11+)
Run without explicit compilation:
java HelloWorld.java
Useful for scripts and learning; production projects still use javac and build tools.
Troubleshooting
| Error | Cause | Solution |
|---|---|---|
cannot find symbol |
Typo or missing import | Check spelling and imports |
class HelloWorld is public, should be in file HelloWorld.java |
Filename mismatch | Rename the file |
java.lang.UnsupportedClassVersionError |
JDK too old | Upgrade JDK or recompile |
Exercise
Create the same Hello World program in all three environments: command line, VS Code, and one full IDE (Eclipse or IntelliJ). Compare the workflow and note which steps differ.