The Java language is becoming more and more popular because of its power and simplicity. Programmers that want to prove their Java skills by taking Sun's Java certification exam for Java 1.4 platform (SCJP 310-035) can use this material to boost their knowledge.
Read the introduction from my first essay on the subject in order to understand how to use this material.
My experience on passing the SCJP exam may be useful to you. Feel free to take a look.
\/\/\/\/\/\/\/\/\/\/
Answer: ~j = (-j) - 1;
\/\/\/\/\/\/\/\/\/\/
The line:
In order to avoid this behavior only call the method remove() from the iterator.
\/\/\/\/\/\/\/\/\/\/
\/\/\/\/\/\/\/\/\/\/
Answer: No.
Multiple threads with the same name can execute simultaneously.
\/\/\/\/\/\/\/\/\/\/
The class compiles and run without issues. The JLS states that the run function must be public, static, return void and take as parameters an array of strings. The above defined function meets the requirements.
\/\/\/\/\/\/\/\/\/\/
Yes, there will be no compilation error but the compiler will not create a class file. (at least this is the behavior with jdk 1.4)
\/\/\/\/\/\/\/\/\/\/
The code does not compile. It is not allowed to surround the type with parenthesis. You can only surround the object:
\/\/\/\/\/\/\/\/\/\/
No. The length attribute is final. This attribute is assigned when the array is created. Any attempt to modify it will be forbidden by the compiler.
\/\/\/\/\/\/\/\/\/\/
The class name "Short" does not collide with the class java.lang.Short because they are not in the same package.
\/\/\/\/\/\/\/\/\/\/
The method append from StringBuffer directly modifies the underlying object (StringBuffer is *not* immutable).
\/\/\/\/\/\/\/\/\/\/
The code prints "CDummy." then it will throw a NullPointerException. This is happening because text[0] is null and the above code tries to dereference this null value.
\/\/\/\/\/\/\/\/\/\/
Pay attention: the above operation concatenates strings.
\/\/\/\/\/\/\/\/\/\/
The code does not compile ! There is no Byte constructor that takes as a parameter a Byte. This is true for all std wrapper classes: Boolean, Byte, Character, Short, Integer, Long, Float, Double.
\/\/\/\/\/\/\/\/\/\/
Because the string "" is the last in the printed expression the whole expression is converted to a string after the addition of b1 and b2.
\/\/\/\/\/\/\/\/\/\/
Yes. If you try to catch a checked exception (like IOException) from an empty try block the code will not compile. The compiler will issue the following error:
This is happening because IOException is a checked exception. Unfortunately the same check does not apply for a function's "throws" clause that never throws the checked exception that it declares to throw. In our case the function main() declares that it throws the checked exception IOException, yet it is clear that the main() function will never throw that exception.
\/\/\/\/\/\/\/\/\/\/
The code does not compile. Transient variables are not serialized. Local variables are not serialized anyway so it makes no sense to apply this qualifier to a local variable.
\/\/\/\/\/\/\/\/\/\/
No. It is legal to feed the Float constructor with a string ending in 'f' or 'F'.
\/\/\/\/\/\/\/\/\/\/
Answer: using the length() method.
\/\/\/\/\/\/\/\/\/\/
Using the member function someCollection.retainAll(Collection col). This function retains in the original collection someCollection only the elements that are also found in the collection col.
\/\/\/\/\/\/\/\/\/\/
The code does not compile. You cannot have in one source file 2 public classes or interfaces or a mix of them.
If you wish to add something feel free to use the forums.