PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Java · Theory

Java Hello World Program

← All stacks

Theory

5/270

Java Hello World Program

Hello World is the smallest Java program. We don’t write it to impress anyone. We write it to check that JDK works. If this prints, javac and java are installed, PATH is fine, and you can learn the next topic. Every bigger Java app — bank, college portal, Android old style — still starts from this same shape: a class, a main method, and some work inside.

All Java code sits inside a class. Write public class Main { ... }. If the class is public, the file name must be Main.java — same word, same spelling, same capital M. Main vs main.java is a different file to the compiler. That one mismatch gives a long error. Check the name before you panic.

The JVM starts here: public static void main(String[] args). Say each word. public — JVM (and others) can see it. static — JVM can call it without new Main(). void — main returns nothing. String[] args — extra words after java Main, like a file name. You don’t need args on day one, but you must write that signature exactly.

Let’s do it on the board. Inside main, write System.out.println("Hello Java");. println prints the text and then goes to the next line. print (no ln) stays on the same line. Compile: javac Main.java. Run: java Main. Output should be exactly Hello Java. If nothing prints, you may have used print with no newline and missed it, or main was not found.

Run flow, slowly: write Main.java → javac Main.java → Main.class appears → java Main → Hello Java. javac is compile. java is run. You never double-click the .class like an .exe. The JVM runs it. Same .class can run on another OS if JVM is there.

After it works, change the string to your name and run again. That tiny change is the first real program. Don’t copy Hello World twenty times without changing anything — that teaches nothing.

Diagram
write Main.java
         │
         ▼
    javac Main.java
         │
         ▼
     Main.class
         │
         ▼
      java Main
         │
         ▼
     Hello Java
Exam tip

Explain each word: public static void main(String[] args).

Example

public class Main {
  public static void main(String[] args) {
    System.out.println("GoCareerGo");
  }
}

Java Hello World Program — output: GoCareerGo. File must be Main.java because the public class is Main.

Short notes

  • DefHello World is the smallest Java program. It checks that JDK works.
  • Rulepublic class Main must be saved as Main.java.
  • RememberJVM starts at public static void main(String[] args).
  • Flowjavac Main.java → java Main → Hello Java.
  • TrapWrong file name / wrong spelling of Main gives a scary error.

Questions

1

What is the starting method in Java?

2

Why is main static?

3

What does void mean in main?

4

What is String[] args?

5

How do you compile and run?

Previous← Difference between C++ and JavaNextProgram Internal →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.