How to end a program in Java?

To terminate a Java program, call the System.exit method.
System.exit(0);

This effectively kills the java process, and stops your program immediately.

What does the number mean?

The number that you pass to the method informs the Operating System about the cause of the kill.

By convention, 0 means the kill was expected. Anything other than 0 is treated as unexpected kill due to some problem.

Just leave it at 0 if you don't care.