• Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaBean naming standard  RSS feed

 
John Paterson
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,

The following are the question, answer and explanation for an objective 1 question taken from the KS &BB study guide page 74.

2. Which method names follow the JavaBeans standard? (Choose all that apply.)

A. addSize
B. getCust
C. deleteRep
D. isColorado
E. putDimensions


Answer:
- B and D use the valid prefixes 'get' and 'is'.
- A is incorrect because 'add' can be used only with Listener methods. C and E are
incorrect because 'delete' and 'put' are not standard JavaBeans name prefixes.
(Objective 1.4)


My question is, so what if add can be used only with Listener methods? The question did not ask for method names following JavaBeans standard applying to non-Listener methods. I understand from the KS&BB book, page 9:

JavaBean Listener Naming Rules

■ Listener method names used to "register" a listener with an event source
must use the prefix add, followed by the listener type. For example,
addActionListener() is a valid name for a method that an event source
will have to allow others to register for Action events.


Since it's listed under JavaBean Listener Naming Rules dosen't add become JavaBean standard? Hope somebody can explain. Thanks.

regards
John
 
Gaurangkumar Khalasi
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally, Java Beans used to set/get particular value of the instance variable of the defined class.
For example, instance variable customer, than void setCustomer(){} and int getCustomer(){}

And for boolean instance variable(for example colorado), it will check its status with isVariableName(for example isColorado() ).
 
Gaurangkumar Khalasi
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
addXxxListerner()
removerXxxListener()

are valid javabeans conventions for adding and removing listeners.

But removeX() or addX() are not JavaBeans naming standards.

For more information:
http://www.coderanch.com/t/262282/java-programmer-SCJP/certification/JavaBeans-naming-standard
http://www.coderanch.com/t/257589/java-programmer-SCJP/certification/SCJP-Errata-Updated
 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gaurangkumar Khalasi wrote:addXxxListerner()
removerXxxListener()

are valid javabeans conventions for adding and removing listeners.

But removeX() or addX() are not JavaBeans naming standards.

For more information:
http://www.coderanch.com/t/262282/java-programmer-SCJP/certification/JavaBeans-naming-standard
http://www.coderanch.com/t/257589/java-programmer-SCJP/certification/SCJP-Errata-Updated


Nice.:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!