• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to end Java Program?

 
Scott Kamen
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know this is incredibly easy and even though I'm not supposed to I still feel somewhat embarrassed asking it. How do you kill (quit) a java application? I had though that you could use kill(0); (or any number value) but I got a compile error. I did a quick look in the indexes of my books and on google but I didn't come up w/ anything. Could someone help me?
thanks,
-Scott
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In simple circumstances, System.exit(int) should do it. So, would returning from the main method.
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using a GUI (e.g. applet), you will need to use the System.exit that Dirk mentioned. Otherwise, the program should exit normally with no need for a specific command to exit.
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes!
System.exit(0);
which can exit
and if your programme involves java swing of the GUI programme
you can type
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
which also can quit the application.
thank you
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you read it?
I hope that it can help you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic