Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
102 views67 pages

Java MCQ

The document is a collection of multiple-choice questions (MCQs) related to Java programming, covering various topics such as Java features, data types, OOP concepts, and exception handling. Each question is followed by the correct answer, providing a comprehensive review for learners. The document spans 67 pages and includes a wide range of questions to test knowledge in Java.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views67 pages

Java MCQ

The document is a collection of multiple-choice questions (MCQs) related to Java programming, covering various topics such as Java features, data types, OOP concepts, and exception handling. Each question is followed by the correct answer, providing a comprehensive review for learners. The document spans 67 pages and includes a wide range of questions to test knowledge in Java.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

Page 1 of 67

JAVA M.C.Q
1. Who invented Java Programming?
a) Guido van Rossum
b) James Gosling
c) Dennis Ritchie
d) Bjarne Stroustrup
Ans: b) James Gosling
2. Which statement is true about Java?
a) Java is a sequence-dependent programming language
b) Java is a code dependent programming language
c) Java is a platform-dependent programming language
d) Java is a platform-independent programming language

Ans : d) Java is a platform-independent programming language

3. Which component is used to compile, debug and execute the java programs?
a) JRE
b) JIT
c) JDK
d) JVM
ans: c) JDK

4. Which one of the following is not a Java feature?


a) Object-oriented
b) Use of pointers
c) Portable
d) Dynamic and Extensible
ans: b) Use of pointers

5. Which of these cannot be used for a variable name in Java?


a) identifier & keyword
b) identifier
c) keyword
d) none of the mentioned

Ans: c) keyword

6. What is the extension of java code files?


a) .js
b) .txt
c) .class
d) .java

Ans: d) .java
Page 2 of 67

7. Which environment variable is used to set the java path?


a) MAVEN_Path
b) JavaPATH
c) JAVA
d) JAVA_HOME

Ans: d) JAVA_HOME

8. Which of the following is not an OOPS concept in Java?


a) Polymorphism
b) Inheritance
c) Compilation
d) Encapsulation
ans: c) Compilation

11. What is not the use of “this” keyword in Java?


a) Referring to the instance variable when a local variable has the same name
b) Passing itself to the method of the same class
c) Passing itself to another method
d) Calling another constructor in constructor chaining

Ans : b) Passing itself to the method of the same class

12. Which of the following is a type of polymorphism in Java Programming?


a) Multiple polymorphism
b) Compile time polymorphism
c) Multilevel polymorphism
d) Execution time polymorphism

Ans : b) Compile time polymorphism

13. What is Truncation in Java?


a) Floating-point value assigned to a Floating type
b) Floating-point value assigned to an integer type
c) Integer value assigned to floating type
d) Integer value assigned to floating type

Ans : b) Floating-point value assigned to an integer type

14. What is the extension of compiled java classes?


a) .txt
b) .js
c) .class
d) .java
ans : c) .class

15. Which exception is thrown when java is out of memory?


a) MemoryError
Page 3 of 67

b) OutOfMemoryError
c) MemoryOutOfBoundsException
d) MemoryFullException

Ans: b) OutOfMemoryError

16. Which of these are selection statements in Java?


a) break
b) continue
c) for()
d) if().

17. Which of these keywords is used to define interfaces in Java?


a) intf
b) Intf
c) interface
d) Interface

18. Which of the following is a superclass of every class in Java?


a) ArrayList
b) Abstract class
c) Object class
d) String

19. Which of the below is not a Java Profiler?


a) JProfiler
b) Eclipse Profiler
c) JVM
d) JConsole

20. Which of these packages contains the exception Stack Overflow


in Java?
a) java.io
b) java.system
c) java.lang
d) java.util

21. Which of the following option leads to the portability and


security of Java?

A. Bytecode is executed by JVM

B. The applet makes the Java code secure and portable


Page 4 of 67

C. Use of exception handling

D. Dynamic binding between objects

22. Which of the following is not a Java features?

A. Dynamic

B. Architecture Neutral

C. Use of pointers

D. Object-oriented

23. The \u0021 article referred to as a

A. Unicode escape sequence

B. Octal escape

C. Hexadecimal

D. Line feed

24. _____ is used to find and fix bugs in the Java programs.

a. JVM

b. JRE

c. JDK

d. JDB

25. Which of the following is a valid declaration of a char?

a. char ch = '\utea';

b. char ca = 'tea';

c. char cr = \u0223;
Page 5 of 67

d. char cc = '\itea';

26. What is the return type of the hashCode() method in the Object class?

a. Object

b. int

c. long

d. void

27. Which of the following is a valid long literal?

a. ABH8097

b. L990023

c. 904423

d. 0xnf029L

28. What does the expression float a = 35 / 0 return?

a. 0

b. Not a Number

c. Infinity

d. Run time exception

29. Evaluate the following Java expression, if x=3, y=5, and z=10:

++z + y - y + z + x++

a. 24

b. 23
Page 6 of 67

c. 20

d. 25

30. Which of the following tool is used to generate API documentation in HTML
format from doc comments in source code?

a. javap tool

b. javaw command

c. Javadoc tool

d. javah command

31. Which of the following creates a List of 3 visible items and multiple
selections abled?

a. new List(false, 3)

b. new List(3, true)

c. new List(true, 3)

d. new List(3, false)

32. Which of the following for loop declaration is not valid?

a. for ( int i = 99; i >= 0; i / 9 )

b. for ( int i = 7; i <= 77; i += 7 )

c. for ( int i = 20; i >= 2; - -i )

d. for ( int i = 2; i <= 20; i = 2* i )

33. Which method of the Class.class is used to determine the name of a class
represented by the class object as a String?
Page 7 of 67

a. getClass()

b. intern()

c. getName()

d. toString()

34. In which process, a local variable has the same name as one of the instance
variables?

a. Serialization

b. Variable Shadowing

c. Abstraction

d. Multi-threading

35. Which of the following is true about the anonymous inner class?

a. It has only methods

b. Objects can't be created

c. It has a fixed class name

d. It has no class name

36. Which package contains the Random class?

a. java.util package

b. java.lang package

c. java.awt package

d. java.io package

37. What do you mean by nameless objects?


Page 8 of 67

a. An object created by using the new keyword.

b. An object of a superclass created in the subclass.

c. An object without having any name but having a reference.

d. An object that has no reference.

38. An interface with no fields or methods is known as a ______.

a. Runnable Interface

b. Marker Interface

c. Abstract Interface

d. CharSequence Interface

39. Which of the following is an immediate subclass of the Panel class?

a. Applet class

b. Window class

c. Frame class

d. Dialog class

40. Which option is false about the final keyword?

a. A final method cannot be overridden in its subclasses.

b. A final class cannot be extended.

c. A final class cannot extend other classes.

d. A final method can be inherited.

41. Which of these classes are the direct subclasses of the Throwable class?
Page 9 of 67

a. RuntimeException and Error class

b. Exception and VirtualMachineError class

c. Error and Exception class

d. IOException and VirtualMachineError class

42. What do you mean by chained exceptions in Java?

a. Exceptions occurred by the VirtualMachineError

b. An exception caused by other exceptions

c. Exceptions occur in chains with discarding the debugging information

d. None of the above

43. In which memory a String is stored, when we create a string using new
operator?

a. Stack

b. String memory

c. Heap memory

d. Random storage space

44. What is the use of the intern() method?

a. It returns the existing string from memory

b. It creates a new string in the database

c. It modifies the existing string in the database

d. None of the above

45. Which of the following is a marker interface?


Page 10 of 67

a. Runnable interface

b. Remote interface

c. Readable interface

d. Result interface

46. Which of the following is a reserved keyword in Java?

a. object

b. strictfp

c. main

d. system

Show Answer Workspace

47. Which keyword is used for accessing the features of a package?

a. package

b. import

c. extends

d. export

48. In java, jar stands for_____.

a. Java Archive Runner

b. Java Application Resource

c. Java Application Runner


Page 11 of 67

d. None of the above

49. Which of the following is false?

a. The rt.jar stands for the runtime jar

b. It is an optional jar file

c. It contains all the compiled class files

d. All the classes available in rt.jar is known to the JVM

50. What is the use of \w in regex?

a. Used for a whitespace character

b. Used for a non-whitespace character

c. Used for a word character

d. Used for a non-word character

51. Which of the given methods are of Object class?

a. notify(), wait( long msecs ), and synchronized()

b. wait( long msecs ), interrupt(), and notifyAll()

c. notify(), notifyAll(), and wait()

d. sleep( long msecs ), wait(), and notify()

52. Which of the following is a valid syntax to synchronize the HashMap?

a. Map m = hashMap.synchronizeMap();

b. HashMap map =hashMap.synchronizeMap();

c. Map m1 = Collections.synchronizedMap(hashMap);
Page 12 of 67

d. Map m2 = Collection.synchronizeMap(hashMap);

53. Which of the following is a mutable class in java?

a. java.lang.String

b. java.lang.Byte

c. java.lang.Short

d. java.lang.StringBuilder

54. What is meant by the classes and objects that dependents on each other?

a. Tight Coupling

b. Cohesion

c. Loose Coupling

d. None of the above

55. Which of the following code segment would execute the stored procedure
"getPassword()" located in a database server?

a. CallableStatement cs = connection.prepareCall("{call.getPassword()}");

cs.executeQuery();

b. CallabledStatement callable = conn.prepareCall("{call getPassword()}");

callable.executeUpdate();

c. CallableStatement cab = con.prepareCall("{call getPassword()}");

cab.executeQuery();
Page 13 of 67

d. Callablestatement cstate = connect.prepareCall("{call getpassword()}");

cstate.executeQuery();

56. How many threads can be executed at a time?

a. Only one thread

b. Multiple threads

c. Only main (main() method) thread

d. Two threads

57. If three threads trying to share a single object at the same time, which
condition will arise in this scenario?

a. Time-Lapse

b. Critical situation

c. Race condition

d. Recursion

58. If a thread goes to sleep

a. It releases all the locks it has.

b. It does not release any locks.

c. It releases half of its locks.

d. It releases all of its lock except one.

59. Which of the following modifiers can be used for a variable so that it can be
accessed by any thread or a part of a program?

a. global
Page 14 of 67

b. transient

c. volatile

d. default

60. In character stream I/O, a single read/write operation performs _____.

a. Two bytes read/write at a time.

b. Eight bytes read/write at a time.

c. One byte read/write at a time.

d. Five bytes read/ write at a time.

61. What is the default encoding for an OutputStreamWriter?

a. UTF-8

b. Default encoding of the host platform

c. UTF-12

d. None of the above

62. Which of these statements is incorrect about Thread?


a) start() method is used to begin execution of the thread
b) run() method is used to begin execution of a thread before start()
method in special cases
c) A thread can be formed by implementing Runnable interface only
d) A thread can be formed by a class that extends Thread class

63. Which of these keywords are used for the block to be examined
for exceptions?
a) check
Page 15 of 67

b) throw
c) catch
d) try

64. Which one of the following is not an access modifier?

a) Protected

b) Void

c) Public

d) Private

65. What is the numerical range of a char data type in Java?


a) 0 to 256
b) -128 to 127
c) 0 to 65535
d) 0 to 32767

66. Which class provides system independent server side


implementation?
a) Server
b) ServerReader
c) Socket
d) ServerSocket

67. Which of the following is true about servlets?

a) Servlets can use the full functionality of the Java class libraries
Page 16 of 67

b) Servlets execute within the address space of web server,


platform independent and uses the functionality of java class
libraries

c) Servlets execute within the address space of web server

d) Servlets are platform-independent because they are written in java

68.What is the range of short data type in Java?


a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
d) None of the mentioned

69. What is the range of byte data type in Java?


a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
d) None of the mentioned

70. An expression involving byte, int, and literal numbers is


promoted to which of these?
a) int
b) long
c) byte
d) float

71. Which of these literals can be contained in float data type


variable?
Page 17 of 67

a) -1.7e+308
b) -3.4e+038
c) +1.7e+308
d) -3.4e+050

72. Which data type value is returned by all transcendental math


functions?

a) int

b) float

c) double

d) long

73. What is the numerical range of a char data type in Java?

a) -128 to 127

b) 0 to 256

c) 0 to 32767

d) 0 to 65535

74. Which of these coding types is used for data type characters in
Java?

a) ASCII

b) ISO-LATIN-1
Page 18 of 67

c) UNICODE

d) None of the mentioned

75. Which of these values can a boolean variable contain?


a) True & False
b) 0 & 1
c) Any integer value
d) true

76. Which of these occupy first 0 to 127 in Unicode character set


used for characters in Java?
a) ASCII
b) ISO-LATIN-1
c) None of the mentioned
d) ASCII and ISO-LATIN1

77. Which one is a valid declaration of a boolean?

a) boolean b1 = 1;

b) boolean b2 = ‘false’;

c) boolean b3 = false;

d) boolean b4 = ‘true’

78. What is the order of variables in Enum?


a) Ascending order
b) Descending order
Page 19 of 67

c) Random order
d) Depends on the order() method

79. Can we create an instance of Enum outside of Enum itself?


a) True
b) False

80. If we try to add Enum constants to a TreeSet, what sorting order


will it use?

a) Sorted in the order of declaration of Enums

b) Sorted in alphabetical order of Enums

c) Sorted based on order() method

d) Sorted in descending order of names of Enums

81. Which method returns the elements of Enum class?


a) getEnums()
b) getEnumConstants()
c) getEnumList()
d) getEnum()

82. Which class does all the Enums extend?


a) Object
b) Enums
c) Enum
d) EnumClass
Page 20 of 67

83. Are enums are type-safe?


a) True
b) False

84. Which of the following is the advantage of BigDecimal over


double?

a) Syntax

b) Memory usage

c) Garbage creation

d) Precision

85. Which of the below data type doesn’t support overloaded


methods for +,-,* and /?

a) int

b) float

c) double

d) BigDecimal

86. What is the base of BigDecimal data type?

a) Base 2

b) Base 8
Page 21 of 67

c) Base 10

d) Base e

87. What is the limitation of toString() method of BigDecimal?


a) There is no limitation
b) toString returns null
c) toString returns the number in expanded form
d) toString uses scientific notation

88. Which of the following is not provided by BigDecimal?


a) scale manipulation
b) + operator

c) rounding
d) hashing

89. BigDecimal is a part of which package?


a) java.lang
b) java.math
c) java.util
d) java.io

90. What is BigDecimal.ONE?


a) wrong statement
b) custom defined statement
c) static variable with value 1 on scale 10
d) static variable with value 1 on scale 0
Page 22 of 67

91. Which class is a library of functions to perform arithmetic


operations of BigInteger and BigDecimal?
a) MathContext
b) MathLib
c) BigLib
d) BigContext

92. How to format date from one form to another?

a) SimpleDateFormat

b) DateFormat

c) SimpleFormat

d) DateConverter

93. Is SimpleDateFormat thread safe?


a) True
b) False

94. How to identify if a timezone is eligible for DayLight Saving?


a) useDaylightTime() of Time class
b) useDaylightTime() of Date class
c) useDaylightTime() of TimeZone class
d) useDaylightTime() of DateTime class

95. What is the replacement of joda time library in java 8?


a) java.time (JSR-310)
b) java.date (JSR-310)
Page 23 of 67

c) java.joda
d) java.jodaTime

96. How is Date stored in database?


a) java.sql.Date
b) java.util.Date
c) java.sql.DateTime
d) java.util.DateTime

97. What does LocalTime represent?


a) Date without time
b) Time without Date
c) Date and Time
d) Date and Time with timezone

98. How to get difference between two dates?


a) long diffInMilli = java.time.Duration.between(dateTime1,
dateTime2).toMillis();
b) long diffInMilli = java.time.difference(dateTime1, dateTime2).toMillis();
c) Date diffInMilli = java.time.Duration.between(dateTime1,
dateTime2).toMillis();
d) Time diffInMilli = java.time.Duration.between(dateTime1,
dateTime2).toMillis();

99. How to get UTC time?


a) Time.getUTC();
b) Date.getUTC();
c) Instant.now();
d) TimeZone.getUTC();
Page 24 of 67

100. Which of these is long data type literal?

a) 0x99fffL

b) ABCDEFG

c) 0x99fffa

d) 99671246

101. Which of these can be returned by the operator &?


a) Integer
b) Boolean
c) Character
d) Integer or Boolean

102. Literals in java must be appended by which of these?


a) L
b) l
c) D
d) L and I

103 .Literal can be of which of these data types?


a) integer
b) float
c) boolean
d) all of the mentioned

104. Which of these can not be used for a variable name in Java?
a) identifier
Page 25 of 67

b) keyword
c) identifier & keyword
d) none of the mentioned

105. Which of these is necessary condition for automatic type


conversion in Java?

a) The destination type is smaller than source type

b) The destination type is larger than source type

c) The destination type can be larger or smaller than source type

d) None of the mentioned

106. If an expression contains double, int, float, long, then the


whole expression will be promoted into which of these data types?
a) long
b) int
c) double
d) float

107. What is Truncation in Java?


a) Floating-point value assigned to an integer type
b) Integer value assigned to floating type
c) Floating-point value assigned to a Floating type
d) Integer value assigned to an integer type

108. Which of these operators is used to allocate memory to array


variable in Java?
Page 26 of 67

a) malloc

b) alloc

c) new

d) new malloc

109. Which of these is an incorrect array declaration?

a) int arr[] = new int[5]

b) int [] arr = new int[5]

c) int arr[] = new int[5]

d) int arr[] = int [5] new

110. 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

c) Array can be initialized when they are declared

d) None of the mentioned

111. Which of these is necessary to specify at time of array


initialization?
Page 27 of 67

a) Row

b) Column

c) Both Row and Column

d) None of the mentioned

112. Generics does not work with?


a) Set
b) List
c) Tree
d) Array

113. How to sort an array?


a) Array.sort()
b) Arrays.sort()
c) Collection.sort()
d) System.sort()

114. How to copy contents of array?


a) System.arrayCopy()
b) Array.copy()
c) Arrays.copy()
d) Collection.copy()

115. Can you make an array volatile?


a) True
b) False
Page 28 of 67

116. Where is an array stored in memory?


a) heap space
b) stack space
c) heap space and stack space
d) first generation memory

117. An array elements are always stored in ________ memory


locations.
a) Sequential
b) Random
c) Sequential and Random
d) Binary search

118. Which of the following can be operands of arithmetic


operators?

a) Numeric

b) Boolean

c) Characters

d) Both Numeric & Characters

119. Modulus operator, %, can be applied to which of these?

a) Integers

b) Floating – point numbers

c) Both Integers and floating – point numbers


Page 29 of 67

d) None of the mentioned

120. Decrement operator, −−, decreases the value of variable by

what number?

a) 1
b) 2
c) 3
d) 4

121. Which of these statements are incorrect?


a) Assignment operators are more efficiently implemented by Java run-
time system than their equivalent long forms
b) Assignment operators run faster than their equivalent long forms
c) Assignment operators can be used only with numeric and character
data type
d) None of the mentioned

122. Can 8 byte long data type be automatically type cast to 4 byte
float data type?

a) True

b) False

123. Which of these is not a bitwise operator?

a) &

b) &=
Page 30 of 67

c) |=

d) <=

124. Which operator is used to invert all the digits in a binary


representation of a number?
a) ~
b) <<<
c) >>>
d) ^

125. On applying Left shift operator, <<, on integer bits are lost one
they are shifted past which position bit?
a) 1
b) 32
c) 33
d) 31

126. Which right shift operator preserves the sign of the value?
a) <<
b) >>
c) <<=
d) >>=

127. Which of these statements are incorrect?


a) The left shift operator, <<, shifts all of the bits in a value to the left
specified number of times
Page 31 of 67

b) The right shift operator, >>, shifts all of the bits in a value to the right
specified number of times
c) The left shift operator can be used as an alternative to multiplying by 2
d) The right shift operator automatically fills the higher order bits
with 0

128. What is the output of relational operators?

a) Integer

b) Boolean

c) Characters

d) Double

129. Which of these is returned by “greater than”, “less than” and


“equal to” operators?

a) Integers

b) Floating – point numbers

c) Boolean

d) None of the mentioned

130. Which of these operators can skip evaluating right hand


operand?
a) !
b) |
Page 32 of 67

c) &
d) &&

131. Which of these statements is correct?


a) true and false are numeric values 1 and 0
b) true and false are numeric values 0 and 1
c) true is any non zero value and false is 0
d) true and false are non numeric values

132. Which of these have highest precedence?

a) ()

b) ++

c) *

d) >>

133. Which of these statements are incorrect?

a) Equal to operator has least precedence

b) Brackets () have highest precedence

c) Division operator, /, has higher precedence than multiplication


operator

d) Addition operator, +, and subtraction operator have equal precedence

134. Which of these selection statements test only for equality?


Page 33 of 67

a) if

b) switch

c) if & switch

d) none of the mentioned

135. Which of these are selection statements in Java?


a) if()
b) for()
c) continue
d) break

136. Which of the following loops will execute the body of loop
even when condition controlling the loop is initially false?
a) do-while
b) while
c) for
d) none of the mentioned

137. Which of these jump statements can skip processing the


remainder of the code in its body for a particular iteration?
a) break
b) return
c) exit
d) continue

138. Which of this statement is incorrect?


a) switch statement is more efficient than a set of nested ifs
Page 34 of 67

b) two case constants in the same switch can have identical values
c) switch statement can only test for equality, whereas if statement can
evaluate any type of boolean expression
d) it is possible to create a nested switch statements

139. The while loop repeats a set of code while the condition is not
met?
a) True
b) False

140. What is true about a break?


a) Break stops the execution of entire program
b) Break halts the execution and forces the control out of the loop
c) Break forces the control out of the loop and starts the execution of
next iteration
d) Break halts the execution of the loop for certain time frame

141. What is true about do statement?


a) do statement executes the code of a loop at least once
b) do statement does not get execute if condition is not matched in the
first iteration
c) do statement checks the condition at the beginning of the loop
d) do statement executes the code more than once always

142. Which of the following is used with the switch statement?


a) Continue
b) Exit
c) break
d) do
Page 35 of 67

143. Which of the following is not a decision making statement?


a) if
b) if-else
c) switch
d) do-while

144. Which of the following is not a valid jump statement?


a) break
b) goto
c) continue
d) return

145. From where break statement causes an exit?


a) Only from innermost loop
b) Terminates a program
c) Only from innermost switch
d) From innermost loops or switches

146. Which of the following is not a valid flow control statement?


a) exit()
b) break
c) continue
d) return

147. Which of the following is not OOPS concept in Java?


a) Inheritance
b) Encapsulation
c) Polymorphism
d) Compilation
Page 36 of 67

148. Which of the following is a type of polymorphism in Java?


a) Compile time polymorphism
b) Execution time polymorphism
c) Multiple polymorphism
d) Multilevel polymorphism

149. When does method overloading is determined?


a) At run time
b) At compile time
c) At coding time
d) At execution time

150. When Overloading does not occur?


a) More than one method with same name but different method
signature and different number or type of parameters
b) More than one method with same name, same signature but different
number of signature
c) More than one method with same name, same signature, same
number of parameters but different type
d) More than one method with same name, same number of
parameters and type but different signature

151. Which type of JavaScript language is ___


a) Object-Oriented
b) Object-Based
c) Assembly-language
d) High-level
Ans : Object-Based

152. Which one of the following also known as Conditional Expression:


Page 37 of 67

a) Alternative to if-else
b) Switch statement
c) If-then-else statement
d) immediate if
ans : immediate if

153. In JavaScript, what is a block of statement?


a) Conditional block
b) block that combines a number of statements into a single compound
statement
c) both conditional block and a single statement
d) block that contains a single statement
ans : block that combines a number of statements into a single compound
statement

154. When interpreter encounters an empty statements, what it will do:


a) Shows a warning
b) Prompts to complete the statement
c) Throws an error
d) Ignores the statements
Ans : Ignores the statements.

155. The "function" and " var" are known as:


a) Keywords
b) Data types
c) Declaration statements
d) Prototypes
Ans : Declaration statements

156. Which of the following variables takes precedence over the others if the
names are the same?
a) Global variable
b) The local element
c) The two of the above
d) None of the above
Page 38 of 67

Ans : The local element

157. Which one of the following is the correct way for calling the JavaScript
code?
a) Preprocessor
b) Triggering Event
c) RMI
d) Function/Method
Ans : Function/Method

158. Which of the following type of a variable is volatile?


a) Mutable variable
b) Dynamic variable
c) Volatile variable
d) Immutable variable
Ans : Mutable variable

159. What is BigDecimal.ONE?


a. it is a custom-defined statement
b. it is a wrong statement
c. it is a static variable that has a value of 1 on a scale of 0
d. it is a static variable that has a value of 1 on a scale of 10
Answer: (c) it is a static variable that has a value of 1 on a scale of 0

160. Which of the following operators can operate on a boolean variable?


A. &&
B. ==
C. ?:
D. +=
a) C & B
b) A & D
c) A, B & D
d) A, B & C
Answer: (d) A, B & C
Page 39 of 67

161. When does Overloading not occur?


a. When more than a single method have the same name, yet different types
or number of parameters and different method signature
b. When more than a single method have the same name, the same signature,
but have different numbers of signature
c. When more than a single method have the same signature, same name, and
the same number of parameters have different types
d. When more than a single method have the same name, the same number
and types of parameters, and yet different signatures
Answer: (d) When more than a single method have the same name, the same
number and types of
parameters, and yet different signatures

162. What is it called when the child object also gets killed when the parent
object is killed in the program?
a. Encapsulation
b. Association
c. Aggregation
d. Composition
Answer: (d) Composition

163. On which platforms Java runs?


(A) Windows
(B) Mac OS
(C) UNIX
(D) All of these
Ans : (D) All of these

164. Java program processing always starts with main() method


(A) True
(B) False
Ans : (A) True

165. Java is case sensitive language


Page 40 of 67

(A) True
(B) False
Ans : (A) True

166. Which of the following option leads to the portability and security of
Java?
a) Bytecode is executed by JVM
b) The applet makes the Java code secure and portable
c) Use of exception handling
d) Dynamic binding between objects
Ans : Bytecode is executed by JVM

167. Out of these methods of the String class, which one can be used for
testing the strings for equality?
a. isequals()
b. isequal()
c. equals()
d. equal()
Answer: (c) equals()

168. What would happen to the thread whenever the garbage collection kicks
off?
a. The garbage collection won’t happen until the running of the thread
b. The thread would continue its operation
c. The garbage collection and the thread don’t interfere with each other
d. The thread would be paused while the running of the garbage collection
Answer: (d) The thread would be paused while the running of the garbage
collection

169. Out of these, which one is the correct way of calling a constructor that
has no parameters of the superclass A by the subclass B?
a. superclass.();
b. super(void);
c. super();
d. super.A();
Page 41 of 67

Answer: (c) super();

170. Out of these methods of the Object class, which one can clone an
object?
a. Object clone()
b. clone()
c. Object copy()
d. copy()
Answer: (a) Object clone()

171. Out of these packages, which one contains an abstract keyword?


a. java.util
b. java.lang
c. java.system
d. java.io
Answer: (b) java.lang

172. Out of these methods, which one can be used for converting all the
characters present in a String into an Array of characters?
a. both getChars() & toCharArray()
b. both charAt() & getChars()
d. charAt()
d. all of the mentioned
Answer: (a) both getChars() & toCharArray()

173. What value is returned by the compareTo() function in case the invoking
string happens to be greater than the compared string?
a. a value that is greater than zero
b. a value that is less than zero
c. zero
d. none of the above
Answer: (a) a value that is greater than zero
174. Out of these exceptions, which one is thrown by the compareTo()
method that is defined in a double wrapper?
a. SystemException
Page 42 of 67

b. ClassCastException
c. IOException
d. CastException
Answer: (b) ClassCastException

175. Where does the String Pool get stored?


a. Metaspace
b. Java Stack
c. Java Heap
d. Permanent Generation
Answer: (c) Java Heap

176. Out of these data members of the HttpResponse class, which one is used
for the storage of the response that is from an http server?
a. address
b. status
c. statusCode
d. statusResponse
Answer: (c) statusCode

177. Out of these methods, which one makes the raw MIME formatted
string?
a. toString()
b. getString()
c. parse()
d. parseString()
Answer: (c) parse()

178. The remover() method throws which of these exceptions:


a. ObjectNotFoundException
b. IllegalStateException
c. IOException
d. SystemException
Answer: (b) IllegalStateException
Page 43 of 67

179. Out of the following, which one is a superclass of all the exception type
classes?
a. String
b. RuntimeExceptions
c. Catchable
d. Throwable
Answer: (d) Throwable

180. What happens when we call two threads that have the same priority to
process simultaneously?
a. Both of the threads will be simultaneouslyexecuted
b. Any one of the threads can be executed first lexicographically
c. Itdepends on the OS
d. There will be no execution of threads
Answer: (c) Itdepends on the OS

181. Out of these classes, which one is used for reading strings and characters
in Java from the console?
a. StringReader
b. BufferedReader
c. InputStreamReader
d. BufferedStreamReader
Answer: (b) BufferedReader

182. Out of these operators, which one can be used to get the run time info
about an object?
a. Info
b. getInfo
c. getinfoof
d. instanceof
Answer: (d) instanceof

183. Out of these classes, which one allows a user to define their own
formatting pattern for time and dates?
a. UsersDateFormat
Page 44 of 67

b. ComplexDateFormat
c. SimpleDateFormat
d. DefinedDateFormat
Answer: (c) SimpleDateFormat

184. Which method can we use in an applet to output a string?


a. transient()
b. drawString()
c. print()
d. display()
Answer: (b) drawString()

185. The public int start() returns what?


a. the start index of the previous match
b. the start index of the current match
c. the start index of the input string
d. None of the above
Answer: (a) the start index of the previous match

186. Which one is a superclass of the ContainerEvent class out of the


following?
a. ComponentEvent
b. InputEvent
c. ItemEvent
d. WindowEvent
Answer: (a) ComponentEvent

187. _______ is a superclass of all the Adapter classes.


a. ComponentEvent
b. Applet
c. InputEvent
d. Event
Answer: (b) Applet

188. Which method in Java generates boolean random values?


Page 45 of 67

a. randomBoolean()
b. nextBoolean()
c. generateBoolean()
d. previousBoolean()
Answer: (b) nextBoolean()

189. Which class produces objects with respect to their geographical


locations?
a. Simple TimeZone
b. Date
c. Locale
d. TimeZone
Answer: (c) Locale

190. Which method is used for notifying the observer about the change in the
observed object?
a. notify()
b. update()
c. observed()
d. check()
Answer: (b) update()

191. Which package is used to remotely invoke a method?


a. java.awt
b. java.rmi
c. java.applet
d. java.util
Answer: (b) java.rmi

192. What are the uses of generics?


a. The generics make a code more readable and optimised
b. The generics make a code faster
c. The generics add stability to a code. They do so by making more bugs
detectable at the runtime
Page 46 of 67

d. The generics add stability to a code. They do so by making more bugs


detectable at the compile time
Answer: (d) The generics add stability to a code. They do so by making more
bugs detectable at the compile time

193. Which mechanism helps in the process of naming as well as visibility


control of the classes and their content?
a. Packages
b. Interfaces
c. Object
d. None of the above
Answer: (a) Packages

194. The configuration is stored in which of the file database tables:


a. .sql
b. .ora
c. .hbm
d. .dbm
Answer: (c) .hbm

195. The primary use of Files.lines(Path path) is that it:


a. reads the lines that are from a file as the Stream
b. reads the files that are at the path specified as the String
c. counts the total number of lines for the files at the specified path
d. reads the filenames at the specified path
Answer: (a) reads the lines that are from a file as the Stream

196. Which keywords for the purpose of upper bound a wildcard?


a. bound
b. stop
c. implements
d. extends
Answer: (d) extends
Page 47 of 67

197. Out of the following statements, which one is not true about the Java
beans?
a. It extends the java.io.Serializable class
b. It implements the java.io.Serializable interface
c. It provides getter and setter methods for its properties
d. It provides us with no argument constructor
Answer: (a) It extends the java.io.Serializable class

198. What does the abbreviation MVC pattern stand for?


a. Model View Class
b. Mock View Class
c. Mock View Controller
d. Model View Control
Answer: (d) Model View Control

199. The advantage of using the PreparedStatement in Java is:


a. More memory usage
b. Prevents SQL injection
c. Encourages SQL injection
d. Slow performance
Answer: (b) Prevents SQL injection

200. How does one move from some desired step to another one?
a. logger.error
b. logger.log
c. System.out.println
d. breakpoints
Answer: (d) breakpoints

201. What would happen if the IP Address of the host can’t be determined?
a) IOException is thrown
b) The system will exit with no message
c) Temporary IP Address will be assigned
d) UnknownHostException is thrown
Answer: (d) UnknownHostException is thrown
Page 48 of 67

202. The storage capacity of a single cookie is:


a) 4095 MegaBytes
b) 4095 bytes
c) 2048 bytes
d) 2048 MegaBytes
Answer: (b) 4095 bytes

203. Which action variable helps in including a file in the JSP?


a) jsp:plugin
b) jsp:include
c) jsp:getProperty
d) jsp:setProperty
Answer: (b) jsp:include

204. ______ file defines dependency in maven.


a) dependency.xml
b) build.xml
c) version.xml
d) pom.xml
Answer: (d) pom.xml
205. The main difference between AutoCloseable and Closeable is that:
a) AutoCloseable throws IOException; Closeable throws Exception
b) AutoCloseable is an implementation; Closeable is a concept
c) AutoCloseable throws Exception; Closeable throws IOException
d) AutoCloseable is a concrete class and Closeable is an interface
Answer: (c) AutoCloseable throws Exception; Closeable throws IOException

206. Who developed the Java programming language?


a) Microsoft
b) Oracle
c) Sun Microsystems
d) Google
ans : c) Sun Microsystems
Page 49 of 67

207. In which year was the first version of Java released?


a) 1991
b) 1995
c) 1998
d) 2000
ans : b) 1995

208. What was the original name for Java?


a) C++++
b) Oak
c) Pine
d) Maple
ans : b) Oak

209. What does JVM stand for?


a) Java Version Machine
b) Java Virtual Mechanism
c) Java Verified Module
d) Java Virtual Machine
ans : d) Java Virtual Machine

210. What does JDK include?


a) Only a compiler
b) Only a runtime environment
c) Both a compiler and a runtime environment
d) None of the above
ans : c) Both a compiler and a runtime environment

211. Which of the following is NOT a part of the JRE?


a) Bytecode verifier
b) Classloader
c) Java Compiler
d) Java API classes
ans : c) Java Compiler
Page 50 of 67

212. What is the primary function of JRE?


a) Compilation
b) Debugging
c) Execution
d) Development
ans : c) Execution

213. Can you run a Java program without JRE?


a) Yes
b) No
ans : b) No

214. Is JVM platform-independent?


a) Yes
b) No
ans : b) No

215. Which operator is used to perform bitwise "AND" operation?


a) &&
b) &
c) |
d) ||
ans : b) &

216. What does the == operator compare in Java objects?


a) Values
b) References
c) Hash codes
d) Fields
ans : b) References

217. Which of the following is a unary operator?


a) +
Page 51 of 67

b) -
c) !
d) All of the above
ans : d) All of the above

218. Which operator has the highest precedence?


a) +
b) *
c) ()
d) &&
ans : c) ()

219. What is the output of the expression true || false?


a) true
b) false
c) null
d) 0
ans : a) true

220. Which of the following is not a primitive data type in Java?


a) byte
b) String
c) double
d) short
ans : b) String

221. What is the default value of the int data type?


a) 0
b) 1
c) null
d) Undefined
ans : a) 0

222. Which of the following data types can store a floating-point number?
a) int
Page 52 of 67

b) byte
c) double
d) char
ans : c) double

223. Which data type can store a single character?


a) String
b) byte
c) char
d) int
ans : c) char

224. How many bits does the long data type use?
a) 8
b) 16
c) 32
d) 64
ans : d) 64

225. What's the main difference between int and Integer in Java?
a) No difference
b) Integer can store larger values than int
c) int is a primitive data type, while Integer is a class
d) int can be null, while Integer cannot
ans : c) int is a primitive data type, while Integer is a class

226. Which loop construct in Java is best suited when the number of
iterations is known?
a) for loop
b) while loop
c) do-while loop
d) break statement
ans : a) for loop

227. What is the purpose of the continue statement in a loop?


Page 53 of 67

a) To exit the loop immediately


b) To skip the current iteration and move to the next iteration
c) To terminate the program
d) To execute a specific block of code
ans : b) To skip the current iteration and move to the next iteration

228. Which loop construct in Java is best suited when the number of
iterations is unknown?
a) for loop
b) while loop
c) do-while loop
d) none
ans : b) while loop

229. What is the key difference between a while loop and a do-while loop in
Java?
a) The syntax used to define the loop
b) The number of iterations performed
c) The condition check timing
d) The ability to use the break statement
ans : c) The condition check timing

230. Which loop construct guarantees that the loop body is executed at least
once?
a) for loop
b) while loop
c) do-while loop
d) continue statement
ans : c) do-while loop

231. What is an infinite loop?


a) A loop that executes only once
b) A loop that never terminates naturally
c) A loop that contains an unreachable code block
Page 54 of 67

d) A loop that uses the continue statement


ans : b) A loop that never terminates naturally

232. Which statement is used to exit a loop prematurely?


a) return statement
b) continue statement
c) break statement
d) exit statement
ans : c) break statement

233. Which loop construct is best suited for iterating over an array or a
collection?
a) for loop
b) while loop
c) do-while loop
d) continue statement
ans : a) for loop

234. How do you declare an array in Java?


a) int arrayName;
b) int[] arrayName;
c) int arrayName[];
d) Both b and c
ans : d) Both b and c

235. Which method is used to get the length of an array in Java?


a) length()
b) size()
c) getLength()
d) length
ans : d) length

236. How do you initialize an array in Java?


a) int[] arr = (1,2,3,4,5);
b) int arr = {1,2,3,4,5};
Page 55 of 67

c) int[] arr = new int[]{1,2,3,4,5};


d) int arr = new int(5);
ans : c) int[] arr = new int[]{1,2,3,4,5};

237. What happens when you try to access an array element with an index
that is out of bounds?
a) It returns -1
b) It returns a null value
c) It throws an exception
d) It initializes a new array
ans : c) It throws an exception

238. How can you check if two arrays are equal in Java?
a) Use the == operator
b) Use the .equals() method
c) Use Arrays.equals() method
d) Compare each element one by one
ans : c) Use Arrays.equals() method

239. How do you access the fourth element of an array named numbers?
a) numbers[4];
b) numbers(3);
c) numbers[3];
d) numbers.get(3);
ans : c) numbers[3];

240. Which of the following operators is used for concatenation of two


strings?
a) +
b) *
c) &
d) +=
ans : a) +

241. Which of the following creates a mutable string?


Page 56 of 67

a) String
b) StringBuilder
c) StringChar
d) StringMutable
ans : b) StringBuilder

242. In Java, strings are:


a) Primitive data types
b) Immutable objects
c) Mutable objects
d) Arrays of characters
ans : b) Immutable objects

243. How do you find the length of a string named 'example'?


a) example.size()
b) example.length()
c) example.getLength()
d) example.len()
ans : b) example.length()

244. What is the result of the expression "Java" + "Programming"?


a) JavaProgramming
b) Java Programming
c) Java-Programming
d) JavaProgramming-
ans : a) JavaProgramming

245. Which method is used to compare two strings for equality?


a) ==
b) equals()
c) compare()
d) isEqual()
Ans : b) equals()

246. Which class can create a string that is thread-safe?


Page 57 of 67

a) String
b) StringBuffer
c) StringBuilder
d) StringSafe
Ans : b) StringBuffer

247. What is the root class for all Java classes?


a) Object
b) Class
c) Superclass
d) Root
Ans : a) Object

248. What is polymorphism?


a) Multiple forms
b) Single form
c) No form
d) Static form
Ans : a) Multiple forms

249. What is encapsulation in Java?


a) The process of combining data and methods into a single unit
b) The process of hiding data and methods within a class
c) The process of creating multiple instances of a class
d) The process of reusing code from existing classes
Ans : a) The process of combining data and methods into a single unit

250. What is inheritance in Java?


a) The process of creating multiple instances of a class
b) The process of hiding data and methods within a class
c) The process of reusing code from existing classes
d) The process of combining data and methods into a single unit
Ans : c) The process of reusing code from existing classes

251. What is polymorphism in Java?


Page 58 of 67

a) The ability of a class to inherit properties and behaviors from another class
b) The process of hiding data and methods within a class
c) The process of creating multiple instances of a class
d) The ability of an object to take on many forms
Ans : d) The ability of an object to take on many forms

252. What are abstract classes in Java?


a) Classes that cannot be instantiated
b) Classes that can be used as blueprints for creating objects
c) Classes that only contain abstract methods
d) All of the above
Ans : d) All of the above

253. What is the purpose of the "super" keyword in Java?


a) To refer to the current object
b) To invoke the superclass constructor or methods
c) To create multiple instances of a class
d) To hide data and methods within a class
Ans : b) To invoke the superclass constructor or methods

254. What is the purpose of the "this" keyword in Java?


a) To refer to the superclass
b) To create multiple instances of a class
c) To hide data and methods within a class
d) To refer to the current object
Ans : d) To refer to the current object

255. What is the purpose of the "final" keyword in Java?


a) To prevent the inheritance of a class
b) To prevent overriding of a method
c) To prevent modification of a variable's value
d) All of the above
Ans : d) All of the above

256. What is an interface in Java?


Page 59 of 67

a) A class
b) A data type
c) A blueprint for a class
d) A data structure
Ans : c) A blueprint for a class

257. Which keyword is used to implement an interface?


a) extends
b) new
c) interface
d) implements
Ans : d) implements

258. Can an interface extend another interface in Java?


a) No
b) Yes
Ans : b) Yes

259. Can an interface have a constructor?


a) Yes
b) No
Ans : b) No

260. Which of the following access modifiers are implicitly applied to


variables in an interface?
a) private
b) protected
c) public
d) default
Ans : c) public

261. Is it possible to create an instance of an interface?


a) Yes
b) No
Ans : b) No
Page 60 of 67

262. How many interfaces can a Java class implement?


a) None
b) Only one
c) Two
d) As many as needed
Ans : d) As many as needed

263. Can an interface inherit from a class?


a) Yes
b) No
Ans : b) No

264. Can an interface method be declared as final?


a) Yes
b) No
Ans : b) No

265. In Java 9, which type of methods can be added to interfaces to share


code between methods?
a) Static
b) Private
c) Final
d) Protected
Ans : b) Private

266. An interface with no methods is known as?


a) Abstract Interface
b) Marker Interface
c) Empty Interface
d) Functional Interface
Ans : b) Marker Interface

267. Which keyword is used to define a default method in an interface?


a) static
Page 61 of 67

b) default
c) final
d) abstract
Ans : b) default

268. Are all methods in an interface abstract?


a) Yes
b) No
Ans : b) No

269. Which of these can be contained in an interface?


a) Abstract methods
b) Constants
c) Default and static methods
d) All of the above
Ans : d) All of the above

270. Which Java feature helps achieve multiple inheritance?


a) Abstract classes
b) Static methods
c) Interfaces
d) Enums
Ans : c) Interfaces

271. What is the default access modifier of a method in an interface in Java?


a) private
b) protected
c) public
d) None of the above
Ans : c) public

272. Why were default methods introduced in Java 8 interfaces?


a) To provide multiple inheritance
b) To add utility functions
c) To provide backward compatibility with older interface versions
Page 62 of 67

d) For better performance


Ans : c) To provide backward compatibility with older interface versions

273. Starting from which Java version can an interface contain method
implementations?
a) Java 5
b) Java 7
c) Java 8
d) Java 9
Ans : c) Java 8

274. What is the purpose of the instanceof operator?


a) Multiply instances
b) Compare two object references
c) Check if an object is an instance of a specific class or interface
d) To create a new instance of a class
Ans : a) Multiply instances

275. Which keyword is used to declare a class variable?


a) volatile
b) transient
c) static
d) final
ans : c) static

276. Which keyword is used to prevent a class from being inherited?


a) final
b) abstract
c) class
d) extends
ans : a) final

277. Which keyword is used to create an instance of a class?


a) new
b) return
Page 63 of 67

c) this
d) create
ans : a) new

278. Which keyword is used to inherit the properties and methods from
another class?
a) import
b) package
c) extends
d) implements
ans : c) extends

279. Which keyword is used to refer to the current instance of a class?


a) class
b) this
c) instance
d) object
ans : c) instance

280. Which keyword in Java is used for importing packages into a program?
a) import
b) package
c) include
d) requires
ans : a) import

281. What does the transient keyword indicate in a Java class?


a) The variable can change over time
b) The variable cannot be serialized
c) The variable is thread-safe
d) The variable is volatile
ans : b) The variable cannot be serialized

282. Which of these is a checked exception?


a) NullPointerException
Page 64 of 67

b) ArithmeticException
c) IOException
d) IndexOutOfBoundsException
ans : c) IOException

283. Which of the following can be used to create a custom checked


exception?
a) Extending the Exception class
b) Extending the Error class
c) Extending the RuntimeException class
d) None of the above
ans : a) Extending the Exception class

284. Which of these is an unchecked exception?


a) ClassNotFoundException
b) SQLException
c) IOException
d) ArithmeticException
ans : d) ArithmeticException

285. Which keyword is used to manually throw an exception in Java?


a) new
b) throw
c) throws
d) Throwable
ans : b) throw

286. Which of these classes is the superclass of all Exception and Error
classes?
a) Exception
b) Error
c) Throwable
d) Object
ans : c) Throwable
Page 65 of 67

287. What does the finally block do?


a) Catches any exception
b) Executes whether an exception is thrown or not
c) Executes only when an exception is thrown
d) Executes only when an exception is not thrown
ans : b) Executes whether an exception is thrown or not

288. Which keyword in Java is used for constant variables?


a) const
b) static
c) constant
d) final
ans : d) final

289. In Java, what is the primary purpose of the Thread class?


a) File handling
b) String operations
c) Network operations
d) Creating and executing threads
ans : d) Creating and executing threads

290. Which method is used to start the execution of a thread?


a) run()
b) start()
c) execute()
d) go()
ans : b) start()

291. What does the join() method do when called on a thread object?
a) Terminates the thread
b) Pauses the thread
c) Forces the current executing thread to wait until the thread it's called on
completes
d) Checks the status of a thread
Page 66 of 67

ans : c) Forces the current executing thread to wait until the thread it's called
on completes

292. Which method can be used to momentarily pause the execution of the
current thread?
a) sleep()
b) wait()
c) pause()
d) stop()
ans : a) sleep()

293. Which interface provides an alternative to extending the Thread class?


a) Runnable
b) Callable
c) Executor
d) Parallel
ans : a) Runnable

294. What is a daemon thread in Java?


a) A thread that monitors and logs other threads
b) A thread that runs continuously in the background
c) A thread that manages memory usage
d) A thread that is part of the Java virtual machine
ans : b) A thread that runs continuously in the background

295. Which interface represents a collection of objects in which duplicate


values can be stored?
a) List
b) Set
c) Map
d) ListMap
ans : b) Set

296. What will be the initial capacity of an ArrayList if it is created with the
no-argument constructor?
Page 67 of 67

a) 0
b) 5
c) 10
d) 16
ans : c) 10

297. What does a Set guarantee?


a) Order
b) No duplicates
c) Both
d) None of the above
ans : b) No duplicates

298. Which List implementation is synchronized?


a) ArrayList
b) Vector
c) LinkedList
d) None of the above
ans : b) Vector

299. Which interface represents a key-value pair mechanism?


a) List
b) Set
c) Queue
d) Map
ans : d) Map

300. Which method is used to check if a Collection is empty?


a) isEmpty()
b) isNull()
c) checkEmpty()
d) hasElements()
ans : a) isEmpty()

(THE END)

You might also like