This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes How to end Java Program? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to end Java Program?" Watch "How to end Java Program?" New topic

How to end Java Program?

Scott Kamen

Joined: Apr 01, 2003
Posts: 15
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?
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
In simple circumstances, System.exit(int) should do it. So, would returning from the main method.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9044
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.

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
which can exit
and if your programme involves java swing of the GUI programme
you can type
which also can quit the application.
thank you

Francis Siu
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
Do you read it?
I hope that it can help you
It is sorta covered in the JavaRanch Style Guide.
subject: How to end Java Program?