Java Basics
beginnerWhat You'll Learn
Theory
Java is a high-level, object-oriented programming language created by James Gosling at Sun Microsystems in 1995. Its core philosophy is "Write Once, Run Anywhere" (WORA) — compiled Java bytecode runs on any platform with a Java Virtual Machine.
The JVM and Platform Independence
Java source code (.java) is compiled by javac into bytecode (.class files). The JVM interprets this bytecode into machine code for the specific platform. This abstraction layer is what enables cross-platform compatibility.
Source (.java) → javac → Bytecode (.class) → JVM → Machine Code
Key Concepts
- JVM — Executes bytecode; available for Windows, macOS, Linux, etc.
- JRE — JVM + core libraries; needed to run Java programs
- JDK — JRE + development tools (compiler, debugger); needed to develop Java programs
- Garbage Collection — Automatic memory management; objects no longer referenced are reclaimed
- Strongly Typed — Every variable must have a declared type
Basic Program Structure
Every Java application needs a class definition with a main method as the entry point.
Why this matters
Java's "Write Once, Run Anywhere" philosophy makes it one of the most widely used enterprise languages. Understanding the JVM, garbage collection, and platform independence is essential for building cross-platform applications.
What's next
In the next lessons, you'll dive deeper into each topic with hands-on examples and exercises.
Exercises
Personal Details Program
Write a Java program that declares variables for your name, age, and favorite hobby. Print them using System.out.println with appropriate messages.
Expected Output:
Name: Alice\nAge: 25\nHobby: Painting