Java console class | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Java console class

Recently I had a look at the java console class and I saw that System.console() has a possibility of returning null. In what case does this occur in? and what is the main use of the console class in java?

14th Nov 2020, 7:47 PM
pNK
pNK - avatar
2 Answers
+ 2
Console is a class in java.io.Console. It is used to read input like Scanner. You can get a line of input with Console.console().readLine(). Console class is a singleton. Meaning that it has only 1 object, which can be accessed with console() method. console() returns the only object of Console class. If Console somehow doesn't have an object, it returns null.
15th Nov 2020, 2:46 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
CarrieForle Thank you for the answer
15th Nov 2020, 8:37 PM
pNK
pNK - avatar