Java System exit() Method7 Nov 2024 | 1 min read The exit() method of System class terminates the current Java virtual machine running on system. This method takes status code as an argument.
SyntaxParameterstatus - It is the exit status. ReturnsThis method does not return any value. ExceptionIf security manager exist and his checkexit method doesn't approve exit with specified status then a SecurityException is thorwn. Example 1Output: array[0]=9 array[1]=8 array[2]=7 array[3]=6 terminatingjvm,exiting Example 2Output: program will terminate when i is 1 your no is 10 your no is 9 your no is 8 your no is 7 your no is 6 your no is 5 your no is 4 your no is 3 your no is 2 your no is 1 Value is 1 now terminating your program Next TopicJava-system-gc-method |
The getProperties() method of Java System class returns the properties of current system. If there is no current set of system property, a set of system properties is first created and initialized. This system property set includes value for the following keys: Key Description of Associated Value java.version Java Runtime...
2 min read
The setErr() method of Java System class is used to reassign the "standard" error output stream. Syntax public static void setErr(PrintStream err) Parameter err - It is the new standard error output stream. Exception: SecurityException: This exception will throw if the security manager exists and its checkPermission method doesn't allow reassigning of the...
1 min read
The getLogger() method of Java System class returns instance of logger. This instance can be used for caller's use. Syntax public static System.Logger getLogger(String name) Parameter name - name of the logger Returns It returns instance of System.Logger, which can be used by the calling class. If name is null then a NullPointerException...
1 min read
The lineSeparator() method of Java System class returns line separator string which is system dependent. It returns same value every time. Syntax public static string lineSeparator() Returns It returns "\n" on UNIX System. It returns "\r\n" on Windows System. Example public class SystemLineSeparatorExample1 { public static void main(String[] args) { String a=System.lineSeparator(); for(char b:a.toCharArray()) { System.out.println((int)b); } } } Output: 13 10 Example 2 public class...
1 min read
The setProperties() method of Java System class sets the properties of the system to the argument of properties. Syntax: public static void setProperties(Properties props) Parameters: props - It is the new system properties. Throws: SecurityException: This exception will throw if the security manager exists and its checkPropertiesAccess method doesn't allow access to...
1 min read
The console() method of Java System class returns Console object only if any Console objected is associated with the java virtual machine. Syntax public static Console console() Returns The Console object of current java virtual machine. Null if Console object is not associated with current java virtual machine. Example 1 import java.io.Console; public class...
1 min read
The setProperty() method of Java system class sets the property of the system which is indicated by a key. Syntax: public static String setProperty(String key, String value ) Parameters: key - It is the name of the system property. value - It is the value of the system property. Returns This method returns...
1 min read
The load() method of java System class loads file specified by the filename argument. Here argument must be an absolute path name. Syntax public static void load(String filename) Parameter filename - It is the file which has to load. Exception NullPointerException: This exception will throw if the filename is null. SecurityException: This exception...
1 min read
The currentTimeMillis() method of System class returns current time in format of millisecond. Millisecond will be returned as unit of time. Syntax public static long currentTimeMillis() Returns Returns difference, measured in milliseconds, between current time and midnight January 1, 1970 UTC(coordinated universal time). Example public class SystemCurrentTimeMillisExample1 { public static void main(String[] args)...
1 min read
The getProperty(String key,Stringdef) method of Java System class returns property of a system which is indicated by a specified key. Syntax public static String getProperty(String key,String def) Parameter key - the name of the system property. def - a default value. Returns This method returns System property or default value if there is...
1 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India