[an error occurred while processing this directive]

Get Property by Name

                         

In this Tutorial we want to describe you a code that helps you in understanding to get Property by Name. For this we have a class name "Get Property By Name". Inside the main method  we have the list of method that help you to get the Properties of  System-

1)System.getProperties ( ) -  This Method returns you current system properties by assigning an instance of properties class and store the current system properties in it.

2)stringPropertyNames( ) -   This Method returns you the current system properties in a Set object  set (Collection interface).

3)Iterator ( )                     -   This allow you to traverse the list of element in a collection.

We declare a String variable name key inside the main method followed by while loop, that  is used to evaluate or check more element present in a iterator .If more element is present, the iterator call next( ).to string returns you the next element in the iterator, convert it into a string and store in a String variable key. The System.out.println is used to print the properties of the system by calling properties.getProperty( key).

GetPropertyByName.java

import java.util.*;

public class GetPropertyByName {

    public static void main(String args[]) {

        Properties properties = System.getProperties();
        Set set = properties.stringPropertyNames();
        Iterator iterator = set.iterator();

        String key;
        while (iterator.hasNext()) {
            key = iterator.next().toString();

            System.out.print(key + " : ");
            System.out.println(properties.getProperty(key));
        }
    }
}

Output
java.runtime.name : Java(TM) SE Runtime Environment
sun.boot.library.path : C:\Program Files\Java\jdk1.6.0_01\jre\bin
java.vm.version : 1.6.0_01-b06
java.vm.vendor : Sun Microsystems Inc.
java.vendor.url : http://java.sun.com/
path.separator : ;
java.vm.name : Java HotSpot(TM) Client VM
file.encoding.pkg : sun.io
user.country : SUN_STANDARD
sun.java.launcher : US
sun.os.patch.level : Service Pack 4
java.vm.specification.name : Java Virtual Machine Specification
user.dir : C:\Documents and Settings\Administrator\
My Documents\NetBeansProjects\GetExample
java.runtime.version : 1.6.0_01-b06
java.awt.graphicsenv : sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs : C:\Program Files\Java\jdk1.6.0_01\jre\lib\endorsed
os.arch : x86
java.io.tmpdir : C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\
line.separator :  
java.vm.specification.vendor : Sun Microsystems Inc.
user.variant :  
os.name : Windows 2000
sun.jnu.encoding : Cp1252
java.library.path : C:\ProgramFiles\Java\jdk1.6.0_01\jre\bin;
.;
C:\WINNT\Sun\Java\bin;C:\WINNT\system32;
C:\WINNT;.;C:\Program Files\Java\jdk1.6.0_01\bin;
C:\maven-2.0.7\bin;
C:\Program Files\Apache Software
Foundation\Tomcat 6.0\bin;
C:\Program Files\apache-ant-1.7.1\bin;
C:\GNUstep\GNUstep\System\Library\
Headers\Foundation;
C:\baadshah\GNUstep\mingw\bin;
C:\baadshah\GNUstep\GNUstep\System\Tools
java.specification.name : Java Platform API Specification
java.class.version : 50.0
sun.management.compiler : HotSpot Client Compiler
os.version : 5.0
user.home : C:\Documents and Settings\Administrator
user.timezone :  
java.awt.printerjob : sun.awt.windows.WPrinterJob
file.encoding : Cp1252
java.specification.version : 1.6
user.name :

C:\Documents and Settings\Administrator\
My Documents\NetBeansProjects\
GetExample\build\classes

java.class.path : Administrator
java.vm.specification.version : 1.0
sun.arch.data.model : C:\Program Files\Java\jdk1.6.0_01\jre
java.home : 32
java.specification.vendor : en
user.language : Sun Microsystems Inc.
awt.toolkit : sun.awt.windows.WToolkit
java.vm.info : mixed mode, sharing
java.version : 1.6.0_01
java.ext.dir :

C:\Program Files\Java\jdk1.6.0_01\jre\lib\ext;
C:\WINNT\Sun\Java\lib\ext

sun.boot.class.path :

C:\Program Files\Java\
jdk1.6.0_01\jre\lib\resources.jar;

C:\Program Files\Java\
jdk1.6.0_01\jre\lib\rt.jar;

C:\Program Files\Java\
jdk1.6.0_01\jre\lib\sunrsasign.jar;

C:\Program Files\Java\
jdk1.6.0_01\jre\lib\jsse.jar;

C:\Program Files\Java\
jdk1.6.0_01\jre\lib\jce.jar;

C:\Program Files\Java\
jdk1.6.0_01\jre\lib\charsets.jar;

C:\Program Files\Java\
jdk1.6.0_01\jre\classes

java.vendor : Sun Microsystems Inc.
file.separator : \
java.vendor.url.bug : http://java.sun.com/cgi-bin/bugreport.cgi
sun.cpu.endian : UnicodeLittle
sun.io.unicode.encoding : little
sun.desktop : windows
sun.cpu.isalist :  
 

Download code

                         

[an error occurred while processing this directive]