Skip to main content

Important Web Design and Development Short Questions

Chapter: 8
Question 1:
In the example code for reading from a file, what is the role of the readLine() method?
Answer: The readLine() method reads a line of text from the file, returning null when the end of the file is reached.
Chapter: 8
Question 2:
What is the purpose of the flush() method in PrintWriter?
Answer: The flush() method ensures that all data in the stream's buffer is written to the file, clearing the buffer for further data.
Chapter: 9
Question 3:
What is the purpose of adding persistence functionality to the address book?
Answer: Adding persistence functionality ensures that records in the address book are saved and available even after the program is closed and reopened. This is achieved by reading from and writing to a text file that stores the person records.
Chapter: 9
Question 4:
How do you handle the scenario when the application starts up and needs to read person records?
Answer: On application start-up, you establish a data channel with a file, read the data line by line, tokenize each line to extract person details, construct PersonInfo objects, and add them to an ArrayList. You then close the stream with the file.
Chapter: 9
Question 5:
What is the role of BufferedReader in the loadPersons method?
Answer: BufferedReader is used to read data efficiently from a file line by line. It is a filter stream that wraps around a FileReader, providing buffering and reducing the number of read operations.
Chapter: 9
Question 6:
What is the difference between a node stream and a filter stream in Java I/O?
Answer: Node streams directly connect to a data source or sink, providing basic functionality for reading/writing data. Filter streams, on the other hand, sit on top of node streams and add additional functionalities like buffering, compression, or encryption.
Chapter: 9
Question 7:
Explain the process of saving person records when the application exits.
Answer: To save person records, you open a data channel with a file, iterate over the ArrayList of PersonInfo objects, build a string for each person with commas separating attributes, write the string to the file, and then close the stream. Ensure to flush the data before closing.
Chapter: 9
Question 8:
What does the split method do in the loadPersons method?
Answer: The split method is used to tokenize a line of text by dividing it into substrings based on a specified delimiter (e.g., a comma). This helps in extracting individual data fields like name, address, and phone number from each line of the file.
Chapter: 9
Question 9:
Why must an abstract class be declared abstract in Java?
Answer: An abstract class must be declared abstract if it contains abstract methods (methods without implementations). This prevents the instantiation of the class and requires subclasses to provide implementations for all abstract methods to become concrete classes.
Chapter: 9
Question 10:
How does an interface differ from an abstract class in Java?
Answer: An interface is a contract that specifies methods without implementations, while an abstract class can have both abstract and fully implemented methods. Interfaces support multiple inheritance, allowing a class to implement multiple interfaces, whereas abstract classes support single inheritance.