×

System Class in Java

The System class provides features including a way to load files and libraries, standard input, standard output, and errors throughput streams, accessibility to outside defined characteristics and environment variables, and a utility method for efficiently copying a portion of an array. It extends the Object class.

Sectors:

  1. public static final InputStream in: The input stream that is "typical." Each stream already is open and prepared to receive data as input. This stream often relates with keyboard input or any other input source that the hosts environment or user has chosen.
  2. public static final PrintStream out: The output stream that is "typical." This stream is open and prepared to receive output information. This stream often relates to order to provide customers or some other output destination that the hosts environment or user has defined.
  3. public static final PrintStream err: the output stream for "standard" errors. This stream is open and prepared to receive output information. This stream often relates to order to provide customers or some other output destination that the hosts environment or user has definedNormally, even though the important transmission flow, the valuation of variable out, has already been redirected to a file or another placement that is typically not constantly monitored, all above output stream is used to display error messages or other data that really should be managed to bring to the user's immediate attention.

Techniques:

  1. static void arraycopy(Object source, int sourceStart, Object Target, int targetSize, int size): propagates an array. The source parameter specifies an array to be copied, and sourceStart specifies the index in the source where the copy should start. Target contains the array which will receive the copy, and targetStart contains the index at which the copy will start within the array. The quantity of elements copied is known as size.

A Sample Program on illustrating arraycopy():

// An example of arraycopy() in Java
import java.lang.*;
import java.util.Arrays;
class SystemDemo
{
    public static void main(String args[])
    {
        int[] a = {2, 3, 4, 5, 6};
        int[] b = {1, 2, 3, 4, 5};
         
        System.arraycopy(a, 0, b, 2, 2);
         
        // array b after arraycopy operation
        System.out.println(Arrays.toString(b));
         
    }
}

Expected Output:

[1, 2, 2, 3, 5]

2. static String clearProperty(String key): the specified key deletes the system property that is indicated by it.

Syntax: public static String clearProperty(String key)

Reverts: the string value of the system

property, or null if there is no property with that key.

If the key is empty, an illegal argument exception occurs.

3. static String getProperty(String key) : the key supplied returns the system property.

Syntax: public static String getProperty(String key)

Reverts: the system property's string value, or null if that key doesn't correspond to any properties,

Exception:

SecurityException: if there is a security manager,

Using the checkPropertyAccess method prevents access to the

referred to system property.

If key is null, a NullPointerException occurs.

If the key is empty, an illegal argument exception occurs.

4. static string getProperty(String key, String def): Gets the system property denoted by the

syntax: public static String getProperty(String key, String def)

returns: the system property's string value,

alternatively, in the absence of a property with that key, the default value.

If a security manager is present and its checkPropertyAccess method disallows access to the requested system property, a SecurityException is thrown.

If key is null, a NullPointerException occurs.

If the key is empty, an illegal argument exception occurs.

5. static String setProperty(String key, String value): Specifies the key to press to set the system property.

syntax: public static String setProperty(String key, String value)

returns: if the system property had no previous value, null is returned.

Exception:

SecurityException: is thrown when a security manager is present but its checkPermission method forbids setting the requested property.

If the key or value is null, a NullPointerException will occur.

If the key is empty, an illegal argument exception occurs.

// Examples of clearProperty() and getProperty in Java ()
// and methods setProperty()
import java.lang.*;
import static java.lang.System.clearProperty;
import static java.lang.System.setProperty;
import java.util.Arrays;
class SystemDemo
{
    public static void main(String args[])
    {
        // examining a certain property
        System.out.println(System.getProperty("user.home"));
         
        // purging this location
        clearProperty("user.home");
         
        System.out.println(System.getProperty("user.home"));
         
        // defining a particular property
        setProperty("user.country", "India");
         
        // checking the property
        System.out.println(System.getProperty("user.country"));
         
        // examining a different property than a system property
        // illustrating getProperty(String key, String def)
        System.out.println(System.getProperty("user.password",
              "Business tycoon"));
    }
}

Expected Output:

null
India
Business tycoon

Related Topics

Swapping Program in Java

Swapping Program in Java The swapping program in Java is used to interchange the values of the two variables. For example, if X = 12 and Y = 24, then the...

4 minutes read.

Java callable example

What is callable in Java? Callable is an interface that is present in Java. There are two methods for constructing threads: one is to inherit the Thread class, while the other...

3 minutes read.

Java Math toDegrees() Method

The toDegrees() method of Java Math class converts a radian angle to an approximately equivalent angle measured in degrees. Syntax: public static double toDegrees(double angrad) Parameters: The parameter ‘angrad ‘represents an angle measured in...

2 minutes read.

Bean class in Java

The web applications that are created with the help of the JSP or Java Server Pages generally have fairly more functionality than the web pages that specifically are created with...

5 minutes read.

Java Math floorDiv() Method

The floorDiv () method of Math class returns the largest integer value that is less than or equal to the algebraic quotient. It firstly divides the dividend and divisor and...

2 minutes read.

Multithreading Program in Java

Multithreading Program in Java: Before discussing multithreading, it is important to discuss threads. Threads are the most fundamental part of a process. A process can have one or more threads....

4 minutes read.

Method Overriding in Java

Overriding  Overriding is also known as run time polymorphism, and it is about the same method with the same signatures in different classes. Overriding can be applied only methods. Method Overriding Method Overriding...

8 minutes read.

Java RandomAccessfile

Writing and reading to random access files are done using this class. An array of many bytes is how a random access file operates. By changing the implied file pointer...

3 minutes read.

Java Math hypot() Method

The hypot() method of Math class returns the square root for the expression x2 + y2 without the intermediate underflow or overflow . Syntax: public static double hypot(double x, double y) Parameters: The parameters...

2 minutes read.

Java instance variable

An instance in object-oriented programming (OOP) is a particular implementation of any object. Each realized version of an item, which might vary in several ways, is an instance. Instantiation is...

3 minutes read.

Java Final Keyword

In Java, the last keyword is used to limit the user. The applications of the java final keyword have large range of usage in program development. Last can be: variablemethodclass A final...

3 minutes read.

Command Class in Java

We use the command class to run commands against the database. The Command class may find a set of parameter objects for use in sending values to a stored procedure...

3 minutes read.

Java extend multiple classes

In Java, what does extend mean? One of several Java inheritance keywords is extended, meaning we pass all or most of the Parent class's characteristics through to the Child class. The...

3 minutes read.

Java SHA256

Definition: In cryptography, SHA is a hash function that takes 20 bytes of input and produces an approximate 40-digit hexadecimal integer as the hash result. Class for Message Digest: Java's MessageDigest Class,...

2 minutes read.

Java Program to Add Digits Until the Number Becomes a Single Digit Number

We will develop Java programme that increase a number's digit count in order to reduce it to one. The issue is also known as the digit root problem. Example Consider the case where...

3 minutes read.

Java Macros

Macros are additions to the JDK 7 compiler in Java. Compile time macros are added and supported. Macros are Java classes that are instantiated and executed during the compilation process....

2 minutes read.

Generic Linked List in Java

A linear data structure known as a Linked List stores values in nodes. As we already know, each node has two properties: its value and a link to the node...

6 minutes read.

String Pool in Java

String Pool in Java: String is one of the most important discussed topics in Java. There are a lot of concepts related to the String and one of them is...

5 minutes read.

How to calculate time complexity of any program in Java

Java : Java's syntax and principles are derived from the C and C++ languages. We know that java is one of the programming language. The main feature of java which is...

3 minutes read.

Java Integer toUnsignedLong() method

The toUnsignedLong() method of Java Integer class returns a long value by simply converting the given argument to long after an unsigned conversion. Syntax public static long toUnsignedLong (int  x) Parameters The parameter ‘x’...

1 minute read.