This Website for Those Students who are searching for a platform to study online in their own Language Hindi, on this website they will learn all courses like IAS, programming, web designing, data science, and competitive exam preparation, etc.


Java Data Type

JAVA - Java Data type



हेल्लो दोस्तों! आज हम इस पोस्ट में Java Data type के बारें में पढेंगे, तो चलिए शुरू करते हैं.



Data types in Java



तो पहले समझ लेते है की Data types होते क्या है.

Data types ये keywords है यह जब भी आप कोई variable create करते है तो उससे पहले compiler को बताते है की आप किस तरह का data उस variable में store करेंगे। इससे compiler उतनी ही memory उस variable को computer की memory में से allot कर देता है। यदि किसी programming language में data types ना हो तो बहुत अधिक memory waste हो सकती है। जब 2 bytes की आवश्यकता हो तब 20 bytes आप waste कर सकते है। इसलिए जितनी भी तरह का data आप store कर सकते है उसके लिए पहले से ही maximum memory limit define की गई है। Java में variables के अन्दर अलग-अलग types की values store की जाती है



जावा statically-typed लैंग्वेज है जिसका अर्थ है कि इसमें variables का प्रयोग करने से पहले उन्हें declare करना होगा.

Data Type अलग-अलग प्रकार के size और value को specify करते है जिन्हें variable में स्टोर किया जा सकता है.



java में दो प्रकार के data types होते हैं:-

  1. Primitive Data Type
  2. Non-primitive Data Type

Primitive Data Type



java में 8 प्रकार के primitive data types होते हैं,

Primitive Data Type वो होते है जिन्हे Java में By default पहले से Define कर गये है.



जो कि निम्नलिखित हैं:-



Data Type

Default Value

Default size

boolean false 1 bit
char '\u0000' 2 byte
byte 0 1 byte
short 0 2 byte
int 0 4 byte
long 0L 8 byte
float 0.0f 4 byte
double 0.0d 8 byte


1:- Boolean

बूलियन डाटा टाइप की केवल दो possible values होती हैं:- true या false. इसका प्रयोग अकसर true/false condition के लिए किया जाता है. इसकी default वैल्यू false होती है. बूलियन डाटा टाइप को boolean कीवर्ड के द्वारा declare किया जाता है.

Example:-
   
     public class booleanExample{
    
    public static void main(String args[]){
    
    boolean isCold = true;
    boolean isFoodTasty = false;

    System.out.println(isCold);
    System.out.println(isFoodTasty);
       }

     }
   
 


Output:

   
   
   true
   false
   
 


2:- Byte

बाइट डाटा टाइप -128 से 127 तक whole numbers को स्टोर कर सकता है. इसका प्रयोग int के स्थान पर किया जा सकता है. इससे memory की बचत होती है. इसका प्रयोग तभी int के स्थान पर किया जाता है जब हमें पता होता है कि स्टोर की जाने वाली वैल्यू -128 से 127 के बीच मे है.



   
   public class byteExample{
    
    public static void main(String args[]){
    
     byte x =30;
     byte y = -50;

    System.out.println(x);
    System.out.println(y);
       }

     }
   
 


Output:

   
   
    30
   -50
   
 


3:- Short

शोर्ट डाटा टाइप -32768 से 32767 तक whole numbers को स्टोर कर सकता है. इसकी default value 0 होती है. byte data टाइप की तरह ही हम short का प्रयोग memory को save करने के लिए कर सकते है.



Example

:-
   
     public class shortExample{
    
    public static void main(String args[]){
    
    short a = 10000;
    short b = -5000;

    System.out.println(short a);
    System.out.println(short b);
       }

     }
   
 


Output:

   
   
     10000
     -5000
     
   
 


4:- Int

int डाटा टाइप की वैल्यू -2147483648 (-231) से 2147483647 (231-1) तक होती है. इसकी default वैल्यू भी शून्य होती है. int का प्रयोग प्रोग्राम में ज्यादातर किया जाता है.



example

   
     public class intExample{
    
    public static void main(String args[]){
    
     int y = 100000;
     int z = -200000;

    System.out.println(y);
    System.out.println(z);
       }

     }
   
 


Output:

   
   
   100000
   -200000
   
 


5:- Long

इस data type की वैल्यू 9223372036854775808 (-263) से 9223372036854775807 (263-1 ) तक होती है. इसका प्रयोग तब किया जाता है जब int इतनी बड़ी value को स्टोर नही कर पाता है. हमें इसमें ध्यान देना चाहिए कि इसकी value को L से end करना होता है.



example

:-
   
     public class longExample{
    
    public static void main(String args[]){
    
     long myNumber = 15000000000L;

    System.out.println(myNumber);

       }

     }
   
 


Output:

   
   
   15000000000
   
 


6:- Float

यह डाटा टाइप 3.4e−038 से 3.4e+038 तक के fractional number को स्टोर कर सकता है. यहाँ ध्यान देने वाली बात यह है कि इसमें हमें value को f से end करना होता है. इसकी default वैल्यू 0.0f होती है.



Example

:-
   
     public class floatExample{
    
    public static void main(String args[]){
    
    float myNumber = 5.75f;

    System.out.println(myNumber);

       }

     }
   
 


Output:

   
   
   5.75
   
 


7:- Double

डबल डाटा टाइप 1.7e−308 से 1.7e+308 तक के fractional number को स्टोर कर सकता है. इसमें ध्यान देने वाली यह बात है कि इसमें हमें value को d से समाप्त करना होता है. इसकी डिफ़ॉल्ट वैल्यू 0.0d होती है



Example-

   
     public class boubleExample{
    
    public static void main(String args[]){
    
    double myNumber = 19.99d;

    System.out.println(myNumber);

       }

     }
   
 


Output:

   
   
   19.99
   
 


8:- Char

char data type का प्रयोग एक single character को स्टोर करने के लिए किया जाता है. इसमें character को हमेशा single quote के अन्दर होना चाहिए. इसकी निम्नतम निम्नतम वैल्यू ‘\u0000 और अधिकतम वैल्यू ‘\uffff’ होती है.



Example-

   
     public class charExample{
    
    public static void main(String args[]){
    
    char myCharacter = 'A';

    System.out.println(myCharacter);

       }

     }
   
 


Output:

   
   
     A
     
   
 


Non primitive Data type



जावा में non primitive डाटा टाइप को reference types कहा जाता है क्योंकि वे object को refer करते हैं.

Non primitive Data type वो होते है जिन्हे User primitive Data type का use कर के बनाये जाते है.

ये निम्नलिखित प्रकार के होते है:-



String

:-

string का प्रयोग characters के एक क्रम (sequence) को स्टोर करने के लिए किया जाता है. इसकी value को double quote के अंदर लिखा जाता है.



Example-



   
     public class StringExample{
    
    public static void main(String args[]){
    
    String MyName = "Education Point";

    System.out.println(MyName);

       }

     }
   
 


Output

   
   
  Education Point
   
 


class

class user के द्वारा define किया गया prototype है जिससे objects बनाये जाते है. इसमें methods और variables होते है.

   
  public class classExample {
    
  public static void main(String args[]){
  
  int x = 5;
  
  }
}
   
 


Output

   
 
    5
 
   
 

object

:-

यह class का instance होता है. और यह real world की entity को प्रस्तुत करता है.

   
      public class objectExample{
    
  int x = 5;

  public static void main(String[] args) {
    MyClass myObj = new MyClass();
    System.out.println(myObj.x);
  }
}
   
 


Output

   


   5

   
 

interface

class की तरह ही interface में भी methods और variable होते है. परन्तु इसमें declare की गयी मेथड abstract होती है.

   
    public class interfaceExample{
    
   // Interface
interface Animal {
  public void animalSound(); // interface method (does not have a body)
  public void sleep(); // interface method (does not have a body)
}

// Pig "implements" the Animal interface
class Pig implements Animal {
  public void animalSound() {
    // The body of animalSound() is provided here
    System.out.println("The pig says: wee wee");
  }
  public void sleep() {
    // The body of sleep() is provided here
    System.out.println("Zzz");
  }
}

class MyMainClass {
  public static void main(String[] args) {
    Pig myPig = new Pig();  // Create a Pig object
    myPig.animalSound();
    myPig.sleep();
  }
}

     }
   
   





Output

The pig says: wee wee Zzz


array

:-

array एक समान data type एक collection होता है.

   
     class arrayExample{
    
    public static void main(String args[]){
    
    String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
    int[] myNum = {10, 20, 30, 40};

    System.out.println(cars[0]);
    System.out.println(myNum[0]);

       }

     }
   
 


Output

   
   
   

   Volvo
   10
   


   
 
Previous
Next Post »

Quote

"Educationists should build the capacities of the spirit of inquiry, creativity, entrepreneurial and moral leadership among students and become their role model."

Dr. Abdual Kalam