×

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

LCM Program in Java

LCM Program in Java The LCM program in Java outputs the LCM of the given numbers. In Arithmetic, the lowest common multiple, least common multiple or smallest common multiple of the...

6 minutes read.

Round Robin Scheduling Program in Java

A CPU scheduling technique is known as Round Robin (RR). Additionally, network schedulers employ it. It was created specifically for a time-sharing system. The temporal slicing scheduling algorithm is another...

4 minutes read.

Shallow copy in Java

Java's most important task is making a copy or clone of an object. In this part, we'll talk about shallow copies in Java and how to make them of Java...

4 minutes read.

Java Pop

The array, linked list, stack, queue, and other data structures are supported by Java programming. The insertion, deletion, and element searching operations are available for every data structure. And Java...

4 minutes read.

&& Operator in Java

“ && ” is the conditional - And operator in Java. In Java, it is an example of a logical operator. In Java, the “ & ” operator has two...

3 minutes read.

Three-way operator in Java

The ternary operator in Java is the only conditional operator that takes three operands. It's a popular one-line substitute for the if-then-else expression among Java programmers. If-else clauses can be...

3 minutes read.

String Manipulation in Java

String Manipulation in Java In Java, string manipulation is a common task performed by programmer. Java String class provides many built-in functions that are used to manipulate string. The manipulation of...

4 minutes read.

RMI program in Java

Remote Method Invocation is what it stands for. An object can call the method of another object in a different space address using the RMI API, which may be on the...

3 minutes read.

Prime Points in Java

The points that divide an integer into two halves containing a prime number are known as prime points. Printing every prime point of a specific number is the task. Let's...

6 minutes read.

Char and String differences in Java

Characters in Java Character (char) belongs to the characters group, which represents symbols in a character set, such as alphabets and numerals. A Java char has 16 bits in length and has a range...

5 minutes read.

Sorting a String in Java

Sorting a String in Java Sorting is a process of arranging available data objects in a meaningful format that is ascending or descending order. Sorting a string or array of String...

4 minutes read.

Java Write File

In this post, we'll examine various Java programming methods for writing into files. Since this class is character-oriented due to how it is used in file handling in Java, it...

4 minutes read.

Lambda expressions in Java

A brief introduction to Lambda expression in java In this topic, we will discuss the lambda expression in java. A lambda expression in Java is an enhanced version of an anonymous...

13 minutes read.

Java Integer floatValue() method

The floatValue() method of Integer class returns a float value for this Integer after a widening primitive conversion. Syntax public float floatValue() Parameters NA Specified by This method is specified by floatValue in class Number Return Value This...

1 minute read.

Star Pattern Programs in Java

Star Pattern Programs in Java The star pattern programs in Java is the part of pattern programs in Java, which we discussed earlier. Right Triangle Star Pattern Filename: StarPatternExample.java public class StarPatternExample {              public static void...

4 minutes read.

Program to Find Square Root of a Number Without sqrt Method in Java

The Java Math class sqrt () function can be used to determine the square root of a number. In this section, we'll write a Java program to find a number's...

3 minutes read.

Java Xmx

This section will explain what Xmx in Java is and how to establish a Java application's maximum heap size. When we execute a Java application, it occasionally displays an error message...

3 minutes read.

Interchange Diagonal elements in Java

In this article, you will be very well acknowledged about what is a matrix with an example. You will also be acknowledged about how to interchange the diagonal elements in...

4 minutes read.

Java Math sin() Method

The sin() method of Java Math class returns the trigonometric sine of the specified angle. Syntax: public static double sin(double a) Parameters: The parameter ‘a’ represents an angle measured in radians. Return Value: The sin() method...

1 minute read.

Java LinkedList

LinkedList Java The Java LinkedList is used to store the elements by using a doubly linked list. It contains the duplicate items, also maintains the order of the insertion, the class...

5 minutes read.