Java Basic Objective Question

1. What is the size of byte variable?

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

Check Answer

2. What is the default value of float variable?

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

Check Answer

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

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

Check Answer

4. Which method must be implemented by all threads?

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

Check Answer

5. What is the default value of Object variable?

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

12. Which package contains the Random class?

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

Check Answer

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

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

Check Answer

14. Which of the following is a marker interface?

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

Check Answer

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’;

Check Answer

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

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

Check Answer

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

Check Answer

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

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

Check Answer

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

Check Answer

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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”;

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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”);

Check Answer

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()

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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()

Check Answer

37. Which of these is not a wrapper class?

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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()

Check Answer

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()

Check Answer

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

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

Check Answer

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()

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

Check Answer

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

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

Check Answer

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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()

Check Answer

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()

Check Answer

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()

Check Answer

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer

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

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

Check Answer