24 Jan 2017

What is if-else condition statement in java..?

Hello guys guys today i will tell about the if -else condition statements

now as you know that the meaning of if in hindi (เค…เค—เคฐ ) so it works on Boolean expression under if brackets if the condition is true then the statements are execute under the curly braces other wise if the condition is false else part is execute ..

now lets study the syntax of if-else condition:


if(boolean-expression)      //if the condition is true 

//executes the statements under the braces
{statements}

//if the condition is false the else part is execute
else
{statements}


Lets take an example of if-else condition part:

class remote
{public static void main(String a[])
{int a=2;

if(a==2)   //if the condition is true
{System.out.println("You entered 2");}

//if the condition is false it execute else part
else {System.out.println("You did not entered 2");}
}}

if you execute the following program then the condition will be true because the value of variable a is 2 as in the condition if you change the value it execute the else part


click to  know deep about the for loop...
















Simple Switch Example

Lets take an example of switch statement without break; :


class Week
{
      public static void main(String a[])
     {
           int day=2;
           switch(day)
           {
               case 1: System.out.println("Monday");
               case 2: System.out.println("Tuesday");
               case 3: System.out.println("Wednesday");
               case 4: System.out.println("Thursday");
               case 5: System.out.println("Friday");
               case 6: System.out.println("Saturday");
               case 7: System.out.println("Sunday");
           }
    }
}


If you execute this program the output is starting from case 2 Tuesday  and end with Sunday
 YOU know i had share you an example of ball and stairs that if you throw a ball to stairs then it falls back to you to you with each steps if their is no blocks like breaks . So tie break statements with each case condition. and then execute this program


this example is with break;

class Week
{
      public static void main(String a[])
     {
           int day=2;
           switch(day)
           {
               case 1: System.out.println("Monday");break;
               case 2: System.out.println("Tuesday");break;
               case 3: System.out.println("Wednesday");break;
               case 4: System.out.println("Thursday");break;
               case 5: System.out.println("Friday");break;
               case 6: System.out.println("Saturday");break;
               case 7: System.out.println("Sunday");
           }
    }
}

execute it and then see the difference.


Follow me to  more learn basics with examples..๐Ÿ˜„๐Ÿ˜„๐Ÿ˜„๐Ÿ˜„๐Ÿ˜„๐Ÿ˜„




Basic Rules applied on Switch statements !!

First of all keep it in mind that java is securest language and inspired by real life .So first , lets imagine your childhood as you play with your self, as throwing a ball against stairs and it will have been come back step by step .....๐Ÿ™‚๐Ÿ™‚


  • The first rule that you keep it in mind is that every switch statements variable must be Integer, convertible Integers(byte,char,short) .

  • The break statement is used with end of case statement .If you don't use the break statement then the sub case value is execute after the true case value .

  • Default statement is must be tie in the body of switch.It is like else part if the no. of case value is not true then the default statement is executed.

Lets take an example of switch statements : Switch_Examples 



What is Switch Statement in java....?

Switch statement is the another part of condition type statements other than if-else condition statements.In technical language  "A Switch statement allows a variable to be tested for equality against a list of values.  "

The syntax of Switch statements looks like that:


switch(expression)
{
case value: //statements
//another value

case value: //statements

default: //optional statements like else part
}

Click on the  link to know about the: Rules applied on switch statements ๐ŸŒ๐ŸŒ๐ŸŒ

16 Jan 2017

How to handle Airhtmetic Exception divide by zero..??

Hello friends today i will show you how to handle Arithmetic Exception using try and catch block:


First of all , i will write a  program with Arithmetic Exception error :]
in this example i will assign three variable a, b and c. We divide a with b (0) , the int data type used to store the values .

class remote
{
    public static void main(String s [])
    {
        int a=10, b=0, c;
        c=a/b;

        System.out.println(c);
        c=a+b;

        System.out.print(c);
    }
}


 if you compile this program you cannot get any error but if you execute this program you will see the error:
     
         Exception in thread "main" java.lang.ArithmeticException: / by zero
        at remote.main(remote.java:6)



to handle this exception you need to use try catch block :
 


class remote
{
    public static void main(String s [])
    {
        int a=10, b=0, c;
        try
        {
           c=a/b;
            System.out.print(c);
        }
        catch(ArithmeticException m)
        {
       
        System.out.println("You cannot divide "+a+" by "+b);

        }
       
        c=a+b;

        System.out.print(c);
    }
}
you have solved the exception error . Now you think why you we use the exception handling case because of stop statement if we get any exception in any line , so we use this 

.

If you have any problem in this program you can comment on this blog and thank you for reading this blog...๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ



















13 Jan 2017

What is Tampering and Impersonation...??

This is another problem after Eavesdropping. Tampering is the modifying  someone's message illegally after reading it. I mean to say that in Tampering not only reads the data but also modifying it is called Tampering. Encryption and Decryption is the one and only solution for stops all the illegal working on the Internet.


The third problem is Impersonation means a person hides their original identity and act as somebody else to make transactions and other things like misusing of confidential information. This is due to a person disguising(เคฐूเคช เคฌเคฆเคฒเคจा ) himself as another person on Internet is called Impersonation.

What is Eavesdropping

Eavesdropping means reading others message illegally  on Internet. For example , reading others email message is turn into this category. But there is Solution also, the encryption and decryption method is the way to protect the message from  unauthorized people .

In this method the message is converted to unreadable form from readable form.Converting the data into unreadable format is called Encryption, and getting back to original format is called Decryption.

While Encryption the data we use a key or password to secure and only known person can decrypt  it by using that key and the third person cannot open this email or message without key.Encryption and Decryption is done by Java technology.