Variables in Programming: A Beginner's complete Guide🌟

Hi friends,Welcome to Java with Suba!💙
Here learn about the Variables in programming with simple example in beginner friendly way!



VARIABLES🌠

        1️⃣ Definition:
                     ⁜Variable is the labeled storage box inside a computer memory.
                     ⁜ It is used to store values/data.
                     ⁜It is defined as an alphabet which is used to store a value.
                     ⁜The alphabet must in lowercase,because uppercase is called constant.So,we use lowercase.
                     ⁜It cannot start with a number.


      2️⃣ Rules:
                ⁂Each and every variable must be start with alphabet (lowercase).
                            Syntax:
                                        Variable name=Value;
                            Example:
                                       a=100;// a->variable,100->integer value.
                                       s=11;//s->variable,11->integer value.
                                       a2=123;//a2->variable,123->integer value.
                                       3a=56;//Invalid declaration.(because it start with number.as per rule variable must start with alphabets).

                                                       ✨ c=a+b;(logic)✨
                                                           variables:c,a,b
                                                           value:a=11,b=5(we assign it)

                           ⁂Each and every variable must be separated by commas(,).
                                       varname1,varname2,.....varnamen;
                                        a,b,c;->Valid declaration.

                           ⁂ No white and blank space are allowed.
                                        Example:
                                               a b c->invalid declaration.
                                               (Reason:white space appears)

                          ⁂Underscore(_) and dollar($) symbol are the two special characters to be allowed in java during the variable declaration.

                                           ( _,$ )->only allowed in java.
                                       Example:

                                         (Valid)🌟
                                                a="hansi";->valid
                                               _a=27;->valid
                                               a_b=43;->valid
                                               $b=128;->valid
                                               $total_price=100;->valid
                                          (Invalid)🌟
                                               1st_name="guru";->invalid (it start with number).
                                                my-age=20;->invalid (do not use any special characters except ( _,$ ).
                                                total amount=30;->invalid (no white space allowed).

📌[These special characters( _ ,$ ) are used at front,back,and middle of the variable.]
📝(Note:Other Programming Languages may use different symbols for example,python only allows underscore( _ )).

                          ⁂At the end of the variable declaration or a statement must be end with semicolon (;).
                             a,b,c;->valid
                             x,y,z->error statement (;) missing.


       3️⃣ Syntax:

                    In Java,you can declare variables in two ways depending on your needs:
                    1.Single Variable Declaration:
                                         Use this when you want to create a single variable and assign a value to it.

                                               datatype variablename = value;

                                            Example:
                                               int age = 20;
                                               string name = "Hansi";

                           2.Syntax for Multiple Variable Declaration:
                                          Use this when you want to declare multiple variables of the same data type in a single line.

                                              datatype varname1,varname2,.........varnamen;

                                             Example:
                                                  int a,b,c;


                                                              Happy Learning!
                                                        Thanks for Reading!💙



                  
                                        
                                                 


 

Comments

  1. Thankyou For Sharing The Details And With Correct Explanation In The Blogger

    ReplyDelete

Post a Comment

Popular posts from this blog

A Beginner's Guide to Code Logic and Structure📝✨

Introduction to Java☕: Beginner's Complete Guide in Tanglish Version💻✨

Introduction to Java ☕: A Complete Beginner's Guide in English Version💻✨