0% found this document useful (0 votes)
60 views

Contents For Java Learning

This document contains 100 topics related to Java programming language MCQs. The topics cover fundamental Java concepts like data types, operators, control statements, classes, objects, inheritance, exceptions, files and streams, multithreading, collections, and more. Each topic contains sample MCQs to test knowledge of that topic.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Contents For Java Learning

This document contains 100 topics related to Java programming language MCQs. The topics cover fundamental Java concepts like data types, operators, control statements, classes, objects, inheritance, exceptions, files and streams, multithreading, collections, and more. Each topic contains sample MCQs to test knowledge of that topic.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

MCQ in Java

Contents
Topics in Java

1. Integer and Floating Data Types -LF 36. Java.io Character Streams
2. Character and Boolean Data Types -LF 37. Serialization
3. Literals & Variables-LF 38. Serialization & Deserialization
4. Type Conversions, Promotions and Castings 39. Networking Basics
5. Arrays 40. URL class
6. Arithmetic Operators -OA 41. HttpResponse & URLConnection Class
7. Bitwise Operators-OA 42. networking - Server, Sockets & httpd Class
8. Relational Operators and Boolean Logic 43. networking - httpd.java Class
Operators-OA 44. networking - Datagrams
9. Assignment Operators and Operator 45. Java.util - ArrayList Class
Precedence-OA 46. Java.util - LinkedList, HashSet & TreeSet
10. Control Statements Class
11. Class Fundamentals & Declaring objects 47. Java.util - Maps
12. Introduction to Methods 48. Java.util - Array Class
13. Constructors & Garbage Collection 49. Java.util - Vectors & Stack
14. Overloading Methods & Argument Passing 50. Java.util - Dictionary, Hashtable &
15. Access Control Properties
16. 51. Java.util - BitSet & Date class
17. Arrays Revisited & Keyword static 52. Methods Taking Parameters
18. String Class 53. Exceptional Handling Basics
19. Inheritance 54. Exceptions Types
20. Method overriding 55. Throw, Throws & Nested Try
21. The Object Class 56. isAlive(), Join() & Thread Synchronization
22. String Handling Basics 57. Implementing Runnable interface for
23. Character Extraction Threads
24. String Comparison 58. Thread class
25. Searching & Modifying a String 59. Multithreading Basics
26. StringBuffer class 60. Networking Basics
27. StringBuffer Methods 61. Finally & Built in Exceptions
28. Packages 62. Creating Threads
29. Interfaces 63. Input & Output Basics
30. Java.lang Introduction 64. Reading Console Input
31. Java.lang - Integer, Long And Character 65. Writing Console Output
Wrappers 66. Reading & Writing Files
32. Java.lang - Void, Process and System Class  67. Applets Fundamentals
33. Java.lang - Object & Math Class 68. Core Java API Packages
34. Java.io Introduction 69. Remote Method Invocation (RMI)
35. Java.io Byte Streams 70. Text Formatting

1
71. Event Handling Basics 84. Java.lang - Runtime & ClassLoader Classes
72. ActionEvent & AdjustmentEvent Class 85. java.lang - Class
73. ComponentEvent, ContainerEvent & 86. Collection Framework Overview
FocusEvent Class 87. Collections Interface
74. MouseEvent, TextEvent & WindowEvent 88. Collection Algorithms
Class 89. Iterators
75. Event Listeners Interfaces 90. Locale & Random Classes
76. Java.lang - Rounding Functions 91. Observable & Timer Class
77. Java.lang - Miscellaneous Math Methods & 92. Restrictions On Generics
StrictMath Class
93. WildcardsRecursion
78. Java.lang - ThreadGroup class & Runnable
94. Command Line Arguments
Interface
79. Java.lang - System Class Advance 95. Inheritance - Abstract Class and Super
96. Try & Catch
80. Java.lang - Double & Float Wrappers
81. Java.lang - Byte & Short Wrappers
97. Creating Exceptions
98. Generics
82. Java.lang - Character Wrapper Advance
83. Java.lang - Boolean Wrapper Advance
99. Generic Methods
100. Type Interface

2
3
Topic -5 Arrays

This section of our 1000+ Java MCQs focuses on Array Data Structure of Java Programming Language.
1. Which of these operators is used to allocate memory to array variable in Java?
a) malloc
b) alloc
c) new
d) new malloc
View Answer

Answer:c
Explanation:Operator new allocates block of memory specified by the size of array, and gives the reference of
memory allocated to the array variable.
2. Which of these is an incorrect array declaration?
a) int arr[] = new int[5]
b) int [] arr = new int[5]
c) int arr[]
arr = new int[5]
d) int arr[] = int [5] new
View Answer

Answer:d
Explanation:Operator new must be succeeded by array type and array size.
3. What will this code print?
int arr[] = new int [5];
System.out.print(arr);
a) 0
b) value stored in arr[0].
c) 00000
d) Garbage value
View Answer

Answer:d
Explanation:arr is an array variable, it is pointing to array if integers. Printing arr will print garbage value. It is not
same as printing arr[0].
4. Which of these is an incorrect Statement?
a) It is necessary to use new operator to initialize an array.
b) Array can be initialized using comma separated expressions surrounded by curly braces.

4
c) Array can be initialized when they are declared.
d) None of the mentioned
View Answer

Answer: a
Explanation:Array can be initialized using both new and comma separated expressions surrounded by curly braces
example : int arr[5] = new int[5]; and int arr[] = { 0, 1, 2, 3, 4};
5. Which of these is necessary to specify at time of array initialization?
a) Row
b) Column
c) Both Row and Column
d) None of the mentioned
View Answer

Answer:a
Explanation:None.
6. What is the output of this program?

1. class array_output {
2. public static void main(String args[])
3. {
4. int array_variable [] = new int[10];
5. for (int i = 0; i < 10; ++i) {
6. array_variable[i] = i;
7. System.out.print(array_variable[i] + " ");
8. i++;
9. }
10. }
11. }
a) 0 2 4 6 8
b) 1 3 5 7 9
c) 0 1 2 3 4 5 6 7 8 9
d) 1 2 3 4 5 6 7 8 9 10
View Answer

Answer:a
Explanation:When an array is declared using new operator then all of its elements are initialized to 0 automatically.
for loop body is executed 5 times as whenever controls comes in the loop i value is incremented twice, first by i++
in body of loop then by ++i in increment condition of for loop.
output:
$ javac array_output.java

5
$ java array_output
02468
7. What is the output of this program?

1. class multidimention_array {
2. public static void main(String args[])
3. {
4. int arr[][] = new int[3][];
5. arr[0] = new int[1];
6. arr[1] = new int[2];
7. arr[2] = new int[3];
8. int sum = 0;
9. for (int i = 0; i < 3; ++i)
10. for (int j = 0; j < i + 1; ++j)
11. arr[i][j] = j + 1;
12. for (int i = 0; i < 3; ++i)
13. for (int j = 0; j < i + 1; ++j)
14. sum + = arr[i][j];
15. System.out.print(sum);
16. }
17. }
a) 11
b) 10
c) 13
d) 14
View Answer

Answer:b
Explanation:arr[][] is a 2D array, array has been allotted memory in parts. 1st row contains 1 element, 2nd row
contains 2 elements and 3rd row contains 3 elements. each element of array is given i + j value in loop. sum contains
addition of all the elements of the array.
output:
$ javac multidimention_array.java
$ java multidimention_array
10
8. What is the output of this program?

1. class evaluate {
2. public static void main(String args[])
3. {
4. int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9};
5. int n = 6;
6. n = arr[arr[n] / 2];

6
7. System.out.println(arr[n] / 2);
8. }
9. }
a) 3
b) 0
c) 6
d) 1
View Answer

Answer:d
Explanation:Array arr contains 10 elements. n contains 6 thus in next line n is given value 2 printing arr[2]/2 i:e 2/2
= 1.
output:
$ javac evaluate.java
$ java evaluate
1
9. What is the output of this program?

1. class array_output {
2. public static void main(String args[])
3. {
4. char array_variable [] = new char[10];
5. for (int i = 0; i < 10; ++i) {
6. array_variable[i] = 'i';
7. System.out.print(array_variable[i] + "");
8. }
9. }
10. }
a) 1 2 3 4 5 6 7 8 9 10
b) 0 1 2 3 4 5 6 7 8 9 10
c) i j k l m n o p q r
d) i i i i i i i i i i
View Answer

Answer:d
Explanation:None.
output:
$ javac array_output.java
$ java array_output
iiiiiiiiii
10. What is the output of this program?

7
1. class array_output {
2. public static void main(String args[])
3. {
4. int array_variable[][] = {{ 1, 2, 3}, { 4 , 5, 6}, { 7, 8, 9}};
5. int sum = 0;
6. for (int i = 0; i < 3; ++i)
7. for (int j = 0; j < 3 ; ++j)
8. sum = sum + array_variable[i][j];
9. System.out.print(sum / 5);
10. }
11. }
a) 8
b) 9
c) 10
d) 11
View Answer

Answer:b
Explanation:None.
output:
$ javac array_output.java
$ java array_output
9

You might also like