How to use System to get system environment variables

The System system class contains some useful class variables and class methods, which can be called through the System class. But it cannot be instantiated. The System class represents the running platform of the current program, and the program cannot create objects of the System class.
Let’s share the code application of the System class today. By practicing the basic code, you can quickly understand the application of the System class methods and variables.
Related variables and methods:
·System.out: stands for standard output stream ()
·Scanner: generally used to obtain console input
·endsWith: Determine whether this string has a suffix of "0"
·System.err: represents the standard error output stream ()
·System.in: Represents the standard input stream, which is keyboard input ()
·hasNext(): Determine whether there is another input item
· gc(): The function of the function is only to remind the virtual machine that it wants to perform a garbage collection.
·\n: line feed
code segment:

public class SystemClassDemo {
	public static void main(String[] args) {
		//Output
		 System.out.println("standard output stream");
		     		    //keyboard input 
				Scanner sc = new Scanner(System.in);
				while (sc.hasNext()) {
					String string = (String) sc.next();
					 System.out.println("Keyboard input content is:" + string);
					if (string.endsWith("0")) {
						break;
					}
				}

Results of the:

//--------------------------------------------------------------------

		System.out.println("---Get all the environment variables of the system System.getenv()---");
			Map<String,String> map = System.getenv();
			Set<String> keySet = map.keySet();
			for (String key : keySet) {
				System.out.println(key + "===>" + map.get(key));
			}
		 System.out.println("---Get a single system environment variable getenv()---");
			System.out.println(System.getenv("JAVA_HOME")+"\n");
		 System.out.println("---Get system properties getProperties()---");
			System.out.println(System.getProperties()+"\n");
		 System.out.println("---Get a single system property getProperties()---");
			System.out.println(System.getProperty("user.name")+"\n");
		 System.out.println("---System garbage collection gc()---");
			System.gc();

Results of the:

//--------------------------------------------------------------------

	System.out.println("---returns the time difference between the current time and midnight UTC January 1, 1970 currentTimeMillis()---");
		System.out.println(System.currentTimeMillis()+"\n");
	 System.out.println("---nanosecond[1 millisecond(ms)=1000000nanosecond(ns)]nanoTime()---");
		System.out.println(System.nanoTime()+"\n");
	 System.out.println("---returns the exact hashCode value of the specified object identityHashCode()---");
		String str1 = new String("Hello");
		String str2 = new String("Hello");
	    System.out.println(System.identityHashCode(str1) + "\t" + System.identityHashCode(str2));
	 // str1 and str2 are different string objects, so their identityHashCode values ​​are different
	String str3 = "world";
	String str4 = "world";
		System.out.println(System.identityHashCode(str3) + "\t" + System.identityHashCode(str4)+"\n");
	 // str3 and str4 are the same string object, so their identityHashCode value is the same
	 System.out.println("----Stop the running virtual machine, exit the program exit()---");
		System.exit(0);
}
}

Results of the:

//--------------------------------------------------------------------
Guess the article you like:
2018UI Course Summary (UI Theory)
What are Java arithmetic operators?
The moment the programmer burst into tears, I couldn’t help but laugh
How to write Oracle constraints?
AE basic interface setting and rotating loading case
"Hotel management system-sauna, foot massage module" project development stage summary
Oracle basic knowledge summary
PS shortcut
How to use Oracle view?
AE dot loading animation production process

Intelligent Recommendation

Java get environment variables and get and set system variables

1. Java obtains environment variables The way Java gets environment variables is very simple: System.getEnv() Get all environment variables System.getEnv(key) Get the value of an environment variable ...

Get JVM environment variables and operating system environment variables

Get environment variables The environment variable here refers to the environment variable associated with the JVM, such as the environment variable set in the following way. There are also some prede...

Spring - How to get system environment variables and variables in the Application configuration file? (EnvironmentaWare)

problem How do I get system environment variables and variables in the Application configuration file? solve Use EnvironmentaWare. Implement the interface environmentaWare and override the method Sten...

C # set and get the system environment variables

C # settings and environment variables 1 Introduction 2. Code Static method in class Environment Environment variables: Set the environment variable: PS: This method of setting environment variables w...

Linux system view, set, get environment variables

Environment variables of linux system Operating system environment variables generally refer to some parameters used to specify the operating environment of the system Common environment variables are...

More Recommendation

Python get system environment variables os.environ and os.putenv

Speaking from a piece of code "if "BATCH_CONFIG_INI" in os.environ:" to determine whether the value of the environment variable is defined If defined, go to the value of the enviro...

C# set and get system environment variables

C# set and get environment variables 1 Introduction 2. Code Static methods under the Environment class Get environment variables: Set environment variables: PS: This method of setting environment vari...

Java| Get system properties and environment variables

Preface Environment variables: 1. View and set environment variables in command line mode 2. View and set environment variables in Java System properties(System properties are obtained and set by Java...

Android guide to get and set system environment variables

       Android Guide to Obtaining and Setting System Environment Variables Preface During the analysis of Android source code, System.getenv("xxx") and get...

GO language - get system environment variables

Why can't 80% of the code farmers can't do architects? >>>   GO language - get system environment variables Study notes   Reprinted on: https: //my.oschina.net/golang/blog/7750...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top