Join David Gassner for an in-depth discussion in this video Using try-with-resources in Java 7, part of Advanced Java Programming.
The Finally block, which I demonstrated in a previous video, is how you always cleaned…up resources in versions of Java prior to Java 7.…But in Java 7 a new syntax was introduced, that's called TryWithResources.…I'll demonstrate it in this project, starting with the Try/catch/Finally architecture that I used before.…In order to use TryWithResources you take instantiation of resources that need to be…cleaned up, and you move them into a pair of parentheses after the Try keyword.…
In my code that means the FileReader and the BufferedReader.…So to change to the Java 7 syntax I'll place the cursor after the Try, and I'll put in…a pair of parentheses. And I'll make a little bit of space between them.…Now I'll take my declarations of the FileReader and the BufferedReader, and I'll cut and…paste that code into the Try call.…I'll also take the code that's instantiating the classes and move those as well.…
So I'm reducing the amount of code it takes to instantiate these objects, grouping the…code together, and setting it up so that these objects will be cleaned up automatically regardless…
- Installing Java on Windows and Mac OS X
- Installing Eclipse
- Using new features such as simplified generics
- Working with advanced class structures (member, local inner, etc.)
- Using the Reflection API
- Navigating inheritance trees
- Managing unordered and ordered sets
- Peeking and polling with queues
- Testing and error handling
- Managing files and directories
- Working with I/O streams
- Next steps with Java
Skill Level Advanced
1. Getting Started
2. Java 7 New Features
3. Using Advanced Class Structures
4. Using the Reflection API
5. More of the Collections Framework
6. Testing and Advanced Exception Handling
Using the finally keyword5m 40s
7. Managing Files and Directories in Java 7
8. Working with I/O Streams
9. Working with Multi-threading
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.