As computer users we are familiar with the response computer programs have from user input and output. This lesson helps show the flip side of how programmers can code a Java program that considers, interprets, and responds to input and output. As this is your first adventure into the realms of more advanced Java, we want to encourage you to explore the Java documentation, the official technical data that goes along with each version of Java that is released.

Java is a powerful programming language that provides us with many ways to read input and write output to consoles, files, etc. In this lesson, we will learn about some of the built-in classes that are useful for completing these tasks, specifically, reading and writing text to a file. Some of these classes include:

Class Definition
System.out A class that holds functions to display out in a terminal or command prompt application.
Scanner A class used to read input passed into a Java program.
FileWriter A class that holds functions to convert byte data into readable text files.
FileReader A class that has functions that convert input from files to byte data for a Java program to use.

We will also learn how to handle potential exceptions that occur due to input and output in a Java program and introduce FileInputStream and FileOutputStream two classes used for reading and writing binary information from files that will be very useful in our continued exploration of Java serialization. By the end of this lesson, we will have successfully run a Java program through the terminal that is capable of reading and writing to the file system!


Review the table to gain a high-level understanding of each class’s purpose, then move on to the next exercise! Explore some of the Java documentation, it may seem pretty intimidating right now, but the first step is familiarization, eventually with repeated exposure, you will gain a solid understanding of the format.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?