Queue and Set Interface

Queue Interface:

Java Queue interface orders the element in FIFO(First In First Out) manner. In FIFO, first element is removed first and last element is removed at last.

How to create the objects?

Queue<String> q1 = new PriorityQueue();
Queue<String> q2 = new ArrayDeque();

PriorityQueue Class

Properties: It holds the elements or objects which are to be processed by their priorities. PriorityQueue doesn't allow null values to be stored in the queue.

Methods: boolean add(object), boolean offer(object), boolean remove(object), Object poll(), Object element() , Object peek(), void clear(), int size()

Deque Interface:

Deque interface extends the Queue interface. In Deque, we can remove and add the elements from both the side. Deque stands for a double-ended queue which enables us to perform the operations at both the 

Deque d = new ArrayDeque();


ArrayDeque Class

ArrayDeque class implements the Deque interface. It facilitates us to use the Deque. Unlike queue, we can add or delete the elements from both the ends.

ArrayDeque is faster than ArrayList and Stack and has no capacity restrictions.

Set Interface

Properties: Set Interface in Java is present in java.util package. It extends the Collection interface.It represents the unordered set of elements which doesn't allow us to store the duplicate items. 

We can store at most one null value in Set. Set is implemented by HashSet, LinkedHashSet, and TreeSet.

Set<data-type> s1 = new HashSet<data-type>();  
Set<data-type> s2 = new LinkedHashSet<data-type>();  
Set<data-type> s3 = new TreeSet<data-type>(); 

HashSet Class

Properties: This class implements the Set interface.
--HashSet doesn’t maintain any order,
--HashSet doesn’t allow duplicates
--HashSet allows null values however if you insert more than one nulls it would still return only one null value.
--HashSet is non-synchronized.
--Hashing is used to store the elements in the HashSet

HashSet<String> hset = new HashSet<String>();

Methods: boolean add(E e) , void clear(), Object clone(), boolean contains(Object o), boolean isEmpty(), int size().

LinkedHashSet Class

Properties: This class implements the Set interface.
--LinkedHashSet maintains insertion order,
--LinkedHashSet doesn’t allow duplicates
--LinkedHashSet allows null values however if you insert more than one nulls it would still return only one null value.
--LinkedHashSet is non-synchronized.
LinkedHashSet<String> set=new LinkedHashSet<String>(); 

Methods: boolean add(E e) , void clear(), Object clone(), boolean contains(Object o), boolean isEmpty(), int size(), boolean remove(Object o), removeAll().


TreeSet Class

Properties: This class implements the SortedSet interface.
--The access and retrieval time of TreeSet is quite fast. The elements in TreeSet stored in ascending order.
--TreeSet doesn’t allow duplicates
--TreeSet doesn’t allows null values 
--TreeSet is non-synchronized.

TreeSet<String> tset = new TreeSet<String>();

Methods: boolean add(E e) , void clear(), Object clone(), boolean contains(Object o), boolean isEmpty(), int size(), boolean remove(Object o), Object first(), Object last(). 

To get more details please watch below youtube video and Subscribe the channel.




Vector and Stack Class in Java

Properties:
Vector uses a dynamic array to store the data elements. It is similar to ArrayList. However, It is synchronized. it is synchronized and due to which it gives poor performance in searching, adding, delete and update of its elements.

How to Create?
Vector<String> v=new Vector<String>();

Methods: addElement(Object element), int capacity(), int size(), firstElement(), lastElement(), get(int index) etc.

To get more details please watch below youtube video and Subscribe the channel.



LinkedList in Java

Java LinkedList class is doubly-linked list implementation of the List and Deque interfaces.

Single and Doubly Linked List
Single and Doubly Linked List
Properties: 
--Permits all elements including duplicates and NULL.
--LinkedList maintains the insertion order of the elements.
--It is not synchronized.
--the manipulation is fast because no shifting is required.
How to create:
LinkedList<String> linkedList = new LinkedList<>();

Methods: boolean add(Object item), void add(int index, Object item), boolean addAll(Collection c), void addFirst(Object item), void addLast(Object item), void clear(), Object clone(), Object getFirst(), Object getLast(), Object poll() etc.

To get more details please watch below youtube video and Subscribe the channel.



ArrayList In Java

List Interface:

1. Can contain duplicates and elements are ordered.
2. List interface is implemented by the classes ArrayList, LinkedList, Vector, and Stack.
3. Lists represents an ordered collection of elements. Using lists, we can access elements by their integer index (position in the list), and search for elements in the list. index start with 0, just like an array.

ArrayList Class in Java:

Properties: 
Ordered – Elements in arraylist preserve their ordering which is by default the order in which they were added to the list.
Index based – Elements can be randomly accessed using index positions. Index start with '0'.
Dynamic resizing:
Non synchronized:
Duplicates allowed – We can add duplicate elements in arraylist. It is not possible in sets.
How to create:
ArrayList<String> alist=new ArrayList<String>();

Methods: add(), set(int index, Object o), remove(index or value), get(int index), indexOf(Object o), int size(), boolean contains(Object o), clear() etc.

To get more details please watch below youtube video and Subscribe the channel.

Part1:


Part2:




Collection Framework in Java

1. A Collection is a group of individual objects represented as a single unit
2. Java Collections can achieve all the operations that you perform on a data such as searching, sorting, insertion, manipulation, and deletion.
3. The Java Collections Framework is a collection of interfaces and classes which helps in storing and processing the data efficiently.

Interfaces:
List
Set
Map
Queue
Deque
SortedSet

Classes:
ArrayList, LinkedList, Vector, Stack, PriorityQueue, HashSet, LinkedHashSet, TreeSet, HashMap, LinkedHashMap, TreeMap and HashTable.

Collection Interface:
1. Root interface with basic methods like add(), remove(), contains(), isEmpty(), addAll(), clear().. etc.
2. All other collection interfaces and classes (except Map) either extend or implement this interface. For example, List (indexed, ordered) and Set (sorted) interfaces implement this collection.

To get more details please watch below youtube video and Subscribe the channel.


Array In Java

What is an Array?
1. An array is a collection of similar type of elements that have a contiguous memory location.
2. The variables in the array are ordered and each have an index.

Java Array
An Array Example
Array Types:

1. Single Dimensional Array
2. Multidimensional Array

Advantages -  
code optimization by storing data and we can retrieve or sort the data efficiently.
We can get any data located at an index position.

Disadvantages-
Stores similar type of data
We can store only the fixed size of elements in the array. It doesn't grow its size at runtime.

1-D Array:

Declaration of an Array:
Syntax: data_type array-name[]; Example: int a[];
 or
Data_type[] array-name;  Example: int[] a;

Instantiation of an Array
array-var-name =new datatype[size];  Example: a= new int[5]

Declaration and Instantiation
Data_type array-name[]=  new data_type[5];
int a[]=new int[5];

Array Literal
Data_type array-name[] = {<Values>}
Example: int a[] = {12,23,1,34,5,6}

2-D Array:

Declaration of an Array:
Syntax: data_type array-name[][]; Example: int a[][];
 or
Data_type[][] array-name;  Example: int[][] a;

Instantiation of an Array
array-var-name =new datatype[][];  Example: a= new int[2][2]

Declaration and Instantiation
Data_type array-name[][]=  new data_type[2][2];
int a[][]=new int[2][2];

Array Literal
Data_type array-name[] = {<Values>}
Example: int a[][] = {{12,23},{23,34}}

To get more details please watch below youtube video and Subscribe the channel.



this Keyword in Java

what is this keyword in java?

this is a reference variable that refers to the current object.

this Keyword usage:
1. To refer current class instance variable
2. To invoke current class method
3. To invoke current class constructor
4. this can be passed as an argument in the method call
5. this can be used to return the current class instance from the method
6. this can be passed as an argument in the constructor call

To get more details please watch below youtube video and Subscribe the channel.


static Keyword in Java

The static keyword in Java is used for memory management
The static keyword belongs to the class than an instance of the class.
Static can be : Variable, Method, Block , Nested class

static Variable:
1. Static variable is used to fulfil the common requirement. For Example company name of employees, college name of students etc. Name of the college is common for all students
2. static variable gets memory only once in the class area at the time of class loading.

static Method:
1. A static method belongs to the class rather than the object of a class.
2. A static method can be invoked without the need for creating an instance of a class.
3. A static method can access static data member and can change the value of it.
Restrictions -
--The static method can not use non static data member or call non-static method directly.
--this and super cannot be used in static context.

Why main method is static?

It is because the object is not required to call a static method. If it were a non-static method, JVM creates an object first then call main() method that will lead the problem of extra memory allocation.

Difference between static and final keyword:

static keyword always fixed the memory that means that will be located only once in the program where as final keyword always fixed the value that means it makes variable values constant

Java static Block:
Is used to initialize the static data member.
It is executed before the main method at the time of classloading.

To get more details please watch below youtube video and Subscribe the channel.

Part1:


Part2:




Constructors in Java

Constructor Definition:

1. It is called constructor because it constructs the value at the time of object creation.
2. Block of code similar to method.
3. It is called when an object of class is created.
4. At the time of calling constructor, memory for the object is allocated in the memory.
5. It is used to initialize the object.
6. Java compiler created the default constructor if your class doesn't have any constructor.

Rules to Create Constructor:

1. Constructor name must be the same as its class name
2. Must have no return type
3. A Java constructor cannot be abstract, static, final, and synchronized

Types of Constructor:

1. Default or no arguments – Provides default values
2. Parameterized constructor

Constrtuctore Overloading:

having more than one constructor with different parameter lists.

Constructor Vs Method:

Java Constructor Vs Java method

Java Constructor Vs Java method 


To get more details please watch below youtube video and Subscribe the channel.


Encapsulation in Java

1. Encapsulation in Java is a mechanism of wrapping the data (variables) and methods together as a single unit.
2. In encapsulation, the variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class. Therefore, it is also known as data hiding.

How to Achieve?

1. Declare the variables of a class as private.
2. Provide public setter and getter methods to modify and view the variables values.


Benefits:

1. The fields of a class can be made read-only (class which has only getter method) or write-only (class which has only setter method) .
2. A class can have total control over what is stored in its fields.

To get more details please watch below youtube video and Subscribe the channel.


Abstraction and Interface in Java

Abstraction:

--Abstraction is a process of hiding the implementation details and showing only functionality to the user.
--In Abstraction only the essential details are displayed to the user. The trivial or the non-essentials units are not displayed to the user. Ex: A car is viewed as a car rather than its individual.
--There are two ways to achieve abstraction in java
1. Abstract class (0 to 100%)
2. Interface (100%)

Abstract Class:

A class which is declared as abstract is known as an abstract class. It can have abstract and non-abstract methods. It needs to be extended and its method implemented.
An abstract class must be declared with an abstract keyword.
Abstract Class can have abstract and non-abstract methods.
Abstract class cannot be instantiated.
Abstract class can have constructors final and static methods also.
Abstract class can have final methods
If there is an abstract method in a class, that class must be abstract.

Interface:

--An interface in java is a blueprint of a class. It has static constants and abstract methods.
--There can be only abstract methods in the Java interface, not method body. It is used to achieve abstraction and multiple inheritance in Java.
--It cannot be instantiated just like the abstract class.
--In interface we can have default and static methods.
--In interface we can have private methods.

Class and Interface Relationships:

Class and Interface in Java

Class and Interface Relationships

Why we use Interface?

--It is used to achieve abstraction.
--By interface, we can support the functionality of multiple inheritance.

Multiple inheritance in Java by interface:

--If a class implements multiple interfaces, or an interface extends multiple interfaces, it is known as multiple inheritance.
--Multiple inheritance is not supported through class in java, but it is possible by an interface,

Multiple Inheritance in Java


Abstract Class Vs Interface

Difference between Abstract Class and Interface
Difference between Abstract Class and Interface


To get more details please watch below youtube video and Subscribe the channel.



Polymorphism in Java

What is Polymorphism?

--Polymorphism in Java is a concept by which we can perform a single action in different ways.
--Polymorphism is derived from 2 Greek words: poly and morphs. The word "poly" means many and "morphs" means forms. So polymorphism means many forms.
--There are two types of polymorphism in Java: compile-time polymorphism and runtime polymorphism.
--Polymorphism can be achieved by method overloading and method overriding

Method Overloading:

--Method Overloading is a feature that allows a class to have more than one method having the same name, if their argument lists are different.
--Signature should be different:

      1. Number of parameters.
      2. Data type of parameters.
      3. Sequence of Data type of parameters.

Method Overriding:

--Declaring a method in sub class which is already present in parent class is known as method overriding.
--Advantage: The main advantage of method overriding is that the class can give its own specific implementation to a inherited method without even modifying the parent class code.

Types of Polymorphism:

1. Static Polymorphism (Static Binding - Early binding) is also known as compile time binding or compile time polymorphism-- Method Overloading in an example -- when type of object is determined at compiled time it is known as Static binding.
2. Dynamic Polymorphism (Dynamic Binding -late binding) is also known as runtime time binding or run time polymorphism -- example method overriding-- When type of object is determined at run time, it is known as dynamic binding.

To get more details please watch below youtube video and Subscribe the channel.




Inheritance in Java

What is Inheritance?

Defnition 1: Inheritance in Java is a mechanism in which one object acquires all the properties and behaviours of a parent object
Defnition 2: The process by which one class acquires the properties(data members) and functionalities(methods) of another class is called inheritance.
Defnition 3: Inheritance can be defined as the process where one class acquires the properties (methods and fields) of another.

Why we use Inheritance?

--For Code Re-usability- The biggest advantage of Inheritance is that the code that is already present in base class need not be rewritten in the child class.
--Avoid duplication in code.
--For method overriding

Different terms associated with Inheritance:

Class: A class is a group of objects which have common properties. It is a template or blueprint from which objects are created.
Sub Class/Child Class: Subclass is a class which inherits the other class. It is also called a derived class, extended class, or child class.
Super Class/Parent Class: Superclass is the class from where a subclass inherits the features. It is also called a base class or a parent class.
Reusability: As the name specifies, reusability is a mechanism which facilitates you to reuse the fields and methods of the existing class when you create a new class. You can use the same fields and methods already defined in the previous class.
There are two ways we can do code reuse either by the implementation of inheritance (IS-A relationship), or object composition (HAS-A relationship)

Syntax:
class Subclass-name extends Superclass-name
     {
          //data members and methods
      }

Types of Inheritance

inheritance in java
Types of Inheritance in Java

Multiple and Hybrid Inheritance
Multiple Inheritance and Hybrid Inheritance in Java

Various Scenarios to create Parent/Child objects:

1. Sub(Child) Class reference and Sub(Child) Object- Allow you to access all the methods and data members of super class and sub class.
2. Super(Parent) Class reference and Sub(Child) Class Object- Allow you to access all the methods and data members of Super class only.
3. Super(Parent) Class reference and Super(Parent) Class Object - Allow you to access all methods and data members of super class only.
4. Sub(Child) Class reference and Super(Parent) Class object- child cannot hold parent object

Usage of inheritance in selenium:

1. We create a Base Class in the Framework to initialize WebDriver interface, WebDriver waits, Property files, Excels, etc., in the Base Class.

2. We extend the Base Class in other classes such as Tests and Utility Class.

To get more details please watch below youtube video and Subscribe the channel.



Why String is Immutable in Java?

In java, string objects are immutable. Immutable simply means unmodified or unchangeable.
Once string object is created its data or state can't be changed but a new string object is created.

To get more details please watch below youtube video and Subscribe the channel.


String Class and Built in Methods in Java

String:

In Java, string represents sequence of char values. An array of characters works same as Java string. For example:

char[] h={'H','E','L','L','O'};
String s=new String(h);

String s=“HELLO";

Java String class provides a lot of methods to perform operations on string

How to create string object?

The java.lang.String class is used to create a string object.
There are two ways to create String object:

By string literal - Java String literal is created by using double quotes. For Example:
String s1=“Selenium";

By new keyword - String s=new String(“Selenium");

Built in Methods:

Java has a librabry of classes and methods organised in packages
Import java.io.console
Import java.io.*

In order to use built in methods we need to import packages or classes
Java.lang package is automatically imported in every java Built in methods categories
String methods
Array methods
Number methods
Character methods

Different String methods:

compareTo - The Java String compareTo() method is used for comparing two strings lexicographically.

boolean equals() - The java string equals() method compares the two given strings based on the content of the string (case sensitive)
String concat() – concat two strings
boolean equalsIgnoreCase() - The java string equals() method compares the two given strings based on the content of the string (not casesensitive)
char charAt() – index position - The java string charAt() method returns a char value at the given index number.
boolean contains()
toUpperCase() – convert to upper case
toLowerCase() – convert to lower case
trim() – remove spaces from both sides of string
substring() --  returns part of string
boolean endsWith()
boolean startWith() – ends with specified suffix or not
int length()
replace()

Java Convert String to int:

Convert String to int using Integer.parseInt(String)
      String str = “54321";
      int num = Integer.parseInt(str);
Convert String to int using Integer.valueOf(String)
      String str=“123";
      int num = Integer.valueOf(str);

Java int to String Conversion:

Convert int to String using String.valueOf() 
 
        String int ivar = 123;
String str = String.valueOf(ivar);
System.out.println("String is: "+str);
System.out.println(555+str);
Convert int to String using Integer.toString()
      int ivar = 123;
      String str = Integer.toString(ivar);
      System.out.println("String is: "+str);
      System.out.println(555+str);

To get more details please watch below youtube video and Subscribe the channel.



Methods in Java

What is a method?

A java method is a set of statements or steps that are grouped together to perform an operation
Method are also known as functions
When we use methods? – whenever we want to perform an operation multiple times
Advantage of methods – code reusability
Types of methods -  built in (predefined) and user defined

1. Built in Methods:

Java has a librabry of classes and methods organised in packages
Import java.io.Console
Import java.io.*

In order to use built in methods we need to import packages or classes
Java.lang package is automatically imported in every java Built in methods categories
String methods
Array methods
Number methods
Character methods

2. User Defined Methods:

Different Method types:
Method without returning any values
Method with returning values
Method using passing parameters

Different ways to call Methods:
Using Objects
Without Using object
Call external methods (from external class)

To get more details please watch below youtube video and Subscribe the channel.

Part1:


Part2:



Class and Object in Java

What is OOP?

Object oriented programming – As the name suggests uses objects in programming. Object oriented programming aims to implement real world entities like inheritance, hiding, polymorphism etc in programming. The main aim of OOP is to bind together the data and the functions that operates on them so that no other part of code can access this data except that function.

Oops Concept

Java is an Object-Oriented Language. As a language that has the Object-Oriented feature, Java supports the following fundamental concepts −

Polymorphism
Inheritance
Encapsulation
Abstraction
Classes
Objects
Methods

1. What is an Object:

In object oriented programming Whenever you do something you need an object.
Print, calculate, execute, process, save and to return
Object don't do things individually
Basically object has couple of information
What object knows  variables  -- to store values
What object does   methods (execute and process)
Object are crated using class. Objects and classes are interrelated to each other.

If we consider the real-world, we can find many objects around us, cars, dogs, humans, etc. All these objects have a state and a behaviour.

If we consider a dog, then its state is - name, breed, color, and the behaviour is - barking, wagging the tail, running.

2. What is a Class?

A class is a blueprint or design from which individual objects are created.

public class Dog {
   String breed;
   int age;
   String color;

   void barking() {
   }

   void hungry() {
   }

   void sleeping() {
   }
}

How to Create an Object?

In Java, an object is created from a class.

Syntax -  <ClassName> Reference = new <ClassName()>;

When an object of a class is created, the class is said to be instantiated. All the instances share the attributes and the behaviour of the class. But the values of those attributes, i.e. the state are unique for each object. A single class may have any number of instances.

To get more details please watch below youtube video and Subscribe the channel.




Modifiers in Java

Modifiers are key words in java that is used to restrict or add access level for classes, attributes, methods and constructors.

Access Modifiers - default, Private, Protected, Public
Non Access modifiers
      For Classes – final, abstract
      For Methods or attributes – final, static, abstract, transient, synchronized, volatile

Access Modifiers Visibility
Access Modifiers Visibility

1. Default:

When no access modifier is specified for a class , method or data member – It is said to be having the default access modifier by default.

The data members, class or methods which are not declared using any access modifiers i.e. having default access modifier are accessible only within the same package.

Scope – within same package

2. Private

The private access modifier is specified using the keyword private.
The methods or data members declared as private are accessible only within the class in which they are declared.
Any other class of same package will not be able to access these members.


Scope – within same class

3. Protected

The protected access modifier is specified using the keyword protected.
The methods or data members declared as protected are accessible within same package or sub classes in different package.

Scope – within same package and other package using inheritance

4. Public

The members, methods and classes that are declared public can be accessed from anywhere. This modifier doesn’t put any restriction on the access.

Scope – accessible from anywhere inside or outside of the package.

To get more details please watch below youtube video and Subscribe the channel.



Java Loop Statements

In programming languages, loops are used to execute a set of instructions/functions repeatedly when some conditions become true.

for loop
while loop
do while loop
enhanced for loop

Loop Examples:

Fetching records (test data) from external source – like DB/ Excel file
Execute one block of code multiple times

1. for loop:

If the number of iteration is fixed, it is recommended to use for loop.

Syntax:

for(init;condition;incr/decr){
// code to be executed
}

Example: Lets print the numbers from 1 to 5.

for(int i=1; i<=5; i++){
  System.out.println("Printing using for loop. Count is: " + i);
 }

Printing using for loop. Count is: 1
Printing using for loop. Count is: 2
Printing using for loop. Count is: 3
Printing using for loop. Count is: 4
Printing using for loop. Count is: 5

2. while loop:

If the number of iteration is not fixed, it is recommended to use while loop.

Syntax:

while(condition){
//code to be executed
}

Example: Lets print the numbers from 1 to 5.

int i=1;
while(i<6){
   System.out.println("Printing using while loop. Count is: " + i);
}

Printing using while loop. Count is: 1
Printing using while loop. Count is: 2
Printing using while loop. Count is: 3
Printing using while loop. Count is: 4
Printing using while loop. Count is: 5


3. do while:

If the number of iteration is not fixed and you must have to execute the loop at least once, it is recommended to use the do-while loop.

Syntax:

do{
//code to be executed
}while(condition);

4. Enhanced/for-each loop

In Java, there is another form of for loop (in addition to standard for loop) to work with arrays and collection, the enhanced for loop.

Syntax:

for(Type var : arrayname){
//code to be executed
}

To get more details please watch below youtube video and Subscribe the channel.



Control flow statements

Control flow statements, would change or break the flow of execution by implementing decision making, looping, and branching your program to execute particular blocks of code based on the conditions.
Control flow statements in Java allow you to run or skip blocks of code when special conditions are met. There are 3 types of control flow statements supported by the Java programming language.

Decision-making: if-then, if-then-else, if else if, nested if else and switch
Looping: for, while, do-while
Branching: break, continue, return

In this post we will mainly discuss about Decision-making statements.

Java if statements:

1. If-then statement

The “if” statement in Java works exactly like in most programming languages. With the help of “if” you can choose to execute a specific block of code when a predefined condition is met.

Syntax:

if (expression) {
   // statements
}

Here expression is a boolean expression (returns either true or false).

If the expression is evaluated to true, statement(s) inside the body of if (statements inside parenthesis) are executed.

If the expression is evaluated to false, statement(s) inside the body of if are skipped from execution.

Example:

public class IfThenDemo {
public static void main(String[] args) {
int age = 2;
System.out.println("James age is " + age + " years old");
if (age < 3) {
System.out.println("James is an Infant");
}
}
}

Output:

James age is 2 years old
James is an Infant

2. The if-then-else Statement:

The if-then-else statement provides a alternate path of execution when an if clause evaluates to false.

Syntax:

The syntax of if-then-else statement is:

if (expression) {
   // codes
}
else {
  // some other code
}

Example:

public class IfThenElseDemo {
public static void main(String[] args) {
int A= 4;
                int B= 7;
if (A > B) {
System.out.println("A is Greater than B");
}
                else{
                        System.out.println("B is Greater Number");
                     }

}
}

Output:

B is Greater Number


3. If else If Statement

In Java, it's possible to execute one block of code among many. For that, you can use if..else...if ladder.

Syntax:

if (expression1)
{
   // codes
}
else if(expression2)
{
   // codes
}
else if (expression3)
{
   // codes
}
.
.
else
{
   // codes
}

Example:

public class FlowControlExample {
public static void main(String[] args) {
int age = 17;
System.out.println("James is " + age + " years old");
if (age < 4) {
System.out.println("James is a baby");
} else if (age >= 4 && age < 13) {
System.out.println("James is a child");
} else if (age >= 13 && age < 20) {
System.out.println("James is a teenager");
} else if (age >= 20 && age < 60) {
System.out.println("James is an adult");
} else {
System.out.println("Jamesr is an old men");
}
}
}

Output:
James is 17 years old
James is a teenager


4. Nested if..else Statement

It's possible to have if..else statements inside a if..else statement in Java. It's called nested if...else statement.

5. Switch Statement:

In Java, the if..else..if ladder executes a block of code among many blocks. The switch statement can a substitute for long if..else..if ladders which generally makes your code more readable.

Syntax:

switch (variable/expression) {
case value1:
   // statements
   break;
case value2:
   // statements
   break;
   .. .. ...
   .. .. ...
default:
   // statements
}


class SwitchDemo {
    public static void main(String[] args) {
        int age = 2;
        String yourAge;
        switch (age) {
            case 1:  System.out.println("You are one year old");
                     break;
            case 2:  System.out.println("You are two year old");
                     break;
            case 3:  System.out.println("You are three year old");
                     break;
            default: System.out.println("You are more than three year old");
                     break;
        }
    }
}

Output:

You are two year old

To get more details please watch below youtube video and Subscribe the channel.


Operators in Java

What is an Operator?

Operator in java is a symbol that is used to perform operations. For example: +, -, *, / etc.
Java provides a rich set of operators to manipulate variables.We will discuss about below operators in this post.

1.Arithmetic Operators
2.Relational Operators
3.Logical Operators
4.Assignment Operators
5.Misc Operators

Arithmetic Operators

Java arithmetic operators are used to perform addition, subtraction, multiplication, and division. They are used to perform basic mathematical operations.

Arithmetic Operators
Arithmetic Operators


Relational Operators

Relational Operators returns Boolean/Logical result.

== (equal to)
!= (not equal to)
> (greater than)
< (less than)
>= (greater than or equal to)
<= (less than or equal to)

Logical Operators:

There are three logical operators given below:

Logical Operators
Logical Operators

How Logical Operator Works
How Logical Operator Works



Assignment Operators

Below are the Assignment operators are given with explanation:

 Assignment Operators with Examples
Assignment Operators with Examples 


Misc Operators

Conditional Operator - Conditional operator is also known as the ternary operator. This operator consists of three operands and is used to evaluate Boolean expressions. The goal of the operator is to decide, which value should be assigned to the variable. The operator is written as −

variable x = (expression) ? value if true : value if false

instanceof Operator - This operator is used only for object reference variables. The operator checks whether the object is of a particular type (class type or interface type). instanceof operator is written as −

( Object reference variable ) instanceof  (class/interface type)

To get more details please watch below youtube video and Subscribe the channel.



Java Variables and Data types

What is a variable?
Different definitions given below:

--Variable is a name of memory location
--A memory location to store temporary data within a   java program.
--A variable is a container which holds the value while the java program is executed. A variable is assigned with a datatype.
--It is a combination of "vary + able" that means its value can be changed.

Variable in Java
Variable Example
Types of Variables

1. Local variable -- used inside a method
Note: Local Variable contains garbage value
2. Instance/global variable --  used inside a class but outside method
Note: Global variable contain null or default value
3. Static variable -- We will discuss in separate post.

What is a Datatype?

--Data types specify the different sizes and values that can be stored in the variable. 
--A data type is a classification of the type of data that a variable or object can hold.
There are two types of data types in Java:
1. Primitive data types: The primitive data types include Boolean, char, byte, short, int, long, float and double.
2. Non-primitive data types: The non-primitive data types include String, Arrays, Classes and Interfaces.

Data types in Java

Data Type Hierarchy

Classification of Data Types

Classification of Data Types

Classification of Data Types

Why Java uses Unicode system?

Unicode is a universal international standard character encoding that is capable of representing most of the world's written languages. Before Unicode, there were many language standards:
ASCII (American Standard Code for Information Interchange) for the United States.
ISO 8859-1 for Western European Language.
KOI-8 for Russian.
GB18030 and BIG-5 for chinese, and so on.
So to support multinational application codes, some character was using single byte, some two. An even same code may represent a different character in one language and may represent other characters in another language.
To overcome above shortcoming, the unicode system was developed where each character is represented by 2 bytes.

To get more details please watch below youtube video and Subscribe the channel.




Java for Selenium: How much Java is Required?

How much java is required for selenium testing? This question is always in the minds of testing professionals who would like to learn selenium, but are not so comfortable with too much of programming to learn. In this post, we will take a detailed look at the extent of Java to be learnt for Selenium scripting.

Java is one of the languages used for writing automation scripts in Selenium. Selenium supports other languages as well like python, ruby, C#, javascript etc. However, java has gained wide spread acceptance in the industry as the preferred language for selenium.

This means that it is advisable to learn java for selenium as it will also help in improving your career prospects.

For Test Automation using Selenium Core Java is sufficient, Advanced Java is not required.

Java Fundamentals and OOPS (Object Oriented Programming System) concepts are required.

We can segregate Java for selenium in to 2 categories.

A) Java Fundamentals

Data types in Java
Variables
Operators in Java
Flow control Statements- Conditional like if else statements and switch case
Loop Statements – For, while, do while and Enhanced for loop
Strings and Arrays in Java
Java methods -  System and user defined
Regular Expressions


B) Java OOPS Concepts and More

Inheritance
Polymorphism
Abstractions
Encapsulations
Abstract Class method
Interface
Interface vs Abstract Class in Java
Constructor
Packages
File Handling
Exceptions Handling
Static keyword
“this” keyword
Garbage Collection
Collection Framework
Multithreading in Java
How to use Buffered Reader in Java

To get more details please watch below youtube video and Subscribe the channel.





Selenium WebDriver: Selenium WebDriver Architecture

There are four components of Selenium Architecture:

Selenium Client Library
JSON Wire Protocol over HTTP
Browser Drivers
Browsers

Selenium Client Library:

Selenium supports multiple libraries such as Java, Ruby, Python, etc., Selenium Developers have developed language bindings to allow Selenium to support multiple languages.
Below is the link to download Selenium Client Language Bindings:

https://www.seleniumhq.org/download/#client-drivers

JSON Wire Protocol over HTTP:

JSON stands for JavaScript Object Notation. It is used to transfer data between a server and a client on the web. JSON Wire Protocol is a REST API that transfers the information between HTTP server. Each BrowserDriver (such as FirefoxDriver, ChromeDriver etc.,)  has its own HTTP server.

Browser Drivers:

Each browser contains separate browser driver. Browser drivers communicate with respective browser without revealing the internal logic of browser’s functionality. When a browser driver is  received any command then that command will be executed on the respective browser and the response will go back in the form of HTTP response.

Real Browsers:

Selenium supports multipe browsers such as Firefox, Chrome, IE, Safari etc.

How Selenium Works Internally:

Lets say you have written below couple of lines of code:

WebDriver driver  = new ChromeDriver();
driver.get(https://www.automationtestininsider.com)

Based on the above statements, Chrome browser will be launched and it will navigates to automationtestinginsider website.

Once you Run the program, every statement in your script will be converted as a URL with the help of JSON Wire Protocol over HTTP. The URL’s will be passed to the Browser Drivers. (In this case, ChromeDriver). Here in our case the client library (java) will convert the statements of the script to JSON format and communicates with the ChromeDriver. URL looks as shown below.

http://localhost:8080/{"url":"https://www.automationtestinginsider.com"}

Every Browser Driver uses a HTTP server to receive HTTP requests.  Once the URL reaches the Browser Driver, then the Browser Driver will pass that request to the real browser over HTTP. Then the commands in your selenium script will be executed on the browser.

If the request is POST request then there will be an action on browser

If the request is a GET request then the corresponding response will be generated at the browser end and it will be sent over HTTP to the browser driver and the Browser Driver over JSON Wire Protocol and sends it to the UI (Eclipse IDE).

This is how Selenium Commands works internally.

To get more details please watch below youtube video and Subscribe the channel.


Selenium WebDriver: First Selenium Program

Prerequisites to run first simple WebDriver Program are:

1. Java IDE (Eclipse/ IntelliJ) - Environment that you will use to write your code in.
2. Selenium Webdriver libraries - Libraries which allows you use all the Selenium functions and classes.
3. Browser drivers (Chrome/ Firefox/IE) - The driver with with Selenium WebDriver communicates.

To get more details please watch below youtube video and Subscribe the channel.


Selenium WebDriver: Download and Install Java and Eclipse

Java is a general-purpose computer-programming language that is concurrent, class-based, object-oriented. It is intended to let application developers "write once, run anywhere.

Let's understand what is JDK, JRE and JVN in brief.

JDK
Java Development Kit is the core component of Java Environment and provides all the tools, executables and binaries required to compile, debug and execute a Java Program. JDK is a platform-specific software and that’s why we have separate installers for Windows, Mac, and Unix systems. We can say that JDK is the superset of JRE since it contains JRE with Java compiler, debugger, and core classes.

JRE
JRE is the implementation of JVM, it provides a platform to execute java programs. JRE consists of JVM and java binaries and other classes to execute any program successfully. JRE doesn’t contain any development tools like java compiler, debugger etc.

JVM
JVM is the heart of Java programming language. When we run a program, JVM is responsible for converting Byte code to the machine specific code. JVM is also platform dependent and provides core java functions like memory management, garbage collection, security etc.

To get more details please watch below youtube video and Subscribe the channel.



Selenium WebDriver: Selenium and it’s History

What is Selenium?

Selenium is a free (open source) automated testing suite for web applications across different browsers and platforms.

Selenium is not just a single tool but a suite of software's, each catering to different testing needs of an organization. It has four components.

Selenium Integrated Development Environment (IDE)
Selenium Remote Control (RC)
WebDriver
Selenium Grid

Selenium Core

The story starts in 2004 at ThoughtWorks in Chicago, with Jason Huggins building the Core mode as "JavaScriptTestRunner“. Its JavaScript program that would automatically control the browser's actions.
Jason Huggins
“JavaScriptTestRunner” was later named as “Selenium Core” and released into the market as an Open Source tool.

This Open Source tool started gaining demand in the market and people started using it for automating the repeated tasks in their Web Applications.

Selenium Remote Control

Unfortunately; testers using Selenium Core had to install the whole application under test and the web server on their own local computers because of the restrictions imposed by the same origin policy. To resolve this another ThoughtWork's engineer, Paul Hammant created system (in 2007) known as the Selenium Remote Control or Selenium 1.

Selenium 1 = Selenium IDE + Selenium RC + Selenium Grid

Paul Hammant

Selenium Grid


Patrick Lightbody to address the need of minimizing test execution times as much as possible, So he created Selenium Grid. Basically grid is for parallel execution and execute your test scripts on multiple environments.

Patrick Lightbody
Using “Selenium Grid”, testers were able to distribute the tests across multiple machines and get them executed them on different machines over their network to reduce or minimize the time taken for overall execution of tests.

Selenium IDE

“Shinya Kasatani”, who developed a Firefox extension named as “Selenium IDE”.

“Selenium IDE” using its record and playback feature, records the automation tests like recording a video and executes the recorded tests like playing the recorded videos.
Shinya Kasatani
Selenium WebDriver

Earlier Selenium 1 used to be the major project of Selenium.

Selenium 1 = Selenium IDE + Selenium RC + Selenium Grid

Later Selenium Team has decided to merge both Selenium WebDriver and Selenium RC to form a more powerful Selenium tool.

They both got merged to form “Selenium 2”

“Selenium WebDriver” was the core of “Selenium 2” and “Selenium RC” used to run in maintenance mode.

Hence Selenium 2 = Selenium IDE + Selenium WebDriver 2.x + Selenium Grid.

“Selenium 2” released on July 8, 2011.

Selenium team has decided to completely remove the dependency for Selenium RC.

After 5 years, “Selenium 3" was released on October 13, 2016 with a major change, which is the original Selenium Core implementation and replacing it with one backed by WebDriver and lot more improvements.

Hence Selenium 3 = Selenium IDE + Selenium WebDriver 3.x + Selenium Grid.

After 3 years from it’s a major release, now Selenium has put out its first alpha version of Selenium 4 on Apr 24, 2019. Still, there is no official announcement about the release date of Selenium 4, but we are expecting it around October 2019. Till that there can be several alpha or beta versions released time to time with stabilization.

To get more details please watch below youtube video and Subscribe the channel.