It is never legal to include the size of the array in your declaration. Yes, we know you can do that in some other language, which is why you might see a question or two that include code similar to the following:
int[5] scores;
The preceding code won't compile. Remember, the JVM doesn't allocate space until you actually instantiate the array object. That's when size matters.
Refrence: SCJP Sun® Certified Programmer for Java™ 6 Study Guide Exam (310-065)
Look for interface difinitions that define constants, but without explicitly using the required modifiers. For example, the following are all identical:
// Looks non-static and non-final, but isn't!
public int x = 1;
// Looks default, non-static, non-final, but isn't!
int x = 1;
// Does't show public or final
static int x = 1;
// Doesn't show public or static
final int x = 1;
// Doesn't show final
public static int x = 1;
// Doesn't show static
public final int x = 1;
// Doesn't show public
static final int x = 1;
// What you get implicitly
public static final int x = 1;
Any combination of the required (but implicit) modifiers is legal, as is using no moddifiers at all! On the exam, you can expect to see questions you won't be able to answer correctly unless you know, for example, that an interface variable is final and can never be given a value by implementing (or any other) class.
Refrence: SCJP Sun® Certified Programmer for Java™ 6 Study Guide Exam (310-065)
The objective says you have to know legal identifiers only for variable names, but the rules are the same for ALL Java components. So remember that a legal identifier for a variable is also a legal identifier for a method or a class. However, you need to distinguish between legal identifiers and naming conventions, such as the JavaBeans standards, that indicate how a Java component should be names. In other words, you must be able to recognize that an identifier is legal even if it does't confirm to naming standards.
If the exam question is asking about naming conventions - not just whether an identifier will compile - JavaBeans will be mentioned explicitly.
Refrence: SCJP Sun® Certified Programmer for Java™ 6 Study Guide Exam (310-065)
- Your Java programs should always end with the .java extension.
- Filenames should match the name of your public class. So for example, if the name of your public class is Hello, you should save it in a file called Hello.java.
- You should write comments in your code explaining what a certain class does, or what a certain method do.
- In creating blocks, you can place the opening curly brace in line with the statement, like for example,
public static void main(String[] args){
or you can place the curly brace on the next line, like,
public static void main(String[] args)
{
You should indent the next statements after the start of a block, for example,
public static void main(String[] args){
System.out.println("Hello ");
System.out.println("world");
}
- For names of classes, capitalize the first letter of the class name. For names of methods and variables, the first letter of the word should start with a small letter. For example:
ThisIsAnExampleOfClassName thisIsAnExampleOfMethodName
- In case of multi-word identifiers, use capital letters to indicate the start of the word except the first word. For example, charArray, fileName,ClassName.
- Avoid using underscores at the start of the identifier such as _read or _write.
- In defining a long value, a lowercase L is not recommended because it is hard to distinguish from the digit 1.
- It always good to initialize your variables as you declare them.
- Use descriptive names for your variables. Like for example, if you want to have a variable that contains a grade for a student, name it as, grade and not just some random letters you choose.
- Declare one variable per line of code. For example, the variable declarations,
double exam = 0;
double quiz = 10;
double grade = 0;
is preferred over the declaration,
double exam = 0, quiz = 10, grade = 0;
- Use the while loop to iterate indefinitely through statements and to perform the statements zero or more times.
- Use the do/while loop to iterate indefinitely through statements and to perform the statements one or more times.
- Use the for loop to step through statements a predefined number of times.
The basic using of Enum should be like following:
public enum SimpleColor {
RED,
GREEN,
BLUE
}
public static void main(String[] args) {
for (SimpleColor sc : SimpleColor.values()) {
System.out.println(sc);
}
}
In addition, you may also using it as following:
public enum ComplexColor {
RED ("Red", "0XFF0000"),
GREEN ("Green", "0X00FF00"),
BLUE ("Blue", "0X0000FF");
private String title;
private String rgb;
ComplexColor(String title, String rgb) {
this.title = title;
this.rgb = rgb;
}
public String title() {
return title;
}
public String rgb() {
return rgb;
}
}
public static void main(String[] args) {
for (ComplexColor cc : ComplexColor.values()) {
System.out.println(cc.title() + " - " + cc.rgb());
}
}
so, you can have more information on it.
Java, JavaScript, HTML, XHTML, AJAX, CSS, etc.