Welcome to your Foundation Test - 1 Code - 819 Name Email Phone 1. Question: Using a Callable would be more appropriate than using a Runnable in which of the following situations? Select 1 option(s): When you want to execute a task directly in a separate thread. When your task might throw a checked exception and you want to execute it in a separate Thread. When your task does not return any result but you want to execute the task asynchronously. When you want to use ExecutorService to submit multiple instances of a task.2. Question: How can you declare a method someMethod() such that an instance of the class is not needed to access it and all the members of the same package have access to it. Select 3 option(s): public static void someMethod() static void someMethod() protected static void someMethod() void someMethod() protected void someMethod() public abstract static void someMethod()3. Question: Given that a code fragment has just created a JDBC Connection and has executed an update statement, which of the following statements is correct? Select 1 option(s): Changes to the database are pending a commit call on the connection. Changes to the database will be rolled back if another update is executed without commiting the previous update. Changes to the database will be committed right after the update statement has completed execution. Changes to the database will be committed when another query (update or select) is fired using the connection.4. Question: Which of the following are valid command line options and their one character shortcuts related to the Java module system? Select 2 option(s): --module -p --module-path -p --module-source-path -s ---module-source-path -m --list-modules -l --show-module-resolution -s --module -m5. Question: Which of the following statements concerning the switch construct are true? Select 3 option(s): A character literal can be used as a value for a case label. A 'long' cannot be used as a switch variable. An empty switch block is a valid construct. A switch block must have a default label. If present, the default label must be the last of all the labels.6. Question: Which of these statements concerning nested classes and interfaces are true? Select 3 option(s): An instance of a static nested class has an inherent outer instance. A static nested class can contain non-static member variables. A static nested interface can contain static member variables. A static nested interface has an inherent outer instance associated with it. For each instance of the outer class, there can exist many instances of a non-static inner class.7. Question: Which of the following is a legal return type of a method overriding the given method: public Object myMethod() {...}Select 1 option(s): Object String Return type can be any class since all objects can be cast to Object. void None of the above.8. Question: Which of the following annotations are retained for run time? Select 3 option(s): @SuppressWarnings @Override @SafeVarargs @FunctionalInterface @Deprecated9. Question: Using a continue in a while loop causes the loop to break the current iteration and start the next iteration of the loop. Select 1 option(s): True False10. Question: Given the following code, which statements are true?class A{ int i;}class B extends A{ int j;}Select 3 option(s): Class B extends class A. Class B is the superclass of class A. Class A inherits from class B. Class B is a subclass of class A. Objects of class B will always have a member variable named i .11. Question: Which of the following statements are correct regarding a functional interface? Select 1 option(s): It has exactly one method and it must be abstract. It has exactly one method and it may or may not be abstract. It must have exactly one abstract method and may have other default or static methods. It must have exactly one static method and may have other default or abstract methods.12. Question: Which of the following statements are true? Select 3 option(s): The condition expression in an if statement can contain method calls. If a and b are of type boolean, the expression (a = b) can be used as the condition expression of an if statement. An if statement can have either an 'if' clause or an 'else' clause. The statement : if (false) ; else ; is illegal. Only expressions which evaluate to a boolean value can be used as the condition in an if statement.13. Question: An anonymous class can be declared in a static method. Select 1 option(s): True False14. Question: Consider the following class:public class Test{ public int id; } Which of the following is the correct way to make the variable 'id' read only for any other class?Select 1 option(s): Make 'id' private. Make 'id' private and provide a public method getId() which will return its value. Make 'id' static and provide a public static method getId() which will return its value. Make id 'protected'15. Question: Which of these methods are defined in the Map interface? Select 2 option(s): contains(Object o) addAll(Collection c) remove(Object o) values( ) toArray( )16. Question: Which of these statements concerning interfaces are true? Select 2 option(s): An interface may extend an interface. An interface may extend a class and may implement an interface. A class can implement an interface and extend a class. A class can extend an interface and can implement a class. An interface can only be implemented and cannot be extended. All methods of an interface are public and abstract.17. Question: A try without resources statement must always have a ............. associated with it.Select 1 option(s): catch throws finally catch or finally or both throw18. Question: Which statements concerning the relation between a non-static inner class and its outer class instances are true? Select 3 option(s): Member variables of the outer instance are always accessible to inner instances, regardless of their accessibility modifiers. Member variables of the outer instance can always be referred to using only the variable name within the inner instance. More than one inner instance can be associated with the same outer instance. An inner class can extend its outer class. A final outer class cannot have any inner classes.19. Question: You are implementing a special sorting algorithm that can sort objects of different classes. Which of the following class declarations will you use? Select 1 option(s): public class SpecialSorter<>{...} public class SpecialSorter< K >{ ...} public class < SpecialSorter >{... } public class SpecialSorter(K){... }20. Question: Which of the following statements regarding inner classes are true ? Select 3 option(s): A non static inner class may have static members. Anonymous inner classes cannot have any 'extends' or 'implements' clause. Anonymous inner classes can only be created for interfaces. Anonymous inner classes can never have initialization parameters. Anonymous inner classes cannot be static.21. Question: Which statements concerning conversion are true? Select 4 option(s): Conversion from char to long does not need a cast. Conversion from byte to short does not need a cast. Conversion from short to char needs a cast. Conversion from int to float needs a cast. Conversion from byte, char or short to int, long, or float does not need a cast.22. Question: Which of the following statements are correct? Select 1 option(s): A List stores elements in a sorted order. A Set keeps the elements sorted and a List keeps the elements in the order they were added. A SortedSet keeps the elements in the order they were added. An OrderedSet keeps the elements sorted. An OrderedList keeps the elements ordered. A NavigableSet keeps the elements sorted.23. Question: What will the following code print?void crazyLoop(){ var c = 0; JACK: while (c < 8){ JILL: System.out.println(c); if (c > 3) break JACK; else c++; } }Select 1 option(s): It will not compile. It will throw an exception at runtime. It will print numbers from 0 to 8 It will print numbers from 0 to 3 It will print numbers from 0 to 424. Question: Which of the following are true about a try/catch statement? Select 1 option(s): If it has multiple catch blocks, then they must be ordered from most specific exception to most generic exception. A try block must have at least a catch or a finally block. In a try-with-resources statement, the finally block is invoked before the resources are closed. A try can have multiple finally blocks.25. Question: Which of these statements concerning the charAt() method of the String class are true? Select 2 option(s): The charAt( ) method can take a char value as an argument. The charAt( ) method returns a Character object. The expression char ch = "12345".charAt(3) will assign 3 to ch. The expression char ch = str.charAt(str.length()) where str is "12345", will assign 3 to ch. The index of the first character is 0. It throws StringIndexOutOfBoundsException if passed a value higher than or equal to the length of the string (or less than 0). It throws ArrayIndexOutOfBoundsException if passed a value higher than or equal to the length of the string (or less than 0).26. Question: Which of the following is/are valid functional interfaces? Select 1 option(s): interface F{ default void m(){ } } interface F{default void m(){ } static void n(){ }} interface F{ void m(); void n(); } interface F{ default void m(){ } abstract void n();} interface F{ void m(){ }}27. Question: Which of these combinations of switch expression types and case label value types are legal within a switch statement? Select 1 option(s): switch expression of type int and case label value of type char. switch expression of type float and case label value of type int. switch expression of type byte and case label value of type float. switch expression of type char and case label value of type byte. switch expression of type boolean and case label value of type boolean.28. Question: Which clause(s) are used by a module definition that uses a service? Select 2 option(s): exports provides uses implements requires29. Question: The following code snippet will print 'true'.short s = Short.MAX_VALUE;char c = s;System.out.println( c == Short.MAX_VALUE);Select 1 option(s): True False30. Question: Compared to public, protected, and private accessibilities, default accessibility is....Select 1 option(s): Less restrictive than public. More restrictive than public, but less restrictive than protected. More restrictive than protected, but less restrictive than private. More restrictive than private. Less restrictive than protected from within a package, and more restrictive than protected from outside a package.31. Question: Which of the following are wrapper classes for primitive types? Select 1 option(s): java.lang.String java.lang.Void java.lang.Null java.lang.Object None of the above32. Question: Which of the following are NOT valid operators in Java? Select 4 option(s): sizeof <<< instanceof mod equals33. Question: Which of these statements are valid when occurring by themselves in a method? Select 3 option(s): while ( ) break ; do { break ; } while (true) ; if (true) { break ; } (When not inside a switch block or a loop) switch (1) { default : break; } for ( ; true ; ) break ;34. Question: Which of these statements concerning the use of modifiers are true? Select 1 option(s): By default (i.e. no modifier) the member is only accessible to classes in the same package and subclasses of the class. You cannot specify visibility of local variables. Local variable always have default accessibility. Local variables can be declared as private. Local variables can only be declared as public.35. Question: Code that uses generic collection classes can interoperate with code that uses raw collections classes because of?Select 1 option(s): type erasure reification just in time compilation byte code instrumentation36. Question: Which of the following standard functional interfaces is most suitable to process a large collection of int primitives and return processed data for each of them? Select 1 option(s): Function< Integer > IntFunction Consumer< Integer > IntConsumer Predicate< Integer >37. Question: Which of the following statements are true? Select 2 option(s): A nested class may be declared static. Anonymous inner class may be declared public. Anonymous inner class may be declared private. Anonymous inner class may be declared protected. Anonymous inner class may extend an abstract class.38. Question: Which of the following statements regarding 'break' and 'continue' are true? Select 1 option(s): break without a label can occur only in a switch, while, do, or for statement. continue without a label can occur only in a switch, while, do, or for statement. break can never occur without a label. continue can never occur WITH a label. None of the above.39. Question: Consider the following directory structure and the files contained in the directories:c:\javatest +- <src> +- <foo.bar> +- <foo> +- <bar> -- BazA.java -- BazB.javaAssuming that the package name specified in BazA and BazB is foo.bar, which of the following statements are correct?Select 1 option(s): There should be a module-info.java file in the src directory for it to be a valid module definition. The foo.bar directory is a valid source module definition. There should be a module-info.java file in the foo.bar directory for it to be a valid source module definition. There should be a module.java file in the foo directory for it to be a valid module definition. There should be a module-info.java file in the bar directory for it to be a valid source module definition. There should be a module.java file in the foo.bar directory for it to be a valid module definition.40. Question: Which of the following statements are true? Select 1 option(s): Non-static nested classes must have either default or public accessibility. Non-static nested classes cannot contain static members. Methods in all nested classes can be declared static. All nested classes can be declared static. A static nested class can contain a non - static inner class.41. Question: Which of these implementations for collection framework interfaces are provided in the standard JDK? Select 3 option(s): TreeMap ArrayMap HashSet ArrayList42. Question: What will the following program print when run? public class TestClass{ public static void main(String[] args){ try{ System.exit(0); } finally{ System.out.println("finally is always executed!"); } }}Select 1 option(s): It will print "finally is always executed!" It will not compile as there is no catch block. It will not print anything. An exception will be thrown None of the above.43. Question: Given that TestClass is a class, how many objects and reference variables are created by the following code?TestClass t1, t2, t3, t4;t1 = t2 = new TestClass();t3 = new TestClass();Select 1 option(s): 2 objects, 3 references. 2 objects, 4 references. 3 objects, 2 references. 2 objects, 2 references. None of the above.44. Question: Identify the correct statement regarding a JDBC Connection:Select 1 option(s): When a JDBC Connection is created, it is in auto-commit mode. When a JDBC Connection is created, its commit mode depends on the parameters used while creating the connection. When a JDBC Connection is created, its auto-commit feature is disabled. When a JDBC Connection is created, its commit mode is undetermined.45. Question: You have been given an instance of an Executor and you use that instance to execute tasks. How many threads will be created for executing these tasks by the Executor? Select 1 option(s): Exactly 1. One thread for each task that is submitted to the Executor. As many as there are cores in the CPU. Number of threads created by the Executor depends on how the Executor instance was created. Number of threads is automatically determined based on the load on the Executor instance.46. Question: You have a method that currently does not handle any exception thrown from the code contained in its method body. You are now changing this method to call another method that throws IOException.What changes, independent of each other, can you make to your method so that it will compile?Select 2 option(s): Set the exception to null and don't rethrow it. Declare IOException in the throws clause of your method. Wrap the call to another method within a try-catch block that catches RuntimeException. Wrap the call to another method within a try-catch block that catches Exception.47. Question: Which of the following command line switches is required (independent of each other) to run a modular application stored in c:\modules\movies.jar? Select 3 option(s): -m c:\modules\movies.jar -p c:\modules\movies.jar -p c:\modules --path c:\modules\movies.jar --module-path c:\modules48. Question: Consider the following code:public static void main(String[] args) { int[] values = { 10, 30, 50 }; for( var val : values ){ var x = 0; while(x<values.length){ System.out.println(x+" "+val); x++; } } }How many times is 2 printed out in the output?Select 1 option(s): 0 1 2 349. Question: Is it possible to create arrays of length zero? Select 1 option(s): Yes, you can create arrays of any type with length zero. Yes, but only for primitive datatypes. Yes, but only for arrays of object references. Yes, and it is same as a null array. No, arrays of length zero do not exist in Java.50. Question: Which of the following statements are true? Select 2 option(s): The modulus operator % can only be used with integer operands. & can have integral as well as boolean operands. The arithmetic operators *, / and % have the same level of precedence. && can have integer as well as boolean operands. ~ can have integer as well as boolean operands.51. Question: What will the following code print? var rlock = new ReentrantLock(); var f1 = rlock.lock(); System.out.println(f1); var f2 = rlock.lock(); System.out.println(f2);Select 1 option(s): true true true false true It will not compile.52. Question: You want to execute your tasks after a given delay. Which ExecutorService would you use? Select 1 option(s): FixedDelayExecutorService TimedExecutorService DelayedExecutorService ScheduledExecutorService53. Question: What will the following code print? public class TestClass{ static char ch; static float f; static boolean bool; public static void main(String[] args){ System.out.print(f); System.out.print(" "); System.out.print(ch); System.out.print(" "); System.out.print(bool); }}Select 1 option(s): 0.0 false 0.0f false 0.0 0 false 0.0 true 0.0f true 0.0f 0 trueTime is Up!