Java Variables

In this lesson, we will learn how to work with Java Variables. Variable in Java is a reserved area allocated in memory. It is a container that holds value. Each variable is assigned a type, which is known as data type.

The reserved area set for the variable stRank is shown below. Here, the variable is assigned a value 5. Also, you can see, we need a datatype to declare a variable. The int data type is used below.

Java Variables

Declare Variables in Java

As in the above figure, variables are declared by adding a data type, with the variable name.

Here are some examples:

Initialize Variables in Java

To initialize a variable, assign a value to it. Here are some examples:

Here’s the usage of variables in a Java program:

For example,

The value of the integer variable above is assigned 90.

Java Bitwise Operators
break continue statements in Java
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading