Welcome to your Test - 1 Unique Test Code - 819 Name Email Phone 1. Question: A developer has written the following code snippet: Console c = System.console(); //1 String line = c.readLine("Please enter your name:"); //2 System.out.println("Hello, "+line); //3Which of the following statements are true about this code if it is run in the background by a scheduler?Select 1 option(s): Line //1 will throw IOException Line //1 will throw NullPointerException. Line //2 will throw IOException. Line //2 will throw NullPointerException. Line //3 will print Hello, null.2. Question: Identify the correct statements about Java Stream API.Select 1 option(s): Streams are reusable. Elements of a stream are mutable. Streams support aggregate operations. All Stream operations are lazy.3. Question: Given:List letters = Arrays.asList("j", "a", "v","a");Which of the following code snippets will print JAVA?Select 3 option(s): letters.forEach(letter->letter.toUpperCase()); letters.forEach(System.out::print); UnaryOperator< String > uo = str->str.toUpperCase();letters.forEach(uo); letters.forEach(System.out::print); UnaryOperator< String > uo = str->str.toUpperCase();letters.replaceAll(uo);letters.forEach(System.out::print); letters.forEach(letter->System.out.print(letter.toUpperCase())); System.out.print(letters.stream().collect(Collectors.joining()).toUpperCase()); System.out.print(letters.stream().collect(Collectors.joining(letter->letter.toUpperCase())););4. Question: Which of the following correctly defines a method named stringProcessor that can be called by other programmers as follows: stringProcessor(str1) or stringProcessor(str1, str2) or stringProcessor(str1, str2, str3), where str1, str2, and str3 are references to Strings.Select 1 option(s): public void stringProcessor(...String){ } public void stringProcessor(String... strs){} public void stringProcessor(String[] strs){} public void stringProcessor(String a, String b, String c){ } public void stringProcessor(var String a){ } Three separate methods need to be written.5. Question: What is wrong with the following code?class MyException extends Exception {} public class TestClass{public static void main(String[] args){TestClass tc = new TestClass(); try{ tc.m1();}catch (MyException e){ tc.m1();}finally{tc.m2(); }}public void m1() throws MyException{throw new MyException(); }public void m2() throws RuntimeException{throw new NullPointerException();}}Select 1 option(s): It will not compile because you cannot throw an exception in finally block. It will not compile because you cannot throw an exception in catch block. It will not compile because NullPointerException cannot be created this way. It will not compile because of unhandled exception. It will compile but will throw an exception when run.6. Question: Given:public class Item{ private String name; private String category; private double price; public Item(String name, String category, double price){ this.name = name; this.category = category; this.price = price; } //accessors not shown}What will the following code print?List<Item> items = Arrays.asList( new Item("Pen", "Stationery", 3.0), new Item("Pencil", "Stationery", 2.0), new Item("Eraser", "Stationery", 1.0), new Item("Milk", "Food", 2.0), new Item("Eggs", "Food", 3.0));ToDoubleFunction<Item> priceF = Item::getPrice; //1items.stream() .collect(Collectors.groupingBy(Item::getCategory)) //2 .forEach((a, b)->{ double av = b.stream().collect(Collectors.averagingDouble(priceF)); //3 System.out.println(a+" : "+av); });Select 1 option(s): Stationery : 2.0 Food : 2.5 [Pen : 3.0, Pencil : 2.0, Eraser : 1.0] : 2.0 [Milk : 2.0, Eggs : 3.0] : 2.5 Pen : 3.0, Pencil : 2.0, Eraser : 1.0 : 2.0 Milk : 2.0, Eggs : 3.0 : 2.5 Stationery : [Pen : 3.0, Pencil : 2.0, Eraser : 1.0] : 2.0Food : [Milk : 2.0, Eggs : 3.0] : 2.5 Compilation error due to code at //1 Compilation error due to code at //2 Compilation error due to code at //37. Question: Which of the statements regarding the following code are correct? public class TestClass{ static int a; int b; public TestClass(){ int c; c = a; a++; b += c; } public static void main(String args[]) { new TestClass(); }}Select 1 option(s): The code will fail to compile because the constructor is trying to access static members. The code will fail to compile because the constructor is trying to use static member variable a before it has been initialized. The code will fail to compile because the constructor is trying to use member variable b before it has been initialized. The code will fail to compile because the constructor is trying to use local variable c before it has been initialized. The code will compile and run without any problem.8. Question: What will the following code print when compiled and run? var numA = new Integer[]{1, 2};var list1 = new ArrayList<Integer>(List.of(numA));list1.add(null);var list2 = Collections.unmodifiableList(list1);list1.set(2, 3);List<List<Integer>> list3 = List.of(list1, list2);System.out.println(list3);Select 1 option(s): [[1, 2, 3], [1, 2, 3]] [1, 2, 3] [[1, 2, 3], [1, 2, null]] [1, 2, null] [1, 2, 3, null] It will throw an exception at run time.9. Question: Given the following module definitions:module m${ requires _n; exports o;}module _n{ requires m$; exports p;}Identify the correct statements.Select 1 option(s): The definitions are invalid because of circular dependency. The definitions are invalid because the package names in the export clauses are invalid. The definitions are invalid because the modules names are invalid. The definitions are invalid because they don't declare dependency on java.base module. The definitions are invalid because of circular dependency as well as ommission of requires java.base;.10. Question: Which is the first line that will cause compilation to fail in the following program?// Filename: A.java class A{ public static void main(String args[]){ A a = new A();B b = new B(); a = b; // 1b = a; // 2 a = (B) b; // 3b = (B) a; // 4}}class B extends A { }Select 1 option(s): At Line 1. At Line 2. At Line 3. At Line 4. None of the above.11. Question: Which of the following are valid declarations inside the FooI interface? interface AI{ void moo();}interface FooI extends AI{ //INSERT CODE HERE}Select 2 option(s): private void foo(){ }; private abstract void foo(); static void foo(); protected void foo(); public final void compute(); final void foo(){ } @Override void moo();12. Question: What will the following code print when compiled and run? public class TestClass { public static void main(String[] args) { String s = "blooper"; StringBuilder sb = new StringBuilder(s); s.append("whopper"); sb.append("shopper"); System.out.println(s); System.out.println(sb); }}Select 1 option(s): blooper and bloopershopper blooperwhopper and bloopershopper blooper and blooperwhoppershopper It will not compile.13. Question: Which of the following class definitions is/are legal definition(s) of a class that cannot be instantiated?class Automobile{ abstract void honk(); //(1)}abstract class Automobile{ void honk(); //(2) }abstract class Automobile{void honk(){}; //(3) } abstract class Automobile{abstract void honk(){} //(4)}abstract class Automobile{ abstract void honk(); //(5)}Select 2 option(s): 1 2 3 4 514. Question: What will the following class print when run?public class Sample{public static void main(String[] args) {String s1 = new String("java"); StringBuilder s2 = new StringBuilder("java"); replaceString(s1);replaceStringBuilder(s2);System.out.println(s1 + s2);}static void replaceString(String s) { s = s.replace('j', 'l');}static void replaceStringBuilder(StringBuilder s) { s.append("c"); }}Select 1 option(s): javajava lavajava javajavac lavajavac None of these.15. Question: Identify correct statements about java.io.Console class?Select 1 option(s): You can read character data from a console but not write to it. You can read both binary and character data from Console object but you cannot write to it. You can read both binary and character data from Console object but you can only write character data to it. You can read as well as write only character data from/to it.16. Question: What will the following code print when run? public class Test { static String s = ""; public static void m0(int a, int b) { s += a; m2(); m1(b); } public static void m1(int i) { s += i; } public static void m2() { throw new NullPointerException("aa"); } public static void m() { m0(1, 2); m1(3); } public static void main(String args[]) { try { m(); } catch (Exception e) { } System.out.println(s); }}Select 1 option(s): 1 12 123 2 It will throw exception at runtime.17. Question: Identify the valid enum declarations.Select 2 option(s): //in file Pets.java enum Pets implements java.io.Serializable{DOG("D"), CAT("C"), FISH("F");String name; Pets(String s) { } public String getData(){ return name; } } //in file Pets.java enum Pets {DOG("D"), CAT("C"), FISH("F");static String prefix = "I am ";String name; Pets(String s) { name = prefix + s;} public String getData(){ return name; }} //in file Pets.java public enum Pets {DOG(1, "D"),CAT(2, "C") {public String getData(){ return type+name; }}, FISH(3, "F");int type; String name; Pets(int t, String s) { this.name = s; this.type = t;} public String getData(){ return name+type; } } //in file Pets.java enum Pets {String name;DOG("D"), CAT("C"), FISH("F"); Pets(String s) { name = s;}} //in file Pets.javaenum Pets{DOG("D"), CAT("C"), FISH("F");String name;public Pets(String s) { }public String getData(){ return name; }} //in file Pets.java enum Pets {DOG("D"), CAT("C"), FISH("F");var name; Pets(String s) { name = s; }public String getData(){ return (String) name; } }18. Question: Consider following classes://In File Other.java package other;public class Other { public static String hello = "Hello"; } //In File Test.java package testPackage; import other.*; class Test{ public static void main(String[] args){ String hello = "Hello", lo = "lo";System.out.print((testPackage.Other.hello == hello) + " "); //line 1 System.out.print((other.Other.hello == hello) + " "); //line 2 System.out.print((hello == ("Hel"+"lo")) + " "); //line 3System.out.print((hello == ("Hel"+lo)) + " "); //line 4System.out.println(hello == ("Hel"+lo).intern()); //line 5}}class Other { static String hello = "Hello"; } What will be the output of running class Test?Select 1 option(s): false false true false true false true true false true true true true true true true true true false true None of the above.19. Question: Given the following code :public class TestClass {int[][] matrix = new int[2][3]; var a = new int[]{1, 2, 3};var b = new int[]{4, 5, 6};public int compute(int x, int y){ //1 : Insert Line of Code here}public void loadMatrix(){for(int x=0; x<matrix.length; x++){ for(int y=0; y<matrix[x].length; y++){ //2: Insert Line of Code here }}}} What can be inserted at //1 and //2?Select 1 option(s): return a(x)*b(y);andmatrix(x, y) = compute(x, y); return a[x]*b[y]; andmatrix[x, y] = compute(x, y); return a[x]*b[y]; andmatrix[x][y] = compute(x, y); return a(x)*b(y); and matrix(x)(y) = compute(x, y); return a[x]*b[y];and matrix[[x][y]] = compute(x, y);20. Question: For what command line arguments will the following program print true?class TestClass{ public static void main(String[] args){Integer i = Integer.parseInt(args[0]); Integer j = i; i--;i++; System.out.println((i==j)); }}Select 3 option(s): 0 -1 127 -256 256 For all the values between 0 and 255 (both included).21. Question: What will the following program print when compiled and run: public class TestClass { public static void main(String[] args) { someMethod(); } static void someMethod(Object parameter) { System.out.println("Value is "+parameter); }}Select 1 option(s): It will not compile. Value is null Value is It will throw a NullPointerException at run time.22. Question: What will the following code print when compiled and run? String val1 = "hello"; StringBuilder val2 = new StringBuilder("world"); UnaryOperator<String> uo1 = s1->s1.concat(val1); //1 UnaryOperator<String> uo2 = s->s.toUpperCase(); //2 System.out.println(uo1.apply(uo2.apply(val2))); //3Select 1 option(s): Compilation error at //1 Compilation error at //2 Compilation error at //3 Compilation error at //1 and //3 It will print WORLDhello It will print WORLDHELLO It will print HELLOWORLD23. Question: Given: Character[] ca = { 'b', 'c', 'a', 'e', 'd' }; List<Character> l = Arrays.asList(ca); l.parallelStream().peek(System.out::print).forEachOrdered(System.out::print);Identify the correct statement about the above code.Select 1 option(s): The characters printed by peek may be in any order but the characters printed by forEachOrdered will always be in the same order as the original list i.e. bcaed. The characters printed by forEachOrdered will always be in the same order as the one printed by the peek method. If forEachOrdered is replaced with forEach, the order of the characters printed by forEach will be the same as the one printed by peek. Both - peek and forEachOrder - may print the characters in any order.24. Question: Assuming that the directory /works/ocpjp/code exists but /works/ocpjp/code/sample does not exist, what will the following code output? Path d1 = Paths.get("/works"); Path d2 = d1.resolve("ocpjp/code"); //1 d1.resolve("ocpjp/code/sample"); //2 d1.toAbsolutePath(); //3 System.out.println(d1); System.out.println(d2);Select 1 option(s): 25. Question: Consider the following code :import java.util.*;class Request { }class RequestCollector{ //1 : Insert declaration here public synchronized void addRequest(Request r){ container.add(r); } public synchronized Request getRequestToProcess(){ return container.poll(); }}What can be inserted at //1?Select 1 option(s): Queue< Request > container = new LinkedList< Request >(); LinkedList container = new LinkedList(); Queue container = new PriorityQueue(); Queue< Request > container = new Queue< Request >(); List al = new ArrayList(); None of these.26. Question: What will the following code print when compiled and run? public class Data{ int value; Data(int value){ this.value = value; } public String toString(){ return ""+value; } public static void main(String[] args) { Data[] dataArr = new Data[]{ new Data(1), new Data(2), new Data(3), new Data(4) }; List<Data> dataList = Arrays.asList(dataArr); //1 for(Data element : dataList){ dataList.removeIf( (Data d) -> { return d.value%2 == 0; } ); //2 System.out.println("Removed "+d+", "); //3 } } }Select 1 option(s): Removed 2, Removed 4 It will print Removed 2 and then an exception stack trace. It will print an exception stack trace. It will not compile due to //1 It will not compile due to //2 It will not compile due to //327. Question: Identify the correct statement(s).Select 2 option(s): To customize the behavior of class serialization, the readObject and writeObject methods should be implemented. To customize the behavior of class serialization, the defaultReadObject and defaultWriteObject methods should be overridden. Objects of a final class cannot be serialized. Constructor of the class for an object being deserialized is never invoked. While serializing an object, only those objects in the object graph that implement Serializable are serialized and the rest are ignored.28. Question: Java's Exception mechanism helps in which of the following ways? Select 2 option(s): It allows creation of new exceptions that are custom to a particular application domain. It improves code because error handling code is clearly separated from the main program logic. It enhances the security of the application by reporting errors in the logs. It improves the code because the exception is handled right at the place where it occured. It provides a vast set of standard exceptions that covers all possible exceptions.29. Question: What can be inserted in the following code so that it will print exactly 2345 when compiled and run? public class FlowTest { static int[] data = {1, 2, 3, 4, 5}; public static void main(String[] args) { for (var i : data) { if (i < 2) { //insert code1 here } System.out.print(i); if (i == 3) { //insert code2 here } } }}Select 2 option(s): break; and//nothing is required continue; and//nothing is required continue;and continue; break;andcontinue; break; andbreak;30. Question: You want to invoke the overridden method (the method in the base class) from the overriding method (the method in the derived class) named m().Which of the following constructs which will let you do that?Select 1 option(s): super.m(); super.this(); base.m(); parent.m(); super();31. Question: Which lines contain a valid constructor in the following code?public class TestClass{public TestClass(int a, int b) { } // 1public void TestClass(int a) { } // 2public TestClass(String s); // 3private TestClass(String s, int a) { } //4 public TestClass(String s1, String s2) { }; //5 }Select 3 option(s): Line // 1 Line // 2 Line // 3 Line // 4 Line // 532. Question: Identify correct statements about the module system of Java.Select 3 option(s): Every module must reside in a directory of its own. A module can specify packages as well as services. Modular JDK is helpful in improving performance of an application. Modules allow service implementations to be hooked up with service users through dependency injection.33. Question: Which of the following declarations is equivalent to var b = 10>11;. Select 2 option(s): bool b = false; var b = false; var b = false|true; bool b = (10<11); boolean b = false;34. Question; Given:public class PlaceHolder<K, V> { //1 private K k; private V v; public PlaceHolder(K k, V v){ //2 this.k = k; this.v = v; } public K getK() { return k; } public static <X> PlaceHolder<X, X> getDuplicateHolder(X x){ //3 return new PlaceHolder<X, X>(x, x); //4 }}Which line will cause compilation failure?Select 1 option(s): 1 2 3 4 Some other unnumbered line. There is no problem with the code.35. Question: Given:package strings;public class StringFromChar { public static void main(String[] args) { String myStr = "good"; char[] myCharArr = {'g', 'o', 'o', 'd' }; String newStr = ""; for(char ch : myCharArr){ newStr = newStr + ch; } boolean b1 = newStr == myStr; boolean b2 = newStr.equals(myStr); System.out.println(b1+ " " + b2); }}What will it print when compiled and run?Select 1 option(s): true true true false false true false false36. Question: Identify the correct statements about the following code:import java.util.*;class Person { private static int count = 0; private String id = "0"; private String interest; public Person(String interest){ this.interest = interest; this.id = "" + ++count; } public String getInterest(){ return interest; } public void setInterest(String interest){ this.interest = interest; } public String toString(){ return id; }}public class StudyGroup{ String name = "MATH"; TreeSet<Person> set = new TreeSet<Person>(); public void add(Person p) { if(name.equals(p.getInterest())) set.add(p); } public static void main(String[] args) { StudyGroup mathGroup = new StudyGroup(); mathGroup.add(new Person("MATH")); System.out.println("A"); mathGroup.add(new Person("MATH")); System.out.println("B"); System.out.println(mathGroup.set); }}Select 1 option(s): It will print : A, B, and then the contents of mathGroup.set. It will compile with a warning. It will NOT throw an exception at runtime. It will compile without warning but will throw an exception at runtime. It will only print : A It will print : A and B.37. Question: Given:class Base{ public <T> List<T> transform(List<T> list) { return new ArrayList<T>(); }}class Derived extends Base{ *INSERT CODE HERE*}What can be inserted in the above code?Select 2 option(s): public ArrayList< Number > transform(List< Number > list) { return new ArrayList< Number >(); }; public ArrayList< Object > transform(List< Object > list) { return new ArrayList< Object >(); }; public < T > ArrayList< T > transform(List< T > list) {return new ArrayList< T >();}; public < T > Collection< T > transform(List< T > list) {return new ArrayList< T >(); }; public < T > Collection< T > transform(Collection< T > list) { return new HashSet< T >(); };38. Question: Which of the following method(s) of java.util.stream.Stream interface is/are used for reduction? Select 2 option(s): collect count distinct findAny findFirst39. Question: What should be placed in the two blanks so that the following code will compile without errors: class XXX{ public void m() { throw new RuntimeException(); }}class YYY extends XXX{ public void m() throws Exception{ throw new Exception(); }}public class TestClass { public static void main(String[] args) { ______ obj = new ______(); obj.m(); }}Select 1 option(s): XXX and YYY XXX and XXX YYY and YYY YYY and XXX None of the options will make the code compile.40. Question" What will the following code print? List<Integer> ls = Arrays.asList(1, 2, 3);Function<Integer, Integer> func = a->a*a; //1ls.stream().map(func).peek(System.out::print); //2Select 1 option(s): Compilation error at //1 Compilation error at //2 149 123 It will compile and run fine but will not print anything.41. Question: Identify the correct statements about ArrayList?Select 3 option(s): ArrayList extends java.util.AbstractList. It allows you to access its elements in random order. You must specify the class of objects you want to store in ArrayList when you declare a variable of type ArrayList. ArrayList does not implement RandomAccess. You can sort its elements using Collections.sort() method.42. Question: What is wrong with the following code written in a single file named TestClass.java? class SomeThrowable extends Throwable { }class MyThrowable extends SomeThrowable { }public class TestClass{ public static void main(String args[]) throws SomeThrowable{ try{ m1(); }catch(SomeThrowable e){ throw e; }finally{ System.out.println("Done"); } } public static void m1() throws MyThrowable{ throw new MyThrowable(); }}Select 1 option(s): The main declares that it throws SomeThrowable but throws MyThrowable. You cannot have more than 2 classes in one file. The catch block in the main method must declare that it catches MyThrowable rather than SomeThrowable. There is nothing wrong with the code and Done will be printed.43. Question: Which of the following statements regarding java.util.HashSet is correct? Select 1 option(s): It keeps the elements in a sorted order. It allows duplicate elements because it is based on HashMap. It stores name-value pairs. The order of elements seen while iterating through a HashSet always remains same. It allows null value to be stored.44. Question: What will be the result of attempting to compile and run the following code? class SwitchTest{ public static void main(String args[]){ for ( var i = 0 ; i < 3 ; i++){ //1 var flag = false; switch (i){ //2 flag = true; //3 } if ( flag ) System.out.println( i ); } }}Select 1 option(s): It will print 0, 1 and 2. It will not print anything. Runtime error. Compilation error at line marked //1. Compilation error at line marked //2. Compilation error at line marked //3.45. Question: What will the following code print? int[] ia1 = { 0, 1, 4, 5}; int[] ia2 = { 0, 1, 1, 5, 6}; int x = Arrays.compare(ia1, ia2); int y = Arrays.mismatch(ia1, ia2); System.out.println(x+" "+y);Select 1 option(s): 1 2 2 2 1 3 -1 2 -1 -246. Question: Given:public class Book { private String title; private String genre; public Book(String title, String genre){ this.title = title; this.genre = genre; } //accessors not shown}and the following code:List<Book> books = Arrays.asList( new Book("Gone with the wind", "Fiction"), new Book("Bourne Ultimatum", "Thriller"), new Book("The Client", "Thriller"));Reader r = b->{ System.out.println("Reading book "+b.getTitle()); };books.forEach(x->r.read(x));What would be a valid definition of Reader for the above code to compile and run without any error or exception?Select 2 option(s): abstract class Reader{abstract void read(Book b); } abstract class Reader{ void read(Book b);} @FunctionalInterface interface Reader{void read(Book b);default void unread(Book b){ } } interface Reader{ default void read(Book b){ }void unread(Book b); private void doSomethingelse(){ }} @FunctionalInterfaceinterface Reader{ default void read(Book b){ System.out.println("Default read");}; }47. Question: What will the following code print? AtomicInteger ai = new AtomicInteger();Stream<Integer> stream = Stream.of(11, 11, 22, 33).parallel();stream.filter( e->{ ai.incrementAndGet(); return e%2==0;});System.out.println(ai);Select 1 option(s): 0 Any number between 1 to 4. 4 Any number between 0 to 348. Question: What will be printed when the following code is compiled and run? package trywithresources;import java.io.IOException;public class Device implements AutoCloseable{ String header = null; public void open(){ header = "OPENED"; System.out.println("Device Opened"); } public String read() throws IOException{ throw new IOException("Unknown"); } public void writeHeader(String str) throws IOException{ System.out.println("Writing : "+str); header = str; } public void close(){ header = null; System.out.println("Device closed"); } public static void testDevice(){ try(Device d = new Device()){ d.open(); d.writeHeader("TEST"); d.close(); }catch(IOException e){ System.out.println("Got Exception"); } } public static void main(String[] args) { Device.testDevice(); } }Select 1 option(s): Device Opened Device closedGot Exception Device Opened Writing : TEST Device closedDevice closed Device OpenedWriting : TEST Device closedGot Exception Device Opened Writing : TESTDevice closedDevice closedGot Exception Device OpenedWriting : TESTDevice closedDevice closed(an exception stack trace)49. Question: Consider the following class...public class ParamTest { public static void printSum(int a, int b){ System.out.println("In int "+(a+b)); } public static void printSum(Integer a, Integer b){ System.out.println("In Integer "+(a+b)); } public static void printSum(double a, double b){ System.out.println("In double "+(a+b)); } public static void main(String[] args) { printSum(1, 2); }}What will be printed?Select 1 option(s): In int 3 In Integer 3 In double 3.0q In double 3 It will not compile.50. Question: Consider the following method: static int mx(int s){ for(int i=0; i<3; i++){ s = s + i; } return s; }and the following code snippet: int s = 5; s += s + mx(s) + ++s; System.out.println(s);What will it print?Select 1 option(s): 21 22 23 24 25 2651. Question: A user thread of a GUI application needs to perform certain security sensitve operations upon receiving system events. For this purpose, a call back handler has been registered with the system by the user thread based upon inputs from the GUI. The operations should be executed only if the user has appropriate permissions as per the security policy.The following code shows the call back handler:public class ProtectedCallbackHandler implements Runnable{ final String action; public ProtectedCallbackHandler(String action){ this.action = action; } public void run(){ AccessController.doPrivileged( new PrivilegedAction<Void>() { public Void run() { //Do sensitive operations based upon action value return null; } }); }}Identify correct statements.Select 1 option(s): The call back handler is not coded correctly because it does not check the priviledeges associated with the user. The call back handler is not coded correctly because it doesn't check any specific priviledeges required for the operation. The call back handler approach will fail because system call back handlers are always executed with full permissions. The call back handler is coded correctly and will work as expected.52. Question: What will the following code print when run? LocalDate d = LocalDate.now(); DateFormat df = new DateFormat(DateFormat.LONG); System.out.println(df.format(d));Select 1 option(s): It will print current date in LONG format. It will print the number of milliseconds since 1 Jan 1970. It will not compile. It will throw an exception at runtime.53. Question: Consider the following code:class MyClass { }public class TestClass{ MyClass getMyClassObject(){ MyClass mc = new MyClass(); //1 return mc; //2 } public static void main(String[] args){ TestClass tc = new TestClass(); //3 MyClass x = tc.getMyClassObject(); //4 System.out.println("got myclass object"); //5 x = new MyClass(); //6 System.out.println("done"); //7 }}After what line the MyClass object created at line 1 will be eligible for garbage collection?Select 1 option(s): 2 5 6 7 Never till the program ends.54. Question: Given:Locale locale = new Locale("en", "US");ResourceBundle rb = ResourceBundle.getBundle("test.MyBundle", locale);Which of the following are valid lines of code?(Assume that the ResourceBundle has the values for the given keys.)Select 2 option(s): String obj = rb.getObject("key1"); Object obj = rb.getObject("key1"); String[] vals = rb.getStringArray("key2"); Object obj = rb.getValue("key3"); Object obj = rb.getObject(1);55. Question: Consider the following code:public class Student {private Map<String, Integer> marksObtained = new HashMap<String, Integer>();private ReadWriteLock lock = new ReentrantReadWriteLock();public void setMarksInSubject(String subject, Integer marks){ // valid code to set marks for a given subject }public double getAverageMarks(){ //1 - INSERT CODE HERE var sum = 0.0; try{for(Integer mark : marksObtained.values()){sum = sum + mark; }return sum/marksObtained.size(); }finally{//2 - INSERT CODE HERE}}} What should be inserted at //1 and //2?Select 1 option(s): lock.lock(); andlock.unlock(); lock.readLock();and lock.readUnlock(); lock.read();andlock.unlock(); lock.readLock().lock();and lock.readLock().unlock();56. Question: Given:public class Book { private String title; private LocalDate releaseDate; public Book(String title, LocalDate releaseDate){ this.title = title; this.releaseDate = releaseDate; } //accessors not shown}and the following code:var books = new ArrayList<Book>(List.of(new Book("The Outsider", LocalDate.of(2019, 1, 1)), new Book("Becoming", LocalDate.of(2018, 1, 1)),new Book("Uri", LocalDate.of(2017, 1, 1))));Predicate<Book> p = b->b.getReleaseDate().isAfter(IsoChronology.INSTANCE.date(2018, 1, 1));Set<String> newBooks = books.stream(). INSERT CODE HEREWhat can be inserted in the code above so that newBooks will be assigned a set of books that were released after the date indicated by the predicate p?Select 3 option(s): .collect(Collectors.partitioningBy(p)).get(true).stream().map(Book::getTitle).collect(Collectors.toCollection(TreeSet::new)); .collect(Collectors.partitioningBy(p)) .get(true).stream().map(Book::getTitle).collect(Collectors.toSet()); .collect(Collectors.partitioningBy(p, Collectors.mapping(Book::getTitle, Collectors.toSet()))); .collect(Collectors.groupingBy(p, Collectors.mapping(Book::getTitle, Collectors.toSet()))); .collect(Collectors.filtering(p, Collectors.mapping(Book::getTitle, Collectors.toSet())));57. Question: What will the following code print when compiled and run? var tickers = List.of("A", "D", "E", "C", "A");var ratio = List.of(1.0, 1.2, 1.5, 1.8, 2.0);var map1 = IntStream.range(0, tickers.size()) .boxed() .collect(Collectors.toMap( i -> tickers.get(i), i -> 1.0/ratio.get(i), (x, y) -> x+y)) ; //<<----- LINE 1var map2 = map1.entrySet().stream().sorted(Map.Entry.comparingByKey()) .collect( Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue, (x, y) -> x-y, LinkedHashMap::new) ); //<<----- LINE 2map2.forEach((var k, var v)->System.out.printf("%s = %.2f\n",k, v));Select 1 option(s): A = 1.50C = 0.56 D = 0.83 E = 0.67 E = 0.67D = 0.83C = 0.56A = 1.50 exception at line 1. exception at line 2. A = 1.50D = 0.83E = 0.67C = 0.56 A = 1.50Time is Up!