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".
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\ |
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; |
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 |
: |
|
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 |
: |
|
sun.boot.class.path |
: |
|
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 |
: |