Home > Software > Java > Core-Java
Interview Questions   Tutorials   Discussions   Programs   

Core-Java - What is adapter class?

asked marvit August 18, 2014 11:18 PM  

What is adapter class?


1 Answers

answered By kavya64   0  
Java Annotations are also called Metadata. Annotations are introduced with JDK 5 onwards. Annotations allows us to add some form of metadata information into our source code, but it doesnot change the execution flow of the program. These annotations can then be processed at compile time by the compiler tools or during at runtime via Java Reflection. Classes, methods, variables may be annotated.

An adapter class is an implementation class  of a listener interface which contains all methods implemented with empty body. for example,WindowAdapter is an adapter class of WindowListener interface.Adapter classes reduce overhead on programming while working with listener interfaces.
Many listener interfaces have more than one callback method. An example is, even the code of myclass can be copied directly into addwindowListener() method,as: 
f.addwindowlistener(new windowAdapter()
    public void windowClosing(windowEvent e)
To avoid having many empty listener methods for many listeners, Adapter classes are provided. These implement the listener interface, and provide empty (no operation) implementation of its methods. The advantage is that the listener can extend these, and only specialize methods of choice without having to provide default implementations for the rest (these are inherited from the Adapter).
Java bean.addFocusListener(new java.awt.event.FocusAdapter()
     public void focusGained(java.awt.event.FocusEvent e)
   add comment

Your answer

Join with account you already have



Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!