Java Programming Fundamentals
Test your knowledge of Java programming concepts including OOP, multithreading, exceptions, assertions, JDBC, and language syntax
Questions
finalize method is used to release system resources.
- True
- False
A local variable in a block may be re-declared in another local block, if the blocks are disjoint.
- True
- False
All loops are controlled by a boolean expression.
- True
- False
switch can be nested.
- True
- False
Which type of Statements can execute parameterized queries?
- PreparedStatement
- ) ParameterizedStatement
- ) ParameterizedStatement and CallableStatement
- All the above
A method can not have the same name as another method in the same class.
- True
- False
Constructors can have a return type.
- True
- False
Any class that implements the Runnable interface has to provide the implementation for the following methods public void start(); public void run();
- True
- False
A thread that has called the wait() method of an object still owns the lock of the object.
- True
- False
If you call the interrupted() method of a thread object twice the second call will always return false.
- True
- False
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?
- The thread that has been waiting the longest.
- The thread that was the last one to to exit the monitor.
- You can never be sure which thread will get to run first.
- The the first thread that called the wait() method
Which of these are valid contructors of a Thread object.
- public Thread(Object obj)
- public Thread(String name)
- public Thread(Runnable trgt)
- public Thread(ThreadGroup grp, Runnable trgt, String name)
- public Thread(ThreadGroup grp, Object ob)
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();
- A
- B
- C
- D
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
- AB
- BC
- AE
- BE
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”);
- A
- B
- C
- D
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
- A
- B
- C
- D
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();
- A
- B
- C
- D
Which declare a compilable abstract class? (Choose all that apply.)
- public abstract class Canine { public Bark speak(); }
- public abstract class Canine { public Bark speak() { } }
- public class Canine { public abstract Bark speak(); }
- public class Canine abstract { public abstract Bark speak(); }
Which is true? (Choose all that apply. )
- X extends Y is correct if and only if X is a class and Y is an interface.
- X extends Y is correct if and only if X is an interface and Y is a class.
- X extends Y is correct if X and Y are either both classes or both interfaces.
- X extends Y is correct for all combinations of X and Y being classes and/or interfaces.
Which method names follow the JavaBeans standard? (Choose all that apply.)
- addSize
- getCust
- deleteRep
- isColorado
- putDimensions