Datatype and variables in Java
In this tutorial, we will discuss Datatype and variables in Java programming language
Data type and variables in Java, is an important concept in Java. Data types represent the different values to be stored in the variable and there are two types of data types In Java.
Datatype and variables in Java
Two type of data type exist in Java
The data type is a keyword or reserved word in Java used to allocate memory to variables. It is pre-defined as part of the programming languages.
Datatype and variables in Java programming language
There are two types of data in Java:
There are eight primitive data types available in Java.
The primitive data type is already predefined and has been allocated with a keyword(known as the reserved word). Let’s look into the eight primitive data types in detail.
The byte data type is an 8-bit signed two’s complement integer
The short data type is a 16 bit signed two’s complement integer.
Int data type is a 32-bit signed two’s complement integer.
The long data type is a 64-bit signed two’s complement integer.
Float data type is a single-precision 32-bit IEEE 754 floating point.
the double data type is a double-precision 64-bit IEEE 754 floating point.
Boolean data type represents one bit of information.
the char data type is a single 16-bit Unicode character.
Reference data are also known as Object data type is created using defined constructors of the classes. They are used to access objects. These variables are declared to be of a specific type that cannot be changed. For example, Students, Sun etc.
Data type and the default value
Variable is using to allocated memory for assigned value. It provides a name and allocates space in memory
How to declare a variable
How to allocate memory using variable
Syntax
Data_type variable_name=value;
Example
int marks=67;
Local variable
The local variable is a type of variable which is declared inside the method as the local variable.
Global or instance variable
The instance variable is a type of variable which is declared inside the class but outside the methods or constructor.
It doesn’t declare as static.
static variable
A variable that is declared as static is known as the static variable.
Static variable is not a local variable.
Boolean
Boolean is a data type in Java which represents only one bit of information, it is either true or false.
Output
true
false
The byte data type is an 8-bit signed two’s complement integer.
Output
a value is 34
b value is 126
The short data type is a 16-bit signed two’s complement integer looks like to byte.
Output
a value is 342
b value is 1263
It is a 32-bit signed two’s complement integer.
Output
a value is 1000
b value is 4567
The long data type is a 64-bit two’s complement integer.
Output
a value is 34265
b value is 1263345
The float data type is a single-precision 32-bit IEEE 754 floating point.
Output
a value is 34.35
b value is 12.5
The double data type is a double-precision 64-bit IEEE 754 floating point.
Output
a value is 343.35
b value is 142.556
The char data type is a single 16-bit Unicode character. A char is a single character.
Output
a is Z
b is Y
Suggested for you
Data type and variable in Java
Feature of Java programming language
Flavour and versions of Java Programming language
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…