Best practice for Constant Class in Java I create a constant class by looking at some of the best practices described here in stackoverflow. Many of those have a single Constant class with variables. Some of the answers suggested creating separate Contant Classes. The way I create a constant class is by naming it Parameters and creating classes i.e. Variables and Constants. Then these classes further have child classes e.g. URL, Columns etc. This time I created a constant class with same structure and a separate class named ReportTemplate. This is my first time creating a Constant class of Objects that don't have a primitive datatype.

public final class ReportTemplate {

    public final static class ColumnIds {
        public static final String TITLE_COLUMN_ID = "title";
        public static final String TYPE_COLUMN_ID = "type";
        public static final String LIFECYCLESTATUS_COLUMN_ID = "lifecyclestatus";
        public static final String INSERTIONTIMESTAMP_COLUMN_ID = "insertionTimestamp";
    }

    public final static class Columns {
        public static final TextColumnBuilder&lt;String&gt; TITLE = col.column(
                "Title", ColumnIds.TITLE, type.stringType());

        public static final TextColumnBuilder&lt;String&gt; LIFECYCLESTATUS = col.column(
                "Lifecycle Status", ColumnIds.LIFECYCLESTATUS,
                type.stringType());

        public static final TextColumnBuilder&lt;String&gt; TYPE = col.column("Type",
                ColumnIds.TYPE, type.stringType());

        public static final TextColumnBuilder&lt;String&gt; INSERTIONTIMESTAMP = col
                .column("Insertion Timestamp",
                        ColumnIds.INSERTIONTIMESTAMP,
                        type.stringType());
    }

    public final static class Styles {
        public static final StyleBuilder HEADING1 = stl.style()
                .setName("heading1").bold().setFontSize(15);

        public static final StyleBuilder HEADING2 = stl.style().setName("heading2")
                .bold().setFontSize(12);

        public static final StyleBuilder HEADING3 = stl.style().setName("heading3")
                .bold().setFontSize(10);
    }

}


I want to know if my


Naming Scheme is correct
Constant class structure is among best practices.
Should I create separate constant classes or having them encapsulated in a parent Constant class is fine?


Edit: April 19, 2016

I have accpeted an answer but i would like more suggestions anytime.

Thank you.
Answer to your questions :

Naming Scheme is correct? - 

Ideally you should not create class with names like Variables, Parameters, etc. as these names also has literal meanings with them in many languages. Besides that, these classes are going to store Constants! You can simply create single class with name Constants! No need to create different Constant classes till it's absolutely necessary. Perhaps, in that case you should go for enums. Why? Check these links :


Link 1.
Link 2


Constant class structure is among best practices ?

This is answered in above point. Keep your naming convention readable enough so that you won't require separate constant classes.
Always try to implement KISS(Keep it Simple Stupid) and DRY(Don't repeat yourself!)

Should I create separate constant classes or having them encapsulated in a parent Constant class is fine?

Ideally not. If you need such requirement then go for enums. As enums are typesafe, you wont end up creating misleading statements. For ex.
If you write following potentially incorrect code then Constant class won't mind:

String playerType = Constants.MALE;


But, if you use enums, that would end up as:

// Compile-time error - incompatible types!
PlayerType playerType = Gender.MALE;