Skip to main content

Posts

Showing posts from December, 2012

Rules for saving a program

PART -1 Click here to watch this on YouTube PART -2 Click here to watch this on YouTube

Working with multiple classes

Click here to watch this in YouTube

Inheritance in java

Inheritance is the process of object of one class having the properties of objects of another class. The class which shows the properties of another class is called the child class or the sub class and the class from which the child class inherits is called the parent class or super class . Inheritance is one of the most important object oriented concept in java. By using inheritance we can combine functionalities of many classes together. By following inheritance it is easy to add more functionality to an existing java application.  For further clarification consider the following example. In the figure given above, you can see that the birds are classified into two categories  one is flying and another is non-flying. The flying and non flying birds have their on different behaviors but yet they are came under the common family birds. From this example you can see that the flying birds and non flying birds are inherits some common behaviors from the birds category. So we can

for each loop

The enhanced (extended) for loop in java is called  the for each loop . It is useful for iterating an array. Syntax: for (type var : array) { statements; } Example: for (String value : args) { System.out.println(value); } Working of loop: The loop function body contains only one statement " type var : array" . The loop iterates till the array contains elements. At each iteration of the loop the array traversed to each of its index such as args[0], args[1],args[2]......etc. Note that here we use the colon operator (:)  not the assignment operator (=). If there is no further elements in the array for iteration then the loop exit from further execution. Consider the following example to know more about the for each loop in java.    class ForEachDemo { public static void main(String args[]) { for(String value : args) { System.out.print(value); System.out.print("\t"); } } } Output:

do while

The do while loop is same as a while loop except that here the Boolean condition checks after the execution of the loop body, because of this the do while loop is an exit control loop . Syntax: do {  loop body; }while(condition); Example:   class DoWhileDemo { public static void main(String args[]) { do { System.out.println("I execute once even the condition is false"); }while(false); } } output: In the example you can see that the loop body executes once even if the condition is a false one at the beginning of the loop.      

for loop

Syntax:   for(initialisation; condition; updating)  {   statements;  } Execution flow of a for loop is given bellow. step 1 : Perform the initialisation step 2 : Check the condition, if condition is false then exit the loop, otherwise continue step 3 : Execute the loop body step 4 : Perform the updating and go to step 2. You can see that the initialization perform only once for the loop. The loop cycles through the condition, loop body and the updation till the condition become  a false one. Condition is always a boolean one. The loop componenets are seperates by semicoloun (;) not by commas (,) Example:   for (int i = 0; i< 5; i++)  {  System.out.println(" Greetings from easy way 2 in ");  } It is possible to use multiple initialization and updation in a for loop, but seperates them with  commas. If multiple condition is used then connects them with any of the logical operators (AND, OR, NOT....)The following is also a valid for loop   for(int i=1,j=0; i<=5;

while loop

Syntax: while(condition) { statements; } It is also same as a for loop. The loop body execution is based on the Boolean condition. The condition of the loop is check first. If the condition is found to be  a true one then, executes the loop body otherwise exit the loop. While loop is consider as an entry control loop. Example: while(true) { System.out.println("This is a never ending loop"); } Example: import java.io.*; public class WhileDemo { public static void main(String args[]) throws IOException { int num; int result = 1; int i = 1; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter a the number :"); num = Integer.parseInt(br.readLine()); System.out.println("Multiplication table of " +num+ "is given bellow "); while(i <= 10) { result = num * i ; System.out.println(num+"  *  "+i+" = "+result); i++; } } } Output:

Conditional Operator (? :)

Syntax for conditional operator available in java is given bellow. variable  = (condition) ? expression-1 : expression-2;  Example:   result  = (s=='+') ? (a + b) : (a - b); The condition is a Boolean statement. If the condition is found to be true, then expression-1  executes and assigned to the variable and if the condition is false then expression-2 executes and assigned to variable. It is very useful, because it perform the action corresponding to true and false condition in a single statement.  In the example if the value of character variable s is + , then a + b is calculated and assign the result to the variable result . And if the value of s is other than + , then a - b is calculated and assign the result to the variable result . Consider the following full example for getting more details about it. import java.io.*; class ConditionalOperatorDemo { public static void main(String args[]) throws IOException { char s; int a,b,result; result =

switch case statement

The switch case is also same as the if else if loop. It also checks multiple conditions for  a single variable or statement. Syntax: switch(statement/variable) { case 1: statements; break; case 2: statements; break; .................... .................... case n: statements; break; default: statements; } The statement or variable is compared to each of the cases for equality. The checking is done in a sequential manner.  If any of the case satisfy the statement/variable then the statement associated with that case only executes. The break statement is important. If  break statement is missing then the loop performs unwanted checking and generates unwanted output. For more details consider the following example. import java.io.*; class SwitchDemo { public static void main(String args[])throws IOException { char ch; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter an alphabet:&

Creating Object Of A Class

                                                            Watch in YouTube click here

if else ladder

It is possible to place an if loop inside the body of another if or else . Such an arrangements of loop is known as loop ladder . For example consider the following set of code. if (condition-1)   // outer if loop { if(condition-2)  // inner if loop { statements; } else { statements; } statements; } else { if (condition-3) // inner if loop { statements; } } You can see that the execution of the inner loop depends on the outer loop condition. Consider the following example for more details. import java.io.*; class LoopLadderDemo { public static void main(String args[]) throws IOException { int num1,num2,num3; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter first number :"); num1 = Integer.parseInt(br.readLine()); System.out.println("Enter second number :"); num2 = Integer.parseInt(br.readLine()); System.out.println("Enter third number :"); num3 = Integer.parseInt(br

First Java Program

            Click Here To Watch This On YouTube                             Previous                                                 Index                                                   Next  

Setting Variable Path

Installing jdk

Anatomy Of An Android Project

First Android Application

Watch this on YouTube

Creating Android Virtual Device (AVD)

Installing Android SDK Part-2

Installing Android SDK Part-1