Is this the most common case?
Why, when I press the x button to close the window in Java application, the window disappears and the application is still running.
I have read so many times that java designers have tried to satisfy Java behavior for the most common needs of programmers and save them precious time etc. etc. What's more common than closing the app when I press the X button?
a source to share
Whatever the reason, it really doesn't matter as long as you know how it works and how to make your program behave the way you want it to.
Assuming that: one app can have multiple windows exiting the app when one of them is closed doesn't seem very smart. Keeping track of how many windows are open / closed / hidden / not yet shown, and so fort to be able to exit when the last windows are closed, it might be too much work / too many edge cases, etc. Thus, it is up to us programmers when we want our application to exit.
Anyway, if you want your application to close when the window (JFrame) is closed, you can simply tell it:
myJFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
a source to share
Many applications have multiple windows open at the same time, and closing one window should not necessarily close the entire application.
Plus, most apps want to do a little more than just System.exit(0);
exit. They might want to ask the user to save some files (or save them automatically), they might want to clear some temporary files, or notify some remote host to shutdown or something like that.
In fact, it is very unlikely that the only effect of closing a window ends up with the JVM.
a source to share
myJFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Disposal is almost always preferred. If you explicitly say EXIT_ON_CLOSE and you ever want to display more than one window, you will need to change your code to use DISPOSE_ON_CLOSE instead. Not a huge deal, of course, just the best choice.
In my opinion, DISPOSE_ON_CLOSE should have been the default and not HIDE_ON_CLOSE. Ok, this is what we have. EXT_ON_CLOSE should be avoided for the same reason that calling System.exit (0) should be avoided in a window listener (although there is nothing wrong with it, it's just not a very flexible future).
Better yet, it's almost always advisable to attach a WindowListener to your frame and set the JFrame.DO_NOTHING_ON_CLOSE to the default. This way, you have control over when the application is closed, including prompting the user to save any work, etc.
a source to share