起動する前にユーザーに入力を求めるプログラムがあります。
public static void main(String args[])
{
String database = JOptionPane.showInputDialog(new JFrame(), "Enter a DB:");
if(database!=null && database.foundInDB()) {
SPVerification spv = new SPVerification();
spv.setVisible(true);
}
//System.exit(1); Without it the program doesn't terminate although it's the end
// of the main function.
}
ユーザーが見つからないデータベースを入力した場合、プログラムは実行されません。
DB名を間違えると以下のif
文が実行されず、mainメソッドの最後までたどり着くがプログラムが終了せず、文のsystem.exit(1)
後ろに追記するとプログラムが終了してしまう。メインの終わりに達したのに、if
なぜ呼び出す必要があるのですか?System.exit(1)