Java MCQ Questions and Answers for BCA, MCA, and GATE Exam

1. Which of these packages contains all the collection classes?

  • java.lang
  • java.util
  • java.net
  • java.awt

2. Which of these classes is not part of Java’s collection framework?

  • Map
  • ArrayException
  • Stack
  • Queue

3. Which of this interface is not a part of Java’s collection framework?

  • List
  • Set
  • SortedMap
  • SortedList

4. Which of these methods deletes all the elements from the invoking collection?

  • clear()
  • reset()
  • delete()
  • refresh()

5. What is a Collection in Java?

  • A group of classes
  • A group of interfaces
  • A group of objects
  • None

6. Which collection does not allow duplicate elements?

  • List
  • Set
  • Map
  • All of the mentioned

7. Which collection allows you to retrieve elements in the order they were inserted?

  • HashSet
  • TreeMap
  • LinkedHashMap
  • PriorityQueue

8. What is the implementation of the List interface?

  • HashMap
  • HashSet
  • LinkedList
  • LinkedHashSet

9. What are not the implementation classes of the List interface?

  • ArrayList
  • HashSet
  • LinkedList
  • Vector

10. Which class is a resizable array implementation?

  • LinkedList
  • ArrayList
  • HashSet
  • ArrayQueue

11. What is multithreaded programming?

  • It’s a process in which two different processes run simultaneously
  • It’s a process in which two or more parts of the same process run simultaneously
  • It’s a process in which many different processes are able to access the same information
  • It’s a process in which a single process can access information from many sources

12. Which of these are types of multitasking?

  • Process-based
  • Thread-based
  • Both
  • None

13. Thread priority in Java is?

  • Integer
  • Float
  • Double
  • Long

14. What will happen if two threads of the same priority are called to be processed simultaneously?

  • Anyone will be executed first lexicographically
  • Both of them will be executed simultaneously
  • None of them will be executed
  • It is dependent on the operating system

15. Which of these statements is incorrect?

  • A thread can exist only in two states, running and blocked
  • By multithreading CPU idle time is minimized, and we can make maximum use of it
  • By multitasking CPU idle time is minimized, and we can make maximum use of it
  • Two threads in Java can have the same priority

16. Which class is used to create a thread in Java?

  • Thread
  • Runnable
  • Process
  • Executor

17. What is the purpose of the wait() method in Java threads?

  • To pause the execution of a thread
  • To terminate a thread
  • To notify other threads to resume execution
  • To release the lock held by the thread

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

  • start()
  • run()
  • execute()
  • begin()

19. What is the purpose of the join() method in Java threads?

  • To interrupt the execution of a thread
  • To wait for a thread to finish its execution
  • To schedule the execution of a thread
  • To notify a thread to stop execution

20. What is the main advantage of multithreading in Java?

  • Improved program performance
  • Simplified program structure
  • Reduced memory usage
  • Elimination of runtime errors

21. Which does autoboxing or unboxing in Java?

  • Compiler
  • Runtime
  • Third-party tools
  • None

22. Which Java version introduced the feature Autoboxing and Unboxing?

  • Java 4
  • Java 5
  • Java 6
  • Java 7

23. What is the need for Autoboxing and Unboxing in Java?

  • Reduces code to be written by developers to convert from Wrapper to Primitive and vice versa
  • Compile time is reduced due to fixed methods followed to automatically convert Objects and Primitives
  • Auto-unboxing improves memory efficiency by converting Wrapper to Primitive and process when the object version is not needed
  • All of the mentioned

24. Autoboxing or Auto-unboxing works with ___ in Java.

  • Loops, Switch statements
  • Ternary Operator
  • IF ELSE statements
  • All the above

25. What is Truncation in Java?

  • Floating-point value assigned to an integer type
  • Integer value assigned to floating type
  • Floating-point value assigned to a Floating type
  • Integer value assigned to an integer type

26. Assert statement is a _____________ statement.

  • Concurrent and synthesizable
  • Sequential and synthesizable
  • Concurrent and Non-synthesizable
  • Sequential and Non-synthesizable

27. What is the use of assert statement in VHDL?

  • To print any string
  • To check the consistency and generate a message
  • Cause execution of sequential statements to wait
  • To check if a condition can stop the execution

28. What is the correct syntax for using ASSERT statement?

  • ASSERT condition [REPORT string] [SEVERITY name];
  • Condition [REPORT string] [SEVERITY name] ASSERT;
  • ASSERT condition [SEVERITY name] [REPORT string];
  • A

29. The assert statement displays a message when the condition is FALSE.

  • TRUE
  • FALSE
  • 0
  • 0

30. How many types of severity levels are there for the ASSERT statement?

  • 1
  • 2
  • 3
  • 4

31. The JUnit testing framework is an ____-source tool for Java developers.

  • Open
  • Closed
  • Both a & B
  • None

32. Code for unit tests ensures that the ____ of a program works as it should.

  • Logic
  • Data
  • Set
  • Array

33. ____, After, and others are some of the classes and interfaces contained in the org.junit package for JUnit testing.

  • Assert
  • Test
  • Before
  • All

34. How many types of unit testing are there?

  • 2
  • 3
  • 4
  • 5

35. Which of the following is/are the type(s) of unit testing?

  • Manual
  • Automated
  • Both A & B
  • None

36. There is a ____ with manual testing.

  • Time Commitment
  • Lack of reliability
  • Both a & B
  • None

37. The ____ of automated testing are greater.

  • Speed
  • Reliability
  • Both a & B
  • None

38. In the ____ annotation, the method is specified as a test method.

  • .@Test
  • .@Before
  • .@Test(timeout=1000)
  • .@After

39. Program logic can be asserted using the ____ class.

  • Org
  • Org.junit
  • org.junit.Assert
  • None

40. A primitive or object can be checked to be equal by calling ____.

  • void assertEquals(boolean expected, boolean actual)
  • void assertTrue(boolean condition)
  • void assertFalse(boolean condition)
  • void assertNull(Object obj)

41. Which of the following architecture does the Swing framework use?

  • MVC
  • MVP
  • Layered architecture
  • Master-Slave architecture

42. Which language is used in the Swing framework?

  • JavaScript
  • Java
  • React
  • Python

43. A ____ is the abstract foundation class for SWING's non-menu user interface controls.

  • Container
  • JComponent
  • Component
  • None

44. A ____ is the basic class for all SWING UI components.

  • Container
  • JComponent
  • Component
  • None

45. A ____ is a one-line input field that allows the user to choose a number or an object value from an ordered sequence.

  • JTextArea
  • JTextField
  • JSpinner
  • JSlider

46. How many types of events are there?

  • 5
  • 3
  • 2
  • 4

47. What is the feature of JavaFX?

  • FXML
  • Scene Builder
  • CSS-like Styling
  • All of them

48. The following is not a component of JavaFX.

  • Prism
  • Scene Graph
  • WebView
  • Browser

49. Prism is _______

  • an open graphics library
  • a high-performance hardware-accelerated graphical pipeline
  • a web engine
  • a media engine

50. Which class is extended to make any JavaFX application?

  • Scene
  • Stage
  • Group
  • Application

51. What are the major components of the JDBC?

  • DriverManager, Driver, Connection, Statement, and ResultSet
  • DriverManager, Driver, Connection, and Statement
  • DriverManager, Statement, and ResultSet
  • DriverManager, Connection, Statement, and ResultSet

52. Select the packages in which JDBC classes are defined?

  • jdbc and javax.jdbc
  • rdb and javax.rdb
  • jdbc and java.jdbc.sql
  • sql and javax.sql

53. Thin driver is also known as?

  • Type 3 Driver
  • Type-2 Driver
  • Type-4 Driver
  • Type-1 Driver

54. Which of the following methods is used to perform DML statements in JDBC?

  • executeResult()
  • executeQuery()
  • executeUpdate()
  • execute()

55. Which methods are required to load a database driver in JDBC?

  • getConnection()
  • registerDriver()
  • forName()
  • Both b & c

56. Which of the following is not a valid statement in JDBC?

  • Statement
  • PreparedStatement
  • QueryStatement
  • CallableStatement

57. A good way to debug JDBC-related problems is to enable?

  • JDBC tracing
  • Exception handling
  • Both a & b
  • Only b

58. JDBC-ODBC driver is also known as?

  • Type 4
  • Type 3
  • Type 1
  • Type 2

59. How many stages are used by Java programmers while using JDBC in their programs?

  • 3
  • 2
  • 5
  • 6

60. How many ways to register a driver?

  • 2
  • 3
  • 4
  • 5