Ambapali Pal

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

Recent posts by Ambapali Pal

You should get it.
What is your answer ?
The question is
----------------
class A extends Thread {
public void run() {
try {
synchronized (this) {
wait();
}
} catch (InterruptedException ie) {
System.out.print(interrupted());
}
}
public static void main(String[] args) {
A a1 = new A();
a1.start();
a1.interrupt();
}
}
is it possible that before a1 has got the opportunity to run, a1.interrupt is called?
------
Yes it is possible .
------------
in that case what wud happen for the wait called in run() method and the out put for as a result?
----------
In that case wait() method will retun immediately and exception will be handled.Since you used System.out.xxx in the exception handling section(exception handling will clear the interrupt status first),
System.out.print(interrupted());
it will result "false".
If the code looks like following, the result would have been "true " followed by "false".
class A extends Thread {
public void run() {
try {
synchronized (this) {
System.out.print(isInterrupted());
wait();
}
} catch (InterruptedException ie) {
System.out.print(isInterrupted());
}
}
public static void main(String[] args) {
A a1 = new A();
a1.start();
a1.interrupt();
}
}

Note : interrupted() clears the interrupt status after its call. So calling it twice for a interrupted thread will result "true false" isInterrupted() does not clear the interrupt status.
You can excute this few times, you will see the result yourself.
Ambapali

class CompilTimeConst{
public static void main(String[]arg){
int k;
int j=2;
final int n = j;
if (n == 2)
k = 3;
// k is not "definitely assigned"
System.out.println(k);
}}


In this case n is blank final variable which is not a compile time constant. n will actually get the value at the run time depending upon whatever the value of the j.
But if you try this way it will compile.

class CompilTimeConst{
public static void main(String[]arg){
int k;
final int j=2;
final int n = j;
if (n == 2)
k = 3;

System.out.println(k);
}}

Also one more point about the the local final variable is that you can keep it blank if you do not use it. Just like othet local variable.
Hope it helps a bit.
Ambapali
So, If understand it correctly , a daemon threda has to be explicityly set by the developer. On it's own none of threads sstarted by the system are daemon threads?
If one daemon thread creates another thread then that will also be a daemon thread.
watch for the following from Thread API


Every thread has a priority. Threads with higher priority are executed in preference to threads with lower priority. Each thread may or may not also be marked as a daemon. When code running in some thread creates a new Thread object, the new thread has its priority initially set equal to the priority of the creating thread, and is a daemon thread if and only if the creating thread is a daemon.


------------------
Every time a thread dies,The JVM looks at the remaining threads to see whether any of them is a user thread.If only daemon threads are left,the JVM terminates.
You are right. So there is no guarantee that the Daemon thread will get a chance to run. The life of Daemon depends on the user thread of the program.
Ambapali
Congratulation !!!

While reclaiming yourself you may feel missing something
Ambapali
17 years ago
Thanks a lot for the wishes.
And also thanks to everybody in the Certification forum for helping me getting confidence quickly through question/answer , dicussion, doubt clearing. This site is really very useful for preparation.
Bert, about the GC I have no idea why I got 66% since the questions were very very basic and simple. Still now I am sure that I have done 100% correct if not my eyes ditched myself while reading them. I was expecting some answers to go wrong in Threads as they were quite tough and toughful. But I got 100% there.
About the Collection classes Dan is right. Kathy's book is perferctly enough for this.
For Math class's methods(mentioned in the objectives), it is better to know the boundary condition(specail cases) return values which you will get in API. That is my feeling after going through the Dan's topic exams.
For String and StringBuffer you need to know the very common methods and whatever you come across in the different mock exams to be well prepared. But the most inmportant thing here is to know when it is returning/pointing to the new string and when it is not. So you have to know the methods keeping the string immutability in mind .
One more tips is be very very clear about threads. As I mentioned before the questions are tough here.This chapter is very good in Kathy's book in describing the basics. Only thing missing there is Daemon thread and related methods in Thread class.
Thank you once again,
Ambapali
17 years ago
Thanks Corey and Dan Chisholm for your suggestion.
About yoour question Dan Culache , are you really talking about containers. Thay are not there in 1.4 exam. If you are preparing for 1.2, then I will say that I donot know.
But if you are talking about collection classes. It is just enough to read basic type of collection interfaces and classes as a point of selecting them in different situation. The methods are not important. Collections are very good in Kathy's book, if you have one.
Bye the way, I just gave the 1.4 exam (passed with 95%) and did not get any tough/rare question on API.
Ambapali
Yeah I tried both of them . 1st one compiles fine and 2nd one does not. I was confused by the Sybex Java Certification 1.2 book, which says that a class cannot have same name as the package. I did not check their errata yet.
Thank you ,
Ambapali
Hi All,
I am just back from the exam center and so excited to get 95% score.
There were lots of loop question. And yes I got the lowest score in Garbage Collection.
I started with Sybex 1.2 book(which is not enough),followed by Dan's exam (not all), Kathy's book, and other mock exams.
I browse through few chapters in Mughal/Rasmussen in the book store.
Thank you,
Ambapali
17 years ago
I have 2 questions regarding this.
1. Can a class have same name as the package included in the package statement ?
2. Can any kind of nested or inner class wheather inside or outside method have same name as the nesting class ?
Thanks in advance.
Ambapali
Thanks Bert and Kathy.
Good to get it today since I am set to go for exam tomorrow (till now). Ofcourse I have till 8 more hrs to change my mind.
Please wish me luck .
Ambapali
Yeah, I dodnot know why but where ever only int type is allowed, it does not take any long even though it is final.
For another example switch statement which only allow int or anything which can be implicitly promoted to int.

int i = 1;
final long b = 1;
switch(i){
case(b)://something
case 2:// something
}
OR
switch(b){
case 1://something
}
None of them compiles.
So I just take it granted that where only int is allowed, no final long or no long literal is allowed.
Hope I am correct.
Ambapali
Can anybody suggect me how much of the API I have remember .
Java Programmer 1.4 Exam objectives 8.X mentions about the methods of Math and Wrapper classes but does not mention the method of the String and StringBuffer class.
Does the exam expects to memorise all the methods of the String and StringBuffer class ?
It is sufficient to read only the mentioned methods of the Math and Wrapper classes ?
Thanks in advance.
Ambapali
I also think that there will only one object in the String pool and total two object will be there one in non-pool memory and one in the pool.
3nd line should not create any object in the pool as the same object exists there alreay.
Even if you call s3.intern() after , that also will not create a new string in the pool for the same reason. It will just point to the existing the object in the pool.
So (s2==s3.intern()) returns true. You can test it.
The API documentation says
"When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned. "
In my opinion creating same object in the string pool more than once violates the concept of the string pool.
I donot know what expert says about it.