Java Variables

Java Variables

  • Variables are containers to hold values.
  • Every variable has name and type, or we can say that a variable is a combination of identifier and datatype.
  • Every variable is an identifier, but every identifier is not a variable.

Properties to define a valid variable

  • The should not contain any space
  • They should not start with digit.
  • Only dollar symbol ($), and underscore symbol( _ ) is allowed to use in the java variable.
  • Java is a case-sensitive language hence a variable named “a” and “A” have different meanings.


In java there are different types of variables mentioned as follows-

  1. int  - 4 byte
  2. Float - 4 byte
  3. Char - 2 byte
  4. Boolean - 1 bit
  5. String (string is not a data type in java it is a class).