0

Before releasing a Java application, do the access modifiers on classes need to be changed or is there something else in place to prevent someone from just importing the final JAR into one of their projects and using the classes?

The only thing I can think of would be to make any public classes final, but it still leaves them exposed.

  • Once you release code to third parties, third parties have access to it. Access modifiers are there to deter mistakes, not prevent malfeasance. You can obfuscate your code, to make it more difficult to understand. – Andy Thomas Jul 27 '15 at 02:37
  • This might help http://stackoverflow.com/questions/1879061/how-to-protect-java-codes-against-decompiler – Smiles Jul 27 '15 at 02:46
  • What do you want to achieve ? Avoid user making mistakes while using your library or prevent user accessing (viewing) your source code ? – Spotted Jul 29 '15 at 06:33
  • Part of it is preventing users from accessing vital parts of the system and potentially breaking it, but my current project has parts in different packages so they have to be exposed to access each other. The other part is just wanting to release clean code and only expose what is needed. I don't need to worry about this with my current project, but I like practicing good habits/new skills before I actually need them. – WhereBunny Aug 02 '15 at 05:06

1 Answers1

0

It depends on what you are releasing. If it is a web app, then you don't (assuming everything works when you are running the application locally); however if it is a library (like external JAR API), then you need to make sure that methods that you want users to use are accessible.

Sarp Kaya
  • 3,446
  • 20
  • 59
  • 95