JavaSE-JDK classes commonly based -System, Math class, BigInteger

1. System class

  • System class represents the system, system-level control many properties and methods are placed inside the class. Such java.lang package is located.
  • Because the class constructor is private, it is impossible to create objects of that class, that is, unable to instantiate the class. Member variable and its internal methods are static, so it can easily be called.

1.1 member variables

System class contains internal in, out and err three member variables, representing the standard input stream (keyboard input), the standard output stream (monitor) and the standard error output stream (display).

1.3 Methods member

  • native long currentTimeMillis (): effect of the method is to return the current computer time, the expression of the format of the current time and computer time GMT time (Greenwich Mean Time) January 1970 No. 10:00:00 as a difference ms number.
  • void exit (int status): the role of this method is to exit the program. Wherein the status value of 0 represents a normal exit, non-zero is aborted. Use this method to achieve out functions of the program such as the graphical interface programming.
  • void gc (): This method is to effect a request for garbage collection systems. As to whether the system is recovered immediately, it depends on the circumstances at the time of realization of the system and the system of garbage collection algorithm execution.
  • String getProperty (String key): the action of the method is to obtain a system corresponding to the attribute value of the attribute named key. Common system
    role attribute name and an attribute in the following table:
    Here Insert Picture Description
String javaVersion = System.getProperty("java.version");
System.out.println("java的version:" + javaVersion);
String javaHome = System.getProperty("java.home");
System.out.println("java的home:" + javaHome);
String osName = System.getProperty("os.name");
System.out.println("os的name:" + osName);
String osVersion = System.getProperty("os.version");
System.out.println("os的version:" + osVersion);
String userName = System.getProperty("user.name");
System.out.println("user的name:" + userName);
String userHome = System.getProperty("user.home");
System.out.println("user的home:" + userHome);
String userDir = System.getProperty("user.dir");
System.out.println("user的dir:" + userDir);

2. Math class

  • java.lang.Math provides a series of static methods for scientific computing. Parameter and return value of the method which is typically a double type.
    abs absolute value
    acos, asin, atan, cos, sin, tan trigonometric
    sqrt square root
    pow (double a, doble b) a b-th power of
    log natural logarithm
    exp e index as a substrate
    max (Double A, Double b)
    min ( Double a, Double B)
    random () returns a random number between 0.0 and 1.0
    long round (double a) double data type convert a long type (rounded)
    toDegrees (Double angrad) radian -> angle
    toRadians (double angdeg) angles -> radian

3. BigInteger与BigDecimal

3.1 BigInteger

  • Int Integer class as wrapper classes, the largest integer value that can be stored 231-1, Long class is limited, a maximum of 2 ^ 63-1. If you want to represent another big integer, whether it is basic data types or their packaging are powerless, let alone the operation.
  • BigInteger java.math packet may represent any integer precision immutable. BigInteger substantially all Java counterpart integer operator, and provide all of the relevant methods java.lang.Math. Further, a BigInteger provides the following operations: arithmetic mode, the GCD calculation, prime testing, prime generation, bit manipulation, and other actions.
  • Constructor
    BigInteger (String val): Construction of the object character string BigInteger

3.2 BigInteger common method

public BigInteger abs():返回此 BigInteger 的绝对值的 BigInteger。  BigInteger add(BigInteger val) :返回其值为 (this + val) 的 BigInteger
 BigInteger subtract(BigInteger val) :返回其值为 (this - val) 的 BigInteger
 BigInteger multiply(BigInteger val) :返回其值为 (this * val) 的 BigInteger
 BigInteger divide(BigInteger val) :返回其值为 (this / val) 的 BigInteger。整数相除只保留整数部分。  BigInteger remainder(BigInteger val) :返回其值为 (this % val) 的 BigInteger。  BigInteger[] divideAndRemainder(BigInteger val):返回包含 (this / val) 后跟(this % val) 的两个 BigInteger 的数组。 
 BigInteger pow(int exponent) :返回其值为 (this^exponent) 的 BigInteger。

3.2 BigDecimal

  • Float and Double classes of general class can be used for scientific computing or engineering calculations, but in business computing, the digital precision required is relatively high, so use the java.math.BigDecimal class.
  • BigDecimal class supports immutable, arbitrary-precision signed decimal fixed-point number.
  • 构造器  public BigDecimal(double val)  public BigDecimal(String val)
  • 常用方法
    public BigDecimal add(BigDecimal augend)
    public BigDecimal subtract(BigDecimal subtrahend)
    public BigDecimal multiply(BigDecimal multiplicand)
    public BigDecimal divide(BigDecimal divisor, int scale, int roundingMode)
Published 337 original articles · won praise 77 · views 570 000 +

Guess you like

Origin blog.csdn.net/feicongcong/article/details/104901575