It's not a secret anymore!
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 REST with Spring (video course) this week in the Spring 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: 9058
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
subject: How to end Java Program?
It's not a secret anymore!