Mega Code Archive

 
Categories / Java Tutorial / Development
 

Returns a default value if the specified property does not exist

public static String getProperty (String key, String default) public class MainClass{   public static void main(String[] args){      System.out.println(System.getProperty("password","defaultPassword"));    } } defaultPassword public class MainClass {   public static void main(String[] args) {       System.out.println("  OS name: " + System.getProperty("os.name", "not specified"));       System.out.println("  JVM Version: " + System.getProperty("java.version", "not specified"));       System.out.println("  user.home: " + System.getProperty("user.home", "not specified"));       System.out.println("  java.home: " + System.getProperty("java.home", "not specified"));   } } OS name: Windows XP JVM Version: 1.5.0 user.home: C:\Documents and Settings\yourname java.home: C:\Java_Dev\sdk\jdk\jre