Java Console Methods

Beginner
4 min read
Updated: Nov 2026
8 method guides
Method index

About This Index

This page is the Java Console Methods index: every public method of the java.io.Console class, each with a full guide covering syntax, parameters, return value, exceptions, three runnable examples, and FAQs. Each example shows the output of a real terminal run, with the text you type marked clearly.

Learn what the Console class is and why System.console() can be null on the Console hub. Use this page when you need a specific method such as readLine(), readPassword(), or printf(). All examples compile on Java 8 and later, except charset(), which needs Java 17.

Run the examples in a terminal.

Many IDE run windows are not real terminals, so System.console() returns null there. Compile and run with javac Name.java and java Name in Command Prompt, PowerShell, or a macOS/Linux terminal.

How to Call a Console Method

Every method here is an instance method: get the console once, check it for null, then call methods on it:

Java
import java.io.Console;

Console console = System.console();
if (console == null) {
    System.out.println("No console available.");
    return;
}
String name = console.readLine("Name: ");      // read a line
console.printf("Hello, %s!%n", name);          // formatted output
char[] pin = console.readPassword("PIN: ");    // hidden input

Java Console Methods Table

All method guides in this Java tutorial series (8 tutorials), grouped by purpose.

Write output to the terminal

4 methods

Print formatted text, get the console PrintWriter, and make sure buffered text actually reaches the screen.

MethodDescriptionTutorial
format()Write formatted text, such as padded columns and rounded numbers, to the terminal.Try it
printf()Print formatted text to the terminal; a convenience alias of format().Try it
writer()Get the console PrintWriter for print(), println(), and printf() style output.Try it
flush()Force any buffered console output to appear on the screen right away.Try it

Read input from the keyboard

3 methods

Read a line of text, read a password without showing it, or get a Reader to wrap in a Scanner or BufferedReader.

MethodDescriptionTutorial
readLine()Read one line of text typed by the user, optionally after a formatted prompt.Try it
readPassword()Read a password or PIN without showing the typed characters, returned as a char array.Try it
reader()Get the console Reader to wrap in a Scanner or BufferedReader.Try it

Console information

1 method

Find out which character encoding the terminal uses (Java 17+).

MethodDescriptionTutorial
charset()Get the Charset the terminal uses to encode printed text and decode typed text (Java 17+).Try it

Frequently Asked Questions

This series covers format(), printf(), writer(), and flush() for output; readLine(), readPassword(), and reader() for input; and charset() (Java 17+) for encoding information.
This index lists 8 guides, from charset() to writer(), grouped into output, input, and console information.
Call System.console(). Console has no public constructor. The method returns null when no interactive terminal is attached, so check for null before you use the result.
readLine() for normal text, readPassword() for passwords and PINs, and reader() when you want to wrap the input in a Scanner or BufferedReader.
Read the Java Console hub first. Then open readLine(), printf(), and readPassword() from the tables below.

Start with readLine()

Ask the user a question and read the answer, with a prompt and a null check.

readLine() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful