Java Tutorial

Introduction to Java

Write Once, Run Anywhere: The power of the JVM and bytecode

What is Java?

Java is a high-level, class-based, object-oriented programming language designed to have as few implementation dependencies as possible. Its most famous slogan, "Write Once, Run Anywhere" (WORA), perfectly describes its main benefit: Java code can run on any device that has a Java Virtual Machine (JVM).
java
public class Main {
    public static void main(String[] args) {
        System.out.println("Welcome to the world of Java!");
    }
}

The JVM Architecture

Wait! How does "Run Anywhere" actually work?
  1. Compiler: Your .java source code is compiled into Bytecode (.class files).
  2. Bytecode: This is an intermediate language that is NOT specific to any CPU.
  3. JVM: The Java Virtual Machine reads the bytecode and translates it into the specific machine code of your computer (Windows, Mac, Linux, or Android).

Key Features of Java

  • Object-Oriented: Everything in Java (almost) is an Object. This makes code modular and reusable.
  • Platform Independent: Thanks to the JVM.
  • Automatic Memory Management: Java uses a Garbage Collector to automatically delete objects that are no longer needed. No manual free() or delete!
  • Secure: Java runs in a "sandbox" (the JVM), preventing code from directly accessing system memory or hardware.
  • Multithreaded: Built-in support for running multiple tasks at once.

The Modern Java Ecosystem

  • Enterprise: Most banking and insurance systems are built on Java (Spring Boot).
  • Android: Java was the original language of Android development.
  • Big Data: Hadoop, Spark, and Cassandra are all written in Java.
  • Scientific: used widely in AI and data science before Python took the lead.

Summary

FeatureDescription
CreatorJames Gosling (Sun Microsystems, 1995)
OwnerOracle Corporation
PlatformJVM (Java Virtual Machine)
ParadigmObject-Oriented (Strictly Class-based)
Main ToolJDK (Java Development Kit)
Main BuildMaven, Gradle
Best ForBackend Apps, Android, Enterprise Systems
SafetyStrong static typing and Garbage Collection
HistoryJava started as "Oak" in 1991
VersionsMajor updates every 6 months (LTS versions: 8, 11, 17, 21)
BytecodeThe universal language of the JVM
StandardEstablished and trusted worldwide for 25+ years
LibraryMassive standard library (The Java API)
Open SourceOpenJDK is the free, community-driven version
PortabilityIdentical behavior across all operating systems
Strong TypeVariables must have a declared type at compile-time
Main Methodpublic static void main(String[] args) (The entry point!)
PackageOrganizes code into logical folders (namespaces)
ImportUse import to bring in external tools
InterfaceDefines what a class MUST do (See Interfaces)
JREJava Runtime Environment (Just for running apps)
JDKJava Development Kit (Everything you need to BUILD apps)
JitJust-In-Time compiler (Speeds up Java while it runs!)