Video is locked.

Unlock the full course today

Join today to access over 15,000 courses taught by industry experts or purchase this course individually.

Advanced Java Programming

Using try-with-resources with I/O

From the course: Advanced Java Programming

Start my 1-month free trial
  • Course details

    Want to get more out of the Java language and platform? In this platform- and framework-neutral course, instructor Bethan Palmer digs into some of the language’s more advanced features, helping you expand your programming skills as she equips you with techniques you can use when building applications anywhere Java is used: in web, mobile, and desktop applications. Bethan covers a variety of topics, including generics, working with the Collections Framework, and functional programming. Plus, learn about I/O in Java, working with files and directories, and structuring applications using the modular system available in Java.

    Instructor

    • Click here to view Bethan Palmer’s instructor page

      Bethan Palmer

      Software Developer and Java Champion

      Bethan Palmer is a developer who loves technology and has a master's degree in computer science.

      For her day job, Bethan is a Java programmer and the product manager for a Java PDF library at IDRsolutions. She gets to spend a lot of time writing and refactoring code, as well as deciding on product strategy and road maps.

      She also spends much of her time attending conferences and is a regular speaker at Oracle Code One and NetBeans Days. She manages and writes articles about Java, technology, the books she's reading, and conferences she's attending on the Java PDF blog.

    Skills covered in this course

    For each course you will get

    • Exercise files and quizzes
    • Certificate of completion from LinkedIn
    • Offline and audio-only options
    Start my free month
  • Learn advanced Java programming

    - [Instructor] When using input and output resources, it is important to use try with resources whenever you can. Using try with resources makes sure that all resources are closed for me. I don't have to worry about manually closing all resources which can be difficult. If resources aren't closed properly, it is easy to end up with code-leaking resources. This is especially true if you are using multiple resources that interact with each other. In this example, I have a class called TryWithResourcesExample. Inside the main method, I have a buffered reader wrapped around a string reader, which just takes a simple string containing Hello World. I then have a simple string writer called writer. Next, I call writer.write, and inside that method, I call reader.readLine so I am using a reader to read a string and then I'm writing it to a writer. Finally, I print out the result. When I run the program, I get the simple Hello World message printed to the console. I have wrapped all of my code…

  • Practice while you learn with exercise files

    Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.

    Download the exercise files for this course. Get started with a free trial today.

  • Download courses and learn on the go

    Watch courses on your mobile device without an internet connection. Download courses using your iOS or Android LinkedIn Learning app.

    Watch this course anytime, anywhere. Get started with a free trial today.

Contents