DEV Community

Tamilselvan K
Tamilselvan K

Posted on

Day-73 Understanding Java OOP Concepts: POJO, Getter & Setter methods

What is a POJO Class?

POJO stands for Plain Old Java Object.

  • It is a simple class with private variables.
  • We use getter and setter methods to access and update those private variables.
  • POJO classes are mainly used in real-time projects to carry data.

Why Use Getter and Setter Methods?

  • We keep variables private for security and data hiding.
  • We use public getter and setter methods to access and update values from outside the class.
  • This way, we can add logic (like validation) in the setter if needed.

Object as Argument

We can also pass objects as arguments to other methods or constructors. This helps in reusing data and makes the code cleaner.

Binding in Java (Static & Dynamic)

  • Static Binding: Happens at compile time.
  • Dynamic Binding: Happens at runtime.

Java is a Statically Typed Language

In Java, the type of variables is checked during compile time, which means we must declare the data type of each variable.

Real-Life Example: Traffic Rules

Traffic rules can be related to the concept of interfaces in Java. Every class that implements an interface must follow its rules or implement its methods.

Interface and Multiple Inheritance

  • In Java, interfaces support multiple inheritance (by separating them with commas).
  • Since we only implement methods (not inherit them), there is no diamond problem.

Top comments (0)