Java Basic Objective Question

1. What is the size of byte variable?

a) 8-bit
b) 16-bit
c) 32-bit
d) 64-bit

Answer: a) 8-bit

2. What is the default value of float variable?

a) 0.0d
b) 0.0f
c) 0
d) 0.0

Answer: b) 0.0f

3. Which of the following is not a keyword in Java?

a) static
b) Boolean
c) void
d) private

Answer: b) Boolean

4. Which method must be implemented by all threads?

a) run()
b) start()
c) stop()
d) main()

Answer: a) run()

5. What is the default value of Object variable?

a) null
b) 0
c) undefined
d) none of the mentioned

Answer: a) null

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

a) object
b) strictfp
c) main
d) system

Answer: b) strictfp

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

a) import
b) package
c) extends
d) export

Answer: a) import

8. Which of these operators is used to allocate memory to array variables in Java?

a) malloc
b) alloc
c) new
d) new malloc

Answer: c) new

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

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

Answer: c) Compilation

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

a) identifier
b) keyword
c) letter
d) constant

Answer: b) keyword

11. Which of these is returned by operator ‘&’?

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

Answer: b) Boolean

12. Which package contains the Random class?

a) java.util package
b) java.lang package
c) java.awt package
d) java.io package

Answer: a) java.util package

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

a) Object
b) int
c) long
d) void

Answer: b) int

14. Which of the following is a marker interface?

a) Runnable
b) Remote
c) Readable
d) Result

Answer: b) Remote

15. Which of these is used to make a class?

a) class
b) struct
c) public
d) void

Answer: a) class

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

a) 0
b) Not a Number
c) Infinity
d) Run time exception

Answer: c) Infinity

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

Answer: c) Javadoc tool

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

a) char ch = ‘\utea’;
b) char ca = ‘tea’;
c) char cr = \u0223;
d) char cc = ‘\itea’;

Answer: a) char ch = ‘\utea’;

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

a) ABH8097
b) L990023
c) 0xnf029L
d) 904423

Answer: c) 0xnf029L

20. What is the numerical range of a char?

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

Answer: d) 0 to 65535

21. Which of these methods is a part of the Java Collection class?

a) add()
b) delete()
c) insert()
d) copy()

Answer: a) add()

22. What does the expression 5.45 + “3.2” evaluate to?

a) “8.65”
b) “5.453.2”
c) 8.65
d) 5.45 + 3.2

Answer: b) “5.453.2”

23. Which of these data types is used by the Java compiler to represent internal object size?

a) byte
b) int
c) short
d) long

Answer: b) int

24. Which of these keywords is used to make a class?

a) class
b) struct
c) public
d) void

Answer: a) class

25. What is the output of Math.floor(3.6)?

a) 4
b) 3
c) 3.0
d) 4.0

Answer: c) 3.0

26. Which of these is the correct way of making a string in Java?

a) String s = ‘Hello’;
b) String s = new String(‘Hello’);
c) String s = ‘new Hello’;
d) String s = “Hello”;

Answer: d) String s = “Hello”;

27. Which method is used to find the length of a string in Java?

a) lengthof()
b) len()
c) length()
d) lenof()

Answer: c) length()

28. What does the expression float a = 1 / 4 return?

a) 0.25
b) 0
c) 0.25f
d) 0.0

Answer: b) 0

29. Which of these operators is used to allocate memory to an object?

a) malloc
b) alloc
c) new
d) new malloc

Answer: c) new

30. Which of these is a valid constructor of class Integer?

a) Integer i = 5;
b) Integer i = “5”;
c) Integer i = new Integer(5);
d) Integer i = new Integer(“5”);

Answer: c) Integer i = new Integer(5);

31. Which of these methods of class String is used to extract a substring from a String object?

a) Substring()
b) SubString()
c) substring()
d) subString()

Answer: c) substring()

32. Which of these is a method of class Object?

a) toString()
b) toInt()
c) toByte()
d) toChar()

Answer: a) toString()

33. Which of these methods is used to compare two String objects for their equality?

a) equals()
b) Equal()
c) isequal()
d) Isequal()

Answer: a) equals()

34. Which of these keywords is used to define packages in Java?

a) pkg
b) Pkg
c) package
d) Package

Answer: c) package

35. Which of these methods of class String is used to obtain length of String object?

a) get()
b) Size()
c) length()
d) getSize()

Answer: c) length()

36. Which of these methods of class String is used to extract more than one character at a time?

a) getChars()
b) GetChars()
c) GetChar()
d) getChar()

Answer: a) getChars()

37. Which of these is not a wrapper class?

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

Answer: d) String

38. Which of these classes is a subclass of wrapper class Number?

a) Byte
b) String
c) System
d) Math

Answer: a) Byte

39. Which of these is a method of class Character?

a) isDigit()
b) isLetter()
c) isUpperCase()
d) All of the mentioned

Answer: d) All of the mentioned

40. Which of these methods of class Double is used to compare the value of two Double objects?

a) equals()
b) isEqual()
c) isEquals()
d) isequal()

Answer: a) equals()

41. Which of these methods of class Integer is used to convert a string to a signed decimal integer?

a) valueOf()
b) parseInt()
c) value()
d) parseValue()

Answer: b) parseInt()

42. Which of these methods is used to print stack trace?

a) dumpStack()
b) getStackTrace()
c) printStackTrace()
d) dump()

Answer: c) printStackTrace()

43. Which of these methods is used to check for the EOF (End of File) in Java?

a) eof()
b) isEOF()
c) read()
d) readLine()

Answer: d) readLine()

44. Which of these methods is used to close a file in Java?

a) closeFile()
b) read()
c) write()
d) close()

Answer: d) close()

45. Which of these is a method of PrintWriter class?

a) print()
b) write()
c) printf()
d) All of the mentioned

Answer: d) All of the mentioned

46. Which of these methods is a method of BufferedWriter class?

a) write()
b) buffer()
c) read()
d) flush()

Answer: a) write()

47. Which of these classes is used to read from a file in Java?

a) FileInputStream
b) BufferedOutputStream
c) DataInputStream
d) BufferedInputStream

Answer: a) FileInputStream

48. Which of these methods of InputStream class is used to read bytes from a file?

a) get()
b) getByte()
c) read()
d) readByte()

Answer: c) read()

49. Which of these is not a member class of Java’s I/O system?

a) FileInputStream
b) BufferedInputStream
c) System.in
d) System.out

Answer: d) System.out

50. Which of these methods is used to flush the output stream?

a) flush()
b) clear()
c) fflush()
d) clearBuffer()

Answer: a) flush()

51. Which of these is a member class of Java’s I/O system?

a) FileInputStream
b) BufferedInputStream
c) System.in
d) All of the mentioned

Answer: d) All of the mentioned

52. Which of these methods is used to delete a file in Java?

a) deleteFile()
b) delete()
c) removeFile()
d) remove()

Answer: b) delete()

53. Which of these methods is used to set the length of a file in Java?

a) setLength()
b) truncate()
c) setFileSize()
d) setSize()

Answer: a) setLength()

54. Which of these is a method of File class?

a) mkdir()
b) create()
c) createDir()
d) makeDir()

Answer: a) mkdir()

55. Which of these is used to read from a file?

a) FileReader
b) FileWriter
c) FileInputStream
d) FileOutputStream

Answer: a) FileReader

56. Which of these is used to write to a file?

a) FileReader
b) FileWriter
c) FileInputStream
d) FileOutputStream

Answer: b) FileWriter

57. Which of these classes is used to read from console?

a) Console
b) Scanner
c) FileReader
d) BufferedReader

Answer: b) Scanner

58. Which of these methods is used to read a character from console?

a) read()
b) readChar()
c) readCharacter()
d) readLine()

Answer: a) read()

59. Which of these methods is used to write a character to console?

a) print()
b) write()
c) putchar()
d) put()

Answer: b) write()

60. Which of these is used to print formatted output to console?

a) format()
b) printf()
c) print()
d) Both a) and b)

Answer: d) Both a) and b)

61. Which of these methods of Object class can clone an object?

a) clone()
b) Copy()
c) copyObject()
d) CloneObject()

Answer: a) clone()

62. Which of these methods of Object class can notify all waiting threads of an object?

a) notify()
b) notifyThread()
c) notifyAll()
d) notifyThreads()

Answer: c) notifyAll()

63. Which of these methods of Object class can wake up all waiting threads of an object?

a) notify()
b) notifyAll()
c) notifyThread()
d) notifyThreads()

Answer: b) notifyAll()

64. Which of these methods of Object class is used to create and start a new thread?

a) run()
b) start()
c) begin()
d) execute()

Answer: b) start()

65. Which of these methods of Object class can wake up a single thread that is waiting on the object’s monitor?

a) notify()
b) notifyAll()
c) notifyThread()
d) notifyThreads()

Answer: a) notify()

66. Which of these methods is used to destroy an object created by constructor?

a) delete()
b) finalize()
c) dereference()
d) None of the mentioned

Answer: b) finalize()

67. Which of these methods is called to start a new thread?

a) run()
b) start()
c) resume()
d) runThread()

Answer: b) start()

68. Which of these methods is called to release a lock on an object?

a) wait()
b) notify()
c) notifyAll()
d) release()

Answer: a) wait()

69. Which of these methods is used to suspend a thread for a period of time?

a) sleep()
b) suspend()
c) wait()
d) stop()

Answer: a) sleep()

70. Which of these methods is called when a thread is about to terminate?

a) end()
b) stop()
c) terminate()
d) finalize()

Answer: d) finalize()

71. Which of these methods is called when a thread is in its running state?

a) wait()
b) notify()
c) run()
d) start()

Answer: c) run()

72. Which of these methods can be used to obtain a lock on an object?

a) wait()
b) notify()
c) notifyAll()
d) synchronized()

Answer: d) synchronized()

73. Which of these methods can be used to release a lock on an object?

a) wait()
b) notify()
c) notifyAll()
d) synchronized()

Answer: a) wait()

74. Which of these methods can be used to force a thread to start?

a) start()
b) run()
c) begin()
d) execute()

Answer: a) start()

75. Which of these methods can be used to terminate a thread?

a) stop()
b) end()
c) terminate()
d) kill()

Answer: a) stop()

76. Which of these methods can be used to suspend a thread?

a) sleep()
b) wait()
c) suspend()
d) notify()

Answer: c) suspend()

77. Which of these methods can be used to resume a suspended thread?

a) start()
b) notify()
c) resume()
d) run()

Answer: c) resume()

78. Which of these methods can be used to stop a running thread?

a) stop()
b) end()
c) terminate()
d) kill()

Answer: a) stop()

79. Which of these methods can be used to check if a thread is alive?

a) isAlive()
b) checkAlive()
c) isThreadAlive()
d) isRunning()

Answer: a) isAlive()

80. Which of these methods can be used to interrupt a thread?

a) interrupt()
b) break()
c) terminate()
d) stop()

Answer: a) interrupt()

81. Which of these methods can be used to yield the CPU to another thread?

a) yield()
b) wait()
c) notify()
d) sleep()

Answer: a) yield()

82. Which of these methods can be used to create a thread?

a) create()
b) Thread()
c) Thread.create()
d) new Thread()

Answer: d) new Thread()

83. Which of these methods can be used to start a thread?

a) run()
b) start()
c) begin()
d) execute()

Answer: b) start()

84. Which of these methods can be used to stop a thread?

a) stop()
b) end()
c) terminate()
d) kill()

Answer: a) stop()

85. Which of these methods can be used to suspend a thread?

a) sleep()
b) wait()
c) suspend()
d) notify()

Answer: c) suspend()

86. Which of these methods can be used to resume a suspended thread?

a) start()
b) notify()
c) resume()
d) run()

Answer: c) resume()

87. Which of these methods can be used to stop a running thread?

a) stop()
b) end()
c) terminate()
d) kill()

Answer: a) stop()

88. Which of these methods can be used to check if a thread is alive?

a) isAlive()
b) checkAlive()
c) isThreadAlive()
d) isRunning()

Answer: a) isAlive()

89. Which of these methods can be used to interrupt a thread?

a) interrupt()
b) break()
c) terminate()
d) stop()

Answer: a) interrupt()

90. Which of these methods can be used to yield the CPU to another thread?

a) yield()
b) wait()
c) notify()
d) sleep()

Answer: a) yield()

91. Which of these methods can be used to create a thread?

a) create()
b) Thread()
c) Thread.create()
d) new Thread()

Answer: d) new Thread()

92. Which of these methods can be used to start a thread?

a) run()
b) start()
c) begin()
d) execute()

Answer: b) start()

93. Which of these methods can be used to stop a thread?

a) stop()
b) end()
c) terminate()
d) kill()

Answer: a) stop()

94. Which of these methods can be used to suspend a thread?

a) sleep()
b) wait()
c) suspend()
d) notify()

Answer: c) suspend()

95. Which of these methods can be used to resume a suspended thread?

a) start()
b) notify()
c) resume()
d) run()

Answer: c) resume()

96. Which of these methods can be used to stop a running thread?

a) stop()
b) end()
c) terminate()
d) kill()

Answer: a) stop()

97. Which of these methods can be used to check if a thread is alive?

a) isAlive()
b) checkAlive()
c) isThreadAlive()
d) isRunning()

Answer: a) isAlive()

98. Which of these methods can be used to interrupt a thread?

a) interrupt()
b) break()
c) terminate()
d) stop()

Answer: a) interrupt()

99. Which of these methods can be used to yield the CPU to another thread?

a) yield()
b) wait()
c) notify()
d) sleep()

Answer: a) yield()

100. Which of these methods can be used to create a thread?

a) create()
b) Thread()
c) Thread.create()
d) new Thread()

Answer: d) new Thread()

What did you think?

Similar Reads

Hi, Welcome back!
Forgot Password?
Don't have an account?  Register Now