Java Common Classes

Source: Internet
Author: User

First, the System class

The System class represents the current running platform for Java,

System is a final class, and all property methods of that class are static.

In the class (standard input), out (standard output), ERR (Error output stream),

The system class is commonly used to log program execution time, copy arrays, determine current system properties, and get environment variables.

System common methods

Currenttimemillis (): Returns the current time in milliseconds.

Exit (int status): Terminates the currently running Java Virtual machine

GetProperties (): Determines the current system properties.

GetProperty (String key): Gets the system properties indicated by the specified key.

Nanotime (): Returns the current value of the most accurate available system timer, in nanoseconds.

GC (): Runs the garbage collector.

Ex1:ststrm. Currenttimemillis (); Returns the number of milliseconds from January 1, 1970 to the current time

EX2: Calculate the time of the loop run

public class processtime{

public static void Main (String args[]) {

Long beginTime = ststrm.currenttimemillis ();

for (int i=0;i<10000;i++) {

Looping statements

}

Long endTime = ststrm.currenttimemillis ();

System.out.print (endTime - beginTime ); Calculate the cycle run time

}

}

System-Tired getproperties () and g Etproperty (String key) method to obtain system-related properties

System Property sheet

java.version Java Runtime Environment version

Java.vendor Java Runtime Environment vendor

Java.vendor.url java vendor's URL

java.home Java installation directory

java.vm.specification.version Java Virtual Machine specification version

Java.vm.specification.vendor Java Virtual Machine Specification provisioning

java.vm.specification.name Java Virtual Machine Specification name

java.vm.version Java Virtual Machine implementation version

Java.vm.vendor Java Virtual machine implementation provider

java.vm.name Java Virtual machine implementation name

java.specification.version Java Runtime Environment specification version

Java.specification.vendor Java Runtime Environment specification vendor

java.specification.name Java Runtime Environment specification name

java.class.version Java class format version number

Java.class.path java classpath

Java.library.path List of paths to search when loading libraries

Java.io.tmpdir The default temporary file path

Java.compiler The name of the JIT compiler to use

java.ext.dirs path to one or more extended directories

os.name Name of the operating system

Architecture of the Os.arch operating system

os.version version of the operating system

file.separator file delimiter ("/" in UNIX system)

path.separator Path Delimiter (":" in UNIX system)

line.separator Line delimiter ("/n" in UNIX systems)

user.name User's account name

user.home User's home directory

user.dir User's current working directory

Terminating the virtual machine, exiting the executing program: system.exit (0);

Second, runtime class

The runtime class represents the current runtime environment of Java,

Each Java program has a runtime instance corresponding to it,

The application is connected to its run-time environment through this object.

Application cannot create its own runtime Real, but can be runtime Get< span> class Font-family: in italics; font-size:18px; Color: #003366; " >runtime () gets the runtime object.

After getting the runtime object , we can use the runtime class-related methods to access information about the JVM, including processor information, memory information, and so on.

ex:/*

Demonstrates how to run an operating system command with the runtime class Access program run-time environment

*/

public class runtimedemo{

public static void Main (String args[]) {

runtime rt=runtime. Getruntime();

System.out.println ("Current number of processors:" +rt.availableprocessors ());

System.out.println ("Number of free Memory:" +rt.freememory ());

System.out.println ("Total ram :" +rt.total memory());

SYSTEM.OUT.PRINTLN ("Maximum available memory :" +rt.max ());

Running operating system commands (ex: running Windows Notepad)

try{

Rt.exec ("notepad.exe");

}catch (Exception e) {

E.printstacktrace ();

}

}

}

For more information, refer to the system and runtime class related methods documentation in the Java.lang package.

Third, string related classes

Java Common Classes

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.