Title | Java Console Class - javatpoint |
---|---|
Author | Abhishek Auti |
Course | Chemical engineering |
Institution | Savitribai Phule Pune University |
Pages | 7 |
File Size | 347.6 KB |
File Type | |
Total Downloads | 25 |
Total Views | 159 |
it is related to study...
4/30/2020
Java Console Class - javatpoint
Ad
Deploy Runtimes - Quick & Easy Spend less time resolving dependencies and more time on quality
ActiveS
Java Console Class The Java Console class is be used to get input from console. It provides methods to read texts and passwords. If you read password using Console class, it will not be displayed to the user. The java.io.Console class is attached with system console internally. The Console class is introduced since 1.5.
⇧ https://www.javatpoint.com/java-console-class
1/7
4/30/2020
Java Console Class - javatpoint
Let's see a simple example to read text from console.
String text=System.console().readLine(); System.out.println("Text is: "+text);
Java Console class declaration Let's see the declaration for Java.io.Console class:
public final class Console extends Object implements Flushable
Java Console class methods Method Reader reader()
Description It is used to retrieve the reader object associated with the console
String readLine()
It is used to read a single line of text from the console.
String readLine(String fmt,
It provides a formatted prompt then reads the single line of text
Object... args)
from the console.
char[] readPassword()
It is used to read password that is not being displayed on the console.
char[] readPassword(String
It provides a formatted prompt then reads the password that is
fmt, Object... args)
not being displayed on the console.
⇧ https://www.javatpoint.com/java-console-class
2/7
4/30/2020
Java Console Class - javatpoint
Console format(String fmt,
It is used to write a formatted string to the console output
Object... args)
stream.
Console printf(String format,
It is used to write a string to the console output stream.
Object... args) PrintWriter writer()
It is used to retrieve the PrintWriter object associated with the console.
void flush()
It is used to flushes the console.
How to get the object of Console System class provides a static method console() that returns the singleton instance of Console class.
public static Console console(){} Let's see the code to get the instance of Console class.
Console c=System.console();
Java Console Example import java.io.Console; class ReadStringTest{ public static void main(String args[]){ Console c=System.console();
⇧
System.out.println("Enter your name: "); https://www.javatpoint.com/java-console-class
3/7
4/30/2020
Java Console Class - javatpoint
String n=c.readLine(); System.out.println("Welcome "+n); } } Output
Enter your name: Nakul Jain Welcome Nakul Jain
Java Console Example to read password import java.io.Console; class ReadPasswordTest{ public static void main(String args[]){ Console c=System.console(); System.out.println("Enter password: "); char[] ch=c.readPassword(); String pass=String.valueOf(ch);//converting char array into string System.out.println("Password is: "+pass); } } Output
Enter password: Password is: 123
⇧ https://www.javatpoint.com/java-console-class
4/7
4/30/2020
Java Console Class - javatpoint
← prev
next →
Help Others, Please Share
Learn Latest Tutorials
AutoCad
Kubernetes
Openpyxl
Tally
Godot
Spring Boot
Gradle
UML
ANN
ES6
Flutter
Selenium Py
⇧ https://www.javatpoint.com/java-console-class
5/7
4/30/2020
Java Console Class - javatpoint
Preparation Aptitude
Logical Reasoning
Verbal Ability
Interview Questions
Reasoning
Verbal A.
Interview
Aptitude
Company Interview Questions Company
Trending Technologies Artificial Intelligence Tutorial
AWS Tutorial AWS
Selenium tutorial Selenium
Cloud tutorial
Hadoop tutorial
Cloud
Hadoop
AI
ReactJS Tutorial
Data Science Tutorial
ReactJS
D. Science
Machine Learning Tutorial
DevOps Tutorial
Angular 7 Tutorial
Blockchain Tutorial
Git Tutorial Git
Angular 7
Blockchain
DevOps ML
B.Tech / MCA https://www.javatpoint.com/java-console-class
⇧ 6/7
4/30/2020
Java Console Class - javatpoint
DBMS tutorial
Data Structures tutorial
DBMS
DAA tutorial
Operating System tutorial
DAA
OS
DS
Compiler Design tutorial Compiler D.
Computer Organization and Architecture
Computer Network tutorial C. Network
Discrete Mathematics Tutorial
Ethical Hacking Tutorial
Computer Graphics Tutorial
D. Math.
E. Hacking
C. Graphics
Cyber Security tutorial
Automata Tutorial
COA
Software Engineering Tutorial
html tutorial Web Tech.
C++
Automata
C
Python tutorial
List of Programs
Python
Programs
Cyber Sec.
Software E.
C++ tutorial
C Language tutorial
Java tutorial Java
.Net Framework tutorial .Net
Control Systems tutorial
Data Mining Tutorial Data Mining
Control S.
⇧ https://www.javatpoint.com/java-console-class
7/7...