Total Pageviews

Wednesday, January 19, 2011

Input and Output


Output - System.out - This is an object not a class.
Input - System.in -See the example below
Scanner scan = new Scanner(System.in);
String str = scan.readLine();
Int a = scan.nextInt();
For password from the command prompt java6 introduces a Console class.
Console cons = System.console();
String username = cons.readLine("User name: ");
char[] passwd = cons.readPassword("Password: ");// password is returned as char array for security reasons

printf in java - Java 5 supports printf someehat similar to that of c. It is implemented to provide formated output.
eg double num = 1000.0/3.0;
System.out.printf("%8.2f",num); shows output as 333.33 (padded with 5 spaces from the left)

2 comments:

  1. java new version supports password masking but is there any other method in previous version for password masking. do anybody knows any ??

    ReplyDelete
  2. @Anjani there is no inbuild mechanism provided by java for console to get password from user. Though this can be done by replacing the character which user enters by "*". (This thing happens in mobile phone browsers).You can have a look at the example for the implementation at : Mask Password

    ReplyDelete