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