What is the use of System.exit()
? What happens if I don't use it? My professor used it in the following way:
public static void main(String[] args) throws Exception {
// make sure that you have the right number of arguments
if (args.length != 1) {
System.out.println("Usage: java FileDemo filename");
System.exit(0);
}
I don't know why he used it. Also I don't get why he asked me to make sure that I have right number of arguments. How does he know if (args.length !=1)
? We have not yet populated String [] args
in the main method.