Data
Basic skills
Constants
How to initialize a constant
Syntaxfinal type CONSTANT_NAME = value;Examples
final int DAYS_IN_NOVEMBER = 30; final double SALES_TAX = .075;
Variables and constants
- A variable stores a value that can change as a program executes, while a constant stores a value that can't be changed.
- To initialize a variable or constant, you declare its data type and assign an initial value.
- To initialize more than one variable for a single data type in a single statement, use commas to separate the assignments.
- To identify float values, you must type an f or F after the number. To identify long values, you must type an l or L after the number.
Naming conventions
- Start variable names with a lowercase letter and capitalize the first letter in all words after the first word.
- Capitalize all of the letters in constants and separate words with underscores.