Sunday, November 26, 2023

Operator Precedence in Java जावा में ऑपरेटर की प्राथमिकता

In Java, operators are evaluated in a specific order called precedence. When an expression has multiple operators, the precedence rules determine which operator is executed first.

जावा में जब किसी अभिव्यक्ति (expression) में कई ऑपरेटर होते हैं, तो उनकी प्राथमिकता यह तय करती है कि कौन सा ऑपरेटर पहले कार्य करेगा।

📌 Operators with higher precedence are evaluated before those with lower precedence.
📌 अधिक प्राथमिकता वाले ऑपरेटर पहले निष्पादित होते हैं।


🔝 Operator Precedence Table (Highest to Lowest)

(उच्च से निम्न प्राथमिकता तक ऑपरेटर)

1️⃣ Postfix Operators (पोस्टफिक्स ऑपरेटर)

  • expr++ (Post-increment)

  • expr-- (Post-decrement)

int a = 5;
int b = a++; // b = 5, a = 6

2️⃣ Unary Operators (यूनरी ऑपरेटर)

  • ++expr, --expr (Pre-increment, Pre-decrement)

  • +expr, -expr (Unary plus, minus)

  • !expr (Logical NOT), ~expr (Bitwise NOT)

  • (type) expr (Type casting)

int x = -10;
int y = +x; // y = -10

3️⃣ Multiplicative Operators (गुणन ऑपरेटर)

  • *, /, %

int a = 6, b = 4;
System.out.println(a * b); // 24

4️⃣ Additive Operators (जोड़ और घटाव ऑपरेटर)

  • +, -

int sum = 10 + 20; // 30

5️⃣ Shift Operators (शिफ्ट ऑपरेटर)

  • <<, >>, >>>

int n = 8;
System.out.println(n << 1); // 16

6️⃣ Relational Operators (संबंध ऑपरेटर)

  • <, >, <=, >=, instanceof

System.out.println(5 < 10); // true

7️⃣ Equality Operators (समानता ऑपरेटर)

  • ==, !=

System.out.println(5 == 5); // true

8️⃣ Bitwise AND (बिटवाइज़ AND)

  • &

System.out.println(5 & 3); // 1

9️⃣ Bitwise XOR (बिटवाइज़ XOR)

  • ^


🔟 Bitwise OR (बिटवाइज़ OR)

  • |


1️⃣1️⃣ Logical AND (तार्किक AND)

  • &&


1️⃣2️⃣ Logical OR (तार्किक OR)

  • ||


1️⃣3️⃣ Conditional (Ternary) Operator (शर्तीय ऑपरेटर)

  • ? :

int max = (a > b) ? a : b;

1️⃣4️⃣ Assignment Operators (असाइनमेंट ऑपरेटर)

  • =, +=, -=, *=, /=, %=

  • &=, |=, ^=, <<=, >>=, >>>=


Conclusion (निष्कर्ष):

Use parentheses ( ) to override default precedence and make complex expressions easier to read and predict. Understanding operator precedence ensures your Java expressions are evaluated correctly and behave as expected.

जटिल अभिव्यक्तियों में स्पष्टता और सही परिणाम पाने के लिए ब्रैकेट्स का उपयोग करें। जावा ऑपरेटर की प्राथमिकता को जानना आवश्यक है ताकि आप सही और सटीक कोडिंग कर सकें।

Operators in java जावा में ऑपरेटर

In Java, operators are special symbols used to perform operations on variables and values. Java supports the following types of operators:

जावा में, ऑपरेटर विशेष चिह्न होते हैं जो वेरिएबल्स और मानों पर संचालन (ऑपरेशन) करते हैं। जावा निम्न प्रकार के ऑपरेटरों का समर्थन करता है:


1️⃣ Arithmetic Operators (गणितीय ऑपरेटर)

Used for basic mathematical operations.
इनका उपयोग गणनाएँ करने के लिए किया जाता है।

Operator Meaning Example
+ Addition a + b
- Subtraction a - b
* Multiplication a * b
/ Division a / b
% Modulus a % b

🔸 Example:

int a = 10, b = 3;
System.out.println(a + b); // 13
System.out.println(a % b); // 1

2️⃣ Relational or Comparison Operators (तुलनात्मक ऑपरेटर)

Used to compare two values.
दो मानों की तुलना करने के लिए प्रयुक्त।

Operator Meaning Example
== Equal to a == b
!= Not equal to a != b
> Greater than a > b
< Less than a < b
>= Greater than or equal a >= b
<= Less than or equal a <= b

🔸 Example:

int x = 5, y = 10;
System.out.println(x > y); // false

3️⃣ Logical Operators (तार्किक ऑपरेटर)

Used for combining two or more conditions.
एक से अधिक शर्तों को जोड़ने के लिए प्रयुक्त।

Operator Meaning Example
&& Logical AND (a > 5 && b < 10)
` `
! Logical NOT !(a > b)

🔸 Example:

boolean a = true, b = false;
System.out.println(a && b); // false

4️⃣ Assignment Operators (सौंपने वाले ऑपरेटर)

Used to assign values to variables.
वेरिएबल्स को मान सौंपने के लिए।

Operator Meaning Example
= Assign a = 5
+= Add and assign a += 3
-= Subtract and assign a -= 2
*= Multiply and assign a *= 4
/= Divide and assign a /= 2
%= Modulus and assign a %= 3

5️⃣ Increment/Decrement Operators (वृद्धि/ह्रास ऑपरेटर)

Used to increase or decrease value by 1.
मान को 1 से बढ़ाने या घटाने के लिए।

Operator Meaning Example
++ Increment a++
-- Decrement a--

🔸 Example:

int a = 10;
a++;
System.out.println(a); // 11

6️⃣ Conditional (Ternary) Operator (शर्तीय ऑपरेटर)

Used as shorthand for if-else.
if-else का लघु रूप।

🔸 Syntax:
condition ? expression1 : expression2;

🔸 Example:

int a = 10, b = 20;
int max = (a > b) ? a : b;
System.out.println(max); // 20

7️⃣ Bitwise Operators (बिटवाइज़ ऑपरेटर)

Used to perform bit-level operations.
बिट स्तर के संचालन के लिए प्रयोग किया जाता है।

Operator Meaning Example
& Bitwise AND a & b
` ` Bitwise OR
^ Bitwise XOR a ^ b
~ Bitwise Complement ~a
<< Left Shift a << 2
>> Right Shift a >> 2
>>> Unsigned Right Shift a >>> 2

🔸 Example:

int a = 5, b = 3;
System.out.println(a & b); // 1
System.out.println(a << 1); // 10

8️⃣ instanceof Operator

Used to test whether an object is an instance of a class or subclass.
किसी ऑब्जेक्ट के क्लास का हिस्सा होने की जांच करता है।

🔸 Example:

String str = "Java";
System.out.println(str instanceof String); // true

9️⃣ Type Casting Operators (डेटा प्रकार परिवर्तन)

Used to convert one data type to another.
एक डेटा प्रकार को दूसरे में बदलने के लिए।

🔸 Example:

double a = 10.5;
int b = (int) a; // Type casting from double to int
System.out.println(b); // 10

Conclusion (निष्कर्ष):

Operators are essential tools in Java that help perform various kinds of operations efficiently. Mastering them is crucial for writing effective code.
ऑपरेटर जावा प्रोग्रामिंग के महत्वपूर्ण उपकरण हैं। इन्हें समझना एक कुशल प्रोग्रामर बनने के लिए आवश्यक है।

Type Casting (Type Conversion) in Java जावा में टाइप कास्टिंग (टाइप कन्वर्शन)

Type casting or Type Conversion refers to the process of converting one data type into another within a specific statement or expression. In Java, there are two main types of type casting:

टाइप कास्टिंग या टाइप कन्वर्शन के अंतर्गत किसी विशेष स्टेटमेंट या एक्सप्रेशन में एक डेटा टाइप को दूसरे डेटा टाइप में बदला जाता है। जावा में टाइप कास्टिंग के दो मुख्य प्रकार होते हैं:


a) Widening Casting (Implicitly) वाइडनिंग कास्टिंग (स्वचालित रूप से) :-

Converting a smaller data type into a larger data type is called widening casting or implicit casting.

एक छोटे डेटा टाइप को बड़े डेटा टाइप में परिवर्तित करना वाइडनिंग कास्टिंग या स्वचालित कास्टिंग कहलाता है।

Conversion order (रूपांतरण क्रम):


byte → short → char → int → long → float → double

Example / उदाहरण:

int i = 5;
double j = i; // Implicit casting - from int to double
System.out.println(i); // Output: 5
System.out.println(j); // Output: 5.0

b) Narrowing Casting (Manually) नैरोविंग कास्टिंग (मैन्युअली) :-

Converting a larger data type into a smaller data type is called narrowing casting or explicit casting.
एक बड़े डेटा टाइप को छोटे डेटा टाइप में परिवर्तित करना नैरोविंग कास्टिंग या मैन्युअल कास्टिंग कहलाता है।

Conversion order (रूपांतरण क्रम):
double → float → long → int → char → short → byte

Example / उदाहरण:

double i = 5.76;
int j = (int) i; // Explicit casting - from double to int
System.out.println(i); // Output: 5.76
System.out.println(j); // Output: 5

Conclusion / निष्कर्ष:-

In the first example, Java automatically converts int to double (implicit casting). In the second, the programmer manually converts double to int (explicit casting). These conversions help in data handling and type safety.

पहले उदाहरण में, जावा int को स्वतः double में बदल देता है (इम्प्लिसिट कास्टिंग)। दूसरे में, प्रोग्रामर को double को int में स्वयं बदलना पड़ता है (एक्स्प्लिसिट कास्टिंग)। डेटा टाइप्स को सही ढंग से संभालने के लिए इन दोनों कास्टिंग विधियों की समझ आवश्यक है।

Data types in Java जावा में डेटा के प्रकार

In Java, data types are used to specify the kind of data a variable can store. Understanding data types is fundamental to writing error-free and efficient code.

जावा में, डेटा प्रकार यह निर्धारित करते हैं कि कोई वेरिएबल किस प्रकार का डेटा संग्रहीत कर सकता है। प्रभावी प्रोग्रामिंग के लिए डेटा प्रकारों की समझ आवश्यक है।


1️⃣ Primitive Data Types आदिम डेटा प्रकार

Primitive data types store simple and direct values. Java supports 8 primitive data types:
आदिम डेटा प्रकार सीधे और सरल मान संग्रहीत करते हैं। जावा में 8 प्रकार के प्रिमिटिव डेटा टाइप होते हैं:

Data Type Size Range / Description डेटा प्रकार आकार सीमा / विवरण
byte 8-bit  -128 to 127 बाइट 8-बिट -128 से 127
short 16-bit   -32,768 to 32,767 शॉर्ट 16-बिट -32,768 से 32,767
int 32-bit  -2,147,483,648 to 2,147,483,647 इंट 32-बिट -2,14,74,83,648 से 2,14,74,83,647
long 64-bit  Very large integer values लॉन्ग 64-बिट बहुत बड़े पूर्णांक मान
float 32-bit    Decimal numbers (single precision) फ्लोट 32-बिट दशमलव संख्या (एकल सटीकता)
double 64-bit  Decimal numbers (double precision) डबल 64-बिट दशमलव संख्या (दोहरी सटीकता)
char 16-bit  Single Unicode character (e.g., 'A') कैरेक्टर 16-बिट एक यूनिकोड वर्ण
boolean 1-bit  true or false बूलियन 1-बिट true या false

Example:

byte myByte = 10;
short myShort = 1000;
int myInt = 100000;
long myLong = 1000000000L;

float myFloat = 3.14f;
double myDouble = 3.14159;

char myChar = 'A';
boolean myBoolean = true;

2️⃣ Reference Data Types संदर्भ डेटा प्रकार

These refer to objects in memory rather than storing the value directly. They store memory addresses that point to the actual data.
ये वेरिएबल डेटा को सीधे स्टोर नहीं करते, बल्कि उस डेटा के मेमोरी पते को स्टोर करते हैं।

a) String – A sequence of characters

स्ट्रिंग – वर्णों का क्रम

String myString = "Hello, Java!";

b) Array – A collection of elements of the same type

एरे – एक जैसे प्रकार के डेटा का संग्रह

int[] myArray = {1, 2, 3, 4, 5};

c) Class – User-defined data type

क्लास – उपयोगकर्ता द्वारा परिभाषित डेटा प्रकार

class Person {
    String name;
    int age;
}
Person myPerson = new Person();
myPerson.name = "John";
myPerson.age = 30;

d) Interface – Blueprint of methods

इंटरफ़ेस – विधियों का खाका

interface Shape {
    void draw();
}
class Circle implements Shape {
    public void draw() {
        System.out.println("Drawing a circle");
    }
}

Summary (सारांश):

Type Description
Primitive                       Stores basic values directly
Reference Stores reference to memory location

प्रकार विवरण
आदिम प्रकार                 मूल मान सीधे स्टोर करता है
संदर्भ प्रकार                 मेमोरी के पते को स्टोर करता है

These data types form the building blocks of Java programming. Mastering them is essential for writing logical, optimized, and bug-free code.
ये डेटा प्रकार जावा प्रोग्रामिंग के मूल स्तंभ हैं। इनकी समझ से आप बेहतर, तेज़ और सही प्रोग्रामिंग कर सकते हैं।

Scope of a variable in java जावा में वेरिएबल का कार्यक्षेत्र

In Java, the scope of a variable refers to the region in a program where the variable is recognized and accessible. Variables in Java can be categorized based on their scope into three main types:

जावा में वेरिएबल का कार्यक्षेत्र उस हिस्से को कहा जाता है जहाँ वेरिएबल मान्य और उपयोग योग्य होता है। जावा में वेरिएबल के कार्यक्षेत्र को तीन प्रमुख वर्गों में बांटा गया है–


1️⃣ Local Variable (लोकल वेरिएबल)

English:

  • Declared and used only inside a method or a block {}.

  • Scope is limited to that method or block.

  • Dies as soon as the control exits the method.

  • Java does not allow same-name variables in nested blocks unlike C/C++.

Hindi:

  • यह किसी मेथड या ब्लॉक {} के अंदर ही घोषित और उपयोग किए जाते हैं।

  • इनका कार्यक्षेत्र उसी मेथड या ब्लॉक तक सीमित होता है।

  • जैसे ही कंट्रोल बाहर जाता है, यह समाप्त हो जाते हैं।

  • जावा में नेस्टेड ब्लॉक्स में एक ही नाम के दो वेरिएबल नहीं बनाए जा सकते हैं।


2️⃣ Instance Variable (इंस्टैंस वेरिएबल)

English:

  • Declared inside a class but outside methods.

  • Every object has its own copy of instance variables.

  • Lives as long as the object lives.

Hindi:

  • यह क्लास के अंदर लेकिन मेथड के बाहर घोषित किए जाते हैं।

  • क्लास के हर ऑब्जेक्ट की अपनी एक कॉपी होती है।

  • जब तक ऑब्जेक्ट मौजूद रहता है, यह भी रहते हैं।


3️⃣ Class Variable (क्लास वेरिएबल)

English:

  • Declared with static keyword inside the class.

  • Shared among all objects of the class.

  • Memory is allocated only once.

Hindi:

  • इसे static कीवर्ड से क्लास के अंदर घोषित किया जाता है।

  • यह क्लास के सभी ऑब्जेक्ट्स के बीच साझा होता है।

  • मेमोरी में केवल एक बार ही इसका स्थान निर्धारित होता है।


🔎 Example Program (उदाहरण प्रोग्राम)

public class VariableScopeExample {

    // Class variable
    static int globalVar = 10;

    public static void main(String[] args) {
        // Local variable
        int localVar = 5;

        System.out.println("Local Variable: " + localVar);
        System.out.println("Class Variable: " + globalVar);

        // Creating an object of SampleClass
        SampleClass obj = new SampleClass();

        // Accessing instance variable through object
        System.out.println("Instance Variable through Object: " + obj.instanceVar);
    }
}

class SampleClass {
    // Instance variable
    int instanceVar = 20;
}

📌 Summary सारांश:

  • Local variables are short-lived and exist only in blocks or methods.

  • Instance variables are object-specific and non-static.

  • Class variables are shared and declared with static.

Variables in Java जावा में वेरिएबल

In Java, a variable is a named storage location used to hold data values during program execution. Variables are essential because they allow you to store, update, and use data dynamically.

जावा में वेरिएबल (चर) एक नामित स्टोरेज स्थान होता है, जिसका उपयोग प्रोग्राम के दौरान डेटा को संग्रहित और उपयोग करने के लिए किया जाता है। वेरिएबल्स प्रोग्रामिंग का एक मूलभूत हिस्सा होते हैं।


🔹 1. Declaration | घोषणा

Before using a variable, it must be declared with its data type and name.

किसी वेरिएबल का उपयोग करने से पहले, उसका डेटा प्रकार और नाम बताकर उसे घोषित (declare) करना होता है।

int age; // Declare an integer variable named 'age'

🔹 2. Initialization | मान देना

After declaring, you can assign a value. This is called initialization.

घोषणा के बाद, वेरिएबल को कोई मान (value) देना Initialization कहलाता है।

age = 50; // Initialize the variable

Declaration and initialization can also be done together:

int age = 50;

🔹 3. Variable Types | वेरिएबल के प्रकार

Java is statically typed, so you must declare the type. Common types are:

int count = 10;         // Integer
double pi = 3.14;       // Decimal number
char grade = 'A';       // Character
boolean isStudent = true; // True or False

जावा में वेरिएबल का डेटा प्रकार पहले से तय करना होता है जैसे int, double, char, boolean आदि।


🔹 4. Naming Rules | नामकरण के नियम

  • Must start with a letter, _ or $

  • Can include letters, digits, _, and $

  • Case-sensitive (Age and age are different)

  • Reserved words like class, int cannot be used

वेरिएबल नाम छोटे अक्षरों से शुरू होते हैं और विशेष शब्दों (keywords) का उपयोग नहीं किया जा सकता।


🔹 5. Scope of Variable | वेरिएबल का स्कोप

Scope means where the variable can be accessed:

public class Example {
    int globalVar = 5; // Class-level (field)

    public void exampleMethod() {
        int localVar = 10; // Local to method
        System.out.println(localVar);
    }
}

वेरिएबल का स्कोप यह तय करता है कि वह किस भाग में मान्य है – जैसे क्लास लेवल, मेथड लेवल या ब्लॉक लेवल।


🔹 6. Final Keyword | अंतिम (Final) वेरिएबल

To make a variable constant, use final:

final double PI = 3.14159;

final का प्रयोग वेरिएबल को स्थायी (unchangeable) बनाने के लिए होता है।


✅ Java Program: Simple Interest | जावा प्रोग्राम: साधारण ब्याज

public class SimpleInterest {
    public static void main(String args[]) {
        // Declare variables
        float p, r, t, si;

        // Initialize variables
        p = 1000;   // Principal
        r = 2;      // Rate
        t = 5;      // Time

        // Calculate SI
        si = (p * r * t) / 100;

        // Print result
        System.out.println("Simple Interest is= " + si);
    }
}

Output:

Simple Interest is= 100.0

📝 Summary (सारांश):

  • Variables store data

  • Must be declared with type

  • Can be initialized separately or together

  • Scope defines accessibility

  • Use final to make constants

वेरिएबल्स डेटा स्टोर करने के लिए आवश्यक हैं, इन्हें पहले घोषित करना होता है, और final से स्थिरांक बनाया जा सकता है।

Constants (Literal) in Java जावा में स्थिरांक

In Java, a constant is a variable whose value cannot be changed once assigned. Constants are used to represent fixed values that remain unchanged during the program’s execution. In Java, constants are declared using the final keyword.

जावा में, स्थिरांक (constant) एक ऐसा वेरिएबल होता है जिसका मान एक बार निर्धारित हो जाने के बाद बदला नहीं जा सकता है। स्थिरांकों का उपयोग ऐसे मानों को दर्शाने के लिए किया जाता है जो प्रोग्राम के निष्पादन के दौरान हमेशा एक जैसे रहते हैं। जावा में, कॉन्स्टेंट्स को final कीवर्ड से घोषित किया जाता है।

📌 Syntax (सिंटैक्स):-

final dataType CONSTANT_NAME = value;

Example (उदाहरण):

final double PI = 3.14159;

🌐 Global Constants in Java | वैश्विक स्थिरांक

In Java, a global constant refers to a value that can be accessed throughout a class or even across multiple classes in the same package. Such constants are generally declared using both the static and final keywords.

जावा में, वैश्विक स्थिरांक (Global Constant) ऐसा मान होता है जिसे किसी एक क्लास या एक ही पैकेज की कई क्लासों में भी उपयोग किया जा सकता है। इसके लिए सामान्यतः static और final दोनों कीवर्ड का प्रयोग किया जाता है।

📌 Syntax (सिंटैक्स):

static final dataType CONSTANT_NAME = value;

Example (उदाहरण):

static final double PI = 3.14159;

✅ Java Program to Demonstrate Constants | जावा प्रोग्राम – स्थिरांक का प्रदर्शन

public class ConstantsExample {
    // Declaration of constants
    static final int MAX_VALUE = 100;
    static final String GREETING = "Hello, World!";
    static final double PI = 3.14159;

    public static void main(String[] args) {
        // Accessing constants within the main method
        System.out.println("Max Value: " + MAX_VALUE);
        System.out.println("Greeting: " + GREETING);
        System.out.println("Value of PI: " + PI);
    }
}

Output (आउटपुट):

Max Value: 100
Greeting: Hello, World!
Value of PI: 3.14159

🔍 Summary (सारांश):

  • Constants help in writing safe and clean code.

  • They make your program more readable and maintainable.

  • Constants should be named in UPPERCASE letters with words separated by underscores (e.g., MAX_SPEED, PI, MIN_BALANCE).

स्थिरांक प्रोग्राम को सुरक्षित, स्पष्ट और समझने योग्य बनाते हैं। इन्हें बड़े अक्षरों (UPPERCASE) में और शब्दों को _ से अलग करके नाम देना चाहिए।

Saturday, November 11, 2023

Java Programming Style जावा प्रोग्रामिंग की शैली

Programming style is a set of guidelines applied to use the instructions of a programming language correctly. Following a programming style is crucial because it helps the programmer understand the code easily, and it reduces the chances of errors.

प्रोग्रामिंग शैली, किसी प्रोग्रामिंग लैंग्वेज के निर्देशों को सही तरीके से उपयोग करने के लिए लागू किए गए दिशानिर्देशों का एक समूह होता है। एक प्रोग्रामिंग शैली का पालन करना अत्यंत आवश्यक होता है क्योंकि इसकी सहायता से प्रोग्रामर कोड को आसानी से समझ सकता है एवं कम त्रुटियां उत्पन्न होती हैं।

Important Rules of Java Programming Style | जावा प्रोग्रामिंग शैली के महत्वपूर्ण नियम:

1️⃣ A Java program should be easy to read and understand.
एक जावा प्रोग्राम पढ़ने एवं समझने में आसान होना चाहिए।

2️⃣ Each class should have Javadoc comments and @author tag.
प्रत्येक क्लास में जावाडॉक टिप्पणी एवं @author टैग होना चाहिए।

3️⃣ Each public method should have Javadoc comments.
हर पब्लिक मेथड में जावाडॉक टिप्पणी होनी चाहिए।

4️⃣ Variables should include a comment explaining their purpose.
वेरिएबल के उद्देश्य की व्याख्या करने वाली टिप्पणी होनी चाहिए।

5️⃣ Add comments inside method body to explain logic.
कोड लॉजिक को समझाने हेतु मेथड बॉडी में टिप्पणी जोड़ी जा सकती है।

6️⃣ Use indentation to show code structure.
कोड संरचना दिखाने के लिए इंडेंटेशन का प्रयोग करें।

7️⃣ Use separate lines for closing curly brace }; opening brace { can be same or next line.
बंद कोष्टक } एक नई पंक्ति में हो, और { उसी या अगली पंक्ति में।

8️⃣ Avoid placing multiple statements on the same line.
एक ही पंक्ति में एक से अधिक स्टेटमेंट न रखें।

9️⃣ Break long lines into smaller readable lines.
लंबी पंक्तियों को छोटे भागों में विभाजित करें।

🔟 Add space between method definitions.
मेथड परिभाषाओं के बीच थोड़ा रिक्त स्थान रखें।

1️⃣1️⃣ Use meaningful names (camelCase, PascalCase).
सार्थक नामों का प्रयोग करें (कैमल केस, पास्कल केस जैसे maxMarks, SimpleInterest).

1️⃣2️⃣ Use final static for constants and enum for grouped constants.
कांस्टेंट के लिए final static और समूह के लिए enum का उपयोग करें।

1️⃣3️⃣ Method should be short and focused.
हर मेथड छोटा और विशिष्ट उद्देश्य वाला हो।

1️⃣4️⃣ Prefer parameters and return values over instance variables.
इंस्टेंस वेरिएबल्स की बजाय पैरामीटर और रिटर्न वैल्यू का उपयोग करें।

1️⃣5️⃣ Class should represent a unique, identifiable concept.
क्लास एक स्पष्ट और पहचाने जाने योग्य अवधारणा को दर्शाए।

1️⃣6️⃣ Keep variables in private section, and getter-setter methods in public section.
वेरिएबल्स को प्राइवेट और गेट/सेट मेथड को पब्लिक सेक्शन में रखें।


Java Environment जावा का वातावरण

Introduction | परिचय 

To develop and run Java applications, a complete setup is needed that includes development tools and a runtime system. This environment is known as the Java Environment and consists mainly of the JDK, JRE, and JVM.
जावा एप्लिकेशन को विकसित और रन करने के लिए एक सम्पूर्ण वातावरण की आवश्यकता होती है, जिसमें डेवलपमेंट टूल्स और रनटाइम सिस्टम शामिल होता है। इसे ही जावा का वातावरण कहा जाता है, जिसमें मुख्यतः JDK, JRE और JVM होते हैं।


1️⃣ Java Development Kit (JDK) | जावा डेवलपमेंट किट

JDK is a software development environment used to build Java applications and applets. It includes:

  • Java Runtime Environment (JRE) – to run applications

  • javac – Java compiler

  • java – Interpreter/Loader

  • jar – Java Archive tool

  • javadoc – Documentation generator

JDK एक सॉफ्टवेयर डेवलपमेंट वातावरण है जिसका उपयोग जावा एप्लिकेशन और एप्लेट्स को बनाने के लिए किया जाता है। इसमें शामिल हैं:

  • Java Runtime Environment (JRE) – एप्लिकेशन चलाने हेतु

  • javac – जावा कंपाइलर

  • java – इंटरप्रेटर/लोडर

  • jar – जावा आर्काइव टूल

  • javadoc – डॉक्यूमेंटेशन जनरेटर


2️⃣ Java Virtual Machine (JVM) | जावा वर्चुअल मशीन

JVM stands for Java Virtual Machine. It provides the runtime environment to execute Java bytecode. It converts bytecode into machine code, enabling Java's platform independence.
JVM का पूरा नाम जावा वर्चुअल मशीन है। यह रनटाइम वातावरण प्रदान करती है और बाइटकोड को मशीन कोड में बदलती है, जिससे जावा प्लेटफार्म स्वतंत्र बनता है।


3️⃣ Java Runtime Environment (JRE) | जावा रनटाइम एनवायरनमेंट

JRE is a part of JDK needed to run Java programs. It includes class libraries and other files used by the JVM at runtime. JRE is developed by Sun Microsystems.
JRE, JDK का हिस्सा है जो जावा प्रोग्राम को रन करने के लिए आवश्यक होता है। इसमें क्लास लाइब्रेरी और अन्य फाइलें होती हैं जिन्हें JVM रनटाइम पर उपयोग करता है। इसे Sun Microsystems ने विकसित किया था।

👉 If you're a developer, install JDK.
👉 If you're just running Java programs, JRE is enough.
यदि आप डेवलपर हैं, तो JDK इनस्टॉल करें।
केवल रन के लिए JRE पर्याप्त है।


✅ Conclusion | निष्कर्ष

Java environment provides everything needed to build and run Java apps. Knowing the difference between JDK, JRE, and JVM is essential for all learners.
जावा वातावरण जावा ऐप्स को बनाने और चलाने के लिए आवश्यक सभी चीजें प्रदान करता है। JDK, JRE और JVM के बीच अंतर जानना सभी छात्रों के लिए जरूरी है।

📚 Other Stream Classes in Java जावा में अन्य स्ट्रीम क्लासेस

In Java, apart from basic byte and character streams, there are several specialized stream classes that provide advanced input-output operat...