Question
Java Programming
Q4 a. List five common examples of exceptions b. What is resource leak c. What happens if several catch blocks match the ty
0 0
Add a comment Improve this question Transcribed image text
Answer #1

sol:

a) 1. ArithmeticException:

           when error occurred in arithmetic operations this exception occurs

    2. ArrayIndexOutOfBoundsException

            when array accessed with illegal index (that is index is greater or equal to size of array ) this exception

           occurs

3. IOException

        if input output operation failed, this exception occurs

    4. NoSuchFieldException

       if the field doesn't exist in class this exception occurs

    5. FileNotFoundException

           if the file is not accessiable this exception occurs

b) Resource leak:

Leak occurs when you are not close a reader, scanner, buffer, or another process that uses resources and      

     needs to clean them up out of memory. Then call scanner. close(), after we can use the Scanner for whatever

   we want to do with scanner. This leak is called resource leak.

c) First matching catch block executed, after the try block is executed.

d) Finally block is used to execute important code such as closing connection, stream etc. It always executed

     whether exception is handled or not.

      

              

Add a comment
Know the answer?
Add Answer to:
Java Programming Q4 a. List five common examples of exceptions b. What is "resource leak" c....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • a) List common examples of exceptions and explain how exceptions are handles in c++. (try, catch,...

    a) List common examples of exceptions and explain how exceptions are handles in c++. (try, catch, throw) b) Declare an abstract class Fraction that can be used for arithmetic of the * operator.

  • Exception handling All Exceptions that can be thrown must descend from this Java class: The getMessage(...

    Exception handling All Exceptions that can be thrown must descend from this Java class: The getMessage( ) method is inherited from this class? What are the two broad catagories of Exceptions in Java? If an Exception is not a checked exception it must extend what class? What is the difference between a checked Exception and an unchecked Exception? What are the two options a programmer has when writing code that may cause a checked Exception to be thrown? Can a...

  • Part 2: Programming with Exceptions In this part of the lab , you will write a...

    Part 2: Programming with Exceptions In this part of the lab , you will write a program that fetches the information stored at a give URL on the web and saves that data to a file. This will also include networking and file operations and partly an exercise in using exceptions. For doing I/O, Java has a pair of nice abstractions: InputStream and OutputStream. These are abstract classes in the package java.io. An InputStream is a place from which you...

  • Advanced Object-Oriented Programming using Java Assignment 4: Exception Handling and Testing in Java Introduction -  This assignment...

    Advanced Object-Oriented Programming using Java Assignment 4: Exception Handling and Testing in Java Introduction -  This assignment is meant to introduce you to design and implementation of exceptions in an object-oriented language. It will also give you experience in testing an object-oriented support class. You will be designing and implementing a version of the game Nim. Specifically, you will design and implement a NimGame support class that stores all actual information about the state of the game, and detects and throws...

  • 3. (a) Outline any four features of Object-Oriented Programming OOP, giving examples in each case. [16...

    3. (a) Outline any four features of Object-Oriented Programming OOP, giving examples in each case. [16 marks]      (b) Consider the following code fragments: If   a = 10; Evaluate the new value of “b” in the following:                (i)   b =   ++ a;               (ii) b = a ++;             What value would a and b store in (i) and (ii) after program execution?                                                                                                            [4 marks] 4. Create a C++ program that makes use of three arrays; name, mark, grade. The program should accept...

  • In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list...

    In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list of objects. Also, this lab specification tells you only what to do, you now have more responsibility to design how to do it. Problem description You are given a text file called 'Students.txt' that contains information on many students. Your program reads the file, creating many Student objects, all of which will be stored into an array list of Student objects, in the Students...

  • Please use Java only. Write a class, ZeroException, which is an Exception, and is used to signal...

    Please use Java only. Write a class, ZeroException, which is an Exception, and is used to signal that something is zero when it shouldn't be. -- Not needed Write the class ArrayManipulator which creates an array and provides several methods to manipulate values taken from an array. --needed ZeroException Task: -- Not needed Exceptions are used to signal many types of problems in a program. We can write our own as well to describe specific exceptional conditions which may arise....

  • Please complete the following programming with clear explanations. Thanks! Homework 1 – Programming with Java: What...

    Please complete the following programming with clear explanations. Thanks! Homework 1 – Programming with Java: What This Assignment Is About? Classes (methods and attributes) • Objects Arrays of Primitive Values Arrays of Objects Recursion for and if Statements Selection Sort    Use the following Guidelines: Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc.) Use upper case for constants. • Use title case (first letter is upper case) for classes. Use lower case with uppercase...

  • Please provide the full code...the skeleton is down below: Note: Each file must contain an int...

    Please provide the full code...the skeleton is down below: Note: Each file must contain an int at the beginning, stating the number of records in the file. Afterwards, the number of records in the file will follow. Each record that follows will consist of a last name (String), and a gpa (double). However, to test the error handling of your program, the number of records will not always match the int value. All possible combinations should be tested. 1.) Prompt...

  • In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list of objects. Also, this lab specification tells you only what to do, you now have more responsibility to...

    In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list of objects. Also, this lab specification tells you only what to do, you now have more responsibility to design how to do it. Problem description You are given a text file called 'Students.txt' that contains information on many students. Your program reads the file, creating many Student objects, all of which will be stored into an array list of Student objects, in the Students...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT