OOP Using Java •
MCQ • Files, Collections Framework and JDBC
Most Important 30 Objective Question - Files, Collections Framework and JDBC
Q1. Which package is mainly used for file handling in Java
A) java.lang
B) java.io
C) java.util
D) java.sql
Answer: B) java.io
Explanation:The java.io package provides classes for file handling and input/output operations.
Q2. Which class is used to create and manage files?
A) File
B) String
C) Thread
D) Scanner
Answer: A) File
Explanation:The File class is used for creating, deleting, and managing files.
Q3. Which stream is used for byte data?
A) Character Stream
B) Byte Stream
C) Text Stream
D) String Stream
Answer: B) Byte Stream
Explanation:Byte streams are used for handling binary data like images and videos.
Q4. Which stream is used for character data?
A) Byte Stream
B) Character Stream
C) Binary Stream
D) Object Stream
Answer: B) Character Stream
Explanation:Character streams are used for handling text data like characters and strings.
Q5. Which class is used to read a file character by character?
A) FileReader
B) FileOutputStream
C) File
D) Thread
Answer: A) FileReader
Explanation:FileReader reads character data from a file.
Q6. Which class is used to write characters into a file?
A) FileReader
B) FileWriter
C) InputStream
D) Scanner
Answer: B) FileWriter
Explanation:FileWriter writes character data into files.
Q7. Which class is used for binary file output?
A) FileWriter
B) FileOutputStream
C) FileReader
D) BufferedReader
Answer: B) FileOutputStream
Explanation:FileOutputStream is used for writing binary data.
Q8. Which class is used for binary file input?
A) FileInputStream
B) FileWriter
C) File
D) StringReader
Answer: A) FileInputStream
Explanation:FileInputStream reads binary data from files.
Q9. Which method is used to close a file?
A) stop()
B) close()
C) end()
D) delete()
Answer: B) close()
Explanation:close() is used to release system resources after file operations.
Q10. Which class allows random access of file data?
A) FileReader
B) RandomAccessFile
C) Scanner
D) BufferedWriter
Answer: B) RandomAccessFile
Explanation:RandomAccessFile allows reading and writing at any position in a file.
Q11. Which framework is used to store and manipulate groups of objects?
A) Thread Framework
B) Collection Framework
C) Exception Framework
D) JDBC Framework
Answer: B) Collection Framework
Explanation:The Collection Framework provides classes and interfaces for handling groups of objects.
Q12. Which class stores duplicate elements and maintains insertion order?
A) HashSet
B) TreeSet
C) ArrayList
D) PriorityQueue
Answer: C) ArrayList
Explanation:ArrayList allows duplicates and maintains insertion order.
Q13. Which class does not allow duplicate elements?
A) ArrayList
B) LinkedList
C) HashSet
D) Vector
Answer: C) HashSet
Explanation:HashSet stores unique elements only.
Q14. Which collection stores elements in sorted order?
A) HashSet
B) TreeSet
C) ArrayList
D) Stack
Answer: B) TreeSet
Explanation:TreeSet automatically stores elements in sorted order.
Q15. Which class is based on linked list structure?
A) LinkedList
B) HashSet
C) TreeSet
D) FileReader
Answer: A) LinkedList
Explanation:LinkedList uses a linked list data structure.
Q16. JDBC stands for:
A) Java Database Connection
B) Java DataBase Connectivity
C) Java Development Connection
D) Java Dynamic Connection
Answer: B) Java DataBase Connectivity
Explanation:JDBC is used to connect Java applications with databases like MySQL, Oracle, etc.
Q17. Which package is used for JDBC?
A) java.io
B) java.sql
C) java.util
D) java.lang
Answer: B) java.sql
Explanation:The java.sql package provides classes and interfaces for database connectivity.
Q18. Which interface is used to establish database connection?
A) Driver
B) Connection
C) Thread
D) ResultSet
Answer: B) Connection
Explanation:The Connection interface represents the connection between Java program and database.
Q19. Which method is commonly used to get database connection?
A) getConnection()
B) createConnection()
C) openConnection()
D) connectDB()
Answer: A) getConnection()
Explanation:DriverManager.getConnection() is commonly used to establish database connection.
Q20. Which object is used to execute SQL queries?
A) Thread
B) Statement
C) File
D) Scanner
Answer: B) Statement
Explanation:Statement is used to execute SQL queries like SELECT, INSERT, UPDATE, DELETE.
Q21. Which object stores the result of SELECT query?
A) Connection
B) ResultSet
C) Statement
D) File
Answer: B) ResultSet
Explanation:ResultSet stores and processes the records returned by SELECT query.
Q22. Which method is used to execute SELECT query?
A) executeUpdate()
B) executeQuery()
C) updateQuery()
D) select()
Answer: B) executeQuery()
Explanation:executeQuery() is used for SELECT statements and returns ResultSet.
Q23. Which method is used for INSERT, UPDATE, DELETE?
A) executeQuery()
B) executeUpdate()
C) executeSelect()
D) executeFetch()
Answer: B) executeUpdate()
Explanation:executeUpdate() is used for INSERT, UPDATE, and DELETE operations.
Q24. Which statement is safer for dynamic queries?
A) Statement
B) PreparedStatement
C) Thread
D) FileWriter
Answer: B) PreparedStatement
Explanation:PreparedStatement is safer and helps prevent SQL injection.
Q25. Which class loads JDBC driver (traditional concept)?
A) Class.forName()
B) Thread.start()
C) Driver.load()
D) File.load()
Answer: A) Class.forName()
Explanation:Traditionally, JDBC driver is loaded using Class.forName().
Q26. Which method moves ResultSet cursor to next row?
A) next()
B) move()
C) row()
D) forward()
Answer: A) next()
Explanation:next() moves the cursor to the next row in ResultSet.
Q27. Which collection allows priority-based processing?
A) ArrayList
B) PriorityQueue
C) HashSet
D) TreeSet
Answer: B) PriorityQueue
Explanation:PriorityQueue processes elements based on priority order.
Q28. Which collection works like double-ended queue?
A) HashSet
B) ArrayDeque
C) LinkedList
D) TreeSet
Answer: B) ArrayDeque
Explanation:ArrayDeque allows insertion and deletion from both ends.
Q29. Which method is used to close JDBC connection?
A) stop()
B) close()
C) delete()
D) end()
Answer: B) close()
Explanation:close() is used to release database resources after JDBC operations.
Q30. Which of the following improves database security?
A) Statement
B) PreparedStatement
C) FileWriter
D) LinkedList
Answer: B) PreparedStatement
Explanation:PreparedStatement improves security by preventing SQL injection attacks.
Google AdSense Ad Placement Here 📢