Java Interface — தமிழ்

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

Java Interface

Program to a capability.

Step-by-step explanationsRunnable JavaPractice + answer

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

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

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

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

An interface describes a contract that different classes can implement. The caller can depend on that contract rather than a concrete implementation. A class may implement more than one interface, which makes capabilities easier to combine.

02 / Step by step

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

Java Interface: OOP-ன் ஒப்பந்தம்

Interface என்பது completely abstract class மாதிரி — அதுல methods இருக்கும், ஆனா body இல்லாது.

Interface implement பண்றதுக்கு implements keyword use பண்றோம்:

Multiple Interfaces

Java-ல multiple inheritance directly support ஆகல — ஆனா multiple interfaces implement பண்ணலாம்:

Interface-ல attributes automatically public, static, மற்றும் final-ஆ இருக்கும். Methods automatically public மற்றும் abstract-ஆ இருக்கும்.

Java reference fragmentJAVA
interface Drawable {
    void draw();
    default String type() { return "2D"; }
}

interface Resizable {
    void resize(int factor);
}

class Square implements Drawable, Resizable {
    int side;
    Square(int s) { this.side = s; }
    public void draw()        { System.out.println("Square " + side + "x" + side); }
    public void resize(int f) { side *= f; }
}

Square sq = new Square(4);
sq.draw();    // Square 4x4
sq.resize(3);
sq.draw();    // Square 12x12

Interfaces — Microservices-ன் அடிப்படை: Real-world Java development-ல், குறிப்பாக Spring Boot microservices-ல், Interfaces மிகவும் critical. Service layer-ல் UserService interface define பண்ணி, UserServiceImpl-ல் implement செய்வது — testing, mocking, மற்றும் multiple implementations-க்கு மிகவும் உதவியாக இருக்கும்.

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 {
        Printable report = new Report();
        report.print();
    }
}
interface Printable { void print(); }
class Report implements Printable { public void print() { System.out.println("Report is ready"); } }
Predict first. Then reveal the expected output / வெளியீடு
Report is ready

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 Receipt class that implements Printable and prints a different message.

Reveal the answer and reasoning / விடை

The caller can use Printable receipt = new Receipt(); and invoke the same print method.

தவிர்க்க வேண்டிய தவறு: A class implementing this interface must provide a public print method; it cannot reduce the access of the interface method.

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

  • 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.