Objective Questions
Objective Questions
1) Unchecked exceptions are checked at compile-time rather they are checked at runtime.
a. True
b. False
ANSWER: False
2) Which method returns the interrupted flag after that it sets the flag to false if it is true?
a. isInterrupted()
b. static interrupted()
d. Both A & C
3) The PipedInputStream and PipedOutputStream classes can be used to read and write
data simultaneously.
a. True
b. False
ANSWER: True
c. An array knows only its type that it contains. Array type is checked at the compile-time
b. Encapsulation
c. Inheritance
ANSWER: Inheritance
a. True
b. False
ANSWER: True
7) Which constructor creates an empty string buffer with the specified capacity as length.
a. StringBuffer()
b. StringBuffer(String str)
c. StringBuffer(int capacity)
8) How many reserved keywords are currently defined in the Java language?
a. 48
b. 49
c. 50
d. 47
ANSWER: 49
9) Which mechanism is used when a thread is paused running in its critical section and
another thread is allowed to enter (or lock) in the same critical section to be executed?
a. Inter-thread communication
b. Initial-thread communication
c. Mutual Exclusive
11) Which class is used to uncompress the file in the deflate compression format, It
provides facility to the other uncompression filters?
a. DeflaterOutputStream class
b. InflaterInputStream class
c. Both A & B
12) Which is used for reading streams of raw bytes such as image data and for reading
streams of characters, consider using FileReader?
a. FileInputStream
b. FileOutputStream
c. Both A & B
ANSWER: FileInputStream
a. True
b. False
ANSWER: True
14) An exception is an event, which occurs during the execution of a program that disrupts
the normal flow of the program's instructions.
a. True
b. False
ANSWER: True
a. Thread Synchronization
b. Process Synchronization
c. Object Synchronization
16) Java application uses an output stream to read data from a source, it may be a file, an
array, peripheral device or socket.
a. True
b. False
ANSWER: False
17) Which is irrecoverable?
a. Error
b. Checked Exception
c. Unchecked Exception
d. Both B & C
ANSWER: Error
18) What is known as the classes that extend Throwable class except RuntimeException
and Error?
a. Checked Exception
b. Unchecked Exception
c. Error
19) A package can be renamed without renaming the directory in which the classes are
stored.
a. True
b. False
ANSWER: False
20) Daemon thread provides services to user threads for background supporting tasks,It
has no role in life than to serve user threads.
a. True
b. False
ANSWER: True
22) Which Exception occurs when a class is not found while dynamically loading a class
using the class loaders?
a. ClassNotFoundException
b. ClassFoundException
c. NoClassDefFoundError
d. ClassDefFoundError
ANSWER: ClassNotFoundException
23) By overriding the toString() method of the Object class, we can return values of the
object, so we don't need to write much code.
a. True
b. False
ANSWER: True
24) Which method of string class in java is used to convert the boolean into String?
25) Classes in the same package cannot access each other's package-access members.
a. True
b. False
ANSWER: False
26) Which is used to separate the hierarchy of the class while declaring an import
statement?
a. Package
b. Applet
c. Browser
ANSWER: Package
27) Which Thread pool is used where container creates a thread pool to process the
request?
a. Servlet
b. JSp
28) Which field of StreamTokenizer if the token is a word, this filed contains the word that
can be used in programming?
a. String sval
b. double nval
c. int ttype
a. True
b. False
ANSWER: True
30) Which statement provides an easy way to dispatch execution to different parts of your
code based on the value of an expression?
a. If
b. Switch
c. Nested-if
d. if-else-if
ANSWER: Switch
31) Which allows you to define one interface and have multiple implementations?
a. Encapsulation
b. Inheritance
c. Polymorphism
ANSWER: Polymorphism
32) Packages are used for distributing a collection of reusable classes, usually in a format
known as Java Archive (JAR) file.
a. True
b. False
ANSWER: True
33) If you are inserting any value in the wrong index as shown below,
a. NullPointerException
b. ArrayIndexOutOfBoundsException
c. ArithmeticException
d. NumberFormatException
ANSWER: ArrayIndexOutOfBoundsException
34) Which data type has this Minimum and Maximum value from 3.4e-038 to 3.4e+038?
a. long
b. Int
c. Byte
d. Float
ANSWER: Float
a. import
b. Static import
ANSWER: import
36) What can be accessed or inherited without actual copy of code to each program?
- Published on 20 Jul 15
a. Browser
b. Applet
c. Package
ANSWER: Package
37) Breaking a string or stream into meaningful independent words is known as
tokenization.
- Published on 20 Jul 15
a. True
b. False
ANSWER: True
38) Which variables are created when an object is created with the use of the keyword
'new' and destroyed when the object is destroyed?
- Published on 20 Jul 15
a. Local variables
b. Instance variables
c. Class Variables
d. Static variables
39) An interface is a blueprint of a class. It has static constants and abstract methods.
- Published on 20 Jul 15
a. True
b. False
ANSWER: True
a. Throwable
b. Exception
c. RuntimeException
d. IOException
ANSWER: Throwable
41) The Object class is not a parent class of all the classes in java by default.
- Published on 20 Jul 15
a. True
b. False
ANSWER: False
42) Which access specifiers can be used for a class so that it’s members can be accessed by
a different class in the different package?
- Published on 20 Jul 15
a. Private
b. Public
c. Protected
ANSWER: Public
43) Which keyword is used to make the classes and interface of another package
accessible to the current package?
- Published on 20 Jul 15
a. Import
b. Implements
c. Instanceof
ANSWER: Import
a. True
b. False
ANSWER: True
a. currentThread()
b. runningThread()
c. runnableThread()
ANSWER: currentThread()
a. PipedInputStream
b. PipedOutputStream
c. DataInputStream
d. DataOutputStream
e. Both C & D
a. Abstract Class
b. Static Class
c. Both A & B
b. False
ANSWER: False
49) Which is a mechanism where one object acquires all the properties and behaviors of
the parent object?
- Published on 20 Jul 15
a. Inheritance
b. Encapsulation
c. Polymorphism
ANSWER: Inheritance
a. StringBuffer class
b. StringBuilder class
c. Both A & B
51) Which is a technique in Java in which a class can have any number of constructors
that differ in parameter lists?
- Published on 17 Jul 15
a. Constructor overloading
b. Method overloading
c. Operator overloading
a. copy()
b. Objectcopy()
c. Objectclone()
d. Clone()
ANSWER: Objectclone()
53) Which class members can be accessed from the classes in the same package as well as
classes in other Packages that are subclasses of the declaring class?
- Published on 17 Jul 15
a. private
b. Public
c. Protected
ANSWER: Protected
54) How many methods does a thread class provides for sleeping a thread?
- Published on 17 Jul 15
a. 3
b. 1
c. 4
d. 2
ANSWER: 2
55) Which class automatically flushes the data so that there is no need to call the flush()
method. Moreover, its methods don't throw IOException?
- Published on 17 Jul 15
a. Console class
b. Scanner Class
c. FileInputStream class
d. PrintStream class
a. java.lang.reflect
b. java.awt
c. java.io
d. java.applet
ANSWER: java.lang.reflect
a. True
b. False
ANSWER: True
58) Nested interface must be public if it is declared outside the interface but it cannot have
any access modifier if declared within the class.
- Published on 17 Jul 15
a. True
b. False
ANSWER: False
59) Which keyword is used for the block to handle the exceptions generated by try block?
- Published on 17 Jul 15
a. Catch
b. Final
c. throw
d. try
ANSWER: Catch
a. java.lang
b. java.util
c. java.io
d. java.awt
ANSWER: java.lang
61) How many ways are there to access package from another package?
- Published on 17 Jul 15
a. 3
b. 2
c. 1
d. 5
ANSWER: 3
62) Both threads are waiting for each other to release the lock, the condition is called
deadlock.
- Published on 17 Jul 15
a. True
b. False
ANSWER: True
63) Which state is the thread still alive, but is currently not eligible to run?
- Published on 17 Jul 15
a. Non-Runnable
b. Terminated
c. Runnable
d. Running
ANSWER: Non-Runnable
64) Which method of DataInputStream class reads a line from the file and returns it as a
string?
- Published on 17 Jul 15
a. WriteInt()
b. readLine()
c. readInt()
d. writeDouble()
ANSWER: readLine()
a. True
b. False
ANSWER: True
a. True
b. False
ANSWER: False
67) What type of constructor is used to provide different values to the distinct objects?
- Published on 16 Jul 15
a. Default constructor
b. Parameterized constructor
c. Overloading constructor
68) Which class is used when a program does not want to handle an exception?
- Published on 16 Jul 15
a. Throws
b. Try
c. Catch
d. Final
ANSWER: Throws
a. 2
b. 3
c. 4
d. 5
ANSWER: 3
b. java.math
c. java.ref
d. java.util
ANSWER: java.lang
a. FileInputStream
b. FileOutputStream
c. Both A & B
ANSWER: FileOutputStream
a. stop()
b. start()
c. terminate()
d. join()
ANSWER: join()
a. java.awt
b. java.applet
c. java.util
d. java.lang
ANSWER: java.util
a. import
b. implements
c. instance of
ANSWER: implements
76) Which method of 'Class' class is used to register the driver class and the method is
used to dynamically load the driver class?
- Published on 15 Jul 15
a. forName()
b. getConnection()
c. createStatement()
d. executeQuery()
ANSWER: forName()
77) A class is declared inside a class but outside a method it is known as ________.
- Published on 15 Jul 15
a. It makes java memory efficient because garbage collector removes the unreferenced
objects from heap memory
b. It is automatically done by the garbage collector so we don't need to make extra efforts
79) Which mechanism is provided to handle the runtime errors so that normal flow of the
application can be maintained?
- Published on 10 Jul 15
a. Exception Handling
b. String Handling
c. Event Handling
a. length()
b. replace()
c. charAt()
d. equalIgnoreCase()
ANSWER: length()
a. James Gosling
b. Ken Thompson
c. Dennis Richie
a. Yes
b. No
ANSWER: No
83) Which classes has Sun Microsystem suggested not to use for read and write the textual
information?
- Published on 15 Jul 15
d. Both A & B
84) Which provides a new way for your programs to interface with code libraries written
in other languages?
- Published on 15 Jul 15
a. JNI
b. JDBC
c. RMI
d. GUI
ANSWER: JNI
85) An abstract class has no use when it is extended by some other class.
- Published on 15 Jul 15
a. True
b. False
ANSWER: True
a. True
b. False
ANSWER: True
b. False
ANSWER: True
89) Which symbol is used to contain the values of automatically initialized arrays. Also
used to define a block of code, for classes, methods, and local scopes?
- Published on 15 Jul 15
a. Brackets
b. Braces
c. Parentheses
d. Semicolon
ANSWER: Braces
91) Which method is used in thread class to starts the execution of the thread?
- Published on 15 Jul 15
a. InputStream
b. OutputStream
c. Input/OutputStream
ANSWER: InputStream
93) Which type of inheritance one super-class have more than one sub-class?
- Published on 15 Jul 15
a. Hierarchical inheritance
b. Single inheritance
c. Multiple inheritances
d. Multilevel inheritance
94) If a subclass has the same method as declared in the parent class it is known as
______.
- Published on 15 Jul 15
a. Method overriding
b. Method overloading
c. Constructor overloading
95) Which method is used to invoke the garbage collector to perform the cleanup
processing?
- Published on 15 Jul 15
a. gc() method
b. finalize() method
c. q.get() method
a. True
b. False
ANSWER: True
a. IOException class
b. RuntimeException Class
c. ClassCastException
d. Both A & B
98) Which method causes the current thread to wait for the specified milliseconds, until
the another thread notifies? (invokes notify() or notifyAll() method)?
- Published on 15 Jul 15
a. java.lang
b. java.awt
c. java.lang.ref
d. java.io
ANSWER: java.awt
100) Which method in thread class causes the currently executing thread object to
temporarily pause and allow other threads to execute?
- Published on 15 Jul 15