Data Types In Java with Example - Passionate Geekz

Breaking

Where you can unleash your inner geek.

Saturday, 18 January 2020

Data Types In Java with Example

In java programming, there are two data types

  • Primitive data type
  • Non-primitive type

Primitive Data Types

Primitive data type are those which can store only one value and never allow us to store multiple value of same data type.

(boolean, char, byte, short, int, long, float and double)

Non-Primitive Types

Non Primitive Types are those which can store multiple value and allow us to store multiple value of different  type.

(Classes, Interfaces, and Arrays)

==============================

Example for Primitive Data Types

1) Integer Data Type

int a= 5 ;

System.Out.Println(a);

2) Float Data Type

Float a=5;

System.Out.Println(a);

3) Character data type

char = “A”

System.Out.println(a);

=============================

Examples for Non-Primitive Types

1) Classes

class MyClass { public static void main(String[] args) { Int a = 5; System.out.println(a); }

2) Array

class ArrayExample {   public static void main(String[] args) {      int[] age = {12, 4, 5, 2, 5};}

3) Interfaces

interface {//methods}

No comments:

Post a Comment