In this tutorial, we will learn to declare Java variables in Eclipse IDE. Two important points to remember is that:
- Java is statically-typed language.
- Java is case sensitive.
What is statically-typed Language?
Statically typed language expects the variables to be declared before using them. In Java we need to declare the variables before using them in the Java programs. Any undeclared variables would result in compilation error
<Undeclared_Variable> cannot be resolved to a variable
The syntax for declaring a variable is:
dataType variable_name; //declaring variable
In the preceding syntax, dataType specifies a Jave type, such as int, char, double, etc. Variable can have any name that follows some specified naming conventions.
Declare Java Variables
For example to declare String variable we can use the following line of code.
Declare an integer variable i.
Declare a double variable called price.
We need to initialize the variable and assign a value. The most common way is to initialize the variable along with the declaration statement.
String name=”Learn java”;
We get this error when we try to run the program without initializing the variable.
The local variable name may not have been initialized
Java is case sensitive language. So, String and string are not equal. We get error if we try to declare
string name=”Learn Java”;
Java Tutorial on this website:
For more information on Java, visit the official website :