Java naming conventions
This is a short summary of Sun's Java naming conventions.
I think the most important code convention in Java is the naming convention. These easy naming conventions make programs more understandable by making them easier to read.
Naming conventions
- Classes and interfaces
- Class and interface names should be nouns, in mixed case with the first letter of each internal word capitalized.
/* classes and interfaces example */ class Circle; class CenterPoint; interface Storing;
- Methods
- Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized.
/* methods example */ start(); setName(); getColor();
- Variables
- Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters.
/* variables example */ int i; String name; Circle snowmanBody;
- Constants
- Constants should be all uppercase with words separated by underscores ("_").
/* constants example */ static final int COLOR_DEPTH = 24; static final int CHESS_TABLE_WIDTH = 8; static final int MAX_VALUE = 10;
Read more about Java code Conventions here:
Code Conventions for the Java Programming Language







-able generally implies it's an interface. (Serializable etc). In this case it's defining a capability of an Object. (or rather, you can do something to an object).
If a bunch of classes is an Something-er, it implies that there's a interface at the top of the hierarchy. Eg, PrintWriter implements Writer. This also lets you swap in different implementations instead of rewriting your code to do different things. Once you start using Dependency Injection, the value of this will become clearer.
I'm personally not a fan of the IInterface/ImplementationImpl way. Javadocs will tell you if it's an Interface. The name of the implementing class should give some idea of how the implementation works. Eg, RMIClassLoader uses RMI, URLClassLoader uses URLs and so on.
- reply
Submitted by tunaranch (not verified) on March 18, 2008 - 2:50am.Whats your take on interface naming conventions, I have seen so many different ones.
I
- reply
Submitted by Visitor (not verified) on March 17, 2008 - 8:05am.I think the I prefix is very suggestive. For example:
interface ILoadable.This is good idea, but need document it on developer's documentation like interface prefix.
- reply
Submitted by Joey on March 17, 2008 - 6:08pm.Post new comment