Java APIs Flashcards

1
Q

The date and

time classes have private constructors to force you to use the static methods.

A

Don’t fall for this. You are not allowed to construct a date or time object directly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

LocalDate

A

Contains just a date—no time and no time zone

2015-01-20

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

LocalTime

A

Contains just a time—no date and no time zone.

12:45:18.401

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

LocalDateTime

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

You need an import statement to work with the date and time classes.

A

import java.time.*;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Autoboxing

A
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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The parse methods, such as parseInt(), return a primitive

A

the valueOf() method returns a wrapper class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

MMMM

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

dd

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

yyyy

A

y represents the year. yy outputs a two-digit year and yyyy outputs a four-digit year.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

mm

A

m represents the minute.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

ISO is a standard for dates.

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

rules to know

A
  1. If both operands are numeric, + means numeric addition.
  2. If either operand is a String, + means concatenation.
  3. The expression is evaluated left to right.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Immutability

A

An object that can’t be changed once it’s created. String is immutable.

Mutable is another word for changeable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly