Saturday, September 4, 2021

# 17. loops

whenever we want to execute the same statements continuously or repeatedly we will go for looping statements

3 types of looping statements

1. while

2. do-while

3. for loop


while:

when do we go for while?

whenever we want to execute the statements continuously or repeatedly whenever we don't know the no of iterations in advance then go for while loop

if we don't know how many times we need to execute

How to define the while

standard syntax:

initialization section;        //starting point

while (condition)        // while is a keyword to convey it as while, the condition should always be boolean(true/false) otherwise we will get a compile-time error

{        //beginnig of loop

;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;

inc/dec section;

}

;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;


case 1: in while once the condition is true the loop body is executed till the condition become false.

case 2: if the condition is false 


int i=1;

while (i<=5)

{

System.out.println("Hello:"+i);

i++;  // i=i+1

}

System.out.println("oow");


do while:

if we want to execute the statement atleast once irrespective of the condition then go for do while

Standard syntax:

initialization section;        //starting point

do     

{        //beginnig of loop

;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;

inc/dec section;

}while (condition)

;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;


Friday, September 3, 2021

# 19. oops concepts

 OOPS, Concepts:

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

1. Data hiding

2. Data abstraction

3. Polymorphism

    3.1. Overloading

    3.2. Overriding

4. Encapsulation

    4.1 Tightly Encapsulation

5. IS-A Relationship

6. HAS-A Relationship (Composition/ aggregation)

7. Coupling

8. Cohesion


1. Data hiding:

 Our internal data should no go out directly

after validation only, If the user is valid/ authorized then only they can access the data is a mechanism called data hiding

data hiding means we are providing some security to the data

In java how we can implement data hiding?

By using a concept called private modifier


2. data abstraction:

By hiding internal implementations, just highlight a set of business methods/ services called data abstraction.

realtime example:

ATM

a lot of services ---> 

case1: we are seeing only services(highlight)

case2: we don't see business implementations(hiding)

Any application only services are showing

We can implement data abstraction using abstracts and interfaces.


4. Encapsulation:

Encapsulation is the process of wrapping the data into a container

Ex: Water bottle is a container we are wrapping water

In java where we are going to wrap our data inside a container is called class

Every java class is the best example of encapsulation

Tightly encapsulation:

A class is said to be a tightly encapsulation class if and only if all the variables in that class should be of type private and it doesn't care about methods.

the methods can be anything


# 18. nested loops

 whenever we know the number of iterations in advance means we know how many times we need to execute the program then we go for loop

 whenever we don't know the number of iterations in advance, we don't know how many times we need to execute the program then we go for while loop 

I want to execute my loop body at least once irrespective of the condition then we can go for do-while

do and then check the condition

what is nested for loop?

A for loop inside a for loop is called nested for loop

what is nested while loop?

A while loop inside a while loop is called nested while loop

A loop inside another loop is called nested loop


for (init section; condition; inc/dec section)

{

;;;;;;;;;;;

    for (init section; condition; inc/dec section)

     {

        ;;;;;;;;;;;

       }

}


Example:

public class LoopsDemo{

public static void main(String[] args)  {

        for (int i=0; i<3; i++)        // outer loop

        {

            System.out.println("OL: " + i);

            for(int j=0; j<=3; j++)        // inner loop

            {

                System.out.println("IL: "+j);

            }

        }

   }

}

// once the control is coming to the inner loop, this inner loop is executed till the condition is false

OUTPUT:

OL: 0

IL: 0

IL: 1

IL: 2

IL: 3

OL: 1

IL: 0

IL: 1

IL: 2

IL: 3

OL: 2

IL: 0

IL: 1

IL: 2

IL: 3

OL: 3

IL: 0

IL: 1

IL: 2

IL: 3


we saw break and continue in switch case.

break:

a break is a keyword or a statement which we can use inside the switch cases and which we can use inside the looping mechanism that can be while, do-while, nested, and for loop

continue:

based on some condition if we want to skip the current iteration then we go for continue 


public class LoopsDemo{

public static void main(String[] args)  {

        for (int i=0; i<=5; i++)        // outer loop

        {

             System.out.println(i);

              if (i==2) {

              break;        // directly it comes out of for loop

               }

          }

           System.out.println("OOFL");

    }

}

OUTPUT:

0

1

2

OOFL


continue:

public class LoopsDemo{

public static void main(String[] args)  {

        for (int i=0; i<=5; i++)        

        {

            

              if (i==2) {

              continue;        // skips current iteration    

               }

             System.out.println(i);

    }

        System.out.println("OOFL");

  }

}

OUTPUT:

0

1

3

4

5

OOFL


break:

public class LoopsDemo{

public static void main(String[] args)  {

        for (int i=0; i<=5; i++)        

        {

            

              if (i==2) {

                break ;  

               }

             System.out.println(i);

    }

        System.out.println("OOFL");

  }

}

OUTPUT:

0

1

2

OOFL


PART 1 completed


part1  java basics

part2  oops

part3  selenium

part4

frameworks






















# 16. control statements

 Control statements: In java, by using control statements we can tell the flow of execution. in which order the statements should execute. d...