File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "JavaBeans Naming Rules" Watch "JavaBeans Naming Rules" New topic

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 ( 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

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

Joined: Jan 10, 2002
Posts: 63870

Not every Java class is a bean.

[Asking smart questions] [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:
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63870

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:
subject: JavaBeans Naming Rules
It's not a secret anymore!