4. Dates, Times, Locales and Resource bundles Flashcards

1
Q

How are the classes in java.time organised?

A
  • Local dates and times: these dates are local to your time zone, the classes: LocalDate, LocalTime, LocalDateTime
  • Zoned dates and times: these dates include time-zone information, the classes:
    ZonedDateTime and OffsetDateTime
  • Formatters for dates and times: you can parse dates with patterns and in a variety of styles,
    the classes: format.DateTimeFormatter
  • Adjustments to dates and times: you can adjust and manipulate dates and times by handy
    increments, the classes: temporal.TemporalAdjusters and temporal.ChronoUnit
  • Periods, Durations: represent an amount of time, periods for days or longer and durations
    for shorter periods (minutes seconds), classes: Periods and Durations
  • Instants: represent a specific instant in time, so you can compute the number of minutes
    between two instants, the class: Instants
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the LocalDate.parse(String string) do?

A

to parse a string that matches the date (so string need to be in the order of ISO-
8601)

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

What does the LocalDate.of(YYYY-MM-DD) do?

A

to parse a string that matches the date (so string need to be in the order of ISO-
8601)

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

What are ZoneRules for?

A
With ZoneRules the class captures the current rules about daylight savings in various parts of the
world. It gives answer on the question is the current ZoneId in daylight savings time?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are ZoneRules for?

A
With ZoneRules the class captures the current rules about daylight savings in various parts of the
world. It gives answer on the question is the current ZoneId in daylight savings time?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which Adjustments are there?

A

You can add days and hours with handy methods of LocalDate and ZonedDateTime classes, suchs as
plusMinutes(). plusYears(), minusWeeks(), minusSeconds().

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

What are temporalAdjusters?

A
The class temporalAdjusters has a whole slew of handy methods to make a TemporalAdjuster for a
variety of scenarios, such as firstDayOfNextYear(), lastDayOfMonth()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a Period?

A

The Period Class in Java class obtains a quantity or amount of time in terms of years, months and days.

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

What is the output of Period?

A

Output of Periods is P for instance P1D, P1Y

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

What will the minus() method do?

A

You can call the minus() method on ZonedDateTime and DateTime classes with an argument of a
Period to minus that period on the current DateTime.

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

What is a Duration?

A

A Duration object ( java. time. Duration ) represents a period of time between two Instant objects.

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

What is the output of a Duration?

A

If you print out the Duration object you will get something like this: PT1H18M. PT means period of
time, 1H18M, means 1 hour 18 minutes.

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

What is an Instance?

A

An instant represent an instant in time. (seconds and nano seconds)

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

How to create a LocalDate?

A

LocalDate.now();
LocalDate.of(2017, 8, 21);
LocalDate.parse(“2017-08-21”);

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

How to create a LocalTime?

A

LocalTime.now();
LocalTime.of(10, 19, 36);
LocalTime.parse(“10:19:36”);

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

How to create a LocalDateTime?

A

LocalDateTime.now();
LocalDateTime.of(aDate, aTime);
LocalDateTime.parse(“2017-04-08T10:19:36);
LocalDateTime.parse(aDateTime, a Formatter);

17
Q

How to create a ZonedDateTime?

A

ZonedDateTime.now();

ZonedDateTime.of(aDateTime, ZoneId.of(aZoneString);

18
Q

How to create a DateTimeFormatter?

A

DateTimeFormatter.ofPattern(“yyyy-MM-dd HH:mm”;

DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withLocale(aLocale);

19
Q

How to create an Instant?

A

Instant.now();
zonedDateTime.toInstant();
aDateTime.toInstant();

20
Q

how to create a Period?

A

Period.between(aDate1, aDate2);

Period.ofDays(2);

21
Q

How to create a Duration?

A

Duration.between(aTime1, aTime2);

Duration.ofMinutes(3);

22
Q

What are the key adjustments of LocalDate?

A

aDate.minusDays(3);
aDate.plusWeeks(2);
aDate.withYear(2018);

23
Q

What are the key adjustments of LocalDate?

A

aTime.minus(3, ChronoUnit.MINUTES);
aTime.plusMinutes(3);
aTime.withHour(12);

24
Q

What are the key adjustments of LocalDateTime?

A

aDateTime.minusDays(3);
aDateTime.plusMinutes(3);
aDateTime.plus(Duration.ofMinutes(4));
aDateTime.withMonth(2);

25
Q

Which 2 Constructors does Locale have?

A
  • Locale(String language)

- Locale(String language, String country)

26
Q

What does getCountry(); return?

A

getCountry(); geeft de afkorting van het land terug.

27
Q

What does getDisplayCountry() terug?

A

getDisplayCountry(); geeft de naam van het land

voluit terug. Geldt hetzelfde voor language.

28
Q

Are DateTime object mutable?

A
  • Datetime objects are immutable so you can’t modify it
29
Q

When do you get ZoneRulesException?

A
  • Je krijgt een ZoneRulesException bij een foute zoneId
30
Q

Which 3 property files does java know?

A
  • System level properties file (not on the exam)
  • Java.util.Properties: makes it easy for a programmer to create and maintain property files for
    whatever applications the programmer chooses.
- Java.util.ResourceBundle: that can use the Properties class to make it easier for a
programmer to add localization and/or internationalization features to application.
31
Q

What is the structure of a property file?

A
  • Set of comments (# or !)
  • Followed by a number of rows of tekst data (each row representing a key/value pair)

Key = value
Key : value
Key value

32
Q

What wil the property.list(); return?

A

propertie.list(); will produce an output of a list of key/value pairs

33
Q

What does the String getProperty(String key) method do?

A

Returns the property associated with the key

34
Q

What does the void load(InputStream is) method do?

A

reads a property list (key and element pairs) from the input byte stream

35
Q

What does the Object setProperty(String key, String value) method do?

A

This wel set the property

36
Q

What does the void store(OutputStream out, String headerComment) method do?

A

writes this property list (key and element
pairs) in this Properties table to the output stream in a format suitable for loading into a Properties table using the
load(InputStream) method

37
Q

What are 2 rules when using ResourceBundle?

A
  • These files must end in “.properties”
  • The end of the name before the “.properties” must be a string that start with an underscore
    and then declares the Locale the file represents (for example: MyApp_nl.properties).
38
Q

What happens when we use ResourceBundle.getBundle(); without a Locale?

A
  • These files must end in “.properties”
  • The end of the name before the “.properties” must be a string that start with an underscore
    and then declares the Locale the file represents (for example: MyApp_nl.properties).
39
Q

How does Java look for the bundles?

A
  • Start with the full Locale requested (first .java then .properties)
  • Then fallback to just Language (first .java then .properties)
  • Then fallback to the default Locale (first .java then .properties)
  • Then fallback to the default bundle (first .java then .properties)
  • Then cry: MissingResourceException