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
  • Java Tutorial: System class in java [How to get the system property indicated by the specified key]


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=QLcKjdm0Umc&list=UUhwKlOVR041tngjerWxVccw

    PropertiesDemo.java
    /*
     * public static String getProperty(String key)
     *
     * Parameters:
     * ----------
     *
     * key - the name of the system property.
     */
    
    public class PropertiesDemo
    {
    
        public static void main(String[] args)
        {
            /*
             * Gets the system property indicated by the
             * specified key.
             */
            String value = System.getProperty("os.name");
            System.out.println("value = " + value);
    
            String value1 = System.getProperty("a.b");
            System.out.println("value1 = " + value1);
    
        }
    }
    
    Output
    value = Windows 7
    value1 = null
    
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/System_getProperty_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/fecc858ed896ce9bbf3cb92f5d438fc2de9eee22/BasicJava/System_getProperty_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
  • Java Tutorial: Properties class in java [How to get all the system properties]


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=uxBVYUluWb4&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial: Properties class in java [How to get all the system properties] 
    Java Tutorial: Properties class in java [How to get all the system properties] 
    PropertiesDemo.java
    import java.io.IOException;
    import java.util.Iterator;
    import java.util.Properties;
    import java.util.Set;
    
    class PropertiesDemo
    {
    
        public static void main(String[] args) throws IOException
        {
    
            /*
             * Returns the system properties
             */
            Properties p = System.getProperties();
    
            /*
             * Returns a set of keys in this property list where
             * the key and its corresponding value are strings,
             * including distinct keys in the default property
             * list if a key of the same name has not already
             * been found from the main properties list.
             */
            Set<String> set = p.stringPropertyNames();
    
            Iterator<String> itr = set.iterator();
    
            while (itr.hasNext())
            {
                String key = (String) itr.next();
                /*
                 * Gets the system property indicated by the
                 * specified key.
                 */
                String value = p.getProperty(key);
                System.out.println(key + " = " + value);
            }
    
        }
    }
    
    Output
    java.runtime.name = Java(TM) SE Runtime Environment
    sun.boot.library.path = C:\Java\jre1.8.0_111\bin
    java.vm.version = 25.111-b14
    java.vm.vendor = Oracle Corporation
    java.vendor.url = http://java.oracle.com/
    path.separator = ;
    java.vm.name = Java HotSpot(TM) 64-Bit Server VM
    file.encoding.pkg = sun.io
    user.script = 
    user.country = US
    sun.java.launcher = SUN_STANDARD
    sun.os.patch.level = Service Pack 1
    java.vm.specification.name = Java Virtual Machine Specification
    user.dir = D:\eclipse\workspace\PropertiesDemo
    java.runtime.version = 1.8.0_111-b14
    java.awt.graphicsenv = sun.awt.Win32GraphicsEnvironment
    java.endorsed.dirs = C:\Java\jre1.8.0_111\lib\endorsed
    os.arch = amd64
    java.io.tmpdir = C:\Users\Ramesh\AppData\Local\Temp\
    line.separator = 
    
    java.vm.specification.vendor = Oracle Corporation
    user.variant = 
    os.name = Windows 7
    sun.jnu.encoding = Cp1252
    java.library.path = C:\Java\jre1.8.0_111\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Java/jre1.8.0_111/bin/server;C:/Java/jre1.8.0_111/bin;C:/Java/jre1.8.0_111/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Lenovo\Bluetooth Software\;C:\Program Files\Lenovo\Bluetooth Software\syswow64;C:\Program Files\OpenVPN\bin;C:\Java\jdk1.8.0_111\bin;C:\Program Files\TortoiseGit\bin;C:\Program Files\Git\cmd;C:\Program Files\TortoiseHg\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;D:\eclipse;;.
    java.specification.name = Java Platform API Specification
    java.class.version = 52.0
    sun.management.compiler = HotSpot 64-Bit Tiered Compilers
    os.version = 6.1
    user.home = C:\Users\Ramesh
    user.timezone = 
    java.awt.printerjob = sun.awt.windows.WPrinterJob
    file.encoding = Cp1252
    java.specification.version = 1.8
    user.name = Ramesh
    java.class.path = D:\eclipse\workspace\PropertiesDemo\bin
    java.vm.specification.version = 1.8
    sun.arch.data.model = 64
    java.home = C:\Java\jre1.8.0_111
    sun.java.command = PropertiesDemo
    java.specification.vendor = Oracle Corporation
    user.language = en
    awt.toolkit = sun.awt.windows.WToolkit
    java.vm.info = mixed mode
    java.version = 1.8.0_111
    java.ext.dirs = C:\Java\jre1.8.0_111\lib\ext;C:\Windows\Sun\Java\lib\ext
    sun.boot.class.path = C:\Java\jre1.8.0_111\lib\resources.jar;C:\Java\jre1.8.0_111\lib\rt.jar;C:\Java\jre1.8.0_111\lib\sunrsasign.jar;C:\Java\jre1.8.0_111\lib\jsse.jar;C:\Java\jre1.8.0_111\lib\jce.jar;C:\Java\jre1.8.0_111\lib\charsets.jar;C:\Java\jre1.8.0_111\lib\jfr.jar;C:\Java\jre1.8.0_111\classes
    java.vendor = Oracle Corporation
    file.separator = \
    java.vendor.url.bug = http://bugreport.sun.com/bugreport/
    sun.cpu.endian = little
    sun.io.unicode.encoding = UnicodeLittle
    sun.desktop = windows
    sun.cpu.isalist = amd64
    
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/PropertiesDemo_System_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/fecc858ed896ce9bbf3cb92f5d438fc2de9eee22/BasicJava/PropertiesDemo_System_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
  • Java Tutorial: Properties class in java [How to get the keys using stringPropertyNames method]


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=YnO_MQvHwRg&list=UUhwKlOVR041tngjerWxVccw

    db.properties
    Java Tutorial: Properties class in java [How to get the keys using stringPropertyNames method] 
    PropertiesDemo.java
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.Iterator;
    import java.util.Properties;
    import java.util.Set;
    
    /*
     * public Set<String> stringPropertyNames()
     * 
     * Returns: 
     * --------
     * 
     * a set of keys in this property list where the key and
     * its corresponding value are strings, including the
     * keys in the default property list.
     */
    
    class PropertiesDemo
    {
    
        public static void main(String[] args) throws IOException
        {
            FileReader fileReader = null;
            try
            {
                fileReader = new FileReader("db.properties");
    
                Properties p = new Properties();
                /*
                 * Reads a property list (key and element pairs)
                 * from the input character stream in a simple
                 * line-oriented format.
                 */
                p.load(fileReader);
    
                /*
                 * Returns a set of keys in this property list
                 * where the key and its corresponding value are
                 * strings, including distinct keys in the
                 * default property list if a key of the same
                 * name has not already been found from the main
                 * properties list.
                 */
                Set<String> set = p.stringPropertyNames();
    
                Iterator<String> itr = set.iterator();
    
                while (itr.hasNext())
                {
                    String key = (String) itr.next();
                    String value = p.getProperty(key);
                    System.out.println("Key = " + key + " , Value = " + value);
                }
    
            }
            finally
            {
                if (fileReader != null)
                {
                    fileReader.close();
                }
            }
        }
    }
    
    Output
    Key = user , Value = root 
    Key = password , Value = oracle 
    
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/PropertiesDemo_stringPropertyNames_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/fecc858ed896ce9bbf3cb92f5d438fc2de9eee22/BasicJava/PropertiesDemo_stringPropertyNames_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
  • Java Tutorial: Properties class in java [How to get the keys using propertyNames method]


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=hyPnVZSukyY&list=UUhwKlOVR041tngjerWxVccw

    db.properties
    Java Tutorial: Properties class in java [How to get the keys using propertyNames method] 
    PropertiesDemo.java
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.Enumeration;
    import java.util.Properties;
    
    /*
     * public Enumeration<?> propertyNames()
     *  
     * Returns: 
     * --------
     * 
     * an enumeration of all the keys in this property list,
     * including the keys in the default property list.
     */
    
    class PropertiesDemo
    {
    
        public static void main(String[] args) throws IOException
        {
            FileReader fileReader = null;
            try
            {
                fileReader = new FileReader("db.properties");
    
                Properties p = new Properties();
                /*
                 * Reads a property list (key and element pairs)
                 * from the input character stream in a simple
                 * line-oriented format.
                 */
                p.load(fileReader);
    
                /*
                 * Returns an enumeration of all the keys in
                 * this property list, including distinct keys
                 * in the default property list if a key of the
                 * same name has not already been found from the
                 * main properties list.
                 */
                Enumeration<?> enumeration = p.propertyNames();
    
                while (enumeration.hasMoreElements())
                {
                    String key = (String) enumeration.nextElement();
                    String value = p.getProperty(key);
    
                    System.out.println("Key = " + key + " , Value = " + value);
                }
    
            }
            finally
            {
                if (fileReader != null)
                {
                    fileReader.close();
                }
            }
        }
    }
    
    Output
    Key = user , Value = root 
    Key = password , Value = oracle 
    
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/PropertiesDemo_propertyNames_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/fecc858ed896ce9bbf3cb92f5d438fc2de9eee22/BasicJava/PropertiesDemo_propertyNames_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
  • Java Tutorial: Properties class in java [How to get the default value if the key is not present]


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=6Ap2aCqLuNM&list=UUhwKlOVR041tngjerWxVccw

    db.properties
    Java Tutorial: Properties class in java [How to get the default value if the key is not present] 
    PropertiesDemo.java
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.Properties;
    
    /*
     * public String getProperty(String key, String
     *                                      defaultValue)
     * 
     * Parameters: 
     * ----------
     * 
     * key - the hashtable key. 
     * 
     * defaultValue - a default value.
     * 
     * Returns: 
     * -------
     * 
     * the value in this property list with the specified
     * key value.
     */
    
    class PropertiesDemo
    {
    
        public static void main(String[] args) throws IOException
        {
            FileReader fileReader = null;
            try
            {
                fileReader = new FileReader("db.properties");
    
                Properties p = new Properties();
                /*
                 * Reads a property list (key and element pairs)
                 * from the input character stream in a simple
                 * line-oriented format.
                 */
                p.load(fileReader);
    
                /*
                 * Searches for the property with the specified
                 * key in this property list. If the key is not
                 * found in this property list, the default
                 * property list, and its defaults, recursively,
                 * are then checked. The method returns the
                 * default value argument if the property is not
                 * found.
                 */
    
                String user = p.getProperty("user", "system");
                String password = p.getProperty("password", "Oracle");
    
                System.out.println("user = "+user);
                System.out.println("password = "+password);
            }
            finally
            {
                if (fileReader != null)
                {
                    fileReader.close();
                }
            }
        }
    }
    
    Output
    user = root 
    password = Oracle
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/PropertiesDemo_default_Value_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/fecc858ed896ce9bbf3cb92f5d438fc2de9eee22/BasicJava/PropertiesDemo_default_Value_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
  • Java Tutorial: Properties class in java | Java properties tutorial


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=8GU6d2560F4&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial: Properties class in java | Java properties tutorial 
    db.properties
    Java Tutorial: Properties class in java | Java properties tutorial 
    PropertiesDemo.java
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.Properties;
    
    /*
     * public String getProperty(String key)
     *
     * Parameters:
     * ----------
     *
     * key - the property key.
     *
     * Returns:
     * -------
     *
     * the value in this property list with the specified
     * key value.
     */
    class PropertiesDemo
    {
    
        public static void main(String[] args) throws IOException
        {
            FileReader fileReader = null;
            try
            {
                fileReader = new FileReader("db.properties");
    
                Properties p = new Properties();
                /*
                 * Reads a property list (key and element pairs)
                 * from the input character stream in a simple
                 * line-oriented format.
                 */
                p.load(fileReader);
    
                /*
                 * Searches for the property with the specified
                 * key in this property list.
                 */
                String user = p.getProperty("user");
                String password = p.getProperty("password");
    
                System.out.println("user = "+user);
                System.out.println("password = "+password);
            }
            finally
            {
                if (fileReader != null)
                {
                    fileReader.close();
                }
            }
        }
    }
    
    Output
    user = root 
    password = oracle 
    
    Refer:
    https://docs.oracle.com/javase/8/docs/api/index.html?java/util/Properties.html

    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/PropertiesDemo_Intro_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/537077189473458d05cdafa94c7c54305b3f3b9e/BasicJava/PropertiesDemo_Intro_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
  • Java Tutorial : Java Threads (Thread vs Runnable_V2)


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=iSXy1jMW2Q8&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial : Java Threads (Thread vs Runnable_V2) 
    Java Tutorial : Java Threads (Thread vs Runnable_V2) 
    Java Tutorial : Java Threads (Thread vs Runnable_V2) 
    Java Tutorial : Java Threads (Thread vs Runnable_V2) 
    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
  • Java Tutorial : Java Threads (Thread vs Runnable_V1)


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=_9_ecVaVrOM&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial : Java Threads (Thread vs Runnable_V1) 
    Java Tutorial : Java Threads (Thread vs Runnable_V1) 
    Java Tutorial : Java Threads (Thread vs Runnable_V1) 
    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