{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CSE Cheet Sheet 2

CSE Cheet Sheet 2 - Exceptions are objects that describe...

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

View Full Document Right Arrow Icon
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. 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. How are exceptions defined in a class (how do you specify an exception can be thrown?) public static void main (String[] args) throws IOException { // the code that throws the exception is here } 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). What is a Stream? A stream is a sequence of bytes that flow from a source to a destination What are the three standard Streams? Standard Input, Standard Output, Standard Error When two objects share the same memory address they are called? Aliases , Student student1 = new Student(); Student student2 = new Student(); student1 = student2; 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. 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. How are interfaces, abstract classes, and inherited classes different? Classes can only inherit from one class, however they can implement multiple classes.
Background image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}