Wednesday, July 23, 2025

Java Class Object - Explained with Example क्लास ऑब्जेक्ट - उदाहरण सहित

An object is a real-world entity that contains both properties (data) and behaviors (methods). In Java, an object is an instance of a class that represents its existence. For example – pen, pencil, calculator, car, or mobile. A class object can be logical or physical and it holds the following:

वास्तविक दुनिया की एक ऐसी इकाई जिसमें गुण (डेटा) और व्यवहार (क्रियाएँ) दोनों होते हैं, उसे ऑब्जेक्ट कहा जाता है। जावा में, एक ऑब्जेक्ट किसी क्लास का instance (उदाहरण) होता है, जो उस क्लास के अस्तित्व को दर्शाता है। जैसे – पेन, पेंसिल, कैलकुलेटर, कार, मोबाइल आदि। एक क्लास ऑब्जेक्ट तार्किक या वास्तविक हो सकता है जिसमें निम्न होते हैं:

Property – Represents the class's variables.

गुण (Property) – क्लास के वेरिएबल को दर्शाता है।


Behavior – Represents the class's methods.

व्यवहार (Behavior) – क्लास की मेथड को दर्शाता है।

In real life, a student is an object with properties like roll number, name, and marks, and behaviors like mark sheet generation, admit card printing, or scholarship status.

वास्तविक जीवन में एक स्टूडेंट ऑब्जेक्ट होता है, जिसके पास रोल नंबर, नाम और प्राप्तांक जैसे गुण होते हैं, और मार्कशीट बनाना, एडमिट कार्ड निकालना या स्कॉलरशिप लेना जैसे व्यवहार होते हैं।


🧰 How to Create Class Object in Java जावा में क्लास ऑब्जेक्ट कैसे बनाएं

In Java, an object of a class is created using the new keyword. 

जावा में किसी क्लास का ऑब्जेक्ट new कीवर्ड के माध्यम से बनाया जाता है।

Syntax

ClassName variable_name = new ClassName();

Example

public class Student {
  int rollno;
  String sname;
  float marks;

  void sinfo() {
    System.out.println("Roll Number: " + rollno);
    System.out.println("Name: " + sname);
    System.out.println("Marks: " + marks);
  }

  public static void main(String[] args) {
    Student s = new Student();
    s.rollno = 1;
    s.sname = "Ajay";
    s.marks = 421;
    s.sinfo();
  }
}

In the above example, the main() method creates an object s of the Student class and accesses its variables using that object.

उपरोक्त उदाहरण में main() मेथड का उपयोग Student क्लास का s नामक ऑब्जेक्ट तैयार करने के लिए किया गया है, और उस ऑब्जेक्ट के माध्यम से क्लास के वेरिएबल्स को एक्सेस किया गया है।


🛠️ Other Ways to Create Object in Java

In Java, objects can also be created using the following ways:

  • Using new keyword

  • Using newInstance() method

  • Using clone() method

  • Using Deserialization

  • Using factory() method


🛠️ जावा में ऑब्जेक्ट बनाने के अन्य तरीके

जावा में ऑब्जेक्ट निम्नलिखित तरीकों से भी बनाए जा सकते हैं:

  • new कीवर्ड का उपयोग करके

  • newInstance() मेथड के द्वारा

  • clone() मेथड के द्वारा

  • Deserialization के द्वारा

  • factory() मेथड के द्वारा

Java Class with Example जावा में क्लास उदाहरण सहित

A class is one of the most important concepts in Object-Oriented Programming. It acts as a template or blueprint that defines the structure and behavior of objects sharing common features. It holds all the properties and behaviors that an object may have. Instead of directly representing real-world entities, we define classes, and then create objects (instances) from them.

क्लास ऑब्जेक्ट ओरिएंटेड प्रोग्रामिंग की सबसे महत्वपूर्ण अवधारणाओं में से एक है। यह एक टेम्पलेट या ढांचा होता है जो समान गुणों वाले ऑब्जेक्ट्स को दर्शाता है। यह ऑब्जेक्ट की सभी विशेषताओं और व्यवहारों को संजोता है। हम किसी भी वास्तविक वस्तु को सीधे न दर्शाकर उसकी क्लास बनाकर ऑब्जेक्ट तैयार करते हैं।

For example, a Student class can represent attributes such as name, roll number, address, phone number, fees, and marks. An instance of the class represents an actual student. In Java, every class usually contains two main parts:

उदाहरण के लिए, एक Student क्लास, नाम, अनुक्रमांक, पता, मोबाइल नंबर, शुल्क, और अंक जैसी विशेषताओं का प्रतिनिधित्व कर सकती है। किसी क्लास का इंस्टैंस एक वास्तविक छात्र को दर्शाता है। जावा में प्रत्येक क्लास सामान्यतः दो भागों से बनी होती है:

a) Attributes

Attributes define the data or characteristics of an object. For example, a Motorcycle class may include attributes like color, style, chassis number, manufacturer, and price. These are typically defined using variables.

एट्रिब्यूट्स किसी वस्तु के गुणों को परिभाषित करते हैं। उदाहरण के लिए, एक Motorcycle क्लास में रंग, स्टाइल, चेसिस नंबर, निर्माता और कीमत जैसे गुण हो सकते हैं। इन्हें वेरिएबल्स द्वारा परिभाषित किया जाता है।

Example attributes for Student class:

int rollno;
String sname;
float marks;

b) Behavior

Behavior describes how an object acts or behaves using methods. For example, the Motorcycle class may have behaviors like startEngine(), stopEngine(), accelerate(), and changeGear().

बिहेवियर किसी वस्तु की क्रियाओं को परिभाषित करता है और इन्हें मेथड्स द्वारा लिखा जाता है। उदाहरण के लिए, Motorcycle क्लास में startEngine(), stopEngine(), accelerate() और changeGear() जैसे बिहेवियर्स हो सकते हैं।

Example method for Student class:

void sinfo() {
// some code
}

💡 Syntax of a Java Class

modifier class ClassName {
// attributes
// methods
}

✅ Example of a Simple Java Class

public class Student {
int rollno;
String sname;
float marks;
void sinfo() {
System.out.println("Roll No: " + rollno);
System.out.println("Name: " + sname);
System.out.println("Marks: " + marks);
}
}

📌 Java Program to Calculate Gross Salary of an Employee

import java.util.*;
public class EmployeeTest {
static class Employee {
double bs, HRA, TA, DA, gs;
void setSalary() {
Scanner s = new Scanner(System.in);
System.out.println("Enter Basic Salary of Employee:");
bs = s.nextDouble();
HRA = 0.05 * bs;
TA = 0.1 * bs;
DA = 0.2 * bs;
}
void getSalary() {
System.out.println("Basic Salary = " + bs);
System.out.println("HRA = " + HRA);
System.out.println("TA = " + TA);
System.out.println("DA = " + DA);
System.out.println("Gross Salary = " + grossSalary());
}
double grossSalary() {
if (bs >= 20000)
gs = bs + HRA + TA + DA + 5000;
else
gs = bs + HRA + TA + DA;
return gs;
}
}
public static void main(String args[]) {
Employee emp = new Employee();
emp.setSalary();
emp.getSalary();
}
}

Labeled Loops in Java लेबल किए गए लूप

Labeled loops are used in Java when working with nested loops to control the flow of execution more precisely. A label is simply a valid Java identifier followed by a colon (:) placed before a loop. It allows the use of break or continue to directly jump to or skip a specific loop block rather than just the inner one. These are especially useful when you need to exit or continue an outer loop from inside an inner loop.

लेबल्ड लूप का उपयोग जावा में नेस्टेड लूप के साथ किया जाता है ताकि प्रोग्राम के कंट्रोल फ्लो को अधिक सटीक तरीके से नियंत्रित किया जा सके। एक लेबल, एक वैध जावा पहचानकर्ता होता है जिसे कोलन (:) के साथ लूप के पहले लिखा जाता है। इसका प्रयोग break या continue स्टेटमेंट के साथ करके हम सीधे बाहरी लूप को प्रभावित कर सकते हैं। यह तब उपयोगी होता है जब हमें किसी इनर लूप से निकलकर सीधे आउटर लूप पर कार्य करना हो या उसे स्किप करना हो।

Syntax:

labelName:
for(initialization; condition; update){
   // loop body
}
labelName:
while(condition){
   // loop body
}

✅ Java Example using Labeled break

public class LabeledBreakExample {
    public static void main(String[] args) {
        outerLoop:
        for (int i = 1; i <= 3; i++) {
            for (int j = 1; j <= 3; j++) {
                if (i == 2 && j == 2) {
                    break outerLoop; // exits both loops
                }
                System.out.println("i=" + i + ", j=" + j);
            }
        }
    }
}

✅ Java Example using Labeled continue

public class LabeledContinueExample {
    public static void main(String[] args) {
        outerLoop:
        for (int i = 1; i <= 3; i++) {
            for (int j = 1; j <= 3; j++) {
                if (j == 2) {
                    continue outerLoop; // skips to next iteration of outer loop
                }
                System.out.println("i=" + i + ", j=" + j);
            }
        }
    }
}

Java Jump Statements (break, continue, return) – Explained with Examples जावा जंप स्टेटमेंट्स – उदाहरणों के साथ

Jump statements in Java are used to control the flow of execution within loops and methods. These help in exiting, skipping, or returning values based on specific conditions, making the program more flexible and powerful.

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


🛑 break Statement

The break statement is used to exit a loop or switch-case block prematurely. It is commonly used when a certain condition is met and further execution inside the loop or switch is unnecessary.

break स्टेटमेंट का उपयोग किसी लूप या switch-case ब्लॉक से अचानक बाहर निकलने के लिए किया जाता है। इसका प्रयोग तब किया जाता है जब किसी शर्त की पूर्ति हो जाती है और लूप या स्विच के अंदर की आगे की प्रक्रिया को रोकना होता है।

Example:

public class BreakExample {
public static void main(String[] args) {
for (int i = 1; i <= 10; i++) {
if (i == 5) {
break;
}
System.out.println("Value: " + i);
}
}
}

🔁 continue Statement

The continue statement skips the current iteration of the loop and proceeds with the next iteration. It is useful when you want to skip only certain values or conditions within a loop.

continue स्टेटमेंट वर्तमान iteration को स्किप करके सीधे अगले iteration पर चला जाता है। इसका प्रयोग तब किया जाता है जब हमें लूप के अंदर कुछ विशेष मानों या स्थितियों को छोड़ना हो।

Example:

public class ContinueExample {
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
if (i == 3) {
continue;
}
System.out.println("Number: " + i);
}
}
}

↩️ return Statement

The return statement is used to exit from a method and optionally return a value. It plays an important role in function-based programming by sending the result of a method back to the caller.

return स्टेटमेंट का उपयोग किसी method से बाहर निकलने और यदि आवश्यक हो तो एक वैल्यू को वापस लौटाने के लिए किया जाता है। यह फंक्शन-बेस्ड प्रोग्रामिंग में एक महत्वपूर्ण भूमिका निभाता है।

Example:

public class ReturnExample {
public static int square(int number) {
return number * number;
}
public static void main(String[] args) {
int result = square(6);
System.out.println("Square is: " + result);
}
}

📌 Summary

  • break is used to stop loops or switch-cases.

  • continue skips current iteration of the loop.

  • return exits the method and may return a value.

  • break का प्रयोग लूप या स्विच को रोकने के लिए किया जाता है।

  • continue लूप के वर्तमान iteration को छोड़ देता है।

  • return method को समाप्त करता है और वैल्यू भी वापस कर सकता है।

Loop Structure in Java जावा में लूप स्ट्रक्चर for loop, while loop, do...while loop

Java supports three types of loops: for loop, while loop, and do...while loop. These loops are used when a task needs to be repeated multiple times.

जावा तीन मुख्य प्रकार के लूप का समर्थन करता है: for loop, while loop, और do...while loop. इनका उपयोग तब किया जाता है जब हमें एक ही कोड को बार-बार चलाना हो।


✅ (a) for Loop – Entry-Controlled Loop

A for loop checks the condition before entering the loop. It has initialization, condition, and update parts written in a single line, separated by semicolons. It's ideal when the number of iterations is known.

for लूप एक एंट्री कंट्रोल लूप होता है जिसमें कंडीशन को पहले चेक किया जाता है। इसमें इनिशियलाइजेशन, कंडीशन और अपडेशन एक ही लाइन में लिखे जाते हैं और अर्धविराम से अलग किए जाते हैं। इसका उपयोग तब किया जाता है जब पहले से पता हो कि लूप कितनी बार चलेगा।

Java Program:

public class ForLoopExample {
public static void main(String[] args) {
System.out.println("For Loop Output:");
for (int i = 1; i <= 5; i++) {
System.out.println("Value of i: " + i);
}
}
}

📤 Output:

Value of i: 1
Value of i: 2
Value of i: 3
Value of i: 4
Value of i: 5

✅ (b) while Loop – Entry-Controlled Loop

The while loop only contains the condition. Initialization is done before the loop, and updating happens inside the loop. It’s useful when the number of iterations is not known beforehand.

while लूप में केवल कंडीशन दी जाती है। इनिशियलाइजेशन लूप से पहले किया जाता है और अपडेशन लूप के भीतर होता है। यह तब उपयोगी होता है जब यह पहले से न पता हो कि लूप कितनी बार चलेगा।

Java Program:

public class WhileLoopExample {
public static void main(String[] args) {
int i = 1;
System.out.println("While Loop Output:");
while (i <= 5) {
System.out.println("Value of i: " + i);
i++;
}
}
}

📤 Output:

Value of i: 1
Value of i: 2
Value of i: 3
Value of i: 4
Value of i: 5

✅ (c) do...while Loop – Exit-Controlled Loop

In do...while, the loop runs at least once regardless of the condition because the condition is checked at the end. It's best when the loop must execute at least once.

do...while लूप में लूप का ब्लॉक कम से कम एक बार जरूर चलता है क्योंकि कंडीशन अंत में चेक की जाती है। इसका उपयोग तब होता है जब आप चाहते हैं कि लूप एक बार जरूर चले।

Java Program:

public class DoWhileExample {
public static void main(String[] args) {
int i = 1;
System.out.println("Do-While Loop Output:");
do {
System.out.println("Value of i: " + i);
i++;
} while (i <= 5);
}
}

📤 Output:

Value of i: 1
Value of i: 2
Value of i: 3
Value of i: 4
Value of i: 5

📌 Conclusion

  • for loop is best when the number of iterations is known.

  • while loop is ideal when the number of iterations is unknown.

  • do...while loop guarantees at least one execution of the loop body.

  • for लूप तब उपयोगी होता है जब iterations पहले से ज्ञात हों।

  • while लूप तब उपयोगी होता है जब iterations का count पहले से न पता हो।

  • do...while लूप का उपयोग तब करें जब आप चाहते हों कि लूप कम से कम एक बार चले।

Switch Case Statement in java जावा में स्विच केस स्टेटमेंट

The switch statement in Java allows the value of an expression or variable to be compared with multiple constant values. It is a control structure that works only with integer, character, enum, or string types. Each case in a switch is associated with a constant value followed by a colon (:), and if the expression matches a case value, the corresponding block is executed. To prevent the fall-through behavior, the break; statement is used at the end of each case. A special default case (which is optional) runs when no other cases match.

The switch statement is often used as a cleaner alternative to nested if...else statements.

Java में switch स्टेटमेंट का प्रयोग एक वैरिएबल या एक्सप्रेशन की वैल्यू को कई अलग-अलग स्थायी (constant) वैल्यूज से तुलना करने के लिए किया जाता है। यह कंट्रोल स्ट्रक्चर केवल इन्टिजर, कैरेक्टर, एनम, या स्ट्रिंग एक्सप्रेशन पर कार्य करता है। प्रत्येक case के साथ एक निश्चित वैल्यू और : का उपयोग होता है। यदि कोई केस वैल्यू एक्सप्रेशन से मेल खाती है, तो उससे संबंधित कोड रन होता है। हर केस के बाद break; का उपयोग आवश्यक होता है जिससे अगले केस को रोका जा सके। यदि कोई केस मेल नहीं खाता है तो default केस (यदि मौजूद हो) रन होता है।

switch स्टेटमेंट का प्रयोग अक्सर नेस्टेड if...else के स्थान पर किया जाता है ताकि कोड ज्यादा क्लीन और पठनीय हो।


💻 Java Program Example using switch

public class SwitchExample {
    public static void main(String[] args) {
        int day = 3;

        switch (day) {
            case 1:
                System.out.println("Monday");
                break;
            case 2:
                System.out.println("Tuesday");
                break;
            case 3:
                System.out.println("Wednesday");
                break;
            case 4:
                System.out.println("Thursday");
                break;
            case 5:
                System.out.println("Friday");
                break;
            case 6:
                System.out.println("Saturday");
                break;
            case 7:
                System.out.println("Sunday");
                break;
            default:
                System.out.println("Invalid day");
        }
    }
}

✅ Output:

Wednesday

📝 Explanation:

In this program, the value of the day variable is 3, so the switch statement matches it with case 3, which prints "Wednesday". The break; ensures no other cases are executed after a match.

Control Structures in Java if, if...else, nested if...else and the ternary operator (?:) जावा में कंट्रोल स्ट्रक्चर एवं उसके प्रकार

Control structures are essential parts of Java programming that control the flow of execution. They help a program make decisions, execute specific blocks of code, or repeat instructions. Java offers several types of control structures like if, if...else, nested if...else, and the ternary operator. These tools make logic implementation easier and organized.

कंट्रोल स्ट्रक्चर जावा प्रोग्रामिंग का एक आवश्यक हिस्सा होते हैं जो प्रोग्राम की निष्पादन प्रक्रिया को नियंत्रित करते हैं। ये प्रोग्राम को निर्णय लेने, विशेष कोड ब्लॉक चलाने या निर्देशों को दोहराने में मदद करते हैं। जावा में if, if...else, nested if...else, और टर्नरी ऑपरेटर जैसे कंट्रोल स्ट्रक्चर होते हैं, जो लॉजिक को आसान और व्यवस्थित बनाते हैं।


✅ 1. if Statement

The if statement checks a condition. If the condition is true, the code inside the if block is executed.

if स्टेटमेंट एक शर्त की जांच करता है। यदि शर्त सत्य होती है, तो if ब्लॉक के अंदर का कोड निष्पादित होता है।

Example:

public class TestIf {
public static void main(String[] args) {
int age = 20;
if(age >= 18) {
System.out.println("You are eligible to vote.");
}
}
}

✅ 2. if...else Statement

The if...else statement allows the program to execute one block of code if a condition is true, and another block if it is false.

if...else स्टेटमेंट प्रोग्राम को एक कोड ब्लॉक चलाने देता है यदि शर्त सत्य हो, और दूसरा ब्लॉक यदि शर्त असत्य हो।

Example:

public class TestIfElse {
public static void main(String[] args) {
int number = 10;
if(number % 2 == 0) {
System.out.println("Even number");
} else {
System.out.println("Odd number");
}
}
}

✅ 3. Nested if...else Statement

Nested if...else statements are used when multiple conditions need to be checked. One if...else is written inside another.

जब एक से अधिक शर्तों की जांच करनी हो तो नेस्टेड if...else का उपयोग किया जाता है। इसमें एक if...else स्टेटमेंट के भीतर दूसरा if...else होता है।

Example:

public class TestNestedIf {
public static void main(String[] args) {
int marks = 85;
if(marks >= 60) {
if(marks >= 80) {
System.out.println("Distinction");
} else {
System.out.println("First Class");
}
} else {
System.out.println("Needs Improvement");
}
}
}

✅ 4. Ternary Operator (?:)

The ternary operator provides a shorthand way to write simple if...else conditions. It returns one of two values based on the condition.

टर्नरी ऑपरेटर एक संक्षिप्त तरीका है जिससे सरल if...else स्थिति को लिखा जा सकता है। यह एक शर्त के आधार पर दो में से कोई एक मान लौटाता है।

Syntax: (condition) ? value_if_true : value_if_false;

Example:

public class TestTernary {
public static void main(String[] args) {
int a = 10, b = 5;
String result = (a > b) ? "a is greater" : "b is greater";
System.out.println(result);
}
}

✅ Conclusion / निष्कर्ष

Control structures are fundamental in building logical decision-making in Java. By using if, if...else, nested conditions, and the ternary operator, developers can guide the program flow effectively. These structures not only simplify the logic but also enhance the readability and functionality of the code.

कंट्रोल स्ट्रक्चर जावा में लॉजिकल निर्णय लेने के लिए अत्यंत आवश्यक हैं। if, if...else, nested कंडीशन और टर्नरी ऑपरेटर का उपयोग करके प्रोग्राम की दिशा को प्रभावी ढंग से नियंत्रित किया जा सकता है। ये स्ट्रक्चर कोड को न केवल सरल बनाते हैं बल्कि उसकी पठनीयता और कार्यक्षमता भी बढ़ाते हैं।

Mathematical Functions in Java जावा में गणितीय क्रियाएं

In Java, mathematical functions are provided by the Math class which belongs to the java.lang package. This class includes many useful methods like min(), max(), pow(), sqrt(), abs(), sin(), cos(), and tan(), which make complex mathematical operations easier. As Math is part of the java.lang package, there is no need to import it explicitly. These methods can be directly accessed in any Java program for performing arithmetic, trigonometric, logarithmic, and rounding calculations.

जावा में गणितीय क्रियाएं करने के लिए Math क्लास प्रदान की गई है, जो java.lang पैकेज का हिस्सा है। इस क्लास में min(), max(), pow(), sqrt(), abs(), sin(), cos(), और tan() जैसे कई महत्वपूर्ण मेथड्स होते हैं, जो जटिल गणितीय संचालन को आसान बनाते हैं। चूंकि यह java.lang पैकेज में आता है, इसलिए इसे विशेष रूप से इम्पोर्ट करने की आवश्यकता नहीं होती। इन मेथड्स का प्रयोग अंकगणित, त्रिकोणमिति, लॉगरिदमिक और राउंडिंग कार्यों को करने में किया जाता है।


📊 Common Math Methods in Java — सामान्य मैथ मेथड्स

 S.No. Method Purpose (English) उद्देश्य (हिंदी)
1 pow(x, y) Returns x raised to the power y x की घात y निकालता है
2 abs(x) Returns the absolute value (positive) of x x का परिमाण (positive मान) देता है
3 min(a, b) Returns the smaller of two values दो मानों में से छोटा मान देता है
4 max(a, b) Returns the greater of two values दो मानों में से बड़ा मान देता है
5 round(x) Rounds the number to the nearest integer संख्या को निकटतम पूर्णांक में बदलता है
6 sqrt(x) Returns the square root of x x का वर्गमूल देता है
7 log(x) Returns the natural logarithm (base e) of x x का लॉगरिदम (प्राकृतिक) निकालता है
8 sin(x) Returns sine value of angle x (in radians) कोण x (रेडियन) का sine मान देता है
9 cos(x) Returns cosine value of angle x कोण x का cosine मान देता है
10 tan(x) Returns tangent value of angle x कोण x का tangent मान देता है
11 sinh(x) Returns hyperbolic sine of x x का हाइपरबोलिक sine मान देता है
12 cosh(x) Returns hyperbolic cosine of x x का हाइपरबोलिक cosine मान देता है
13 tanh(x) Returns hyperbolic tangent of x x का हाइपरबोलिक tangent मान देता है
14 toDegrees(x) Converts angle in radians to degrees रेडियन को डिग्री में बदलता है
15 toRadians(x) Converts angle in degrees to radians डिग्री को रेडियन में बदलता है

💡 Java Program Example

import java.lang.Math;

public class Test {
  public static void main(String[] args) {
    double x = 10, y = 5;

    System.out.println("Power of x and y is: " + Math.pow(x, y));
    System.out.println("Square root of y is: " + Math.sqrt(y));
    System.out.println("Maximum of x and y is: " + Math.max(x, y));
    System.out.println("Logarithm of x is: " + Math.log(x));
  }
}

Program Output (संभावित आउटपुट):

Power of x and y is: 100000.0  
Square root of y is: 2.23606797749979  
Maximum of x and y is: 10.0  
Logarithm of x is: 2.302585092994046  

Expression Statement in Java जावा में एक्सप्रेशन स्टेटमेंट

In Java, expression statements are valid expressions that end with a semicolon ;. These are used to perform operations like assigning values, calling methods, or creating objects. Java supports mainly four types of expression statements: assignment expressions, increment/decrement expressions, method calling, and object creation expressions.

जावा में, एक्सप्रेशन स्टेटमेंट ऐसे वैध एक्सप्रेशन होते हैं जो अर्धविराम ; के साथ समाप्त होते हैं। इनका उपयोग वैल्यू असाइन करने, मेथड कॉल करने या ऑब्जेक्ट बनाने जैसे कार्यों को करने के लिए किया जाता है। जावा मुख्यतः चार प्रकार के एक्सप्रेशन स्टेटमेंट को सपोर्ट करता है: असाइनमेंट एक्सप्रेशन, इन्क्रीमेंट/डीक्रीमेंट एक्सप्रेशन, मेथड कॉलिंग और ऑब्जेक्ट क्रिएशन एक्सप्रेशन।

1️⃣ Assignment Expression

Assignment expressions are used to assign values to variables. These include simple assignments as well as compound assignments like +=, -=, *=, etc.

a += 5;
b *= 7;
c = 3;

असाइनमेंट एक्सप्रेशन का उपयोग वैरिएबल्स को मान असाइन करने के लिए किया जाता है। इसमें साधारण असाइनमेंट के साथ-साथ +=, -=, *= जैसे संयुक्त असाइनमेंट भी शामिल होते हैं।


2️⃣ Increment and Decrement Expression

These expressions are used to increase or decrease the value of a variable using prefix or postfix operators.

++a;
--b;
c++;
d--;

इन एक्सप्रेशन्स का उपयोग वैरिएबल के मान को बढ़ाने या घटाने के लिए किया जाता है। इसमें प्रीफिक्स (++a, --b) और पोस्टफिक्स (c++, d--) दोनों प्रकार के ऑपरेटर आते हैं।


3️⃣ Method Calling Expression

A method call can also be an expression statement in Java, regardless of whether the method returns a value or not.

obj.factorial();

जावा में, कोई भी मेथड कॉल एक एक्सप्रेशन स्टेटमेंट हो सकता है, चाहे वह मेथड कोई मान लौटाए या नहीं।


4️⃣ Object Creation Expression

Creating an object using the new keyword is also a valid expression statement in Java.

Test t = new Test();

new कीवर्ड का उपयोग करके ऑब्जेक्ट बनाना भी जावा में एक वैध एक्सप्रेशन स्टेटमेंट होता है।


➕ Arithmetic Expression and Its Solution

Arithmetic expressions involve the use of mathematical operators like addition (+), subtraction (-), multiplication (*), division (/), and modulus (%). A single-mode arithmetic expression uses operands of the same data type, such as integer or floating-point. Let’s assume A = 10 and B = 5, and see how different arithmetic operators work.

अंकगणितीय एक्सप्रेशन में गणितीय ऑपरेटरों जैसे जोड़ (+), घटाव (-), गुणा (*), भाग (/) और शेषफल (%) का उपयोग होता है। एक सिंगल-मोड अंकगणितीय एक्सप्रेशन में सभी ऑपरेण्ड समान प्रकार के होते हैं, जैसे कि इन्टिजर या फ्लोट। मान लीजिए A = 10 और B = 5, तो देखें विभिन्न ऑपरेटर कैसे कार्य करते हैं।


🔢 Table of Arithmetic Expressions

Operator Operation Expression & Result
+            Addition              A + B = 15
- Subtraction A - B = 5
* Multiplication A * B = 50
/ Division A / B = 2
% Modulus A % B = 0


✅ Conclusion

Understanding expression statements is key to writing functional Java programs. They allow you to perform tasks like assigning values, updating variables, calling functions, or instantiating objects. Arithmetic expressions help in performing mathematical operations efficiently.

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

Thursday, July 17, 2025

JRE (Java Runtime Environment) installation process, जेआरई (जावा रनटाइम एनवायरनमेंट) इंस्टालेशन प्रक्रिया

🖥️ Java Runtime Environment (JRE) Installation Guide

जावा रनटाइम एनवायरनमेंट (JRE) कैसे इनस्टॉल करें

Java Runtime Environment (JRE) एक सॉफ्टवेयर पैकेज है जो जावा प्रोग्राम को रन कराने के लिए आवश्यक होता है। यह एक लाइब्रेरी और JVM (Java Virtual Machine) प्रदान करता है जो जावा एप्लिकेशन को आपके कंप्यूटर पर चलने योग्य बनाता है।

JRE को इंस्टॉल करने के लिए नीचे दिए गए स्टेप्स को फॉलो करें —


📥 Step-by-step Installation Process of JRE for Windows

Windows के लिए JRE इंस्टॉलेशन के चरण :

🟢 Step 1: नीचे दी गई लिंक पर जाएं और JRE डाउनलोड पेज ओपन करें –
🔗 https://www.oracle.com/java/technologies/javase-jre8-downloads.html

🟢 Step 2:
👉 अपनी Windows version (32-bit या 64-bit) के अनुसार JRE डाउनलोड करें।
👉 "Accept License Agreement" को चुनें और फिर डाउनलोड बटन पर क्लिक करें।

🟢 Step 3:
डाउनलोड की गई .exe फ़ाइल को रन करें।

🟢 Step 4:
Install Wizard खुलेगा। अब "Install" बटन पर क्लिक करें। आप चाहें तो इंस्टॉलेशन लोकेशन को बदल सकते हैं या डिफ़ॉल्ट छोड़ सकते हैं।

🟢 Step 5:
इंस्टॉलेशन कुछ मिनटों में पूरा हो जाएगा। “Finish” बटन पर क्लिक करें।

🟢 Step 6 (Optional):
अब आप अपने सिस्टम पर किसी भी .jar या Java आधारित एप्लिकेशन को रन कर सकते हैं। Command Prompt में टाइप करें:

java -version

यह जांचने के लिए कि JRE ठीक से इंस्टॉल हुआ है।


🛠️ फर्क क्या है JDK और JRE में?

  • JDK: Java Developer Kit – डेवलपर के लिए, कोड लिखने, रन और डिबग करने हेतु।

  • JRE: Java Runtime Environment – केवल कोड रन करने हेतु, डेवलपमेंट के लिए नहीं।

📚 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...