With Java 1.5, autoboxing and unboxing are introduced to automatically convert the primitive type into boxed wrappers or vice versa.
Autoboxing: It is the process of converting primitives to their corresponding object type automatically.
Unboxing: It is the process of converting object types to their corresponding primitives automatically.
Continue reading Autoboxing and Unboxing in Java
In java, every object has two identity methods:
- equals : compares two objects in order to determine if they are equal or not. If you do not override this method or no parent class overrides it, equals method acts like == operator by default. (Beware that == operator compares object references not values.)
- hashcode: provides and an int value which is derived from the memory address of the object. If two objects occupy same memory address they have same hashcode by default.
If you leave equals and hashcode methods as it is, one can conclude that whenever equals is true for two object, their hashcode value must be same.
So in order to not to break this rule, if you override one of these methods, you must override both.
Why do we need hashcode ?
Continue reading Understanding equals and hashcode in Java
If you are coming from C/C++ programming background, you probably heard about “Call by Value” and “Call by Reference” argument passing mechanisms.
- Call by Value : A copy of the object instance is passed to called method. Any modifications made on the object inside the method will not be reflected back to the original object.
- Call by Reference : A reference to the original object is passed to called function. This reference may be thought as an alias for the original object and any modification done on the alias object inside the method actually done on the original object.
In this sense what about JAVA?
Continue reading Argument passing nature of JAVA