воскресенье, 4 сентября 2011 г.

char to ascii integer and back

http://bytes.com/topic/java/answers/17511-char-ascii-integer-back
System.out.println((int)'A');
System.out.println((char)65);

http://ubuntuforums.org/showthread.php?t=298414

воскресенье, 17 июля 2011 г.

Aggregation and composition in Java

http://www.celinio.net/techblog/?cat=14
I usually forget the differences between the composition and the aggregation relationships and mix them together, so here is a memento that i will share with everyone.
  • Composition : a filled diamond
  • Aggregation : an unfilled diamond
The relation between a car and a tyre is an aggregation because the tyre is still a tyre if it is not attached to a car. The tyre has a life of its own. It exists outside of a car and you can use it on another car.
The relation between a car and a carburetor is a composition because the carburetor has no use if it is out of a car.
Aggregation and composition in Java
Now more interesting is the implementation in Java of these 2 relationships :
Aggregation :
class Car {

}

class Tyre {
private  car = new Car();

}

Composition :
class Carburetor {

}

class Car{
Carburetor  carburetor = null ;
public void setCarburetor( Carburetor  carburetor )
{
this.carburetor = carburetor;
}


}