Given the code fragment:
What is the result?
Correct Answer:
B
The code fragment is comparing the values of a, b, and c using the < and > operators. The first comparison, d, is checking if a is less than b and greater than c. Since a is equal to 2, b is equal to -2, and c is equal to -4, this comparison will evaluate to true. The second comparison, e, is checking if a is greater than b and a is greater than c. Since a is equal to 2, b is equal to -2, and c is equal to -4, this comparison will evaluate to false.
Therefore, the result will be true 1 false 2. References: Operators (The Java™ Tutorials > Learning the Java Language - Oracle
Given:
What is the result?
A.
1001
1001
1000
B.
101
101
1000
C.
100
100
1000
D.
1001
100
1000
Correct Answer:
D
The code fragment is using the bitwise operators & (AND), | (OR), and ^ (XOR) to perform operations on the binary representations of the integer values. The & operator returns a 1 in each bit position where both operands have a 1, the | operator returns a 1 in each bit position where either operand has a 1, and the ^ operator returns a 1 in each bit position where only one operand has a 1. The binary representations of the integer values are as follows:
✑ 1000 = 1111101000
✑ 100 = 1100100
✑ 101 = 1100101
The code fragment performs the following operations:
✑ x = x ^ y; // x becomes 1111010101, which is 1001 in decimal
✑ y = x ^ y; // y becomes 1100100, which is 100 in decimal
✑ x = x ^ y; // x becomes 1100101, which is 101 in decimal
The code fragment then prints out the values of x, y, and z, which are 1001, 100, and 1000 respectively. Therefore, option D is correct.
Which statement is true about migration?
Correct Answer:
B
The answer is B because a bottom-up migration is a strategy for modularizing an existing application by moving its dependencies to the module path one by one, starting from the lowest-level libraries and ending with the application itself. This way, each module can declare its dependencies on other modules using the module-info.java file, and benefit from the features of the Java Platform Module System (JPMS), such as reliable configuration, strong encapsulation, and service loading.
Option A is incorrect because a top-down migration is a strategy for modularizing an existing application by moving it to the module path first, along with its dependencies as automatic modules. Automatic modules are non-modular JAR files that are treated as modules with some limitations, such as not having a module descriptor or a fixed name. A top-down migration allows the application to use the module path without requiring all of its dependencies to be modularized first.
Option C is incorrect because a top-down migration does not require any specific order of migrating modules, as long as the application is moved first and its dependencies are moved as automatic modules. A bottom-up migration, on the other hand, requires the required modules to migrate before the modules that depend on them.
Option D is incorrect because unnamed modules are not automatic modules in any migration strategy. Unnamed modules are modules that do not have a name or a module descriptor, such as classes loaded from the class path or dynamically generated classes. Unnamed modules have unrestricted access to all other modules, but they cannot be accessed by named modules, except through reflection with reduced security checks. References:
✑ Oracle Certified Professional: Java SE 17 Developer
✑ Java SE 17 Developer
✑ OCP Oracle Certified Professional Java SE 17 Developer Study Guide
✑ Migrating to Modules (How and When) - JavaDeploy
✑ Java 9 Modularity: Patterns and Practices for Developing Maintainable
Applications
Given the code fragment:
What is the result?
Correct Answer:
B
The code fragment is using the Java SE 17 API to get the current time and then truncating it to minutes. The result will be the current time truncated to minutes, which is why option B is correct. References:
✑ https://education.oracle.com/products/trackp_OCPJSE17
✑ https://mylearn.oracle.com/ou/learning-path/java-se-17-developer/99487
✑ https://docs.oracle.com/javase/17/docs/api/java.base/java/time/Instant.html#truncatedTo(java.time.temporal.TemporalUnit)
Given the code fragment:
What is the result:
Correct Answer:
D
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