Sunday, October 19, 2008

Declaration Rules

Declaration Rules (Objective 1.1)
  • A source code file can have only one public class.
  • If the source file contains a public class, the filename must match the public class name.
  • A file can have only one package statement, but multiple imports.
  • The package statement (if any) must be the first (non-comment) line in a source file.
  • The import statements (if any) must come after the package and before the class declaration.
  • If there is no package statement, import statements must be the first (noncomment) statements in the source file. package and import statements apply to all classes in the file.
  • A file can have more than one nonpublic class.
  • Files with no public classes have no naming restrictions.

Identifiers

Identifiers (Objective 1.3)
  • Identifiers can begin with a letter, an underscore, or a currency character.
  • After the first character, identifiers can also include digits.
  • Identifiers can be of any length.
  • JavaBeans methods must be named using camelCase, and depending on the method's purpose, must start with set, get, is, add, or remove.

Wednesday, October 1, 2008

JavaBeans Standards

JavaBeans are the Java classes that have private properties. JavaBeans method standards are the standard way to access the properties of JavaBean classes.
We need to know the JavaBeans standard for SCJP in order to select the most suitable naming to access the private properties.

JavaBean Property Naming Rules:
- get/set for the property which is not Boolean type
- get/set or is/set for the Boolean type property
- get/set methods must be public

For example:

public class Foo {
private int iValue;
private boolean bValue;
private String sValue;

public int getIValue() {
return iValue;
}
public void setIValue(int value) {
iValue = value;
}
public boolean isBValue() {
return bValue;
}
public void setBValue(boolean value) {
bValue = value;
}
public String getSValue() {
return sValue;
}
public void setSValue(String value) {
sValue = value;
}

}