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.
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 are closed for "Java Peer Class".
what is a native object?
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++.
That’s an excellent definition for native. Thanks Sandeep.
this is a good web site
nice information thak u
Really nice blog.
what s peer interface?
very good
me too…love java papers…/111
hmmmm..very good
good timing..
what is a peer class for String. This question was asked in an interview?
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.