DEV Community

Nanthini Ammu
Nanthini Ammu

Posted on • Edited 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. Starting variable names with lowercase is a convention, not a rule. Java compiler does not care about uppercase/lowercase style. Using uppercase is valid but not recommended.
  6. It is Case-sensitive.
  7. 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 (4)

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?

Collapse
 
nanthini_ammu_ac02ad32802 profile image
Nanthini Ammu

Starting variable names with lowercase is a convention, not a rule. Java compiler does not care about uppercase/lowercase style. Using uppercase is valid but not recommended.

Collapse
 
kelwin_kishore profile image
Kelwin Kishore

looks like you forgot to add that in the above post

Thread Thread
 
nanthini_ammu_ac02ad32802 profile image
Nanthini Ammu

Will include, thanks