Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Java
  3. Question
Java

How To Use End Program In Java?

Asked by Ashish Mishra Sep 22, 2023 1.5K views 1 answer
Share

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?

Your answer

1 Answer

More Java discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Java Blogs

Guides, tips and career advice on Java from JanBask experts.