What is Java?#
Java is a general-purpose, object-oriented programming language released by Sun Microsystems in 1995 (created by James Gosling's team; Oracle owns it today). It is one of the most widely used languages in the world:
- Enterprise and banking software - most large Indian IT services projects (TCS, Infosys, Wipro...) use Java with Spring Boot.
- Android apps - Android was built around Java (Kotlin is now preferred, but it runs on the same platform).
- Big data tools - Hadoop, Kafka, Spark and Elasticsearch run on the JVM.
- Desktop and server applications, trading systems, and a huge open-source ecosystem.
Key features: object-oriented, platform independent, strongly typed, automatic memory management (garbage collection), multithreading built in, and a very large standard library.
Write once, run anywhere#
C and C++ compile to machine code for one specific CPU and operating system. Java compiles to bytecode - instructions for a virtual computer, the Java Virtual Machine (JVM). Any machine with a JVM (Windows, Linux, macOS, Android) can run the same .class file.
Main.java --javac--> Main.class (bytecode) --java (JVM)--> runs on Windows / Linux / Mac
| Term | What it is |
|---|---|
| JVM (Java Virtual Machine) | runs bytecode; translates it to machine code (using a JIT compiler for speed) |
| JRE (Java Runtime Environment) | JVM + standard libraries - enough to run Java programs |
| JDK (Java Development Kit) | JRE + compiler (javac) + tools - needed to develop Java programs |
Java का code पहले bytecode में compile होता है, किसी खास computer के machine code में नहीं। यह bytecode JVM पर चलता है, और JVM हर operating system के लिए उपलब्ध है। इसलिए एक बार compile किया हुआ program Windows, Linux, Mac - कहीं भी चल जाता है: "Write Once, Run Anywhere"।
Your first Java program#
Hello, Java! 2 + 3 = 5
Press Run - the code is compiled with javac and run on a real JVM.
Line by line#
| Code | Meaning |
|---|---|
public class Main |
Every Java program lives inside a class. public means visible everywhere. |
public static void main(String[] args) |
The entry point. The JVM calls this method first. |
public |
the JVM must be able to call it from outside |
static |
it belongs to the class, so no object needs to be created first |
void |
it returns nothing |
String[] args |
command-line arguments as an array of strings |
System.out.println(...) |
print, then move to a new line |
Java is case-sensitive: System is not system, and main is not Main. Every statement ends with ;, and every { needs a matching }.
print, println and printf#
No new line... now a new line. Tab: after tab Quote: "Java" and backslash: \ Name: Isha, Age: 20, CGPA: 8.76
printf works like C's printf: %s string, %d integer, %.2f decimal with 2 places, %n new line.
Comments#
// single-line comment
/* multi-line
comment */
/**
* Javadoc comment - used to generate API documentation.
*/
Installing Java and running from the terminal#
- Install a JDK - for example Eclipse Temurin (Adoptium) JDK 21 or Oracle JDK 21 (21 is a long-term-support version).
- Use an IDE: IntelliJ IDEA Community (most popular), Eclipse, VS Code with the Java extension pack, or BlueJ for beginners.
- From a terminal:
javac Main.java # compile → Main.class
java Main # run (no .class extension)
java Main.java # Java 11+: compile and run a single file in one step
In the browser editor here, always keep the class with main named Main. In your own projects, the file name must match the public class name.
Summary#
- Java compiles to bytecode that runs on the JVM on any operating system.
- JDK (develop) ⊃ JRE (run) ⊃ JVM (execute).
- Programs start at
public static void main(String[] args)inside a class. printlnadds a new line,printdoes not,printfformats.