Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Another question from javacross simulation!

 
Noel Hinders
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
here is a question from http://www.javacross.com simulation please help me for a solution.
Q].You are updating some data and is result of some calculations. When your thread performs an integer division by 0 causing an ArithmeticException, you have no catch code, which of these will happen
a].the application will terminate
b].the JVM will start a new thread to perform the update operation
c].the application will not terminate but the updating will cease
d].none of the above will happen
 
Arunagiri, Shanmugham
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the application will terminate and a stack trace will be printed on the screen.
------------------
SeE Consulting(P) Ltd
Bangalore,India
 
Anshuman Acharya
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree, anuragiri
 
Junaid Bhatra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your application may or may not terminate. Whenever there is an uncaught exception in a thread, that thread dies. Ofcourse if your program has only 1 non-daemon thread, i.e. user-thread (for eg. only a main thread), then JVM will exit. Otherwise if there are multiple daemon threads running, then the other threads will happily continue to run and JVM will not exit.
 
anil bisht
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i agree with u Junaid
Noel try this code and u will get the answer
public class A extends Thread{
static int i=0;
public void run()
{
System.out.println("all done before"+i);
if (i ==0)
i = 1/i;
System.out.println("all done"+i);
}
public static void main(String[] args){
A t1 = new A();
t1.start();
try{
sleep(200);}catch (Exception e){}
i++;
A t2 = new A();
t2.start();
System.out.println("all done. exiting now");
}
}

HTH
anil
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic