Home » questions » System.getProperty in java ?

System.getProperty in java ?

2006-08-16 05:33:56, Category: Programming & Design
getProperty public static String getProperty(String key)Gets the system property indicated by the specified key. First, if there is a security manager, its checkPropertyAccess method is called with the key as its argument. This may result in a SecurityException. If there is no current set of system properties, a set of system properties is first created and initialized in the same manner as for the getProperties method. Parameters: key - the name of the system property. Returns: the string value of the system property, or null if there is no property with that key. Throws: SecurityException - if a security manager exists and its checkPropertyAccess method doesn't allow access to the specified system property. NullPointerException - if key is null. IllegalArgumentException - if key is empty. According to java docs. Now what is the difference between setProperty(String key, String value) and getProperty(). Please help with a small code ? K Banerjee

Answers

  1. puckstorm

    On 2006-08-16 05:50:46


    With System.setProperty() you can actually set either a custom system property or one of the predefined ones. You have to have a 'write' access to the property when you call setProperty() whereas when you call getProperty() you have to have a 'read' access to it. getProperty() simply returns a String value and does not set anything.