Java variable declaration and assignment

By | July 12, 2020

Java variable declaration and assignment:

In any Java program, variable is the basic unit of storing data. A variable can be declared by using an identifier i.e the variable name and a data type. We can also initialize a variable when it is declared.

In Java, before using any variable, it should be declared. At the same time, In Java, if a local variable is used without initializing it, compiler will throw an error. However, other variables such as member variable are assigned with the default values automatically.

Declaration and assignment of java variables:

We can declare variables anywhere in the program.

Points to be noted:

1. Variables must have a type.

int rank;

String name;

2. Variables must have a name.

3. Assigning a value to the variable.

rank =1;

name = “selenium”;

4. We can declare and assign a variable in single step.

int rank = 1;

 

Recommended Posts:

How to remove last element from an ArrayList

Remove element from ArrayList

How to swap two numbers without using third variable in Java ***

How to capitalize each word in Java

Java interview questions

Generate random between 1 to 10 in Java

 

Note: If you like selenium99.com and want to contribute any articles, then please send your articles to techygeeks99@gmail.com. 

If you want to improve this article or find any mistake in the article, then please use comment box to share your feedback.

Links: TestNG

Tags: Java variable declaration and assignment

Leave a Reply

Your email address will not be published. Required fields are marked *