java online - Data types & it's types in java Programming language

Programming languages or concepts

Data types in java and it's types Programming language:

   data type specify size and type of value that can be stored in an identifier.

   Java language has rich implementation of data types.

Data types are divided into two types.
  1. Primitive data types
  1. Non primitive data types

Primitive data types in java

    Primitive data types are predefined and available within the Java language.

Primitivedata types are already hard coded into the compiler to be recognised when the program is executed.  

 Non-primitive data types in java:

     These data types are special types of data which are user defined.


1) primitive data types:-

          Java primitive data types are the ones which are predefined by the programmer programming language which is this case in Java without primitive data types retooled be impossible to Prem programs.Primitive data types are also the building block of non primitive data types. 

 There are 8 types of Java primitive data types   
  1. int
  2. float
  3. char
  4. Boolean
  5. Byte
  6. Short
  7. Lang
  8. Double


1) integer data types in java:-

    int is used for storing integer value.

  Int size 4 bytes & has a default value of 0.

  The minimum value of integer is -2^31 and the minimum value is 2^ 31 .

  It can be used to store integer values unless there is a need for storing numbers larger or smaller than the limits.

Ex. 

              int a= 99;


2) Float Data types in java:

      Float is used for storing decimal values.

It's default value is 0.0f & has a size of 4 bytes.

It has an infinite value range.

 It has single precision bit.

It's always advised to use float in place of double if there is a memory constraint.

Ex. 

              float a= 99.99f ;


3) character data type in Java:-

    Char as the name suggests it useful for storing single value characters. 

it's defaultvalue is '\u,0000'  VIT d maximum value being '\uffff' 

 It has 4 size of 2 bytes.

Ex. 

            Char ch = 'S' ;


4) Boolean data type in Java:-

   Boolean is a special data types which can have   only two values true & false.

  It has a different value of false and size of 1 bytes.

  It comes in used for storing flag values.

Ex. 

          boolean flag= true;


5) Bytes Data types in java:-

     It's an 8 bit signed two's complements 

 The range of values are -128 to 127. 

 It is space efficient because a replacement for int data type usage but it doesn't have size rang as the int data types.

Ex .

           byte a = 99;


6) Short Data types in java:-

     This data type please also similar to the integer data type.

It's 2 time smaller than integer data type.

Its minimum range is-32768 to maximum range is 32,767.

Ex. 

            Short a=10;

7) Lang data types in java:-

   This data type primary stored huge sized numeric data.

  It is a 64 bit integer .

It's rang from -2^63 to +(2^64)-1.

It has a size of 8 bytes.

It is helpful when you need to store data which is longer than integer data types.

Ex .

           lang a= 12882123;


8) Double data types in java:-

    This is similar to the float data type. 

It has one advantage over float data type.

It has two bit precision over the float data type which has one bit precision.

It still shouldn't be used for precision sensitive data such as currency.

It has a range of-2^31 to (-2^31)-1.

Ex.

         double a= 99.99d;



Data TypeDefault ValueDefault size
byte01 byte
short02 bytes
int04 bytes
long0L8 bytes
float0.0f4 bytes
double0.0d8 bytes
booleanfalse1 bit
char'\u0000'2 bytes



Simple program for data types in java

Import java.io.IOException

Class demoDataTypes

{

  public static void main(String[] args) throws IOException {

    int a = 99;

    short s = 9;

    byte b = 8;

    long l = 8208686622l;

    float f = 99.99f;

    double d = 999.9999d;

    System.out.println("The integer variable is " + a);

    System.out.println("The short variable is " + s);

    System.out.println("The byte variable is " + b);

    System.out.println("The long variable is " + l);

    System.out.println("The float variable is " + f);

    System.out.println("The double variable is " + d);


  }

}

  

   2) Non- primitive data types in java:-

Non primitive data type are created by programmers.

they are not predefined in Java like primitive data type these data types are used to store a group of values and serveral values.

The size in memory of a primitive data type is already defined but the size of non primitive depends on the programmers.

Non primitive data types can have customised methods on them.

There are four main types of non primitive data types.

  1. String
  2. Class
  3. Array
  4. Interface

1) String:-

     String are a group of character surrounding by double quotes.

   String are mostly used to store chunks of text and information.

Syntax:

String<String_variable_name>="<sequence_of_Strings>";

Ex.

           String name="Saurabh";

2) Array:-

      Array  are a way of storing information in a list format.

here is her very helpful when we store data that will not have a lot of added elements for listed that require more manipulation there are linked lists.

String [ ] arr = { name, "Hello", "23"};

Creating an array involves two steps which are;

1) Array Declaration.

2) Array Initialisation.

Array Declaration:-

        We declare an array variable of the desired data type.

Syntax:

   data_type array_name[ ] ;

   datae_type[ ] array_name;

Ex. 

       int Str [ ];


Array Initialisation:-

    We allocate the memory to the array with the help of a new operator and assign the memory to the array variable.

Syntax:

 array_name = new data_type[ size of array] ;

array_name = new data-type { elements of array using commas};

3) java classes:-

    We create a class using class keyboard.

    A class is a collection of object of the same type it is a user-defined blueprint orprototype which define the behaviour and state of object class and object are the basic element of object oriented programming that represent the real world entities.

Class consists of set top properties variables or methods / operations to define the the behaviour of an object.

A class can be declared using the following components in the order:-

  1. Access modifiers
  2. Class name
  3. Body
Syntax:-

    Access modifiers class class_name

     {

        Class body& variables & methods ();

      }


Ex. 

Public class MyClass{

              int a=10;

               Void display ()

                {

                          //Methods body

                 }

}


4) java interface:-

And interface is another reference type in Java.

It is a similar to a class

And interface behaves like a blueprint of a class, which specifies what a class has to do and not how it will do.

it can also have methods and variables but the methods are declared implicity as a public and abstract in interfaces.

Syntax:-

     interface interface_name

use and interface in a class we have to append the keyword implements after the class name followed by the interface name

Class class_name implements interface_name

Ex. 

Interface student1

{

      Class MyClass implements student1

       {

              // Class Body

        }

 }


close