Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-uppercase constants in Java

This question about why constants in Java are uppercase by convention made me try to think of counter examples.

I can think of at least one (Double.NaN). Are there others?

like image 854
JRL Avatar asked Feb 19 '10 11:02

JRL


3 Answers

Of course, public final static PrintStream out (in java.lang.System.out). But it's a very good exception, because System.OUT.println is just ugly.

Also, most of the time loggers are initialized as follows:

private static final Logger logger = Logger.getLogger(MyClass.class);

However, in both cases these are not constants in the true sense of the term. So perhaps we can make a distinction:

Fields that are static because they need a static access, and final because they should not be re-assigned at runtime, are not necessarily constants.

like image 83
Bozho Avatar answered Sep 27 '22 20:09

Bozho


There are lots of serialVersionUID!

Others in ResultSetMetaData like columnNoNulls, columnNullable...
DatabaseMetaData and ICC_Profile have lots of mixed case constants.

Here is a list with most, if not all, JavaSE constants: Constant Field Values

like image 20
user85421 Avatar answered Sep 27 '22 21:09

user85421


Color constants like black, red, green etc from java.awt.Color class.

It should be noted that java.awt.Color also provides the uppercase alternatives (e.g. BLACK, RED, GREEN etc) of these constants.

like image 33
missingfaktor Avatar answered Sep 27 '22 22:09

missingfaktor