Home » Java programming language

Java System class clearProperty() method with example

System class clearProperty() method: Here, we are going to learn about the clearProperty() method of System class with its syntax and example.
Submitted by Preeti Jain, on September 14, 2019

System class clearProperty() method

  • clearProperty() method is available in java.lang package.
  • clearProperty() method is used to remove or clear the property value denoted by the given argument (property_name).
  • clearProperty() method is static so this method is accessible with the class name too.
  • clearProperty() method may be thrown various type of exception and the exception are given below:
    • SecurityException: If a particular method checkPropertyAcess() does not allow access to the given system property in the method.
    • NullPointerException: If the given system property is null.
    • IllegalArgumentException: If the given system property value is empty.

Syntax:

    public static String clearProperty(String property);

Parameter(s):

  • property – represents the name of the property to be removed.

Return value:

The return type of this method is String, it returns the old string value of the System property and if there is no property value with that "property_name", it returns null.

Example:

// Java program to demonstrate the example of 
// clearProperty() method of System Class.

public class ClearPropertyMethod {
    public static void main(String[] args) {
        // By using  getProperty() method is used 
        // to get the value of the property
        System.out.println(System.getProperty("user.name"));

        // By using  clearProperty() method is used to 
        // clear the value of the property
        System.clearProperty("user.name");

        // Display the value of the property
        System.out.println("After clearProperty()...");
        System.out.println(System.getProperty("user.name"));
    }
}

Output

E:\Programs>javac ClearPropertyMethod.java
E:\Programs>java ClearPropertyMethod
root
After clearProperty()...
null


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.