JAVA-based System

Source: Internet
Author: User

Overview: 1. the System class represents the current JAVA program running platform 2. the System class provides many static methods for System-level operations (see the program for details) [java] package com. cxy. f; import java. util. map; public class SystemTest {/*** System class method use test (java 7) */public static void main (String [] args) {// obtain all environment variables of the System, here we can find the familiar JAVA_HOME Map <String, String> env = System. getenv (); for (String one: env. keySet () {System. out. println (one + ":" + env. get (one);} // Of course, we can also directly obtain an environment variable, as long as you know its name System. ou T. println (System. getenv ("java_home"); System. out. println ("-----------------------------"); // For more information about System attributes, see java api System. out. println (System. getProperty ("OS. name "); System. out. println (System. getProperty ("java. vm. name "); System. out. println (System. getProperty ("java. version "); System. out. println (System. getProperty ("user. home "); System. out. println (System. getProperty ("user. dir "); System. out. print Ln ("-----------------------------"); // The hashCode calculated by the object address to identify the uniqueness of the object (newbie, Please bypass) String s1 = new String ("cxy "); string s2 = new String ("cxy"); www.2cto.com System. out. println ("is the hashCode of the s1 and s2 objects the same?" + (s1.hashCode () = s2.hashCode (); System. out. println ("Whether the hashCode calculated by the address of the object s1 and s2 is the same:" + (System. identityHashCode (s1) = System. identityHashCode (s2); String s3 = "cxy"; String s4 = "cxy"; System. out. println ("objects s3 and s4 are calculated by addresses Whether the hashCode is the same: "+ (System. identityHashCode (s3) = System. identityHashCode (s4); System. out. println ("---------------------------"); // two methods for obtaining the current System time (the time difference between midnight on January 1, January 1, 1970) System. out. println (System. currentTimeMillis (); // System in milliseconds. out. println (System. nanoTime (); // nanoTime System. out. println ("-----------------------------"); System. runFinalization (); // run the finalize method of the object. System. gc (); // run the Garbage Collector (officially explained). In fact, this kind of operation may be just the creation of a snapshot to run // terminate the currently running Java Virtual Machine (officially translated) // The actual call is Runtime. getRuntime (). exit (status) System. exit (0); // If the parameter is not 0, it indicates that the exception is terminated. Put it in the catch block where the exception is caught.} Note: there are still several questions not discussed here: load, loadLibrary, indicates the standard input, output, and error Field To be continued...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.