language basics and Operators


Language Basics
I. Keywords: ---
These are the predefined words in the library.which consists of special meaning in programming.
In java we have 50 Keywords +10 reserved words  are there.
Ex: ---
if,else,case,switch,break,volatile,class,interface…etc.
II .Identifiers:------
 To Identify Specific  memory Blocks ..
Rules:
  1. Should Start With An Alphabet.
  2. No Spaces.
  3. Use----Underscore
III.Data Types: ---
DataType
Size
Range
byte
8bits
-12 8 To +127
char
16bits
-32768 to 32767
short
16bits
-32768 to 32767
int
32bit
-2147483648 to 2147483647
long
64bit
-9223372036854775808L to9223372036854775807L
float
32bit
1.4x10-34 to3.4x10+34 to
double
64bit
4.9E-324 to 1.7E+308
boolean

true Or false

IV: Variable:
 Storage Location
Syntax:
 <Datatype>  <Identifier/variablename>;
  Ex:  int a;  float F1=7.3f;
//If we don’t Mention F Then by Default It Takes as Double.
double abc=7.3;
Variables:----
         C &C++
            Java
1.Global(Can Access Anywhere)
1.Classlevel(Can Access Anywhere) or instance or reference variables
2.Local
2.Methodlevel variables

class FirstExample
 {
   public static void main(String [] args)
    {
      int x=10;
   System.out.println(x);
}
}

Operators:
 1. Arithmetic operator:
       +  -   /   *  %(modulus)
class ArithmaticOpDemo{
      public static void main(String[] args) {
                  int a=10,b=20,c;
                  c=a+b;
                  System.out.println ("the sum is :"+c);
                  System.out.println ("the mul is :"+(a*b));
                  System.out.println ("the div is :"+(a/b));
                  System.out.println ("the remainder is :"+(a%b));
      }
}
2. Increment/Decrement Operator:  
           ++     --
 They are classified into
       ++                                                                    --
Preincriment: ++a                                       Predecrement: --a                   
Postincrement:a++                                      Postdecremenet:a—

3.Compound Assignment Operator:
                ++        -=       /=   *=     %=
    class CompoundOpDemo {
      public static void main(String[] args) {
                  int x=30;
                  x+=4;
                  System.out.println("+=4:"+x);
                  int y=5;
                  y*=3;
                  System.out.println("*=3:"+y);
                  int d=50;
                  d/=5;
                  System.out.println("after div:"+d);
                  int f=40;
                  System.out.println("remainder:"+(f%=4));
      }  
}
4. Relational Operator:           
              >   >=    <     <=     ==     !=(not equal)
        When you are relational operators we will get a Boolean type of result  i.e “True/false”
      
         Class RelOpDemo {
          public static void main(String[] args) {
              int a=30,b=20;
             System.out.println (a+">"+b+":"+(a>b));
             System.out.println (a+">="+b+":"+(a>=b));
         }
       }
5. Logical Operator: 
        &&          ||         !
       (and)       (or)    (not)
class LogicalOpDemo {
      public static void main(String[] args) {
                  int a=3,b=2,c=1;
                  System.out.println((a>b)&&(a>c));
                  System.out.println((a<b)&&(a>c));
        System.out.println((a>b)||(a>c));
      }
      }

6.Bitwise Operator:(Deprecated)     
      
          &   |    ^(XOR)    >>     <<   

7. Conditional Operator:
                        ?:
     Syntax: 
               (Condition)? True part : False part
     class ConditinalOpDemo {
      public static void main(String[] args){
                  int p=20,q=30,r;
                  r=(p>q)?p:q;
                  System.out.println(r);
      }
      }

No comments:

Post a Comment