Header Ads

Datatypes in Java

 Datatypes in Java


In Java, data types determine the type of values that can be stored in variables. Each data type has specific characteristics and memory requirements. Java supports two types of data types: primitive data types and reference data types.

Primitive Data Types:

1. **byte**: The byte data type is an 8-bit signed integer with a range from -128 to 127. It is commonly used when dealing with raw binary data or memory-mapped files.

2. **short**: The short data type is a 16-bit signed integer with a range from -32,768 to 32,767. It is often used in arrays when memory space is a concern.

3. **int**: The int data type is a 32-bit signed integer with a range from -2,147,483,648 to 2,147,483,647. It is the most commonly used integer type in Java.

4. **long**: The long data type is a 64-bit signed integer with a range from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. It is used when a wider range of values is needed.

5. **float**: The float data type is a single-precision 32-bit floating-point number. It can represent decimal values and has a range from approximately 1.4E-45 to 3.4E+38.

6. **double**: The double data type is a double-precision 64-bit floating-point number. It has a larger range and higher precision compared to float, ranging from approximately 4.9E-324 to 1.8E+308.

7. **boolean**: The boolean data type represents a boolean value, which can be either true or false. It is commonly used in conditional statements and loops.

8. **char**: The char data type represents a single 16-bit Unicode character. It can store any character from the Unicode character set.

Reference Data Types:

1. **class**: The class data type refers to objects of user-defined classes. It allows you to create instances of classes and access their properties and methods.

2. **interface**: The interface data type refers to interfaces, which define a contract for implementing classes. An interface can be used as a reference type to hold objects of classes implementing that interface.

3. **array**: The array data type allows you to store multiple values of the same type in a contiguous memory location. Arrays can be of any data type, including both primitive and reference types.

4. **String**: The String data type represents a sequence of characters. It is a reference type, but it is often treated as a primitive type due to its frequent usage.

These are the basic data types in Java. It's important to choose the appropriate data type based on the range of values and memory requirements to ensure efficient and accurate programming.


हिंदी:

जावा में, डेटा टाइप्स परिभाषित करते हैं कि चर रूप में कौन से मान संग्रहीत किए जा सकते हैं। प्रत्येक डेटा टाइप के विशेष विशेषताएं और मेमोरी की आवश्यकताएं होती हैं। जावा में दो प्रकार के डेटा टाइप्स होते हैं: प्राथमिक डेटा टाइप्स और संदर्भ डेटा टाइप्स।

प्राथमिक डेटा टाइप्स:

1. **बाईट**: बाईट डेटा टाइप 8-बिट साइन्ड इंटीजर होता है जिसकी मान सीमा -128 से 127 तक होती है। इसे आमतौर पर कच्चे बाइनरी डेटा या मेमोरी-मैप्ड फ़ाइलों के साथ काम करने के लिए उपयोग किया जाता है।

2. **शॉर्ट**: शॉर्ट डेटा टाइप 16-बिट साइन्ड इंटीजर होता है जिसकी मान सीमा -32,768 से 32,767 तक होती है। यह अक्सर एरे में उपयोग किया जाता है जब मेमोरी स्थान चिंता होती है।

3. **इंट**: इंट डेटा टाइप 32-बिट साइन्ड इंटीजर होता है जिसकी मान सीमा -2,147,483,648 से 2,147,483,647 तक होती है। यह जावा में सबसे आम इंटीजर टाइप है।

4. **लॉंग**: लॉंग डेटा टाइप 64-बिट साइन्ड इंटीजर होता है जिसकी मान सीमा -9,223,372,036,854,775,808 से 9,223,372,036,854,775,807 तक होती है। यह जब एक व्यापक मानों की सीमा की आवश्यकता होती है तब उपयोग किया जाता है।

5. **फ़्लोट**: फ़्लोट डेटा टाइप एकल-सटीकता 32-बिट फ़्लोटिंग-प्वाइंट नंबर होता है। यह दशमलव मानों को प्रतिष्ठित कर सकता है और प्रायः 1.4E-45 से 3.4E+38 तक की मान सीमा होती है।

6. **डबल**: डबल डेटा टाइप डबल-सटीकता 64-बिट फ़्लोटिंग-प्वाइंट नंबर होता है। यह फ़्लोट से बड़ी सीमा और उच्च सटीकता वाला होता है, औसतन 4.9E-324 से 1.8E+308 तक की मान सीमा होती है।

7. **बूलियन**: बूलियन डेटा टाइप सत्य या असत्य को प्रतिष्ठित करता है। यह आमतौर पर शर्ती वाक्यों और लूपों में उपयोग किया जाता है।
8. **चार** (char): चार डेटा टाइप एकल 16-बिट यूनिकोड वर्ण होता है। यह यूनिकोड वर्ण संग्रह का प्रतिष्ठान कर सकता है।

संदर्भ डेटा टाइप्स (Reference Datatypes):

1. **कक्षा** (class): कक्षा डेटा टाइप प्रयोगकर्ता-निर्मित कक्षाओं के ऑब्जेक्ट्स का संदर्भ करता है। इसकी मदद से आप कक्षाओं के उदाहरण बना सकते हैं और उनकी गुणधर्म और विधियों तक पहुंच सकते हैं।

2. **इंटरफ़ेस**: इंटरफ़ेस डेटा टाइप इंटरफ़ेस का संदर्भ करता है, जो कक्षाओं को लागू करने के लिए एक समझौता परिभाषित करता है। एक इंटरफ़ेस को एक संदर्भ टाइप के रूप में उपयोग किया जा सकता है, जो उस इंटरफ़ेस को लागू करने वाली कक्षाओं के ऑब्जेक्ट्स को रखने के लिए होता है।

3. **ऐरे**: ऐरे डेटा टाइप आपको समान प्रकार के अनुरूप मानों को एकत्रित मेमोरी स्थान में संग्रहीत करने की अनुमति देता है। ऐरे किसी भी डेटा टाइप की हो सकती है, सहित ही प्राथमिक और संदर्भ टाइप्स दोनों।

4. **स्ट्रिंग**: स्ट्रिंग डेटा टाइप एक वर्ण-क्रम को प्रतिष्ठित करता है। यह एक संदर्भ टाइप है, लेकिन इसे अक्सर प्राथमिक टाइप की तरह व्यवहार किया जाता है दरअसल इसका अक्सर उपयोग होता है।

ये जावा में मूल डेटा टाइप्स हैं। सही और कुशल प्रोग्रामिंग के लिए मानों की सीमा और मेमोरी आवश्यकताओं के आधार पर उचित डेटा टाइप का चयन करना महत्वपूर्ण होता है।

No comments

Powered by Blogger.