JAVA 45th-Other Object API (1), javaapi

Source: Internet
Author: User
Tags natural logarithm time in milliseconds

JAVA 45th-Other Object API (1), javaapi

I. System class

1.

static long currentTimeMillis()Returns the current time in milliseconds.

In fact, the time difference between the current time and the Coordinated Universal Time at midnight, January 1, January 1, 1970 (measured in milliseconds ).

Long time = 1414069291407l; // lSystem. out. println (time) is added to the long type );

2.

Static void exit (int status) terminates the currently running Java virtual machine.

Static void gc () run the Garbage Collector

3. Key Points

staticProperties GetProperties determines the current system property.
Import java. util. properties; import java. util. set; public class Main {// get the linefeed of the current operating System public static final String LINE_SEPARATOR = System. getProperty ("line. separator "); public static void main (String [] args) {// obtain system attribute information, and stored in the Properties set. The // properties set stores String-type key-value pairs. util. hashtable <Object, Object> // it is best to use your own storage and retrieval methods to complete element operations/* Set <String> stringPropertyNames () returns the key Set in this attribute list, the key and its corresponding value are strings. If a key with the same name is not found in the master attribute list, It also includes different keys in the default attribute list. */Properties pro = System. getProperties (); Set <String> set = pro. stringPropertyNames (); for (String string: set) {String value = pro. getProperty (string); // obtain the key value System. out. println (string + "-:-" + value);} // set the attribute information for the System. setProperty ("myname", "xxxxxx"); // The information is global and can be called by any program }}

Ii. Runtime class

When viewing the API documentation, we can clearly see that Runtime does not have a constructor (indicating that an object cannot be created), but there are non-static methods in the method abstract, there is a static getRuntime () method, which indicates that the Runtime class is designed using the singleton design mode.

Import java. io. IOException; public class Main {public static void main (String [] args) throws IOException, InterruptedException {Runtime r = Runtime. getRuntime (); // return a process // execute: execute xxxx.exe and call a local program. Note that an exception is thrown. // r.exe c ("notepad.exe "); // In this way, the write will be first found in the current path, and then the path // specified // r.exe c ("c: \ xxx \ LoL.exe "zookeeper was transferred to cmdr.exe c (" notepad.exe C :\\ HelloWorld. java "); // use the XX program to parse the XXX file. Note that the file must match Process p = r.exe c (" notepad.exe "); Thread. sleep (1000); // display for one second, kill, note that an exception is thrown p. destroy (); // kill sub-process }}

Iii. Math class

public final class Math 
 
 
extends Object

Note that it cannot be inherited

The Math class covers many mathematical functions and can fully challenge what you have learned. The Math method is static.

The ratio of the circumference to the diameter of the PI circle E is the base number of the natural logarithm.

Import java. io. IOException; import java. util. random; public class Main {public static void main (String [] args) {double d1 = Math. ceil (11.51); // returns the smallest integer greater than the value of double d2 = Math. floor (11.51); // returns the maximum integer less than the value of double d3 = Math. round (11.51); // returns rounded to System. out. println (d1); System. out. println (d2); System. out. println (d3); System. out. println (Math. max (4, 5); System. out. println (int) Math. pow (2, 3); // returns the power B of a for (int I = 0; I <10; I ++) {System. out. println (int) (Math. random () * 10); // 0-9 random number // System. out. println (Math. floor (Math. random () * 10);} Random ran = new Random (); // the Random object // returns the next pseudo-random number, it is a double value that is evenly distributed between 0.0 and 1.0 from the sequence of the random number generator. For (int I = 0; I <10; I ++) {// System. out. println (int) (ran. nextDouble () * 6 + 1); // the abbreviated form is as follows: int d = ran. nextInt (6) + 1; // nextInt is the method System in Random. out. println (d );}}}



How can I learn the API help documentation and learn useful information when I am studying JAVA? I am a cainiao and cannot find anything I want to use,

Many people may not be familiar with the Inner Class mentioned in Java. In fact, similar concepts also exist in C ++, that is, Nested Class ), the differences and connections between the two are compared in the following section. On the surface, the internal class defines another class in the class (as we can see below, the internal class can be defined in many places), but it is actually not that simple, at first glance, the internal class seems redundant. Its usefulness may not be so significant for beginners, but with its in-depth understanding, you will find that Java designers have a good heart for internal classes. Learning to use internal classes is part of advanced Java programming. It allows you to design your program structure more elegantly. The following describes how:

First meeting

Public interface Contents {
Int value ();
}

Public interface Destination {
String readLabel ();
}

Public class Goods {
Private class Content implements Contents {
Private int I = 11;
Public int value (){
Return I;
}
}

Protected class GDestination implements Destination {
Private String label;
Private GDestination (String whereTo ){
Label = whereTo;
}
Public String readLabel (){
Return label;
}
}

Public Destination dest (String s ){
Return new GDestination (s );
}
Public Contents cont (){
Return new Content ();
}
}

Class TestGoods {
Public static void main (String [] args ){
Goods p = new Goods ();
Contents c = p. cont ();
Destination d = p. dest ("Beijing ");
}
}

In this example, the class Content and GDestination are defined inside the class Goods and have the protected and private modifiers respectively to control the access level. Content represents Goods Content, while GDestination represents Goods destination. They implement the Content and Destination interfaces respectively. In the following main method, you can directly use Contents c and Destination d to perform operations. You don't even see the names of these two internal classes! In this way, the first benefit of the internal class is embodied-hiding the operations you don't want others to know, that is, encapsulation.

At the same time, we also found that the first method to get internal class objects out of the scope of the external class is to create and return the internal class objects using its external class method. The cont () and dest () methods in the preceding example do this. Is there any other way? Of course, the syntax format is as follows:

OuterObject = new outerClass (Constructor Parameters );

OuterClass. innerClass innerObject = outerObject. new InnerClass (Constructor Par ...... full text >>>

Who can give me a JAVA api document when I am learning java?

Java. SQL allows you to access and process data stored in the data source using the JavaTM programming language. (generally, it is recommended that you use the next API for a link. There are a lot of APIs on the Internet. Do you need to find your mailbox? I will send it to you, and 1.6 of the APIS will
 

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.