Hey guys, I'm trying to look up the various conventions for writing classes in Java (and beyond). For anyone equally new to programming, I've been looking at the various coding standards found @ https://ace.apache.org/dev-doc/coding-standards.html
My Question:
For the pros out there, I'm trying to get confirmed where (in Java) I should place constructors. Is it typical to group them all up before or after normal methods? I've seen a lot of people start with constructors.
Here's what I'm thinking right now:
/**
* JAVADOC
*
*/
package gTLD.subdomain.application.package.subpackage.*;
import external package.subpackage.*;
// Class, Interface, Enum and Annotation names: nouns with first letter per word capitalized.
public MyClass extends SuperClass implements Interface {
public static void main(String[] args) {
}
private static final int CONSTANTINE = 123; // All final variables at top of list.
private static String m_goldMember = null; // Other fields. Notice the m_
// Recommend one declaration per line. Encourage commenting and cause less confusion.
// All instance variables at bottom of list.
private int x = 0; // x of something
private int y = 0; // y of something
/* Methods: Verbs with first letter lowercase.
* Vars used and declared within methods must always be initialized explicitly.
* Declare all local vars just before needed.
*/
Constructor (x, y, z) {
}
method (x, y, z) {
}
String toString() {
return stringConcat; // stringConcat: whichever variables concatonated to create the string;
}
}
Feel free to comment on how you personally organize things and what you think is good and bad (e.g. about my code here).
Thanks in advance.