Tuesday, January 29, 2019

Write a Java program to find whether given number is Armstrong or not
Armstrong numbers are: 153, 370, 371, 407
Definition: We call a given number as Armstrong if it is equal to the sum of the powers of its own digits.
Ex: abcd...n => pow(a,n) + pow(b,n) + pow(c,n) + pow(d,n) + .... =abcd...n
Answer:
package seleniumrepo;

import java.util.Scanner;
class ArmstrongNumber{
          public static void main(String args[]){
                int n, sum = 0, temp, r;
                Scanner in = new Scanner(System.in);
                System.out.println("Enter a number to check if it is an armstrong number");   
                n = in.nextInt();
                temp = n;
                while( n!= 0 ){
                       r = n%10;
                       sum = sum + r*r*r;
                       n= n/10;
                 }
                 if ( temp == sum )
                       System.out.println("Entered number is an armstrong number.");
                  else
                       System.out.println("Entered number is not an armstrong number."); 
   
                 in.close();
         }
}


Based on the type of data stored, data types are classifying as 3 types in Java.
  1. Primitive Datatype (Fundamental Datatype):
  2. Derived Datatype
  3. User Defined Datatype
Primitive Datatype (Fundamental Datatype)
The datatype which stores only single value is Primitive datatype. Primitive datatypes are also known as fundamental datatypes. In java programming language, there are 8 primitive datatypes classified into 4 categories.
  • Integer type category
  • Floating-point category
  • Character type category
  • Boolean type category
            Ex: int, float, char etc.,
Derived Datatypes: 
Derived datatypes are pre-defined datatypes given by the programming language. These derived datatypes are created by primitive datatypes and they can be used for storing multiple values.
            Ex: Array
User Defined Datatypes:
These datatypes will be created by the programmer according to application requirement, in which we can store any type of values and number of values.
            Ex: Class

1. Integer Category Data Types:
This category can be used for storing numbers which can be either +ve or -ve without decimal points.
We have 4 types under integer category. The size and range are as below:
 Data Type                               Size                                                 Range
  byte                                       1 Byte (2^8)                               -128 to 127
  short                                      2 Bytes                                       -32768 to 32767
  int                                          4 Bytes                              -2,147,483,648 to 2,147,483,647
  long                                       8 Bytes        -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

2. Floating-Point Category Data Types:
This category can be used for storing numbers which can be +ve or -ve with decimal points. We have two types under floating point category:
Data Type                               Size                                                 Range
  float                                       4 Bytes                                  1.4 e^-45 to 3.4 e^38
  double                                   8 Bytes                                  4.9e^-324 to 1.8 e^308

3. Character Type Category Data Type:
This category can be used for storing a single character. A character can be represented by an Alphabet or a digit or a special symbol.
This category contains only one datatype that is Char.
Data Type                               Size                                                 Range
  Char                                    2 Bytes                                             0 to 65535

4. Boolean Type Category Data Type:
This category can be used for storing either True or False. We have only one datatype under this category that is Boolean.
Data Type                               Size                                                 Range
  Boolean                          JVM Dependent                                 True or False

Difference between White Box Testing and Black Box Testing:
WBT: This is defined as method of testing in which one can perform testing on an application having internal structural knowledge of it. This is also known as Glass Box Testing.
  • This testing focuses on the structural part of an application and hence the Developers are involved in this type of testing.
BBT: This is defined as the method of testing in which one can perform testing on an application with much focus on functional part of it and ever without having an internal structural knowledge of application.

  • Actually the Test Engineers are involved in the BBT. 

Monday, January 28, 2019


                   package seleniumrepo;

                          public class ExtractNumerics{
                              public static void main(String[] args) {
                                      ExtractNumerics e=new ExtractNumerics();
                                      e.getInteger("!@#123HHGasd");
                              } 
                              public void getInteger(String str) {
                                     str=str.replaceAll("[^0-9]", "");
                                     System.out.println(str);
                             }
                         }

Sunday, January 27, 2019

we cannot iterate a Map directly using iterators, because Map are not Collection.
There are different methods to iterate through MAP elements:
Method 1: Using Iterator and keySet().
package seleniumrepo;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class TestIterator {
public static void main(String[] args) {
              Map<String,String> mp=new HashMap<String,String>();
              mp.put("1", "avinash");
              mp.put("2", "venu");
              mp.put("3", "dharma");
              mp.put("4", "hari");
              Iterator<String> it=mp.keySet().iterator();
              while(it.hasNext()){
                    String temp=it.next();
                    System.out.println(temp + " " +mp.get(temp));
              }
}
}

Method 2: Using foreach() method. It is defined as default method in the Map interface.

package seleniumrepo;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class TestIterator {
public static void main(String[] args) {
                Map<String,String> map=new HashMap<String,String>();
                map.put("1", "avinash");
                map.put("2", "venugopal");
                map.put("3", "dharma");
                map.put("4", "hari");
                map.forEach((k,v)->System.out.println("Key: "+k+" Value: "+v));
}

Method 3: Using entrySet() and Map.Entry(K, V).
package javaprograms;

import java.util.HashMap;

import java.util.Map;
public class TestIterator {
public static void main(String[] args) {
                    Map<String,String> map=new HashMap<String,String>();
map.put("1", "avinash");
map.put("70", "venugopal");
map.put("30", "dharma");
map.put("4", "hari");
System.out.println(map.values());
for(Map.Entry<String, String> entry: map.entrySet()) {
 System.out.println("Key: "+entry.getKey()+"\t"+ "Value: "+entry.getValue());
}
}
}

Output:
[avinash, hari, venugopal, dharma]
Key: 1 Value: avinash
Key: 4 Value: hari
Key: 70 Value: venugopal
Key: 30 Value: dharma

package seleniumrepo;

import java.util.Arrays;
/*
 * Check whether two strings are anagram of each other
 * Ex: LISTEN <=> SILENT, TRIANGLE <=> INTEGRAL, HEART <=> EARTH
 */
public class Anagram {
public static void main(String[] args) {
String s="LISTEN";
String s1="SILENT";
char[] ch=s.toCharArray();
char[] ch1=s1.toCharArray();
Arrays.sort(ch);
Arrays.sort(ch1);
if(Arrays.equals(ch, ch1)){
                   System.out.println("True - Given number is words are anagrom of each other");
}else{
                   System.out.println("False - Given number is words are not anagrom of each other");
              }
}
}

Functional Interface: is an interface it contains only one abstract method and declares with annotation @FunctionalInterface
E.g:
                        @FunctionalInterface
                        interface ReverseString{
String reverse(String n);
                        }

    public class ImplementingLamdaExpression {
         public static void main(String args[]){
ReverseString myreverse= str ->{
String result="";
for(int i=str.length()-1;i>0;i--){
result=result+str.charAt(i);
}
return result;
};
System.out.println(myreverse.reverse("avinash"));
}
   }

Why?- To enable functional programming in java we use lamda expression
Advantages of Functional programming:
  • you can assign function to a variable i.e. a=func()
  • you can pass function as parameter to other function i.e. fun(fun)
Examples of functional interface:
     Runnable-> only one abstract method - run()
     Callable-> only one abstract method -  call()
     Comparable-> only one abstract method -compareTo()

Default and static methods in an interface:
     Before 1.8 interface contains only abstract methods. Later, interface allows default static methods

i.e. functional interface can have 100's of default and static methods but should have only one abstract method

Interface interf
{
public void abstract m4();-- This wont throw any error and will not be considered as functional interface as it is having more than on abstract method
public void abstract m1();

public void default m2()
{
}

public void static m3()
{
}

}

@FunctionalInterface(This is the using of @FunctionalInterface annotation)
Interface interf
{

public void abstract m1();
public void abstract m4();-- This will throw error saying that functional interface should have only abstract method
public void default m2()
{
}

public void static m3()
{
}


Lambda Expressions: It is a anonymous(nameless) function. It does not has method name, method return type nor modifiers
           General Method:
                 public void m1(){
                          System.out.println("Hello world");
                 }
           Converting above method into lamda expression:
           for that we use '->' symbol
           no method name,no return type and no modifiers
           () -> {System.out.println("Hello world");}
a. prime or not
Prime number: A prime number is a whole number greater than 1 whose only factors are 1 and itself.
Ans:
---
public class PrimeTest {
public static void main(String[] args) {
int n, i, k=0;
            System.out.println("Enter a positive integer: ");
            Scanner sc = new Scanner(System.in);
            n=sc.nextInt();
            for(i=2;i<=n/2;++i){
                 if(n%i==0){
                       k=1;
                       break;
                 }
             }
             if (k==0)
                  System.out.println(n+" is a prime number");
             else {
                 System.out.println(n+" is not a prime number");
              }
              sc.close();
}
}
Output:
-------
Enter a positive integer: 29
29 is a prime number.
Factorial of a given number using recursion.
public lass FactorialRecursion{
        public static void main(String[] ar){
             System.out.print("Enter a number : ");
             int n;
             Scanner sc=new Scanner(System.in);
             n=sc.nextInt();
             double ans=fact(n);
             System.out.println("The factorial of "+n+" = "+ans);
             sc.close();
        }

        public static double fact(int num){
               if(num==1){
                     return(1);
               }else{
                     return(num*(fact(num-1))); //Calling itself again with a different value.
                 }
        }
}

O/P: Enter a number : 5
The factorial of 5 = 120.0
with out recursion: 
public class Factorial {
       public static void main(String[] args) throws NumberFormatException, IOException  {
               BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
               System.out.println("Enter  the Number");
               int no=Integer.parseInt(br.readLine());
               int fact=1;
               for(int i=1;i<=no;i++){
                     fact=fact*i;
               }
               System.out.println("Factorial is: "+ fact);
       }


}

Saturday, January 26, 2019

/*
* Input: A14BC654 -> acceptable
* Input: AB54C54D -> not acceptable 
* Input: A23BED75 -> acceptable
* Conditions to check: 
* 1) First and Last index values of the string are character and digit respectively 
* 2) If condition 1 is satisfies it prints last number value of the string. For example, the value 654 if we pass first String, should print 75 if we pass 3rd string. 
* Note: 2nd string fails in 1st condition check itself 
*/
METHOD 1:
public class NumbersInString {
public static void main(String[] args) {
String str="A14BC654";
String lastNumber="";
if(str.matches("[a-zA-Z].*[0-9]")) {           // start condition check 1
for(int j=str.length()-1;j>=0;j--) {
if(Character.isDigit(str.charAt(j))) {       // start condition check 2
lastNumber=lastNumber+str.charAt(j);
}else {
break;
}       // closing else block
}       // closing for loop
System.out.println("Last Number of given String is: "+lastNumber);
}else {
System.out.println("String "+str+" is not matched with first condition");
}    // closing condition check 1
}
}
Output: 654

METHOD 2:
public class NumbersInString {
public static void main(String[] args) {
String str="A14BC654";
String lastNumber="";
for(int i=0;i<str.length()-1;i++) {
if(Character.isAlphabetic(str.charAt(0))&&Character.isDigit(str.charAt(str.length()-1))){
for(int j=str.length()-1;j>=0;j--) {
if(Character.isDigit(str.charAt(j))) {
lastNumber=lastNumber+str.charAt(j);
}else {
break;
}
}
System.out.println("Last Number of given String is: "+lastNumber);
break;
}else {
System.out.println("String "+str+" is not mached with first condiation");
}
}
}
Output: 654

Monday, January 21, 2019

Write a Java Program to remove duplicate values from an array?

package seleniumrepo;

public class DisticntElements {
    public static void printDistinctElements(int[] arr){
        for(int i=0;i<arr.length;i++){
            boolean isDistinct = false;
            for(int j=0;j<i;j++){
                if(arr[i] == arr[j]){
                    isDistinct = true;
                    break;
                }
            }
            if(!isDistinct){
                System.out.print(arr[i]+" ");
            }
        }
    }
   
    public static void main(String a[]){
        int[] nums = {5,2,7,2,4,7,8,2,3};
        DisticntElements.printDistinctElements(nums);
    }
}

Saturday, January 19, 2019

Palindrome Number: A Palindrome number is a number that remains the same when its digits are reversed.
We get total 90 numbers between 100 and 1000.

public class PalindromeNumber {

public static void main(String[] args) {

int n=121;
int rev=0;
int temp=n;
while(n!=0){
rev=rev*10+n%10;
n=n/10;
}
if(temp==rev){
System.out.println(temp+" Is Palindrome");
}else{
System.out.println(temp+" Is Not Palindrome");
}
}
}

Thursday, January 17, 2019

All are used to mark a field in a page object.
@FindBy: It is an alternative mechanism for locating the element or a list of elements. Used in conjunction with PageFactory this allows users to quickly and easily create PageObjects. (api link)
Example:
    For example, these two annotations point to the same element:
    Syntax 1:        @FindBy(id = "foobar")
                              WebElement foobar;
                              @FindBy(how = How.ID, using = "foobar")  // How is an enum, ID is an Enum constant
                              WebElement foobar;
and these two annotations point to the same list of elements:
    Syntax 2:          @FindBy(tagName = "a")
                               List<WebElement> links;
                               @FindBy(how = How.TAG_NAME, using = "a")
                               List<WebElement> links;
Note: Alternative way of @FindBys: driver.findElements(new ByChained(by1,by2)); (where by1 -> By by1=By.id("");, by2 -> By by2=By.id("");)
@FindBys: Find for all DOM elements that matches each of the locators in sequence.(api link)
Example:
        @FindBys({@FindBy(id = "foo"),
              @FindBy(className = "bar")})
         private List<WebElement> list;
@FindAll: Search for all elements that match any of the FindBy criteria. (api link)
Example:
        @FindAll({@FindBy(id = "foo"),
              @FindBy(className = "bar")})
private List<WebElement> list;

@CacheLookup: as the name suggests helps us control when to cache a WebElement and when not to. This annotation when applied over a WebElement instructs Selenium to keep a cache of the WebElement instead of searching for the WebElement every time from the WebPage. This helps us save a lot of time. (api link)
Example:
        @CacheLookup
@FindBy(how=How.ID, using="foo")
private WebElement element;

Hope this Helps!!!

MySQL:
Sub queries in SQL are great tool for this kind of scenario, here we first select maximum salary and then another maximum excluding result of subquery
mysql> SELECT max(salary) FROM Employee WHERE salary NOT IN (SELECT max(salary) FROM Employee);
using subquery and < operator instead of IN clause:
mysql> SELECT max(salary) FROM Employee WHERE salary < (SELECT max(salary) FROM Employee);
Oracle:
using ROW_NUMBER
select * from ( select e.*, row_number() over (order by salary desc) as row_num from Employee e ) where row_num = 2;
Using DENSE_RANK():
SELECT * FROM (SELECT S.*,DENSE_RANK() OVER (PARTITION BY DNO ORDER BY SALARY DESC) DR FROM SOURCE ) S WHERE S.DR=2;


A Project Object Model or POM is the fundamental unit of work in Maven. It contains the project configuration details used by Maven.
Some of the configuration that can be specified in the POM are the project dependencies, the plugins or goals that can be executed, the build profiles, and so on.
The minimum requirement for a POM are the following:
  • project root
  • modelVersion - should be set to 4.0.0
  • groupId - the id of the project's group.
  • artifactId - the id of the artifact (project)
  • version - the version of the artifact under the specified group
Here's an example:
  1. <project>
  2. <modelVersion>4.0.0</modelVersion>
  3. <groupId>com.mycompany.app</groupId>
  4. <artifactId>my-app</artifactId>
  5. <version>1</version>
  6. </project>
Maven Version Range in Dependencies:
Upgrading Maven dependencies manually has always been a tedious work, especially in projects with a lot of libraries releasing frequently.
Developers could specify version ranges within which the artifacts would’ve been upgraded without the need of a manual intervention.
Version requirements have the following syntax: ('x' represents version)

  • 1.0 -> "Soft" requirement on 1.0 (just a recommendation, if it matches all other ranges for the dependency)
  • [1.0]: -> "Hard" requirement on 1.0
  • (,1.0]: -> x <= 1.0
  • [1.5,): -> x >= 1.5
  • [1.2,1.3]: -> 1.2 <= x <= 1.3
  • [1.0,2.0): -> 1.0 <= x < 2.0
  • (,1.0],[1.2,): -> x <= 1.0 or x >= 1.2; multiple sets are comma-separated
  • (,1.1),(1.1,): -> this excludes 1.1 (for example if it is known not to work in combination with this library)
A square bracket ( [ & ] ) means "closed" (inclusive).
A parenthesis ( ( & ) ) means "open" (exclusive).
Maven2 has provided two special metaversion values to achieve the result: LATEST and RELEASE.
They’ve been deprecated and completely removed in Maven3 for the sake of reproducible builds.
Note: When you release a software, you should always make sure that your project depends on specific versions to reduce the chances of your build or your project being affected by a software release not under your control.

public static void main(String[] args){} or public static void main(String... args){}:
Java main method is the entry point of any java program. Its syntax is always "public static void main(String[] args)". You can only change the name of String array argument.
public: This is an access modifier means this method can be accessed anywhere.
static: The main() method can be accessed directly with the class name without instantiation. When java runtime starts, there is no object of the class present initially. That’s why the main method has to be static so that JVM can load the class into memory and call the main method.
void: tells the compiler main doesn't return any value.
main: method name. It’s fixed and when we start a java program, JVM looks for the main method.
String[] args: method accepts an argument of type String array. This also called command line arguments. Argument name can be anything instead of args.
We can also specify parameter as "String... args".
If we tried to change parameter type as "Integer[]" then JVM doesn't allow you to run a java application in eclipse.
Example: Class name: TestClass

Passing Command Line Arguments in Eclipse:
It is another style of giving values to the program at runtime. Here arguments are passed at running time (not readily at compile time); the traditional way is through method calls and taking input from keyboard
Method 1: Right on class name -> Run As -> Run Configurations...
Click on Arguments Tab, enter the text in Program Arguments section as below:

The output will appear as below for the above program:
The value of args[0] is: I
The value of args[1] is: love
The value of args[2] is: my
The value of args[3] is: India

Method 2: Create an another class TestClass2 and call main of TestClass1 in TestClass2 by passing a String type array as argument value. See the below code:
Run TestClass2, Output get as below:
The value of args[0] is: Apple
The value of args[1] is: Banana
The value of args[2] is: Orange
The value of args[3] is: Grapes



Why not List<String> listString = new ArrayList<String>(); 
You can assign an ArrayList<String> to a List<String> reference variable, but you can never assign an object with one generic type to an object with another generic type, no matter what inheritance there is.
Above code gives compile time Error "Type mismatch: cannot convert from ArrayList<String> to List<Object>".



Note:
Object o1=new String();  -> Possible (Upcasting and Automatic in Java)
Stringo1=new Object ();  -> Not Possible

Wednesday, January 9, 2019

Write a Java Program to print Fibonacci  series up to 10
   
   public class Fibonacci {
public static void main(String[] args) {
int num = 10; 
System.out.println("*****Fibonacci Series*****");
int f1=0, f2=0, f3=1;
for(int i=1;i<=num;i++){
if(f2<=10) {
System.out.print(" "+f2+" ");
}
f1 = f2;
f2 = f3;
f3 = f1 + f2;
}
}
   }
Output:
*****Fibonacci Series*****

 0  1  1  2  3  5  8 

Tuesday, January 8, 2019

Software Testing: 
The process of verifying or validating an application with the intention of finding bugs or defect in software so that it could be corrected before product is delivered to the end user. 
                                                            (OR)
It is an activity to verify whether actual results are matched with expected results and ensure software is defect free, provide customer satisfaction.
Software testing has come to play a vital role in the success of the business.
This can be done through either manually or using automation tool.
Project vs Product:
ProjectIf a software application designs for a specific client, then it is called PROJECT. 
                                                            (OR)
    If any organization is developing the application according to the client specification then it is called as project
Ex: Banking web sites like HDFC Netbanking site, IRCTC, APSRTC etc.,
ProductIf a software application is design for multiple clients, then it is called a PRODUCT. 
                                                           (OR)
If any organization is developing the application and marketing it is called as PRODUCT.
Example: Windows, Gmail, WhatsApp etc.,
Types of Software Testing:
  1. Functional Testing
  2. Non-Functional Testing
Functional Testing: Functional Test is a type of software testing whereby the system is tested against the functional requirements/specifications.
Functional testing is done to verify all the functionality of a product. 
This testing mainly involves black box testing and it is not concerned about the source code of the application. The Testing can be done either manually or using Automation tool.
Typically, functional testing involves the following steps:
    • Identify functions that the software is expected to perform.
    • Create input data based on the function’s specifications.
    • Determine the output based on the function’s specifications.
    • Execute the test case.
    • Compare the actual and expected outputs.
Non-Functional Testingtype of Software testing to check non-functional aspects of a software application. Non functional testing activities includes:
    • Performance testing
    • Load Testing
    • Stress testing
    • Volume testing
    • Security testing
    • Installation testing
    • Compatibility Testing
    • Recovery testing


Sunday, January 6, 2019

Both Iterator and Iterable are interfaces in Java Collection Framework. Here are some differences:
Iterator: Iterator  is an interface that manages iteration over an Iterable. It maintains a state of where we are in the current iteration, and knows what the next element is and how to get it. See API here
Iterator lets you check if it has more elements using hasNext() and move to the next element (if any) using next().
This interface is a member of the Java Collections Framework. It has the methods hasNext(), next(), remove()
Iterable: Implementing this interface allows an object to be the target of the "for-each loop" statement. See Iterable API here.
An iterable produces iterators

Both are interfaces in Java. Here some common differences between Comparator and Comparable.
  1. Comparator in Java is defined in java.util package while Comparable interface in Java is defined in java.lang package.
  2. Comparator has the method int compare(T o1,T o2) which compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. While Comparable has method public int compareTo(T o) which returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
  3. compare method of Comparator compares its two arguments for order. compareTo method of Comparable interface compares this object with the specified object for order.
  4. Comparator has equals(Object obj) method while Comparable doesn't.
It is very frequently asked interview question for me. I was no answer as till now we know only we need drivers( like chromedriver.exe, geckodriver.exe, IEDriverServer.exe) and pass them to the System.setProperty() to launch a browser using selenium web driver. But why?
Reason:
As selenium WebDriver has no native implementation of a browser, we have to direct all the webdriver commands through a driver server (driver file).
Driver server is a standalone server which implements WebDriver's wire protocol.
Wire protocol defines a RESTful web service using JSON over HTTP and is implemented in request/response pairs of "commands" and "responses".
The wire protocol will inherit its status codes from those used by the Driver Server.
Each Driver implements Webdriver protocol and starts a server on your system.  All your tests communicate to this server to run your tests
Note: Each browser contains web browser engine. To display the web content, the web browser engine is required. There are different web browser engines and driver servers for each web browsers.


Hope this helps!!!

Friday, January 4, 2019

Difference between HashMap and ConcurrentHashMap:
  • ConcurrentHashMap is thread-safe that is the code can be accessed by single thread at a time. while HashMap is not thread-safe
  • HashMap can be synchronized by using synchronizedMap(HashMap) method. By using this method we get a HashMap object which is equivalent to the HashTable object. So every modification is performed on  Map is locked on Map object. ConcurrentHashMap is by default synchronized
  • ConcurrentHashMap does not allow NULL values . So the key can not be null in ConcurrentHashMap. While In HashMap there can only be one null key.
  • In multiple threaded environment HashMap is usually faster than ConcurrentHashMap. As only single thread can access the certain portion of the Map and thus reducing the performance. While in HashMap any number of threads can access the code at the same time.



Thursday, January 3, 2019

Java API provides foreach() method since jdk1.8v.
This method traverses each element of the collection until all elements have been Processed by the method or an exception is raised.
Exceptions thrown by the Operation are passed to the caller.
foreach() is defined as default method in Iterable interface and overiden in ArrayList and Arrays classes.
(Note: interface allows default and static keywords since jdk1.8v)
Implementation in ArraList:
ArrayList Class implements List interface extends Collection interface extends Iterable interface
 foreach() implementation in Iterable:
default void forEach(Consumer<? super T> action) {
        Objects.requireNonNull(action);
        for (T t : this) {
            action.accept(t);
        }
}

overridden method in ArrayList as below:

@Override
        @SuppressWarnings("unchecked")
        public void forEachRemaining(Consumer<? super E> consumer) {
        }

Parameter: This method takes a parameter action which represents the action to be performed for each element.
Returns: This method does not returns anything.
Exception: This method throws NullPointerException if the specified action is null.
In Java 8 using lambda expressions we can simply replace for-each loop with
elements.forEach (e -> System.out.println(e) );
Map in Java does not extends Iterable. Map itself has its own forEach method that you can use to iterate through key-value pairs. Which is not overriden.

Static is a keyword in Java, which is used for
    1. static blocks
    2. variables
    3. methods and 
    4. inner classes or nested classes
  • A static member can be accessed directly with the class name with out creating an object. 
  • The value of the  static variable is shared by all objects of a class means same set of copy available to all the objects.
  • If any variable is modified by an object those changes visible to every object. Static content doesn't belongs to any particular instance or object.
Static can not be used for Outer most class class. Why?
  1. Every class is already common to all the objects. No need to make class static to become available to all the objects
  2. A class is belongs to package level. Class can be accessed directly with <package_name.ClassName>. No need to make class as static.

selenium-repo by venu

Blog helps to a student or IT employee to develop or improve skills in Software Testing.
For Online Classes Email us: gadiparthi122@mail.com

Followers

About Me

My photo
Hyderabad, Andhra Pradesh, India
I am Automation Testing Professional. I have completed my graduation in B.Tech (Computers) from JNTU Hyderabad and started my career in Software Testing accidentally since then, I passionate on learning new technologies

Contact Form

Name

Email *

Message *

Popular Posts