diff --git a/Capture 10.png b/Capture 10.png new file mode 100644 index 0000000..5982588 Binary files /dev/null and b/Capture 10.png differ diff --git a/Capture 11.png b/Capture 11.png new file mode 100644 index 0000000..acc3d63 Binary files /dev/null and b/Capture 11.png differ diff --git a/Capture 12.png b/Capture 12.png new file mode 100644 index 0000000..45ee0ce Binary files /dev/null and b/Capture 12.png differ diff --git a/Questions.txt b/Questions.txt index e32f5b3..226b66e 100644 --- a/Questions.txt +++ b/Questions.txt @@ -693,4 +693,31 @@ Q) Given: 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 +C) No objects are eligible for GC + +Q) Given: + StringBuilder sb1 = new StringBuilder("Hello"); + StringBuilder sb2 = new StringBuilder("World"); + sb1 = null; + sb2 = sb1; + +Which is true? +A) Object containing "Hello" is unreferenced and eligible for GC +B) Object containing "World" is unreferenced and eligible for GC +C) No objects are eligible for GC + +Q) Given: +static String doStuff(String s) { + s = new String("Hello"); + return new String(s); +} + +and: + String y = doStuff("Hello"); + // line n1 + +how many String objects are eligible for GC at line n1 +A) 0 +B) 1 +C) 2 +D) 3 \ No newline at end of file diff --git a/image-000001.png b/image-000001.png new file mode 100644 index 0000000..395b525 Binary files /dev/null and b/image-000001.png differ diff --git a/image-000002.png b/image-000002.png new file mode 100644 index 0000000..4cd480a Binary files /dev/null and b/image-000002.png differ diff --git a/image-000003.png b/image-000003.png new file mode 100644 index 0000000..81dd07b Binary files /dev/null and b/image-000003.png differ diff --git a/mod.one/pom.xml b/mod.one/pom.xml new file mode 100644 index 0000000..3e13ce0 --- /dev/null +++ b/mod.one/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + org.example + SafariJava17CertStudy + 1.0-SNAPSHOT + + + mod.one + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/mod.one/src/main/java/anotherpackage/PackageLevel.java b/mod.one/src/main/java/anotherpackage/PackageLevel.java new file mode 100644 index 0000000..b5cbcca --- /dev/null +++ b/mod.one/src/main/java/anotherpackage/PackageLevel.java @@ -0,0 +1,5 @@ +package anotherpackage; + +public class PackageLevel { + static String msg = "package access"; +} diff --git a/mod.one/src/main/java/module-info.java b/mod.one/src/main/java/module-info.java new file mode 100644 index 0000000..7c615e5 --- /dev/null +++ b/mod.one/src/main/java/module-info.java @@ -0,0 +1,7 @@ +/*open*/ module mod.one { +// requires java.base; // implicitly required + + exports service to mod.two, bad; +// opens service to mod.two, bad; + opens service; +} diff --git a/mod.one/src/main/java/service/MyValues.java b/mod.one/src/main/java/service/MyValues.java new file mode 100644 index 0000000..67eaf31 --- /dev/null +++ b/mod.one/src/main/java/service/MyValues.java @@ -0,0 +1,6 @@ +package service; + +public class MyValues { + public static String message = "Hello"; + private static String secretMessage = "Whisper"; +} diff --git a/mod.two/pom.xml b/mod.two/pom.xml new file mode 100644 index 0000000..68b6f80 --- /dev/null +++ b/mod.two/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + org.example + SafariJava17CertStudy + 1.0-SNAPSHOT + + + mod.two + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/mod.two/src/main/java/anotherpackage/HackIt.java b/mod.two/src/main/java/anotherpackage/HackIt.java new file mode 100644 index 0000000..0c80c9d --- /dev/null +++ b/mod.two/src/main/java/anotherpackage/HackIt.java @@ -0,0 +1,7 @@ +package anotherpackage; + +//public class HackIt { +// public static String getIt() { +// return anotherpackage.PackageLevel.msg; +// } +//} diff --git a/mod.two/src/main/java/client/MyClient.java b/mod.two/src/main/java/client/MyClient.java new file mode 100644 index 0000000..7c75ee3 --- /dev/null +++ b/mod.two/src/main/java/client/MyClient.java @@ -0,0 +1,19 @@ +package client; + +//import anotherpackage.HackIt; + +import java.lang.reflect.Field; + +public class MyClient { + public static void main(String[] args) throws Throwable { + System.out.println(service.MyValues.message); +// System.out.println(service.MyValues.secretMessage); + Class cl = service.MyValues.class; + Field f = cl.getDeclaredField("secretMessage"); + f.setAccessible(true); + Object secret = f.get(null); + System.out.println(secret); + // JPMS prohibits "split packages" +// System.out.println(HackIt.getIt()); + } +} diff --git a/mod.two/src/main/java/module-info.java b/mod.two/src/main/java/module-info.java new file mode 100644 index 0000000..69bdf7a --- /dev/null +++ b/mod.two/src/main/java/module-info.java @@ -0,0 +1,3 @@ +module mod.two { + requires mod.one; +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index fd004ec..6d98068 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,11 @@ org.example SafariJava17CertStudy 1.0-SNAPSHOT + pom + + mod.one + mod.two + 17