Java Programming Fundamentals
Test your knowledge of Java programming concepts including exception handling, threading, string manipulation, reflection, and AWT.
Questions
How long does the following code run? for(int x=0; x=3; x++)
- Never
- Three times
- Forever
- Error
Any class that implements the Runnable interface has to provide the implementation for the following methods public void start(); public void run();
- True
- False
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"); }
- output Positive infinity
- output Negative infinity
- Will fail to compile
- Runtime exception
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); }
- 2
- 0
- 3
- 2.5
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); }
- Compiler error.
- Compiles and runs printing out 2
- Compiles and runs printing out 1
- An ArrayIndexOutOfBounds Exception at runtime
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); } }
- . Compiler error.
- Will throw a NoSuchMethod error at runtime.
- It will compile and run printing out "10"
- It will run with no output.
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)); } }
- -23
- -22.0
- 22.0
- 24
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.
- True
- False
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));
- false false false dar
- false true false Poddar
- Compiler Error
- true true FALSE dar
Identify whether the following statement is true or false.
The keyword synchronized can be used with only a method
- True
- False
Identify whether the following statement is true or false.
The run () method should necessary exist in classes created as subclass of Thread
- True
- False
What is the purpose of the toolkit in the Abstract Window Toolkit (AWT)?
- To repair broken frames
- To create custom components
- An interface between the abstract window layer and windowing implementation
- To facilitate multicolor printing
What is an interface class?
- A collection of method declarations and constant values
- An abstract base class
- A way to get multiple inheritance
- A way to inherit variables and method implementations
Vertical and horizontal scroll bar increments are how many units by default?
- 12.5 units
- 100 units
- 5 units
- 1 unit
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?
- Late binding
- Early binding
- Java developers are very introspective people
- Reflection is possible in all languages
The StringBuffer class supports what type of strings?
- Mutable (changeable)
- Immutable (unchangeable)
- Violins and cellos
- Rotated and scaled
Why does an Assert class that checks program assertions need several implementations of its assert method?
- The Java language has loose type checking
- The Java language has tight type checking
- To keep tabs on garbage collection
- You never know how many you need, so you should always cover the most obvious cases
Handling an exception allows a program to terminate execution
- True
- False
Java's exception handling mechanism keeps error-processing code in the main line of a program's code to improve program clarity.
- True
- False
Identify the correct examples of Exception
- Divide by zero error
- Accessing the elements of an array beyond its range
- Invalid input
- Opening an empty file
- Hard disk crash