Dear all, I am new to Java. I want to ask what is the difference between Java Bean and the ordinary Java Classes? Regards, Joe
Joined: Jan 30, 2002
The only requirement that an ordinary java class be considered a bean is that it must have a public default constructor and use getters and setters to access its public properties. Properties can be read-only, write-only and read-write. So if you have a read-write int property named age then you must have methods public int getAge() and public void setAge(int age) For a boolean instead of prefixxing with get you can use is instead for example public boolean isLogged(). Also you can have indexed properties which are simply arrays using getters and setters. Finally you can fire property changes for interested listeners whenever a bean's property changes.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher