Java Common Classes

Source: Internet
Author: User
Tags square root time in milliseconds value of pi

A. Math class
The Math class provides a way to sequence basic mathematical and geometric functions.
The math class is the final class, and all of its member variables and member methods are static.
Common properties and methods of the math class:
Static constant--PI: Double value of pi
static method:
Double Pow (double A, double b) calculates the B-side of a
Double sqrt (double A) calculates the square root of a given value
int abs (int a) calculates the absolute value of the int type values A, and also receives parameters of type long, float, and double
Double Ceil (double A) returns the double value of the smallest integer greater than or equal to a
Double floor (double A) returns the double value of the largest integer less than or equal to a
int max (int a, int b) returns large values in the values A and B of type int, and also accepts parameters of type long, float, and double
int min (int a, int b) returns the smaller values in a and B, or can receive parameters of type long, float, and double
int round (float a); Rounding back integers
Double random () returns a double value with a positive sign that is greater than or equal to 0.0 and less than 1.0! []
Two. Random class
Objects of the random class can generate "pseudo-random numbers."
Common methods:
Public?int?nextint (int? bound)
Returns a pseudo-random integer value from 0 (inclusive) to bound (not included).

  public?boolean?nextBoolean() 返回一个“伪随机”的boolean值

Three. System class
Member variables
The system class contains in, out, and err three member variables representing the standard input stream (keyboard input), the standard output stream (display), and the standard error output stream (display).
Member Methods
public static void Arraycopy (object src, int srcpos, object dest, int destpos, int length)
Int[] A = {1,2,3,4};
Int[] B = new Int[5];
System.arraycopy (a,1,b,3,2);
Exit () method
public static void exit (int status)
The function of this method is to exit the program. Where status has a value of 0 for normal exit, not 0 for abnormal exit. By using this method, the program Exit function can be realized in the programming of graphical interface.
GC () method
public static void GC ()
The function of this method is to request the system for garbage collection. Whether the system is recovered immediately depends on the implementation of the garbage collection algorithm in the system and the implementation of the system.
Garbage collection, the Finalize () method is called before releasing non-Java resources
Currenttimemillis method
public static long Currenttimemillis ()
Returns the number of milliseconds from midnight January 1, 1970 to the current time in milliseconds
Four. Runtime class
Purpose: To correlate an application with its running environment
Obtain an instance by using the GetRuntime () static method.
EXEC executes the specified string command in a separate process, which returns the Process object, which can be killed by using the Destroy () method of the Procedure object
Five. Date class and SimpleDateFormat class
Date class: Represents the day and time
Methods for providing the components of the operation date and time
SimpleDateFormat class
format for customizing date and time
Date date = new Date (); Create Date Object
SimpleDateFormat sdf= New SimpleDateFormat ("yyyy-
Mm-dd HH:mm:ss ");//Custom date format
String now = Sdf.format (date);
System.out.println (now);
Six. Calendar class:
Abstract class
Used to set and get specific parts of date/time data

The Calendar class provides methods and static fields to manipulate calendars
int get (Int?field) returns the value of the given calendar field
Month indicator
Day_of_month indicates the day of the one month
Day_of_week indicates one day in one weeks! []

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.