About this question
I discovered a few ways to exit the Java programs. There are two solutions that I have found. One is using the return statement. On wishing to end or quit the program execution, I use this. The second is utilizing the System. exit(). However, I am confused as to how these work exactly. Have a look at the codes below:
public class Testing {
public static void main(String... str) {
System.out.println(1);
System.exit(0);
System.out.println(2);
return;
}
}
I am quite confident that 2 won’t appear. I want to know why returns and other codes are written below the statement of the System. exit (), and what is the actual definition of return?