MENU

Output Java system properties in an easy-to-read format

TOC

Java system propertyoutput in alphabetical order. System.getProperties()

Javaindicates certainty, emphasis, etc.system propertyHere is a sample program that outputs keys and values in alphabetical order for easy viewing.
Once stored in the TreeMap, the data is sorted alphabetically before output.

Usually the following method is well presented, but it is very difficult to see because the values are broken in the middle and not alphabetically ordered.

Properties props = System.getProperties();
props.list(System.out);
-- listing properties -- java.runtime.name=Java(TM) 2 Runtime Environment, Stand... sun.boot.library.path=C:\develop\Java\jdk1.5.0_08\jre\bin java.vm.version=1.5.0_08-b03 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=JP sun.os.patch.level=Service Pack 2 java.vm.specification.name=Java Virtual Machine Specification user.dir=C:\apps\0-app java.runtime.version=1.5.0_08-b03 java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment java.endorsed.dirs=C:\develop\Java\jdk1.5.0_08\jre\lib\e... os.arch=x86 java.io.tmpdir=C:\DOCUME~1\***\LOCALS~1\Temp\ line.separator= java.vm.specification.vendor=Sun Microsystems Inc. user.variant= os.name=Windows XP sun.jnu.encoding=MS932 java.library.path=C:\develop\Java\jdk1.5.0_08\bin;.;C:\... java.specification.name=Java Platform API Specification java.class.version=49.0 sun.management.compiler=HotSpot Client Compiler os.version=5.1 user.home=C:\Documents and Settings\**** user.timezone= java.awt.printerjob=sun.awt.windows.WPrinterJob file.encoding=MS932 java.specification.version=1.5 user.name=**** java.class.path=C:\apps\0-app\bin;C:\apps\0-app\jre1.... java.vm.specification.version=1.0 sun.arch.data.model=32 java.home=C:\develop\Java\jdk1.5.0_08\jre java.specification.vendor=Sun Microsystems Inc. user.language=ja awt.toolkit=sun.awt.windows.WToolkit java.vm.info=mixed mode, sharing java.version=1.5.0_08 java.ext.dirs=C:\develop\Java\jdk1.5.0_08\jre\lib\ext sun.boot.class.path=C:\develop\Java\jdk1.5.0_08\jre\lib\r... java.vendor=Sun Microsystems Inc. file.separator=\ java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport... sun.cpu.endian=little sun.io.unicode.encoding=UnicodeLittle sun.desktop=windows sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+m...


sample program

/** * Prints system property keys and values in alphabetical order. */ public static void outputSystemProperties() { Properties p = System.getProperties(); TreeMap map = new TreeMap(); map.putAll(p); Iterator itr = map.keySet().iterator(); while (itr.hasNext()) { String key = (String)itr.next(); String value = (String)map.get(key); System.out.println(key + "=" + value);

Execution Result

◆Example of Execution

public static void main(String[] args) { outputSystemProperties();

◆Output result

awt.toolkit=sun.awt.windows.WToolkit file.encoding=MS932 file.encoding.pkg=sun.io file.separator=\ java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment java.awt.printerjob=sun.awt.windows.WPrinterJob java.class.path=C:\apps\0-app\bin;C:\apps\0-app\jre1.6.0\lib\rt.jar;C:\apps\0-app\sys\lib\bcprov-jdk14-123.jar java.class.version=49.0 java.endorsed.dirs=C:\develop\Java\jdk1.5.0_08\jre\lib\endorsed java.ext.dirs=C:\develop\Java\jdk1.5.0_08\jre\lib\ext java.home=C:\develop\Java\jdk1.5.0_08\jre java.io.tmpdir=C:\DOCUME~1\***\LOCALS~1\Temp\ java.library.path=C:\develop\Java\jdk1.5.0_08\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\develop\Java\jdk1.5.0_08\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\ProgramFilesDevelop\TOOLS\ant-1.6.1\bin;C:\develop\eclipse32\extensions\tptp-4.2.0\agent-controller\\bin;C:\Program Files\QuickTime\QTSystem\ java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition java.runtime.version=1.5.0_08-b03 java.specification.name=Java Platform API Specification java.specification.vendor=Sun Microsystems Inc. java.specification.version=1.5 java.vendor=Sun Microsystems Inc. java.vendor.url=http://java.sun.com/ java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi java.version=1.5.0_08 java.vm.info=mixed mode, sharing java.vm.name=Java HotSpot(TM) Client VM java.vm.specification.name=Java Virtual Machine Specification java.vm.specification.vendor=Sun Microsystems Inc. java.vm.specification.version=1.0 java.vm.vendor=Sun Microsystems Inc. java.vm.version=1.5.0_08-b03 line.separator= os.arch=x86 os.name=Windows XP os.version=5.1 path.separator=; sun.arch.data.model=32 sun.boot.class.path=C:\develop\Java\jdk1.5.0_08\jre\lib\rt.jar;C:\develop\Java\jdk1.5.0_08\jre\lib\i18n.jar;C:\develop\Java\jdk1.5.0_08\jre\lib\sunrsasign.jar;C:\develop\Java\jdk1.5.0_08\jre\lib\jsse.jar;C:\develop\Java\jdk1.5.0_08\jre\lib\jce.jar;C:\develop\Java\jdk1.5.0_08\jre\lib\charsets.jar;C:\develop\Java\jdk1.5.0_08\jre\classes sun.boot.library.path=C:\develop\Java\jdk1.5.0_08\jre\bin sun.cpu.endian=little sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86 sun.desktop=windows sun.io.unicode.encoding=UnicodeLittle sun.jnu.encoding=MS932 sun.management.compiler=HotSpot Client Compiler sun.os.patch.level=Service Pack 2 user.country=JP user.dir=C:\apps\0-app user.home=C:\Documents and Settings\*** user.language=ja user.name=*** user.timezone= user.variant=

I see that all information is listed in alphabetical order.
Especially if all java.class.path, java.library.path, etc. are not shown, it will take a long time to solve the problem.

java.class.path=C:\apps\0-app\bin;C:\apps\0-app\jre1....
        ↓arrow (mark or symbol)
java.class.path=C:\apps\0-app\bin;C:\apps\0-app\jre1.6.0\lib\rt.jar;C:\apps\0-app\sys\lib\bcprov-jdk14-123.jar

summary

This article explains how to organize Java system properties in alphabetical order for easy viewing. With normal property output methods, the information is cut off or displayed out of order, making it difficult to read.TreeMapUsing this to sort and output the properties makes it easier to understand. A concrete example program is introduced to provide a method for Java programmers to check system properties efficiently.

For those with skills as a Java programmer, side jobs are highly recommended. This is because Java is widely used in the development of corporate mission-critical systems and web applications, and is in high demand. By using Java as a side job, you can not only increase your income, but also improve your skills and learn new technologies.

TOC