Win a copy of Rust Web Development this week in the Other Languages forum!

Yun Hao

+ Follow
since Nov 19, 2004
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 Yun Hao

I just took the exam yesterday. I got very good score 98%. I got 60 questions correct out of 61. I want to thank Javaranch which is great place for me to find any answer. I want to thank all those whoever answered my questions. I want to thank Kathy Sierra and Bert Bates who wrote the book Sun Certified Programmer & Developer for Java 2 Study Guide (Exam 310-035 & 310-027). It is a very good book to refresh my knowledge on Java and got the key points for the exam.
Most of all, I want to thank Dan Chisholm. His mock exam is really wonderful. I did all his 20 comprehensive exams. The questions he provided covered almost everything. By doing his exams, you can find what you were missing during the preparation and what you misunderstood. When I did his first exam, I got 61%, when I did his last few exams I got several 98%. It not only helps you understand each topic and also gives you confidence to take the exam. I very appreciate. And also recommend whoever is going to take the exam try to finish all his exams.
By the way, I am not Java Programmer. All my knowledge in Java I got from colleage few years ago. I spent one month to prepare the exam. So the book and Dan's mock exam questions really helped me a lot.
Thanks all of you again!
17 years ago
Is there any ono who took the exam can tell me the exact time for the test? I mean the time for answering the 61 questions? whether the computer only starts to record the time when I start the first question? I know there is tutorial and survey questions during the test, whether it will be counted into the exam time?
Thanks in advance
see the code below:
1. int i=Integer.valueOf(s).intValue();
2. double d=Double.valueOf(s).doubleValue();

if s is null value, run statement 1 will get NumberFormatException, it will be the same for all integer type wrapper class.
if s is null value, run statement 2 will get NullPointerException.
I don't know why they have two different exceptions. but if s is non number string, all of them will get NumberFormatException which is understandable.
Thanks Permil. I want to be much clearer. You are saying that no object is eligible for garbage collection after line 2. Is that what you mean? This is what I thought first. Because "My String" is in the string literal pool.If I change the line 1 to s1=new String("My String"); after line 2, I think one object is eligible for garbage collection.

The answer should be a, c , d, e. Explain below:
in method m1(), it created three local variable a1,a2,a3. a0 points to the same object as a3 first. when you ran the for loop a0 will point to in the order of object A1,A2,A3,A1. so the output for sure will have A1A2A3A1. afer m1() returns, those local reference variable a1,a2,a3,a0 expired, so the objects they point to are eligible for collection. then run System.gc(), Remember running System.gc() just requires JVM to collect gargabe. it is not guranteed whether it will collect or not and in which order it will collect. Although there are three objects eligible to collect, it may collect one or two(answer c) or three ( answer d, e) or none( answer a) of them.
Suppose in the code, we have statement like this:

1. String s1="My String";
2. s1="Another String";

my question is after line 1, whether there is object created? After line 2, whether there is object eligible for garbage collection?
I am going to take the exam 2 weeks later. I tried Marcus Green's Mock Exam1. I found there are almost 20% questions about GUI and IO like file system accessing. When I prepared my exam, I didn't spend time on these two parts. Because I used Kathy Sierrs's book Sun Certified Programmer & Developer for Java as my study guide. It didn't cover these two parts for the programmer exam 310-035. I read the objectives of the exam from sun website, it looks like not test these two parts also. I am not sure about that. Is there anyone who knows that for sure whether the current exam 310-035 (Sun Certified Programmer for the Java 2 Platform 1.4) tests these two parts or not. I am scared because I am going to take the exam soon and that two parts are relatively new to me and maybe hard for me to completely get through in a short time.
Very appreciate if any one who knows that and replys me soon.
Thanks Barry. I am using jdk1.4.2. It looks like only new version jdk gave the compile error. I am going to take the Certification Exam. So I think if there is question like that in finally clause there is throw statement, I should choose compile fails.

Just to confirm, Premkumar and Nitin, by any chance if you check the message, can you tell me which jdk version you used to compile the code since you both didn't get any warning or error. Thanks in advance.
"this" refers the instance of current object, like a reference refers an instance of a object or class. In your code, you used which is class name followed by a member, in java you can only access a static member by using class name. Althouth reference veriable can access both static and non static member. That is why you got the error.

If you change your code to make id as static, it will work fine.
The way you did by removing OuterTest, it worked fine because id refers the member in your InnerTest which is inherited from OuterTest. So if you use id or, it refers member id of InnerTest, it will give you result "Default". If you use, it refers member id of OuterTest, you can know the result will be STP
Very interesting. I tried the code Nitin Bhagwat put again. I still got the same compiler error "finally clause could not complete normally". In theory, it should not have such compiling error since the exception already declared. I am using javasdk1.4.2_04 running on windows2000, the command line i typed javac
It is very strange same code got two different results. Is there anything wrong with my command although i don't think so.
can anyone else try this code again to see whether you get compile error or it is working okay for you also.
Look at following example:
class MyException extends Exception{}

//some other codes here-----
public void myfirst() throws MyException{ //line 10
}catch(MyException e){
} finally{
throw new MyException(); //line 15
}//end of myfirst

public void mysecond () throws MyException {
}//end of my second

//----rest of the other code

my question: if we compile the code, we will get compile error to say that finally clause line 15 could not complete normally. Why this happens? I already declare throws MyException in method myfirst(). however if I put
mysecond(); instead which throws MyException, it works fine. Does it mean I can not put an explicit throw in finally clause even the exception is declared in the method?