diff --git a/Questions.txt b/Questions.txt index 3256c17..e32f5b3 100644 --- a/Questions.txt +++ b/Questions.txt @@ -662,3 +662,35 @@ D) the code compiles if the following is added at point x E) the code compiles if the following is added at line n1 non-sealed abstract class Z implements X permits Q {} final class Q extends Z {} + + +Q) Given, rooted on the base of the classpath: +---file: localization/MyResources.properties +name=Fred +----------------------------------------------- +---file: localization/MyResources_de.properties +name=Helmut +----------------------------------------------- +and: + + Locale.setDefault(Locale.FRENCH); + ResourceBundle bundle = PropertyResourceBundle.getBundle( + "MyResources"); + System.out.println("Name is " + bundle.getString("name")); + +What is the result? +A) Name is Helmut +B) Name is Fred +C) Name is null +D) an exception is thrown +E) compilation fails + +Q) Given: + StringBuilder sb1 = new StringBuilder("Hello"); + StringBuilder sb2 = sb1; + sb1 = null; + +Which is true? +A) sb1 is unreferenced and eligible for GC +B) sb1 and sb2 are unreferenced and eligible for GC +C) No objects are eligible for GC \ No newline at end of file diff --git a/image-000000.png b/image-000000.png new file mode 100644 index 0000000..59d3473 Binary files /dev/null and b/image-000000.png differ diff --git a/src/main/java/localization/TryThis.java b/src/main/java/localization/TryThis.java new file mode 100644 index 0000000..722f057 --- /dev/null +++ b/src/main/java/localization/TryThis.java @@ -0,0 +1,15 @@ +package localization; + +import java.util.Locale; +import java.util.PropertyResourceBundle; +import java.util.ResourceBundle; + +public class TryThis { + public static void main(String[] args) { + Locale.setDefault(Locale.FRENCH); + ResourceBundle bundle = PropertyResourceBundle.getBundle( + "localization.MyResources"); + System.out.println("Name is " + bundle.getString("name")); + + } +} diff --git a/src/main/java/sealedtypes/Ex1.java b/src/main/java/sealedtypes/Ex1.java index da70dad..e3377d3 100644 --- a/src/main/java/sealedtypes/Ex1.java +++ b/src/main/java/sealedtypes/Ex1.java @@ -1,15 +1,30 @@ package sealedtypes; -interface Transporter { +// IF, but only if, all types in this sealed type hierarchy +// are in the same source file, then permits may be omitted. +// I believe the intention is to simplify development +//sealed interface Transporter /*permits Truck, Car, Bicycle*/ { +// If running (but also compiler observes this) under Module System +// (JPMS) elements of the hierarchy can be in the same module but +// different packages. IF NOT under JPMS, all elements in the hierarchy +// MUST BE IN THE SAME PACKAGE +sealed interface Transporter permits Truck, Car, Bicycle { } -class Truck implements Transporter { +sealed class Truck implements Transporter permits BoxVan { } -class Car implements Transporter { +// lose control of children here +non-sealed class BoxVan extends Truck {} + +final class Car implements Transporter { } -//class Bicycle implements Transporter {} +// records are implicitly final! +// enums are not "final" but they control their child types +// if any exist, they must be anonymous/nested types +// records can implement interfaces, but cannot extend anything explicit +record Bicycle() implements Transporter {} public class Ex1 { public static void main(String[] args) { diff --git a/src/main/resources/localization/MyResources.properties b/src/main/resources/localization/MyResources.properties new file mode 100644 index 0000000..6a22883 --- /dev/null +++ b/src/main/resources/localization/MyResources.properties @@ -0,0 +1 @@ +name=Fred diff --git a/src/main/resources/localization/MyResources_de.properties b/src/main/resources/localization/MyResources_de.properties new file mode 100644 index 0000000..e8d95c1 --- /dev/null +++ b/src/main/resources/localization/MyResources_de.properties @@ -0,0 +1 @@ +name=Helmut