In Java code conventions, the instance variables should be placed before the methods or after the methods? I know, in the code convention of Oracle or Apache, they recommend the instance variables should be placed before the methods. However, in the book of Core Java, the authors place the instance variables after the methods. Hmm…maybe because of my C++ background, during my learning C++, I am educated that public functions should be placed before private members, because people care more about the functionality your code provide. Therefore, I want to know which is preferred way? If you can explain your reasons using your experiences of practical projects, that’s better.
In Java code conventions, the instance variables should be placed before the methods or
Share
The normal Java convention is to put static variables first, instance variables, followed by constructors, and then the methods last.
You can always find people / books that don’t follow the normal conventions.
See above.
No reason, apart from the fact that this is the accepted normal way of doing it, and writing code that goes against the normal conventions tends to make it less readable … for people who follow the normal conventions.
It is possible that someone has done some empirical studies of code readability in which they measured relative readability. But I’ve never bothered to search them out.