Obfuscation by itself might not. The goal of obfuscation is to try and hide what is present. This can be done at a code level (there used to be code contests (there still might) where the goal was to write source code that was almost impossible for a human to read and understand, but would still be compilable and produce useful (?) output). Or it can be done on the code that has been compiled.
This is almost exactly the opposite of what we strive for when we write
Java code. We try to give our packages reasonable names, and the classes within those packages reasonable names, and the methods and variables within those classes reasonable names. If you obfuscate all that, you may end up with two results - it may be harder for someone to work out what your original intention was, and you may end up with physically smaller files.
For example, consider a stack trace like:
Compared with:
(and yes, I have seen stack traces from code that has been obfuscated that looked like that)
For Java to be able to provide you with meaningful stack traces, it must keep track of all the package, class, method and variable names. As you can see, there were about 75 bytes saved by changing to meaningless names. And given that there are probably far more packages, classes, and variables, there are probably far greater savings involved.
Just that saving alone will reduce the size of your jar files.
As Ulf mentions, obfuscating the code will not tune the application, however it
may load faster given that the resultant file sizes may be smaller. There are so many variables involved here though, that this is by no means guaranteed.
Note that using the -g:none option of javac will remove some of the debugging information, but this will reduce it even further. Also, it is still fairly easy to use a decompiler to reverse engineer a class compiled with the -g:none option - it is far more difficult to do it with multiple classes that have been obfuscated.
If you do look at obfuscators, then I strongly recommend you look at one that can give you some meaningful way of handling errors when they occur. For example, you might want one that can translate the meaningless a.a.a.a.A.a() back into com.javaranch.database.table.RowHandler.add()
Regards, Andrew
[ March 03, 2007: Message edited by: Andrew Monkhouse ]