Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 17.4, Problem 17.4.1CP
Explanation of Solution
Necessity of declaring “IOException”:
Most of the methods in the I/O classes throw “java.io.IOException” So, it is necessary to declare to throw “java.io.IOException”.
It is not possible to throw multiple exceptions in a single throw statement, because each throw statement handles only a single exception.
Declaration of exception in the method:
public static void main(String[] args)
{
thro...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a class called MyException with appropriate attributes and methods toprocess different types of exceptions thrown in C++ and add proper comments in the code.thanks
Is the SecurityException type a checked or unchecked exception in the java.lang package? Must we not throw NoSuchMethodException? Be sure to provide reasons for your answers.
How can you handle potential exceptions like IOException when working with InputStreams in Java?
Chapter 17 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 17.2 - What is a text file and what is a binary file? Can...Ch. 17.2 - How do you read or write text data in Java? What...Ch. 17.3 - Prob. 17.3.1CPCh. 17.3 - How is a Java character represented in the memory,...Ch. 17.3 - If you write the string ABC to an ASCII text file,...Ch. 17.3 - If you write the string 100 to an ASCII text file,...Ch. 17.3 - What is the encoding scheme for representing a...Ch. 17.4 - Prob. 17.4.1CPCh. 17.4 - Why should you always close streams? How do you...Ch. 17.4 - Prob. 17.4.3CP
Ch. 17.4 - Does FileInputStream/Fi1eOutputStream introduce...Ch. 17.4 - What will happen if you attempt to create an input...Ch. 17.4 - How do you append data to an existing text file...Ch. 17.4 - Prob. 17.4.7CPCh. 17.4 - What is written to a file using writeByte(91) on a...Ch. 17.4 - How do you check the end of a file in an input...Ch. 17.4 - What is wrong in the following code? Import...Ch. 17.4 - Suppose you run the following program on Windows...Ch. 17.4 - After the following program is finished, how many...Ch. 17.4 - For each of the following statements on a...Ch. 17.4 - What are the advantages of using buffered streams?...Ch. 17.5 - How does the program check if a file already...Ch. 17.5 - How does the program detect the end of the file...Ch. 17.5 - How does the program count the number of bytes...Ch. 17.6 - Prob. 17.6.1CPCh. 17.6 - Prob. 17.6.2CPCh. 17.6 - Is it true that any instance of...Ch. 17.6 - Prob. 17.6.4CPCh. 17.6 - Prob. 17.6.5CPCh. 17.6 - What will happen when you attempt to run the...Ch. 17.7 - Can RandomAccessFi1e streams read and write a data...Ch. 17.7 - Create a RandomAccessFi1e stream for the file...Ch. 17.7 - What happens if the file test.dat does not exist...Ch. 17 - (Create a text file) Write a program to create a...Ch. 17 - (Create a binary data file) Write a program to...Ch. 17 - (Sum all the integers in a binary data file)...Ch. 17 - (Convert a text file into UTF) Write a program...Ch. 17 - Prob. 17.5PECh. 17 - Prob. 17.6PECh. 17 - Prob. 17.7PECh. 17 - (Update count) Suppose that you wish to track how...Ch. 17 - (Address book) Write a program that stores,...Ch. 17 - (Split files) Suppose you want to back up a huge...Ch. 17 - (Split files GUI) Rewrite Exercise 17.10 with a...Ch. 17 - Prob. 17.12PECh. 17 - (Combine files GUI) Rewrite Exercise 17.12 with a...Ch. 17 - (Encrypt files) Encode the file by adding 5 to...Ch. 17 - (Decrypt files) Suppose a file is encrypted using...Ch. 17 - (Frequency of characters) Write a program that...Ch. 17 - (BitOutputStream) Implement a class named...Ch. 17 - (View bits) Write the following method that...Ch. 17 - (View hex) Write a program that prompts the user...Ch. 17 - (Hex editor) Write a GUI application that lets the...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- 3. Explain the difference between a programmer-defined exception that extends the Java Exceptionclass and one that extends the Java RunTimeExceptionclass.arrow_forwardHow would a try-catch block in a java program to be used to solve the following errors within the file. If the user enters the incorrect file name, or the wrong format of a number like 'two' instead of the digit '2'?arrow_forwardIs the Security Exception that comes from the java.lang package a checked exception or an unchecked one? What about an exception that says there is no such method?arrow_forward
- Write a Java application with comments, that throws and catches an ArithmeticException when you attempt to take the square root of a negative value. Prompt the user for an input value and try the Math.sqrt() method on it. The application either displays the square root or catches the thrown Exception and displays an appropriate message.arrow_forwardI have to create a Java program that lets the user interact with it, so they can learn about exceptions. How do I let the user interact with a list of options and direct them to a catch statement? Here is my program so far: import java.util.Scanner;import java.io.*;import java.util.InputMismatchException; public class Exceptions{ public static void main(String[] args)throws IOException{ // declare variables char option = 'y'; //Arithhmetic & Array TEST int array[] = {10,20,30,40}; int num1 = 50; int num2 = 10; // Setting up scanner to get user data Scanner exc = new Scanner(System.in); // Main method (menu, try-catch block) // all within a loop try { } // I want to learn how an ArrayIndexOutOfBoundsException... catch(ArrayIndexOutOfBoundsException exception) { System.out.println("This exception is thrown when the array index that was entered is…arrow_forwardWith reason Output of this :-System.out.println(0/0) ;System.out.println(0.0/0) ;A) NAN, NANB) INFINITY, INFINITYC) EXCEPTION, EXCEPTIOND) EXCEPTION, INFINITY Explain the logic alsoarrow_forward
- In Java when a method throws a checked Exception, what must we always do when calling that method? A. Make sure to declare the method as static. B. Put it inside a try/catch block. C. Set the permission level of the method to private. D. Check our input, and if it will be bad input we must throw an exception before calling the method.arrow_forwardyour code does not run Exception Handling correctly like shown in my 2nd picture . Can you please fix it ?arrow_forwardAnswer the following questions based on your knowledge of java exception and java text and binary I/Os: Java exception can be handled locally using try-catch block or can be thrown to the calling When should you prefer to throw an exception to the calling method instead of using try-catch? Is it possible to write a program to read from a text file without handling the exception? Why should a programmer consider binary I/O instead of text I/O? Suppose that you are implementing a program to write a string “সিএিই-110” in a binary file. Java provides you three different methods – writeBytes(String), writeChars(String), and writeUTF(String). How many bytes will be written by each of those method for the give string? Why should not you consider the writeBytes(String) method in this case?arrow_forward
- Let's say there is a catch handler that exactly matches the exception object type. What are the conditions in which exception objects of that type could be handled differently?arrow_forwardPLZ help with the follwoing IN JAVA Suppose that statement2 causes an exception in the following try-catch block: Will statement3 be executed? If the exception is not caught, will statement4 be executed? If the exception is caught in the catch block, will statement4 be executed?arrow_forwardPlease fast Concurrent Programming.Can you help me explain what is happening please? In the following code segment what happens after the processRow method finishes while (!done){processRow(myRow);try{barrier.wait();} catch (interrupted exception, ie){return;}catch(BrokenBarrierException bbe){return;}}arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education