Prabhat Ranjan wrote:
we can also do the same in class, so which one is the best.
Best is relative and subjective.
Usually I go by the way how the java source code is written.
If you look at say SwingConstants, you will notice it is an interface.
In my opinion, using an interface just to keep constants is an abomination. Yes, Sun did it in the class libraries, but they also made some other questionable choices, so that shouldn't count for much.
But Java 5 gave us "static import" of a class, which accomplishes much the same, and is IMO a much cleaner way than to implement an interface.
It's not an either or question. It depends on what the class or interface stands for.
Constants can belong to a certain interface as much as other constants belong to a certain class. Think of the place where these constants belong, and define them there.
Like Lester said, don't make an interface (or class!) specifically for the purpose of holding constants. Constants without context are meaningless.