File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Three Little Questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Three Little Questions" Watch "Three Little Questions" New topic
Author

Three Little Questions

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
All the three questions originates from practicing the JQPlus mock exam:
1. Daemon thread never stops. (True?)
2. Can a user thread stop a daemon thread? (False?)
3. I thought that a transient variable cannot be final and a transient variable cannot be static. However,
public final static transient int i = 10;
does not give compilation error. Is my concept on "transient" wrong?
Amond Adams
Ranch Hand

Joined: Nov 28, 2000
Posts: 62
1. Daemon threads do not Stop (false) JVM exists when no user threads are running and it does'nt care to wait for Daemon threads, stoping them as it exists.
2. A user thread can stop a daemon thread. (true)
Consider the following piece of code....
class D{
public static void main(String[] args){
DT t1 = new DT();
t1.setDaemon(true);
t1.start();
try{
Thread.sleep(1);
} catch(Exception e){}
t1.stop();
System.out.println("Done...");
}
}
class DT extends Thread{
public void run(){
for(int i=0; i<100;i++) System.out.println(Thread.currentThread().getName() + " says " + i);
}
}
Run the code and observe....
3. yes you can declare a variable to be final static transient int i
Perhaps you mixed it up with volatile where volatile variables cannot be final and vice versa, but they can be static.
Santhosh Kumar
Ranch Hand

Joined: Nov 07, 2000
Posts: 242
there is another catch here. Interface member variables can't be volatile. Because variables defined in Interface are by-default static and final. But volatile variables can't be final. So volatile variables are not allowed in interfaces.
Santhosh.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Three Little Questions