Java System class use method sample get System Information _java

Source: Internet
Author: User

Common methods:

Copy Code code as follows:

Long Currenttimemillis (); Gets the millisecond value of the current time
void exit () terminates the currently running Java virtual machine.

Copy Code code as follows:

public static void Method () {
Long L = System.currenttimemillis ();
System.out.println (l);

System.exit ();
}

Describes system attribute information: Properties System.getproperties ();

The information obtained by this method is stored in the Properties collection
Because properties is a subclass of Hashtable, a subclass of the map collection, pour into the util package
Then you can retrieve the elements of the collection by using the Map method
The keys and values in the collection are stored in strings, no generic definitions

Copy Code code as follows:

public static void Method_properties () {
Get all property information for the current system
Properties prop = System.getproperties ();
Iterate through the property information in the prop, or you can use an iterator
For (Object Obj:prop.keySet ()) {
String value = (string) prop.get (obj);
System.out.println (obj+ "= = =" +value);


Get the corresponding property information by key
String value = System.getproperty ("Os.name");//If no this key returns null
System.out.println (value);
}
}


Customizing system information in the system

Copy Code code as follows:

public static void SetProperties () {
System.setproperty ("Makey", "myvalue");
System.out.println (System.getproperty ("Makey"));
}

Out: Standard output, default is monitor
In: standard input, default is keyboard

Related Article

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.