{"id":81859,"date":"2022-04-11T00:50:44","date_gmt":"2022-04-11T06:20:44","guid":{"rendered":"https:\/\/www.whizlabs.com\/blog\/?p=81859"},"modified":"2022-09-07T22:18:31","modified_gmt":"2022-09-08T03:48:31","slug":"java-se-8-programmer-certification","status":"publish","type":"post","link":"https:\/\/www.whizlabs.com\/blog\/java-se-8-programmer-certification\/","title":{"rendered":"Free Questions on Oracle Certified Professional, Java SE 8 Programmer (OCPJP 8) (1Z0 809)"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">The Oracle Certified Professional, Java SE 8 Programmer Certification exam (1Z0-809) requires you to have a practical understanding and Hands-on experience with Java SE8 version. <\/span><span style=\"font-weight: 400;\">The prerequisite for this certification is the completion of the Oracle Certified Associate(OCA) certification.<\/span><\/p>\n<p>In this article, we provide <a href=\"https:\/\/www.whizlabs.com\/ocpjp-scjp\/\">Java SE 8 Programmer certification<\/a><span style=\"font-weight: 400;\"> 1Z0-809 free test questions. These 1Z0-809 exam questions are for your easy assessment of the certification exam, and to give you an idea on the pattern of the questions that could be asked in the actual exam.<\/span><\/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-8-programmer-certification\/#Domain_Java_Class_Design\" >Domain : Java Class Design<\/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-8-programmer-certification\/#Domain_Building_Database_Applications_with_JDBC\" >Domain : Building Database Applications with JDBC<\/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-8-programmer-certification\/#Domain_Exceptions_and_Assertions\" >Domain : Exceptions and Assertions<\/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-8-programmer-certification\/#Domain_Generics_and_Collections\" >Domain : Generics and Collections<\/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-8-programmer-certification\/#Domain_Java_Class_Design-2\" >Domain : Java Class Design<\/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-8-programmer-certification\/#Domain_Java_Concurrency\" >Domain : Java Concurrency<\/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-8-programmer-certification\/#Domain_Java_Class_Design-3\" >Domain : Java Class Design<\/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-8-programmer-certification\/#Domain_Building_Database_Applications_with_JDBC-2\" >Domain : Building Database Applications with JDBC<\/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-8-programmer-certification\/#Domain_Exceptions_and_Assertions-2\" >Domain : Exceptions and Assertions<\/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-8-programmer-certification\/#Domain_Generics_and_Collections-2\" >Domain : Generics and Collections<\/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-8-programmer-certification\/#Domain_Java_Class_Design-4\" >Domain : Java Class Design<\/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-8-programmer-certification\/#Domain_Java_Concurrency-2\" >Domain : Java 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-8-programmer-certification\/#Domain_Java_File_IO_NIO2\" >Domain : Java File I\/O (NIO.2)<\/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-8-programmer-certification\/#Domain_Building_Database_Applications_with_JDBC-3\" >Domain : Building Database Applications with JDBC<\/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-8-programmer-certification\/#Domain_Exceptions_and_Assertions-3\" >Domain : Exceptions and Assertions<\/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-8-programmer-certification\/#Domain_Generics_and_Collections-3\" >Domain : Generics and Collections<\/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-8-programmer-certification\/#Domain_Java_Concurrency-3\" >Domain : Java Concurrency<\/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-8-programmer-certification\/#Domain_Java_File_IO_NIO2-2\" >Domain : Java File I\/O (NIO.2)<\/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-8-programmer-certification\/#Domain_Java_Stream_API\" >Domain : Java Stream 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-8-programmer-certification\/#Domain_Generics_and_Collections-4\" >Domain : Generics and Collections<\/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-8-programmer-certification\/#Domain_Java_Concurrency-4\" >Domain : Java Concurrency<\/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-8-programmer-certification\/#Domain_Generics_and_Collections-5\" >Domain : Generics and Collections<\/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-8-programmer-certification\/#Domain_Generics_and_Collections-6\" >Domain : Generics and Collections<\/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-8-programmer-certification\/#Domain_Java_File_IO_NIO2-3\" >Domain : Java File I\/O (NIO.2)<\/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-8-programmer-certification\/#Domain_Java_Stream_API-2\" >Domain : Java Stream API<\/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-8-programmer-certification\/#Summary\" >Summary<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_Class_Design\"><\/span><span style=\"font-weight: 400;\">Domain : Java Class Design<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q1 : Given<\/span><\/em><\/h4>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0interface Switchable{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">void sw(int i);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0abstract class Switch{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">abstract void sw(int i);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0class It _ _ _ _ _ _ _ _ _ _ _ _ _{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public void sw(int i){}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public static void main(String []arg){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">System.out.print(&#8220;A&#8221;);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<\/ol>\n<h4><em><span style=\"font-weight: 400;\">\u00a0Which is true?\u00a0<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>At line 7 extending the abstract class \u201cSwitch\u201d is more\u00a0 appropriate than implementing the interface \u201cSwitchable\u201d<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>At line 7 implementing the interface \u201cSwitchable\u201d is more\u00a0 appropriate than extending the abstract class\u00a0 \u201cSwitch\u201d\u00a0<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>At line 7 implementing the interface or extending the interface won\u2019t give us any advantage over another<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>Since the both the interface and the abstract class are abstract, both of them will provide same flexibility<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>Implementing or extending will fail this code from compiling<\/span><\/p>\n<p><b>Correct Answer: B<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><b>B is correct<\/b><span style=\"font-weight: 400;\"> as in this code both the interface and the abstract class provide same functionality\u00a0 to class \u201cIt\u201d but implementing the interface is preferable as it allows \u201cIt\u201d class to extend another class when needed.<\/span><br \/>\n<b>A is incorrect<\/b><span style=\"font-weight: 400;\"> as if we extends the abstract class then we can\u2019t extend another class if needed.<\/span><br \/>\n<b>C and D are incorrect<\/b><span style=\"font-weight: 400;\"> as in this case, interface clearly provides us more flexibility over abstract class.<\/span><br \/>\n<b>E is incorrect<\/b><span style=\"font-weight: 400;\"> as we have correctly overload the \u201csw()\u201d method at line 9.<\/span><\/p>\n<p><b>Reference:<\/b> <a href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/java\/IandI\/usinginterface.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/tutorial\/java\/IandI\/usinginterface.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Building_Database_Applications_with_JDBC\"><\/span><span style=\"font-weight: 400;\">Domain : Building Database Applications with JDBC<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q2 : Which of the following isolation level will block all kind of reads on a row until the transaction is committed?<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>TRANSACTION_READ_COMMITTED<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>TRANSACTION_READ_UNCOMMITTED<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>TRANSACTION_ REPEATABLE_READ<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>TRANSACTION_SERIALIZABLE<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>TRANSACTION_READ<\/span><\/p>\n<p><b>Correct Answer: D<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Refer to the following table about the Isolation Level provided in the oracle reference site.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Isolation Level<\/b><\/td>\n<td><b>Transactions<\/b><\/td>\n<td><b>Dirty Reads<\/b><\/td>\n<td><b>Non-Repeatable Reads<\/b><\/td>\n<td><b>Phantom Reads<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">TRANSACTION_NONE<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Not supported<\/span><\/td>\n<td><i><span style=\"font-weight: 400;\">Not applicable<\/span><\/i><\/td>\n<td><i><span style=\"font-weight: 400;\">Not applicable<\/span><\/i><\/td>\n<td><i><span style=\"font-weight: 400;\">Not applicable<\/span><\/i><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">TRANSACTION_READ_COMMITTED<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Supported<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Prevented<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Allowed<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Allowed<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">TRANSACTION_READ_UNCOMMITTED<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Supported<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Allowed<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Allowed<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Allowed<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">TRANSACTION_REPEATABLE_READ<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Supported<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Prevented<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Prevented<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Allowed<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">TRANSACTION_SERIALIZABLE<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Supported<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Prevented<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Prevented<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Prevented<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">According to above table it is clear that the isolation level \u201cTRANSACTION_SERIALIZABLE\u201d will block all kind of reads on a row until the transaction is committed. So the <\/span><b>correct option is D.<\/b><\/p>\n<p><b>Reference:<\/b><a href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/jdbc\/basics\/transactions.html\" target=\"_blank\" rel=\"noopener\"> <span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/tutorial\/jdbc\/basics\/transactions.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Exceptions_and_Assertions\"><\/span><span style=\"font-weight: 400;\">Domain : Exceptions and Assertions<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q3 : Consider following three statements (select true statements ) .<\/span><\/em><\/h4>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><span style=\"font-weight: 400;\">A try with resources statement without a catch block requires a finally block.<\/span><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><span style=\"font-weight: 400;\">A try with resources statement without a finally block requires a catch block.<\/span><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><span style=\"font-weight: 400;\">A try with resources statement with only one statement can omit the {}<\/span><\/h4>\n<\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Only I<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Only III<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Only I and II<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>Only II and III<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>None of above<\/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;\"> since the all given three statements are false. A try-with-resources statement does not require a catch or finally block where a traditional try statement requires at least one of the two. Even with one statement it is manadory to have {} with try with resources.<\/span><\/p>\n<p><b>Reference<\/b><span style=\"font-weight: 400;\">: <\/span><a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/essential\/exceptions\/tryResourceClose.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/javase\/tutorial\/essential\/exceptions\/tryResourceClose.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Generics_and_Collections\"><\/span><span style=\"font-weight: 400;\">Domain : Generics and Collections<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q4 : Given<\/span><\/em><\/h4>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0import java.util.*;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0import java.util.function.Predicate;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public class Whizlab{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public static void main(String[] args){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0List&lt;Integer&gt; numbers = new ArrayList&lt;&gt;();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 numbers.add(10);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 numbers.add(11);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 numbers.add(13);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 numbers.add(19);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 numbers.add(5);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">Predicate&lt;Integer&gt; predit = p -&gt; p &gt; 10;\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">numbers.stream().filter(predit);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">System.out.println(numbers);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<\/ol>\n<h4><em><span style=\"font-weight: 400;\">What is the output?<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\">[10, 5]<\/span><br \/>\n<span style=\"font-weight: 400;\">[11,\u00a0 13, 19]<\/span><br \/>\n<span style=\"font-weight: 400;\">[10, 11, 13, 19, 5]<\/span><br \/>\n<span style=\"font-weight: 400;\">Compilation fails due to error at line 16<\/span><br \/>\n<span style=\"font-weight: 400;\">Compilation fails due to error at line 18<\/span><\/p>\n<p><b>Correct Answer: C<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">java.util.function.Predicate interface defines an abstract method named test(T t) that accepts an object of generic type T and returns a boolean primitive.\u00a0 At line 16, we have passed valid lambda expression which takes an Integer object in and return true if it is greater than 10.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">At line 18 ,\u00a0 we called stream method on numbers so it will become a stream, then we invoke filter method by passing the created predicate. But there is no any terminal operation after filter method. Streams are lazy because intermediate operations are not evaluated unless terminal operation is invoked.\u00a0 Streams never make changes to the source object. So output contains all values of the list, hence <strong>option C is correct.<\/strong><\/span><\/p>\n<p><b>Reference<\/b><span style=\"font-weight: 400;\">: <\/span><a href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/collections\/streams\/parallelism.html#laziness\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/tutorial\/collections\/streams\/parallelism.html#laziness<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_Class_Design-2\"><\/span><span style=\"font-weight: 400;\">Domain : Java Class Design<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q5 : Given<\/span><\/em><\/h4>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public class Whiz{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">static int x;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public static void main(String[] args){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">Whiz w1 = new Whiz ();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">Whiz w2 = new Whiz ();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">Whiz w3 = new Whiz ();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">w1.method();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">w2.method();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">w3.method();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public void method(){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">while(++x&lt;3){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">System.out.print(&#8220;A&#8221;);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0}\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span><\/em><\/h4>\n<\/li>\n<\/ol>\n<h4><em><span style=\"font-weight: 400;\">What is the output?<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>AAAAAA<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>AA<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>No output<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>Compilation fails due to error on line 15<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>Compilation fails due to multiple errors<\/span><\/p>\n<p><b>Correct Answer: B<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Static variable x\u201d at line 3 has default value \u201c0\u201d as we have not given any specific value. So when the \u201cmethod()\u201d invokes first time using \u201cw1\u201d object reference, while loop executes and will print \u201cA\u201d twice and final value of the variable \u201cx\u201d is 3. Since the variable \u201cx\u201d is static every other object share same value of the variable \u201cx\u201d. So when w1 and w2 objects try invoke method(), while loop wouldn\u2019t invoke because x is already reached to 3.<\/span><\/p>\n<p><b>Reference: <\/b><a href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/java\/javaOO\/classvars.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/tutorial\/java\/javaOO\/classvars.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_Concurrency\"><\/span><span style=\"font-weight: 400;\">Domain : Java Concurrency<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q6 : Which of the followings are true?\u00a0<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>There is no different between Callable\u2019s \u201ccall()\u201d method and Runnable\u2019s \u201crun()\u201dmethod<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Callable\u2019s \u201ccall()\u201d method allows to return some value while Runnable\u2019s \u201crun()\u201d doesn\u2019t<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Callable is a class while Runnable is an interface<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>Both the Callable and Runnable interfaces have only one method<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>Both Callable\u2019s \u201ccall()\u201d method and Runnable\u2019s \u201crun()\u201d methods can\u2019t be overridden to throw checked exception when necessary<\/span><\/p>\n<p><b>Correct Answers: B and D<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><b>Option B is correct<\/b><span style=\"font-weight: 400;\"> as the Callable\u2019s \u201ccall()\u201d method allows it to return some value.<\/span><br \/>\n<b>Option D is correct <\/b><span style=\"font-weight: 400;\">as both the Callable and Runnable interfaces have only one method. The Callable interface has only the \u201ccall()\u201d method and the Runnable interface only got the \u201crun()\u201d method.<\/span><br \/>\n<b>Option A is incorrect <\/b><span style=\"font-weight: 400;\">as there are different between Callable\u2019s \u201ccall()\u201d method and Runnable\u2019s \u201crun()\u201dmethod. Callable\u2019s \u201ccall()\u201d method can return a value and it also can throw exceptions while Runnable\u2019s \u201crun()\u201dmethod doesn\u2019t.<\/span><br \/>\n<b>Option C is incorrect <\/b><span style=\"font-weight: 400;\">as the Callable is an interface like the Runnable.<\/span><br \/>\n<b>Option E is incorrect <\/b><span style=\"font-weight: 400;\">as the Callable\u2019s \u201ccall()\u201d method can be overridden to throw checked exception when necessary.<\/span><\/p>\n<p><b>Reference: <\/b><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/concurrent\/Callable.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/concurrent\/Callable.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_Class_Design-3\"><\/span><span style=\"font-weight: 400;\">Domain : Java Class Design<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q7 : Given<\/span><\/em><\/h4>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public class Whiz{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public static void main(String[] args){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">I2.print();\u00a0 \u00a0 \u00a0 \u00a0 <\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">I1.print();\u00a0 \u00a0 \u00a0 \u00a0 <\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0interface I1{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public static void print(){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">System.out.print(&#8220;1&#8221;);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0interface I2 extends I1{ \u00a0 \u00a0 \u00a0 <\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public static void print(){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">System.out.print(&#8220;2&#8221;);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<\/ol>\n<h4><em><span style=\"font-weight: 400;\">What is the output?<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>11<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>22<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>12<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>21<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>Compilation fails<\/span><\/p>\n<p><b>Correct Answer: D<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Static methods in interfaces are not inherited so there is no problem in defining new static method with same name in I2. Hence output will be 2 and 1. So <strong>option D is correct.<\/strong><\/span><\/p>\n<p><b>Reference<\/b><span style=\"font-weight: 400;\">: <\/span><a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/java\/IandI\/defaultmethods.html\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.oracle.com\/javase\/tutorial\/java\/IandI\/defaultmethods.html<\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Building_Database_Applications_with_JDBC-2\"><\/span><span style=\"font-weight: 400;\">Domain : Building Database Applications with JDBC<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q8 : You are asked to establish a connection to a MySql database in the \u201clocalhost\u201d, called \u201cSchool\u201d. You are given the password as \u201cabcd\u201d and the user name as the \u201cadmin\u201d.<\/span><\/em><br \/>\n<em><span style=\"font-weight: 400;\">Which of the following connection URL \/ arguments can be passed to getConnection method of DriverManager ?<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>&#8220;jdbc:mysql:\/\/localhost:3306\/School?&#8221;+&#8221;user=admin&amp;password=abcd&#8221;\u00a0<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>&#8220;jdbc:mysql:\/\/School:3306?user=admin&amp;password=abcd&#8221;<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>&#8220;jdbc:mysql:\/\/localhost:3306\/School&#8221;,&#8221;abcd&#8221;,&#8221;admin&#8221;\u00a0\u00a0<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>&#8220;jdbc:mysql:\/\/School:3306\/localhost?user=admin&amp;password=abcd&#8221;<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>&#8220;jdbc:mysql:\/\/:3306\/School&#8221;,&#8221;admin&#8221;, &#8220;abcd&#8221;\u00a0\u00a0<\/span><\/p>\n<p><b>Correct Answers: A and E<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><b>getConnection method of DriverManager class is overloaded.\u00a0<\/b><\/p>\n<p><b>public static Connection getConnection(String url) throws SQLException<\/b><\/p>\n<p><b>public static Connection getConnection(String url, Properties info) throws SQLException<\/b><\/p>\n<p><b>public static Connection getConnection(String url,String user, String password) throws SQLException<\/b><\/p>\n<p><b>jdbc:mysql:\/\/[host][:port]\/[database][?property1][=value1]&#8230;<\/b><\/p>\n<p><b>Host<\/b><span style=\"font-weight: 400;\"> &#8211; The host name where MySQL server is running. Default is 127.0.0.1 &#8211; the IP address of localhost.<\/span><\/p>\n<p><b>Port<\/b><span style=\"font-weight: 400;\"> &#8211; The port number where MySQL is listening for connection. Default is 3306.<\/span><\/p>\n<p><b>Database<\/b><span style=\"font-weight: 400;\"> &#8211; The name of an existing database on MySQL server. If not specified, the connection starts no current database.<\/span><\/p>\n<p><b>Property<\/b><span style=\"font-weight: 400;\"> &#8211; The name of a supported connection properties. &#8220;user&#8221; and &#8220;password&#8221; are 2 most important properties.<\/span><\/p>\n<p><b>Value<\/b><span style=\"font-weight: 400;\"> &#8211; The value for the specified connection property.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">According to given scenario, host should be localhost, database should be school, user name should be \u201cadmin\u201d and the password should be \u201cabcd\u201d.<\/span><\/p>\n<p><b>Option A is correct <\/b><span style=\"font-weight: 400;\">as it follows correct format and pass the parameters in correct order.<\/span><br \/>\n<b>Option E is correct<\/b><span style=\"font-weight: 400;\"> as when we don\u2019t specify\u00a0 the host name default host will be 127.0.0.1 which is for localhost.<\/span><br \/>\n<b>Option B and D are incorrect<\/b><span style=\"font-weight: 400;\"> as we have passed the \u201cSchool\u201d as the host name.<\/span><br \/>\n<b>Option C is incorrect <\/b><span style=\"font-weight: 400;\">as password and user name are in incorrect order.<\/span><\/p>\n<p><b>References: <\/b><a href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/jdbc\/overview\/index.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/tutorial\/jdbc\/overview\/index.html<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"http:\/\/www.oracle.com\/technetwork\/java\/overview-141217.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/www.oracle.com\/technetwork\/java\/overview-141217.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Exceptions_and_Assertions-2\"><\/span><span style=\"font-weight: 400;\">Domain : Exceptions and Assertions<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q9 : Given ( assertions are enabled )<\/span><\/em><\/h4>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public class Whizlab{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public static void main(String[] args) {<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">int j = 9;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">assert(++j &gt; 7): &#8220;Error&#8221;;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">assert(j==12): j;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">assert(++j &gt; 8): System.out.println(j);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<\/ol>\n<h4><em><span style=\"font-weight: 400;\">What is the output?<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>8<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>9<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Compilation fails due to line 5<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>Compilation fails due to line 6<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>Compilation fails due to multiple errors<\/span><\/p>\n<p><b>Correct Answer: D<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><b>Option D Is correct <\/b><span style=\"font-weight: 400;\">as the code fails to compile only due to line 6. When an assert statement has two expressions, the second expression must return a value. The only two-expression assert statement that doesn\u2019t return a value is on line 6.<\/span><\/p>\n<p><b>Reference: <\/b><a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/technotes\/guides\/language\/assert.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/7\/docs\/technotes\/guides\/language\/assert.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Generics_and_Collections-2\"><\/span><span style=\"font-weight: 400;\">Domain : Generics and Collections<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q10 : Given<\/span><\/em><\/h4>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">import java.util.ArrayList;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">import java.util.List;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">public class Whiz{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public static void main(String[] args){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">List list = new ArrayList();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">list.add(\u201c1\u201d);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">list.add(\u201c2\u201d);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">list.add(\u201c3\u201d);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">list.add(\u201c4\u201d);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">System.out.println(list.set(3,\u201d3\u201d));<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">}\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<\/ol>\n<h4><em><span style=\"font-weight: 400;\">What is the output?<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>4<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>3<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>-1<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>An Exception is thrown<\/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;\">We have used ArrayList class set method at line 13,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">public E set(int index,<\/span> <span style=\"font-weight: 400;\">E element)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This method replaces the element at the specified position in this list with the specified element, and returns the element which is removed. So in this case 4 will be returned since 4 is located in the position we are going to remove. So <strong>option A is correct.<\/strong><\/span><\/p>\n<p><b>Reference: <\/b><a href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/collections\/interfaces\/List.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/tutorial\/collections\/interfaces\/List.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_Class_Design-4\"><\/span><span style=\"font-weight: 400;\">Domain : Java Class Design<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q11 : Given<\/span><\/em><\/h4>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public class Pro {<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">static int i;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public static void main(String[] args){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">Pro p1 = new Pro();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">Pro p2 = new Pro();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">Pro p3 = new Pro();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">p1.method();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">p2.method();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">p3.method();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public void method(){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">while(++i&lt;3){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">System.out.print(&#8220;A&#8221;);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0}\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/span><\/em><\/h4>\n<\/li>\n<\/ol>\n<h4><em><span style=\"font-weight: 400;\">What is the output?<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>AAAAAA<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>AA<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>No output<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>Compilation fails due to error on line 15<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>Compilation fails due to multiple errors<\/span><\/p>\n<p><b>Correct Answer: B<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Static variable \u201ci\u201d at line 3 has default value \u201c0\u201d as we have not given any specific value. So when the \u201cmethod()\u201d invokes first time using \u201cp1\u201d object reference, while loop executes and will print \u201cA\u201d twice. Since the variable \u201ci\u201d is static \u201cp2\u201d and \u201cp3\u201d objects sees variable \u201ci\u201d with value larger than 3, so when using \u201cp2\u201d and \u201cp3\u201d for invoking the \u201cmethod()\u201d, while loop will not execute.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The output only contains two \u201cA\u201ds as explained above, so <strong>option B is correct.<\/strong><\/span><br \/>\n<b>Option A is incorrect<\/b><span style=\"font-weight: 400;\">, it would be correct if the variable \u201ci\u201d was a instance variable.<\/span><br \/>\n<b>Options D and E are incorrect <\/b><span style=\"font-weight: 400;\">as the code compiles fine.\u00a0<\/span><\/p>\n<p><b>Reference: <\/b><a href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/java\/javaOO\/classvars.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/tutorial\/java\/javaOO\/classvars.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_Concurrency-2\"><\/span><span style=\"font-weight: 400;\">Domain : Java Concurrency<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q12 : Given<\/span><\/em><\/h4>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0import java.util.concurrent.atomic.*;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public class Whizlab{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">private static class CStore implements Runnable{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">int x=1;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\"> private AtomicInteger cps = new AtomicInteger(10);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public void run(){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">while(x &gt; 0){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">try{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">Thread.sleep(500);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}catch(Exception e){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">System.out.print(e);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">synchronized(this){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">x = cps.decrementAndGet();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\"> }<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">System.out.print(cps);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public static void main(String args[]){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">CStore cs = new CStore();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">Thread th1 = new Thread(cs);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">Thread th2 = new Thread(cs);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">th1.start();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">th2.start();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<\/ol>\n<h4><em><span style=\"font-weight: 400;\">Which of the following could be an output?<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Always 9876543210<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Might be 9876543210-1<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>An Exception<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>Never ending loop<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/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;\">Since Java 1.5 the java language provides atomic variables, e.g. AtomicInteger or AtomicLong which provide methods like getAndDecrement(), getAndIncrement() and getAndSet() which are atomic. Before the inception of the Java SE 5 atomic classes, programmers were forced to write synchronized code blocks around multithreaded objects. These synchronized blocks are inefficient and an added burden on the developer. The java.util.concurrent.atomic package relieved this burden by providing atomic equivalents to primitive types as well as object references.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Here, we have created a static class called \u201cCStore\u201d and it has implemented the Runnable interface. In this class we have created an AtomicInteger of value 10. Using a while loop and the AtomicInteger class \u201cdecrementAndGet()\u201d method, we have tried to print the numbers from 10 to 0 in a reverse order in the overridden \u201crun()\u201d method.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">AtomicInteger class\u2019 \u201cdecrementAndGet()\u201dmethod will cause the reduction 1 from the current value of the AtomicInteger variable and return the reduced value. So in this code, in every iterate of the while loop, that returning value of the AtomicInteger class\u2019 \u201cdecrementAndGet()\u201dmethod will be assigned to the variable \u201cx\u201d.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Both th1 and th2 are working on same \u201ccs\u201d object. In the every iteration of while loop, one thread invokes the run it\u2019ll go to sleep mode for 500ms after checking the current value of the variable \u201cx\u201d. When the value of the \u201cx\u201d equal to 1 both threads see that x&gt;0, so both threads will reduce 1 from the current value of the \u201cx\u201d, so the output will contain -1. So the <strong>option B is correct.<\/strong><\/span><\/p>\n<p><span style=\"font-weight: 400;\">Here using applying the synchronization at line 15 is not needed as the \u201ccps\u201d is an AtomicInteger and the method \u201cdecrementAndGet()\u201d perform an atomic operation. We could avoid the -1, if we synchronized the checking of the value of the \u201cx\u201d at line 9. So we can see that, even with Atomic variables. Memory consistence errors are still possible.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Other options are incorrect based on above logic.<\/span><\/p>\n<p><b>References: <\/b><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/concurrent\/atomic\/AtomicInteger.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/concurrent\/atomic\/AtomicInteger.html<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/essential\/concurrency\/atomicvars.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/tutorial\/essential\/concurrency\/atomicvars.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_File_IO_NIO2\"><\/span><span style=\"font-weight: 400;\">Domain : Java File I\/O (NIO.2)<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q13 : Given :<\/span><\/em><\/h4>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">import java.io.IOException;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">import java.nio.file.*;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">import java.nio.file.attribute.*;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">import java.util.regex.Pattern;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public class Mat{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">static boolean f;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">public static void main(String []args)throws IOException{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">Path path = Paths.get(&#8220;I:\\\\whizlabs&#8221;);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">FileVisitor&lt;Path&gt; searcher = new Search();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">Files.walkFileTree(path, searcher);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\"> \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">if(!f)System.out.print(&#8220;No matches&#8221;);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">private static final class Search extends SimpleFileVisitor&lt;Path&gt; {<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public FileVisitResult postVisitDirectory(Path dir, IOException e)throws IOException {<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">Pattern p = Pattern.compile(&#8220;&#8230;&#8221;);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">PathMatcher pm = FileSystems.getDefault().getPathMatcher(&#8220;glob:&#8230;&#8221;);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">if(pm.matches(dir.getFileName())){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">System.out.println(dir);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">f=true;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">return FileVisitResult.CONTINUE;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<\/ol>\n<h4><em><span style=\"font-weight: 400;\">Note: assume that the I:\\whizlabs actually exists and contain files and directories and you have enough permission.<\/span><\/em><br \/>\n<em><span style=\"font-weight: 400;\">Which is the result?<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Completion succeeds and \u201cNo matches\u201d will be printed as the output<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Completion succeeds and prints only the paths of the \u201cwhizlabs\u201d directory and its subdirectories<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Completion succeeds and prints only the paths of the subdirectories of the \u201cwhizlabs\u201d directory which contains only three letters for directory name<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>An exception will be thrown at the runtime<\/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;\">We can use \u201cjava.nio.file.PathMatcher\u201d interface to perform match operations on paths. To have a \u201cPathMatcher\u201d, we can use the \u201cgetPathMatcher()\u201d method in the \u201cjava.nio.file.FileSystem\u201d class. We should pass a String to the method and that String work as the pattern for matching operations. We can use \u201cregex\u201d syntax or \u201cglob\u201d syntax for matching, when we pass the pattern, using the \u201cregex:\u201d prefix, we indicates that we are passing the \u201cregex\u201d syntax. If we pass \u201cglob\u201d syntax, then we use the \u201cglob:\u201d prefix to the pattern.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We can use the \u201cwakFileTree()\u201d method combining with the \u201cPathMatcher\u201d to recursively perform path matching operations.<\/span><\/p>\n<p><b>Option A is correct <\/b><span style=\"font-weight: 400;\">as the \u201cwakFileTree()\u201d method visit all the files and subdirectories of the given file root, the \u201cpostVisitDirectory ()\u201d method is invoked after the all entries are visited. Then the method compares the current directory with the \u201cPathMatcher\u201d. As we have passed the glob syntax \u201c<\/span><b>&#8230;<\/b><span style=\"font-weight: 400;\">\u201d, there will be no matching path because not like with regex syntax, with glob syntax, \u201c.\u201d has no special meaning so this glob syntax only matches with a names which are created with three \u201c.\u201d.<\/span><br \/>\n<b>Option B and C are incorrect<\/b><span style=\"font-weight: 400;\"> as explained above.<\/span><br \/>\n<b>Option D is incorrect <\/b><span style=\"font-weight: 400;\">as we have given that the directory actually exists and we have enough permission.<\/span><br \/>\n<b>Option E is incorrect<\/b><span style=\"font-weight: 400;\"> as code compiles fine.<\/span><\/p>\n<p><b>References: <\/b><a href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/essential\/io\/find.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/tutorial\/essential\/io\/find.html<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/file\/FileSystem.html#getPathMatcher(java.lang.String)\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/file\/FileSystem.html#getPathMatcher(java.lang.String)<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Building_Database_Applications_with_JDBC-3\"><\/span><span style=\"font-weight: 400;\">Domain : Building Database Applications with JDBC<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q14 : Given<\/span><\/em><\/h4>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0import java.sql.*;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public class Pro{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public static void main(String []args)throws SQLException{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">DBConnect dc = new DBConnect();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">dc.insert(6,&#8221;Martha&#8221;,&#8221;Kent&#8221;,&#8221;2012-10-10&#8243;);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0class DBConnect{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0private Connection con;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">private Statement stm;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0private ResultSet rs;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public DBConnect(){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Assume: A connection object and a Statement object are successfully created in \u00a0 \u00a0 this constructor.<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public void insert(int id, String fname, String lname, String date)throws SQLException{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">try{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">String query = &#8220;INSERT INTO users VALUES( null , &#8216;&#8221; + fname + &#8220;&#8216;, &#8216;&#8221;+lname+ &#8220;&#8216;, &#8216;&#8221;+date+&#8221;&#8216;)&#8221;;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">stm.executeQuery (query);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}finally{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0con.close();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<\/ol>\n<h4><em><span style=\"font-weight: 400;\">Note: You can consider given table as the \u201cusers\u201d table. And consider the ID can be auto increment.<img decoding=\"async\" class=\"aligncenter wp-image-81860 size-full\" title=\"Users Table Java\" src=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/03\/o14.1.jpg\" alt=\"Users Table Java\" width=\"439\" height=\"210\" srcset=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/03\/o14.1.jpg 439w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/03\/o14.1-300x144.jpg 300w\" sizes=\"(max-width: 439px) 100vw, 439px\" \/><\/span><\/em><em><span style=\"font-weight: 400;\">Which of the following is true?<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>A new record will be added as follows:<img decoding=\"async\" class=\"aligncenter size-full wp-image-81861\" src=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/03\/o14.2.png\" alt=\"Users Table Java\" width=\"216\" height=\"19\" \/><\/span><span style=\"font-weight: 400;\"><strong>B. <\/strong>A new record will be added as follows:<img decoding=\"async\" class=\"aligncenter size-full wp-image-81862\" src=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/03\/o14.3.png\" alt=\"\" width=\"220\" height=\"19\" \/><\/span><span style=\"font-weight: 400;\"><strong>C. <\/strong>Code will run without any exception but no record will be added<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>Compilation fails due to error at line 22<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>An exception will be thrown at runtime<\/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;\">as a SQLException is thrown at runtime. INSERT is a data manipulation statement (DML). In this code, trying to execute DML statement using the \u201cexecuteQuery()\u201d method will cause the SQLException. To execute such a query, we should have used the \u201cexecute()\u201d method or the \u201cexecuteUpdate()\u201d method. So line 22, will cause an exception.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If we used \u201cexecute()\u201d method or the \u201cexecuteUpdate()\u201d\u00a0 method, the output could be B. Because ID can be auto increment, passing \u201cnull\u201d to ID won\u2019t cause any problem. If we pass null, it will automatically choose a suitable value.<\/span><\/p>\n<p><b>References:<\/b> <a href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/jdbc\/basics\/processingsqlstatements.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/tutorial\/jdbc\/basics\/processingsqlstatements.html<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/sql\/ResultSet.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/sql\/ResultSet.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Exceptions_and_Assertions-3\"><\/span><span style=\"font-weight: 400;\">Domain : Exceptions and Assertions<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q15 : Given<\/span><\/em><\/h4>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0class Whizlab{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public static void main(String args[]){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">int x = 10, y = 0;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">try{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">int c = x\/y;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">catch(IllegalArgumentException | NullPointerException e){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">System.out.print(&#8220;Multi&#8221;);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">catch(Exception e){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">System.out.print(&#8220;Exc&#8221;);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0 <\/span> <span style=\"font-weight: 400;\"> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span><\/em><\/h4>\n<\/li>\n<\/ol>\n<h4><em><span style=\"font-weight: 400;\">Which is the output?<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>No output<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Multi<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Exc<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>An uncaught exception will be thrown<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>Compilation fails<\/span><\/p>\n<p><b>Correct Answer: C<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><b>Option C is correct<\/b><span style=\"font-weight: 400;\"> as at line 6, an ArithmeticException is thrown but it couldn\u2019t be caught by the multiple exception catch box so the exception is passed to the catch box at line 11, so \u201cExc\u201d will be printed.<\/span><br \/>\n<b>Option A is incorrect <\/b><span style=\"font-weight: 400;\">as an ArithmeticException is thrown at the runtime.<\/span><br \/>\n<b>Option B is incorrect <\/b><span style=\"font-weight: 400;\">as the ArithmeticException couldn\u2019t be caught by the multiple exception catch box.<\/span><br \/>\n<b>Option D is incorrect<\/b><span style=\"font-weight: 400;\"> as there is no uncaught exception<\/span><br \/>\n<b>Option E is incorrect<\/b><span style=\"font-weight: 400;\"> as code compiles fine.<\/span><\/p>\n<p><b>Reference:<\/b> <a href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/essential\/exceptions\/catch.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/tutorial\/essential\/exceptions\/catch.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Generics_and_Collections-3\"><\/span><span style=\"font-weight: 400;\">Domain : Generics and Collections<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q16 : Consider<\/span><\/em><br \/>\n<em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">class Whizlab&lt;Double&gt; { }<\/span><\/em><br \/>\n<em><span style=\"font-weight: 400;\">Which of the following is valid initialization of the class Whizlab?<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Whizlab&lt;&gt; my = new Whizlab&lt;&gt;();<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Whizlab&lt;int&gt; my = new Whizlab&lt;&gt;();<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Whizlab&lt;String&gt;\u00a0 my = new Whizlab&lt;&gt;();<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>Whizlab&lt;&gt;\u00a0 my = new Whizlab();\u00a0<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>None of above<\/span><\/p>\n<p><b>Correct Answer: C<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">A generic class is defined with the following format:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">class name { \/* &#8230; *\/ }<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The type parameter section, delimited by angle brackets (&lt;&gt;), follows the class name. It specifies the type parameters (also called type variables) T1, T2, &#8230;, and Tn.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">So in given statement we have use Double as the type name, but note that it is not the type of the generic. Hence here when we initialize we can use any valid type like given in option C.<\/span><\/p>\n<p><b>Options B and D incorrect <\/b><span style=\"font-weight: 400;\">since we can\u2019t use primitive type as generic<\/span><\/p>\n<p><b>Reference:<\/b> <a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/java\/generics\/types.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/javase\/tutorial\/java\/generics\/types.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_Concurrency-3\"><\/span><span style=\"font-weight: 400;\">Domain : Java Concurrency<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q17 : Given the following method :<\/span><\/em><\/h4>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0public Long compute() {<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">if (high &#8211; low &lt;= MAX) {<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">long sum = 0;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">for (int i = low; i &lt; high; ++i)<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">sum += array[i];<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">return sum;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">} else {<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">int mid = low + (high &#8211; low) \/ 2;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">Sum left\u00a0 = new Sum(array, low, mid);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">Sum right = new Sum(array, mid, high);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">long rightAns = right.compute();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">left.fork();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">long leftAns\u00a0 = left.join();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">return leftAns + rightAns;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0<\/span> <span style=\"font-weight: 400;\">} \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span><\/em><\/h4>\n<\/li>\n<\/ol>\n<h4><em><span style=\"font-weight: 400;\">Which of the following statements is true?<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Code fragment shows the appropriate way of using the Fork-Join<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Code fragment doesn\u2019t show the appropriate way of using the Fork-Join<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Code fragment will fail the compilation due to error on line 17<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>None of above<\/span><\/p>\n<p><b>Correct Answer: B<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><b>Option B is correct <\/b><span style=\"font-weight: 400;\">as we have called \u201ccompute()\u201d method recursively before calling the \u201cfork()\u201d method so if we used this order then we would have no parallelism since this computes the \u201cright\u201d before starting to compute left. So this is not the appropriate way of using the Fork-Join.<\/span><br \/>\n<b>Option C is incorrect<\/b><span style=\"font-weight: 400;\"> as calling these methods in any order won\u2019t cause any compile time error.<\/span><\/p>\n<p><b>Reference: <\/b><a href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/essential\/concurrency\/forkjoin.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/tutorial\/essential\/concurrency\/forkjoin.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_File_IO_NIO2-2\"><\/span><span style=\"font-weight: 400;\">Domain : Java File I\/O (NIO.2)<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q18 : Given<\/span><\/em><\/h4>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">import java.nio.file.*;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">import java.io.IOException;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">import java.util.*;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">class Whizlab{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public static void main(String [] args)throws IOException{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">Path path = Paths.get(&#8220;..\\\\myfile.txt&#8221;);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><\/li>\n<\/ol>\n<h4><em><span style=\"font-weight: 400;\">Which, inserted independently at line 7, will compile and produce the owner of the \u201cmyfile.txt\u201d as the output?<\/span><\/em><br \/>\n<em><span style=\"font-weight: 400;\">I. Map&lt;String, Object&gt; mp = new HashMap();<\/span><\/em><br \/>\n<em><span style=\"font-weight: 400;\">\u00a0 \u00a0mp = Files.readAttributes(path, &#8220;*&#8221; );<\/span><\/em><br \/>\n<em><span style=\"font-weight: 400;\">\u00a0 \u00a0System.out.print(mp.get(\u201cowner\u201d));<\/span><\/em><br \/>\n<em>II. BasicFileAttributes at = Files.readAttributes(path, BasicFileAttributes.class);<\/em><br \/>\n<em><span style=\"font-weight: 400;\">\u00a0 \u00a0 System.out.print(at.owner ());<\/span><\/em><br \/>\n<em><span style=\"font-weight: 400;\">III. System.out.print(Files.getOwner (path));<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Only I<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Only I and II<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Only III<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>None<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>All<\/span><\/p>\n<p><b>Correct Answer: C<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><b>Option C is correct <\/b><span style=\"font-weight: 400;\">as only the code fragment III will compiles and produces the expected output.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The code fragment I, is incorrect as there is one overloaded version of java.nio.file.Files class\u2019 \u201creadAttributes()\u201d method which takes path object and a string (and a LinkOption\u00a0 but it\u2019s optional).\u00a0 By using it we can have a Map of basic-file-attributes. We can specify which basic-file-attributes we need to retrieve, by using the String argument. Here we have passed \u201cowner\u201d, hoping that,it will return a map object only containing the owners name of the file which path object referring but the \u201cowner\u201d attribute is not an one of basic-file-attributes so the output will be \u201cnull\u201d as there is no key called \u201cowner\u201d in the returning map.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Other version of the java.nio.file.Files class\u2019 \u201creadAttributes()\u201d will cause compilation fails as there is no method called \u201cowner()\u201d in the \u201cBasicFileAttributes\u201d.<\/span><\/p>\n<p><b>References:<\/b> <a href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/essential\/io\/fileAttr.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/tutorial\/essential\/io\/fileAttr.html<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/file\/Files.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/file\/Files.html<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/file\/attribute\/BasicFileAttributes.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/file\/attribute\/BasicFileAttributes.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_Stream_API\"><\/span><span style=\"font-weight: 400;\">Domain : Java Stream API<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q19 : Given<\/span><\/em><\/h4>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0import java.util.Optional;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public class Whizlab{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public static void main(String[] args){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">Optional&lt;Integer&gt; ops = Optional.of(new Integer(10));<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">ops.filter(x -&gt; Integer.compare(12, x) &gt; 0).ifPresent(System.out::print);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">System.out.println(ops.get());\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<\/ol>\n<h4><em><span style=\"font-weight: 400;\">What is the output?<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>10<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>1010<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Optional[10]<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>A NoSuchElementException<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/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;\">At line 5 we have created an instance of optional with an Integer wrapper. Then at line 6 invoking the filter method by passing \u201cx -&gt; Integer.compare(12, x) &gt; 0\u201d as the predicate will not filter that optional element hence when the invoking ifPresent there is valid element inside the optional. So it will execute the consumer of the ifPresent method which is printing statement. So 10 will be printed then at line 7 get method will return the element of Optional hence again 10 will be printed. Hence <strong>option B is correct.<\/strong><\/span><\/p>\n<p><b>Reference:<\/b> <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/Optional.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/Optional.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Generics_and_Collections-4\"><\/span><span style=\"font-weight: 400;\">Domain : Generics and Collections<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q20 : If we add Enum constants to a tree set what will be the order in which they will be maintained?<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Insertion order<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Order in which constants are declared<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Reverse\u00a0 sorting\u00a0 order<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>Won&#8217;t maintain any order<\/span><\/p>\n<p><b>Correct Answer: B<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Enum implements Comparable via the natural order of the enum (the order in which the values are declared), so if we add enum to a sorted collection like tree set it will maintain the order in which constants are declared. Hence <strong>option B is correct.<\/strong><\/span><\/p>\n<p><b>Reference: <\/b><a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/java\/javaOO\/enum.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/javase\/tutorial\/java\/javaOO\/enum.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_Concurrency-4\"><\/span><span style=\"font-weight: 400;\">Domain : Java Concurrency<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q21 : Given<\/span><\/em><\/h4>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">import java.util.concurrent.locks.*;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">import java.util.concurrent.*;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">import java.util.*;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">class Whizlab{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">static class Task1 implements Callable&lt;Integer&gt;{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">public Integer call(){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">return\u00a0 1;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">static class Task2 implements Callable&lt;Integer&gt;{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public Integer call(){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">return 2;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">static class Task3 implements Callable&lt;Double&gt;{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public Double call(){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">return 3.0;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public static void main(String []args)throws Exception{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">final ExecutorService pool = Executors.newFixedThreadPool(2);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">List&lt;Callable&lt;Integer&gt;&gt; cal = new ArrayList&lt;&gt;();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">cal.add(new Task2());<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">cal.add(new Task1());<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">System.out.print(pool.invokeAny(cal));<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">pool.shutdownNow();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<\/ol>\n<h4><span style=\"font-weight: 400;\"><em>Which is true about the above code?<\/em>\u00a0<\/span><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Compilation fails<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>An exception will be thrown at runtime<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Only 1 or 2 will be printed as the output<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>Only 2 will be printed as the output<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>2 1 Will be printed as the output<\/span><\/p>\n<p><b>Correct Answer: C<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">In this code, we have created three Callable objects (Task1, Task2, Task3). Then we have created a FixedThreadPool with two threads. This type of pool always has a specified number of threads running; if a thread is somehow terminated while it is still in use, it is automatically replaced with a new thread. Tasks are submitted to the pool via an internal queue. Then we have added Task2 and Task1 to a ArrayList. The invokeAny() method takes a collection of Callable objects, or subinterfaces of Callable. Invoking this method does not return a Future, but returns the result of one of the Callable objects. You have no guarantee about which of the Callable&#8217;s results you get. So in this code invoking the \u201cinvokeAny()\u201d method at line 28, will return 1 or 2 but not both. So the answer is C.<\/span><\/p>\n<p><b>Options D and E are incorrect<\/b><span style=\"font-weight: 400;\"> as explained above.<\/span><br \/>\n<b>Option A is incorrect <\/b><span style=\"font-weight: 400;\">as the code compiles fine.<\/span><\/p>\n<p><b>References:<\/b> <a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/concurrent\/ExecutorService.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/concurrent\/ExecutorService.html<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/essential\/concurrency\/exinter.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/tutorial\/essential\/concurrency\/exinter.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Generics_and_Collections-5\"><\/span><span style=\"font-weight: 400;\">Domain : Generics and Collections<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q22 : Given<\/span><\/em><\/h4>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0import java.util.ArrayList;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0import java.util.List;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0public class Whiz{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public static void main(String[] args){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 List&lt;Integer&gt; ints = new ArrayList&lt;&gt;();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 <\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">ints.add(1);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">ints.add(2);\u00a0 \u00a0 <\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">ints.add(3);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">ints.replaceAll(i -&gt; i\/2);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">System.out.println(ints.stream().distinct().count());<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<\/ol>\n<h4><em><span style=\"font-weight: 400;\">What is the output?<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>1<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>2<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>3<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>An exception is thrown<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/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 replaceAll method of the List interface replaces each element of this list with the result of applying the operator to that element.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0default void replaceAll(UnaryOperator operator)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0The default implementation is equivalent to, for this list:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">final ListIterator li = list.listIterator();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">while (li.hasNext()) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">li.set(operator.apply(li.next()));<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">So here we have passed UnaryOperator to divide elements by 2 and then assigned them to each position, hence it will result in a list to contain, 0, 1 and 1. At line 12 invoking distinct will remove duplicate 1 so count will be 2. Hence <\/span><b>option B is correct.<\/b><\/p>\n<p><b>Reference:<\/b> <a href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/collections\/interfaces\/List.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/tutorial\/collections\/interfaces\/List.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Generics_and_Collections-6\"><\/span><span style=\"font-weight: 400;\">Domain : Generics and Collections<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q23 : Given<\/span><\/em><\/h4>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">import java.util.Map;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">import java.util.TreeMap;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public class Whizlab{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">public static void main(String args[]){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">Map&lt;String, Integer&gt; tmap =\u00a0 new TreeMap&lt;&gt;();<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">tmap.put(&#8220;ab&#8221;,1);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">tmap.put(&#8220;abc&#8221;,2);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">tmap.put(&#8220;abcd&#8221;,3);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">tmap.replaceAll( (k,v) -&gt; (int)k.charAt(v) );<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">System.out.println(tmap.values());<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0}\u00a0<\/span><\/em><\/h4>\n<\/li>\n<\/ol>\n<h4><em><span style=\"font-weight: 400;\">What is the output?<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>[1, 2, 3]<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>[98, 98, 98]<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>[98, 99, 100]<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>An Exception<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>Compilation fails<\/span><\/p>\n<p><b>Correct Answer: C<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Java 8 introduced a new method called replaceAll in the Map interface. It replaces each entry&#8217;s value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception. Exceptions thrown by the function are related to the caller.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">public void replaceAll(BiFunction function)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">So here at line 11 we have passed BiFunction to get the char at index of value from the key string and then to return the ascii value of the char. So in this case values will be replaced with their keys char value of the given position. SO <\/span><b>option C is correct.<\/b><\/p>\n<p><b>Reference<\/b><span style=\"font-weight: 400;\">: <\/span><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/TreeMap.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/TreeMap.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_File_IO_NIO2-3\"><\/span><span style=\"font-weight: 400;\">Domain : Java File I\/O (NIO.2)<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q24 : Given :<\/span><\/em><\/h4>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">import java.nio.file.*;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">import java.io.*;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">import java.nio.file.attribute.*;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">class NIO{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\"> \u00a0 \u00a0 \u00a0 \u00a0 public static void main(String [] args)throws IOException{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Path path = Paths.get(&#8220;..\\\\myfile.txt&#8221;);<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\"> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\"> \u00a0 \u00a0 \u00a0 \u00a0 }<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<\/ol>\n<h4><em><span style=\"font-weight: 400;\">Note: assume that the myfile.txt actually exists and code runs on a windows flat form and the\u201d myfile.txt\u201d file is already marked as read only and you have enough permission to do any operation on the file.<\/span><\/em><br \/>\n<em><span style=\"font-weight: 400;\">Which, inserted independently at line 9, will compile and produce the group owner of the file.of the \u201cmyfile.txt\u201d as the output?<\/span><\/em><\/h4>\n<p><em><span style=\"font-weight: 400;\">I. PosixFileAttributes pa =\u00a0 Files.readAttributes(path, PosixFileAttributes.class);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 System.out.print(pa.group().getName());<\/span><\/em><\/p>\n<p><em><span style=\"font-weight: 400;\">II. PosixFileAttributes pa =\u00a0 Files.readAttributes(path, PosixFileAttributes.class); System.out.print(pa.group());<\/span><\/em><\/p>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>Only I will cause a compile time error<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>Only II will cause a compile time error<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>Both will cause compile time error<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>None of the above is true<\/span><\/p>\n<p><b>Correct Answer: D<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><b>Option D is correct <\/b><span style=\"font-weight: 400;\">as \u201cPosixFileAttributes\u201d are only supported on file systems that support the Posix family standards. But windows is a dos file system. In this code trying to use PosixFileAttributes on a dos file system causes an \u201cUnsupportedOperationException &#8221; at the runtime. So other options are incorrect.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If this code runs on a unix file system then the code fragment I will produce the expected output.<\/span><\/p>\n<p><b>References: <\/b><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/file\/attribute\/PosixFileAttributes.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/nio\/file\/attribute\/PosixFileAttributes.html<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/essential\/io\/fileAttr.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">http:\/\/docs.oracle.com\/javase\/tutorial\/essential\/io\/fileAttr.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Domain_Java_Stream_API-2\"><\/span><span style=\"font-weight: 400;\">Domain : Java Stream API<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><em><span style=\"font-weight: 400;\">Q25 : Given<\/span><\/em><\/h4>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">import java.util.stream.IntStream;<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public class Whiz{<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">public static void main(String[] args){<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">IntStream ints = IntStream.of(3,2,1,5,3,4,5); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\">System.out.print(ints.filter(e -&gt; e&gt;3).distinct().average().getAsDouble());<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span> <span style=\"font-weight: 400;\">}<\/span><\/em><\/h4>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\">\n<h4><em><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0}<\/span><\/em><\/h4>\n<\/li>\n<\/ol>\n<h4><em><span style=\"font-weight: 400;\">What is the output?<\/span><\/em><\/h4>\n<p><span style=\"font-weight: 400;\"><strong>A. <\/strong>5.0<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>B. <\/strong>4.0<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>C. <\/strong>4.5<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>D. <\/strong>3.28<\/span><br \/>\n<span style=\"font-weight: 400;\"><strong>E. <\/strong>Compilation fails due to error at line 8<\/span><\/p>\n<p><b>Correct Answer: C<\/b><\/p>\n<p><b>Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">First at line 7, we have created an IntStream with duplicated values. At line 8 we have used a filter to get a stream which contains only values greater than 3. Calling distinct will remove all duplicated values in the stream, so finally when average calls only 4 and 5 are remaining. So the result average will be 9 divided by 2 ( = 4.50). Since we use getAsDouble, the whole number with fraction part will be printed, hence <\/span><b>option C is correct.<\/b><\/p>\n<p><b>Options A and D are incorrect<\/b><span style=\"font-weight: 400;\"> as it is not the average.<\/span><br \/>\n<b>Option B is incorrect <\/b><span style=\"font-weight: 400;\">as we get the double value.<\/span><\/p>\n<p><b>Reference<\/b><span style=\"font-weight: 400;\">: <\/span><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/stream\/Stream.html#noneMatch-java.util.functon.Predicate-\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/stream\/Stream.html#noneMatch-java.util.functon.Predicate-<\/span><\/a><\/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;\">Hope we are able to solve your doubts and you have got clarity on some of the concepts of the Oracle Certified Professional [Java SE 8 1Z0-809] certification exam. Learn and explore more such concepts with<\/span> Oracle Certified Professional [Java SE 8] Practice Tests &amp; Video course available on our official website.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Oracle Certified Professional, Java SE 8 Programmer Certification exam (1Z0-809) requires you to have a practical understanding and Hands-on experience with Java SE8 version. The prerequisite for this certification is the completion of the Oracle Certified Associate(OCA) certification. In this article, we provide Java SE 8 Programmer certification 1Z0-809 free test questions. These 1Z0-809 exam questions are for your easy assessment of the certification exam, and to give you an idea on the pattern of the questions that could be asked in the actual exam. Domain : Java Class Design Q1 : Given \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0interface Switchable{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 void sw(int i); [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":82087,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","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":"","adv-header-id-meta":"","stick-header-meta":"","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":[4860,4859],"class_list":["post-81859","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-1z0-809-exam","tag-java-se-8-programmer-certification-exam"],"uagb_featured_image_src":{"full":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2022\/04\/Free-Questions-on-Oracle-Certified-Professional_-Java-SE-8-Programmer-OCPJP-8-1Z0-809-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-8-Programmer-OCPJP-8-1Z0-809-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-8-Programmer-OCPJP-8-1Z0-809-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-8-Programmer-OCPJP-8-1Z0-809-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-8-Programmer-OCPJP-8-1Z0-809-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-8-Programmer-OCPJP-8-1Z0-809-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-8-Programmer-OCPJP-8-1Z0-809-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-8-Programmer-OCPJP-8-1Z0-809-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-8-Programmer-OCPJP-8-1Z0-809-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-8-Programmer-OCPJP-8-1Z0-809-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-8-Programmer-OCPJP-8-1Z0-809-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-8-Programmer-OCPJP-8-1Z0-809-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-8-Programmer-OCPJP-8-1Z0-809-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-8-Programmer-OCPJP-8-1Z0-809-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-8-Programmer-OCPJP-8-1Z0-809-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-8-Programmer-OCPJP-8-1Z0-809-Certification-Exam.webp",150,79,false]},"uagb_author_info":{"display_name":"Pavan Gumaste","author_link":"https:\/\/www.whizlabs.com\/blog\/author\/pavan\/"},"uagb_comment_info":1,"uagb_excerpt":"The Oracle Certified Professional, Java SE 8 Programmer Certification exam (1Z0-809) requires you to have a practical understanding and Hands-on experience with Java SE8 version. The prerequisite for this certification is the completion of the Oracle Certified Associate(OCA) certification. In this article, we provide Java SE 8 Programmer certification 1Z0-809 free test questions. These 1Z0-809&hellip;","_links":{"self":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/81859","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\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/comments?post=81859"}],"version-history":[{"count":11,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/81859\/revisions"}],"predecessor-version":[{"id":84669,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/81859\/revisions\/84669"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/media\/82087"}],"wp:attachment":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/media?parent=81859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/categories?post=81859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/tags?post=81859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}