Q1. Given: Which of the four are valid modifications to synchronize access to the valid list between threads t1 and t2? A. Replace line 1 with: Synchronized (t2) (t1.start();) synchronized(t1) (t2.start(); ) korrekte Schreibweise: synchronized (t2) {t1.start();} synchronized(t1) { t2.start();} B. Replace Line 2 with: static CopyWriteArrayList list = new CopyWriteArrayList(); korrekte Schreibweise: static CopyOnWriteArrayList list = new CopyOnWriteArrayList(); C. Replace line 3 with: synchronized public static void addItem…
Q1. Which code fragment is required to load a JDBC 3.0 driver? A. DriverManager.loadDriver ("org.xyzdata.jdbc.NetworkDriver"); B. Class.forName("org.xyzdata.jdbc-NetworkDriver"); C. Connection con = Connection.getDriver ("jdbc:xyzdata://localhost:3306/EmployeeDB"); D. Connection con = DriverManager.getConnection ("jdbc:xyzdata://localhost:3306/EmployeeDB"); View AnswerAnswer: B Explanation: In previous versions (prior to 4.0) of JDBC, to obtain a connection, you first had to initialize your JDBCdriver by calling the method Class.forName. This methods required an object of type java.sql.Driver. Note: DriverManager: This fully implemented class…
Q1. Given the Greetings.properties file, containing: What is the result? A. Compilation fails B. HELLO_MSG C. GOODGYE_NSG D. Hello, everyone! E. Goodbye everyone! View AnswerAnswer: A Explanation: The code will not compile. The problem is the following line: System.out.println(resource.getObject(1)); In particular getObject(1) throws the following error: Exception in thread "main" java.lang.RuntimeException: Uncompilable source code -Erroneous sym type: .loadResourceBundle Note:getObject(String key) !!! String keyGets an object for the given key from this resource bundle or one of…
Q1. Given the code fragment: What is the result? A. getName (0): C:\ subpath (0, 2): C:\education\report.txt B. getName(0): C:\ subpth(0, 2): C:\education C. getName(0): education subpath (0, 2): education\institute D. getName(0): education subpath(0, 2): education\institute\student E. getName(0): report.txt subpath(0, 2): insritute\student View AnswerAnswer: C Explanation: Example: Path path = Paths.get("C:\\home\\joe\\foo"); getName(0) -> home subpath(0,2) Reference: The Java Tutorial, Path Operations Q2. Given: From what threading problem does the program suffer? A. deadlock B. livelock C. starvation D. race condition View AnswerAnswer: B Explanation: A thread often…
Q1. Which four are true about enums? A. An enum is typesafe. B. An enum cannot have public methods or fields. C. An enum can declare a private constructor. D. All enums implicitly implement Comparable. E. An enum can subclass another enum. F. An enum can implement an interface. View AnswerAnswer: A,C,D,F Explanation: C: The constructor for an enum type must be package-private or private access. Reference: Java…
Q1. Given these facts about Java types in an application: -Type x is a template for other types in the application. -Type x implements dostuff (). -Type x declares, but does NOT implement doit(). -Type y declares doOther() . Which three are true? A. Type y must be an interface. B. Type x must be an abstract class. C. Type y must be an abstract class. D. Type x…