Java classes are generally divided into logical \"blocks\". Is there a convention to mark these sections? Ideally, it would be supported by the major IDEs.
I personally
As far as I know there is no such thing as a supported specification for grouping class members together. You can use what-ever comment convention you like, but chances are it will not be supported by any tool.
It is better to group related members into separate class via inheritance or aggregation. This is considered a good OOP style
I personally use 80-chars line separators, like this :
public class Client {
//================================================================================
// Properties
//================================================================================
private String name;
private boolean checked;
//================================================================================
// Constructors
//================================================================================
public Client() {
}
public Client(String name, boolean checked) {
this.name = name;
this.checked = checked;
}
//================================================================================
// Accessors
//================================================================================
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isChecked() {
return checked;
}
public void setChecked(boolean checked) {
this.checked = checked;
}
}
Of course, this may seem a bit overkill for such a small POJO, but believe me, it proved very useful in some huge projects where I had to browse through big source files and quickly find the methods I was interested in. It also helps understand the source code structure.
In Eclipse, I have created a set of custom templates (Java -> Editor -> Templates in Eclipse's Preferences dialog) that generate those bars, eg. - sepa (SEParator for Accessors) - sepp (SEParator for Properties) - sepc (SEParator for Constructors) - etc.
I also modified the standard "new class" template (Java -> Code Style -> Code Templates in Eclipse Preferences screen)
Also, there is an old Eclipse plugin called Coffee-bytes, which enhanced the way Eclipse folds portions of code. I don't know if it still works, but I remembed one could define arbitrary foldable zones by adding special comments, like // [SECTION] or something. It might still work in recent Eclipse revisions, so take a look.
For IntelliJ i do like:
public void ________________INIT__________________() {};
looking pretty in file structure!
I liked that also when i was using xcode. For eclipse i use ctrl+o (quick outline) to navigate through a Java class.
If you can cluster your methods, do another class specifically for that concept that you want to capture in a section. Go ahead, creating files is free.
I would use javadoc; or use the following as a simple "separator" (single or 3 lines):
/** RecyclerOnItemClickListener */
/**
* RecyclerOnItemClickListener
*/
So that in IDE it appears in a different color other than the unobtrusive commented grey.