1.Java Base System Object

Source: Internet
Author: User

Bi Xiangdong Teacher Java Basic Learning Note--system Object

After learning about the system object in Java today, it is important for us to feel this object for the following useful purposes.

1. Get the current operating system version and type.

2. Gets the environment variables in the path of the current operating system.

The sample code is as follows:

/*System: Methods and properties in a class are static. Out: Standard output, default is console. In: standard input, default is keyboard. Describe the system some information Get system property information: Propcrtics*/ImportJava.util.*;classsystemdemo{ Public Static voidMain (string[] args) {Properties prop=system.getproperties (); //because properties is a subclass of Hashtable, which is a subclass object of the collection of maps. //then the elements in the collection can be extracted by means of a map. //The collection is stored in a string and has no generic definition. //How do you customize some of the unique information in your system? //system.setproperty ("MyKey", "Nebula"); //Get all property value informationSystem.out.println ("+--------get all property information---------------+");  for(Object obj:prop.keySet ()) {String value=(String) prop.get (obj); System.out.println (obj+"::"+value); } System.out.println ("+--------Get the specified attribute information---------------+"); //gets the specified property informationString value=system.getproperty ("Os.name"); System.out.println ("Gets the specified operating system property information for:" +value); //is it possible to load some information dynamically when the JVM starts?
Note: To run the following code, be sure to follow the format: Java-dhaha=ssssssss Systemdemo.
String v=system.getproperty ("haha"); System.out.println ("V=" +v); }}

normal operation Please enter :

                javac Systemdemo.java                Java Systemdemo

Program:

To use dynamic loading for some information, enter:

                javac Systemdemo.java                  - dhaha=ssssssss Systemdemo

Program:

1.Java Base System Object

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.