Data Types In Java

Core Java Tutorial

[fblike]

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 and are 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.

 

1) Primitive data types

 

This image describes the primitive data types in java that can be used.

Primitive Data Types : Java

 

Default Values : Primitive Data Types

 

This image describes the default values of primitive data type in java.

Default Values : Primitive Data Type

 

2) 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 exampleString is a non-primitive data type. Other examples are enum, class, array etc.

Note : We’ll be using all these data type throughout our Java Tutorial, so you will get the use 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:

1) Global Variable : They can be accessed anywhere in the program.

2) Local Variable : They can be accessed inside a block or a method.

3) Static Variable : They can be accessed inside a static method ,these variables retain their value if changed.