- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Types of variable in java
Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in the memory.
Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals, or characters in these variables.
There are two data types available in Java -
Primitive Data Types
Reference/Object Data Types
There are eight primitive data types supported by Java. Primitive data types are predefined by the language and named by a keyword.
You must declare all variables before they can be used. Following is the basic form of a variable declaration -
data type variable [ = value][, variable [ = value] ...] ;
the data type is one of Java's data types and a variable is the name of the variable. To declare more than one variable of the specified type, you can use a comma-separated list.
Following are valid examples of variable declaration and initialization in Java -
Example
int a, b, c; // Declares three ints, a, b, and c. int a = 10, b = 10; // Example of initialization byte B = 22; // initializes a byte type variable B. double pi = 3.14159; // declares and assigns a value of PI. char a = 'a'; // the char variable a is initialized with value 'a'
- Related Articles
- Global Special Variable Types in Perl
- Capacitor Types: Fixed & Variable Capacitors
- Types of packages in Java
- Types of Array in Java
- Types of inheritance in Java
- Types of References in Java
- variable naming conventions of java
- Final variable in Java
- Instance variable in Java
- Types of Java comments.
- Types of access modifiers in Java?
- Types of quantifiers in Java regex
- java variable declaration
- Java static variable
- instance variable hiding in Java
