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.
write Main.java
│
▼
javac Main.java
│
▼
Main.class
│
▼
java Main
│
▼
Hello JavaExplain each word: public static void main(String[] args).