Skip to content

Commit

Permalink
Final!
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonHGR committed May 10, 2023
1 parent 07a573a commit f27564f
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 1 deletion.
Binary file added Capture 10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Capture 11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Capture 12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 28 additions & 1 deletion Questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
Binary file added image-000001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image-000002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image-000003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions mod.one/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.example</groupId>
<artifactId>SafariJava17CertStudy</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>mod.one</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
5 changes: 5 additions & 0 deletions mod.one/src/main/java/anotherpackage/PackageLevel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package anotherpackage;

public class PackageLevel {
static String msg = "package access";
}
7 changes: 7 additions & 0 deletions mod.one/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -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;
}
6 changes: 6 additions & 0 deletions mod.one/src/main/java/service/MyValues.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package service;

public class MyValues {
public static String message = "Hello";
private static String secretMessage = "Whisper";
}
20 changes: 20 additions & 0 deletions mod.two/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.example</groupId>
<artifactId>SafariJava17CertStudy</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>mod.two</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
7 changes: 7 additions & 0 deletions mod.two/src/main/java/anotherpackage/HackIt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package anotherpackage;

//public class HackIt {
// public static String getIt() {
// return anotherpackage.PackageLevel.msg;
// }
//}
19 changes: 19 additions & 0 deletions mod.two/src/main/java/client/MyClient.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
3 changes: 3 additions & 0 deletions mod.two/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module mod.two {
requires mod.one;
}
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<groupId>org.example</groupId>
<artifactId>SafariJava17CertStudy</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>mod.one</module>
<module>mod.two</module>
</modules>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down

0 comments on commit f27564f

Please sign in to comment.