Skip to main content

Important Web Design and Development Short Questions

Chapter: 13
Question 1:
What is an inner class in Java, and how can it be used in event handling?
Answer: An inner class is a class defined within another class. It can be used in event handling to manage events while allowing the outer class to inherit from other classes. Inner classes have access to the outer class's members and can be used for organizing event handling code.
Chapter: 13
Question 2:
How can inner classes solve the problem of single inheritance in Java when handling multiple types of events?
Answer: Inner classes allow you to handle multiple types of events by defining separate inner classes for each type of event, even if the outer class is inheriting from another class. This avoids the problem of single inheritance.
Chapter: 13
Question 3:
What is the role of the WindowHandler inner class in the EventEx example?
Answer: In the EventEx example, the WindowHandler inner class extends WindowAdapter and overrides the windowClosing method to display a "Good Bye" message and exit the application when the window is closed.
Chapter: 13
Question 4:
What are anonymous inner classes, and when are they typically used?
Answer: Anonymous inner classes are unnamed classes defined at the point of instantiation. They are used for short-lived, one-time use cases where a named class is not necessary, such as handling an event in a concise way.
Chapter: 13
Question 5:
How does the EventEx example use an anonymous inner class to handle window events?
Answer: In the EventEx example, an anonymous inner class is used to handle window events by creating an instance of WindowAdapter directly within the addWindowListener method call, and overriding the windowClosing method to show a message before exiting.
Chapter: 13
Question 6:
What are the benefits of using inner classes or anonymous inner classes in GUI event handling?
Answer: Using inner or anonymous inner classes keeps event handling code close to the GUI components it manages, making the code more organized and easier to maintain. Inner classes also allow the outer class to inherit from other classes while still handling events effectively.
Chapter: 14
Question 7:
What is the purpose of Java Database Connectivity (JDBC)?
Answer: JDBC provides a standard library for accessing databases in Java. It offers interfaces and classes to interact with relational databases, allowing Java applications to execute SQL queries and update operations on a database.
Chapter: 14
Question 8:
Which package must be imported to use JDBC in Java?
Answer: You need to import the java.sql package, which contains the basic interfaces and classes required to work with databases using JDBC.
Chapter: 14
Question 9:
How do you set up a Data Source Name (DSN) for Microsoft Access?
Answer: Go to Control Panel → Administrative Tools → Data Sources (ODBC). In the System DSN tab, click Add, choose Microsoft Access Driver (*.mdb), and then set up the DSN by selecting the database file and naming the DSN, e.g., personDSN.
Chapter: 14
Question 10:
What is the first step to connect to a database using JDBC?
Answer: The first step is to import the java.sql package, which provides the necessary classes and interfaces for JDBC operations.