Can you explain in more detail what you want to do? Do you want to store passwords in a database or file or somewhere else in encrypted form?
One technique that is used very frequently (for example, it is how most versions of Unix store passwords of user accounts in the file /etc/passwd) is the following:
Instead of storing the password itself, you store a "digest" of the password. There are several different algorithms to create the digest, for example SHA and MD5. Those digest algorithms are one-way algorithms: you can encrypt data with them, but it is not possible to decrypt it (you can't get the original data back out of the digest).
When someone logs on to your system, the user types in his or her password. Your program now computes the digest of the password that the user typed in, and compares that digest to the digest in the database. If the two are the same, then the correct password was typed in.
So you see, the trick here is that if you know the digest, you don't know the password, because the algorithm only works one way.
Java has methods to compute digests over data: see the class java.security.MessageDigest.