wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes setPriority() and labels Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "setPriority() and labels " Watch "setPriority() and labels " New topic
Author

setPriority() and labels

Hussain
Ranch Hand

Joined: Nov 22, 2001
Posts: 110
hi all ,

as i m solving sun_guoqiao mocks a very confusing quest comes
tht is:-
public class Test052
{
public static void main(String args[])
{
int i;
for( i=0; ; ++i) {
if( i > 3 ) break; //1
}
int k = 0;
labelA: { //2
if(k > 0) break labelA;
}
labelA: { //3
if(k < 0) break labelA;
}
}
}
its explanation said tht labels named can be used as long as the overlapp....
plz make me understand.wht she tried to say?
and
Other thing is :--
public class T002 extends Thread
{
public static void main(String args[])
{
T002 t = new T002();
System.out.print(t.getPriority() + " ");
t.start();
t.setPriority(1); //1
System.out.println(t.getPriority()); //2
}
}
this question explanation said tht setPriority() should be uses in order to have some effect ...
i can't undersatnd the above explanation as it also have effect of setPrioirty() before the start() method.
plz help me............

Muhammad Hussain<br />Sun Certified Java Programer (SCJP2)<br />Sun Certified Web Component Devloper SCWCD
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Muhammad,
With out seeing the sentence, I can't say what someone was trying to say. I can however, explain it myself. You seem to be having an issue with the statement labels.
In java, labels are statement specific and not program specific as in C or other languages. What does that mean? Well, it means that the label is only in effect for a single statement. In the case of your example the statement is enclosed in braces:

Once I get out of the statement labelA is no longer a valid label. Therefore I can make use of the same label in another statement.
I can't re-use a valid label while it is valid (i.e., inside its' own statement). Therefore I will get a compiler error trying the following.

Regards,
Manfred.
Hussain
Ranch Hand

Joined: Nov 22, 2001
Posts: 110
thankx sir i m gratefull to Manfred Leonhardt..
 
jQuery in Action, 2nd edition
 
subject: setPriority() and labels
 
Similar Threads
Flow Control
Cannot understand the flow of code...
Can you expailn me the flow..
setPriority(int i) method of Thread
Thread------ getPriority.