Komal Nandini (MVC, JTree MCQ)
Komal Nandini (MVC, JTree MCQ)
GroupMembers
Enrollment
Sr.No. Name Class Roll No.
Number
1
Komal Tintore 2207110452 TYCO2 122
2
Nandini Salunke 2207110463 TYCO2 `129
JTree
A. JTable
B. JList
C. JTree
D. JPanel
Answer: C) JTree
Explanation: JTree is the Swing component used for displaying hierarchical data
structures, such as file systems or organizational charts.
A) expandNode(int row)
B) expandPath(TreePath path)
C) expandRow(int row)
D) expandTree()
Explanation: The expandRow(int row) method is used to expand a specific node based
on its row index. Another method, expandPath(TreePath path), can also be used to
expand a node using its path.
3. Which method is used to add a TreeSelectionListener to a JTree?
A) addTreeSelectionListener()
B) addSelectionListener()
C) addNodeListener()
D) addTreeListener()
Answer: A) addTreeSelectionListener()
A) TreeModel
B) DefaultTreeModel
C) TreeTableModel
D) TreeNodeModel
Answer: B) DefaultTreeModel
Explanation: DefaultTreeModel is the default data model for JTree and manages the tree
structure, including the nodes and their relationships.
A) ActionEvent
B) MouseEvent
C) TreeSelectionEvent
D) KeyEvent
Answer: C) TreeSelectionEvent
Explanation: TreeSelectionEvent occurs when the user selects or deselects a node in the
JTree.
7. What method is used to collapse all nodes in a JTree?
A) collapseAll()
B) collapsePath(TreePath path)
C) collapseNode(TreeNode node)
D) collapseRow(int row)
Explanation: The collapseRow(int row) method collapses a node at a specific row index.
You can also use collapsePath(TreePath path) to collapse a node based on its path.
A) TreeNode
B) TreeModel
C) TreePath
D) TreeStructure
Answer: C) TreePath
Explanation: TreePath represents the path from the root node to a specific node in the
tree, allowing easy access and manipulation of nodes.
9. How can you make a JTree editable?
A) setEditable(true)
B) enableEditing()
C) editTree()
D) setEditMode(true)
Answer: A) setEditable(true)
Explanation: Calling setEditable(true) makes the tree nodes editable, allowing users tochange
the labels of nodes.
A) getRootNode()
B) getRoot()
C) getTreeRoot()
D) getModel().getRoot()
Answer: D) getModel().getRoot()
Explanation: To retrieve the root node, you access the tree’s model using getModel()and
then call getRoot() on the model.
11. What is the purpose of the TreeModel interface?
Explanation: TreeModel defines the data structure and relationships of the nodes in a
JTree, making it essential for managing the tree’s data.
A) updateTree()
B) repaintTree()
C) treeDidChange()
D) updateUI()
Answer: D) updateUI()
Explanation: The updateUI() method updates and repaints the UI of the JTree
component, ensuring that any changes are reflected visually.
13. Which of the following is not a valid use of JTree?
Explanation: JTree is used for hierarchical data. A list of items with no hierarchy is
bettersuited for a JList.
A) setCellRenderer(TreeRenderer renderer)
B) setTreeRenderer(Renderer renderer)
C) setCellEditor(CellEditor editor)
D) setCellRenderer(TreeCellRenderer renderer)
MVC Architecture
A) Model-View-Controller
B) Model-Variable-Controller
C) Model-View-Configuration
D) Multi-View-Controller
Answer: A) Model-View-Controller
Explanation: MVC is a design pattern that divides an application into three main
components: Model, View, and Controller.
20.In a web application using MVC, which component would typically handle HTTP
requests?
A) View
B) Model
C) Controller
D) Router
Answer: C) Controller
Explanation: The Controller is responsible for handling HTTP requests in a web application.
It processes the incoming requests, interacts with the Model, and determines which View to
render.
Answer: A) Model
Explanation: In MVC architecture, 'M' stands for Model. The Model represents the data
and the business logic of the application. It directly manages the data,
logic, and rules of the application.
22.What is the purpose of the Model in MVC?
A) Model
B) View
C) Controller
D) Database
Answer: C) Controller
Explanation: The Controller handles user inputs, processes them, and updates the Model or
View accordingly.
Answer: B) Model
Explanation: The Model is responsible for data retrieval and manipulation, which includes
interactions with the database.