DEV Community

Nanthini Ammu
Nanthini Ammu

Posted on

Java Variable

  1. Java Variable is a container that stores data in memory. Every varaiable has a name, data type and a value.
  2. It is stored in Stack memory.
  3. Variable name should start with small letter.
  4. variable name can start with these special characters $ and _
  5. It is Case-sensitive.
  6. The type of data that can be stored in a variable is defined by data type.

Ex :
int number = 10;
int -> data type
number -> variable name
= -> assignment operator
10 -> value
; -> end of statement

// Declaration and Assignment in different line:
int speed; // Declaration
speed = 50; // Assignment of a value

//Declared and initialized in one line:
int speed = 50;
String name = "Java";

Top comments (1)

Collapse
 
kelwin_kishore profile image
Kelwin Kishore

Variable names should start with a lowercase letter — is this mandatory?, what happens when we use capital letter, is it valid?