Java Programming MCQ QB: Unit 1: Basic Syntactical Construct in Java
Java Programming MCQ QB: Unit 1: Basic Syntactical Construct in Java
Java Programming MCQ QB: Unit 1: Basic Syntactical Construct in Java
1. Java is developed by
a) Sun Microsystems of USA
b) Microsoft
c)Adobe
d) None
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
10 The java interpreter uses method before any objects are created.
a)Class
b) Main
c)Constructor
d) All of above
18 refer to fix value that does not change during the execution of a
program.
a)variables
b) constants
c)identifiers
d) integer
25 Which statement is used to skip the loop and continue with the next iteration?
a)continue
b) terminate
c)skip
d) break
28 Java .
a)Only compiles
b) Only interprets
c) Compiles and then interprets
d) Interprets & then compile
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];
C) float d[ ]= {1,2,3};
A) stringBuffer
B) stringClass
C) toString( )
D) stringChar
19. Which of the following classes are available in the java.lang package?
A) i and ii only
C) ii and iv only
D) i and iv only
20. Consider the following code,
B) a default character
C) no characters in it
D) number of characters in it
21. …………………. returns a sting that contains the human-readable equivalent of the
value with which it is called.
A) toValue()
B) value()
C) valueOf()
D) getValue()
A) getChars()
B) toString()
C) toCharArray()
D) getString()
22412 JAVA PROGRAMMING MCQ QB 1
A) Mutual Exclusion
B) Inheritance
C) Package
D) Interface
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
A) java.util
B) java.awt
C) java.net
D) java.lang
i) When present, the package must be the first non-comment statement in the file.
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?
A) i only
B) ii only
C) iii only
A) Classes
B) interfaces
C) editing tools
package P1;
public class student {Body of Student}
Class Test {Body of Test}
import P1.*;
Class Result{
student S1;
Test t1;
}
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
A) java.io
B) java.awt
C) java.net
D) java.util
A) i and ii only
D) i and iv only
20. Which of the following sub-classes are included in object class in Java.
D) i, ii and iv only
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
22412 JAVA PROGRAMMING MCQ QB 1
1. Which of the following are the most common run-time errors in Java programming.
i) Missing semicolons
A) i and ii only
D) i and iv only
2. Which of the following are the most common compile time errors in Java programming.
i) Missing semicolons
B)
C) i, ii and iv only
3. The unexpected situations that may occur during program execution are
C) i, ii and iv only
A) throwable
B) catchable
C) hierarchical
D)
E) ArrayIndexOutofBounds
A) Numerical
B) Arithmetic
C) Mathematical
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.
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
A) throw
B) catch
C) finally
D) try
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
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");
}
}
}
A) Exception caught
C) finally
D) Thrown
...................
...................
try {
int x=0;
int y=50/x;
System.out.println("Division by zero");
}
catch(ArithmeticException e) {
System.out.println("catch block");
}
..................
..................
A) Error.
B) Division by zero
C) Catch block
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?
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
a) Process based
b) Thread based
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
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
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
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.
4. State whether the following statements about the Applets are True or False.
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?
</applet>
B) <applet>
</applet>
C) <applet
</applet>
D) <applet
</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>
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
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.
C) i, ii and iv only
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.
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
A. java.Applet class
B. java class
C. Applet class
D. java.applet.Applet class
A. Javascript
B. Css
C. HTML
D. SQL
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
22412 JAVA PROGRAMMING MCQ QB 1
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
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
4. The OutputStreams include methods that are designed to perform the following tasks.
C) i, ii and iv only
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( )
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( )
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.
C) i, ii and iv only
12. DataInput is
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( )
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.
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
A) Object
B) Piped
C) Pushback
D) Filtered