DEV Community

Gayathri.R
Gayathri.R

Posted on

what is variable

variables are containers used for storing data values. They are categorized into different types based on the kind of data they hold.
Types of Variables:

String: Stores text, enclosed in double quotes (e.g., "Hello").
int: Stores whole numbers (integers), without decimals (e.g., 123, -123).
float: Stores floating-point numbers (numbers with decimals), requiring an f suffix (e.g., 19.99f, -19.99f).
char: Stores single characters, enclosed in single quotes (e.g., 'a', 'B').
boolean: Stores values with two states: true or false. 
Enter fullscreen mode Exit fullscreen mode

Declaring and Assigning Variables:
To create a variable, you must specify its data type and assign it a value using the following syntax:
Java

type variableName = value;

Examples:
string.
Java

String name = "John";
Enter fullscreen mode Exit fullscreen mode

int.
Java

int myNum = 15;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)