Java Peer Class

Last modified on November 13th, 2009 by Joe.

Peer classes are written by java API developers to interface with native objects. Peer classes should be rightly mentioned as peer interfaces. You can program for the interface as if you are connecting to the C / C++ or any native objects. After doing the programming, you can use javah command line tool that is available in your jdk to generate the stub classes.Peer

It will not have any attributes and you cannot inherit them. Those are just a handle for you to write your implementation based on them. Also every peer class is a parallel to a native class and it is a one to many mapping. One peer and many native objects. But mostly it will be used like one to one mapping.

The last sighting of peer classes was in JDK 1.0 (Component) had a method getPeer() which returned a ComponentPeer. But it was immediately deprecated in JDK 1.1 But all those classes are still residing in the JDK and used internally. There is a package java.awt.peer with a complete set of peers for platform dependent objects. You might need to write your own peer classes if you are going to write platform specific code and implementations. If not, just be aware about these peer classes and that’s simply enough.

Comments on "Java Peer Class"

  1. som says:

    what is a native object?

  2. Sandeep Kumar says:

    The word ‘native’ is often used for refering to code written in platform specific coding language, e.g. C, C++. So, when you say ‘native code’, it refers to ‘machine code’. Such code is compiled to directly run with a particular processor(hardware) and its set of instructions.

    So, ‘native object’ implies objects that are created using native codes. This word best suits with OOP native languages like C++.

  3. Joe says:

    That’s an excellent definition for native. Thanks Sandeep.

  4. muhammadeja says:

    this is a good web site

  5. Anonymous says:

    nice information thak u

  6. Arslan says:

    Really nice blog.

  7. M.Lakshmi says:

    what s peer interface?

  8. sweety says:

    very good

  9. sweety says:

    me too…love java papers…/111

  10. bhavika says:

    hmmmm..very good
    good timing..

  11. Jafar says:

    what is a peer class for String. This question was asked in an interview?

  12. Joe says:

    Jafar, I don’t think there is something like that.

    With some googling I found that in one occasion StringBuffer is referred as a peer class of String. But it should be done in a general sense like referring a peer.

    Technically, I don’t think there is something like that.

Comments are closed for "Java Peer Class".