Your users must be able to run your .jar
file. So you can't prevent them from knowing the code being run while also letting them run your code. You can only apply effort to make life difficult for the most common de-compiling and reverse engineering strategies.
If you must hide your code here are some options:
.jar
files already discourage people from viewing the source. Look in the .jar and you should not see source .java
files (unless you specifically chose to include them). The .class files must be included and they can be de-compiled into a machine readable equivalent of your program, but it won't be easy to read or understand.
Rewrite the program in C and then use an obfuscate program on the source and compile from that. This is about as locked and hidden as you can make it. Anyone who looks at your code will see completely humanly-incomprehensible gibberish that is so hard to modify to be understandable, it becomes much easier to just observe the program behavior and write a new program that imitates it.
Convert your jar file to a .exe for windows: How can I convert my Java program to an .exe file?
Nuclear option:
If you have the sourcecode for the alien space ship/Iron man suit, and you must hide this code at any cost then you will need to remove the rights and liberties of the user using it while using your program. No single user must be allowed to observe or understand your program close enough to get a feel for how it is doing what it is doing. Third parties must be involved to randomize and obfuscate not only the code itself, but also the perception of how the user understands the tasks are being completed. A hired goon or mal-ware can monitor the users use of the program and electrocute the user or self destruct if it detects the hint that they are trying to understand or build upon your code. The sourcecode must become self aware and to delete itself on suspicious behavior.
Microsoft and XBox are using these sorts of strategies by removing the rights and liberties of users by writing hardware and software that bricks itself if you annoy the mothership. Pick up that can citizen. Don't make me taze you.