DEV Community

Tpointechblog
Tpointechblog

Posted on

Best Java Tutorial to Learn Object-Oriented Programming

If you’re serious about becoming a software developer, mastering Object-Oriented Programming (OOP) is non-negotiable—and the best place to start is Java. In this Java Tutorial, Tpoint Tech brings you a comprehensive, step-by-step guide to learning OOP in Java, right from understanding What is Java? to writing real-world Java classes.

Image description

What is Java?

Java is a high-level, object-oriented programming language developed by Sun Microsystems (now owned by Oracle). Released in 1995, Java is designed to be platform-independent using the JVM (Java Virtual Machine), meaning code written once can run anywhere.

Why is Java Popular?

  • Object-Oriented by design
  • Used in enterprise applications, Android development, web apps, and cloud-based solutions
  • Huge ecosystem and community support
  • Strong memory management, multi-threading, and security

Why Learn Object-Oriented Programming with Java?

Java is built around Object-Oriented Programming, which is a programming paradigm focused on classes, objects, inheritance, polymorphism, encapsulation, and abstraction.

OOP improves:

  • Code modularity
  • Reusability
  • Easier debugging
  • Real-world modeling

Setting Up Java

Before diving in, make sure Java is installed:

  1. Download Java JDK from Oracle’s site.
  2. Install an IDE like IntelliJ IDEA, Eclipse, or use VS Code with Java extension.
  3. Verify Java installation using terminal:
java -version
Enter fullscreen mode Exit fullscreen mode

Basic Java Structure

Here’s a simple “Hello World” program:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Welcome to Tpoint Tech!");
    }
}
Enter fullscreen mode Exit fullscreen mode

🧱 Understanding Classes and Objects

Class = Blueprint

Object = Instance of Class

public class Car {
    String color = "Red";
    int speed = 100;

    void drive() {
        System.out.println("Car is driving at " + speed + " km/h.");
    }
}
Enter fullscreen mode Exit fullscreen mode

Creating an Object:

public class Main {
    public static void main(String[] args) {
        Car myCar = new Car();
        System.out.println("Color: " + myCar.color);
        myCar.drive();
    }
}
Enter fullscreen mode Exit fullscreen mode

Encapsulation

Encapsulation is the concept of hiding internal details using private variables and public getters/setters.

public class Student {
    private String name;

    public void setName(String n) {
        name = n;
    }

    public String getName() {
        return name;
    }
}
Enter fullscreen mode Exit fullscreen mode
public class Main {
    public static void main(String[] args) {
        Student s = new Student();
        s.setName("Aman");
        System.out.println("Student Name: " + s.getName());
    }
}
Enter fullscreen mode Exit fullscreen mode

Inheritance

Inheritance allows one class to inherit properties from another.

class Animal {
    void sound() {
        System.out.println("Animal makes a sound");
    }
}

class Dog extends Animal {
    void bark() {
        System.out.println("Dog barks");
    }
}

public class Main {
    public static void main(String[] args) {
        Dog d = new Dog();
        d.sound();
        d.bark();
    }
}
Enter fullscreen mode Exit fullscreen mode

Polymorphism

Polymorphism = One method, many forms (compile-time and runtime)

Method Overloading (Compile-time):

class MathOperation {
    int add(int a, int b) {
        return a + b;
    }

    double add(double a, double b) {
        return a + b;
    }
}
Enter fullscreen mode Exit fullscreen mode

Method Overriding (Runtime):

class Animal {
    void sound() {
        System.out.println("Animal sound");
    }
}

class Cat extends Animal {
    void sound() {
        System.out.println("Meow");
    }
}
Enter fullscreen mode Exit fullscreen mode

🧱 Abstraction

Abstraction is hiding complexity and showing only essentials. Achieved using abstract classes or interfaces.

abstract class Shape {
    abstract void draw();
}

class Circle extends Shape {
    void draw() {
        System.out.println("Drawing Circle");
    }
}
Enter fullscreen mode Exit fullscreen mode

Mini Project: Simple Bank Account System

class BankAccount {
    private double balance = 0;

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

    void withdraw(double amount) {
        if (amount <= balance)
            balance -= amount;
        else
            System.out.println("Insufficient balance.");
    }

    void showBalance() {
        System.out.println("Current Balance: " + balance);
    }
}
Enter fullscreen mode Exit fullscreen mode
public class Main {
    public static void main(String[] args) {
        BankAccount acc = new BankAccount();
        acc.deposit(5000);
        acc.withdraw(1500);
        acc.showBalance();
    }
}
Enter fullscreen mode Exit fullscreen mode

Conclusion

This Java Tutorial gave you a hands-on introduction to core Object-Oriented Programming concepts using Java. From basic class structures to advanced features like inheritance and polymorphism, Java provides a perfect environment to master OOP principles.

So next time someone asks What is Java?, you’ll not only have the answer—you’ll have the code to prove it.

At Tpoint Tech, we believe in learning by doing. So keep coding, keep practicing, and explore more Java tutorials to become a confident Java developer.

Top comments (0)