Tuesday, 28 February 2017

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


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:
https://sites.google.com/site/ramj2eev1/home/javabasics/System_getProperty_default_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/System_getProperty_default_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/fecc858ed896ce9bbf3cb92f5d438fc2de9eee22/BasicJava/System_getProperty_default_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment