You are on page 1of 6

1.

How to write the main function

2. Datatypes

                byte,short,char,int,long, float,double, boolean

3. Literals

                Integer literals

                int x = 0b0110_0010;

                System.out.println(x);

                int cardno = 1_2;

                System.out.println(cardno);

                literal cannot start / end with _

                _12;       //invalid

                12_;       //invalid

                12_32;   //valid

                12343_3;// valid

                Float Literals

                12.5;     

                1_2.5;    //valid

                12_.4;    //invalid


                12.4_5; //valid

                Character Literal

                'a'

                "String Literal"

Assignment Operators

                big = small;          //valid

                small = big;          //not valid

Arithmetic Operators

                % can be applied to float / double

                ++ ,--

                int x = 5;

                int y = 0;

                y = ++x + ++x;

                                6 + 7

                x = 5;

                y = x * x + ++x   (31)

                x = 5;

                y = x + x + x * ++x            40
 

Relational Operators

                > ,>= , < , <= , == , !=

                result of relational operation is boolean

C Question

struct Student

                int regno;

};            

int main()

                int x = 5;

                struct Student   s1 = {5};

                if(x)                        x != 0

                {

                }

                if(s1)                      s1 != 0

                {

                }
}             

----------------------------

Logical Operators

                && , || , !

                int x = 5 , y = 5;

                if(++x > 10 && ++y > 10)

                {}

                S.o.p(x);

                S.o.p(y);

                6 > 10 -> F (Skip ++y > 10)

                if(++x > 5 && ++y > 10) 

                6 > 5 -> T (Evaluate ++y > 10)

                & -> Evaluate both conditions

-------------

                boolean & boolean         : Logical AND

                int & int                                : Bitwise AND

------------
                &, | , ^, ~ , >> , << , >>>

                int x = 0b01011010

                int y = 0b01101101

                int a = x & y;

                S.o.p(a);

                byte       x = 0x

------------------------------------------

String brcode = "ME";      

      switch(brcode)

      {

      case "CS" : System.out.println("Computer Science");

                      break;

      case "EC" : System.out.println("Electronics Science");

                      break;

      case "ME" : System.out.println("Mechanical Science");

                      break;            

      }

     

      int x = 5;

      final int a = 2;

      switch(x)
      {

      case 1 :System.out.println("Computer Science");

                      break;

      case a : System.out.println("Electronics Science");

                      break;

      case 3 : System.out.println("Mechanical Science");

                      break;

      }

                case constant : Constant can be of string, final variable.

                                                Other things similar to C

                const and goto are keywords; no action is associated with these keywords.

You might also like