Monday, July 28, 2008

Something for Solaris SPARC

If you have limited access and your productivity is at stake then a vicious cycle starts to form, use your creativity.



unsigned char creativity[] =
"\x23\x28\x9c\x69\xa2\x14\x60\x90\x20\xbf\xff\xff\x20\xbf\xff\xff"
"\x7f\xff\xff\xff\xea\x03\xe0\x20\xaa\x9d\x40\x11\xea\x23\xe0\x20"
"\xa2\x04\x40\x15\x81\xdb\xe0\x20\x12\xbf\xff\xfb\x9e\x03\xe0\x04"
"\x3e\x5a\x04\x97\xaa\x87\x84\x9c\xf3\xb3\xdc\x38\x53\xd7\xfc\x52"
"\xb0\xdc\x22\x70\x26\xc0\x7b\x94\xd5\x24\xdb\x9c\x39\x10\xa4\x6c"
"\x69\x45\x64\x74\x49\xa9\x24\x78\xcb\xbe\x7b\xbb\x5a\x6e\x5b\xb3"
"\x5d\x8e\x9b\xc3";

Annihilate with passion.

Sunday, July 13, 2008

Equality of Java Objects

There are 3 candidates for the equality test in Java:
1. Primitives
2. References
3. Objects


When we compare things in Java, what is really being compared? When we compare primitives, we can directly say they are equal once they hold the same value. Therefore they can be compared using the == operator. The same is true for reference variables, however, we are not comparing the actual values being referred to, rather we compare the pointers to the actual values.


Primitive



int someInt = 1;
if (someInt == 1) {
//this block will execute
}

The equality of two objects is tested using the equals method of the Object class. The default behavior of the equals method is just the same as the == operator. However, some classes override this method for a specific comparison. One example is the String class, the equals method is overridden to test the equality of the actual strings being held by two String objects.


Object without an overridden equals method



Object a = new Object();
Object b = new Object();

if (a.equals(b)) {
//this block will not execute
}

Object with an overridden equals method



String a = new String("I am a string!");
String b = new String("I am a string!");

if (a.equals(b)) {
//this block will execute depending on the implementation
//of the equals method, for this instance, it compares the string literals
//being held by two String objects
}

So if you are unsure of how the equals method behave in a specific class, RTF API documentation!