Java Programming Fundamentals

Test your knowledge of Java programming concepts including exception handling, threading, string manipulation, reflection, and AWT.

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

How long does the following code run? for(int x=0; x=3; x++)

  1. Never
  2. Three times
  3. Forever
  4. Error
Question 2 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 3 Multiple Choice (Single Answer)

What is the result of trying to compile and run the following code. public final static void main(String[] args){ double d = 10.0 / -0; if(d == Double.POSITIVE_INFINITY) System.out.println("Positive infinity"); else System.out.println("Negative infinity"); }

  1. output Positive infinity
  2. output Negative infinity
  3. Will fail to compile
  4. Runtime exception
Question 4 Multiple Choice (Single Answer)

What is the result that will be printed out ? void aMethod() { float f = (1 / 4) * 10; int i = Math.round(f); System.out.println(i); }

  1. 2
  2. 0
  3. 3
  4. 2.5
Question 5 Multiple Choice (Single Answer)

What is the result that will be printed out ? void aMethod() { float f = (1 / 4) * 10; int i = Math.round(f); System.out.println(i); }

  1. Compiler error.
  2. Compiles and runs printing out 2
  3. Compiles and runs printing out 1
  4. An ArrayIndexOutOfBounds Exception at runtime
Question 6 Multiple Choice (Single Answer)

What will happen if you try to compile and run this ? public class Test{ static{ print(10); } static void print(int x){ System.out.println(x); System.exit(0); } }

  1. . Compiler error.
  2. Will throw a NoSuchMethod error at runtime.
  3. It will compile and run printing out "10"
  4. It will run with no output.
Question 7 Multiple Choice (Single Answer)

What is the value of d that will be printed out. public class Test { public final static void main(String[] args) { double d = - 22.22222; System.out.println(Math.ceil(d)); } }

  1. -23
  2. -22.0
  3. 22.0
  4. 24
Question 8 True/False

ZZZ (Duplicate) - Identify whether the following statement is true or false. The finally block is executed when an exception is thrown, even if no catch matches it.

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

ZZZ (Duplicate) - What is the output of the following, StringBuffer sb1 = new StringBuffer("Debopam"); StringBuffer sb2= new StringBuffer("Debopam "); String ss1 = " Debopam "; System.out.println(sb1==sb2); System.out.println(sb1.equals(sb2)); System.out.println(sb1.equals(ss1)); System.out.println("Poddar".substring(3));

  1. false false false dar
  2. false true false Poddar
  3. Compiler Error
  4. true true FALSE dar
Question 10 True/False

Identify whether the following statement is true or false.
The keyword synchronized can be used with only a method

  1. True
  2. False
Question 11 True/False

Identify whether the following statement is true or false.
The run () method should necessary exist in classes created as subclass of Thread

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

What is the purpose of the toolkit in the Abstract Window Toolkit (AWT)?

  1. To repair broken frames
  2. To create custom components
  3. An interface between the abstract window layer and windowing implementation
  4. To facilitate multicolor printing
Question 13 Multiple Choice (Single Answer)

What is an interface class?

  1. A collection of method declarations and constant values
  2. An abstract base class
  3. A way to get multiple inheritance
  4. A way to inherit variables and method implementations
Question 14 Multiple Choice (Single Answer)

Vertical and horizontal scroll bar increments are how many units by default?

  1. 12.5 units
  2. 100 units
  3. 5 units
  4. 1 unit
Question 15 Multiple Choice (Single Answer)

Reflection (introspection) is querying a class about its properties, and operating on methods and fields by the name for a given object instance. Why is reflection possible in the Java language?

  1. Late binding
  2. Early binding
  3. Java developers are very introspective people
  4. Reflection is possible in all languages
Question 16 Multiple Choice (Single Answer)

The StringBuffer class supports what type of strings?

  1. Mutable (changeable)
  2. Immutable (unchangeable)
  3. Violins and cellos
  4. Rotated and scaled
Question 17 Multiple Choice (Single Answer)

Why does an Assert class that checks program assertions need several implementations of its assert method?

  1. The Java language has loose type checking
  2. The Java language has tight type checking
  3. To keep tabs on garbage collection
  4. You never know how many you need, so you should always cover the most obvious cases
Question 18 True/False

Handling an exception allows a program to terminate execution

  1. True
  2. False
Question 19 True/False

Java's exception handling mechanism keeps error-processing code in the main line of a program's code to improve program clarity.

  1. True
  2. False
Question 20 Multiple Choice (Multiple Answers)

Identify the correct examples of Exception

  1. Divide by zero error
  2. Accessing the elements of an array beyond its range
  3. Invalid input
  4. Opening an empty file
  5. Hard disk crash