Java Programming MCQs Sample Question Paper – I
1. Java is purely object-oriented and provides –
a. Abstraction, inheritance
b. Encapsulation, polymorphism
c. Abstraction, polymorphism
d. All of the above
Ans. D
2. Compilation is the process of converting the code into a language that is –
a. Assembly language
b. Machine language
c. High-level language
d. Low-level language
Ans. B
3. ___ is the ability of an application to perform multiple tasks at the same time.
a. Dynamic language
b. Interpreted
c. Multithreading
d. None of the above
Ans. C
4. BY code is a highly optimized set of ________ designed to be executed by the java runtime system, which is called JVM.
a. Date
b. Information
c. Instructions
d. Machine
Ans. C
5. There are _______ kind of data types in java.
a. 8
b. 4
c. 2
d. 3
Ans. C
6. Rules for naming variable in Java.
a. Must not a keyword in java
b. Must not begin with a digit
c. Must not contain embedded spaces
d. All of the above
Ans. D
7. The new operator is used to create a –
a. Function object
b. Class object
c. Method object
d. None of the above
Ans. B
8. To display data on-screen used –
a. println( )
b. print( )
c. none of the above
d. a & b
Ans. D
9. Operator which concatenates two strings is –
a. *
b. –
c. +
d. None of the above
Ans. C
10. In Java, a class that is inherited is called –
a. Subclass
b. Superclass
c. a and b
d. None of the above
Ans. B
11. How many relationships in Java –
a. 4
b. 2
c. 3
d. 6
Ans. A
12. Which keyword is used to derive a class from a superclass?
a. Implements
b. Extends
c. Package
d. None of the above
Ans. B
13. How many access specifier in Java.
a. 3
b. 2
c. 4
d. None of the above
Ans. A
14. Protected access specifier is accesses –
a. Accessible to the subclasses of the class in which they are declared
b. Accessible to all class (implicitly & explicitly)
c. Both a & b
d. None of the above
Ans. A
15. Super keyword is used for –
a. Calling superclass constructor
b. To access the hidden member of superclass
c. Both s & b
d. None of the above
Ans. C
16. An abstract class is used as –
a. A subclass to derive a specific class of same kind
b. A base class to derive a specific class of the same kind
c. A base class to implement a specific class of the same kind
d. None of the above
Ans. B
17. Java provides a mechanism for partitioning the class namespace into more manageable chunks. This mechanism is –
a. Interface
b. Inheritance
c. Package
d. All of the above
Ans. C
18. By defaults all the method in the interface is –
a. Public
b. Abstract
c. a & b
d. All of the above
Ans. B
19. Which keyword is used for implementing an interface –
a. Extends
b. Package
c. Implements
d. None of the above
Ans. C
20. Which mechanism is used in Java when an abnormal event occurs during program execution and stop the flow of instruction.
a. Exception handling
b. Exception
c. Inheritance
d. None of the above
Ans. A
21. Which exception is thrown when an exceptional arithmetic condition has occurred?
a. Null pointer exception
b. Arithmetic exception
c. Array index out of bound exception
d. None of the above
Ans. B
22. What are the different exception handling technique?
a. Try
b. Finally
c. Catch
d. All of the above
Ans. D
23. The two major classes for byte streams are –
a. Input and output
b. Input stream and output stream
c. Reader and writer classes
d. None of the above
Ans. B
24. What are different methods of an input stream.
a. int read ( )
b. int read (byte [] b)
c. int available
d. All of the above
Ans. D
25. What are different methods of an output stream?
a. void close ( )
b. void write (int n)
c. int read (byte [] b, int off, int len)
d. Both a and b
Ans. D
26. The read line( ) method of the buffered class is used for –
a. Writing line of text to the console
b. Reading line of text from the console
c. Both a and b
d. None of the above
Ans. B
27. The random access files class has several methods that allow random access to contact within the file, these methods are –
a. void seek (long pos)
b. long getFilePointer ( )
c. long length
d. All of the above
Ans. D
28. Serialization is the key to implementing –
a. Input-output stream
b. Persistence program
c. Program
d. All of the above
Ans. B
29. Read object () method of object input stream class is used to –
a. Write object to the stream
b. Read the object and write the object to stream
c. Read the object and write the object to stream
d. None of the above
Ans. C
30. Input and output stream are superclasses used for reading from and writing to –
a. Character streams
b. Byte streams
c. Both a and b
d. None of the above
Ans. B
31. The applet tag is used to embed an applet in an HTML document the applet tag takes –
a. Zero parameter
b. More than one parameter
c. Zero or more parameters
d. None of the above
Ans. C
32. Life cycle of an applet has _________ methods.
a. 3
b. 5
c. 2
d. 4
Ans. D
33. An event comprises of components –
a. Event object
b. Event source
c. Event handler
d. All of the above
Ans. D
34. Types of component events are –
a. Component-hidden
b. Component-moved
c. Component-resized
d. Component-shown
e. All of the above
Ans. E
35. The ODBC is written in ________ language, a java program cannot directory communicate with an ODBC driver.
a. Java language
b. C language
c. Both a & b
d. None of the above
Ans. B
36. Java soft created the JDBC-ODBC bridge driver that translates the –
a. ODBC API to JDBC API
b. JDBC API to ODBC API
c. JDBC API to other API
d. None of the above
Ans. B
37. RMI stands for –
a. Remote method invocation
b. Real mechanism interface
c. Remote mechanism interface
d. None of the above
Ans. A
38. JVM stands for –
a. Java virtual mechanism
b. Java virtual machine
c. Java value machine
d. None of the above
Ans. B
39. Local objects are objects that execute on the –
a. Other machine
b. Local machine
c. a & b both
d. None of the above
Ans. B
40. Remote objects are objected that executes on the –
a. Local machine
b. Other machine
c. Both a & b
d. None of the above
Ans. B
41. CORBA stands for –
a. Common object request broker architecture
b. Common object response broke architecture
c. Common object remote broken architecture
d. None of the above
Ans. A
42. Java Beans is the –
a. Software component architecture
b. System component architecture
c. Software common architecture
d. Simple component architecture
Ans. A
43. The bean box allows to –
a. Resize and move beans around
b. Save and restores sets of bean
c. Add new beans from JAR files
d. All of the above
Ans. D
44. Bean obtains all the benefits of Java’s.
a. “Write once, run anywhere”
b. “Read once, run anywhere”
c. Both a and b
d. None of the above
Ans. A
45. JSP stands for –
a. Java standard pages
b. Java servlet pages
c. Java server pages
d. None of the above
Ans. C
46. To test JSP user need a –
a. JSP editor
b. JSP engine
c. Java webserver
d. None of the above
Ans. B
47. JSP looks like HTML – True or False
a. False
b. True
Ans. B
48. ______ are the component of server-side java development.
a. JSP
b. Java servlet
c. Both a & b
d. None of the above
Ans. B
49. JDK stands for –
a. Java developer kit
b. Java decode kit
c. Java development kit
d. None of the above
Ans. C
50. In java, what the use of extends keyword –
a. Access the variables & methods of base class
b. Access the variables & methods of subclass
c. Both a and b
d. None of the above
Ans. A
51. How many types of servlet in java.
a. 1
b. 2
c. 3
d. 4
Ans. B
52. _______ is the result of compiling a java program is interpreted and executed.
a. Java code
b. File name
c. Byte code
d. All of the above
Ans. C
53. Which tool is used when you want to document the java source file with proper comment entries.
a. Java
b. Java
c. Jdb
d. Javadoc
Ans. D
54. Java is the interpreter that is used to execute a compiled java application.
a. True
b. False
Ans. A
55. The javac program is the tool used to convert java files into class files that cannot be run by an interpreter.
a. False
b. True
Ans. A
56. If you need to extract more than one character at a time, you can use one.
a. CharAt ( )
b. getchars ( )
c. getch ( )
d. None of the above
Ans. B
57. Which method returns a copy of the invoking string from which any leading and trailing white space has been removed.
a. Replace( )
b. Contact( )
c. Trim( )
d. None of the above
Ans. C
58. Null pointer exception is thrown when an application attempts to use null where an object is required.
a. True
b. False
Ans. A
59. The code in the final block is not executed regardless of whether an exception is thrown or not.
a. False
b. True
Ans. A
60. The capability of an object to exist beyond the execution of the program that created it is known as.
a. Serialization
b. Persistence
c. Inheritance
d. a and b
Ans. B
61. Public class switch-case
{
public static void main (String ar[] )
int weekday = 3;
switch (weekday)
{
case 1: System.out.println (“Sunday”); break;
case 2: System.out.println (“Monday”); break;
case 3: System.out.println (“Tuesday”); break;
case 4: System.out.println (“Wednesday”); break;
case 5: System.out.println (“Thursday”); break;
case 6: System.out.println (“Friday”); break;
case 7: System.out.println (“Saturday”); break;
default:System.out.println (“Not a valid day”); break;
}
}
}
a. Thursday
b. Saturday
c. Monday
d. Tuesday
Ans. D
62. Class test
{ Public static void main(String ar[] )
{ int i;
for (i = 1; i<=10; j++)
{ system.out.print(i);
}
}
a. Public, i, ;
b. Main, string, j, system
c. Both are a & b
d. None of the above
Ans. B
63. Public class test
{
Public static void main (String arg [] )
{
int n = 4;
int fact = i;
int i = 1
while (i<=n)
{
fact = fact * i
i++;
}
System.out.println (“factorial of “+ n +”is” + fact);
}
}
a. 120
b. 720
c. 24
d. None of the above
Ans. C
64. Class Demo
{
public static void main (string args [])
{
String S1 = “Hi”;
String S2 = “hi”;
Systems.out.print ln (S1 + “equalignorecase” + S2 + “→” + S1.equalignorecase (S2));
System.out.println (S1.equals (S2));
}
}
a. True, false
b. False, true
c. True, true
d. False, false
Ans. A
65. Match the following –
a. Upper a. Extends
b. Concat b. Implements
c. Exception handles c. To uppercase( )
d. Inheritance d. +
e. Interface e. Try, catch
a. d, e, a, b, c
b. e, d, b, a, c
c. c, d, e, a, b
d. None of the above
Ans. C
66. Define the steps of the applet life cycle.
a. stop( ), start( ), init( ), destroy( ).
b. init( ), stop( ), start( ), destroy( ).
c. start( ), init( ), destroy( ), stop( ).
d. init( ), start( ), stop( ), destroy( ).
Ans. D
67. Steps in the servlet life cycle
a. Create, load, servlet request, select servlet instance, select. service method, wait for next request, destroy ( ), unload
b. Select servlet instance, load the servlet, create, select request, wait, unload.service ( ) method
c. Server load, servlet create, init ( ), servlet request, select servlet instance, select service method, wait, unload
d. None of the above
Ans. C
68. Keyword used in exception – handling are –
a. try, final, catch
b. try, static, finally
c. try, catch, finally
d. final, caught, try
Ans. C
69. Variable can be declared inside of interface declarations. They are implicitly final and static, meaning they cannot be changed by the implementing class.
a. True
b. False
Ans. A
70. Find the output of the following program
class demo1
{
public static void main (String a [])
{
String s = “Now is the time for all good men” + “to come to the aid of their country.”;
System.out.println (“indexOf(t)= ” + s.indexOf(‘t’));
System.out.println (“lastIndexOf (t) = ”+ s.lastIndexOf(‘t’));
}
}
a. 8,62
b. 9,60
c. 7,65
d. 11,55
Ans. C
71. find o/p
class getchars
{
public static void main (String ar[])
{
String s = “this is a demo of the get chars method”;
int start = 10;
int end = 14;
char buf [] = new char [end – start];
s.getchars (start, end, buf, 0);
System.out.println (buf);
}
}
a. of
b. the
c. demo
d. b & c
Ans. C
72. find error
class demo3
{
public static void main (String a[])
{
char chars [] = { “a”, “b”, “c” };
String s = new String (“char”);
System.out.println (s.length);
}
}
a. char
b. system. out
c. “ ”, ‘’
d. ‘ ‘, string. length ( )
Ans. D
73. find o/p
class abc
{
public static void main (String as[])
{
Char ch[ ] = {‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’}
String s = new string (ch, 2, 3);
System.out.println (s);
}
}
a. b, c, d
b. c, d, e
c. d, e, f
d. a, b, c
Ans. B
74. What is the o/p of the following code:-
public class TX
{
public static void main (String ar[ ] )
{ int a = 5, b=5, c, d;
c = a++;
System.outprintln (“a = “+a+”c=”+c);
d = ++b;
System.out.println(“b = “+b+”d = “+d);
}
}
a. 7, 6
5, 5
b. 5, 6
6, 6
c. 6, 5
6, 6
d. 4, 4
5, 4
Ans. C
75. Match the following –
a. a kind of a. Driver
b. Boolean b. RMI
c. JDB ODBC bridge c. Relationship
d. Print writer d. Data type
e. Remote object e. Get a writer
(a). a, c, b, d, e
(b). c, d, a, e, b
(c). e, c, b, d, e
(d). b, c, a, d, e
Ans. B
Download Java Programming MCQs Sample Question Paper in Pdf
Java Programming MCQ Questions and Answers: Set-2
C Programming and Data Structure MCQ Test Paper – II
Thanks for visiting our website, if you have any query regarding our MCQs services, please comment using the below comment box.