JAVA OBJECTIVE TYPE 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()
c. non static interrupted()
d. Both A & C
ANSWER: static interrupted()
3) The PipedInputStream and PipedOutputStream classes can be used to read and write
data simultaneously.
a. True
b. False
ANSWER: True
4) From the following statements which is a disadvantage of an java array?
a. An array can hold primitive types data
b. An array has its size that is known as array length
c. An array knows only its type that it contains. Array type is checked at the compile-time
d. An array holds only one type of data
ANSWER: An array holds only one type of data
5) The following Syntax is used for?
class Subclass-name extends Superclass-name
{
//methods and fields
}
a. Polymorphism
b. Encapsulation
c. Inheritance
d. None of the above
ANSWER: Inheritance
6) ResultSetMetaData interface is useful because it provides methods to get metadata from
the ResultSet object.
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)
d. None of the above
ANSWER: 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
d. None of the above
ANSWER: Inter-thread communication
10) Which method is used to change the name of a thread?
a. public String getName()
b. public void setName(String name)
c. public void getName()
d. public String setName(String name)
ANSWER: public void setName(String name)
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
d. None of the above
ANSWER: InflaterInputStream class
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
d. None of the above
ANSWER: FileInputStream
13) Switch is more efficient than nested if or if - else in java.
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
15) Mutual exclusive and inter-thread communication are which type of Synchorization?
a. Thread Synchronization
b. Process Synchronization
c. Object Synchronization
d. None of the above
ANSWER: Thread 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
d. None of the above
ANSWER: Checked Exception
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
21) Which methods are provided by the PrintStream class?
a. Read data to another stream
b. Write data to another stream
c. Read data to same stream
d. Write data to same stream
ANSWER: Write data to another stream
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?
a. public static String valueOf(double I)
b. public static String valueOf(boolean I)
c. public boolean equals(Object anObject)
d. public static String valueOf(Object obj)
ANSWER: public static String valueOf(double I)
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
d. All of the above
ANSWER: Package
27) Which Thread pool is used where container creates a thread pool to process the
request?
a. Servlet
b. JSp
c. All of the above
d. None of the above
ANSWER: All of the above
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
d. static final int TT_WORD
ANSWER: double nval
29) The JDK forms an extended subset of a software development kit (SDK)
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
d. None of the above
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,
1. int a[]=new int[5];
2. a[10]=50;
it would result in ______.
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
35) Which provides accessibility to classes and interface?
a. import
b. Static import
c. All the above
d. None of the above
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
d. None of the above
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
ANSWER: Instance 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
40) Which is a superclass of all exception classes?
- Published on 20 Jul 15
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
d. None of the above
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
d. None of the above
ANSWER: Import
44) If you import a package, subpackages will not be imported.
- Published on 20 Jul 15
a. True
b. False
ANSWER: True
45) Which method returns a reference to the currently executing thread object?
- Published on 20 Jul 15
a. currentThread()
b. runningThread()
c. runnableThread()
d. None of the above
ANSWER: currentThread()
46) Which are subclasses of FilterInputStream and FilterOutputStream?
- Published on 20 Jul 15
a. PipedInputStream
b. PipedOutputStream
c. DataInputStream
d. DataOutputStream
e. Both C & D
ANSWER: Both C & D
47) Which class cannot be instantiated?
- Published on 13 Jul 15
a. Abstract Class
b. Static Class
c. Both A & B
d. None of the above
ANSWER: Abstract Class
48) Java Virtual Machine is platform independent.
- Published on 20 Jul 15
a. True
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
d. None of the above
ANSWER: Inheritance
50) Which class is thread-safe i.e. multiple threads cannot access it simultaneously,So it is
safe and will result in an order?
- Published on 17 Jul 15
a. StringBuffer class
b. StringBuilder class
c. Both A & B
d. None of the above
ANSWER: StringBuffer class
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
d. None of the above
ANSWER: Constructor overloading
52) Which method of object class can clone an object?
- Published on 17 Jul 15
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
d. None of the above
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
ANSWER: PrintStream class
56) Which package is used for analyzing code during run time?
- Published on 10 Jul 15
a. java.lang.reflect
b. java.awt
c. java.io
d. java.applet
ANSWER: java.lang.reflect
57) Multiple inheritances is not supported in case of class but it is supported in case of
interface.
- Published on 17 Jul 15
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
60) Under which package is the string class encapsulated?
- Published on 17 Jul 15
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()
65) The Java Virtual Machine is the cornerstone of the Java platform.
- Published on 17 Jul 15
a. True
b. False
ANSWER: True
66) By interface, we cannot support the functionality of multiple inheritances.
- Published on 17 Jul 15
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
d. None of the above
ANSWER: Parameterized 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
69) How many types of constructor are defined in the StringTokenizer class?
- Published on 16 Jul 15
a. 2
b. 3
c. 4
d. 5
ANSWER: 3
70) Which package includes all the standard classes of java?
- Published on 16 Jul 15
a. java.lang
b. java.math
c. java.ref
d. java.util
ANSWER: java.lang
71) Which is used for writing data to a file in file handling?
- Published on 10 Jul 15
a. FileInputStream
b. FileOutputStream
c. Both A & B
d. None of the above
ANSWER: FileOutputStream
72) Which method waits for a thread to die?
- Published on 16 Jul 15
a. stop()
b. start()
c. terminate()
d. join()
ANSWER: join()
73) Which package includes StringTokenizer that tokenizes a string into independent
words?
- Published on 16 Jul 15
a. java.awt
b. java.applet
c. java.util
d. java.lang
ANSWER: java.util
74) JVM stands for?
- Published on 16 Jul 15
a. Java Very Large Machine
b. Java Verified Machine
c. Java Very Small Machine
d. Java Virtual Machine
ANSWER: Java Virtual Machine
75) Which keyword is used by classes to implement an interface?
- Published on 16 Jul 15
a. import
b. implements
c. instance of
d. None of the above
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. Anonymous Inner class
b. Member Inner class
c. Local Inner class
d. Static nested class
ANSWER: Member Inner class
78) What is the disadvantage of Garbage Collection?
- 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
c. None of the above
ANSWER: None of the above
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
d. None of the above
ANSWER: Exception Handling
80) Which string function returns the number of characters in a string?
- Published on 15 Jul 15
a. length()
b. replace()
c. charAt()
d. equalIgnoreCase()
ANSWER: length()
81) Who is also called father of Java Programming Language?
- Published on 15 Jul 15
a. James Gosling
b. Ken Thompson
c. Dennis Richie
d. None of the above
ANSWER: James Gosling
82) Can we start a thread twice?
- Published on 15 Jul 15
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
a. BufferedInputStream and BufferedOutputStream
b. SequenceInputStream and SequenceOutputStream
c. FileInputStream and FileOutputStream
d. Both A & B
ANSWER: FileInputStream and FileOutputStream
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
86) Garbage Collection is the process of reclaiming the runtime unused memory
automatically.
- Published on 15 Jul 15
a. True
b. False
ANSWER: True
87) What is the advantage of Method Overloading?
- Published on 15 Jul 15
a. Method overloading increases the readability of the program
b. Method overloading does not increases the readability of the program
c. Method overloading does not increases the reliability of the program
d. None of the above
ANSWER: Method overloading increases the readability of the program
88) PatternSyntaxException Class Methods is an unchecked exception that indicates a
syntax error in a regular expression pattern.
- Published on 15 Jul 15
a. 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
90) Which packages are also termed as Java API Packages?
- Published on 15 Jul 15
a. Java System Packages
b. User Defined Package
c. Java Defined Packages
d. None of the above
ANSWER: Java System Packages
91) Which method is used in thread class to starts the execution of the thread?
- Published on 15 Jul 15
a. public void start()
b. public void run()
c. public void stop()
d. public void suspend()
ANSWER: public void start()
92) Which stream does Java application uses to read data from a source, it may be a file,
an array, peripheral device or socket?
- Published on 15 Jul 15
a. InputStream
b. OutputStream
c. Input/OutputStream
d. None of the above
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
ANSWER: Hierarchical 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
d. None of the above
ANSWER: Method overriding
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
d. None of the above
ANSWER: gc() method
96) If there is no constructor in a class, compiler automatically creates a default
constructor.
- Published on 15 Jul 15
a. True
b. False
ANSWER: True
97) What are the main subclasses of the Exception class?
- Published on 15 Jul 15
a. IOException class
b. RuntimeException Class
c. ClassCastException
d. Both A & B
ANSWER: 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. public final void wait(long timeout)throws InterruptedException
b. protected void finalize()throws Throwable
c. public final void wait(long timeout,int nanos)throws InterruptedException
d. protected Object clone() throws CloneNotSupportedException
ANSWER: public final void wait(long timeout)throws InterruptedException
99) Which package is used for GUI?
- 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
a. public boolean isAlive()
b. public int getId()
c. public void yield()
d. public boolean isDaemon()
ANSWER: public void yield()