Codecademy Logo

Input and Output

Scanner class

The Scanner class is used to read user input in a Java program. It requires declaration within a program before a user of the program is prompted to input values.

IOExceptions

IOExceptions refer to any errors that a program may encounter that are related to the input or output of a Java program.

Compiling Java Programs

Java programs must first be compiled into bytes, and only then can they be run using the terminal or command prompt.

FileInputStream

In Java, FileInputStream is used to read data from a file into the program.

FileOutputStream

In Java, FileOutputStream is used to output data from a program into a file on your computer.

System.out

In order to print output using a Java program, a developer can use the following three commands:

  • System.out.print(): prints in the same line a when a program is running
  • System.out.println(): prints output in a new line
  • System.out.printf(): prints formatted string. It allows for the use of format specifiers such as “%s” or “%c” that can be used to insert variable values

Learn More on Codecademy