Example usage for java.lang System console

List of usage examples for java.lang System console

Introduction

In this page you can find the example usage for java.lang System console.

Prototype

public static Console console() 

Source Link

Document

Returns the unique java.io.Console Console object associated with the current Java virtual machine, if any.

Usage

From source file:Main.java

public static void main(String[] args) {
    Console console = System.console();

    console.printf("%s%n", "this is a test");
}

From source file:Main.java

public static void main(String[] args) {

    Console ob = System.console();

    ob.printf("from java2s.com");

    ob.flush();
}

From source file:Main.java

public static void main(String[] args) {
    Console console = System.console();

    char passwordArray[] = console.readPassword("Enter your secret password: ");
    console.printf("Password entered was: %s%n", new String(passwordArray));
}

From source file:Main.java

public static void main(String[] args) {
    Console console = System.console();
    if (console != null) {
        console.printf("Console is  available.%n");
    } else {//from www .jav  a  2  s.  c o  m
        System.out.println("Console is  not  available.%n");
        return; // A console is not available
    }
    String userName = console.readLine("User Name: ");
    char[] passChars = console.readPassword("Password: ");
    String passString = new String(passChars);
    if (passString.equals("letmein")) {
        console.printf("Hello %s", userName);
    } else {
        console.printf("Invalid  password");
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    Console cnsl = System.console();

    if (cnsl != null) {

        String name = cnsl.readLine("Name: ");

        System.out.println("Name entered : " + name);
    }/*from w  ww.  j  a  v  a 2s.c  o m*/

}

From source file:Login.java

public static void main(String[] args) throws Exception {
    Console console = System.console();
    String username = console.readLine("Username:");
    char[] pwd = console.readPassword("Password:");

    System.out.println("Username = " + username);
    System.out.println("Password = " + new String(pwd));

    username = "";
    for (int i = 0; i < pwd.length; i++)
        pwd[i] = 0;/*from w  ww . j  a v a2s  . c o  m*/
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    Console cnsl = System.console();

    if (cnsl != null) {

        String alpha = cnsl.readLine("Name: ");

        System.out.println("Name is: " + alpha);

        char[] pwd = cnsl.readPassword("Password: ");

        System.out.println("Password is: " + pwd);
    }/*from  ww  w . jav  a2  s .c om*/
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    Console cnsl = System.console();

    if (cnsl != null) {
        String fmt = "%1$4s %2$10s %3$10s%n";

        // format
        cnsl.printf(fmt, "Items", "Quanity", "Price");
        cnsl.printf(fmt, "-----", "-----", "-----");
        cnsl.printf(fmt, "PHP", "1Kg", "15");
        cnsl.printf(fmt, "CSS", "2Kg", "50");
        cnsl.printf(fmt, "Java", "3Kg", "30");
        cnsl.printf(fmt, "HTML", "4Kg", "80");
    }/*from   w  ww  . j  a  v  a2 s .  c om*/

}

From source file:Main.java

public static void main(String[] args) throws Exception {

    Console cnsl = System.console();

    if (cnsl != null) {
        String fmt = "%1$4s %2$10s %3$10s%n";

        // format
        cnsl.format(fmt, "Items", "Level", "Price");
        cnsl.format(fmt, "-----", "-----", "-----");
        cnsl.format(fmt, "PHP", "1", "15");
        cnsl.format(fmt, "CSS", "2", "50");
        cnsl.format(fmt, "Java", "3", "30");
        cnsl.format(fmt, "HTML", "4", "80");
    }/*from  ww  w.  j a va 2s.  c o  m*/

}

From source file:Main.java

public static void main(String[] args) throws Exception {

    Console cnsl = System.console();

    // test for console not null
    if (cnsl != null) {

        // read line from the console
        String name = cnsl.readLine("Enter  name  : ");

        // print/*from  w w w . j a  v  a  2  s .c o m*/
        System.out.println("You have entered : " + name);
    }

    // flushes console and forces output to be written
    cnsl.flush();

}