aspose file tools*
The moose likes Beginning Java and the fly likes A silly question about naming convention Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A silly question about naming convention" Watch "A silly question about naming convention" New topic
Author

A silly question about naming convention

Vinicius Souza
Ranch Hand

Joined: May 18, 2011
Posts: 45

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!


Java is the best (I love C too) heehhh
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
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

Joined: May 18, 2011
Posts: 45

Thanks for the informations guys.
@Campbell Ritchie, can you give me an example about this five lines ? Thanks in advance!
dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
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
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
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
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
Also, always use spaces, not tabs, for indenting.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14150
    
  18

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:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
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.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4392
    
    8

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
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
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

Joined: Apr 06, 2010
Posts: 4392
    
    8

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

Joined: May 18, 2011
Posts: 45

Thanks a lot guys. And @Campbell Ritchie, I will use your style because its really a lot clean for me.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
You’re welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A silly question about naming convention