Java Console ClassLast Updated : 24 Jan 2026 The Console class in Java is used to read input from the system console, including text and passwords. In this chapter, we will learn what the Console class is, why it is used, its declaration, important methods, how to obtain a Console object, and how to read text and passwords using examples. What is Console Class in Java?The Console class is used to interact with the system console, and it is used to read text input and passwords securely from the user. When a password is read using the Console class, the characters are not displayed on the screen. The Console class is internally connected to the system console and was introduced in Java 1.5. Java Console class declarationThe following declaration shows how the Console class is defined in Java. Constructor of Console ClassThe Console class does not provide any public constructors. The Console class is created internally by the Java runtime and is tightly bound to the system console. Because of this, you cannot create a Console object using the new keyword. Instead, the Console object is obtained using the System.console() method. Getting Console ObjectThe System class provides a method to obtain the Console object. Note: If the program is not run from a real console (for example, inside some IDEs), this method may return null. Methods of Console ClassThe Console class provides methods to read input and write output to the console.
Examples of Java Console ClassThe following examples demonstrate how to use the Console class to read user input. Example 1: Reading Text from ConsoleThis example demonstrates how to read a line of text from the console using the Console class. Output: Enter your name: Nakul Jain Welcome Nakul Jain Example 2: Reading Password from ConsoleThis example demonstrates how to read a password from the console without displaying it on the screen. Output: Enter password: Password is: 123 Next TopicJava FilePermission Class |
We request you to subscribe our newsletter for upcoming updates.