Java Variables

Just like we have some rules that we follow to speak English (the grammar), we have some rules to follow while writing a Java program. This set of these rules is called syntax. It’s like Vocabulary and Grammar of Java.

Variables

  • A variable is a container that stores a value.
  • This value can be changed during the execution of the program.
  • Example: int number = 8; (Here, int is a data type, the number is the variable name, and 8 is the value it contains/stores).
Rules for declaring a variable name

We can choose a name while declaring a Java variable if the following rules are followed:

  • Must not begin with a digit. (E.g., 1deep is an invalid variable)
  • Name is case sensitive. (Sandeep and sandeep are different)
  • Should not be a keyword (like Void).
  • White space is not allowed. (int Code With Sandeep is invalid)
  • Can contain alphabets, $character, _character, and digits if the other conditions are met.

Was this article helpful?
YesNo

Leave a Comment

Your email address will not be published. Required fields are marked *