"Java Common class demo"

Source: Internet
Author: User
Tags set set

First, the Java.lang.System class.

Systemextends Object

This class contains some useful class fields and methods. It cannot be instantiated.

In the System facilities provided by the class, there are standard input, standard output and error output streams, access to externally defined properties and environment variables, methods for loading files and libraries, and a practical way to quickly copy part of an array.

1. Currenttimemillis method.

The method returns the millisecond value of the current system time.

long currenttime=system.currenttimemillis ();        System.out.println (currenttime); // gets the millisecond value of the current time to midnight 1970.1.1. 

2. Key methods: GetProperties, GetProperty and SetProperty methods.

getProperties ()
GetProperty (String key)
GetProperty (String key,string def)

setproperties (Properties props)

The first three methods are the methods used to get the system properties, the method to get all the properties, the second method and the third method are the methods to get a system property based on key.

The fourth method is to add the specified system attributes (key-value pairs) to the system property set.

Properties is a subclass of Hashtable, so it also holds key-value pairs. But it doesn't have generics, and it has its own way of traversing:

Gets the set set of keys by using the Stringpropertyname () method.

Stringpropertynames ()

The value is obtained by the GetProperty method based on the key.

 String getProperty(String key)
Searches for a property in this property list with the specified key.
 String getProperty(String key, String defaultValue)
Searches for a property in the property list with the specified key.

"Java Common class demo"

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.