Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CAN YOU DO QUESTION 1 IN JAVA LANGUAGE. THANKS 752 Chapter 11 Exceptions and Adv

ID: 663102 • Letter: C

Question

CAN YOU DO QUESTION 1 IN JAVA LANGUAGE. THANKS

752 Chapter 11 Exceptions and Advanced File I/O 11. Assume that the reference variable r refers to a serializable object. Write code that serializes the object to the file ObjectData.dat Short Answer exception is thrown? 1. What is meant when it is said that an 2. What does it mean to catch an exception? 3. What happens when an exception is thrown, but the try statement does not have a catch clause that is capable of catching it? 4. What is the purpose of a finally clause? 5. Where does execution resume after an exception has been thrown and caught? 6. When multiple exceptions are caught in the same try statement and some of them are 7. 8. 9. 10. 11. 12. 13. related through inheritance, does the order in which they are listed matter? What types of objects can be thrown? When are you required to have a throvs clause in a method header? What is the difference between a checked exception and an unchecked e What is the difference between the throw statement and the throws clause? What is the difference between a text file and a binary file? What is the difference between a sequencial access file and a random access file? What happens when you serialize an object? What happens when you deserialize an object? xception? Programming Challenges MyProgramminglab Visit www.myprogramminglab.com to complete many of these Programming Challenges online and get instant feedback. 1. TestScores Class Write a class named Testscorea. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgunentexception. Demonstrate the class in a program. 2. Testscores Class Custom Exception Write an exception class named InvalidTestscore. Modify the TestScores class you wrote in Programming Challenge 1 so that it throws an InvalidTestScore exception if any of the test scores in the array are invalid. 3. RetailItem Exceptions Programming Challenge 4 of Chapter 6 required you to write a Retailiten class that holds data pertaining to a retail item. Write an exception class that can be instantiated and thrown when a negative number is given for the price. Write instantiated and thrown when a negative number is given for the units on hand. Demon- strate the exception classes in a another exception class that can be i program

Explanation / Answer

Short Answer:

Question 1: What is the meant when it is said that an exception is thrown?

Ans 1:

A Java function can throw an exception if it encounters a condition it cannot handle. The concept is simple: a function will not only inform the Java compiler what values it can return, it is also going to inform the compiler what can go incorrect.

For example, Java code that attempts to read from a text file knows that the text file might not exist or that it might be empty. The java code that tries to process the information in a file therefore will need to notify the compiler that it can throw some sort of IOException.

The place where you promote that your function can throw an exception is in the header of the function; the header changes to reflect the checked exceptions the function can throw.

For example, here is the header for a function in the Java BufferedReader class from the standard java library. The method reads a line of text from a stream, such as a text file or network connection.

public String readLine() throws IOException

The header indicates this function returns a string, but it also has the capacity to go wrong in a special way

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote