• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 507
  • Last Modified:

How to terminate java program from JVM??????

Hi...

In java to terminate the program probably using System.exit() method...
Are there any another way to termiate the program with out using the above method....

Advance thanks...to u r help !!!!!!!!

Thanks,
Venkat.
0
ramareddyj
Asked:
ramareddyj
  • 9
  • 6
  • 5
  • +2
2 Solutions
 
objectsCommented:
yes, the vm will terminate whan all non-damon threads have completed.
0
 
ramareddyjAuthor Commented:
Hello...
In my do-while loop to termiate program when the user enter exit. at the time i am termiating the java program.
using System.exit();
In my Situation should not use the above method....It is restricted....
is there any another method or process to termiate the program...


Thanks,
Venkat.
0
 
objectsCommented:
Whats restricted exactly?

They are the only two ways to terminate the vm
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ramareddyjAuthor Commented:
In my java program don't use the System.exit() method...
so..i want to temiate my java program..with out using above method...
Let me know what are the two way to termiate the java program.


Thanks,
Venkat.
0
 
sciuriwareCommented:
When your main() returns the program only continues when there are other threads.
a GUI creates such.
When you (e.g.) dispose of all windowing from a GUI the program finally exits.

;JOOP!
0
 
sciuriwareCommented:
public class MyProgram
{
    public static void main(String[] argv)
    {
         System.out.println("This is my program");
    }
}

certainly exits after the message is output.

;JOOP!
0
 
ramareddyjAuthor Commented:
do
{
System.out.println("Aldebaran Space Liners\n" +
      "1. Add Passenger \n" +
                "2. Add Destination \n" +
      "3. Add Crew \n" +
      "4. Display Space Ship \n" +
      "5. Save to file \n" +
      "6. Load from file \n" +
      "7. Exit ");
      ystem.out.println("Please enter your choice:");
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      choice =br.readLine();
      option = Integer.parseInt(choice);
      
            switch (option) {
                                                  some cases.................
                  }      
                  
                  
}
      while(option != 7);
      {
      System.out.println("Thank you for using the program.");
      System.exit(0);
      }



this is my code...i used System.exit(0) for termianation.....
How to terminate without using above method..in my code.........

Regards,
Venkat.

0
 
objectsCommented:
> Let me know what are the two way to termiate the java program.

I already did, see my first comment

> How to terminate without using above method..in my code.........

break out of the loop, ie. finish the thread

0
 
ramareddyjAuthor Commented:
Whats restricted exactly?
They are the only two ways to terminate the vm

This is given by u......that's y i asked what are those methods...
How to terminate without using above method..in my code.........called with out using System.exit() method..


Thanks,
Venkat.
0
 
sciuriwareCommented:
ramareddyj, we gave you the answer!
can you read English?

;JOOP!
0
 
sciuriwareCommented:
Replace:

     while(option != 7);
     {
     System.out.println("Thank you for using the program.");
     System.exit(0);
     }

by

     while(option != 7);
     System.out.println("Thank you for using the program.");

;JOOP!
0
 
objectsCommented:
ramareddyj> Are there any another way to termiate the program with out using the above method....

objects> yes, the vm will terminate whan all non-damon threads have completed.
0
 
ramareddyjAuthor Commented:
Very first u given that two methods are there for termiate the java program...
that's y i asked what are the two methods to termiate the program....
Let me know what are those two methods....
As i Know to remove System.exit(0)...in my code..
I want are there any another method in place of System.exit(0) method..to terminate the program...



Thanks,
Venkat.
0
 
objectsCommented:
two method:

1. the one you are already using, and

2. the one I mentioned in my first comment
0
 
sciuriwareCommented:
ramareddyj, why can't you understand? The 2nd method to exit
is just TO DO NOTHING!

The return from main() to the system is an attempt to exit!

;JOOP!
0
 
ramareddyjAuthor Commented:
U also not under stand my problem..first...
Thank u for u r help !!!!!!!!!!!!!!!!

Thanks,
Venkat.

0
 
sciuriwareCommented:
Well objects, ........................ we tried.
0
 
matthew016Commented:
while(true) {
     System.out.println(...);
     System.out.println("Please enter your choice:");
     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     choice =br.readLine();
     option = Integer.parseInt(choice);
     
     switch (option) {
             case ...
             case 7 : System.exit();
     }    
}


0
 
matthew016Commented:
Oh, didn't understand question
0
 
Mayank SAssociate Director - Product EngineeringCommented:
The options proposed should work as long as you are not creating any new threads in your program (and not setting them as daemon).
0
 
sciuriwareCommented:
All was said already ....................
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Yes, just trying in different words in case it is still not clear.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
(which is why I said the options proposed should work - not taking credit away from those who already posted it)
0
 
sciuriwareCommented:
No problem man, this is just a hopeless case.  4th world I presume.
0
 
sciuriwareCommented:
Please split between objects and me.

;JOOP!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 9
  • 6
  • 5
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now