Since Java 1.2, JPasswordField.getText() has been deprecated “for security reasons”, ecouraging usage of getPassword() method “for stronger securty”.
However, I was able to get the password stored in JPasswordField at least in Oracle JRE 1.7 by analysing the heap dump (JPasswordField instance -> model -> s -> array).
So how does JPasswordField.getPassword() helps to protect the password?
Well, the documentation for it states:
But, of course, if you use the
getTextmethod, you get back a String, which is immutable, so you couldn’t carry out the same recommendation.