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 Variable

Java Syntax

Java Variables






हेलो दोस्तों तो आज हम Java वेरिएबल के बारे में जानेंगे तो चलिए सुरु करते है

अगर आपने पहले कोई और Programming Language पड़ी है तो आप वेरिएबल के बारे में जानते होंगे और जो student Java Language से start कर रहे है तो उनके लिए ये नया है तो चलिए जानते है ये Variable क्या है।

Java द्वारा किसी भी information को store करने के लिए आप variables का use करते है। Variables memory location का एक नाम है।

वेरिएबल एक स्टोरेज एरिया होता है जिसका प्रयोग डेटा को स्टोर करने के लिए किया जाता है. variable डेटा को contain किये रहता है

How to Declaring Variables

Java Variables को Declaring (Creating) करने के लिए सबसे पहले आपको Datatype Define करना होगा.
Java मै जब हम कोई Variable बनाते है तो पहले हमे बताना होता है की हम कोनसी Value store करना चाहते है जैसे कोई Strinng या Number तो Variables के पहले हमें ये keyword Define करना होता है फिर (=) का sign Use करते हुए
आप Variable का Name लिखते है तो Java में ऐसे Create किया जाता है।


Example

  
  
  

    String name = "Education point";
    
    System.out.println(name);


  


output



  
  
  
  
       Education point
  



  
Education point

और अगर आपको Number Store करना चाहते है तो आपको int Datatype define करना होगा और उसकी Value को Singal quote या dubble quote लगाने की जरुरत नहीं है।



Example

  
  
  

    int age = 21;
    System.out.println(age);



  


Output
  
  
  

    21
    



  


Override or Reassign variable value


अगर आपको किसी variable की value को दुबारा change करनी है तो आप उस variable का नाम लिख कर (=) का sign लगा कर नई Value दे सकते है पर याद रहे जिस Vareiable की Value आप Reassign कर रहे हो तो पुरानी वाली Value Override या आसान भाषा में बोलू तो Delete हो जाएगी चलो Example की मदत समझतें है.
वैसे अगर आपको dataype और keywords क्या है समझ नहीं आ रहा तो tenstion मत लीजिये जल्दी ही new lession में इन दोनों को डिटेल में पड़ेंगे

  
  
  
      //old value

    int age = 21; 
    System.out.println("This is old value");
    System.out.println(age);



   //new value
   int age = 18;
   System.out.println("This is New value");
   System.out.println(age);




  


output

  
  
    This is old value

    21
    
    This is New value
    
    18


  


Final Variables

दोस्तों Final variable वो variable होते है जिसे एक बार define करने के बाद दुबारा नहीं कर सकते यहाँ final एक Keyword है जिसे हम variable के पहले define करते है

Example:
  
  
  
    final int age = 21;
    myNum = 18;  // will generate an error: cannot assign a value to a final variable



  


उदाहरण के लिए माना कि हमें किसी छात्र का नाम तथा उसका रोल नंबर वेरिएबल में स्टोर करना है. इसके लिए हम दो variables लेते है एक वेरिएबल में छात्र का नाम स्टोर करते है जबकि दुसरे वेरिएबल में रोल नंबर स्टोर करते है.

Types of Variables

जावा में तीन प्रकार के variables हैं:



  1. Local variable
  2. Instance Variable
  3. Static variable





1. Local Variable in Java


Method के body के अंदर घोषित एक variable को local variable कहा जाता है। आप इस variable का उपयोग केवल उस method के भीतर कर सकते हैं और class में अन्य methods को भी पता नहीं है कि variable मौजूद है।

एक local variable को “static” keyword के साथ परिभाषित नहीं किया जा सकता है।



2. Instance variable



Class के अंदर घोषित एक variable लेकिन method के body के बाहर, instance variable कहलाता है। इसे static घोषित नहीं किया गया है।

इसे instance variable कहा जाता है क्योंकि इसकी value, instance specific है और instances के बीच साझा नहीं की जाती है।



3. Static variable

एक variable जिसे static घोषित किया जाता है उसे static variable कहा जाता है। यह local नहीं हो सकता।
आप static variable की एक प्रति बना सकते हैं और class के सभी instances में साझा कर सकते हैं। static variable के लिए मेमोरी
आवंटन (allocation) केवल एक बार होता है जब class को मेमोरी में load किया जाता है।



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