Java System console() Method7 Nov 2024 | 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. SyntaxReturns
Example 1Output: Console is not supported Example 2Output: Console is null Next TopicJava-system-currenttimemillis-method |
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 setOut() method of Java System class is used to reassign the standard output stream. Syntax: public static void setOut(PrintStream out) Parameters: out - new standard output stream. Throws: SecurityException: This exception will throw if security manager exists and its checkPermission method doesn't allow reassigning of the standard outputstream. Example import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import...
1 min read
The identityHashCode() method of Java System class returns hash code for the specified object. It is returned by the default method hashCode(). Syntax public static int identityHashCode (Object x) Parameter x - object for which the hashCode is to be calculated Returns Returns the hash code. Returns zero as reference if hash code...
1 min read
The nanoTime() method of Java System class returns high resolution time source in nanoseconds of running java virtual machine. It returns the current value of JVM. Syntax public static long nanoTime() Returns Returns a high resolution time source in nanoseconds. Example public class SystemNanoTimeExample1 { public static void main(String[] args) { System.out.println("Current time in...
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 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 gc() method of System class runs the garbage collector. Through this method, JVM makes best effort to reuse the memory of discarded objects for quick reuse. Syntax public static void gc() Example 1 import java.awt.Window; public class SystemGCExample1 { public static void main(String[] args) { for (int i = 0; i<...
1 min read
The runFinialization() method of java system class runs finalization methods which can be of any objects pending finalization. Syntax public static void runFinalization() Example public class SystemRunFinalizationExample1 { public static void main(String[] args) { System.out.println("Starting finalization.."); System.runFinalization(); System.out.println("Finilization ended!!"); } } Output: tarting finalization.. Finilization ended!! TopicJava-system-seterr-method ...
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