• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Three Little Questions

 
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
There is no greater crime than stealing somebody's best friend. I miss you tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic