Saturday, 10 June 2017

Java Tutorial: System class in java [How to get the default value if Key is not present] ~ foundjava


Click here to watch in Youtube : 

https://www.youtube.com/watch?v=-NwT89yD15Y&list=UUhwKlOVR041tngjerWxVccw

PropertiesDemo.java

/*
 * public static String getProperty(String key, String
 *                                               def)
 * 
 * Parameters: 
 * ----------
 * 
 * key - the name of the system property.  
 * def - a default value.
 */

public class PropertiesDemo
{

    public static void main(String[] args)
    {
        /*
         * Gets the system property indicated by the
         * specified key.if not present it will return
         * default value.
         */
        String value1 = System.getProperty("a.b", "hello");
        System.out.println("value1 = " + value1);

        
        String value2 = System.getProperty("os.name", "hello");
        System.out.println("value2 = " + value2);
        
    }
}
Output
value1 = hello
value2 = Windows 7

Click the below link to download the code:

CLICK HERE

No comments:

Post a Comment