Java 101The Console class

time to read 1 min | 110 words

The Java.io.Console class provides methods to access the character-based console device, if any, associated with the current Java Virtual Machine. This class is attached to the System console internally.

Console class provide means to read text and passwords from the console.

To read a line as a String:

Console console = System.console();
String myString = console.readLine();

To read a password as an array of chars:

Console console = System.console();
char[] pw = console.readPassword();

If you read passwords using Console class, it will not be displayed to the user.

Keep in mind that this class does not have a high level of security and it is mostly used at development stage.


This is a post in the Java 101 series.
Other posts in this series:

  1. Apr 29, 2017 Translating Scanner tokens into primitive types
  2. Apr 28, 2017 Listing a file system's root directories
  3. Apr 27, 2017 The Console class
  4. Apr 20, 2017 Using an interface as a parameter
  5. Apr 19, 2017 Using bounded type parameters in generic methods
  6. Apr 18, 2017 Using the Deprecated annotation
  7. Apr 17, 2017 Diamond Operator in Java
  8. Apr 15, 2017 Altering format string output by changing a format specifier's argument_index
  9. Apr 13, 2017 Future of Interface in Java 9
  10. Apr 12, 2017 More about Interface in Java 8
  11. Apr 10, 2017 Manage Your JVM Environment with SDKMAN
  12. Apr 09, 2017 Updating interfaces by using default methods
  13. Apr 08, 2017 Converting Stacktrace to String

Related Post:

  1. May 02, 2017 Get more with collections!
  2. Apr 29, 2017 Translating Scanner tokens into primitive types
  3. Apr 28, 2017 Listing a file system's root directories
  4. Apr 20, 2017 Using an interface as a parameter
  5. Apr 19, 2017 Using bounded type parameters in generic methods
  6. Apr 18, 2017 Using the Deprecated annotation
  7. Apr 17, 2017 Diamond Operator in Java
  8. Apr 15, 2017 Altering format string output by changing a format specifier's argument_index
  9. Apr 13, 2017 Future of Interface in Java 9
  10. Apr 12, 2017 More about Interface in Java 8
  11. Apr 11, 2017 Spring Boot in a Single File
  12. Apr 10, 2017 Manage Your JVM Environment with SDKMAN
  13. Apr 09, 2017 Updating interfaces by using default methods
  14. Apr 08, 2017 Converting Stacktrace to String
  15. Apr 07, 2017 Synchronized Statement in Java
  16. Jul 12, 2016 Fix Java Unsupported major.minor version 52.0 on Ubuntu