Java TutorialLesson 7Free preview
Java Variables
This lesson is part of Java · All levels
Summary
A variable is a naming container for storing data in a Java program. You learn how to declare variables by writing down the data type followed by the name and the initial value, and the valid naming rules like you shouldn't prefix numbers or keywords. Java also recognizes the var type that facilitates short declarations.
Key points
- The declaration of variables is written in the type formatData name = value;
- The name of the variable may contain letters, numbers, $, and _, but it must not be preceded by numbers
- Variables must be declared and given a value before use, or program error
- Keywords like int, class, and static should not be used as variable names.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.