DOC PREVIEW
TRINITY CSCI 1321 - Generics, Enums, and Exceptions

This preview shows page 1-2-3 out of 9 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 91Generics, Enums, and Exceptions2/3/20092Opening Discussion■Do you have any questions about the quiz?■Let's look at solutions to the interclass problem.■Will we regularly run out of time before finishing slides?■What is the equivalent of scanf in Java?■Book corrections appreciated.■Do you have any questions about the reading?■Do you have any questions about the assignment?3Making General Typesafe■The problem with using the Object type for general polymorphism is that it many different type checks have to be done at runtime and you lose static type safety.■Using generics we can take our general function interface and make it static typesafe.■How can you combine these more general types of functions?4Enums■C had enums. What were they supposed to do? What was the problem with them?■Java includes enums as well. They serve the same goals, but lack the pitfalls.■Java enum syntax can get quite complex, but the basic form is simple and very similar to C.5Error Handling■How did you handle errors in C? (Consider the fopen function.)■What are some problems with this method?6Exceptions■Error handling in Java is done with exceptions, not return values or flags.■Normal exceptions can't be ignored and they don't propagate. Runtime exceptions don't propagate.7Syntax■For anything that isn't a RuntimeException you have to include handling code. For RuntimeExceptions it is optional.■If you want to deal with a possible exception in the current method do this:try {➔statements} catch(ExceptionType1 e) {➔statements} [catch(ExceptionType2 e) { ...} ...]■If this method can't handle it you add a throws clause to the method and it will go up to the calling method.Type name(args) throws ExType[,...] {...}8Additional Information■Exceptions also have the advantage that they can provide additional information.■Stack trace.■Informative message.■You can create your own exception classes. Strive to have them provide sufficient information for debugging.9Minute Essay■Do you have any questions about Java as a language? We are now moving from the language to libraries and problem solving.■Interclass Problem – Write a program that uses a Scanner to read the contents of a file. The hint is that you will have a line something like Scanner sc=new Scanner(new File(“filename.txt”));. You can decide what to do with the contents. Be creative. You might consider methods like


View Full Document

TRINITY CSCI 1321 - Generics, Enums, and Exceptions

Documents in this Course
Recursion

Recursion

11 pages

Iterators

Iterators

10 pages

Actors

Actors

9 pages

Recursion

Recursion

15 pages

Recursion

Recursion

10 pages

Threads

Threads

7 pages

Trees

Trees

11 pages

Load more
Download Generics, Enums, and Exceptions
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Generics, Enums, and Exceptions and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Generics, Enums, and Exceptions 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?