Java OOP: Object-Oriented Programming — தமிழ்

</>Coding Tamilan.← Java course & curriculum
Java Masterclass · Lesson 24 / 50 · தமிழ்

Java OOP: Object-Oriented Programming

Bring state and behavior together.

Step-by-step explanationsRunnable JavaPractice + answer

முக்கிய விளக்கங்கள் தமிழில் உள்ளன. Runnable example மற்றும் கூடுதல் practice notes ஆங்கிலத்தில் உள்ளன.

இந்தப் பாடத்தில்…

  • Explain the key idea behind OOP.
  • Read and run a complete example, then predict what changes.
  • Recognize the topic-specific mistake discussed below.
01 / The concept

அடிப்படையைப் புரிந்துகொள்ளுங்கள்

Object-oriented programming models concepts using objects with state and behavior. A class defines a type; each new object can hold its own field values. Start with a concrete example before memorizing the names of OOP principles.

02 / Step by step

விரிவான விளக்கங்கள்

Object-Oriented Programming (OOP) என்றால் என்ன?

Java ஒரு முழுமையான Object-Oriented Programming (OOP) language. Procedural programming-ல் functions மற்றும் logic-க்கு முக்கியத்துவம் அளிக்கப்படுகிறது. ஆனால், OOP-ல் data மற்றும் methods-ஐ உள்ளடக்கிய Objects-க்கு முக்கியத்துவம் அளிக்கப்படுகிறது.

Development-ல் OOP-ஐ பயன்படுத்துவதன் முக்கிய நன்மைகள்:

  • Code-ஐ விரைவாகவும் எளிதாகவும் execute செய்ய முடியும்.
  • பெரிய Projects-க்கு மிகவும் தெளிவான structure கிடைக்கிறது.
  • DRY (Don't Repeat Yourself) principle-ஐ பின்பற்றி, code-ஐ எளிதாக reuse செய்யலாம்.
  • Complex applications-ஐ maintain மற்றும் debug செய்வது மிகவும் சுலபம்.

OOP-இன் 4 முக்கிய தூண்கள் (The 4 Pillars of OOP)

Pillar (தூண்)விளக்கம்Java-வில் பயன்பாடு
EncapsulationData மற்றும் methods-ஐ ஒரே unit-ஆக பாதுகாப்பது; sensitive data-ஐ மறைப்பது.private fields மற்றும் public getters/setters
Inheritanceஒரு Parent class-இன் பண்புகளை Child class பெற்றுக்கொள்வது (Code Reusability).extends keyword
Polymorphismஒரே method வெவ்வேறு Objects-ல் பல வடிவங்களில் செயல்படுவது.Method overriding (@Override) மற்றும் Overloading
Abstractionதேவையான தகவல்களை மட்டும் வெளிப்படுத்தி, பின்னணி வேலைகளை மறைப்பது.Abstract classes மற்றும் Interfaces

Real-world Analogy: உங்களின் Smartphone ஒரு சிறந்த OOP உதாரணம்! அது வன்பொருளை encapsulate செய்கிறது, பொதுவான தொலைபேசி பண்புகளை inherit செய்கிறது, பலவகைப்பட்ட polymorphic apps-ஐ ஆதரிக்கிறது, மற்றும் பேட்டரி மேலாண்மை போன்ற சிக்கலான தொழில்நுட்பங்களை பயனர்களிடமிருந்து abstract செய்கிறது.

Spring Boot மற்றும் Microservices போன்ற நவீன Enterprise Frameworks முழுமையாக இந்த 4 OOP principles-ஐ அடிப்படையாகக் கொண்டே செயல்படுகின்றன. எனவே OOP-ல் வலுவான அடித்தளம் அமைப்பது ஒரு Senior Full-Stack Developer-ஆக மாறுவதற்கு மிகவும் அவசியமாகும்.

Java reference fragmentJAVA
// Define a class (Blueprint)
class Car {
    String brand;
    int speed;

    void drive() {
        System.out.println(brand + " driving at " + speed + " km/h");
    }
}

public class Main {
    public static void main(String[] args) {
        // Create objects (Instances)
        Car car1 = new Car();
        car1.brand = "Toyota";
        car1.speed = 80;
        car1.drive();  // Output: Toyota driving at 80 km/h

        Car car2 = new Car();
        car2.brand = "BMW";
        car2.speed = 120;
        car2.drive();  // Output: BMW driving at 120 km/h
    }
}

Interview Question: OOP-ல் உள்ள 'Encapsulation' கோட்பாட்டின் முக்கிய நோக்கம் என்ன?

  1. ஒரே பெயரில் பல methods-ஐ உருவாக்குவது
  2. Child class-ஐ Parent class-ல் இருந்து பிரிப்பது
  3. Sensitive data-ஐ பாதுகாத்து, direct access-ஐ தடுப்பது
  4. Code-ஐ run ஆவதற்கு முன்பே compile செய்வது
Reveal answer / விடை

Sensitive data-ஐ பாதுகாத்து, direct access-ஐ தடுப்பது

சரியான விடை! Encapsulation என்பது data-ஐ பாதுகாப்பதற்கான ஒரு கவசம். `private` variables மற்றும் `public` getters/setters மூலம் data integrity-ஐ உறுதி செய்வதே இதன் முக்கிய நோக்கமாகும்.

03 / Read and predict

முழுமையான உதாரணம்

This complete Main.java program focuses on the lesson idea. Reference fragments above may demonstrate individual statements; this example includes the imports, entry point, and supporting types it needs.

Main.java · complete runnable exampleJAVA
public class Main {
    public static void main(String[] args) throws Exception {
        Bicycle bike = new Bicycle();
        bike.speed = 10;
        bike.accelerate();
        System.out.println(bike.speed);
    }
}
class Bicycle {
    int speed;
    void accelerate() { speed += 5; }
}
Predict first. Then reveal the expected output / வெளியீடு
15

The output shown was checked by running this complete example. Trace the executed statements in order, then compare with your run.

04 / Learn by changing

Change it. Run it. Understand it.

Load this lesson example into the editor. Change one value or statement, predict the result, then press RUN to execute Java.

Open Java editor ↗
After the editor loads, choose Load this lesson example, then press RUN.

Powered by OneCompiler. Code you run is sent to OneCompiler for execution. For Scanner examples, supply input in the editor I/O panel; for file examples, files exist in its execution environment.

05 / Your turn

நீங்களே முயற்சி செய்யுங்கள்

Practice challenge

Create a second Bicycle and print its speed without accelerating it.

Reveal the answer and reasoning / விடை

The second object starts with its own speed value, 0. Changing one object does not automatically change another.

தவிர்க்க வேண்டிய தவறு: A class is the definition of a type. A variable holding an object reference is not the class itself.

பாடத்தின் சுருக்கம்

  • Explain the example without reading the output first.
  • Make the change requested in the practice task.
  • Describe why the result changed—or why compilation failed.

Ready to move on? Follow the next lesson in course order, or return to the curriculum to review a prerequisite.

Coding Tamilan · Understand the idea. Try the code. Build the habit.