개발기술/Java

Java 범용 library

bsh6226 2024. 5. 5. 22:03
  • java.math package
    • BigInteger, BigDecimal:Represents arbitrary-precision integers with no upper or lower bounds
      • Constructor
        • BigInteger(String val/integer): Creates a BigInteger instance from a string representation of an integer.
        • BigDecimal(String val/double val): Creates a BigDecimal instance from a double value.
      • Operations:
        • add(BigInteger val), subtract(BigInteger val), multiply(BigInteger val), divide(BigInteger val), mod(BigInteger val)
        • pow(int exponent): Raises this instance to the power of the specified exponent.
        • compareTo(BigInteger val): Compares this instance with another BigInteger, returning -1, 0, or 1.
        • instance data conversion : instance.toString() / instance.xxxvalue()
  • java.math class
    • abs(val) : Returns the absolute value of an argument.
    • max,min (two value): Returns the greater, smaller of two values.
    • pow(base val, power val) : Returns the value of the first argument raised to the power of the second argument
    • ceil(val): Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.
    • floor(val): Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer.
    • round(val): Returns the closest long or int, as indicated by the method's return type, to the argumen
  • java.time package
    • java.time package contains classes for date and time manipulation
    • class0 : LocalDate
      • Format: yyyy-MM-dd (e.g., 2024-07-31).
    • class1 : LocalDateTime : Represents a date-time without a time-zone in the ISO-8601 calendar system
      • Format: yyyy-MM-ddTHH:mm:ss (e.g., 2024-07-31T12:00:00).
      • method 1 : now(): Obtains the current date-time from the system clock in the default time-zone.
      • method2 : of(int year, int month, int dayOfMonth, int hour, int minute): Obtains an instance of LocalDateTime from a year, month, day, hour, and minute.
      • method3 : format(DateTimeFormatter formatter): 매개변수 formatter에서 정의된대로 다듬어서 string 반환
    • class2 : DateTimeFormatter
      • Formatter for printing and parsing date-time objects.
      • method1 : ofPattern(String pattern): Creates a formatter using the specified pattern.
      • method2 : format(TemporalAccessor temporal): Formats a date-time object using this formatter.
      • static field1 : DateTimeFormatter.ISO_LOCAL_DATE : yyyy-MM-ddTHH:mm:ss 형태의 formatter을 호출
      • static field2 : DateTimeFormatter.ISO.TIME : HH:mm:ss 형태의 formatter을 호출 , 시분초 
        • ISO Date and Time Standards 
          • DateTimeFormatter formatter = DateTime
          • Formatter.ofPattern("yyyy-MM-dd HH:mm:ss");
          • String currentDate = now.format(formatter);
  • System.currentTimeMillis() : is a method in Java that returns the current time in milliseconds since the Unix epoch. The Unix epoch is defined as the beginning of January 1, 1970, in UTC `(Coordinated Universal Time).
    • Time Zone Independence: The value returned by System.currentTimeMillis() is in UTC, making it independent of the system’s time zone.
    • unit of the time : The unit of time returned by System.currentTimeMillis() in Java is milliseconds. ( 1 second = 1,000 milliseconds, 1 minute = 60 seconds, 1 hour = 3,600 seconds, 1 day = 86,400 seconds)

 

 

 

 

  • java.util.Random
    • the package generate pseudorandom numbers. The seed is derived from current time in millisecond.  You can either pass a seed explicitly to the constructor of a Random object 
    • method
      • nextBoolean(): Returns a random boolean value.
      • nextInt(): Returns a random integer.
      • nextInt(int bound): Returns a random integer between 0 (inclusive) and the specified bound (exclusive).
      • nextLong(): Returns a random long.
      • nextDouble(): Returns a random double between 0.0 (inclusive) and 1.0 (exclusive).
      • nextFloat(): Returns a random float between 0.0f (inclusive) and 1.0f (exclusive).
  •  java.util.UUID
    • UUID :  Universal Unique Identifier, which is a standardized method of generating identifiers that are unique across different systems and networks 
      • A UUID is a 128-bit number, typically expressed as a string of 32 hexadecimal characters and broken down into five groups, separated by hyphens. This format is represented as 8-4-4-4-12, making a typical UUID look like this: 123e4567-e89b-12d3-a456-426614174000.
    • randomUUID(): Generates a random UUID (Version 4).
      • UUID uuid = UUID.randomUUID();
    • toString(): Returns a UUID as a string.