java 2 3
fdsa
fdsa
-
- 1 / 496
-
Lernkarten
What are the 4 important time classes for the exam?
- java.time.LocalDate
- java.time.LocalTime
- java.time.LocalDateTime
- java.time.ZonedDateTime
Can we call new LocalDate()?
No
Does this work?:
LocalDate date = LocalDate.of(2020, Month.OCTOBER, 20);
LocalTime time = LocalTime.of(11,12,34);
System.out.println(date.format(DateTimeFormatter.ISO_LOCAL_TIME));
System.out.println(time.format(DateTimeFormatter.ISO_LOCAL_DATE));
No, will throw an exception because of incompatible types
How to add custom text values to dateTimeFormatters?
excape the text by surrounding it with a pair of single quotes: '
DateTimeFormatter.ofPattern("MMM dd', Party''s at' hh:mm);
How to get the users current locale?
Locale.getDefault()
How to get the german language from locale?
Locale.GERMAN
How to get the german region from Locale?
Locale.GERMANY
How to use the locale-builder?
new Locale.Builder().setRegion("US").setLanguage("en").build();
How to set the default locale?
Locale.setDefault(locale)
Does Locale.setDefault change the locale for the system?
No only for that one javaprogramm
What is the NumberFormat-method for getting a general-purpose formatter?
NumberFormat.getInstance()
NumberFormat.getInstance(locale)
What is the NumberFormat-method for getting a general-purpose formatter (with number instance)
NumberFormat.getNumberInstance()
NumberFormat.getNumberInstance(locale)
What is the NumberFormat-method for getting a formatter for formatting monetary amounts?
NumberFormat.getCurrencyInstance()
NumberFormat.getCurrencyInstance(locale)
What are the decimal format symbols?
# - omits the position if no digit exists for it . $2.2
0 - put a 0 in the position if no digit exists for it - $002.20
How to custom format numbers?
new DecimalFormat("###,###,###.0");
How to get a DateTimeFormatter-instance for formatting dates=
DateTimeFormatter.ofLocalizedDate(dateStyle)
How to get a DateTimeFormatter-instance for formatting times?
DateTimeFormatter.ofLocalizedTime(timestyle)
How to get a DateTimeFormatter-instance for formatting dates and times?
DateTimeFormatter.ofLocalizedDateTime(dateStyle, timeStyle)
DateTimeFormatter.ofLocalizedDateTime(dateTimeStyle)
What are possible FormatStyle-parameters?
SHORT, MEDIUM, LONG, FULL
How to get a formatter for a specific locale?
Datetimeformatter.withLocale(locale)
How to set the default locale only for displaying data about the locale?
with Locale.Category value DISPLAY
How to set the default locale only for formatting dates,numbers or currencies?
With Locale.Category value FORMAT
Where is the resourcebundle stored?
in a properties file
What is a properties file?
A textfile that contains a list of key/value pairs
How to get the bundle for a locale?
ResourceBundle.getBundle("name");
ResourceBundle.getBundle("name", locale);
How to get a set of all keys in a ResourceBundle?
resourceBundle.keySet()
What are the steps of getting the proper ResourceBundle?
- Look for the resource bundle for the requested locale, followed by the one for the default locale
- for each locale, check language/country, followed by just the language
- use the default resource bundle if no matching locale can be found
Can java get keys from multiple resource bundles?
Yes, f.e. from the parent resource bundle
How to use params in the resourcebundle?
f.e. with {0} and {1} and then use :
String format = rb.getString("helloByName");
System.out.println(MessageFormat.format(format, "Tammy", "Henry"));
How to set properties in the properties class?
var props = new Properties();
props.setProperty("name", "Ourzoo");
Whats the difference in the properties class between get() and getProperty()?
only getProperty allowes a default value
When to use a supplier? Which function is provided?
when you want to generate or supply values without taking any input.
T get();
When to use a consumer? Whats the function?
when you want to do something with a parameter but not return anything
void accept(T t);
What does a function (the functional iterface) do? Which function impletemns it?
responsible for turning one parameter into a value of a potentially different type and returning it
R apply(T t);
What does a UnaryOperator/BinaryOperator do?
Unary: transforms its value into one of the same type
BinaryOperatior: merges two values into one of the same type
Unary: T apply(T t);
Binary: T apply(T t1, T t2);
What are convenience metthods for Consumer?
Consumer andThen(Consumer);
What are convenience metthods for Function?
Function andThen(Function);
Function compose(Function);
What are convenience metthods for Predicate?
Predicate and(Predicate);
Predicate negate();
Predicate or(Predicate);
Wbhat does the compose function do for the interface function?
chains functional interfaces
What is the optional-method for returning a value and what happens if the optional is empty?
get() , throws exception