Search code examples
performancestaticconstantspublicfinal

Big Constant File Performance issue


In a performance critical application which strategy is better?

Having a single big constants (.java) file (public static final variables) or multiple files with lesser number of variables.


Solution

  • Makes no difference once it is compiled.

    If those constants are primitives, they are inlined at compile time. The class that defined them is not even needed at runtime.

    If they are objects, they are loaded once the class file that defines gets accessed the first time. That will only happen once during the life of your JVM.