Important Web Design and Development Short Questions
Chapter: 9
Question 1:
What is the role of the print method in the Printable interface?
Answer:
The print method in the Printable interface is a contract that implementing classes must define. It specifies that the class will provide its own implementation of the print method, which is used to display or print the object's information.
Chapter: 9
Question 2:
How does polymorphism work with interfaces in Java?
Answer:
Polymorphism with interfaces allows a single interface reference to point to objects of different implementing classes. This enables dynamic method dispatch where the method implementation is determined at runtime based on the object's actual class.
Chapter: 10
Question 3:
What is a graphical user interface (GUI)?
Answer:
A graphical user interface (GUI) is a visual interface to a program that uses GUI components like buttons, menus, and labels. It allows users to interact with the program via the mouse or keyboard, and its appearance and functionality are collectively known as the program's look and feel.
Chapter: 10
Question 4:
Name the packages in Java that provide classes for GUI components.
Answer:
The packages in Java that provide classes for GUI components are java.awt (Abstract Windowing Toolkit) and javax.swing. java.awt includes original GUI components, while javax.swing contains newer, pure Java components that allow for a uniform look and feel across platforms.
Chapter: 10
Question 5:
What is the difference between GUI classes and Non-GUI support classes in Java?
Answer:
GUI classes are visible and interactable by the user, such as JButton and JFrame. Non-GUI support classes provide necessary functions for GUI classes without producing visual output, such as layout managers and event handling classes.
Chapter: 10
Question 6:
What are AWT components and why are they called "Heavy Weight Components"?
Answer:
AWT components are part of the java.awt package and are tied directly to the local platform's graphical user interface capabilities. They are called "Heavy Weight Components" because they rely on the operating system's windowing system and create corresponding processes on the OS.
Chapter: 10
Question 7:
Explain the term "Light Weight Components" in Swing.
Answer:
Swing components are referred to as "Light Weight Components" because they are written entirely in Java and are managed through threads, not directly tied to the operating system's windowing system. This allows for a consistent appearance and functionality across different platforms.
Chapter: 10
Question 8:
Describe the steps to create a GUI using JFrame in Java.
Answer:
To create a GUI using JFrame, follow these steps: 1) Import necessary packages (java.awt.* and/or javax.swing.*). 2) Setup the top-level container (e.g., JFrame). 3) Get the component area of the top-level container. 4) Apply a layout manager to the component area. 5) Create and add components. 6) Set the frame's size and visibility.
Chapter: 10
Question 9:
What does the setLayout method do in Java GUI programming?
Answer:
The setLayout method is used to specify the layout manager for a container. It determines how components are arranged within the container, including their size and position. For example, con.setLayout(new FlowLayout()) sets a flow layout where components are placed in a left-to-right flow.
Chapter: 10
Question 10:
How does GridLayout arrange components in a container?
Answer:
GridLayout arranges components in a grid of cells with a specified number of rows and columns. Each cell is of equal size, and components are added row by row. If there are more components than cells, they will fill the grid and overflow to additional rows.