• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A silly question about naming convention

 
Ranch Hand
Posts: 86
1
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends, Im creating the following class:

I readed the Java naming conventions file, because its very important to me to follow this conventions. So, if I follow the correct convention the name of accessor method will be getOnCreateEvent() correct? Or it will be getonCreateEvent() ? (with the 'o' lower case) ?
Thanks in advance!

 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's Camel case (The humps .. Get it?)

Your method is called getOnCreateEvent(), however be warned that in some EL (Expression Languages)
and the "new" Ruby/Groovy/Roo patterns, your view code would refer to it as "onCreateEvent()".
The EL will put a "get" in front of it, and convert the "o" to "On".

Also if boolean types "get" can magically become "is" ;)

Welcome to the Fold!

Pat.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agree. Capital O. You should follow the indentation and spacing conventions, too. A get method takes 5 lines, one of which is blank. Not 1 line as you wrote.
 
Vinicius Souza
Ranch Hand
Posts: 86
1
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the informations guys.
@Campbell Ritchie, can you give me an example about this five lines ? Thanks in advance!
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Agree. Capital O. You should follow the indentation and spacing conventions, too. A get method takes 5 lines, one of which is blank. Not 1 line as you wrote.


I include a leading blank line where the house style forces me to place the opening brace at the end of a line. My own preference is to place the opening brace by itself on the next line following the method signature. With this formatting I find that a leading blank line is too much white space. I never like to see trailing blank lines before the closing brace.
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The blank line comes after the closing brace (or before the method header). 1 method header, 1 {, 1 return ..., 1 } and 1 blank makes 5.
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, always use spaces, not tabs, for indenting.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell's tips are good, but there are really no "official" naming conventions or coding standards for Java. Almost all Java software seems to use the same naming conventions for classes, variable names, method names etc., following the style of the standard Java library. The placement of braces differs at different places.

The closest to standard code conventions is this old (but still relevant) document: Code Conventions for the Java Programming Language.

At the company I'm currently working at, we put opening braces on the same line. Like this:
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote: . . . At the company I'm currently working at, we put opening braces on the same line. . . .

Most code conventions tell you the same thing, except for one common difference: whether { goes at the end of the line or on a line by itself.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:At the company I'm currently working at, we put opening braces on the same line.


Where I work we do whatever we want , but I've always much preferred that style as well. Both have sensible justifications, in my mind. As long as you don't mix and match!
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They are right to tell Jesper to use a particular convention. You get code awkward to read if you allow people to mix {} conventions.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, well, where I work it's a big enough job to get people to use the same technologies, never mind the same style.
 
Vinicius Souza
Ranch Hand
Posts: 86
1
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot guys. And @Campbell Ritchie, I will use your style because its really a lot clean for me.
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You’re welcome
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic