Exam2ReviewAnswers2

Exam2ReviewAnswers2 - Exam 2 Review Session 1. Exceptions...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Exam 2 Review Session 1. Exceptions are objects that describe unusual or erroneous situations. How do you catch an exception? Put the code that throws an exception inside a try{//statements} block. Then catch the exceptions such as catch(IOException ioe){//statements}. Then you can follow with the optional finally{//statements} block which executes no matter what happens in the try{} block. 2. What is the purpose of the optional finally{} block when handling exceptions? The finally{} block is used to manage resources or to guarantee some code is executed whether or not there is an exception thrown by the code in the try{} block. 3. How are exceptions defined in a class (how do you specify an exception can be thrown?) Example: public static void main (String[] args) throws IOException   {      // the code that throws the exception is here   } 4. Some common exceptions you may have encountered are listed below, when have these needed to be caught? IOException: Thrown by most input/output operations, including keyboard input. NumberFormatException: Thrown for example by Integer.parseInt( ) NotSerializableException: Is thrown when trying to write an object that does not implement the interface Serializable. FileNotFoundException: Has been encountered when trying to read in from a file, but no file with the specified name exists. ArrayIndexOutOfBoundsException: Thrown when trying to access an index bigger than the size of the array (or negative index). 5. What is a Stream? A stream is a sequence of bytes that flow from a source to a destination
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6. What are the three standard Streams? Standard Input Standard Output Standard Error 7. When two objects share the same memory address they are called? aliases example: Student student1 = new Student(); Student student2 = new Student(); student1 = student2; // making them aliases of each other 8. Explain the terms by reference, by value, and what types of parameters are associated with each. By reference means that an address is being passed thus creating an alias from the called methods parameter to the callers passed variable. When changes are made inside the method to the referenced object it changes both the variable inside the method and outside the method. All objects are passed by reference. By value means that a local copy is made and the value of the variable is passed. This is true for all primitive data types. So if you change the value of the variable inside the called method it doesn’t change the variable passed by the caller. 9. How are nested classes different from non-nested classes, Why use them? There are no differences in the make up of the class only the scope that it has been defined in. Nested classes have access to the instance variables of its containing class. Nested classes are compiled into their own bytecode file. 10. How are interfaces, abstract classes, and inherited classes different?
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/18/2011 for the course CSE 205 taught by Professor Matasu during the Spring '08 term at ASU.

Page1 / 14

Exam2ReviewAnswers2 - Exam 2 Review Session 1. Exceptions...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online