Saturday, 23 November 2019

SE - 42 - Major interfaces used in Selenium

Lets see few of the interfaces which are used in Selenium. The list also contains few of the JAVA interfaces which may be used in terms of Selenium :

1) WebDriver
2) WebElement
3) Alert
4) TakesScreenshoot
5) All the Listners (Eg : WebdriverEventListener , ItestListener ,etc)
6) SearchContext
7) Iterable , Collection,List,Queue, Set , etc
8) Wait
9) Comparator
10)JavaScriptExecutor
11) Row , Cell (Apache POI)

SE - 41 - Island of isolation in JAVA

Island of isolation is a term given to a condition where 2 objects are ready for garbage collection when the following conditions are met :

1) Object 1 references to Object 2
2) Object 2 references to Object 1

      Test i;
      public static void main(String[] args) 
      {
          Test t1 = new Test();
          Test t2 = new Test();
          t1.i = t2;
          t2.i = t1;
          t1 = null;
          t2 = null;
          System.gc();
      }

SE - 13 - Static and non-Static Methods !!

- We can call static methods directly while we can not call non static methods directly. You need to create and instantiate an object of class for calling non static methods.

- Non static stuff (methods, variables) can not be accessible Inside static methods Means we can access only static stuff Inside static methods. Opposite to It, Non static method do not have any such restrictions. We can access static and non static both kind of stuffs Inside non static methods

- Static method Is associated with the class while non static method Is associated with an object.

- Static methods can't be overrided in java. If we try to override a static method Java treats it as a new method and rule of parent/child doesn't applies to it

-Static methods can be overloaded in JAVA with rules of overloading

Monday, 18 November 2019

SE - 16 - Caching in Java for Integers

In java "==" is used to compare object references. The caching in Java allows to reuse the referenced objects and save memory. So in the given range of caching the same object reference is used and the comparison results as true while beyond the range it returns false.

Note :
1) Caching was introduced in Java 5
2) It basically improves the performance
3) Caching range lies between -127 to +127
4) Caching applies for Integer , Byte , short , Long and Character objects too
5) It only works for autoboxed type of objects. It is not applicable for normal object declaration(eg : Integer integer1 = new Integer(123);.


Example :
 public static void main(String[] args) {
  Integer integer1 = 123;
  Integer integer2 = 123;
  
  Integer integer3 = 128;
  Integer integer4 = 128;
  
  if (integer1 == integer2)
   System.out.println("integer1 == integer2");
  else
   System.out.println("integer1 != integer2");
  
  if (integer3 == integer4)
   System.out.println("integer3 == integer4");
  else
   System.out.println("integer3 != integer4");
  
 }


Output:
integer1 == integer2
integer3 != integer4





SE - 15 - String methods in Java !

1) To compare two strings
 - str1.compareTo(str2) [3-way comparison (positive ,negative,0)]
 - str1.equals(str2) [2-way comparison(true,false)]

2) To join 2 strings
 - str1.concat(str2) [Its a method]
 - str1 + str2 [Its a operator]

3) to find the character by index position
 - str1.charAt(1)

4) to compare 2 strings ignoring the case
 - str1.equalsIgnoreCase(str2);

5) to convert a string to upper or lower case
 - Str1.toUppercase();
 - Str1.toLowercase();

6) to remove spaces from both sides of string
 - str1.trim();

7) to trim a part of string
 - Str1.substring(2,12); [based on index]

8) It checks that a string ends\starts with specified suffix and it result boolean result
 - str.endsWith("ABC") [checks if the string ends with ABC]
 - str.startsWith("ABC") [checks if the string starts with ABC]

9) to find the length of a string
- str.length();

10) to replace any word with given word in a string
 - str1.replace("AB","CD")


SE - 40 - Copy Constructor in Java

We can create a copy constructor by giving the parameter as object of same class . Once created then we copy each field  of the input object into the new instance

Note :
1) Java never creates a copy constructor by default rather we need to manually create it.
2) Copy constructor and cloning in Java are not same

public class Student {
    private int roll;
    private String name;
     
    public Employee(Student stu) {
        this.id = stu.roll;
        this.name = stu.name;
    }
}



SE - 39 - Some basics about thread in Java

Lets see some of the basics about thread in java :

1) Thread can't be started twice. It can be started only once by using start() method. If we attempt to start the thread twice we get IllegalThreadStateException.

2) We can create Thread in Java in 2 ways :
     a) By implementation of Runnable class
     b) By extending Thread class

3) Only start() method is used to start the thread. If we call the run() method then the Thread will not be called rather it will behave as normal method calling

4)  Suppose if there is any statement written (Eg : printing some text , etc) after start() method in thread then in output we will see the thread initiated after the execution of next statement.  Java will execute the next statement then start the thread.