In order to prepare for any exam it is very useful to try to answer to questions related to the exam material (assuming that you have a solid theoretical base). This technique has proven to be very efficient for me for at least 3 reasons:
Recently, I passed Sun's Java certification exam for Java 1.4 platform (SCJP 310-035). As part of my preparation effort I wrote a lot of material that could be useful for other test takers. As my spare time will allow, I will post the material on my web site.
Before using this preparation material please read below:
Feel free to write me if you find any omissions, errors or if you have something interesting to say about this extensive subject: "Java certification". Best of luck with your exam preparation !
\/\/\/\/\/\/\/\/\/\/
The code does not compile. The literal 4096L is of type long so a possible loss of precision can occur when converting to int.
\/\/\/\/\/\/\/\/\/\/
32767
The code compiles because the compiler is smart enough to compute that the number 32767 will fit in a short. A quiet conversion from int to short takes place.
\/\/\/\/\/\/\/\/\/\/
The code does not compile: a char cannot be used to initialize a String
\/\/\/\/\/\/\/\/\/\/
No. The Unicode representation is translated to new line by the *compiler* which breaks the code. The escape sequence '\n' is not translated by the compiler but by the runtime code which makes this approach OK.
\/\/\/\/\/\/\/
\/\/\/\/\/\/\/\/\/\/
b. The pre/post increment operator cannot appear on the left side of an expression.
\/\/\/\/\/\/\/\/\/\/
a += a++; // here a = 2 + 2; the incrementation a++ is LOST;
\/\/\/\/\/\/\/\/\/\/
Answer: b
The + operator operates on integers. The byte operands are converted to int prior to execution, thus the result of the addition is an int. An explicit cast (from int to byte) is required in order to compile the code.
\/\/\/\/\/\/\/\/\/\/
Answer: b
\/\/\/\/\/\/\/\/\/\/
Answer: b (you cannot compare NaN values; the only way to detect those is to use the function Float.isNaN(x))
\/\/\/\/\/\/\/\/\/\/
Yes.
\/\/\/\/\/\/\/\/\/\/
Answer: a
\/\/\/\/\/\/\/\/\/\/
line2 (this operator can only be applied to int)
\/\/\/\/\/\/\/\/\/\/
Answer: false, true
\/\/\/\/\/\/\/\/\/\/
8,0
The first shift is effectively by 1 because only the first 5 bits are considered when shifting the second shift is by 31 positions (the codification of -1 is 11111111111111111); as a result all the bits are shifted out => the result is 0
\/\/\/\/\/\/\/\/\/\/
Answer:c. The ternary operator ?: has higher precedence that the assignment operator.
\/\/\/\/\/\/\/\/\/\/
"x1 is equal with x2". Obviously, the references x1 and x2 point to the same object while the x3 reference points to some other object.
\/\/\/\/\/\/\/\/\/\/
The void return type is missing from the 'main' function signature.
\/\/\/\/\/\/\/\/\/\/
Yes. The use of brackets {} is not compulsory.
\/\/\/\/\/\/\/\/\/\/
'longL1 is NOT equal with intI1' (this is happening because the equals method tests to see if the parameter received is an instance of a 'Long' - 'Integer' is not an instance of a 'Long')