java 2 3
fdsa
fdsa
-
- 1 / 496
-
Cartes-fiches
What are the 5 checked exceptions we have to be familiar with?
FileNotFoundException, IOException, NotSerialziableException, ParseException, SQLException
From what Exception inherits NumberFormatException?
IllegalArgumentException
From what Exception inherits FileNotFoundException and NotSerializableException?
IOException
Does close in AutoClosable have to throw an exception?
the implemented version of close() can chose to throw an exception or a subclass or not throw any exceptions at all
In which scope are resources which are declared within a try-with-resources block?
in the scope within the try block
When is it possible to declare resources which are used within try-with-resoruces?
Also prior to the try-with-resorucres-statement if they are marked final or are effectively final
Where are supresses exceptions added?
Only to exceptions thrown in the try clause
Whats the syntax of assert?
assert test_value;
assert test_value: message;
--> may include optional parantheses and a message:
assert ("Bla".equals(bla)): "Failed";
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();