Popular Posts

Wednesday, December 01, 2004

a += b is NOT the same as a = a+b

Yeah, its not the same in Java.

int a = 2
float b = 3.2

a = a + b => leads to compile time error as expected. Explicit cast is required because of loss of preciiosn.

a += b => (Surprisingly!!) works fine - without even a warning!!

According to the Java Language Specification ----

A compound assignment expression of the form E1 op= E2 is equivalent to E1 = (T)((E1) op (E2)), where T is the type of E1, except that E1 is evaluated only once. Note that the implied cast to type T may be either an identity conversion (§5.1.1) or a narrowing primitive conversion (§5.1.3). For example, the following code is correct:

short x = 3;
x += 4.6;

and results in x having the value 7 because it is equivalent to:

short x = 3;
x = (short)(x + 4.6);

So its a feature of the language after all !!

And u thot they never preach u wrong.... Most of the books tell ya otherwise, don't they?

Grady Booch's Handbook of Software Architecture

Handbook of Software Architecture by Grady Booch -

- http://www.booch.com/architecture/index.jsp

The site is not completely functional.

Booch's blog is at:


Tuesday, November 30, 2004

We know the rule on using GC.Collect() - Do not use it unless u must use it!

So when do we use it?

Go check this -


Monday, November 29, 2004

Java linkblog

Found the following blog useful:


Gives lots of links to Java related articles/software....

Wednesday, November 24, 2004

funny sig

Found this funny sig in John Evdemon's blog...

"There are only 10 types of people in this world; those who understand binary and those who don't."