Search This Blog

Friday, November 11, 2005


java can be used by the programmers to find the info about a java class. It can also be used to disassemble the code that should in a class file.Ex: javap javap java.lang.IntegerWhen we compile a java class file, the java compiler generates a class file inbyte code (numbers representing instructions). When javap tool is executedwith -c option these numbers will be converted as instructions like getstatic,return.As part of the Object class we have an implementation of toString(),hashCode() methods. Depending upon our requirement we may need toprovide the implementation of these methods.The implementation of hashCode provided by Java Soft may not be suitablefor our classes. In this case we need to implement our own logic for hashCode. The objects representing the same information must return the same hashcode.Apart from implementing hashCode we need to implement equals() –returns true if your objects are considered to be equal.Even though equals was implemented as part of object class this may notsatisfy our requirements. In such a case we need to override equals().*We have to override equals() whenever hashCode() is overridden.toString() provided as part of object class returns the name of the class andthe hashcode. This may not be that useful in debugging the code.toString()hashCode() Used for debuggingequals()Most of the programmers debug their applications by including thestatements that displays the information about the object. It is alwaysadvisable to provide toString() that returns the info about the object.Its our responsibility to return useful info from toString() method.Used to identify whether theobjects are same or not

No comments: