There is a nice article that explains why encryption cannot work:
http://www.javaworld.com/article/2077342/core-java/cracking-java-byte-code-encryption.html?page=1.
As mentioned, obfuscation is a better bet if you really need to do that. Obfuscators vary in quality. Some simply change names, so its a fairly trivial exercise to get sensible java code back. The better ones perform functional-invariant bytecode transformations that produce bytecode that cannot be represented as Java source code. You can still read the bytecode, but getting Java code back is much more difficult.
Ultimately the JVM needs to see the bytecode to run your application, so whatever solution you use will have a flaw in it. If the attacker is motivated enough they can work out what your program does.
The most secure solution would be to find a way not to distribute your source code, such as keeping the sensitive code behind a secure webservice.
Who are you trying to protect the code from?