• 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 ►

Thursday, August 9, 2012

OPERATORS

0 comments
The next step of java learning course is operator . We will see operator now

Operator are some  reserved  character such as + , - , * , / ,% etc .


Operators operate on single operands or multiple operands to perform some operations.


operator which performs operation on a single operand is called as unary operator.


Operator which performs operation on two operands is called binary operator.



Operator which performs operation on three operands is called ternary operator.

operator are classified into 4 types

 1  airthmetic operator 
 2  biwise operator 
 3  relational operator 
 4  logical operator 

Read more ►

Understanding First Java program

2 comments
It is the time to move in programming now .After learning the feature of java the next step of java learning is to understand the art of program writing.Here we will go with the simple program and will see how to write a simple program.


================================================================
||       public class hello                                                                                                         ||
||        {                                                                                                                                   ||
||       public static void main{String args[] }throws Exception                                            ||
||       {                                                                                                                                    ||
||      System.out.println("hello this is my first java program");                                         ||
||       }                                                                                                                                    ||
||                                                                                                                                             ||
================================================================
System is in class java.lang package which comes with jdk by default hence we need not have to include  import statement

In System class "out" is a staticvariable for print stream class

in print writer class print() and println() methods are given that they can print any type data type valueit may be an byte short word int long float double char etc.

====================================================================

To compile the above program
javac hello.java

To run the above program
java hello
Read more ►

interpreted

0 comments
                               INTERPRETED


The Java is an interpreted language as well. With an interpreted language 
like Java, programs run directly from the source code. 

The interpreter program reads the source code and translates it on the fly 
into computations. Thus,the  Java is language  is interpreted language depends
 on an interpreter program.
The versatility of being platform independent makes Java to different and 
attractive  from other languages. The java program  source code to be written 
and distributed is platform independent. 
Another main advantage of Java language as an interpreted language is its error
 debugging quality. Due to this quality any error  in the program gets traced and 
shortout.
Read more ►

dynamic and secure

0 comments
                      Dynamic
While  the execution of  java program the user can get the  files dynamically from 
a local drive of  system or from a system many miles away from the user just by 
connecting with the Internet.
                        

                         Secure
Java language strictly does not use memory pointers explicitly. Java programs  run 
under an area called the sand box. Security manager determines the accessibility 
options of a class like reading and writing a file to the local  disk.   Java 
technology uses the public key encryption system to allow the java applications to
 transmit over the internet in the secure encrypted form. The bytecode Verifier is 
responsible for the check of classes after loading. 

Read more ►

Wednesday, August 8, 2012

robustness in java

0 comments
                                           ROBUST
Java has the very strong memory allocation and  the automatic garbage collection mechanism. It provides the very powerful exception handling and typechecking mechanism as compare to other programming languages like c and c++. Compiler checks the program for  the  error and interpreter checks the run time error and makes the computer system secure from damage. Due to these all of the above features the java language is robust.
Read more ►