Java: Get the current system environment and system properties
Java Basic: Exercise-88 with Solution
Write a Java program to get the current system environment and system properties.
Pictorial Presentation:
Sample Solution:
Java Code:
import java.lang.*;
public class Exercise88 {
public static void main(String[] args) {
// Print a message indicating the display of the current system environment
System.out.println("\nCurrent system environment:");
// Retrieve and print the system environment variables using System.getenv()
System.out.println(System.getenv());
// Print a message indicating the display of the current system properties
System.out.println("\n\nCurrent system properties:");
// Retrieve and print the system properties using System.getProperties()
System.out.println(System.getProperties());
}
}
Sample Output:
Current system environment: {PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr /games:/usr/local/games, LESSCLOSE=/usr/bin/lesspipe %s %s, COMP_WORDBR EAKS= "'><;|&(:, JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java, TE RM=xterm, XFILESEARCHPATH=/usr/dt/app-defaults/%L/Dt, LANG=en_US.UTF-8, XDG_SESSION_ID=2, MAIL=/var/mail/students, LIBVIRT_DEFAULT_URI=qemu:// /system, LOGNAME=students, PWD=/home/students/b25a3500-573c-11e7-b9f3-f db9bc0efa62, _=/usr/bin/timeout, LESSOPEN=| /usr/bin/lesspipe %s, SHELL =/bin/bash, SSH_TTY=/dev/pts/0, SSH_CLIENT=192.168.0.102 50450 22, OLDP WD=/home/students, USER=students, SSH_CONNECTION=192.168.0.102 50450 19 2.168.0.200 22, NLSPATH=/usr/dt/lib/nls/msg/%L/%N.cat, XDG_RUNTIME_DIR= /run/user/1003, LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;3 5:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43: ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*. arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:* .lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31 :*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo =01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz= 01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar =01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7 z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.b mp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*. xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35 :*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01; 35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v= 01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=0 1;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl= 01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf= 01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a =00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.o gg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*. xspf=00;36:, SHLVL=3, HOME=/home/students} Current system properties: {java.runtime.name=Java(TM) SE Runtime Environment, sun.boot.library.pa th=/opt/jdk/jdk1.8.0_71/jre/lib/amd64, java.vm.version=25.71-b15, 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.country=US, sun.java.launcher=SUN_STANDARD, s un.os.patch.level=unknown, java.vm.specification.name=Java Virtual Mach ine Specification, user.dir=/home/students/b25a3500-573c-11e7-b9f3-fdb9 bc0efa62, java.runtime.version=1.8.0_71-b15, java.awt.graphicsenv=sun.a wt.X11GraphicsEnvironment, java.endorsed.dirs=/opt/jdk/jdk1.8.0_71/jre/ lib/endorsed, os.arch=amd64, java.io.tmpdir=/tmp, line.separator= , java.vm.specification.vendor=Oracle Corporation, os.name=Linux, sun.j nu.encoding=UTF-8, java.library.path=/usr/java/packages/lib/amd64:/usr/ lib64:/lib64:/lib:/usr/lib, java.specification.name=Java Platform API S pecification, java.class.version=52.0, sun.management.compiler=HotSpot 64-Bit Tiered Compilers, os.version=4.4.0-47-generic, user.home=/home/s tudents, user.timezone=, java.awt.printerjob=sun.print.PSPrinterJob, fi le.encoding=UTF-8, java.specification.version=1.8, java.class.path=., u ser.name=students, java.vm.specification.version=1.8, sun.java.command= Exercise88, java.home=/opt/jdk/jdk1.8.0_71/jre, sun.arch.data.model=64, user.language=en, java.specification.vendor=Oracle Corporation, awt.to olkit=sun.awt.X11.XToolkit, java.vm.info=mixed mode, java.version=1.8.0 _71, java.ext.dirs=/opt/jdk/jdk1.8.0_71/jre/lib/ext:/usr/java/packages/ lib/ext, sun.boot.class.path=/opt/jdk/jdk1.8.0_71/jre/lib/resources.jar :/opt/jdk/jdk1.8.0_71/jre/lib/rt.jar:/opt/jdk/jdk1.8.0_71/jre/lib/sunrs asign.jar:/opt/jdk/jdk1.8.0_71/jre/lib/jsse.jar:/opt/jdk/jdk1.8.0_71/jr e/lib/jce.jar:/opt/jdk/jdk1.8.0_71/jre/lib/charsets.jar:/opt/jdk/jdk1.8 .0_71/jre/lib/jfr.jar:/opt/jdk/jdk1.8.0_71/jre/classes, java.vendor=Ora cle Corporation, file.separator=/, java.vendor.url.bug=http://bugreport .sun.com/bugreport/, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.end ian=little, sun.cpu.isalist=}
Flowchart:
Java Code Editor:
Previous: Write a Java program than read an integer and calculate the sum of its digits and write the number of each digit of the sum in English.
Next: Write a Java program to check whether a security manager has already been established for the current application or not.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/java-exercises/basic/java-basic-exercise-88.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics