Java Programming Fundamentals

Test your knowledge of Java programming concepts including OOP, multithreading, exceptions, assertions, JDBC, and language syntax

20 Questions Published

Questions

Question 1 True/False

finalize method is used to release system resources.

  1. True
  2. False
Question 2 True/False

A local variable in a block may be re-declared in another local block, if the blocks are disjoint.

  1. True
  2. False
Question 3 True/False

All loops are controlled by a boolean expression.

  1. True
  2. False
Question 4 True/False

switch can be nested.

  1. True
  2. False
Question 5 Multiple Choice (Single Answer)

Which type of Statements can execute parameterized queries?

  1. PreparedStatement
  2. ) ParameterizedStatement
  3. ) ParameterizedStatement and CallableStatement
  4. All the above
Question 6 True/False

A method can not have the same name as another method in the same class.

  1. True
  2. False
Question 7 True/False

Constructors can have a return type.

  1. True
  2. False
Question 8 True/False

Any class that implements the Runnable interface has to provide the implementation for the following methods public void start(); public void run();

  1. True
  2. False
Question 9 True/False

A thread that has called the wait() method of an object still owns the lock of the object.

  1. True
  2. False
Question 10 True/False

If you call the interrupted() method of a thread object twice the second call will always return false.

  1. True
  2. False
Question 11 Multiple Choice (Single Answer)

A number of threads of the same priority have relinquished the lock on a monitor and are in a waiting state after having called the wait() method of the object. A new thread enters the monitor and calls the notifyAll() method of the meonitor. Which of these threads will be the first one to resume?

  1. The thread that has been waiting the longest.
  2. The thread that was the last one to to exit the monitor.
  3. You can never be sure which thread will get to run first.
  4. The the first thread that called the wait() method
Question 12 Multiple Choice (Multiple Answers)

Which of these are valid contructors of a Thread object.

  1. public Thread(Object obj)
  2. public Thread(String name)
  3. public Thread(Runnable trgt)
  4. public Thread(ThreadGroup grp, Runnable trgt, String name)
  5. public Thread(ThreadGroup grp, Object ob)
Question 13 Multiple Choice (Single Answer)

class Line { Line 1. public class Point { public int x,y; } Line 2. public Point getPoint() { return new Point(); } Line 3. } Line 4. class Triangle { Line 5. public Triangle() { Line 6. // insert code here Line 7. } 18. } Which code, inserted at line Line 6, correctly retrieves a local instance of a Point object? A. Point p = Line.getPoint(); B. Line.Point p = Line.getPoint(); C. Point p = (new Line()).getPoint(); D. Line.Point p = (new Line()).getPoint();

  1. A
  2. B
  3. C
  4. D
Question 14 Multiple Choice (Multiple Answers)

public class test { Line 1. public static void main(String [] a) { Line 2. assert a.length == 1; Line 3. } Line 4. } Which two will produce an AssertionError? (Choose two.) A. java test B. java -ea test C. java test file1 D. java -ea test file1 E. java -ea test file1 file2 F. java -ea:test test file1

  1. AB
  2. BC
  3. AE
  4. BE
Question 15 Multiple Choice (Single Answer)

Given a method that must ensue that its parameter is not null: Line 1. public void someMethod(Object value) { Line 2. // check for null value Line 3. System.out.println(value.getClass()); Line 4. } What, inserted at line 2, is the appropriate way to handle a null value? A. assert value == null; B. assert value !null, “value is null”; C. if (value == null) { throw new AssertionException(”value is null”); D. if (value == null) { throw new IllegalArgumentException(”value is null”);

  1. A
  2. B
  3. C
  4. D
Question 16 Multiple Choice (Single Answer)

Line 1. public class ClassA { Line 2. public void count(int i) { Line 3. count(++i); Line 4. } Line 5. } And: Line 6. ClassA a = new ClassA(); Line 7. a.count(3); Which exception or error should be thrown by the virtual machine? A. StackOverflowError B. NullPointerException C. NumberFormatException D. IllegalArgumentException E. ExceptionlnlnitializerError

  1. A
  2. B
  3. C
  4. D
Question 17 Multiple Choice (Single Answer)

public class Foo implements java.io.Serializable { Line1. private int x; Line2. public int getX() { return x; } Line 3.publicFoo(int x){this.x=x; } Line 4. private void writeObject( ObjectOutputStream s) Line 5. throws IOException { Line 6. // insert code here Line 7. } Line 8. } Which code fragment, inserted at line Line 6, will allow Foo objects to be correctly serialized and deserialized? A. s.writeInt(x); B. s.serialize(x); C. s.writeObject(x); D. s.defaultWriteObject();

  1. A
  2. B
  3. C
  4. D
Question 18 Multiple Choice (Single Answer)

Which declare a compilable abstract class? (Choose all that apply.)

  1. public abstract class Canine { public Bark speak(); }
  2. public abstract class Canine { public Bark speak() { } }
  3. public class Canine { public abstract Bark speak(); }
  4. public class Canine abstract { public abstract Bark speak(); }
Question 19 Multiple Choice (Single Answer)

Which is true? (Choose all that apply. )

  1. X extends Y is correct if and only if X is a class and Y is an interface.
  2. X extends Y is correct if and only if X is an interface and Y is a class.
  3. X extends Y is correct if X and Y are either both classes or both interfaces.
  4. X extends Y is correct for all combinations of X and Y being classes and/or interfaces.
Question 20 Multiple Choice (Multiple Answers)

Which method names follow the JavaBeans standard? (Choose all that apply.)

  1. addSize
  2. getCust
  3. deleteRep
  4. isColorado
  5. putDimensions