Java APIs Flashcards
The date and
time classes have private constructors to force you to use the static methods.
Don’t fall for this. You are not allowed to construct a date or time object directly
LocalDate
Contains just a date—no time and no time zone
2015-01-20
LocalTime
Contains just a time—no date and no time zone.
12:45:18.401
LocalDateTime
Contains both a date and time but no time zone
2015-01-20T12:45:18.401
Java uses T to
separate the date and time when converting LocalDateTime to a String.
You need an import statement to work with the date and time classes.
import java.time.*;
Autoboxing
Since Java 5, you can just type the primitive value and Java will convert it to the relevant wrapper class for you. This is called autoboxing.
The parse methods, such as parseInt(), return a primitive
the valueOf() method returns a wrapper class
MMMM
M represents the month. The more Ms you have, the more verbose the Java output.
For example, M outputs 1, MM outputs 01, MMM outputs Jan, and MMMM outputs January.
dd
d represents the date in the month. As with month, the more ds you have, the more
verbose the Java output. dd means to include the leading zero for a single-digit month.
yyyy
y represents the year. yy outputs a two-digit year and yyyy outputs a four-digit year.
mm
m represents the minute.
ISO is a standard for dates.
DateTimeFormatter.ISO_LOCAL_DATE
2020-01-20
DateTimeFormatter.ISO_LOCAL_TIME
11:12:34
DateTimeFormatter.ISO_LOCAL_DATE_TIME
2020-01-20T11:12:34
(T separates date from time)
rules to know
- If both operands are numeric, + means numeric addition.
- If either operand is a String, + means concatenation.
- The expression is evaluated left to right.
Immutability
An object that can’t be changed once it’s created. String is immutable.
Mutable is another word for changeable.