aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes JavaBeans Naming Rules Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "JavaBeans Naming Rules" Watch "JavaBeans Naming Rules" New topic
Author

JavaBeans Naming Rules

Karim Kiswarday
Ranch Hand

Joined: Oct 01, 2010
Posts: 50

Hello everybody,
I have a question about the JavaBeans Property Naming Rules used in B&K book.

This rule explain that: (pag 9)
"Getter method signatures must be marked public, take no arguments, and have a return type that matches the argument type of the setter method for that property."

But in the Java APIs, this JavaBeans property is not observed.
For example:
1)In the Java URL class (java.net package) a getter has this signature:
public final Object getContent(Class[] classes) //it takes an array argument

2)In the Integer class (java.lang package) three getters don't have standard signatures:
public static Integer getInteger(String nm)
public static Integer getInteger(String nm, int val)
public static Integer getInteger(String nm, Integer val)

and in other classes of other packages have this not standard JavaBeans behavior.

I will use this rule, but why in the Java API is not all the time respected?
Is it a issue/compatibility with the past?

Thanks, and sorry for my english
KK


No fun at the table, no fun in the sack.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61201
    
  66

Not every Java class is a bean.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
URL and Integer are not JavaBean components - they are not conforming JavaBean rules.

JavaBean components are objects that can be visually manipulated in the IDE,
for example in a Swing form buillder in NetBeans you can drag and drop JavaBean components from a palette
and place them on a form (button, editbox, menu etc.), launch a property editor on placed component,
set some components' properties using the property editor etc. - without writing any line of code.
You can create your own JavaBean components and add them to the palette.
To create such component, you must create a java class that MUST conform JavaBean specification.
If it doesn't conform JavaBean rules - it is not JavaBean and it can't be used in this way.
Here you can find more information about JavaBeans:
http://en.wikipedia.org/wiki/JavaBean
http://www.oracle.com/technetwork/java/javase/tech/index-jsp-138795.html
http://wiki.netbeans.org/NetBeansJavaBeansTutorial
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61201
    
  66

Ireneusz Kordal wrote:JavaBean components are objects that can be visually manipulated in the IDE

That is but one -- and fairly niche -- use of JavaBeans.

They are also used extensively in web applications and by frameworks such as Spring and Hibernate.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaBeans Naming Rules