Home »
Code Examples »
Scala Code Examples
Scala - Get and Print all Environment Variables and System Properties Code Example
The code for Get and Print all Environment Variables and System Properties
import scala.collection.JavaConverters._
import scala.language.implicitConversions
// Getting & Printing environment variables
val environmentVars = System.getenv().asScala
for ((key,value) <- environmentVars) println(s"key: $key, value: $value")
// Getting & Printing system properties
val SystemPropVars = System.getProperties().asScala
for ((key,value) <- SystemPropVars) println(s"key: $key, value: $value")
/*
Output:
key: PATH, value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
key: SHELL, value: /bin/bash
key: HOSTNAME, value: jdoodle
key: PWD, value: /home
key: LANG, value: en_US.UTF-8
key: SHLVL, value: 1
key: HOME, value: /root
key: _, value: /usr/sbin/java
key: java.specification.version, value: 17
key: sun.jnu.encoding, value: UTF-8
key: java.class.path, value: ""
key: java.vm.vendor, value: Oracle Corporation
key: sun.arch.data.model, value: 64
key: java.vendor.url, value: https://openjdk.java.net/
key: java.vm.specification.version, value: 17
key: os.name, value: Linux
key: sun.java.launcher, value: SUN_STANDARD
key: user.country, value: US
key: sun.boot.library.path, value: /usr/lib/jvm/java-17-openjdk/lib
key: scala.home, value: /usr/share/scala
key: sun.java.command, value: scala.tools.nsc.MainGenericRunner jdoodle.scala
key: jdk.debug, value: release
key: sun.cpu.endian, value: little
key: user.home, value: /root
key: user.language, value: en
key: scala.boot.class.path, value: /usr/share/scala/lib/jline.jar:/usr/share/scala/lib/jna.jar:/usr/share/scala/lib/scala-compiler-doc.jar:/usr/share/scala/lib/scala-compiler.jar:/usr/share/scala/lib/scala-library.jar:/usr/share/scala/lib/scalap.jar:/usr/share/scala/lib/scala-reflect.jar:/usr/share/scala/lib/scala-repl-frontend.jar
key: java.specification.vendor, value: Oracle Corporation
key: java.version.date, value: 2021-10-19
key: java.home, value: /usr/lib/jvm/java-17-openjdk
key: file.separator, value: /
key: java.vm.compressedOopsMode, value: 32-bit
key: line.separator, value:
key: java.vm.specification.vendor, value: Oracle Corporation
key: java.specification.name, value: Java Platform API Specification
key: sun.management.compiler, value: HotSpot 64-Bit Tiered Compilers
key: java.runtime.version, value: 17.0.1+12
key: user.name, value: root
key: path.separator, value: :
key: os.version, value: 5.4.0-121-generic
key: java.runtime.name, value: OpenJDK Runtime Environment
key: file.encoding, value: UTF-8
key: scala.usejavacp, value: true
key: java.vm.name, value: OpenJDK 64-Bit Server VM
key: java.vendor.url.bug, value: https://bugreport.java.com/bugreport/
key: java.io.tmpdir, value: /tmp
key: java.version, value: 17.0.1
key: user.dir, value: /home
key: os.arch, value: amd64
key: java.vm.specification.name, value: Java Virtual Machine Specification
key: native.encoding, value: UTF-8
key: java.library.path, value: /usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib
key: java.vm.info, value: mixed mode
key: java.vendor, value: N/A
key: java.vm.version, value: 17.0.1+12
key: sun.io.unicode.encoding, value: UnicodeLittle
key: java.class.version, value: 61.0
*/
Code by IncludeHelp,
on August 11, 2022 00:18