• We Code
  • We Design
  • We Develope
  • We Write
  • We Share

menu

Sunday, August 26, 2012

switch and for statement

0 comments
This post of java learning course is focused on java switch statement  and java for statement.
The java course  syntex for java  switch statement and java for  statement is listed below.

Switch Statement

Switch statement helps us to select/choose out of many choices.

switch (expression)
 {
  
   case var1:statement1;
            :break;
   case var2:statement2;
            :break;
   case var3:statement3;
            :break;
   case var4:statement4;
            :break;
   case var5:statement5;
            :break;
   case var6:statement6;
            :break;
   case var7:statement7;
            :break;
   case var8:statement8;
            :break;
   default:  statement9;
}


For loop

This is a self contained looping statement that contain initialisation/initial value,termination condition & increment/decrement

for(var declaration-cum initialization;condition;increment/decrement)
  {
   some codes
  }

Read more ►

Branching in JAVA or Control statements in JAVA

0 comments

Control statements are used to make branching (if,if-else,if-else-if etc) ,looping(for,while,do-while),skiping(switch) and exiting block of code(countinue,break)



  1. if counditions
  2. if()
  3. if(),else
  4. if(),else if(),else



if()  tells whether the condition is satisfied or not ,if condition satisfies the following block of if() code (also called as if() condition body )  will execute.



if(coundition)

 {
   do something
  }

if(),else


this statement helps to select one possible block of code out of two conditions.


if(coundition)

 {
   do something
  }
else
{
  do something else
}

if(),else if(),else

                 This statement helps to select one possible block of code out of three conditions.


if(condition)

 {
   do something
  }
else  if(another condition)
 {
   do something else
  }
else
{
  do something else
}

Nasted if conditions


In this we will write conditon under an another condition .


if(condition 1)

{
    if(coundition 2)
      {
         
        if(condition 3)
          {
            do something
           }
          
        else (condition 4)   
           {
             do something
            }
     
     else (condition 5)
      {          
         do something
       }

else(condition 6)

  {
    do something
 }
      

Read more ►

Thursday, August 23, 2012

Relational Operators in JAVA

2 comments
Relational operators in JAVA are the binary operator, as we know know binary operator take two parameter .For comparing values of variables ad literals Java provided relational operators. Relational operators relate a given value with several possible values of a variable . The result of the relational operators help to make branching iterating a block and to terminate the block statement

Relational operator returns boolean i.e true or false





==            equal to

!=             not equal to
>               greater than
>=            greater than equal to
<              less  than
<=            less than equal to




for instance/example




int a = 25;

int b=75;
double x=35.87;
double x=85.87;
char c1='b';
char c2='c';
..............................................
a=b    false
a!=b   true
a<b    true
x>y    false
c1==c2  false
35==10 false
...............................................

Example :

class RelationalOperatorDemo{
    public static void main(String[] args){
        int firstVar = 2;
        int secondVar= 9;
        if(firstVar == secondVar)
            System.out.println("firstVar == secondVar");
        if(firstVar != secondVar)
            System.out.println("firstVar != secondVar");
        if(firstVar > secondVar)
            System.out.println("firstVar > secondVar");
        if(firstVar < secondVar)
            System.out.println("firstVar < secondVar");
        if(firstVar <= secondVar)
            System.out.println("firstVar <= secondVar");
    }
}

The Output will be 

firstVar != secondVar
firstVar <  secondVar
firstVar <= secondVar
Read more ►

Sunday, August 19, 2012

Bitwise Operators In Java

0 comments
Bitwise operators are used to manipulate individual bits of a data item. There are situations where individual bits of data are modified.

These operators operate only on byte,short ,int and long types 





      OPERATOR                                    DISCRIPTION  




  1.        ~                        ::             Bitwise NOT                         
  1.        &                        ::             Bitwise AND                         
  1.         |                        ::             Bitwise OR                           
  1.         ^                       ::             Bitwise exclusive OR           
  1.        <<                      ::             Left shift                                 
  1.        >>                      ::             Right shift                               
  1.        >>>                    ::             Right shift zero fill                
  • & operator  Bitwise  AND operator  compares each bit of first operand with each bit of second operand.For instance 71 binary number is 01000111 and 25 binary number is 00011001. If both the bits are 1 and 1 the result is 1 if any one of the bit is 0 the result is 0
  • | operator     Bitwise  AND operator  compares each bit of first operand with each bit of second operand. If both the bits are 1 and 1 the result is 1 ,even if any one of the operand is 1 the result is 1 and only if both of the bit is 0 the result is 0
  • ^ operator       Bitwise exclusive or operator  compares each bit of first operand with each bit of second operand. If both  the operand are 0 and 1 the result is 0 and only if any one of the bit is 0 and other is 1 the result is 0
  • ~ Operator     Bitwise NOT operator is a unary operator . This oprator is used only on a single operand.
  • << Operator  The  left shift operator is used to shift the bits of a given operand  to left for specified number of position
  • >> Operator  The  right shift operator is used to shift the bits of a given operand  to right for specified number of position
  • >>> Operator  The  right shift operator is used to shift the bits of a given operand  to right for specified number of position.The  difference in >> and >>>  is the sign bit extension is not done .Instead of 1s filled at leftmost bit is -ve integer values,0's  are filled





public class BitwiseOpertorDemo{
public static void main(String args[]) {
int firstVar = 60; /* 60 = 0011 1100 */
int secondVar = 13; /* 13 = 0000 1101 */
int ThirdVar = 0;
ThirdVar = firstVar & secondVar ; /* 12 = 0000 1100 */
System.out.println("firstVar & secondVar = " + ThirdVar );
ThirdVar = firstVar | secondVar ; /* 61 = 0011 1101 */
System.out.println("firstVar | secondVar = " + ThirdVar );
ThirdVar = firstVar ^ secondVar ; /* 49 = 0011 0001 */
System.out.println("firstVar ^ secondVar = " + ThirdVar );
ThirdVar = ~firstVar ; /*-61 = 1100 0011 */
System.out.println("~firstVar = " + ThirdVar );
ThirdVar = firstVar << 2; /* 240 = 1111 0000 */
System.out.println("firstVar << 2 = " + ThirdVar );
ThirdVar = firstVar >> 2; /* 215 = 1111 */
System.out.println("firstVar >> 2 = " + ThirdVar );
ThirdVar = firstVar >>> 2; /* 215 = 0000 1111 */
System.out.println("firstVar >>> 2 = " + ThirdVar );
}
}
Read more ►

Wednesday, August 15, 2012

Increment And Decrement Operator in Java

1 comments
There are two arithmetic  operator ++ and -- . Both are unary operators and operate only on integers . The ++ is called increment operator and -- is called decrement operator 


  1. The ++ operator  in prefix increments operand first  and the uses operand  next
  2. The ++ operator in suffix/postfix uses operand first and then increments operand 
  3. The -- operator  in prefix decrements operand first and  the uses the operand next
  4. The -- operator in suffix/postfix uses operand first and then decrements operand

Eample of the Increment And Decrement  Operator :


//PrefixPostfixTest.java


public class  PrefixPostfixTest
{
  public static void main (String args[]) throws Exception
{
int i=45,j=35;
System.out.println("i is "+i);
System.out.println("++i is "+(++i));
System.out.println("j is "+j);

 
System.out.println("j++ is "+(j++));
System.out.println("--i is "+(--i));
System.out.println("j is "+j);
System.out.println("j-- is "+(j--));
}
}


commands for compiling and running the program 

For compilation ------ javac prefixpostfixtext.java
For Execution--------- java   prefixpostfixtext
Read more ►

Tuesday, August 14, 2012

operator assignment in Java

0 comments
All five operators can be used in operator assignment .This helps to avoid repeating operators in two places of a statement

      //OperatorAssignmentTest.java

               public class OperatorAssignmentTest.java


                 
                           

                  {
                 public static void main(String args[] )throws Exception
                   {  
                             int i=10;
                             i=i+1;
                     System.out.println.("i initail  value is 10 ,i+1 is" +i);
                             int j=10;
                             j+=1;
                     System.out.println.("j initail  value is 10 ,j+1 is" +j);
                     }
                 }

Read more ►

Sunday, August 12, 2012

AIRTHMETIC OPERATORS in JAVA

0 comments
In java these are the following arithmetic operators



operator             description

.........................................................
+                         addition
-                          subtract
*                         multiplication
/                          division
%                       modulus/reminder
.............................................................


arithmetic operators in java takes two operand and perform arithmetic operation like addition subtraction .

//airthmeticoperatortest.java



public class ArithmeticOperatorTest

{
  public static void main ( String args[]) throws exception
{
int=10,j=20;
int k=30;
System.out.println("i+j ="+k);
int l=i-j;
system.out.println("i-j="+l);
int m=i*j;
System.out.println("i*j="+m);
}
}



Read more ►