Skip to content

Commit

Permalink
Day 3 break 4
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonHGR committed May 10, 2023
1 parent 4df0e2a commit 07a573a
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 4 deletions.
32 changes: 32 additions & 0 deletions Questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file added image-000000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions src/main/java/localization/TryThis.java
Original file line number Diff line number Diff line change
@@ -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"));

}
}
23 changes: 19 additions & 4 deletions src/main/java/sealedtypes/Ex1.java
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/localization/MyResources.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name=Fred
1 change: 1 addition & 0 deletions src/main/resources/localization/MyResources_de.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name=Helmut

0 comments on commit 07a573a

Please sign in to comment.