DEV Community

The Practical Developer
The Practical Developer

Posted on Originally published at practicaldevblog.blogspot.com

Java Explained: Object-Oriented Basics Without the Jargon

Introduction

Java has been around since 1995 and still runs an enormous share of the world's backend systems, Android apps, and enterprise software. Its staying power comes from one idea, taken seriously: everything in your program is an object — a thing with data and behaviour.

That sounds abstract. It becomes concrete with one example: a bank account.

Classes and objects

A class is the blueprint. An object is a thing built from that blueprint. You write the class once, then create as many objects from it as you need.

public class BankAccount {
    private double balance;

    public BankAccount(double startingBalance) {
        balance = startingBalance;
    }

    public void deposit(double amount) {
        balance += amount;
    }

    public double getBalance() {
        return balance;
    }
}

BankAccount mine = new BankAccount(100);
mine.deposit(50);
System.out.println(mine.getBalance()); // 150.0
Enter fullscreen mode Exit fullscreen mode

BankAccount is the class; mine is an object. The object holds its own balance, and its methods (deposit, getBalance) are the only way to interact with it.

The four ideas of object-oriented programming

Java's design rests on four ideas, and the bank account shows all of them:

  • Encapsulation — the balance is private, so outside code cannot set it directly to a nonsense value. It must go through deposit, which is the controlled door.
  • Abstraction — code using the account does not need to know how the balance is stored. It just calls getBalance(). The inside can change without breaking the outside.
  • Inheritance — a SavingsAccount can extend BankAccount, reusing deposit and balance, and adding interest. You write the shared behaviour once.
  • Polymorphism — code that works with a BankAccount works with a SavingsAccount too, because it is a kind of bank account. One interface, many forms.

You do not need to memorise these words. If you remember "hide the data, expose the behaviour, reuse through inheritance", you have the substance.

Why Java is verbose — and why that is sometimes good

Java code is longer than Python or JavaScript for the same task. Types are declared everywhere, and even a small program needs a class and a main method. Beginners often find this annoying, and fairly so.

The trade is explicitness: when you read Java code six months later, the types tell you exactly what each value is, and the compiler catches mismatches before the program runs. In large teams and long-lived systems, that explicitness is worth the extra typing.

"Write once, run anywhere"

Java programs compile to bytecode, which runs on the Java Virtual Machine (JVM) — a program that itself runs on Windows, macOS, Linux, and more. Compile once, and the same bytecode runs anywhere a JVM exists. That portability was Java's original selling point, and it is still true today.

Takeaway

A class is a blueprint, an object is a thing built from it, and the four object-oriented ideas are just ways of keeping data safe, behaviour clear, and code reusable. Start with one class, one object, and one method, and Java stops looking intimidating.

Originally published at https://practicaldevblog.blogspot.com/2026/10/java-explained-object-oriented-basics.html

Top comments (0)