In order to know how to end program in Java, you should be aware that calling return with in a function doesn’t end it. You need to use System.exit(0) command to terminate the Java Virtual Machine.

public void endProgram(){
  System.out.println('This will print');
  System.out.println('This can not print');

    Tweet this to help others

In this code the first command will execute and print the string. But, third print statement will not execute. System.exit(0) will end the program and terminate the JVM before the java code reach the 3rd line.


About the Author


I am Akash Mittal, an overall computer scientist. If you want to guest post, need help in your projects, want to advertise, Feel free to contact me at [email protected]

View All Articles