I am learning Java from Java doc and I want to implement the examples, but I am facing some problems. Can anyone describe me this problem, and tell me how can i get values from console using eclipse IDE.
Whenever, I execute this example, the output is No Console.
Code i've built so far:
public class Password {
public static void main(String[] args) throws IOException {
Console c = System.console();
if (c == null) {
System.err.println("No console");
System.exit(1);
}
String login = c.readLine("Entyer your login password");
char[] oldPassword = c.readPassword("Enter your old password");
if (verify(login, oldPassword)) {
boolean noMatch;
do {
char[] newPassword1 = c.readPassword("Enter your new password");
char[] newPassword2 = c.readPassword("Enter new password again");
noMatch = !Arrays.equals(newPassword1, newPassword2);
if (noMatch) {
c.format("Password not mathc. Try again.%n");
} else {
change(login, newPassword1);
c.format("Password for %s change.%n", login);
}
Arrays.fill(newPassword1, ' ');
Arrays.fill(newPassword2, ' ');
} while (noMatch);
}
Arrays.fill(oldPassword, ' ');
}
static void change(String login, char[] password) {
// TODO Auto-generated method stub
}
private static boolean verify(String login, char[] password) {
// TODO Auto-generated method stub
return true;
}
}