John Paverd

Ranch Hand
+ Follow
since Nov 17, 2002
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by John Paverd

Sounds like you deserved to get 100%, but I didn't. I chose the wrong answer on a question about unreachable code.
Thanks, all.
16 years ago
If a base class has a method defined as
void method() { }
Which of the following are legal prototypes in a derived class of this class. Select the two correct answers.
A. void method() { }
OK. This is a legal override.
B. int method() { return 0;}
Invalid. You can't change the return type when you override a method.
C. void method(int i) { }
OK. Since the parameter list is different, method is being overloaded, not overridden.

D. private void method() { }
Invalid. You cannot narrow access to methods when overriding them.
[ March 03, 2003: Message edited by: John Paverd ]
I finally took the exam today. It feels good to be done! I learned a lot from participating in the JavaRanch Programmer Certification forum. Thanks to all who posted questions and answers.
The hardest part of preparing for this exam was not learning Java. I had problems memorizing stuff, and kept getting test questions wrong even though I knew the basic material. Taking your suggestions to make flash cards solved the first problem. Taking lots of mock exams solved the 2nd. Dan Chisholm's exams fit the bill here! Practice makes almost perfect
I didn't get the "Kathy and Bates" book(or is that the Sierra and Bert book?)until I was already familiar with most of the material for the exam, but I still found it very useful. The book is very focused on teaching you what you need to know for the exam. The exam watch notes explain all the ways that the examiners will try to trick you. The review questions are very similar to the ones on the real exam.
Some exam taking tips:
As the HitchHiker's Guide to the Galaxy said, Don't panic! 2 questions out of the first 3 were the hardest on the test. There were a lot of easier questions after that, and I had time to go back and review the questions I was unsure about. If you have time left, I recommend that you review all your answers. I found that I had checked the wrong answer for one of the easier questions.

The question I got wrong was in the Flow control, assertions, and exception handling section. I got all the Threads and GC questions right, and then missed an easier one!
Thanks, JavaRanch.
16 years ago
float f = 1/3;
The type of an expression is determined by the types of its operands. In the expression 1 / 3, both operands are ints, so integer division is used, and the resulting value is an int, 0. On assignment, the int 0 will be promoted to the type of the assigned variable, which is float. Therefore f == 0.0f.
Here are some different scenarios to help reinforce the concept:
float f;
f = 1f / 3;
f = (float)1 / 3;
f = (float) ( 1 / 3);
f = 1.0 / 3;
Not all of them will compile.
Here is a link that explains in more detail the information that Dan and I gave to you: Sun Java documentation on assertions
You must use a special switch to compile code that contains assertions:
javac -source 1.4
In future versions of Java assertions may be enabled by default, but as of JDK 1.4 you must explicitly enable the compilation of assertions. This was done to allow code that compiled under previous versions of the JDK to compile under JDK 1.4.
[ February 27, 2003: Message edited by: John Paverd ]

Originally posted by leandro oliveira:
but does it explains why the following is not true???
(""+ch).equals(new StringBuffer("").append(ch))==false;

(i did not understand)

This statement tests if a String is equal to a StringBuffer. According to the API for String.equals,

Compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.

So this comparison will always return false, even if the String and StringBuffer contain the same character sequences.
The strict answer to the question is that the garbage collector could be invoked at any time by the JVM.
I think that the question should be: What is the first line after which an object created in main is eligible for garbage collection? (I'm also assuming that object is a valid class defined elsewhere.)
The answer I would give is "After line 6", because after line 6, the object created in line 5 is no longer referenced.
However, the object created in line 4 will only be eligible for garbage collection after line 8, when both variables no longer refer to it.
[ February 24, 2003: Message edited by: John Paverd ]
The wrapper classes are immutable: Byte, Short, Integer, Long, Float, Double, Character, Boolean, Void. Once you have constructed a wrapper object, you cannot change the primitive value that it contains.
Please see this IBM developer works article, which defines an immutable object as one whose externally visible state cannot change after it is instantiated. Under that definition, I would not consider an array to be an immutable object.

Originally posted by Gurucharan Murudeshwar:
Hello All,
Generally, we use the static methods by saying
But here, the instantiation itself triggers the println line.

When you type "java TestStatic" on the command line, the JVM will load the TestStatic class and will execute the static main method: TestStatic.main(args). It is this that causes the static initializer to be executed, not the instantiation of an instance of TestStatic. This can be verified by adding some printlns to the code:

The output is:
This is strange !!!
Before instantiation
After instantiation
As soon as an object is not accessible from a live thread, it will be eligible for garbage collection, even if other objects that are also eligible for garbage collection refer to the object.
Please read this topic, which shows an example of objects which refer to each other, but are still eligible for GC.
[ February 12, 2003: Message edited by: John Paverd ]
How do you indicate that you are finished taking the exam, and wish to submit it for grading? Do you have to go through all the questions before you can do that?
I wake up screaming from nightmares where I accidentally submit the exam for grading before I've even answered the first question
No, not really, but I'd like to know.

Originally posted by leandro oliveira:
ok!!! so I can't define an abstract method to be strictfp!!! but by declaring the abstract class or interface as srictfp only the variables will be strictfp!!! and none of the abstract methods will be strictfp!!! (is this true???)
when you declare a strictfp class, all the methods, that are implemented,and variables in it will be strictfp!! (is it true???)

In addition to what Sarma said, please note that variables cannot be strictfp, only expressions can be strictfp. Declaring a class or method strictfp means that all expressions within the class or method are FP-strict, not the variables.
If you want to know exactly what FP-strict means, you can read Sections 4.2.3 and 15.4 of the JLS, but that is probably way more than you need to know for the exam.
When I compiled this under JDK 1.4.1, I got the following error:
test/ [9:1] illegal combination of modifiers: abstract and strictfp
abstract strictfp float myMethod(float a);
An abstract method cannot enforce a particular implementation of itself, other than that the return type and signature must match, and the access modifier and exception specification be compatible.
Modifiers such as synchronized, native or strictfp are specific to the implementation of the abstract method, and cannot be specified when you declare an abstract method.