AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



java-basics: What is System.exit in Java?

Could you please explain to me what is system.exit in java and why we use it?

java x 211
basics x 171
Posted On : 2013-12-25 22:04:49.0
profile Garima Gupta - anyforum.in Garima Gupta
596129554549
up-rate
5
down-rate

Answers


The java.lang.System.exit() method terminates the currently running Java Virtual Machine.
The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination.

Following is the declaration for java.lang.System.exit() method :
public static void exit(int status)

***************************** Example of System.exit() method *****************************

package in.anyforum;

import java.lang.*;

public class SystemDemo {

public static void main(String[] args) {

int arr1[] = { 0, 1, 2, 3, 4, 5 };
int arr2[] = { 0, 10, 20, 30, 40, 50 };
int i;

// copies an array from the specified source array
System.arraycopy(arr1, 0, arr2, 0, 1);
System.out.print("array2 = ");
System.out.print(arr2[0] + " ");
System.out.print(arr2[1] + " ");
System.out.println(arr2[2] + " ");

for(i = 0;i < 3;i++) {
if(arr2[i] > = 20) {
System.out.println("exit...");
System.exit(0);
}
else {
System.out.println("arr2["+i+"] = " + arr2[i]);
}
}
}
}

================================ Output ================================

array2 = 0 10 20
arr2[0] = 0
arr2[1] = 10
exit...

Posted On : 2013-12-25 22:32:49
Satisfied : 1 Yes  0 No
profile Saksham Kumar - anyforum.in Saksham Kumar
73433936114
Reply This Thread
up-rate
5
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in