Skip to main content

Important Web Design and Development Short Questions

Chapter: 7
Question 1:
What is the difference between unchecked and checked exceptions in Java?
Answer: Unchecked exceptions are subclasses of RuntimeException and Error, do not require explicit handling, and are usually internal to the program. Checked exceptions must be caught or declared in a throws clause, and the compiler will issue an error if not handled.
Chapter: 7
Question 2:
How does the try block work in Java?
Answer: The try block in Java contains code that might generate errors. If an exception occurs within this block, the corresponding catch block is executed to handle the exception.
Chapter: 7
Question 3:
What is the purpose of the finally block in Java exception handling?
Answer: The finally block in Java always executes whether an exception occurs or not. It is typically used to clean up resources, such as closing a file or database connection.
Chapter: 7
Question 4:
What does the throw keyword do in Java?
Answer: The throw keyword in Java is used to manually throw an exception. This can be used when the programmer wants to create an exception explicitly.
Chapter: 7
Question 5:
What is the role of the throws keyword in Java?
Answer: The throws keyword in Java is used in a method signature to declare that the method might throw certain exceptions, passing the responsibility of handling them to the caller of the method.
Chapter: 7
Question 6:
What happens if a finally block is present but an exception occurs in the try block?
Answer: If an exception occurs in the try block and a finally block is present, the finally block will still execute after the catch block (if present) or after the exception is thrown.
Chapter: 7
Question 7:
What is printStackTrace in Java, and why is it useful?
Answer: printStackTrace is a method defined in the Throwable class that shows the full method calling history with line numbers. It is extremely useful in debugging to trace where an exception occurred.
Chapter: 8
Question 8:
What is a stream in the context of Java I/O?
Answer: A stream in Java I/O represents an abstraction of a data source or sink, which can produce or receive pieces of data. It simplifies data handling for various devices.
Chapter: 8
Question 9:
Why is the concept of streams important in Java?
Answer: Streams provide a uniform way to interact with different data sources (e.g., files, consoles, networks) by abstracting the complexities of each device into a common interface.
Chapter: 8
Question 10:
How are Java I/O library classes categorized?
Answer: Java I/O classes are divided by input and output. Input streams read data, while output streams write data. They help in managing data flow between the program and devices.