JAVA PROGRAMMING (22412)
Hey buddies, I'm sharing with you Java multiple questions and answers for your study and exam preparations. These java multiple choice questions and answers cover all the points of java programming. These multiple-choice questions will help you with your exam preparation and quiz help.
1. Java is developed by
___________________
a) Sun Microsystems of USA
b) Microsoft
c) Adobe
d) None
2 ________________ is one of the inventors of Java.
a) Dannis Ritchie
b) James Gosling
c) Bjarne Stroustrup
d) Balagurusamy
3 ____________ is one of the java features that enables java program to run
anywhere anytime.
a)Object-Oriented
b)Multithreaded
c)Platform-Independent
d) Dynamic & Extensible
4 _____________ is one of the java features that can handle multiple tasks simultaneously.
a) Object-Oriented
b) Dynamic & Extensible
c) Platform-Independent
d) Multithreaded
5 Java compiler translates source code into _____________
a) Bytecode
(Virtual Machine Code)
b) Bitcode
c) Machine Code
d) User code
6 Java interpreter translates _____________ into machine code.
a) Bitcode
b) Bytecode(Virtual
Machine Code)
c) Machine Code
d) User code
7 Java compiler produces an intermediate code known as ____________
a) Bitcode
b) Machine Code
c) Bytecodes
d) User code
8 ____________ tool helps us to find errors in our programs.
a) jhelp
b) javah
c) javap
d) jdb
9 The ____________ includes hundred of classes and methods grouped into several
function packages.
a) API
b) JVM
c) JAVAC
d) JRE
10 The java interpreter uses ____________ method before any objects are
created.
a) Class
b) Main
c) Constructor
d) All of above
11 ____________ is use for naming classes, methods, variables etc in a program.
a) Operator
b) Separator
b) Identifier
d) Constructor
12 ____________ is reserved keyword in java.
a) Abstract
b) Extends
b) Package
d) All of above
13 Java provides an extensive set of classes, arranged in ___________.
a) Package
b) Library file
c) Template class
d) None
14 The process of converting one date type to another is called__________
a) Translating
b) Casting
c) Compiling
d) Declaring
15 Java does not support ______________.
a) Operator overloading
b) Global variable
c) Multiple inheritance
d) All of above
16 Casting from byte to __________ data type, the result is no loss
information.
a) short
b) int
c) long
d) all of above
17 Casting from shot to __________ data type, the result is no loss
information.
a) byte
b) int
c) long
d) double
18___________ refer to fix value that does not change during the execution of a
program.
a) variables
b) constants
c) identifiers
d) integer
19 ____________ operators are used to construct mathematical expression as in
algebra.
a) Relational
b) Mathematical
c) Arithmetic
d) Logical
20 Which constraint must be considered at the time of variable declaration?
a) It should not be keyword
b) It must not begin with digit
c) White space not allowed
d) All of above
21 The comparisons can be done with help of ____________ operator.
a) Relational
c) Arithmetic
b) Mathematical
d) Assignment
22 Which of the following is not an assignment operator?
a) +=
b) = =
c) %=
d) =
23 _____________ operator is used to construct conditional expression.
a) Dot(.)
b) instanceof
c) Ternary(?:)
d) None
24 Which statement is used to terminate the loop early?
a) terminate
b) continue
c) skip
d) break
25 Which statement is used to skip the loop and continue with the next
iteration?
a) continue
b) terminate
c) skip
d) break
26 _________ is a group of contiguous or related data items that share a common
name.
a) Variable
b) Array
c) Constant
d) none
27 Which of the following is the correct declaration statement in java program?
a) int num=new int[5]
b) int num=new num[5]
c) int[] num=new int[5]
d) None
28 Java __________________.
a) Only compiles
b) Only interprets
c) Compiles and then
interprets
d) Interprets & then compile
29 JVM stands for __________________
a) Java Virtual Method
b) Java Virtual Machine
c) Java Variable & Methods
d) Java Versatile Machine
30 Which of the following is a ternary operator?
a) +=
b) ?
c) %=
d) =
1. Range of short
variable is ______________
a) -128 to 128
b) -128 to 127
c) -32768 to 32767
d) -32768 to 32768
2 _______________ is the default access specifier in JAVA.
a) friendly
b) private
c) protected
d) public
3 __________ variables and methods can be called without using the objects.
a) static
b) final
c) abstract
d) none of the above
4 Which of the following statements is true?
a) supports operator overloading
b) Java supports
interfaces
c) Java supports pointers
d) Java supports multiple inheritances
5 What keyword is used in Java to define a constant?
a) static
b) final
c) abstract
d) private
6 If two methods have the same name but a different parameter list then it is called___________
a) Method overriding
b) Method overloading
c)Operator overloading
d) None of these
7 ______________ constructor is created when an object of a particular class is
created.
a) Default
b) Parameterized
c) Copy
d) None of these
8 _______________ inheritance is not supported by JAVA.
a) Multiple
b) Multi level
c) Hierarchical
d) Hybrid
9 The mechanism of deriving a new class from an old one is called
______________.
a) Method overriding
b) Method overloading
c) Operator overloading
d) Inheritance
10 ________ keyword does not allow a method to be overridden in the subclass.
a) public
b) abstract
c) final
d) static
11 ________ methods must be overridden in the subclass.
a) public
b) final
c) abstract
d) static
12 The subclass constructor uses the ________ keyword to invoke the constructor
of the superclass.
a) super
b) Final
c) static
d) public
13 __________ is a special method in java that enables an object to initialize
itself when it is created.
a) constructor
b) destructor
c) static
d) final
14 ________ defines only abstract methods and final fields.
a) Interface
b) Final class
c) Abstract class
d) Class
15 __________ keyword is used to inherit a class.
a) extend
b) extends
c) implement
d) implements
16 We cannot create a
subclass of _________ class.
a) Abstract
b) public
c) static
d) final
Answers of MCQ:
1. (c), 2. (a), 3. (a), 4. (b), 5. (b), 6. (a), 7. (a), 8. (a), 9. (d), 10.
(c), 11. (c), 12. (a), 13. (a), 14. (a), 15. (b), 16. (d)
17. Which of the following declaration of the array contains the error?
A) int x[ ]= int[10];
B) int [ ] y=new int[5];
C) float d[ ]= {1,2,3};
D) int a[ ] = {1, 2,3; int b[ ]; b=a;
1. What are the features
of an Object Oriented Programming (OOPs)?
A) Inheritance
B) Encapsulation
C) Polymorphism
D) All the above
2. What are the features reused using Inheritance in Java?
A) Methods
B) Variables
C) Constants
D) All the above
3. The class that is being inherited or subclassed is called ___.
A) Subclass
B) Superclass
C) -
D) –
4. The class that inherits an already defined class is called ___.
A) Subclass
B) Superclass
C) -
D) –
5. Java language supports ___ type of inheritance.
A) Multiple Inheritance
B) Multi-Level Inheritance
C) -
D) –
6. ………………… is one of the cornerstones of object-oriented programming because it
allows the creation of hierarchical classifications.
A) Mutual Exclusion
B) Inheritance
C) Package
D) Interface
7. ……………….. helps to extend the functionality of an existing by adding more
methods to the
subclass.
A) Mutual Exclusion
B) Inheritance
C) Package
D) Interface
8. The variables, methods, and inner classes that are declared ………………… are
accessible to the sub-classes of the class in which they are declared.
A) private
B) public
C) protected
D) friend
9. State whether the following statements about the advantages of organizing
classes into packages are True or False.
i) Two classes in two different packages can not have the same name.
ii) The classes contained in the packages of other programs can be easily
reused.
A) True, False
B) False, True
C) True, True
D) False, False
10. ………………….. package in java contents language utility classes such as
vectors, hash
tables, random numbers date etc.
A) java.util
B) java.awt
C) java.net
D) java.lang
11. …………………….. package in java contents set of classes for implementing
graphical user
interface, which includes classes for windows, buttons, lists, menus and so on.
A) java.util
B) java.awt
C) java.net
D) java.lang
12. State whether the following statements are True or False.
i) When present, the package must be the first non-comment statement in the
file.
ii) When we implement an interface method, it should be declared as public.
A) True, False
B) False, True
C) True, True
D) False, False
13. Which keyword can protect a class in a package from accessibility by the
classes outside the
package?
i) private ii) protected iii) final
A) i only
B) ii only
C) iii only
D) None of the above
14. A package is a collection of
A) Classes
B) interfaces
C) editing tools
D) classes and interfaces
15. Package P1 contains the following code
package P1;
public class student {Body of Student}
Class Test {Body of Test}
Now consider the following code;
import P1.*;
Class Result{
student S1;
Test t1;
}
This code compile because
A) Class result should be declared public.
B) Student class is not available
C) Test class is not
available
D) Result body is not fully defined
16. Which of the following classes in the Java.io package defines a method to
delete a file.
A) Stack
B) File
C) String
D) Vector
17. For a valid file object reference, we can create a new file using the
following classes defined
in the Java.io package.
i) FileOutputStream
ii) RandomAccessFile
iii) DataInput
A) i and ii only
B) ii and iii only
C) i and iii only
D) All i, ii and iii
18. The Date class includes within ………………….. package.
A) java.io
B) java.awt
C) java.net
D) java.util
19. Which of the following classes are included in java.awt package.
i) Font ii) Frame iii) Float iv) File
A) i and ii only
B) ii and iii only
C) iii and iv only
D) i and iv only
20. Which of the following sub-classes are included in object class in Java.
i) Dictionary ii) Date iii) Label iv) Thread
A) i, ii and iii only
B) ii, iii and iv only
C) i, iii and iv only
D) i, ii and
iv only
21. An …………………. is an incomplete class that requires further specification.
A) abstract class
B) final class
C) static class
D) super class
22. A class can be declared as ………………………. if you do not want the class to be
subclassed.
A) abstract
B) final
C) static
D) super
23. The …………………….. keyword is used to derive a class from a super-class.
A) adds
B) extends
C) duplicate
D) inherit
24. If a class that implements an interface does not implement all the methods
of the interface,
then the class becomes a/an …………………….. class.
A) abstract
B) final
C) static
D) super
25. By convention, java packages begin with ………………. letters while all the class
names
begin with an ………………… letter.
A) uppercase, uppercase
B) lowercase, lowercase
C) uppercase, lowercase
D) lowercase, uppercase
1. Which of the following are the most common run-time errors in Java
programming.
i) Missing semicolons
ii) Dividing an integer by zero
iii) Converting invalid string to number
iv) Bad reference of objects
A) i and ii only
B) ii and iii only
C) iii and iv only
D) i and iv only
2. Which of the following are the most common compile
time errors in Java programming.
i) Missing semicolons
ii) Use of undeclared variables
iii) Attempting to use a negative size for an array
iv) Bad reference of objects
A) i, ii and iii only
B) ii, iii and iv only
C) i, ii and iv only
D) All i, ii, iii and iv
3. The unexpected situations that may occur during program execution are
i) Running out of memory
ii) Resource allocation errors
iii) Inability to find a file
iv) Problems in network
A) i, ii and iii only
B) ii, iii and iv only
C) i, ii and iv only
D) All i, ii, iii and iv
4. The class at the top of the exception classes hierarchy is called ………………… …
A) throwable
B) catchable
C) hierarchical
D) ArrayIndexOutofBounds
5. ………………… exception is thrown when an exceptional arithmetic condition has
occurred.
A) Numerical
B) Arithmetic
C) Mathematical
D) All of the above
6. ……………………….. exception is caused when an applet tries to perform an action
not
allowed by the browser’s security setting.
A) Throwable
B) Restricted
C) Security
D) ArrayIndexOutofBounds
7. …………………….. an exception is thrown when an attempt is made to access an array
element beyond the index of the array.
A) Throwable
B) Restricted
C) Security
D) ArrayIndexOutofBounds
8. You can implement exception-handling in your
program by using which of the following keywords.
i) Try ii) NestTry iii) Catch iv) Finally
A) i, ii and iii only
B) ii, iii and iv only
C) i, iii and iv only
D) All i, ii, iii and iv
9. When a ……………………. block is defined, this is guaranteed to execute, regardless
of
whether or not an exception is thrown.
A) throw
B) catch
C) finally
D) try
10. The ……………………. statement is passed a single parameter, which is reference to
the
exception object thrown.
A) throw
B) catch
C) finally
D) try
11. Every try statement should be followed by at least one catch statement;
otherwise …………………. will occur.
A) no execution
B) null
C) zero
D) compilation error
12. If an exception occurs within the …………………….. block, the appropriate
exceptionhandler that is associated with the try block handles the exception.
A) throw
B) catch
C) finally
D) try
13) Exception classes are available in the ……………………package.
A) java.lang
B) java.awt
C) java.io
D) java.applet
14. …………………….. is caused by general I/O failures, such as inability to read
from file.
A) I/O failure
B) I/O exception
C) I/O inability
D) I/O distortion
15. Consider the following try…….. catch block:
class TryCatch
{
public static void main(String args[ ])
{
try
{
double x=0.0;
throw(new Exception("Thrown"));
return;
}
catch(Exception e)
{
System.out.println("Exception
caught");
return;
}
finally
{
System.out.println("finally");
} } }
What will be the output?
A) Exception caught
B) Exception caught finally
C) finally
D) Thrown
16. Consider the following code snippet:
...................
...................
try {
int x=0;
int y=50/x;
System.out.println("Division by
zero");
}
catch(ArithmeticException e) {
System.out.println("catch
block");
}
..................
..................
What will be the output?
A) Error.
B) Division by zero
C) Catch block
D) Division by zero Catch block
17. State whether the following statements are True or False.
i) A catch can have comma-separated multiple arguments.
ii) Throwing an Exception always causes program termination.
A) True, False
B) False, True
C) True, True
D) False, False
18. Java uses a keyword ………………… to preface a block of code that is likely to
cause an
error condition and ‘throw’ an exception.
A) throw
B) catch
C) finally
D) try
19. When an exception in a try block is generated, Java treats the multiple
……………….
statements like cases in switch statements.
A) throw
B) catch
C) finally
D) try
20. The …………………. statement can be used to handle an exception that is not
caught by any
of the previous catch statements.
A) throw
B) catch
C) finally
D) try
21. What is multithreaded programming?
a) It’s a process in which two different processes run simultaneously
b) It’s a process in which
two or more parts of same process run simultaneously
c) It’s a process in which many different process are able to access same
information
d) It’s a process in which a single process can access information from many
sources
22. Which of these are types of multitasking?
a) Process based
b) Thread based
c) Process and Thread
based
d) None of the mentioned
23. Thread priority in Java is?
a) Integer
b) Float
c) double
d) long
24. What will happen if two thread of the same priority are called to be
processed
simultaneously?
a) Anyone will be executed first lexographically
b) Both of them will be executed simultaneously
c) None of them will be executed
d) It is dependent on the
operating system
25. Which of these statements is incorrect?
a) By multithreading CPU idle time is minimized, and we can take maximum use of
it
b) By multitasking CPU idle time is minimized, and we can take maximum use of
it
c) Two thread in Java can have the same priority
d) A thread can exist only
in two states, running and blocked
26. What will be the output of the following Java code?
1. class multithreaded_programing
2. {
3. public static void main(String args[])
4. {
5. Thread t = Thread.currentThread();
6. System.out.println(t);
7. }
8. }
a) Thread[5,main]
b) Thread[main,5]
c) Thread[main,0]
d)
Thread[main,5,main]
27. What is the priority of the thread in the following Java Program?
1. class multithreaded_programing
2. {
3. public static void main(String args[])
4. {
5. Thread t = Thread.currentThread();
6. System.out.println(t);
7. }
8. }
a) 4
b) 5
c) 0
d) 1
28. What is the name of the thread in the following Java Program?
1. class multithreaded_programing
2. {
3. public static void main(String args[])
4. {
5. Thread t = Thread.currentThread();
6. System.out.println(t);
7. }
8. }
a) main
b) Thread
c) System
d) None of the mentioned
1. When the ………………. method of the Applet class is called, it displays the
result of the
Applet code on the screen.
A) paint( )
B) repaint( )
C) update( )
D) reupdate( )
2. Before we try to write applets, we must make sure that Java is installed
properly and also
ensure that either the java is installed properly and also ensure that either
the java ……………..
or a java-enabled browser is available.
A) viewer( )
B) appletviewer( )
C) appletrunner( )
D) browserviewer( )
3. Arrange the steps involved in developing and testing the applet in correct
order.
i) creating an executable applet (.classfile)
ii) preparing <APPLET> tag
iii) creating HTML file
iv) building an applet code (.java file)
v) testing the applet code
A) 1-i, 2-ii, 3-iii, 4-iv, 5-v
B) 1-ii, 2-iii, 3-iv, 4-v, 5-i
C) 1-iv, 2-i, 3-ii, 4-iii,
5-v
D) 1-iii, 2-iv, 3-v, 4-i, 5-ii
4. State whether the following statements about the Applets are True or False.
i) Applets can communicate with other services on the network.
ii) Applets cannot run any program from the local computer.
A) True, False
B) False, True
C) True, True
D) False, False
5. Applet class is a subclass of the panel class, which is again a subclass of
the
………………….. class.
A) object
B) component
C) awt
D) container
6. The ………………… method called the first time an applet is loaded into the memory
of a
computer.
A) init( )
B) start( )
C) stop( )
D) destroy( )
7. The ……………………… method is called every time the applet receives focus as a
result of
scrolling in the active window.
A) init( )
B) start( )
C) stop( )
D) destroy( )
8. Which of the following applet tags is legal to embed an applet class named
Test into a
webpage?
A) <applet class=Test width=200 height=100>
</applet>
B) <applet>
code=Test.class width=200 height=100>
</applet>
C) <applet
code=Test.class width=200 height=100>
</applet>
D) <applet
param=Test.class width=200 height=100>
</applet>
9. If you want to assign a value of 88 to the variable year, then which of the
following lines can
be used within an <applet> tag.
A) number = getParameter(88)
B) <number=99>
C) <param = radius value=88>
D) <param name=number
value=88>
10. The …………………. class is an abstract class that represents the display area of
the applet.
A) display
B) graphics
C) text
D) area
11. The graphics class provides methods to draw a number of graphical figure
including
i) Text ii) Lines iii) Images iv) Ellipse
A) i, ii and iii only
B) ii, iii and iv only
C) i, iii and iv only
D) All i, ii, iii and iv
12. The ………………. method is called to clear the screen and calls the paint( )
method.
A) update( )
B) paint( )
C) repaint( )
D) reupdate( )
13. The ………………….. method is automatically called the first time the applet is
displayed on the screen and every time the applet receives focus.
A) update( )
B) paint( )
C) repaint( )
D) reupdate( )
14. The ………………. method is defined by the AWT which causes the AWT runtime
system
to execute a call to your applet’s update( ) method.
A) update( )
B) paint( )
C) repaint( )
D) reupdate( )
15. Text field can be created by which of the following methods.
i) TextField( ) ii) TextFieldString( )
iii) TextField(int) iv) TextField(string, int)
A) i, ii and iii only
B) ii, iii and iv only
C) i, ii and iv only
D) All i, ii, iii and iv
16. In java applet, we can display numerical values by first converting them
into string and then
using the ………………… method.
A) paint( )
B) drawstring( )
C) draw( )
D) convert( )
17. We can change the text to be displayed by an applet by supplying new text
to be displayed by an applet by supplying new text to the applet through a
……………………… tag.
A) <EDIT>
B) <CHANGE>
C) <REPLACE>
D) <PARAM>
18. Which of the following is/are the possible values for alignment attribute
of Applet tag.
i) Top ii) Left iii) Middle iv) Baseline
A) i, ii and iii only
B) ii, iii and iv only
C) i, iii and iv only
D) All i, ii, iii and iv
19. The ……………….. attribute of applet tag specifies the amount of horizontal
blank space the
browser should leave surrounding the applet.
A) SPACE=pixels
B) HSPACE=piexls
C) HWIDTH=piexls
D) HBLANK=pixels
20. ……………………. attribute of applet tag specify the
width of the space on the HTML page
that will reserved for the applet.
A) WIDTH=pixels
B) HSPACE=piexls
C) HWIDTH=piexls
D) HBLANK=pixels
21. An applet is a Java class that extends the?
A. java.Applet class
B. java class
C. Applet class
D. java.applet.Applet
class
22. Applets are designed to be embedded within an __________.
A. Javascript
B. Css
C. HTML
D. SQL
23. Which of the following is required to view an applet?
A. JCM
B. JDM
C. JVM
D. Java class
24. Which method is automatically called after the browser calls the init
method?
A. start
B. stop
C. destroy
D. paint
25. Which method is only called when the browser
shuts down normally?
A. start
B. stop
C. destroy
D. paint
1. The …………………… package contains a large number of stream classes that provide
capabilities for processing all types of data.
A) java.awt
B) java.io
C) java.util
D) java.net
2. State whether the following statements about the stream in Java.
i) The two basic streams used are the input and output streams.
ii) Filters are used to read data from one stream and write it to another
stream.
A) True, True
B) True, False
C) False, True
D) False, False
3. The InputStream class defines methods for performing input functions such as
i) reading bytes ii) closing streams
iii) skipping ahead in a stream iv) flushing streams
A) ii, iii and iv only
B) i, ii and iii only
C) i, iii and iv only
D) All i, ii, iii and iv
4. The OutputStreams include methods that are designed to perform the following
tasks.
i) closing streams |
ii) flushing streams |
A) ii, iii and iv only
B) i, ii and iii only
C) i, ii and iv only
D) All i, ii, iii and iv
5. Which of the following method(s) is not included in the InputStream class.
A) available( )
B) reset( )
C) flush( )
D) close( )
6. Which of the following methods are not included in the OutputStream class.
A) write( )
B) skip( )
C) close( )
D) flush( )
7. The class DataInputStream extends …………………….. and implements the interface
DataInput.
A) FileInputStream
B) SequenceInputStream
C) FilterInputStream
D) InputStream
8. The method …………………., force writes whenever the data accumulates in the
output
stream.
A) write( )
B) flush( )
C) read( )
D) reset( )
9. The DataInputStream and DataOutputStream classes are …………………….. streams
that allow the reading and writing of Java primitive data types.
A) file
B) sequence
C) object
D) filter
10. The ……………………… class provides the capacity to read primitive data types from
an
input stream.
A) pushbackInputStream
B) DataInputStream
C) BufferedInputStream
D) PipeInputStream
11. Which of the following is/are the methods of the DataOutputStream class.
i) void
writeChar(intV) |
ii) void writeLong(longV) |
A)
ii, iii and iv only
B) i, ii and iii only
C) i, ii and iv only
D) All i, ii, iii and iv
12. DataInput is
A) an abstract class defined in java.io
B) a class we can use to read primitive data types
C) an interface that defines methods to open files
D) an
interface that defines methods to read primitives data types
13. Which exception is thrown by the read( ) method of InputStream class.
A) Exception
B) IOException
C) ReadException
D) File Not Found Exception
14. The ……………………… method of the BufferedReader class is used for reading lines
of
text from the console, the file or other input streams.
A) read( )
B) read(byte[]b)
C) readLine( )
D) readByte( )
15. ……………………. class is used to increase the efficiency of input operations.
A) DataInputStream
B) FileInputStream
C) BufferedInputStream
D) PipeInputStream
16. State whether the following statements about DataInputStream class are
True.
i) readBoolean( ) reads one byte and returns true if that byte is nonzero,
false if it is zero.
ii) readByte( ) reads a byte as an 8-bit signed value.
iii) readChar( ) reads a unicode character.
A) True, False, True
B) False, True, False
C) True, False, False
D) True, True, True
17. The ……………………. class implements the DataInput and DataOutput interfaces for
performing I/O using the primitive data types.
A) RandomAccessFile
B) OutputStream Reader
C) InputStreamReader
D) DataOutputStream
18. The class ………………………. is a subclass of object class which can be used for breaking
up a stream of text from an input text file into meaningful pieces.
A) Streamtokenizer
B) RandomAccessFile
C) InputStreamReader
D) DataOutputStream
19. Combining two or more input streams into a single input stream can be
achieved using the ………………. class.
A) SequenceOutputStream
B) BufferedInputStream
C) BufferedOutputStream
D) SequenceInputStream
20. ……………….. streams provide functionally for threads to communicate and
exchange data between them.
A) Object
B) Piped
C) Pushback
D) Filtered