- 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()
- Constructor
- BigInteger, BigDecimal:: Represents arbitrary-precision integers with no upper or lower bounds
- 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).
- now(): Gets the current date from the system clock.
- of(int year, int month, int dayOfMonth): Creates a LocalDate instance for a specific date.
- plusDays(long daysToAdd): Adds a specific number of days to the date.
-
- 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);
- ISO Date and Time Standards
- class1 : LocalDateTime : Represents a date-time without a time-zone in the ISO-8601 calendar system
- 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.
- UUID : Universal Unique Identifier, which is a standardized method of generating identifiers that are unique across different systems and networks
Java annotation
to provide metadata for methods where it is applied
@Target(ElementType.METHOD):
- Specifies that this annotation can only be applied to methods.
@Retention(RetentionPolicy.RUNTIME):
- Indicates that this annotation will be available at runtime. : This is necessary if you want to use reflection or an aspect-oriented programming (AOP) library (e.g., Spring AOP) to process this annotation.
'개발기술 > Java' 카테고리의 다른 글
Java 코딩구현 - Java I/O (1) | 2024.06.14 |
---|---|
Java 구현 - 변수, 데이터타입, 컬렉션 (0) | 2024.05.22 |
Java 코딩구현기본 - 클래스, 메소드, 객체지향, ENUM (0) | 2024.04.20 |
Java 코딩구현기초 - 연산자/조건반복문 (0) | 2024.04.11 |
프로그래밍 언어 특징비교분석 (0) | 2024.04.09 |