That is perfectly acceptable, probably even the standard.
(public/private) static final TYPE NAME = VALUE;
where TYPE
is the type, NAME
is the name in all caps with underscores for spaces, and VALUE
is the constant value;
I highly recommend NOT putting your constants in their own classes or interfaces.
As a side note: Variables that are declared final and are mutable can still be changed; however, the variable can never point at a different object.
For example:
public static final Point ORIGIN = new Point(0,0); public static void main(String[] args){ ORIGIN.x = 3; }
That is legal and ORIGIN
would then be a point at (3, 0).
Related Posts:
- Why is there no Constant feature in Java?
- What is a class constant?
- How do I “decompile” Java class files? [closed]
- How do I compare strings in Java?
- Could not reserve enough space for object heap
- What does “Could not find or load main class” mean?
- Editor does not contain a main type in Eclipse [duplicate]
- com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
- JavaFX – Exception in Application start method? [duplicate]
- How is “mvn clean install” different from “mvn install”?
- JRE Missing when installing eclipse
- What does “?” mean in Java? [duplicate]
- Global variables in Java
- Does the Project Lombok @Data annotation create a constructor of any kind?
- Javac is not found
- Please initialize the log4j system properly. While running web service
- ‘mvn’ is not recognized as an internal or external command, operable program or batch file
- Server Tomcat v9.0 Server at localhost failed to start
- How can I convert a .jar to an .exe?
- Error: NoClassDefFoundError: org/apache/commons/logging/LogFactory
- What does .class mean in Java?
- What does the following Oracle error mean: invalid column index
- how to fix java.lang.arrayindexoutofboundsexception: 0?
- Convert the string into stringBuilder in java
- “NoClassDefFoundError: Could not initialize class” error
- Print ArrayList
- Unrecognized SSL message, plaintext connection? Exception
- What is difference between CrudRepository and JpaRepository interfaces in Spring Data JPA?
- How to create an empty array?
- How to decompile a whole Jar file?
- How to fix org.hibernate.LazyInitializationException – could not initialize proxy – no Session
- Find how many connected groups of nodes in a given adjacency matrix
- Java dynamic array sizes?
- Java – Best way to print 2D array?
- “cannot find symbol: method” but the method is declared
- No enclosing instance of type is accessible.
- How to remove single character from a String
- How do I set the proxy to be used by the JVM
- Where to get the tools.jar to use with the Java 8 jdk early release
- int cannot be converted to string?
- What are the possible values of the Hibernate hbm2ddl.auto configuration and what do they do
- How to fix the Hibernate “object references an unsaved transient instance – save the transient instance before flushing” error
- InvocationTargetException when running a javafx program
- PersistentObjectException: detached entity passed to persist thrown by JPA and Hibernate
- How do I use the JAVA_OPTS environment variable?
- What is the difference between iterator and iterable and how to use them?
- Netbeans installation doesn’t find JDK
- keytool error Keystore was tampered with, or password was incorrect
- Difference between a HashMap and a dictionary ADT
- Converting A String To Hexadecimal In Java
- javax.xml.bind.UnmarshalException: unexpected element (uri:””, local:”Group”)
- Enqueue, Dequeue and ViewQueue in Java
- org.xml.sax.SAXParseException: Content is not allowed in prolog
- Running Command Line in Java
- Working Soap client example
- Java GUI: about getContentPane( ) method and content
- How are “mvn clean package” and “mvn clean install” different?
- Why are two empty ArrayLists with different generic types equal?
- java.lang.VerifyError: Inconsistent stackmap frames at branch target 421
- How to convert an Instant to a date format?
- equivalent to push() or pop() for arrays?
- JaxbRepresentation gives error “doesnt contain ObjectFactory.class or jaxb.index”
- How do I fix a NoSuchMethodError?
- What is the Java equivalent for LINQ?
- “Expression expected” and “Cannot find symbol” error
- Android Studio ERROR: Cannot resolve symbol ‘View’
- Static Initialization Blocks
- “Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar” when starting the Scala interpreter
- Swing/Java: How to use the getText and setText string properly
- Multiple delimiters in Scanner class of Java
- Eclipse Problems View not showing Errors anymore
- unexpected type error
- What does it mean: The serializable class does not declare a static final serialVersionUID field? [duplicate]
- “Cannot be resolved to a type” when attempting to use Scanner
- Converting a 2-3-4 tree into a red black tree
- Generic stack implementation
- Java generating non-repeating random numbers
- java eclipse red exclamation mark
- Java FileOutputStream Create File if not exists
- Configure active profile in SpringBoot via Maven
- Is there any way to program Java on Visual Studio 2015
- Keylistener not working for JPanel
- the getSource() and getActionCommand()
- Failed to install android-sdk: “java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema”
- Maven build Compilation error : Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Maven
- Regex pattern including all special characters
- Error: ‘)’ expected compiler error
- How to specify filepath in java?
- Issue installing Netbeans in Windows 10: Java SE Development Kit (JDK) was not found on this computer
- dequeue and enqueue methods in queue implementation
- How to specify the default error page in web.xml?
- Exception is never thrown in body of corresponding try statement
- Could not transfer artifact org.apache.maven.plugins:maven-surefire-plugin:pom:2.7.1 from/to central (http://repo1.maven.org/maven2)
- Using while loop as input validation [duplicate]
- java -version and javac -version showing different versions
- when spring boot startup,throw out the “method names must be tokens” exception
- How to get javax.comm API?
- how to convert exe file to .jar file? [duplicate]
- How to print a table of information in Java
- set background color: Android