Java

Java, released by Sun Microsystems in 1995 (James Gosling), made class-based object-oriented programming mainstream. Code compiles to bytecode that runs on the Java Virtual Machine, so "write once, run anywhere" became a practical promise for large systems.

Paradigm: Object-Oriented Programming

What Makes Java Special

  • Classes and interfaces. Nearly all code lives in a class. A class extends one parent and can implement many interfaces, a contract of methods with no state.
  • Static typing. The compiler checks types before the program runs. Generics such as List<Shape> keep collections safe without casts.
  • Automatic memory management. A garbage collector frees unused objects, which removes a whole class of bugs seen in C.
  • The JVM ecosystem. The same virtual machine runs Kotlin, Scala and Clojure, and a huge library and tooling ecosystem surrounds it.
  • It keeps modernizing. Lambdas, records, sealed types, pattern matching and virtual threads have added functional and concise styles to the object model.

Example: Polymorphism with an interface and records

import java.util.List;

interface Shape {
    double area();
}

record Circle(double radius) implements Shape {
    public double area() { return Math.PI * radius * radius; }
}

record Rectangle(double width, double height) implements Shape {
    public double area() { return width * height; }
}

public class Main {
    public static void main(String[] args) {
        List<Shape> shapes = List.of(new Circle(1.0), new Rectangle(2, 3));
        for (Shape s : shapes) {
            System.out.printf("%s -> %.2f%n", s, s.area());
        }
    }
}

How It Works

  • Shape is an interface: it promises an area() method but says nothing about how to compute it.
  • record (Java 16 and later) declares a small immutable class; the constructor, accessors and toString are generated for you.
  • The loop holds each item as a Shape and calls area(). The version that runs depends on the real object, which is polymorphism.
  • The output is Circle[radius=1.0] -> 3.14 and Rectangle[width=2.0, height=3.0] -> 6.00.

History and Where It Is Used

Java is a core language for enterprise back ends, Android (with Kotlin), big-data tools such as Hadoop and Kafka, and large financial systems. Its long-term support releases and vast ecosystem make it a safe career choice. See the Java roadmap for a complete course.

Learn More