Data Types In JAVA | Core Java Tutorial | Minigranth
Data Types In Java : Introduction
Data types in java are the set of values from which an expression can take a value. They represent what type of value any variable can hold or a method can return andare used as per the category of attribute present.
Similarly, these data types are categorized into multiple categories based on their usage. We will be covering the two data types in java which will be sufficient to cover almost any type of expression and variable present.
Data Types In Java : The Discussion
There exists two types of data types in java that are Primitive Data types and Non Primitive data types which are also known as object type data type too. Let's discuss them collectively in tabular form in order to explain you better.
Primitive data types
Primitive Data Types : Java
Default Values : Primitive Data Type
Non-Primitive Data Types/Object Type
Non-Primitive data types which are created by the user. They are also called reference types.
These types refers to an object. The type of reference variable is non-primitive.
For example : String is a non-primitive data type. Other examples are enum, class, array etc.
Note : We’ll be using all these data type throughout this Java Tutorial, so you will get the concept of data types and how they are used.
Variable In Java : Introduction
Variables are like containers which hold some data that is needed in the program. It is an identifier to a memory location.
For example : int a=50;
Here ‘a’ is the variable name, int is the data type and 50 is the value stored in variable named ‘a’.
There are three types of variable in Java which are:
Global Variable : They can be accessed anywhere in the program.
Local Variable : They can be accessed inside a block or a method.
Static Variable : They can be accessed inside a static method ,these variables retain their value if changed.