Java & SQL Objective Type Questions with
Answers
Java Swing (Core Java GUI Components)
1. Which of the following is true about JTextField in Java?
a) It allows multiple lines of text
b) It is used to accept a single line of input from the user
c) It cannot be edited by the user
d) It is a subclass of JLabel
Answer: b) It is used to accept a single line of input from the user
2. Which method is used to retrieve text from a JTextField?
a) getValue()
b) getText()
c) setText()
d) fetchText()
Answer: b) getText()
3. JLabel is mainly used for:
a) Taking input from the user
b) Displaying read-only text or images
c) Creating menus
d) Closing the application
Answer: b) Displaying read-only text or images
4. Which of the following is correct about JLabel?
a) It is editable by default
b) It does not support images
c) It is a display-only component
d) It is a container for other components
Answer: c) It is a display-only component
5. Which of the following is true about JFrame?
a) It is a top-level container
b) It cannot contain panels
c) It is abstract
d) It is a subclass of JPanel
Answer: a) It is a top-level container
6. Which method is used to close a JFrame when the user clicks the close button?
a) setVisible(false)
b) dispose()
c) setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
d) exitOnClose()
Answer: c) setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE
7. The purpose of JPanel in Java is:
a) To represent a top-level window
b) To group and organize components
c) To handle database connections
d) To create menus
Answer: b) To group and organize components
8. JPanel is a subclass of:
a) JFrame
b) Container
c) Component
d) AbstractButton
Answer: b) Container
9. Which layout places components in a single row or column?
a) FlowLayout
b) GridLayout
c) BorderLayout
d) BoxLayout
Answer: d) BoxLayout
10. In BorderLayout, how many regions can we add components into?
a) 3
b) 4
c) 5
d) Unlimited
Answer: c) 5 (North, South, East, West, Center)
SQL Basics
11. Which SQL command is used to retrieve data from a database?
a) INSERT
b) UPDATE
c) SELECT
d) DELETE
Answer: c) SELECT
12. Which of the following is the correct syntax to delete all rows from a table?
a) DROP TABLE table_name;
b) DELETE * FROM table_name;
c) DELETE FROM table_name;
d) REMOVE FROM table_name;
Answer: c) DELETE FROM table_name
13. What is the default sorting order of ORDER BY in SQL?
a) DESC
b) Random
c) ASC
d) None
Answer: c) ASC
14. Which SQL clause is used to filter records?
a) WHERE
b) ORDER BY
c) GROUP BY
d) HAVING
Answer: a) WHERE
15. Which of the following creates a new table in SQL?
a) INSERT
b) CREATE
c) UPDATE
d) ALTER
Answer: b) CREATE