Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

How to name a method like addBooks According to the Java Naming Standard

 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to name a method like addBooks According to the Java Naming Standard

Is it like



Varuna
 
Marshal
Posts: 69019
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the method add books to something? Then public void addBooks is correct.

You would probably pass a List<Book> or Book[] array as a parameter, so you end up withor
 
Varuna Seneviratna
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes This add books and also I want to know how to name this method according to Java Bean naming standard


Varuna
 
Sheriff
Posts: 21922
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java Bean naming standard does not have any support for methods except the following:
- getXxx and setXxx, where xxx is your property
- addXxxListener and removeXxxListener, for adding and removing XxxListener instances
 
Varuna Seneviratna
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct Rob I was confused when I referred the Study Guide for SCJP of Kathy and Bert it mentions naming conventions only for set and get methods for Java Beans.Then what came into my mind was what is the naming standard for methods that are not setting or returning values.According to what I get Java Beans does not have methods other than for setting or returning values.Am I correct?


Varuna
 
Rob Spoor
Sheriff
Posts: 21922
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well there's the adding and removing of event listeners I mentioned, but for the rest no.

Still, addBook(Book book), removeBook(Book book), addBooks(Book[] books), addBooks(Collection<Book> books), removeBooks(Book[] books) and removeBooks(Collection<Book> books) are perfect names - as long as they do what the say they do
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd disagree slightly with Rob and Campbell. If you are adding all of the elements of one collection to the contents of another collection then I would follow the naming used in the Collection interface. i.e. use addAllBooks(List<Book> books) instead of addBooks(List<Book> books).


[ October 17, 2008: Message edited by: Paul Beckett ]
 
Varuna Seneviratna
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a document that I can refer about Java Bean naming standard

Varuna
 
Campbell Ritchie
Marshal
Posts: 69019
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I won't disagree about "addAllBooks."
 
Rob Spoor
Sheriff
Posts: 21922
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul has a point, but I'm lazy and that's three extra characters each time
 
Bartender
Posts: 9612
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Varuna Seneviratna:
Is there a document that I can refer about Java Bean naming standard



JavaBeans API Specifications
Code Conventions for the Java Language
 
Campbell Ritchie
Marshal
Posts: 69019
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Rob Prime:
Paul has a point, but I'm lazy and that's three extra characters each time

He has "Campbell" in his name; he's bound to be right.
 
The City calls upon her steadfast protectors. Now for a tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic