{"id":81866,"date":"2022-04-11T00:53:27","date_gmt":"2022-04-11T06:23:27","guid":{"rendered":"https:\/\/www.whizlabs.com\/blog\/?p=81866"},"modified":"2023-03-21T00:53:22","modified_gmt":"2023-03-21T06:23:22","slug":"java-se-11-developer-exam-questions","status":"publish","type":"post","link":"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/","title":{"rendered":"Free Sample Questions on Oracle Certified Professional, Java SE 11 Developer (1Z0-819)"},"content":{"rendered":"<p>Are you looking for Oracle Certified Java SE 11 developer questions ? Then this article has sample questions on <a href=\"https:\/\/www.whizlabs.com\/ocpjd-java-se-11-developer-1z0-819\/\">Java SE 11 Developer certification<\/a> exam and it is free.<\/p>\n<p><span style=\"font-weight: 400;\">The Oracle Certified Professional, Java SE 11 Developer (1Z0-819) certification exam requires a thorough knowledge of Java Programming and coding practices. If you are thinking about how to pass 1Z0-819 exam, then these Java SE 11 developer exam questions<\/span><span style=\"font-weight: 400;\"> give you a clear picture of what the actual exam is going to be like.\u00a0<\/span><\/p>\n<p>Let&#8217;s start Learning !<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_76 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #ea7e02;color:#ea7e02\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #ea7e02;color:#ea7e02\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Secure_Coding_in_Java_SE_Application\" >Domain : Secure Coding in Java SE Application<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Annotations\" >Domain : Annotations<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Java_IO_API\" >Domain : Java I\/O API<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Localization\" >Domain : Localization<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Exception_Handling\" >Domain : Exception Handling<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Working_with_Arrays_and_Collections\" >Domain : Working with Arrays and Collections<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Working_with_Streams_and_Lambda_expressions\" >Domain : Working with Streams and Lambda expressions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Exception_Handling-2\" >Domain : Exception Handling<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_S2-_Controlling_Program_Flow\" >Domain : S2- Controlling Program Flow<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Secure_Coding_in_Java_SE_Application-2\" >Domain : Secure Coding in Java SE Application<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Annotations-2\" >Domain : Annotations<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Concurrency\" >Domain : Concurrency<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Secure_Coding_in_Java_SE_Application-3\" >Domain : Secure Coding in Java SE Application<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Java_IO_API-2\" >Domain : Java I\/O API<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_S2-_Controlling_Program_Flow-2\" >Domain : S2- Controlling Program Flow<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Working_with_Streams_and_Lambda_expressions-2\" >Domain : Working with Streams and Lambda expressions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Java_Object-Oriented_Approach\" >Domain : Java Object-Oriented Approach<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Concurrency-2\" >Domain : Concurrency<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Java_IO_API-3\" >Domain : Java I\/O API<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Java_Platform_Module_System\" >Domain : Java Platform Module System<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Localization-2\" >Domain : Localization<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Java_Platform_Module_System-2\" >Domain : Java Platform Module System<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Exception_Handling-3\" >Domain : Exception Handling<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Working_with_Streams_and_Lambda_expressions-3\" >Domain : Working with Streams and Lambda expressions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Java_Platform_Module_System-3\" >Domain : Java Platform Module System<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Annotations-3\" >Domain: Annotations<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Domain_Java_Platform_Module_System-4\" >Domain: Java Platform Module System<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-28\" href=\"https:\/\/www.whizlabs.com\/blog\/java-se-11-developer-exam-questions\/#Summary\" >Summary<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Secure_Coding_in_Java_SE_Application\"><\/span><span style=\"font-weight: 400;\">Domain : Secure Coding in Java SE Application<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q1 : To which of the following attacks is this code vulnerable?<\/strong><br \/>\n<strong>public boolean getEmployee(Integer id) throws SQLException {<\/strong><br \/>\n<strong>var sql = &#8220;SELECT * FROM emp WHERE id = ?&#8221;;<\/strong><br \/>\n<strong>try (var stmt = conn.prepareStatement(sql)) {<\/strong><br \/>\n<strong>stmt.setInt(1, id);<\/strong><br \/>\n<strong>try (var rs = stmt.executeQuery(sql)) {<\/strong><br \/>\n<strong>return rs.next();<\/strong><br \/>\n<strong>}<\/strong><br \/>\n<strong>}<\/strong><br \/>\n<strong>}<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Leaking Resources<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Leaking Confidential data<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>DoS<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>SQL injection<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>None of these<\/span><\/p>\n<p><b>Correct Answer: E<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><b>Choice E is the correct answer.<\/b><span style=\"font-weight: 400;\"> this code is not vulnerable to any of these attacks. This is a trick question that might appear in the exam.<\/span><br \/>\n<b>Choice A is incorrect. <\/b><span style=\"font-weight: 400;\">The usage of tryWithResources statement ensures that PreparedStatement and ResultSet objects are closed automatically and hence there is no leakage of resources.\u00a0<\/span><br \/>\n<span style=\"font-weight: 400;\">Confidential data leak can happen if sensitive data is logged in log files, exception messages etc.<\/span><b> Choice B is incorrect <\/b><span style=\"font-weight: 400;\">because no confidential data leaking is possible on this code.<\/span><br \/>\n<span style=\"font-weight: 400;\">Denial-of-Service (DoS) attack is an explicit attempt to prevent legitimate users from using a service by hackers. Such an attack typically launched by sending continuous requests to the server for a particular web resource. <\/span><b>Choice C is also incorrect <\/b><span style=\"font-weight: 400;\">because there is no Denial of Service attack possible here.<\/span><br \/>\n<span style=\"font-weight: 400;\">SQL injection is a common attack that consists of insertion of SQL code via input data from the client application. <\/span><b>Choice D is incorrect<\/b><span style=\"font-weight: 400;\"> because SQL injection is not applicable here because of the proper use of PreparedStatement with bind variables here.<\/span><\/p>\n<p><b>Reference: <\/b><a href=\"https:\/\/www.oracle.com\/java\/technologies\/javase\/seccodeguide.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/www.oracle.com\/java\/technologies\/javase\/seccodeguide.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Annotations\"><\/span><span style=\"font-weight: 400;\">Domain : Annotations<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q2 : Which of the following are true about annotations?<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Annotation names are not case sensitive<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Annotations always contain elements<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Annotations can be applied to classes, methods, expressions, and annotations<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>When using a marker annotation, parentheses are optional<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>None of these<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>F. <\/strong>All of these<\/span><\/p>\n<p><b>Correct Answers: C and D<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Annotations, a form of metadata, provide data about a program that is not part of the program itself. Annotations have no direct effect on the operation of the code they annotate.<\/span><\/p>\n<p><b>Choice C is correct.<\/b><span style=\"font-weight: 400;\"> Annotations can be applied to declarations: declarations of classes, fields, methods, and other program elements.<\/span><br \/>\n<b>Choice D is also correct.<\/b><span style=\"font-weight: 400;\"> If the annotation has no elements, then the parentheses can be omitted. Such annotations are called marker annotations.<\/span><br \/>\n<b>Choice A is incorrect. <\/b><span style=\"font-weight: 400;\">Annotation names are case sensitive.<\/span><br \/>\n<b>Choice B is incorrect. <\/b><span style=\"font-weight: 400;\">An annotation can have elements, these look like methods. However, these are optional. The only purpose is to mark a declaration and hence are called marker annotations.<\/span><\/p>\n<p><b>References: <\/b><a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/java\/annotations\/basics.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/javase\/tutorial\/java\/annotations\/basics.html<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/java\/annotations\/declaring.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/javase\/tutorial\/java\/annotations\/declaring.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_IO_API\"><\/span><span style=\"font-weight: 400;\">Domain : Java I\/O API<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q3 : Which code fragment when inserted at line 3 will produce the output as &#8220;..\/..\/a.txt&#8221;<\/strong><br \/>\n<strong>1 var path1 = Path.of(&#8220;a.txt&#8221;);<\/strong><br \/>\n<strong>2 var path2 = Path.of(&#8220;b\/c.txt&#8221;);<\/strong><br \/>\n<strong>3 \/\/ insert code here<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>System.out.println(path1.relativize(path2));<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>System.out.println(path2.relativize(path1));<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>System.out.println(path2.normalize(path1));<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>System.out.println(path1.normalize(path2));<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>None of these<\/span><\/p>\n<p><b>Correct Answer: B<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The relativize(Path) method constructs a relative path between the current path and a given path. If both path values are relative, then the relativize() method computes the paths<\/span><\/p>\n<p><span style=\"font-weight: 400;\">as if they are in the same current working directory. Alternatively, if both path values are<\/span><\/p>\n<p><span style=\"font-weight: 400;\">absolute, then the method computes the relative path from one absolute location to another,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">regardless of the current working directory.<\/span><\/p>\n<p><b>Choice B is correct. <\/b><span style=\"font-weight: 400;\">To get to a.txt from the current path of b\/c.txt , you need to go up two levels (the file itself counts as one level) and then select a.txt. The output of choice B is \u201c..\/..\/a.txt\u201d. <\/span><b>Thus choice B is correct and E is incorrect.<\/b><br \/>\n<span style=\"font-weight: 400;\">Calling relativize() is on path2 will get to the path b\/c.txt from the current path of a.txt, resulting in the output\u00a0 \u201c..\/b\/c.txt\u201d. This is not the expected result and hence <\/span><b>choice A is incorrect.<\/b><br \/>\n<span style=\"font-weight: 400;\">The normalize() method is invoked on a Path object to eliminate unnecessary redundancies in a path. An empty path is returned if this path does not have a root component and all name elements are redundant. This method takes no arguments. Hence choices and D will cause compiler errors. <\/span><b>Thus choices C and D are incorrect.\u00a0<\/b><\/p>\n<p><b>References: <\/b><a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/nio\/file\/Path.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/nio\/file\/Path.html<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/essential\/io\/pathOps.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/javase\/tutorial\/essential\/io\/pathOps.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Localization\"><\/span><span style=\"font-weight: 400;\">Domain : Localization<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q4 : What is the result of compiling and running this code?<\/strong><br \/>\n<strong>double d = 1234567.890;<\/strong><br \/>\n<strong>NumberFormat f2 = new DecimalFormat(&#8220;$000,000,000.00000&#8221;);<\/strong><br \/>\n<strong>System.out.println(f2.format(d));<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Does not compile<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Throws exception<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Prints $001,234,567.89000<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>Prints $1,234,567.89<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>Prints a different result<\/span><\/p>\n<p><b>Correct Answer: C<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The format method of DecimalFormat accepts a double value as an argument and returns the formatted number in a String. The pattern parameter passed to the DecimalFormat constructor is the number pattern that numbers should be formatted according to.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">There are 11 Special Pattern Characters, but the most important are:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">0 \u2013 prints a digit if provided, 0 otherwise<\/span><\/p>\n<p><span style=\"font-weight: 400;\">hash \u2013 prints a digit if provided, nothing otherwise<\/span><\/p>\n<p><span style=\"font-weight: 400;\">. \u2013 indicate where to put the decimal separator<\/span><\/p>\n<p><span style=\"font-weight: 400;\">, \u2013 indicate where to put the grouping separator<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In the code fragment given, &#8220;$000,000,000.00000&#8221; is the format string given. So the output should have a length of 9 digits before the decimal point and 5 digits after that. To the number 1234567.890, the format method adds leading and trailing zeros to make the output the desired length, as 0 is used as the pattern character. Also, a dollar sign is prefixed, as the pattern starts with it. Hence <\/span><b>choice C is correct.<\/b><br \/>\n<span style=\"font-weight: 400;\">If hash was used instead of 0 in the pattern, 1234567.89 would have no trailing or leading zeros appended to it and D would have been correct. Hence, in this case,<\/span><b> option D is incorrect.<\/b><br \/>\n<b>Options A and B are incorrect<\/b><span style=\"font-weight: 400;\"> because there are no such errors. As<\/span><b> C is correct, choice E is automatically incorrect.<\/b><\/p>\n<p><b>Reference: <\/b><a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/text\/DecimalFormat.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/text\/DecimalFormat.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Exception_Handling\"><\/span><span style=\"font-weight: 400;\">Domain : Exception Handling<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q5 : Which feature in Java is an attempt to reduce the number of NullPointerExceptions?<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Optional<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Enum<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Predicate<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>Annotation<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>Module<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>F. <\/strong>None of these<\/span><\/p>\n<p><b>Correct Answer: A<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Java 8 Optional class allows representing optional values instead of null references. This reduces the possibility of NullPointerExceptions. Optional can be considered as a single-value container that either contains a value or doesn&#8217;t. The advantage of using Optional as compared to null references is that the Optional class forces you to think about the case when the value is not present. As a consequence, you can prevent unintended null pointer exceptions. Thus <\/span><b>choice A is correct and F is incorrect.<\/b><br \/>\n<span style=\"font-weight: 400;\">An enum type is a special data type that enables for a variable to be a set of predefined constants. The variable must be equal to one of the values that have been predefined for it. It has nothing to do with NullPointerException and hence <\/span><b>choice B is incorrect.<\/b><br \/>\n<span style=\"font-weight: 400;\">Predicate is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference. Hence <\/span><b>C is also incorrect.<\/b><br \/>\n<span style=\"font-weight: 400;\">Annotations, a form of metadata, provide data about a program that is not part of the program oo.itself. Annotations have no direct effect on the operation of the code. So <\/span><b>D is incorrect<\/b><span style=\"font-weight: 400;\"> too.<\/span><br \/>\n<span style=\"font-weight: 400;\">.A Java module is a packaging mechanism that enables you to package a Java application or Java API as a separate Java module. So <\/span><b>E is incorrect <\/b><span style=\"font-weight: 400;\">too.<\/span><\/p>\n<p><b>Reference: <\/b><a href=\"https:\/\/www.oracle.com\/technical-resources\/articles\/java\/java8-optional.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/www.oracle.com\/technical-resources\/articles\/java\/java8-optional.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Working_with_Arrays_and_Collections\"><\/span><span style=\"font-weight: 400;\">Domain : Working with Arrays and Collections<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q6 : What will be the output of this code?<\/strong><br \/>\n<strong>Set&lt;String&gt; colors = new HashSet&lt;&gt;(); \/\/line 1<\/strong><br \/>\n<strong>colors.add(&#8220;yellow&#8221;); \/\/line 2<\/strong><br \/>\n<strong>colors.add(&#8220;Blue&#8221;); \/\/line 3<\/strong><br \/>\n<strong>colors.sort((a1, a2) -&gt; a1.compareTo(a2)); \/\/line 4<\/strong><br \/>\n<strong>System.out.println(colors);<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Prints [yellow, Blue]<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Exception at runtime<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Prints [Blue, yellow]<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>Compiler error at line 1<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>Compiler error at line 4<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>F. <\/strong>None of these<\/span><\/p>\n<p><b>Correct Answer: E<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">A Set is an unordered collection with no duplicate elements. As a HashSet does not maintain the order of its elements, sorting of HashSet is not possible. However, a List is a sortable collection, which takes a Comparator, as the argument. A Comparator is an object that defines a compare() method that can be used to compare two objects, this defines the sort order. However, there is no such sort() method in Set.<\/span><\/p>\n<p><b>Choice E is correct<\/b><span style=\"font-weight: 400;\">. As the sort() method is not defined for Set implementations, line 4 in the given example does not compile. The compiler complains that the sort() method is undefined.<\/span><br \/>\n<b>Choice A is incorrect.<\/b><span style=\"font-weight: 400;\"> As there is a compiler error in line 4, nothing is printed.<\/span><br \/>\n<b>Choice B is incorrect.<\/b><span style=\"font-weight: 400;\"> As the program has a compiler error, a runtime exception cannot be thrown.<\/span><br \/>\n<b>Choice C is incorrect<\/b><span style=\"font-weight: 400;\"> because the program cannot be executed due to the compiler error. If the sample code had List and ArrayList instead of Set and HashSet, the output would have been [Blue, yellow].<\/span><br \/>\n<b>Choice D is incorrect.<\/b><span style=\"font-weight: 400;\"> The diamond operator was introduced in Java 7 to simplify instantiation of generic classes. When the diamond &lt;&gt; operator is used on the right side as in line 1. the compiler can infer that the class instantiated is to have the same type as the variable it is assigned to. Hence there is no compiler error in line 1.<\/span><\/p>\n<p><b>Reference: <\/b><a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/collections\/interfaces\/order.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/javase\/tutorial\/collections\/interfaces\/order.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Working_with_Streams_and_Lambda_expressions\"><\/span><span style=\"font-weight: 400;\">Domain : Working with Streams and Lambda expressions<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q7 : When will the Student object created on line 3 become eligible for garbage collection?<\/strong><br \/>\n<strong>public class Student { \/\/ line 1<\/strong><br \/>\n<strong>\u00a0\u00a0public static void main(String[] args) { \/\/ line 2<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0Student one = new Student(); \/\/ line 3<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0Student two = one; \/\/ line 4<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0Student three = two; \/\/ line 5<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0one = null; \/\/ line 6<\/strong><br \/>\n<strong>\u00a0 \u00a0Student four = one; \/\/ line 7<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0two = null; \/\/ line 8<\/strong><br \/>\n<strong>\u00a0 \u00a0three = new Student(); \/\/ line 9<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0System.gc(); \/\/ line 10<\/strong><br \/>\n<strong>\u00a0\u00a0} \/\/ Line 11<\/strong><br \/>\n<strong>}<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>After line 6<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>After line 7<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>After line 8<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>After line 9<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>After line 10<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>F. <\/strong>After line 11<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>G. <\/strong>None of these<\/span><\/p>\n<p><b>Correct Answer: D<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The Student object from line 3 has three references to it: one, two and three. The references one and two are set to null on lines 6 and 8, respectively. The reference three is made to point to a new Student object in line 9. Hence, there will be no more references after line 9 and is thus eligible for GC (garbage collection). Hence,<\/span><b> choice D is correct.<\/b><br \/>\n<b>Choice A is incorrect<\/b><span style=\"font-weight: 400;\"> because only the reference one is set to null after line 6. The references two and three still point to the object and hence it cannot be garbage collected.<\/span><br \/>\n<b>Choice B is incorrect <\/b><span style=\"font-weight: 400;\">because the reference four is set to null in line 7 and this has no effect on GC.<\/span><br \/>\n<b>Choice C is incorrect <\/b><span style=\"font-weight: 400;\">because only the references one and two are set to null by line 8, the reference three still points to the object and hence it cannot be garbage collected.<\/span><br \/>\n<span style=\"font-weight: 400;\">As no more references exist for the object after line 9, the object becomes eligible for GC that time itself. This makes <\/span><b>choices E, F and G incorrect. <\/b><span style=\"font-weight: 400;\">Also, note that calling System.gc() has no effect on eligibility for garbage collection.<\/span><\/p>\n<p><b>References: <\/b><a href=\"https:\/\/www.oracle.com\/webfolder\/technetwork\/tutorials\/obe\/java\/gc01\/index.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/www.oracle.com\/webfolder\/technetwork\/tutorials\/obe\/java\/gc01\/index.html<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/javarevisited.blogspot.com\/2011\/04\/garbage-collection-in-java.html#axzz6p6PJImg8\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/javarevisited.blogspot.com\/2011\/04\/garbage-collection-in-java.html#axzz6p6PJImg8<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Exception_Handling-2\"><\/span><span style=\"font-weight: 400;\">Domain : Exception Handling<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q8 : What will be the result?<\/strong><br \/>\n<strong>public static void main(String[] args) {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0try {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0FileReader fileReader = new FileReader(&#8220;c:\\\\data\\\\input-text.txt&#8221;);<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0int data = fileReader.read();<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} catch (IOException | IllegalStateException ex) {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ex = null;<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/strong><br \/>\n<strong>}<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Does not compile because FileReader is not closed after use<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Does not compile because multiple exceptions cannot be caught in a single catch block<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Does not compile because IllegalStateException does not extend IOException<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>Does not compile because ex cannot be reassigned to anything<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>Does not compile because null value cannot be assigned to any exception variable<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>F. <\/strong>Runs without any errors<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>G. <\/strong>Throws an exception at runtime<\/span><\/p>\n<p><b>Correct Answer: D<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Java provides a feature named multi-catch blocks in which you can combine multiple catch handlers. The catch clauses of multiple exceptions can be combined using a single pipe symbol (|). : If a catch block handles more than one exception type, then the catch parameter is implicitly final, and thus it cannot be reassigned to anything. Hence ex=null assignment does not compile. Thus, <\/span><b>choice D is correct.<\/b><br \/>\n<span style=\"font-weight: 400;\">Ideally, resources such as FileReader must be closed after use to prevent any resource leak. However, this does not cause any error while compiling. Hence, <\/span><b>choice A is incorrect.<\/b><br \/>\n<span style=\"font-weight: 400;\">As multiple exceptions can be handled in a multi-catch block, <\/span><b>choice B is incorrect. <\/b><span style=\"font-weight: 400;\">In a multi-catch block, you cannot combine catch handlers for two exceptions that share a base- and derived-class relationship. Hence, <\/span><b>choice C is incorrect.<\/b><br \/>\n<b>Choice E is incorrect <\/b><span style=\"font-weight: 400;\">because there is no such rule that a null value cannot be assigned to an exception variable.<\/span><br \/>\n<span style=\"font-weight: 400;\">As <\/span><b>choice D is correct, choices F and G are also incorrect.<\/b><\/p>\n<p><b>Reference: <\/b><a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/technotes\/guides\/language\/catch-multiple.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/javase\/7\/docs\/technotes\/guides\/language\/catch-multiple.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_S2-_Controlling_Program_Flow\"><\/span><span style=\"font-weight: 400;\">Domain : S2- Controlling Program Flow<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q9 : What is the result of the following code snippet?<\/strong><br \/>\n<strong>public class Switch1 {<\/strong><br \/>\n<strong>private static final String APPLE = &#8220;APPLE&#8221;;<\/strong><br \/>\n<strong>private static String mango;<\/strong><br \/>\n<strong>public static void main(String[] args) {<\/strong><br \/>\n<strong>String fruit = &#8220;Berry&#8221;;<\/strong><br \/>\n<strong>mango = &#8220;Mango&#8221;;<\/strong><br \/>\n<strong>int i = 0;<\/strong><br \/>\n<strong>switch (fruit) {<\/strong><br \/>\n<strong>case &#8220;Mango&#8221;:<\/strong><br \/>\n<strong>break;<\/strong><br \/>\n<strong>case APPLE:<\/strong><br \/>\n<strong>i++;<\/strong><br \/>\n<strong>default:<\/strong><br \/>\n<strong>i++;<\/strong><br \/>\n<strong>case &#8220;VIOLIN&#8221;:<\/strong><br \/>\n<strong>i++;<\/strong><br \/>\n<strong>case &#8220;BERRY&#8221;:<\/strong><br \/>\n<strong>++i;<\/strong><br \/>\n<strong>break;<\/strong><br \/>\n<strong>}<\/strong><br \/>\n<strong>System.out.print(i);<\/strong><br \/>\n<strong>}\u00a0<\/strong><br \/>\n<strong>}<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>0<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>1<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>2<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>Throws an exception\u00a0<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>3<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>F. <\/strong>The code does not compile<\/span><\/p>\n<p><b>Correct Answer: E<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The switch statement is used where there are a number of possible execution paths. It works with the byte, short, char, and int primitive data types. It also works with enumerated types,the String class, and some wrapper classes.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">In the case of String expressions, the comparison is case sensitive like the String.equals method. Hence, the value &#8220;Berry&#8221; does not match the case &#8220;BERRY&#8221; or any other case. As a result, the default case is executed, which first increments i to 1. As there is no break statement, the next two cases are also executed, which result in i being incremented twice more. Thus the value of i is printed as 3. Thus <\/span><b>option E is correct <\/b><span style=\"font-weight: 400;\">and the other options are incorrect.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">As String is a valid expression type in the switch statement. Also, case expressions must be constants. APPLE is a constant as it is declared as final. Hence, there are no compiler errors or exceptions. So <\/span><b>options D and F are incorrect.<\/b><\/li>\n<\/ul>\n<p><b>References: <\/b><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/technotes\/guides\/language\/strings-switch.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/javase\/8\/docs\/technotes\/guides\/language\/strings-switch.html<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/java\/nutsandbolts\/switch.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/javase\/tutorial\/java\/nutsandbolts\/switch.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Secure_Coding_in_Java_SE_Application-2\"><\/span><span style=\"font-weight: 400;\">Domain : Secure Coding in Java SE Application<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q10 : What is the security issue in the given code?<\/strong><br \/>\n<strong>public class LibClass {<\/strong><br \/>\n<strong>transient boolean flag = false;<\/strong><br \/>\n<strong>private static final String FILESEPARATOR = &#8220;file.separator&#8221;;<\/strong><br \/>\n<strong>public static String getPropValue() {<\/strong><br \/>\n<strong>return AccessController.doPrivileged(new PrivilegedAction&lt;String&gt;() {<\/strong><br \/>\n<strong>public String run() {<\/strong><br \/>\n<strong>return System.getProperty(FILESEPARATOR);<\/strong><br \/>\n<strong>}<\/strong><br \/>\n<strong>});<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0}<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0public static void main(String args[]) throws Exception {<\/strong><br \/>\n<strong>try (var ois = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(&#8220;hello.txt&#8221;)))) {<\/strong><br \/>\n<strong>ois.writeObject(&#8220;Hello&#8221;);<\/strong><br \/>\n<strong>}<\/strong><br \/>\n<strong>System.out.println(getPropValue());<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0}<\/strong><br \/>\n<strong>}<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Code is not secure because reading a system property will always result is loss of sensitive data<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Code is not secure because the system property is retrieved using a hard-coded value<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Code is not secure because the variable flag is declared transient<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>Code is not secure because the resources are not closed after use<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>There is no such security issue in the code<\/span><\/p>\n<p><b>Correct Answer: E<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><b>Option E is correct.<\/b><span style=\"font-weight: 400;\"> There is no security issue in the code. No sensitive data is leaked, resources left open or there is any vulnerability.<\/span><br \/>\n<span style=\"font-weight: 400;\">Reading a system property might be necessary at times and in such cases privileged code can be given access only to that specific property, Thus sensitive data can be protected. Hence <\/span><b>option A is incorrect.<\/b><br \/>\n<span style=\"font-weight: 400;\">For safety reasons, the inputs passed to doPrivileged must be restricted to a limited set of acceptable (usually hard-coded) values. Instead of allowing the code to access any system property, only the given (hard-coded) system property can be accessed in this code. As this is secure, <\/span><b>option B is also incorrect.<\/b><br \/>\n<span style=\"font-weight: 400;\">Specifying transient variables does not cause any insecurity. In fact, it is advisable to keep sensitive data transient to prevent it from being serialized. Hence <\/span><b>option C is also incorrect.<\/b><br \/>\n<span style=\"font-weight: 400;\">When closing chained\/wrapped streams, we need to close only the outermost stream. In the given code, ObjectOutputStream is the outermost stream. This and the connected streams are automatically closed when the try-with-resources block ends. Hence, <\/span><b>option D is also incorrect.<\/b><\/p>\n<p><b>Reference: <\/b><a href=\"https:\/\/www.oracle.com\/java\/technologies\/javase\/seccodeguide.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/www.oracle.com\/java\/technologies\/javase\/seccodeguide.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Annotations-2\"><\/span><span style=\"font-weight: 400;\">Domain : Annotations<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q11 : Which annotation can be used to indicate that a method may be removed in a future release?<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>@Retention<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>@SuppressWarnings<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>@Deprecated<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>None of these<\/span><\/p>\n<p><b>Correct Answer: C<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">@Deprecated annotation can be used to indicate that the marked element (module, class, method, or member) should no longer be used. From Java 9, two optional attributes got added to the @Deprecated annotation: since and forRemoval. The since attribute defines the Java version in which the element was marked deprecated first. The default value is an empty string. The forRemoval attribute ( default value is false) can be specified as true if the element will be removed in the next release. Hence <\/span><b>option C is correct.<\/b><\/p>\n<p><span style=\"font-weight: 400;\">@Retention annotation is used to indicate how long annotations with the annotated type are to be retained. The possible values are below.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">SOURCE Used only in the source file, discarded by the compiler<\/span><\/p>\n<p><span style=\"font-weight: 400;\">CLASS Stored in the .class file but not available at runtime (default compiler behavior)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">RUNTIME Stored in the .class file and available at runtime<\/span><\/p>\n<p><span style=\"font-weight: 400;\">As this does not indicate anything about the use of an element in the future versions, <\/span><b>option A is incorrect.<\/b><br \/>\n<span style=\"font-weight: 400;\">The @SuppressWarnings annotation Indicates that the named compiler warnings should be suppressed in the annotated element (and in all program elements contained in the annotated element). Hence <\/span><b>option B is also incorrect.<\/b><\/p>\n<p><b>Reference: <\/b><a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/core\/enhanced-deprecation1.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/en\/java\/javase\/11\/core\/enhanced-deprecation1.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Concurrency\"><\/span><span style=\"font-weight: 400;\">Domain : Concurrency<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q12 : What is the expected result of executing the following code?<\/strong><br \/>\n<strong>ExecutorService service = null;<\/strong><br \/>\n<strong>Runnable task2 = () -&gt; {<\/strong><br \/>\n<strong>for (int i = 0; i &lt; 3; i++) {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0 try {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Thread.sleep(3000);<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0 } catch (InterruptedException e) {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0 e.printStackTrace();<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0 }<\/strong><br \/>\n<strong>}<\/strong><br \/>\n<strong>};<\/strong><br \/>\n<strong>try {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0 service = Executors.newSingleThreadExecutor();<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0 service.execute(task2);<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0 service.execute(task2);<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0 service.execute(task2);<\/strong><br \/>\n<strong>\u00a0} finally {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0 if (service != null)<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 service.shutdown();<\/strong><br \/>\n<strong>\u00a0\u00a0 }<\/strong><br \/>\n<strong>service.awaitTermination(2, TimeUnit.SECONDS);<\/strong><br \/>\n<strong>System.out.println(&#8220;Done&#8221;);<\/strong><br \/>\n<strong>}<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>It will immediately print &#8220;Done&#8221;<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>It will wait for 2 seconds and then print &#8220;Done&#8221;<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>It will wait for 3 seconds and then print &#8220;Done&#8221;<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>It will wait for 5 seconds and then print &#8220;Done&#8221;<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>It will wait for 9 seconds and then print &#8220;Done&#8221;<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>F. <\/strong>Code causes compiler error<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>G. <\/strong>It will throw an exception at runtime<\/span><\/p>\n<p><b>Correct Answer:<\/b> <b>B<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The awaitTermination() method waits the specified time until all tasks have completed execution, returning earlier if all tasks finish or an InterruptedException is detected.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In the main thread, three tasks are submitted to an ExecutorService. Then the ExecutorService is shut down. Each task takes at least 3 seconds to complete (Thread.sleep() is called for 3 seconds). As the awaitTermination() method is invoked passing 2 seconds, it will return with a value of false after two seconds. Hence, <\/span><b>option B is correct and options A, C, D and E are incorrect.<\/b><br \/>\n<span style=\"font-weight: 400;\">There is no compiler error or exception thrown. Hence, <\/span><b>options F and G are incorrect.<\/b><\/p>\n<p><b>Reference: <\/b><a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/concurrent\/ExecutorService.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/concurrent\/ExecutorService.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Secure_Coding_in_Java_SE_Application-3\"><\/span><span style=\"font-weight: 400;\">Domain : Secure Coding in Java SE Application<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q13 : Which of the following are needed to be used together to prevent SQL Injection attacks while executing SQL queries?<\/strong><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Use of CallableStatement<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Use of PreparedStatement<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Passing user-supplied data as bind variables<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Passing user-supplied data concatenated to SQL query<\/span><\/li>\n<\/ol>\n<p><b>Correct Answers: B and C<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">SQL injection is a hacking technique used to exploit an application&#8217;s vulnerability by passing user supplied data as part of an SQL query. To prevent this, PreparedStatement needs to be used by replacing the values in the bind variables (\u201c?\u201d) within the query with user supplied data. Hence, <\/span><b>options B and C are correct.<\/b><br \/>\n<span style=\"font-weight: 400;\">Unsanitized user data should never be concatenated with the query, hence <\/span><b>option D is incorrect.<\/b><br \/>\n<span style=\"font-weight: 400;\">Callable statement is used to execute stored procedures and not for SQL queries as specified in the question. Hence, <\/span><b>option A is also incorrect.<\/b><\/p>\n<p><b>Reference: <\/b><a href=\"https:\/\/www.oracle.com\/java\/technologies\/javase\/seccodeguide.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/www.oracle.com\/java\/technologies\/javase\/seccodeguide.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_IO_API-2\"><\/span><span style=\"font-weight: 400;\">Domain : Java I\/O API<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q14 : Given<\/strong><br \/>\n<strong>class Test {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0public static void main(String[] args) throws IOException {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Path root = Path.of(&#8220;root&#8221;);<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Path b = Path.of(&#8220;root\/a\/b&#8221;);<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Path c = Path.of(&#8220;root\/c&#8221;);<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Files.createDirectories(b);<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Files.createDirectory(c);<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Files.walk(root).forEach(System.out::println);<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0}<\/strong><br \/>\n<strong>}<\/strong><br \/>\n<strong>Which of the following can be the given program&#8217;s output?<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>b c<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>a a\/b c<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>a c a\/b<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>root\/a root\/c root\/a\/b<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>root root\/a root\/a\/b root\/c<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>F. <\/strong>root root\/a root\/c root\/a\/b<\/span><\/p>\n<p><b>Correct Answer: E<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The Files class includes two methods for walking the directory tree using a depth-first search.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">public static Stream&lt;Path&gt; walk(Path start, FileVisitOption&#8230; options) throws IOException<\/span><\/p>\n<p><span style=\"font-weight: 400;\">public static Stream&lt;Path&gt; walk(Path start, int maxDepth, FileVisitOption&#8230; options) throws IOException<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The static method walk() uses lazy evaluation and evaluates a Path only as it gets to it.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Here&#8217;s a description of the walk method from the Java SE API Specification:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Return a Stream that is lazily populated with Path by walking the file tree rooted at a given starting file. The file tree is traversed depth-first, the elements in the stream are Path objects that are obtained as if by resolving the relative path against start.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The stream walks the file tree as elements are consumed. The Stream returned is guaranteed to have at least one element, the starting file itself.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In the given program, the <\/span><i><span style=\"font-weight: 400;\">root<\/span><\/i><span style=\"font-weight: 400;\"> directory must be present in the output. Hence, <\/span><b>option E is correct.<\/b><br \/>\n<span style=\"font-weight: 400;\">As the root directory is not present, <\/span><b>options A, B, C and D are incorrect.<\/b><br \/>\n<b>Option F is also incorrect <\/b><span style=\"font-weight: 400;\">as the path <\/span><i><span style=\"font-weight: 400;\">root\/a\/b<\/span><\/i><span style=\"font-weight: 400;\"> must be right behind the path <\/span><i><span style=\"font-weight: 400;\">root\/a<\/span><\/i><span style=\"font-weight: 400;\"> due to depth-first traversal.<\/span><\/p>\n<p><b>Reference: <\/b><a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/nio\/file\/Files.html#walk(java.nio.file.Path,java.nio.file.FileVisitOption...)\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/nio\/file\/Files.html#walk(java.nio.file.Path,java.nio.file.FileVisitOption&#8230;)<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_S2-_Controlling_Program_Flow-2\"><\/span><span style=\"font-weight: 400;\">Domain : S2- Controlling Program Flow<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q15 : Given:<\/strong><br \/>\n<strong>int i, j;<\/strong><br \/>\n<strong>for (i = j = 0; ; ++i, j&#8211;) {<\/strong><br \/>\n<strong>\u00a0 \u00a0if (i &#8211; j &gt; 10) {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0}<\/strong><br \/>\n<strong>}<\/strong><br \/>\n<strong>System.out.println(i + &#8221; &#8221; + j);<\/strong><br \/>\n<strong>What is the output of the given code?<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>6 -6<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>5 -5<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>4 -4<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>It runs into an infinite loop<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>Compilation fails<\/span><\/p>\n<p><b>Correct Answer: A<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The for statement is used to iterate over a range of values. It repeatedly loops until a particular condition is satisfied. The general form of the for statement can be expressed as follows:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">for (initialization; termination;<\/span><br \/>\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0increment) {<\/span><br \/>\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0statement(s)<\/span><br \/>\n<span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">There is nothing wrong with the given code, hence it compiles without any issues. The variables i and j are initialized to 0. The body of the for construct keeps running until i &#8211; j &gt; 10. This happens when variables i and j reach 6 and -6, respectively. At this point, the break statement is executed and the for construct exits. Hence, <\/span><b>option A is correct<\/b><span style=\"font-weight: 400;\"> and the others are incorrect.<\/span><\/p>\n<p><b>Reference: <\/b><a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/java\/nutsandbolts\/for.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/javase\/tutorial\/java\/nutsandbolts\/for.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Working_with_Streams_and_Lambda_expressions-2\"><\/span><span style=\"font-weight: 400;\">Domain : Working with Streams and Lambda expressions<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q16 : Which of the following descriptions about streams is false?<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>A stream is not a data structure that stores elements<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>An operation on a stream produces a result, but does not modify its source<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Many stream operations can be implemented lazily<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>While collections have a finite size, streams need not<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>An element in a stream can be visited more than once to optimize operations<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>F. <\/strong>None of the above<\/span><\/p>\n<p><b>Correct Answer: E<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Here&#8217;s an excerpt from the Java 11 API Specification:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Streams differ from collections in several ways:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">No storage. A stream is not a data structure that stores elements; instead, it conveys elements from a source such as a data structure, an array, a generator function, or an I\/O channel, through a pipeline of computational operations. Hence, the description in option A is true, which makes <\/span><b>option A incorrect.<\/b><br \/>\n<span style=\"font-weight: 400;\">Functional in nature. An operation on a stream produces a result, but does not modify its source. For example, filtering a Stream obtained from a collection produces a new Stream without the filtered elements, rather than removing elements from the source collection.\u00a0 Hence, the description in option B is true, which makes <\/span><b>option B incorrect.<\/b><br \/>\n<span style=\"font-weight: 400;\">Laziness-seeking. Many stream operations, such as filtering, mapping, or duplicate removal, can be implemented lazily, exposing opportunities for optimization. For example, &#8220;find the first String with three consecutive vowels&#8221; need not examine all the input strings. Stream operations are divided into intermediate (Stream-producing) operations and terminal (value- or side-effect-producing) operations. Intermediate operations are always lazy.\u00a0 Hence, the description in option C is true, which makes <\/span><b>option C incorrect.<\/b><br \/>\n<span style=\"font-weight: 400;\">Possibly unbounded. While collections have a finite size, streams need not. Short-circuiting operations such as limit(n) or findFirst() can allow computations on infinite streams to complete in finite time.\u00a0 Hence, the description in option D is true, which makes <\/span><b>option D incorrect.<\/b><br \/>\n<span style=\"font-weight: 400;\">Consumable. The elements of a stream are only visited once during the life of a stream. Like an Iterator, a new stream must be generated to revisit the same elements of the source.\u00a0 Hence, the description in option E is false, which makes option <\/span><b>E the correct option.<\/b><\/p>\n<p><b>Reference: <\/b><a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/stream\/package-summary.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/stream\/package-summary.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_Object-Oriented_Approach\"><\/span><span style=\"font-weight: 400;\">Domain : Java Object-Oriented Approach<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q17 : Given:<\/strong><br \/>\n<strong>class SuperTest {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0public Object myMethod(Object&#8230; args) {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ A valid body<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0}<\/strong><br \/>\n<strong>}<\/strong><br \/>\n<strong>class Test extends SuperTest {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\/\/ Method 1<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0public Object myMethod(String&#8230; args) {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ A valid body<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0}<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\/\/ Method 2<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0public Object myMethod(Integer[] args) {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ A valid body<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0}<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\/\/ Method 3<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0public Object myMethod(Object arg) {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ A valid body<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0}<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\/\/ Method 4<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0public String myMethod(Object[] args) {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ A valid body<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0}<\/strong><br \/>\n<strong>}<\/strong><br \/>\n<strong>Which method in the Test class doesn&#8217;t overload the only method in the SuperTest class?<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Method 1<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Method 2<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Method 3<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>Method 4<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>None of the above<\/span><\/p>\n<p><b>Correct Answer: D<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">As per the Oracle Java Specification, an instance method in a subclass with the same signature (name, plus the number and the type of its parameters) and return type as an instance method in the superclass overrides the superclass&#8217;s method.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Only the method in option D has the same name, number and type of parameters, and return type as the superclass method, hence this is correct.\u00a0 It is important to note that varargs is just syntactic sugar for arrays, hence method 4 overrides the super-class&#8217;s method.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The first three methods of the Test class don&#8217;t have the same parameters as the method in the SuperTest class, hence they don&#8217;t override. Hence, the other options are incorrect.<\/span><\/p>\n<p><b>Reference: <\/b><a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/java\/IandI\/override.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/javase\/tutorial\/java\/IandI\/override.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Concurrency-2\"><\/span><span style=\"font-weight: 400;\">Domain : Concurrency<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q18 : Which of the following is NOT true about Runnable and Callable?<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Both Runnable and Callable can be used to construct a Thread object<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>A Callable task can throw a checked exception, while a Runnable task cannot<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>An ExecutorService can execute a collection of Callable tasks at once<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>When submitting a Runnable, an ExecutorService returns a Future instance<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>None of the above<\/span><\/p>\n<p><b>Correct Answer: A<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The Thread class doesn&#8217;t have a constructor that accepts a Callable argument; hence, option A is false and hence the correct answer.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The Callable.call method specifies the Exception class in its declaration; thus, it can throw any checked exception. In contrast, the Runnable.run method doesn&#8217;t specify any exception class and cannot throw a checked exception. Therefore, option B is true and hence incorrect.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The invokeAll() method of ExecutorService executes the given Callable tasks, returning the result of one that has completed successfully. The\u00a0 submit() method of ExecutorService Submits a Runnable task for execution and returns a Future representing that task. Thus, we can see that Options C and D are true and hence incorrect as per the invokeAll and submit() methods defined in the ExecutorService interface.<\/span><\/p>\n<p><b>References: <\/b><a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/lang\/Thread.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/lang\/Thread.html<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/lang\/Runnable.html#run()\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/lang\/Runnable.html#run()<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/concurrent\/Callable.html#call()\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/concurrent\/Callable.html#call()<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/concurrent\/ExecutorService.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/concurrent\/ExecutorService.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_IO_API-3\"><\/span><span style=\"font-weight: 400;\">Domain : Java I\/O API<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q19 : Given:<\/strong><br \/>\n<strong>Path p = Path.of(&#8220;test.txt&#8221;);<\/strong><br \/>\n<strong>Files.writeString(p, &#8220;Hello&#8221;); \/\/ Line 1<\/strong><br \/>\n<strong>Files.writeString(p, &#8220;Goodbye&#8221;); \/\/ Line 2<\/strong><br \/>\n<strong>System.out.println(Files.readString(p));<\/strong><br \/>\n<strong>Suppose the file &#8220;test.txt&#8221; didn&#8217;t exist. What is the given code fragment&#8217;s output?<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Hello<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Goodbye<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Hello Goodbye<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>An exception is thrown on line 1<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>An exception is thrown on line 2<\/span><\/p>\n<p><b>Correct Answer: B<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The writeString(Path, String) is used to write to a file. It takes the Path of the file and a String which is to be written into the file. It has optional parameters such as charset and open option.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">When the Files.writeString method is called the first time, a file with the specified name is created and contains the string &#8220;Hello&#8221;. Subsequently, the second invocation of that method<\/span><\/p>\n<p><span style=\"font-weight: 400;\">replaces the existing content with the new string. Therefore, there&#8217;s no exception, the final string inside the given file is &#8220;Goodbye&#8221;. Thus <\/span><b>option B is correct<\/b><span style=\"font-weight: 400;\"> and the others are incorrect.<\/span><\/p>\n<p><b>Reference:<\/b><a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/nio\/file\/Files.html#writeString(java.nio.file.Path,java.lang.CharSequence,java.nio.file.OpenOption...)\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\"> https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/nio\/file\/Files.html#writeString(java.nio.file.Path,java.lang.CharSequence,java.nio.file.OpenOption&#8230;)<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_Platform_Module_System\"><\/span><span style=\"font-weight: 400;\">Domain : Java Platform Module System<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q20 : Which of the following isn&#8217;t a valid option of the jdeps command?<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>&#8211;generate-module-info<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>&#8211;generate-open-module<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>&#8211;check-deps<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>&#8211;list-deps<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>&#8211;list-reduced-deps<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>F. <\/strong>&#8211;print-module-deps<\/span><\/p>\n<p><b>Correct Answer: C<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The jdeps command is used to launch the Java class dependency analyzer.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This is how he command is used.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">jdeps [options] path &#8230;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Here are descriptions of some options of the jdeps command:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211;generate-module-info dir<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Generates module-info.java under the specified directory. The specified JAR files will be analyzed. This option cannot be used with &#8211;dot-output or &#8211;class-path options. Use the &#8211;generate-open-module option for open modules.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211;generate-open-module dir<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Generates module-info.java for the specified JAR files under the specified directory as open modules. This option cannot be used with the &#8211;dot-output or &#8211;class-path options.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211;check module-name [, module-name&#8230;]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Analyzes the dependencies of the specified modules. It prints the module descriptor, the resulting module dependencies after analysis, and the graph after transition reduction. It also identifies any unused qualified exports.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211;list-deps<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Lists the module dependencies and also the package names of JDK internal APIs (if referenced).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211;list\u2014reduced-deps<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Same as &#8211;list-deps without listing the implied reads edges from the module graph. If module M1 reads M2, and M2 requires transitive on M3, then M1 reading M3 is implied and is not shown in the graph.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8211;print-module-deps<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Same as &#8211;list-reduced-deps with printing a comma-separated list of module dependencies. The output can be used by jlink &#8211;add-modules to create a custom image that contains those modules and their transitive dependencies.<\/span><\/p>\n<p><b>Reference: <\/b><a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/tools\/jdeps.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/en\/java\/javase\/11\/tools\/jdeps.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Localization-2\"><\/span><span style=\"font-weight: 400;\">Domain : Localization<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q21 : Given<\/strong><br \/>\n<strong>DateFormat formatter = new SimpleDateFormat(&#8220;Timezone zz&#8221;);<\/strong><br \/>\n<strong>formatter.setTimeZone(TimeZone.getTimeZone(&#8220;PST&#8221;));<\/strong><br \/>\n<strong>Date date = new Date();<\/strong><br \/>\n<strong>String output = formatter.format(date);<\/strong><br \/>\n<strong>System.out.println(output);<\/strong><br \/>\n<strong>What is the output of the given code?<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Timezone -0700<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Timezone -07:00<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Timezone PDT<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>Timezone Pacific Daylight Time<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>An IllegalArgumentException is thrown<\/span><\/p>\n<p><b>Correct Answer: E<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date \u2192 text), parsing (text \u2192 date), and normalization.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">When you create a SimpleDateFormat object, a pattern String is specified, whose contents determine the format of the date and time. In a date-time format pattern, all letters (from &#8220;A&#8221; to &#8220;Z&#8221; and from &#8220;a&#8221; to &#8220;z&#8221;) are reserved. If we want to include letters in a formatted string, we must put them in single quotes, such as &#8216;Timezone&#8217;.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In the given code, the word Timezone isn&#8217;t escaped, hence the program attempts to parse its letters. Since &#8220;T&#8221;, the first letter in the word, isn&#8217;t a predefined pattern letter, the program fails with an IllegalArgumentException.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If the pattern string had been escaped correctly, option C would have been the correct answer.<\/span><\/p>\n<p><b>Reference: <\/b><a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/i18n\/format\/simpleDateFormat.html#datepattern\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/javase\/tutorial\/i18n\/format\/simpleDateFormat.html#datepattern<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_Platform_Module_System-2\"><\/span><span style=\"font-weight: 400;\">Domain : Java Platform Module System<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q22 : Given a module named service, which contains a service interface called com.acme.spi.MyService. Its service provider, com.acme.MyServiceImpl, is enclosed in another module called impl.<\/strong><br \/>\n<strong>Which of the following is a correct declaration of the service module?<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>module service { exports com.acme.spi; }<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>module service { requires impl; }<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>module service { exports com.acme.spi; requires impl; }<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>module service { exports com.acme.spi; uses com.acme.MyServiceImpl; }<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>module service { exports com.acme.spi.MyService; provides com.acme.MyServiceImpl; }<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>F. <\/strong>module service { exports com.acme.spi.MyService; requires impl; uses com.acme.MyServiceImpl; }<\/span><\/p>\n<p><b>Correct Answer: A<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">A service is composed of an interface, the classes the interface references, and a way of looking up implementations of the interface. The service provider interface specifies what behavior the service will have. A service locator is able to find the classes that implement a service provider interface.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">When using a service loader, the service interface and its clients know nothing about service providers. Therefore, the service module shouldn&#8217;t have any information about the impl module as well as the enclosed service provider. Option A is correct as it does not require any module.<\/span><\/p>\n<p><b>Options B and C are incorrect <\/b><span style=\"font-weight: 400;\">as they require the impl module. In addition, the declaration in option B doesn&#8217;t even export the service interface for public use.<\/span><br \/>\n<b>Options D, E and F are incorrect <\/b><span style=\"font-weight: 400;\">since the directives are incorrectly used.<\/span><\/p>\n<p><b>Reference: <\/b><a href=\"about:blank\"><span style=\"font-weight: 400;\">http:\/\/http:\/\/openjdk.java.net\/projects\/jigsaw\/spec\/sotms\/#services<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Exception_Handling-3\"><\/span><span style=\"font-weight: 400;\">Domain : Exception Handling<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q23 : Given:<\/strong><br \/>\n<strong>public class MyResource implements AutoCloseable {<\/strong><br \/>\n<strong>\u00a0 \u00a0public void open() throws IOException {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0throw new IOException(&#8220;open&#8221;);<\/strong><br \/>\n<strong>}<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0public void close() {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0throw new ArithmeticException(&#8220;close&#8221;);<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0}<\/strong><br \/>\n<strong>}<\/strong><br \/>\n<strong>And:<\/strong><br \/>\n<strong>public class Test {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0public static void main(String[] args) throws IOException {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0try (MyResource myResource = new MyResource()) {<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0myResource.open();<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0throw new NullPointerException(&#8220;try&#8221;);<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/strong><br \/>\n<strong>\u00a0\u00a0\u00a0\u00a0}<\/strong><br \/>\n<strong>}<\/strong><br \/>\n<strong>Which exceptions are suppressed when the given program runs and throws an exception<\/strong><em><span style=\"font-weight: 400;\">?<\/span><\/em><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>IOException only<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>ArithmeticException only<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>NullPointerException only<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>IOException and ArithmeticException<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>IOException and NullPointerException<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>F. <\/strong>ArithmeticException and NullPointerException<\/span><\/p>\n<p><b>Correct Answer: B<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The try-with-resources statement is a try statement that declares one or more resources and ensures that each resource is closed at the end of the statement, whether an exception occurs or not.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">According to the Oracle&#8217;s Java Tutorials, if an exception is thrown from the try block and one or more exceptions are thrown from the try-with-resources statement, then those exceptions thrown from the try-with-resources statement are suppressed.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In the given code, the close() method is called when the resource is closed. Therefore, the exception thrown by this method is suppressed. In this case, this exception is ArithmeticException and hence <\/span><b>option B is correct.<\/b><br \/>\n<span style=\"font-weight: 400;\">The exception propagating up the call stack is the one that is thrown from the try block, which is an IOException in this case. Hence, <\/span><b>D and E are incorrect.<\/b><br \/>\n<span style=\"font-weight: 400;\">The NullPointerException is not thrown within the close() method and hence, it is also not suppressed. Hence, <\/span><b>option C is also incorrect.<\/b><\/p>\n<p><b>Reference: <\/b><a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/essential\/exceptions\/tryResourceClose.html#suppressed-exceptions\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/javase\/tutorial\/essential\/exceptions\/tryResourceClose.html#suppressed-exceptions<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Working_with_Streams_and_Lambda_expressions-3\"><\/span><span style=\"font-weight: 400;\">Domain : Working with Streams and Lambda expressions<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q24 : Given:<\/strong><br \/>\n<strong>Stream.of(Optional.ofNullable(null)).findFirst().ifPresent(System.out::println);<\/strong><br \/>\n<strong>What is the output of the given code fragment?<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Null<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Optional.empty<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Nothing<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>A NoSuchElementException is thrown<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>A NullPointerException is thrown<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>F. <\/strong>Compilation fails<\/span><\/p>\n<p><b>Correct Answer: B<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The ifPresent method enables us to run a lambda expression on the wrapped value if it&#8217;s found to be non-null. This method takes a Consumer as the argument and returns void. The ofNullable() method returns an Optional describing the given value, if non-null, otherwise returns an empty Optional.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The Optional.ofNullable method produces an empty Optional object since the argument is null. This is the only element in the stream, hence the Stream.findFirst operation returns an Optional object wrapping that empty Optional. The empty Optional is then printed out by the consumer passed to the Optional.ifPresent method. Hence, <\/span><b>option B is correct.<\/b><br \/>\n<span style=\"font-weight: 400;\">As the empty Optional is not null or empty, <\/span><b>options A and C are incorrect.<\/b><br \/>\n<span style=\"font-weight: 400;\">As there are no exceptions or compiler errors, the <\/span><b>options D, E and F are incorrect.<\/b><\/p>\n<p><b>Reference: <\/b><a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/Optional.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/Optional.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_Platform_Module_System-3\"><\/span><span style=\"font-weight: 400;\">Domain : Java Platform Module System<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q25 : Given service interface MyService and service implementation class MyServiceImpl. Suppose all the module declarations are valid. Which two of the following are correct ways to get an instance of the service in the client module?<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>MyService service = new MyServiceImpl();<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>MyService service = ServiceLoader.load(MyService.class);<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>MyService service = new ServiceLoader().load(MyService.class);<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>MyService service = ServiceLoader.load(MyServiceImpl.class);<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>MyService service = ServiceLoader.load(MyService.class).findFirst().get();<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>F. <\/strong>MyService service = ServiceLoader.load(MyService.class).iterator().next();<\/span><\/p>\n<p><b>Correct Answers: E and F<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">A ServiceLoader is an object that locates and loads service providers deployed in the run time environment. Invoking the load() method on the Service Loader creates a new service loader for the given service. The findFirst() method is invoked to load the first available service provider of this loader&#8217;s service. Hence, <\/span><b>options E and F are correct.<\/b><br \/>\n<span style=\"font-weight: 400;\">When using a service loader, the implementation class isn&#8217;t involved in the client code. Instead, it&#8217;s loaded dynamically at runtime. This means <\/span><b>options A and D are incorrect.<\/b><br \/>\n<b>Option C is incorrect <\/b><span style=\"font-weight: 400;\">because the ServiceLoader class doesn&#8217;t have a public constructor.<\/span><br \/>\n<b>Option B is incorrect <\/b><span style=\"font-weight: 400;\">as the load method returns a ServiceLoader instance rather than an instance of the implementation class.<\/span><\/p>\n<p><b>Reference: <\/b><a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/ServiceLoader.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/ServiceLoader.html<\/span><\/a><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Annotations-3\"><\/span>Domain: Annotations<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q26. Given:<\/strong><\/p>\n<p><strong>@SuppressWarnings(&#8220;deprecation&#8221;)<\/strong><\/p>\n<p><strong>class Foo {<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0@SuppressWarnings(&#8220;removal&#8221;)<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0void m() {<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0@SuppressWarnings(&#8220;unchecked&#8221;)<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0List list = new ArrayList();<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ do something<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0}<\/strong><\/p>\n<p><strong>}<\/strong><\/p>\n<p><strong>Which kinds of warnings are suppressed in statements indicated by the comment \/\/ do something?<\/strong><\/p>\n<p><b>Options<\/b><\/p>\n<p><span style=\"font-weight: 400;\">A. Deprecation only<\/span><\/p>\n<p><span style=\"font-weight: 400;\">B. Removal only<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C. Unchecked only<\/span><\/p>\n<p><span style=\"font-weight: 400;\">D. Deprecation and removal<\/span><\/p>\n<p><span style=\"font-weight: 400;\">E. Removal and unchecked<\/span><\/p>\n<p><span style=\"font-weight: 400;\">F. Deprecation, removal and unchecked<\/span><\/p>\n<p><b>Answer<\/b><span style=\"font-weight: 400;\">: D<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This annotation specifies which kinds of warnings can be ignored. Applying this annotation to a class, method, or type basically tells the compiler to suppress any kind of warnings.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Here&#8217;s an extract from the Java SE API Specification about the @SuppressWarnings annotation:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Indicates that the named compiler warnings should be suppressed in the annotated element (and in all program elements contained in the annotated element). Note that the set of warnings suppressed in a given element is a superset of the warnings suppressed in all containing elements. For example, if you annotate a class to suppress one warning and annotate a method to suppress another, both warnings will be suppressed in the method.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">As per the explanation above, the suppression of deprecation and removal warnings apply to the whole body of the m() method in the above code. The unchecked warning is suppressed for the list local variable only.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>Reference<\/strong>:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/lang\/SuppressWarnings.html<\/span><\/p>\n<p><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/javase\/specs\/jls\/se11\/html\/jls-9.html#jls-9.6.4.5<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_Platform_Module_System-4\"><\/span>Domain: Java Platform Module System<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>Q27. Given a module named service, which contains a service interface called com.acme.spi.MyService. Its service provider, com.acme.MyServiceImpl, is enclosed in another module called impl.<\/strong><\/p>\n<p><strong>Which of the following is a correct declaration of the service module?<\/strong><\/p>\n<p><b>Options<\/b><\/p>\n<p>A.<\/p>\n<p><span style=\"font-weight: 400;\">module service {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0exports com.acme.spi;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p>B.<\/p>\n<p><span style=\"font-weight: 400;\">module service {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0requires impl;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p>C.<\/p>\n<p><span style=\"font-weight: 400;\">module service {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0exports com.acme.spi;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0requires impl;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p>D.<\/p>\n<p><span style=\"font-weight: 400;\">module service {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0exports com.acme.spi;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0uses com.acme.MyServiceImpl;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p>E.<\/p>\n<p><span style=\"font-weight: 400;\">module service {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0exports com.acme.spi.MyService;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0provides com.acme.MyServiceImpl;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0F.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">module service {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0exports com.acme.spi.MyService;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0requires impl;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0uses com.acme.MyServiceImpl;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><b>Answer<\/b><span style=\"font-weight: 400;\">: A<\/span><\/p>\n<p><span style=\"font-weight: 400;\">A service is composed of an interface, the classes the interface references, and a way of looking up implementations of the interface. The service provider interface specifies what behavior the service will have. A service locator is able to find the classes that implement a service provider interface.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">When using a service loader, the service interface and its clients know nothing about service providers. Therefore, the service module shouldn&#8217;t have any information about the impl module as well as the enclosed service provider. Option A is correct as it does not require any module.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Options B and C are incorrect as they require the impl module. In addition, the declaration in option B doesn&#8217;t even export the service interface for public use.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Options D, E and F are incorrect since the directives are incorrectly used.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Reference:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">http:\/\/openjdk.java.net\/projects\/jigsaw\/spec\/sotms\/#services<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">We are hopeful that these free questions and answers on Java SE 11 Developer certification, must have helped you take one step ahead in your overall preparation for the Java 1Z0-819 exam. Learn and prepare, and pass the exam in the first attempt. Follow through for more such <\/span>Practice Tests <span style=\"font-weight: 400;\">for the<\/span> Oracle Certified Professional, Java SE 11 Developer (1Z0-819) exam in our official website. Keep Learning !<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Are you looking for Oracle Certified Java SE 11 developer questions ? Then this article has sample questions on Java SE 11 Developer certification exam and it is free. The Oracle Certified Professional, Java SE 11 Developer (1Z0-819) certification exam requires a thorough knowledge of Java Programming and coding practices. If you are thinking about how to pass 1Z0-819 exam, then these Java SE 11 developer exam questions give you a clear picture of what the actual exam is going to be like.\u00a0 Let&#8217;s start Learning ! Domain : Secure Coding in Java SE Application Q1 : To which of [&hellip;]<\/p>\n","protected":false},"author":356,"featured_media":82086,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"default","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[13],"tags":[4858],"class_list":["post-81866","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-java-se-11-developer-exam-questions"],"uagb_featured_image_src":{"full":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/04\/Free-Questions-on-Oracle-Certified-Professional_-Java-SE-11-Developer-1Z0-819-Certification-Exam.webp",600,315,false],"thumbnail":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/04\/Free-Questions-on-Oracle-Certified-Professional_-Java-SE-11-Developer-1Z0-819-Certification-Exam-150x150.webp",150,150,true],"medium":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/04\/Free-Questions-on-Oracle-Certified-Professional_-Java-SE-11-Developer-1Z0-819-Certification-Exam-300x158.webp",300,158,true],"medium_large":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/04\/Free-Questions-on-Oracle-Certified-Professional_-Java-SE-11-Developer-1Z0-819-Certification-Exam.webp",600,315,false],"large":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/04\/Free-Questions-on-Oracle-Certified-Professional_-Java-SE-11-Developer-1Z0-819-Certification-Exam.webp",600,315,false],"1536x1536":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/04\/Free-Questions-on-Oracle-Certified-Professional_-Java-SE-11-Developer-1Z0-819-Certification-Exam.webp",600,315,false],"2048x2048":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/04\/Free-Questions-on-Oracle-Certified-Professional_-Java-SE-11-Developer-1Z0-819-Certification-Exam.webp",600,315,false],"profile_24":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/04\/Free-Questions-on-Oracle-Certified-Professional_-Java-SE-11-Developer-1Z0-819-Certification-Exam.webp",24,13,false],"profile_48":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/04\/Free-Questions-on-Oracle-Certified-Professional_-Java-SE-11-Developer-1Z0-819-Certification-Exam.webp",48,25,false],"profile_96":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/04\/Free-Questions-on-Oracle-Certified-Professional_-Java-SE-11-Developer-1Z0-819-Certification-Exam.webp",96,50,false],"profile_150":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/04\/Free-Questions-on-Oracle-Certified-Professional_-Java-SE-11-Developer-1Z0-819-Certification-Exam.webp",150,79,false],"profile_300":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/04\/Free-Questions-on-Oracle-Certified-Professional_-Java-SE-11-Developer-1Z0-819-Certification-Exam.webp",300,158,false],"tptn_thumbnail":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/04\/Free-Questions-on-Oracle-Certified-Professional_-Java-SE-11-Developer-1Z0-819-Certification-Exam-250x250.webp",250,250,true],"web-stories-poster-portrait":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/04\/Free-Questions-on-Oracle-Certified-Professional_-Java-SE-11-Developer-1Z0-819-Certification-Exam.webp",600,315,false],"web-stories-publisher-logo":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/04\/Free-Questions-on-Oracle-Certified-Professional_-Java-SE-11-Developer-1Z0-819-Certification-Exam.webp",96,50,false],"web-stories-thumbnail":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/04\/Free-Questions-on-Oracle-Certified-Professional_-Java-SE-11-Developer-1Z0-819-Certification-Exam.webp",150,79,false]},"uagb_author_info":{"display_name":"Vasanth Rajan","author_link":"https:\/\/www.whizlabs.com\/blog\/author\/vasanth\/"},"uagb_comment_info":468,"uagb_excerpt":"Are you looking for Oracle Certified Java SE 11 developer questions ? Then this article has sample questions on Java SE 11 Developer certification exam and it is free. The Oracle Certified Professional, Java SE 11 Developer (1Z0-819) certification exam requires a thorough knowledge of Java Programming and coding practices. If you are thinking about&hellip;","_links":{"self":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/81866","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/users\/356"}],"replies":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/comments?post=81866"}],"version-history":[{"count":14,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/81866\/revisions"}],"predecessor-version":[{"id":88074,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/81866\/revisions\/88074"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/media\/82086"}],"wp:attachment":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/media?parent=81866"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/categories?post=81866"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/tags?post=81866"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}