Specialized Classes
About
Specialized classes in Java are designed to address specific use cases, offering functionality beyond basic data manipulation. These classes, part of Java’s standard library, provide advanced features such as handling large numbers, high-precision arithmetic, date and time operations, and more. They simplify complex operations and enhance the robustness of applications.
BigInteger
Represents arbitrarily large integer values.
Used in cryptography, mathematical computations, and scenarios requiring precision beyond the range of
int
orlong
.
BigDecimal
Handles arbitrary-precision decimal numbers.
Essential for financial calculations where precision is crucial.
Optional
Represents optional values to avoid
null
and preventNullPointerException
.Encapsulates a value that may or may not be present.
Provides methods like
isPresent()
,orElse()
,orElseThrow()
, andifPresent()
.
Math
Provides utility methods for basic numeric operations.
Includes functions for trigonometry, logarithms, rounding, and random number generation.
Methods are static and easy to use.
Date and Time API (java.time)
Simplifies date and time manipulation.
Introduced in Java 8 to address shortcomings of older
Date
andCalendar
classes.
Key Classes
LocalDate: Represents a date without time.
LocalTime: Represents time without date.
LocalDateTime: Combines date and time.
ZonedDateTime: Includes timezone.
UUID
Generates unique identifiers.
Commonly used for database primary keys, distributed systems, or identifiers in APIs.
Provides 128-bit unique identifiers.
Ensures uniqueness across distributed systems.
Scanner
Simplifies reading user input from various sources (console, files, strings).
Parses primitive types and strings.
Offers methods like
nextInt()
,nextLine()
, andnextDouble()
.
Formatter
Formats strings, numbers, and dates in a customizable manner.
Supports format specifiers like
%s
,%d
, and%f
.Allows localization.
Properties
Used for configuration management by storing key-value pairs.
Supports file input and output.
Commonly used for application settings.
Regex (Pattern and Matcher)
Provides pattern matching for strings.
Pattern
class compiles regular expressions.Matcher
class matches patterns against inputs.
Atomic Classes
Supports atomic operations on variables for thread-safe programming.
AtomicInteger
,AtomicLong
,AtomicBoolean
.
Random
Generates random numbers.
Supports customizable random number generation.
Provides methods like
nextInt()
,nextDouble()
, andnextBoolean()
.
Last updated
Was this helpful?