aspose file tools*
The moose likes Beginning Java and the fly likes By convention - are there for exemple first variables, second getters and setters and third methods? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "By convention - are there for exemple first variables, second getters and setters and third methods?" Watch "By convention - are there for exemple first variables, second getters and setters and third methods?" New topic
Author

By convention - are there for exemple first variables, second getters and setters and third methods?

André Asantos
Ranch Hand

Joined: Nov 23, 2009
Posts: 234
By convention - are there for exemple first variables, second getters and setters and third methods into the class?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Do you mean the order they are in the source file ?


[My Blog]
All roads lead to JavaRanch
André Asantos
Ranch Hand

Joined: Nov 23, 2009
Posts: 234
Exactly...
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Personally, I prefer to have all instance variables at the top, and then methods (getters, setters included). I think it's the way it's done most of the time.

You can refer to the Code Conventions for the Java Programming Language.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

I usually use the following order:
1) static fields
2) instance fields
3) constructors
4) methods


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
I usually use the following order:

instance variables
final instance variables
static variables
final static variables
Constructors
Methods, in alphabetical order

John.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

John de Michele wrote:Methods, in alphabetical order

Why in alphabetical order? The Javadoc does that for you. I prefer to keep them together based on functionality. For instance, each getter and setter are put together, in the same order as the order of their matching fields; getter before setter.
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Rob Prime wrote:Why in alphabetical order? The Javadoc does that for you. I prefer to keep them together based on functionality. For instance, each getter and setter are put together, in the same order as the order of their matching fields; getter before setter.


Just a personal preference. I find it more aesthetically pleasing to have methods in alphabetical order. I can see the value of your method, but at an aesthetic level, it just feels disordered to me. For the record, all of my variables are organised in alphabetical order in each group, too .

John.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: By convention - are there for exemple first variables, second getters and setters and third methods?