1. Technology



Girl working with the notebook in green office
Photography by Bobi/Moment/Getty Images

A constant is a variable whose value cannot change once it has been assigned.

In Java, the final keyword can be used with primitive data types and immutable objects (e.g., String) to create constants.

However, using the final keyword with a variable that references a normal object does not guarantee the contents of that object will stay the same. It only guarantees that the variable will always hold a reference to the same object. See, Final Keyword and Objects for more information.


Add the final keyword to declare an int variable as a constant:

final int DAYS_IN_JANUARY = 31;


# A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  1. About.com
  2. Technology
  3. Java
  4. Java Glossary
  5. C
  6. Definition for the Java Term: Constant

©2014 About.com. All rights reserved.