Since Strings are immutable in Java, any handling of passwords in Java should be via a char[] which can be overwritten with Arrays.fill() as soon it is no longer needed. Even if the String goes out of scope, there is no guarantee if or when it will be garbage collected, and even if it is garbage collected, there is no guarantee that the memory will be overwritten.