Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Advanced Java Wrap-up

This section covered some of the more advanced topics in Java. You learned about:

  • Exceptions: How to handle errors and exceptional situations in your code.
  • Collections: How to use the Java Collections Framework to store and manipulate groups of objects.
  • Streams: How to use the Streams API to process collections of data in a declarative way.
  • Generics: How to write type-safe code that works with different types of objects.
  • File I/O: How to read from and write to files.
  • Threads: How to write multithreaded programs that can perform multiple tasks concurrently.

Exercise

Write a Java program that reads a list of words from a file, counts the frequency of each word, and then writes the results to a new file.

Requirements:

  1. Create a text file named words.txt with a list of words, one word per line.
  2. Write a program that reads the words from words.txt.
  3. Use a Map to store the frequency of each word.
  4. Use the Streams API to process the list of words.
  5. Write the word frequencies to a new file named word_frequencies.txt.
  6. Handle any potential IOExceptions that may occur.