Hello Friends!!!
Today we are going to learn the example of datatypes. Please refer to Datatypes to get all the details of Java Datatypes.
Let's start with What is variable?
Variable (scalar) is a named memory location (Name given by a programmer or developer to identify that memory location for their purpose is also known as Identifier) we can store a value to a variable it is temporary storage for a value.
In Java, we can define a variable with its type. Here is how to declare a variable?
<data_type> <var1>,<var2>,<var3>;
For Example,
int employee_id, length;
Even we can assign a value to the variable such as,
<data_type> <var1>=<val1>,<var2>=<val2>;
For Example,
int employee_id=123,length=5;
Now let's take a demo class to define a variable with different data types.
Today we are going to learn the example of datatypes. Please refer to Datatypes to get all the details of Java Datatypes.
Let's start with What is variable?
Variable (scalar) is a named memory location (Name given by a programmer or developer to identify that memory location for their purpose is also known as Identifier) we can store a value to a variable it is temporary storage for a value.
In Java, we can define a variable with its type. Here is how to declare a variable?
<data_type> <var1>,<var2>,<var3>;
For Example,
int employee_id, length;
Even we can assign a value to the variable such as,
<data_type> <var1>=<val1>,<var2>=<val2>;
For Example,
int employee_id=123,length=5;
Now let's take a demo class to define a variable with different data types.
Here is the output of the above example,
Fig. The output of the above example |
Here, in long and float data type we need to add L or l or F or f after values so that values can be considered as long or float otherwise it is considered as integer or double value.
In float datatype, if we don't write f or F, it shows an error.
float f1=45.567; //if we write this line, it generates below error.
Fig. An Error for float data type |
Till then that's it, Happy Coding...☺😊
No comments:
Post a Comment