Definition
📌 Introduction
Java was released by Sun Microsystems in 1995 with the promise "write once, run anywhere." Java code compiles to bytecode, which runs on the Java Virtual Machine (JVM) — so the same compiled program runs unchanged on Windows, macOS, or Linux.Java is widely used for Android apps, enterprise backend systems, and large-scale software where reliability matters..
Syntax
syntax
public class ClassName {
public static void main(String[] args) {
// your code here
}
}Example
java
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}Output
outputHello, World!
Important Points
- Java files must be named exactly after their public class, e.g.
Main.javaforpublic class Main. - Java is object-oriented — everything lives inside a class.
System.out.println()prints text followed by a new line.- Java runs on the JVM, which is why the same .class file works across operating systems.
Common Mistakes
- Naming the file differently from the public class name.
- Forgetting that
mainmust be exactlypublic static void main(String[] args). - Missing a semicolon at the end of a statement.
Interview Tip
🎯 Before your interview
"What does JVM stand for and why does it matter?" — Java Virtual Machine; it's what makes Java bytecode portable across operating systems.
