---
title: "Java Console Class"  
description: "The Java Console class is often using to get input from console. It provides methods to read text and password."  
author: "Anupam Mishra"  
published: 2015-11-16  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/11915/java-console-class  
category: "java"  
tags: ["java", "j2ee"]  
reading_time: 1 minute  

---

# Java Console Class

If you want to read [password](https://www.mindstick.com/blog/118/retriving-user-password-by-using-stored-procedure-in-asp-dot-net) using [Console](https://www.mindstick.com/blog/210/the-console-class) [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp), it will not be displayed to the user end.\

The Console class is internally attached with [system](https://yourviews.mindstick.com/view/87103/allahabad-high-court-bulldozed-the-islamic-madrasa-system-in-up) console. Console class is defined in java.io package.

Let’s we take example to read [user name](https://answers.mindstick.com/qa/30717/how-to-retrieve-user-name-in-case-of-window-authentication) and password given by the user end.\

> ```
> import java.io.*;  class ConsoleClassEx{  public static void main(String args[]){  Console c=System.console();System.out.println("Enter your name: ");  String n=c.readLine();  System.out.println("Enter password: ");  char[] ch=c.readPassword(); //It's not shown  user endString pass=String.valueOf(ch);//converting char array into string  System.out.println("Welcome "+n); System.out.println("Password is: "+pass);  }  }
> ```

![Java Console Class](https://www.mindstick.com/mindstickarticle/1bab7ba5-d2f6-4b54-b070-b27c4795e045/images/cbe182ed-8ae0-4493-8d76-0b1efdc44162.png)

>

\

---

Original Source: https://www.mindstick.com/articles/11915/java-console-class

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
