I passed Java Silver SE17 in October 2025 (click here for my passing experience). When studying for it, I created a problem set based on the content I studied in the “Black Book” shown below and repeated it many times.
I felt it would be a waste to let this problem set sit unused, so I decided to publish it on my blog (significantly modified).
I created this referring to “志賀 澄人 徹底攻略Java SE 17 Silver問題集[1Z0-825]対応”. It should cover the scope of this Black Book. I omitted content that was not in the Black Book or did not appear in the actual exam.
I referred to 志賀 澄人 徹底攻略Java SE 17 Silver問題集[1Z0-825]対応 to make these quizzes and believe I covered the whole section of the book, not what is not on this book and what is not on the test I have taken.
Also, there are a total of 60 questions in the Java Silver SE17 Quizzes 1 to 6 on this blog, which matches the number of questions in the actual exam, so maybe you can use it as a mock exam??
The explanations were created using Gemini and checked by me. I learned Java at a programing school and on the test I have taken. Please forgive me if the explanations are not perfect.
However, the code has been checked in Eclipse, so the correctness of the questions should be accurate.
1:Choose the correct result when compiling and executing the following code.
public class Main {int i;
static void a() {
System.out.print(i--);
}
public static void main(String[] args) {
a();Main.a();
}
}
A: 00
B: 0-1
C: -1-2
D: Compilation error
E: Exception thrown at runtime
Check the answer
This is because it attempts to reference the instance variable "i" inside the static method "a()".
2:Choose the correct result when compiling and executing the following code.
public class Main {int i;
protected Main(){
i=20;
}
protected void a() {
System.out.print(this.i);
System.out.print(i);
}
public static void main(String[] args) {
Main a=new A();a.a();
A b=new A();b.a();
}
}
class A extends Main{int i=1;
A(){
i=10;
}
}
A: 0000
B: 20202020
C: 20201020
D: 0010
E: Compilation error
F: Exception thrown at runtime
Check the answer
First instance (Main a = new A();) new A() is called. Before the A() constructor is executed, the parent class Main() constructor is implicitly called. Main.i is assigned 20. The A() constructor is executed. A.i is assigned 10. a.a() is called. What is executed is Main.a(). "this.i" refers to the field of the Main class, so it outputs 20. "i" refers to the field of the Main class, so it outputs 20. Second instance (A b = new A();) new A() is called. Similar to the above, Main.i of the new object is set to 20, and A.i is set to 10. "this.i" and "i" refer to the field of the Main class, so they each output 20.
3:Choose the correct result when compiling and executing the following code.
public class Main {
static Number []i[]=new Short[3][3];
public static void main(String[] args) {
Main a=new Main();a.i[1]= new Short[]{1};a.i[2]=new Short[]{null,2};
Main b=new Main();
int sum=0;
for(Number j[]:b.i) {
for(Number k:j) {
if(k==null)sum+=100;
else sum+=(Short)k;
}
}
System.out.println(sum);
}
}
A: 403
B: 900
C: 0
D: 3
E: Compilation error
F: Exception thrown at runtime
Check the answer
1. Initial state of the array (static field i)static Number []i[]=new Short[3][3]; causes the static field "i" to refer to a Short[3][3] object.All elements are initialized with null, which is the default value for reference types.i=[{null,null,null},{null,null,null},{null,null,null}]
2. Modification of the array (processing of a)Both "a" and "b" share the same static field "i". By assignment, i[1] and i[2] are replaced with new arrays.a.i[1] = new Short[]{1};a.i[2] = new Short[]{null, 2};i=[{null,null,null},{1},{null, 2}]
3. Loop processing (processing of b)b.i refers to the above array, and the total value "sum" is calculated.
| Processing Step | j (Inner Array) | Value of k | k == null | Processing (sum += ...) | Total sum |
|---|---|---|---|---|---|
| i[0] | {null, null, null} | null | True | 100 | 0 → 100 |
| null | True | 100 | 100 → 200 | ||
| null | True | 100 | 200 → 300 | ||
| i[1] | {1} | 1 | False | (Short)1 (Unboxing) | 300 → 301 |
| i[2] | {null, 2} | null | True | 100 | 301 → 401 |
| 2 | False | (Short)2 (Unboxing) | 401 → 403 | ||
| Final value of sum: 403 | |||||
4:Choose the correct result when compiling and executing the following code.
public class Main {
public static void main(String[] args) {
Object i[][]= {{null},{1}};
Object j[]=i[1].clone();Object [][]k=i.clone();
j[0]=2.0;k[1][0]=null;
System.out.print(""+(i[1][0]==j[0])+(i[1][0]==k[1][0]));
k[0]=new Integer[] {3,4};
System.out.print((k[0]==i[0])+""+(k==i)+k.equals(i));
}
}
A:falsefalsefalsetruetrue
B:falsefalsefalsefalsefalse
C:falsetruefalsefalsefalse
D:falsetruefalsetruetrue
E:truetruetruefalsefalse
F:Compilation error
Check the answer
1. Initial State and Clone
Object i[][]= {{null},{1}};
Object j[]=i[1].clone();
Object [][]k=i.clone();
i: 2D array.
i[0] refers to the array {null}.
i[1] refers to the array {Integer(1)}.
j: It is a new array, but j[0] refers to the same Integer(1) object as i[1][0].
k: It is a new array, but its element k[0] refers to the same array as i[0], and k[1] refers to the same array as i[1].
2. First Change
j[0]=2.0;
k[1][0]=null;
j[0]=2.0;:
j[0] comes to refer to a new Double(2.0) object. There is no effect on i[1][0].
k[1][0]=null;:
Since k[1] and i[1] are the same array object, the value of i[1][0] is also overwritten with null.
3. First Output (i[1][0]==j[0] and i[1][0]==k[1][0])
System.out.print(""+(i[1][0]==j[0])+(i[1][0]==k[1][0]));
(i[1][0] == j[0]):
i[1][0] is null, j[0] is Double(2.0) (non-null).
null == Object is false.
(i[1][0] == k[1][0]):
i[1][0] is null, k[1][0] is null.
null == null is true.
Output (first half): falsetrue
4. Second Change
k[0]=new Integer[] {3,4};
k[0] comes to refer to a new array {3, 4}.
i[0] remains referring to the original array {null} (i[0] and k[0] have become different arrays).
5. Second Output (k[0]==i[0], k==i, k.equals(i))
System.out.print((k[0]==i[0])+""+(k==i)+k.equals(i));
(k[0] == i[0]): k[0] is a new array, i[0] is the old array, and their references are different. Thus, false.
(k == i): k is a clone (separate object) of the top-level array of i. Thus, false.
k.equals(i): The equals() method for arrays (inherited from Object) performs reference comparison, same as ==. Since k and i are different objects, it is false.
Output (second half): falsefalsefalse
5:Which of the following code is correct to write inside the following record?
public record A(String i) {
}
A:A(){}
B:A(String i){this.i=i;System.out.print(“Hi”);}
C:A(){this(“anything”);}
D:All of A, B, and C
E:B and C
F:None of the above
Check the answer
According to record rules, the access modifier of the constructor must not be more restrictive than the access modifier of the record itself (which is public in this case). Therefore, A through C, which lack the public modifier, all result in a compilation error.
6:When compiling the following code fragment, where will a compilation error occur: line A, line B, or line C?
record A(String i,int j) {
A(){ //line A
this.i=null;this.j=0;
}
A(String i,int k){ //line B
this.i=i==null?"Hi":i;j=k<0?0:k;
}
A(int j){ //line C
this(null,3);
}
}
A:No compilation error
B:A, B, C
C:A
D:B
E:C
F:B, C
G:A, C
Check the answer
line A: Compilation error This is a custom constructor (non-canonical constructor). To ensure the initialization of components, a custom constructor must call another constructor (canonical constructor) in its first statement to delegate initialization. This code attempts to assign directly to the fields (this.i=null;) in the constructor body without delegating (this(...)), so it results in a compilation error. line B: No compilation error (Valid definition of canonical constructor) This has the same signature as the canonical constructor generated automatically by the record, but since it explicitly assigns to the components in the body, this form is valid as a canonical constructor definition. Because the assignment happens, you can include logic for validation or data conversion (in this case, null check or negative value check) to set the values. Even if argument names differ (j and k), if the type and order match, it is recognized as a canonical constructor. line C: No compilation error This is a custom constructor, but since it calls the canonical constructor in the first statement (this(null, 3)) and correctly delegates the component initialization, it is a valid description following the record rules.
7:Choose the correct result when compiling and executing the following code.
public class Main {
public static void main(String[] args) {
System.out.println(a());
}
private static String a() {
try {
throw new Exception();
} catch (Throwable t) {
System.out.print("catch ");
return "CR ";
} finally {
System.out.print("finally ");
return "FR ";
}
}
}
A:catch finally CR
B:catch finally FR
C:catch CR finally
D:catch FR finally
E:Compilation error
F:Exception thrown at runtime
Check the answer
This question asks about the execution order of try-catch-finally blocks in Java and the special priority of a return statement from a finally block.
1. Execution of try block
Method a() is called, and the try block is entered.
An exception is thrown by throw new Exception();.
Execution of the try block is interrupted.
2. Execution of catch block
The thrown Exception is caught by catch (Throwable t).
After being caught, the following processing is executed in order.
System.out.print("catch "); is executed.
return "CR "; is executed. Here, the method's return value "CR " is determined, but the method does not terminate immediately.
3. Execution of finally block
Regardless of how the try or catch block ended, the finally block is executed.
System.out.print("finally "); is executed.
return "FR "; is executed.
4. Termination of method
Under Java rules, if there is a return statement in the finally block, that value **overwrites the return value determined in the catch block**, and the return in the finally block becomes the final return value of the method.
Method a() returns "FR ", and the main method prints it.
8:We want to output 0 when compiling and executing the following code. What should be put in the blank ■■■■■■■?
public class Main {
int i;
public static void main(String[] args) {
int i=1;
System.out.println(■■■■■■■);
}
}
A:i
B:this.i
C:Main.i
D:new Main().i
E:B and D
F:B, C, and D
Check the answer
Location of the value we want to output (0): The instance variable int i; of the Main class is not explicitly initialized, so it holds the default value of 0. Therefore, to output 0, we need to access this instance variable i. A: i → Refers to the local variable (value is 1) within the main method, so 1 is output. B: this.i → The main method is static and is not tied to a specific instance, so the this keyword cannot be used, resulting in a compilation error. C: Main.i → i is an instance variable (non-static) and cannot be accessed directly using the class name, resulting in a compilation error. D: new Main().i → A new Main object is temporarily created, and the instance variable i of that object is accessed. Since the value of instance variable i is the default value 0, 0 is output. Therefore, only new Main().i can output 0.
9:Which of the following code fragments does not cause a compilation error?
A:void a() {try {throw new java.io.IOException();}finally {}
int j;}
B:void a() {try {throw new java.io.IOException();}catch(Exception i){}
int j;}
C:void a() throws Exception{try {throw new java.io.IOException();}finally{}
int j;}
D:A, B, and C
E:B and C
F:None of them are free of compilation errors
Check the answer
This question relates to Java's unreachable code rules. If the compiler determines that there is no possibility for execution to reach a line of code, it generates an error.
A: Compilation error occurs
void a() {
try {
throw new new java.io.IOException(); // Checked exception
} finally {
}
int j; // Unreachable
}
A checked exception (IOException) is unconditionally thrown in the try block.
Since there is no catch block to catch this exception and no throws declaration in the method signature, this method cannot handle the exception, and it terminates by propagating the exception.
Therefore, the compiler judges that there is no normal path to reach int j; immediately after exiting the try-finally block, resulting in an error as unreachable code.
B: No compilation error
void a() {
try {
throw new java.io.IOException();
} catch(Exception i) { // Catch exception
}
int j; // Reachable
}
The catch block catches the IOException and completes the exception handling.
After exception handling is complete, a path is established for processing to continue normally to int j; after exiting the try-catch block, so no compilation error occurs.
C: Compilation error occurs
void a() throws Exception{
try {
throw new java.io.IOException(); // Unconditional throw
} finally {
}
int j; // Unreachable
}
Although delegation of the exception is legal due to throws Exception, the exception is thrown unconditionally within the try block.
After processing passes through the finally block, the exception propagates to the caller and the method terminates.
Similar to case A, the compiler judges that there is absolutely no path to normally exit the try-finally block and reach int j;, resulting in an error as unreachable code.
10:Choose the correct result when compiling and executing the following code.
public class Main {
public static void main(String[] args) {
String i=String.valueOf("Hello");
Main(i);Main(i,"Hi");
System.out.println(i.toLowerCase());
}
static String Main(String i) {
return i+=" World";
}
public static void Main(String i,String j) {
i.replace("Hello", j);
}
}
A:hello World
B:hi World
C:hello
D:hi
E:Compilation error
F:Exception thrown at runtime
Check the answer
The behavior of this code is determined by method overloading in Java, the immutability of String, and the effect on local variables.
1. Initialization
String i=String.valueOf("Hello");
The local variable i in the main method refers to the string "Hello".
2. First method call: Main(String i)
Main(i); // i = "Hello"
static String Main(String i) {
return i+=" World";
}
The value of local variable i ("Hello") is passed to method Main(String i) (pass-by-value).
Inside the method, i += " World" is executed. Since String is immutable, this creates a new string "Hello World".
The reference to this new string "Hello World" is stored in the local variable i within the method and then returned.
However, this return value is not received within the main method.
Therefore, the local variable i in the main method remains referring to the original value "Hello" and does not change.
3. Second method call: Main(String i, String j)
Main(i,"Hi"); // i = "Hello"
public static void Main(String i,String j) {
i.replace("Hello", j);
}
i ("Hello") and "Hi" are passed to the method.
i.replace("Hello", j) is executed.
The replace() method does not change the original string but creates a new string "Hi" and returns its reference.
However, this return value is discarded without being stored anywhere.
Therefore, the local variable i in the main method remains referring to the value "Hello" here as well and does not change.
4. Final Output
System.out.println(i.toLowerCase());
The local variable i in the main method remains "Hello" until the end.
i.toLowerCase() returns "hello", which is the lowercase version of "Hello".
The final output is hello.
コメント