Variables In Java In Hindi

📔 : Java 🔗

variable किसी memory को दिया गया नाम है जो कि किसी value को Hold करती है या store करती है। मतलब जब हम Variable define कर रहें है तो हम memory में value को store करके उसे नाम दे रहे होते हैं। इसलिए variables को named storage भी कहते हैं।

Image could not load

Variables

Java define a variable

Java में variables PHP , Python , JavaScript से थोड़ा different तरीके से define किया जाता है। Java में variables को उनके data types के साथ define किया जाता है , मतलब आपको initialize करते समय यह बताना पड़ता है , कि variables किस type की value store करेगा। Java में variables को उनके data types के साथ define किया जाता है , जैसा कि आप example में देख सकते हैं।

class Variables {
public static void main(String[] args) { // define integer variable. int age = 25; // defien string variable. String name = "Rahul Kumar"; System.out.println("Name : "+ name); System.out.println("Age : "+ age); } }

तो कुछ इस तरह से Java में variables को define किया जाता है। हालाँकि data types और भी कई तरह के होते हैं जिन्हे आप आगे detail में पढ़ेंगे।

normally define किये गए सभी variables की value को अपनी need के according change / update कर सकते हैं।

int age=90;age = 65;//you can change variable value any timeage = 89;

Java में variables case sensitive होते हैं , मतलब same name के साथ lower और upper case में define किये गए variables अलग होंगे।
See Example -

class Variables {
public static void main(String[] args) { String name = "variable : name"; // now define same vairable with different case. String Name = "variable : Name"; System.out.println(name); System.out.println(Name); } }

Java declare multiple variables

आप same data type के variables को अलग अलग initialize करने के बजाय उन्हें एक साथ भी define कर सकते हैं।

class Variables
{ public static void main(String[] args) { // you can define multiple variables like this. int x = 51, y = 16, z = 50; System.out.println(x + y + z); } }

Java One Value to Multiple Variables

आप equals = operator का use करके किसी value को same type के variable में भी assign कर सकते हैं।

class Variables {
public static void main(String[] args) { // define multiple variables. int x, y, z; // assign same value to all variables. x = y = z = 10; System.out.println(x + y + z); } }
Important about variable

1. आप same variable को एक से ज्यादा बार define नहीं कर सकते हैं -

2. हालाँकि यह , ध्यान रहे कि data type के according ही variable में value store होनी चाहिए , ऐसा नहीं हो सकता है कि int variable में string value assign करें। और char type के variable में boolean . हालाँकि ऐसा करने पर syntax error मिलेगी, या हो सकता है कि variable में assign की value proper नहीं मिलेगी।

Java Rules to define variables

  1. variable name सिर्फ letters, digits, underscores, और dollar signs के साथ define कर सकते हैं।

  2. variable name किसी letter से ही start होना चाहिए।

  3. variable name को हमेशा lowercase letter से start करना चाहिए और white space नहीं होने चाहिए।

  4. जैसा कि आपने ऊपर example देखा कि variable name case sensitive होते हैं , तो इस बात का ध्यान रखें।

  5. Java language में define कोई भी reserved keyword (int or boolean) , variable name नहीं हो सकते हैं।

Java Types Of Variables

हालाँकि variables के types भी कई तरह से होते हैं।

  1. int : integers store करता है (whole numbers), decimals के बिना, जैसे 123 या -123।

  2. float : floating-point numbers store करता है, decimals के साथ, जैसे कि 19.99 or -19.99।

  3. char : single characters store करता है, जैसे 'A' or 'B'। Char values single quotes से घिरे होते हैं।

  4. string : text store करता है, जैसे "Hello World"। String values double-quotes से घिरे हैं।

  5. boolean : दो states के साथ value को store करता है: true or false।

I Hope, अब आपको Java में variables के बारे में अच्छे से समझ आ गया होगा।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers