James Quinton

Ranch Hand
+ Follow
since Oct 02, 2006
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 James Quinton

JLS is lengthy and wording.
it's not necessary for passing scjp. I spent 1 month on study guide and did couple of mock exams and passed scjp5 with 89%
i used jls for reference purpose only if I have doubts on any specific items. It's more like a dictionary to me.
I lost my SCJP5 certificate after moving to my new place.
I am wondering if it's possible to get a replacement?
Hey guys, I don't think Mark Cade's Study Guide has a legal version of eBook.
Please respect the copyright.
I just cleared the exam this morning with 88%, not a bad score.
But I was hoping to get 90%. My weakest part API only getting 70%.
Anyway, I am glad to pass and going to move forward.
13 years ago

Originally posted by Keith Lynn:
Except for leaving out the phrase in B, that is the exact output you get if you interpret B.

Why do you think it doesn't make sense James?


the phrase "in B" is what I meant "doesn't make sense".
in exam, as soon as I saw this kind of thing, I chose the easiest answer and went to the next one.

Originally posted by Jothi Shankar Kumar Sankararaj:
James, it does make sense. From this one example above, you get to know the flow how classes get loaded and how instance variables gets initialized. Good to bring up this question here.



it doesn't make sense with this output:
AAA
Bvar=0
BBB
Bvar=2222
Avar=0


guys, look at it close, very close.
[ November 20, 2006: Message edited by: James Quinton ]
maybe I am too picky, Keith.
But compare your output, the original output doesn't make sense.
are you sure you gave the correct code sample?
your output doesn't make any sense at all.

Originally posted by Jim Yingst:
In the code you just quoted, s1 and s2 refer to two different objects, "123" and "456". However in the original code, both s1 and s2 refer to the same object, "123". That's how Java handles String literals (and String constant expressions). Two literals / constant expressions that have the same content will be made to refer to the exact same instance. There are some very subtle exceptions involving multiple classloaders, but let's skip that for now.



ok, then. Let me put this way:
class MyThread extends Thread{
String s;
public void run(){
synchronized(s){
//something here
}
}
public MyThread(String s){
this.s=s;
}

public static void main(String[] args){
String s1="123";
String s2="456";
new MyThread(s1).start();
new MyThread(s2).start();
}
}

will the above "something here" will be synchronized?

Originally posted by Jim Yingst:
[James]: Does that imply if s1 and s2 have different value such as:
String s1="123";
String s2="456";
The code will not be synchronized?


No. The code will be synchronized, period, because the code uses the synchronized keyword - as you see in the code. That's just terminology. But what's important here is that the code is synchronized on a particular object (or two particular objects) known as the monitor - the object whose lock is acquired for synchronization.



Jim, we have two instances of MyThread class here, not just one.
I know what does "synchronized" mean on a particular object. But here we have reference s1 and s2 being used by two different threads. I guess the underlying question is: are s1 and s2 referring to one object?
[ November 20, 2006: Message edited by: James Quinton ]

Originally posted by Jim Yingst:
The code will be synchronized in either case, in the sense that the code uses synchronized blocks to acquire locks, as you can see from looking at the code. However if the two MyThread instances are synchronized on two different String instances (two different values of s) then the synchronization will have no significant effect - the two method calls may run concurrently. But if the two MyThread instances are synchronized on the same String instance, then the two run() methods may not run concurrently. Or more precisely, the synchronized blocks within the run() methods may not run concurrently.


what are you talking about? I am totally out of mind
I found a mock question like this:

class MyThread extends Thread{
String s;
public void run(){
synchronized(s){
//something here
}
}
public MyThread(String s){
this.s=s;
}

public static void main(String[] args){
String s1="123";
String s2="123";
new MyThread(s1).start();
new MyThread(s2).start();
}
}

The answer of the question explains that two thread created will be synchronized and waiting each other on "synchronized" part because s1 and s2 are pointing to same string object the pool.

Is that true? Does that imply if s1 and s2 have different value such as:
String s1="123";
String s2="456";
The code will not be synchronized?
It is a very nice question helping you understand that each Object has its only lock. However, this kind of code is practically useless, it's for academic purpose only.

Originally posted by kay lin:
what exactly do you mean by "more specific" sorry I am sitll not clear on that..



you can understand "more specific" as "narrower", or "closer".
In you code example, float is narrower than double. Hence, float is closer to int and long.