Java Peer Class

November 13th, 2009

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.

what is a native object?

som on December 8th, 2009 4:36 am

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

Sandeep Kumar on January 12th, 2010 4:58 pm

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

Joe on January 13th, 2010 4:06 am

this is a good web site

muhammadeja on January 28th, 2010 4:19 pm





hidden and gravatar enabled.