Please enable JavaScript to use CodeHS

CodeHS Glossary

Constant Java

A constant is a variable you define at the top of the program that doesn’t change. The reason to define constants is to store named variables that have relevant values for the program. You define constants at the top of the program using ALL_CAPS_WITH_UNDERSCORES, unlike normal variables, which use lowerCamelCase One of the main reasons you use constants is to avoid using magic numbers in your code. This is an example of a constant: ``` private static final int CARDS_IN_DECK = 52; ``` Now we can use the meaningful name `CARDS_IN_DECK` throughout our program rather than the magic number 52.