1z1-829問題一発合格させる問題集はOracle Java認定で!
1z1-829練習テストPDF試験材料
質問 # 19
Given:
What is the result
- A. UnDefined
- B. Marketing
Undefined - C. Marketing
- D. Marketing
Finance
Technical
正解:A
解説:
Explanation
The code fragment is using the switch statement with the new Java 17 syntax. The switch statement checks the value of the variable desig and executes the corresponding case statement. In this case, the value of desig is
"CTO", which does not match any of the case labels. Therefore, the default case statement is executed, which prints "Undefined". The other case statements are not executed, because there is no fall through in the new syntax. Therefore, the output of the code fragment is:
Undefined
質問 # 20
Given the code fragment:
What is the result:
- A. ADEABCB // the order of element is unpredictable
- B. ABCE
- C. ABBCDE // the order of elements is unpredictable
- D. ABCDE // the order of elements is unpredictable
正解:C
解説:
Explanation
The answer is D because the code fragment uses the Stream API to create two streams, s1 and s2, and then concatenates them using the concat() method. The resulting stream is then processed in parallel using the parallel() method, and the distinct() method is used to remove duplicate elements. Finally, the forEach() method is used to print the elements of the resulting stream to the console. Since the order of elements in a parallel stream is unpredictable, the output could be any of the options given, but option D is the most likely.
References:
Oracle Certified Professional: Java SE 17 Developer
Java SE 17 Developer
OCP Oracle Certified Professional Java SE 17 Developer Study Guide
Parallelizing Streams
質問 # 21
Given:
Which statement is true?
- A. The program fails to compile.
- B. The program throws outofStockException.
- C. The program throws StockException.
- D. The program throws ClassCastException
正解:A
解説:
Explanation
The answer is B because the code fragment contains a syntax error that prevents it from compiling. The code fragment tries to catch a StockException in line 10, but the catch block does not have a parameter of type StockException. The catch block should have a parameter of type StockException, such as:
catch (StockException e) { // handle the exception }
This is required by the Java syntax for the catch clause, which must have a parameter that is a subclass of Throwable. Without a parameter, the catch block is invalid and causes a compilation error.
Option A is incorrect because the program does not throw a StockException, as it does not compile.
Option C is incorrect because the program does not throw an OutofStockException, as it does not compile.
Option D is incorrect because the program does not throw a ClassCastException, as it does not compile.
References:
Oracle Certified Professional: Java SE 17 Developer
Java SE 17 Developer
OCP Oracle Certified Professional Java SE 17 Developer Study Guide
The try-with-resources Statement (The Java™ Tutorials > Essential Classes > Exceptions) The catch Blocks (The Java™ Tutorials > Essential Classes > Exceptions)
質問 # 22
Given the directory structure:
Given the definition of the Doc class:
Which two are valid definition of the wordDoc class?
- A. Package p1, p2;
Public sealed class WordDoc extends Doc () - B. Package p1;
Public final class WordDoc extends Doc () - C. Package p1, p2;
Public non-sealed class WordDoc extends Doc () - D. Package p1;
Public class wordDoc extends Doc () - E. Package p1,
non-sealed abstract class WordDoc extends Doc () - F. Package p1;
Public non-sealed class wordDoc extends Doc ()
正解:B、F
解説:
The correct answer is A and F because the wordDoc class must be a non-sealed class or a final class to extend the sealed Doc class. Option B is incorrect because the wordDoc class must be non-sealed or final. Option C is incorrect because the wordDoc class cannot be in a different package than the Doc class. Option D is incorrect because the wordDoc class cannot be a sealed class. Option E is incorrect because the wordDoc class cannot be an abstract class. Reference: Oracle Certified Professional: Java SE 17 Developer, 3 Sealed Classes - Oracle Help Center
質問 # 23
Given the code fragment:
What is the result?
- A. Range 1
Range 2
Range 3 - B. Range 1
- C. Range1
Note a valid rank. - D. Range 1
Range 2
Range 3
Range 1
Not a valida rank
正解:D
解説:
The code fragment is using the switch statement with the new Java 17 syntax. The switch statement checks the value of the variable rank and executes the corresponding case statement. In this case, the value of rank is 4, so the first case statement is executed, printing "Range1". The second and third case statements are also executed, printing "Range2" and "Range3". The default case statement is also executed, printing "Not a valid rank". Reference: Java Language Changes - Oracle Help Center
質問 # 24
Which statement is true?
- A. The tryLock () method returns a boolean indicator immediately if it has managed to acquire the lock, otherwise it waits for the lock acquisition.
- B. The Lock () method returns a boolean indicator immediately regardless if it has or has not managed to acquire the lock
- C. The lock () method returns a boolean indicator immediately if it has managed to acquire the lock, otherwise it waits for the lock acquisition.
- D. The tryLock () method returns a boolean indicator immediately regardless if it has or has not managed to acquire the lock.
正解:D
解説:
The tryLock () method of the Lock interface is a non-blocking attempt to acquire a lock. It returns true if the lock is available and acquired by the current thread, and false otherwise. It does not wait for the lock to be released by another thread. This is different from the lock () method, which blocks the current thread until the lock is acquired, and does not return any value. Reference: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/concurrent/locks/Lock.html#tryLock(), 3, 4, 5
質問 # 25
Given the course table:
Given the code fragment:
- A. 0
- B. true
- C. 1
- D. false
正解:B
解説:
Explanation
The code fragment will execute the update statement and set the course fee of the course with ID 1021 to
5000. The executeUpdate method returns an int value that indicates the number of rows affected by the SQL statement. In this case, only one row will be updated, so the result variable will be 1. The if statement will check if the result is greater than 0, which is true, and print "Updated successfully". Therefore, the output of the code fragment is true. References: https://education.oracle.com/products/trackp_OCPJSE17,
https://mylearn.oracle.com/ou/learning-path/java-se-17-developer/99487,
https://docs.oracle.com/en/java/javase/17/docs/api/java.sql/java/sql/Statement.html#executeUpdate(java.lang.Str
質問 # 26
Given the code fragment:
What is the result?
- A. Cat
Dog - B. Cat
null - C. A NullPointerException is thrown
Cat
Cat - D. Dog
Dog
正解:B
解説:
The answer is E because the code fragment creates a new Pet object with the name "Dog" and assigns it to the variable p. Then, it assigns p to p1. Next, it changes the name of p1 to "Cat". Then, it assigns p1 to p. Finally, it sets p to null and prints the name of p and p1. The output will be "Cat" and "null" because p is set to null and p1 still points to the Pet object with the name "Cat".
質問 # 27
Given the product class:
And the shop class:
What is the result?
- A. Cookie 0.0 2.99
- B. Cookie 2.99 2.99
- C. Compilation fails
- D. An exception is produced at runtime
- E. Cookie 0.0 0.0
- F. Cookie 3.99 2.99
正解:C
解説:
Explanation
The code fragment will fail to compile because the readObject method in the Product class is missing the
@Override annotation. The readObject method is a special method that is used to customize the deserialization process of an object. It must be declared as private, have no return type, and take a single parameter of type ObjectInputStream. It must also be annotated with @Override to indicate that it overrides the default behavior of the ObjectInputStream class. Without the @Override annotation, the compiler will treat the readObject method as a normal method and not as a deserialization hook. Therefore, the code fragment will produce a compilation error. References: Object Serialization - Oracle, [ObjectInputStream (Java SE 17 & JDK 17) - Oracle]
質問 # 28
Given the code fragment:
Which action sorts the book list?
- A. At Line n1, convert type to mutable array type.
- B. At Line n2, replace books,sort() with books.stream().sort(0.
- C. At line n1, convert books type to mutable ArrayList type.
- D. At Line n2, replace compareTo () with compare ().
正解:D
解説:
The code fragment is trying to sort a list of books using the Collections.sort() method. The correct answer is D, because the compareTo() method is not the correct way to compare two objects in a Comparator. The compare() method is the correct way to compare two objects in a Comparator and return an int value that indicates their order1. The compareTo() method is used to implement the Comparable interface, which defines the natural order of objects of a class2. The other options are incorrect because they either do not change the type of the list, which is already mutable, or they do not use the correct syntax for sorting a stream, which requires a terminal operation such as collect()3. Reference: Comparator (Java SE 17 & JDK 17), Comparable (Java SE 17 & JDK 17), Stream (Java SE 17 & JDK 17)
質問 # 29
Given:
Which action enables the code to compile?
- A. Replace 15 with item.display (''Flower'');
- B. Replace 7 with public void display (string design) {
- C. Replace 2 with static string name;
- D. Replace 3 with private static void display () {
正解:B
解説:
The answer is C because the code fragment contains a syntax error in line 7, where the method display is declared without any parameter type. This causes a compilation error, as Java requires the parameter type to be specified for each method parameter. To fix this error, the parameter type should be added before the parameter name, such as string design. This will enable the code to compile and run without any errors. Reference:
Oracle Certified Professional: Java SE 17 Developer
Java SE 17 Developer
OCP Oracle Certified Professional Java SE 17 Developer Study Guide
Java Methods
質問 # 30
Given:
What is the result?
- A. runsruns
- B. runsflips
- C. flipsruns
- D. flipsflips
- E. Compilation fails
正解:E
解説:
Explanation
The code fragment will fail to compile because the play method in the Dog class is declared as private, which means that it cannot be accessed from outside the class. The main method is trying to call the play method on a Dog object, which is not allowed. Therefore, the code fragment will produce a compilation error.
質問 # 31
Given the code fragment:
What is the result?
- A. 0
- B. 2
2
0 - C. 1
- D. 1
2
-4 - E. 1
1
1 - F. 2
正解:A
解説:
Explanation
The code fragment uses the Collections.binarySearch method to search for the string "e3" in the list. The first search returns the index of the element, which is 2. The second search returns the index of the element, which is 0. The third search returns the index of the element, which is -4. The final result is
2. References: Collections (Java SE 17 & JDK 17) - Oracle
質問 # 32
Given:
What is the result?
- A. D D D
- B. B A D
- C. D A D
- D. B A C
正解:B
解説:
Explanation
The answer is C because the code demonstrates the concept of method overloading and type conversion in Java. Method overloading allows different methods to have the same name but different parameters. Type conversion allows values of one data type to be assigned to another data type, either automatically or explicitly. In the code, the class Test has four methods named sum, each with different parameter types: int, float, and double. The main method creates an instance of Test and calls the sum method with different arguments. The compiler will choose the most specific method that matches the arguments, based on the following rules:
If there is an exact match between the argument types and the parameter types, that method is chosen.
If there is no exact match, but there is a method with compatible parameter types, that method is chosen.
Compatible types are those that can be converted from one to another automatically, such as int to long or float to double.
If there is more than one method with compatible parameter types, the most specific method is chosen.
The most specific method is the one whose parameter types are closest to the argument types in terms of size or precision.
In the code, the following method calls are made:
test.sum(10, 10.5) -> This matches the sum(int a, float b) method exactly, so it is chosen.
The result is 20.5, which is converted to int and printed as 20 (B).
test.sum(10) -> This does not match any method exactly, but it matches the sum(double a) method with compatible types, as int can be converted to double automatically. The result is 10.0, which is printed as 10
(A). test.sum(10.5, 10) -> This does not match any method exactly, but it matches two methods with compatible types: sum(float a, float b) and sum(double a, double b). The latter is more specific, as double is closer to the argument types than float. The result is 20.5, which is printed as 20 (D).
Therefore, the output is B A D. References
Oracle Certified Professional: Java SE 17 Developer
Java SE 17 Developer
OCP Oracle Certified Professional Java SE 17 Developer Study Guide
Method Overloading in Java
Type conversion in Java with Examples
Java Method Overloading with automatic type conversions
質問 # 33
Given:
- A. Compilation fails
- B. A NumberFormatException is thrown
- C. Hello
- D. there
正解:A
解説:
The code fragment will fail to compile because the parseInt method of the Integer class is a static method, which means that it can be invoked without creating an object of the class. However, the code is trying to invoke the parseInt method on an object of type Integer, which is not allowed. The correct way to invoke the parseInt method is by using the class name, such as Integer.parseInt (s). Therefore, the code fragment will produce a compilation error. Reference: Integer (Java SE 17 & JDK 17) - Oracle
質問 # 34
Given:
What is the result?
- A. The program throws a MissingResourceException.
- B. User name (EN - US)
- C. User name (EN)
- D. UserName
- E. User name (US)
正解:A
解説:
The answer is B because the code fragment contains a logical error that causes a MissingResourceException at runtime. The code fragment tries to load a resource bundle with the base name "Captions.properties" and the locale "en_US". However, there is no such resource bundle available in the classpath. The available resource bundles are:
Captions.properties
Captions_en.properties
Captions_US.properties
Captions_en_US.properties
The ResourceBundle class follows a fallback mechanism to find the best matching resource bundle for a given locale. It first tries to find the resource bundle with the exact locale, then it tries to find the resource bundle with the same language and script, then it tries to find the resource bundle with the same language, and finally it tries to find the default resource bundle with no locale. If none of these resource bundles are found, it throws a MissingResourceException.
In this case, the code fragment is looking for a resource bundle with the base name "Captions.properties" and the locale "en_US". The ResourceBundle class will try to find the following resource bundles in order:
Captions.properties_en_US
Captions.properties_en
Captions.properties
However, none of these resource bundles exist in the classpath. Therefore, the ResourceBundle class will throw a MissingResourceException.
To fix this error, the code fragment should use the correct base name of the resource bundle family, which is "Captions" without the ".properties" extension. For example:
ResourceBundle captions = ResourceBundle.getBundle("Captions", currentLocale); This will load the appropriate resource bundle for the current locale, which is "Captions_en_US.properties" in this case. Reference:
Oracle Certified Professional: Java SE 17 Developer
Java SE 17 Developer
OCP Oracle Certified Professional Java SE 17 Developer Study Guide
ResourceBundle (Java Platform SE 8 )
About the ResourceBundle Class (The Java™ Tutorials > Internationalization)
質問 # 35
Which statement is true?
- A. thread in waiting state consumes CPU cycles.
- B. IllegalStateException is thrown if a thread in waiting state is moved back to runnable.
- C. After the timed wait expires, the waited thread moves to the terminated state.
- D. A thread in waiting state must handle InterrupedException.
正解:D
解説:
A thread in waiting state is waiting for another thread to perform a particular action, such as calling notify() or notifyAll() on a shared object, or terminating a joined thread. A thread in waiting state can be interrupted by another thread, which will cause the waiting thread to throw an InterruptedException and return to the runnable state. Therefore, a thread in waiting state must handle InterruptedException, either by catching it or declaring it in the throws clause. Reference: Thread.State (Java SE 17 & JDK 17), [Thread (Java SE 17 & JDK 17)]
質問 # 36
Given the code fragment:
Which code fragment returns different values?
- A. int sum = listOfNumbers. Stream () reduce (5, (a, b) -> a + b) ;
- B. int sum = listOfNumbers. parallelStream () reduce (5, Integer:: sum) ;
- C. int sum = listOfNumbers. Stream () reduce (0, Integer:: sum) + 5
- D. int sum = listOfNumbers. Stream () reduce ( Integer:: sum) ; +5;
- E. int sum = listOfNumbers. parallelStream () reduce ({m, n) -> m +n) orElse (5) +5;
正解:D
解説:
The answer is C because the code fragment uses a different syntax and logic for the reduce operation than the other options. The reduce method in option C takes a single parameter, which is a BinaryOperator that combines two elements of the stream into one. The method returns an Optional, which may or may not contain a value depending on whether the stream is empty or not. The code fragment then adds 5 to the result of the reduce method, regardless of whether it is present or not. This may cause an exception if the Optional is empty, or produce a different value than the other options if the Optional is not empty.
The other options use a different syntax and logic for the reduce operation. They all take two parameters, which are an identity value and a BinaryOperator that combines an element of the stream with an accumulator. The method returns the final accumulator value, which is equal to the identity value if the stream is empty, or the result of applying the BinaryOperator to all elements of the stream otherwise. The code fragments then add 5 to the result of the reduce method, which will always produce a valid value.
For example, suppose listOfNumbers contains [1, 2, 3]. Then, option A will perform the following steps:
Initialize accumulator to identity value 5
Apply BinaryOperator Integer::sum to accumulator and first element: 5 + 1 = 6 Update accumulator to 6 Apply BinaryOperator Integer::sum to accumulator and second element: 6 + 2 = 8 Update accumulator to 8 Apply BinaryOperator Integer::sum to accumulator and third element: 8 + 3 = 11 Update accumulator to 11 Return final accumulator value 11 Add 5 to final accumulator value: 11 + 5 = 16 Option B will perform the same steps as option A, except using a lambda expression instead of a method reference for the BinaryOperator. Option D will perform the same steps as option A, except using parallelStream instead of stream, which may change the order of applying the BinaryOperator but not the final result. Option E will perform the same steps as option A, except using identity value 0 instead of 5.
Option C, however, will perform the following steps:
Apply BinaryOperator Integer::sum to first and second element: 1 + 2 = 3 Apply BinaryOperator Integer::sum to previous result and third element: 3 + 3 = 6 Return Optional containing final result value 6 Add 5 to Optional value: Optional.of(6) + 5 = Optional.of(11) As you can see, option C produces a different value than the other options, and also uses a different syntax and logic for the reduce operation. Reference:
Oracle Certified Professional: Java SE 17 Developer
Java SE 17 Developer
OCP Oracle Certified Professional Java SE 17 Developer Study Guide
Guide to Stream.reduce()
質問 # 37
Given the code fragment:
abstract sealed interface SInt permits Story, Art { default String getTitle() { return "Book Title" ; }
}
Which set of class definitions compiles?
- A. Public interface story extends sInd {}
Public interface Art extends SInt {} - B. Non-sealed interface story extends SInt {}
Class Art implements Sint {} - C. Non-sealed interface story extends SInt {}
Non-sealed interaface Art extends Sint {} - D. Interace story extends STnt {}
Interface Art extends SInt {} - E. Sealed interface Storty extends sInt {}
Non-sealed class Art implements Sint {}
正解:E
解説:
The answer is C because the code fragment given is an abstract sealed interface SInt that permits Story and Art. The correct answer is option C, which is a sealed interface Story that extends SInt and a non-sealed class Art that implements SInt. This is because a sealed interface can only be extended by the classes or interfaces that it permits, and a non-sealed class can implement a sealed interface.
Option A is incorrect because interface is misspelled as interace, and Story and Art should be capitalized as they are the names of the permitted classes or interfaces.
Option B is incorrect because public is misspelled as public, and sInd should be SInt as it is the name of the sealed interface.
Option D is incorrect because a non-sealed interface cannot extend a sealed interface, as it would violate the restriction of permitted subtypes.
Option E is incorrect because both Story and Art cannot be non-sealed interfaces, as they would also violate the restriction of permitted subtypes.
Reference:
Oracle Certified Professional: Java SE 17 Developer
Java SE 17 Developer
OCP Oracle Certified Professional Java SE 17 Developer Study Guide
Sealed Classes and Interfaces in Java 15 | Baeldung
Sealed Class in Java - Javatpoint
質問 # 38
Which statement is true?
- A. The tryLock () method returns a boolean indicator immediately if it has managed to acquire the lock, otherwise it waits for the lock acquisition.
- B. The Lock () method returns a boolean indicator immediately regardless if it has or has not managed to acquire the lock
- C. The lock () method returns a boolean indicator immediately if it has managed to acquire the lock, otherwise it waits for the lock acquisition.
- D. The tryLock () method returns a boolean indicator immediately regardless if it has or has not managed to acquire the lock.
正解:D
解説:
Explanation
The tryLock () method of the Lock interface is a non-blocking attempt to acquire a lock. It returns true if the lock is available and acquired by the current thread, and false otherwise. It does not wait for the lock to be released by another thread. This is different from the lock () method, which blocks the current thread until the lock is acquired, and does not return any value. References:
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/concurrent/locks/Lock.html#tryLock(), 3, 4
質問 # 39
......
1z1-829[2024年08月] 最新リリース] 試験問題あなたを必ず合格させます:https://jp.fast2test.com/1z1-829-premium-file.html