How to Reverse an arrayList in Java using Collections and Recursion ?

To reverse a List in Java e.g. ArrayList or LinkedList, you should always use the Collections.reverse() method. It's safe and tested and probably perform better than the first version of the method you write to reverse an ArrayList in Java
In this tutorial, I'll show you how to reverse an ArrayList of String using recursion as well. 

In a recursive algorithm, a function calls itself to do the job. After each pass problem becomes smaller and smaller until it reaches to the base case 

In order to reverse a List using recursion our base case is a list of one element. If your list contains one element then the reverse of that list is the list itself, so just return it. Now, on each pass we need to add the last element on the list into a new list called reversed. Once the program reaches to base case and starts winding down, we end up all the elements in the reverse order. To accommodate that, we have  used the addAll() method of java.util.Collection class.


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class TestSolution {
 public static void main(String args[]) {
List<String> books = new ArrayList<>(); 
books.add("Beautiful Code");
 books.add("Clean Code");
 books.add("Working Effectively with Legacy Code");
System.out.println("Original order of List: " + books);
Collections.reverse(books); 
System.out.println("The reversed List: " + books);
 // Now, let's try to reverse a List using recursion List<String> output = reverseListRecursively(books); 
System.out.println("Reversed list reversed again: " + output); } 
/** * A recursive algorithm to reverse a List in Java * * @param list * @return */
 private static List<String> reverseListRecursively(List<Stringlist) {
 if (list.size() <= 1) { 
return list;
                                      }
 List<String> reversed = new ArrayList<>();
 reversed.add(list.get(list.size() - 1)); // last element 
reversed.addAll(reverseListRecursively(list.subList(0list.size() - 1)));
 return reversed; 
      }
 } 

Output Original order of List: [Beautiful Code, Clean Code, Working Effectively with Legacy Code] The reversed List: [Working Effectively with Legacy Code, Clean Code, Beautiful Code] Reversed list reversed again: [Beautiful Code, Clean Code, Working Effectively with

Built-in Functions In Python - Letter E



enumerate(sequence, start=0)

Return an enumerate object. sequence must be a sequence, an iterator, or some other object which supports iteration. The next() method of the iterator returned by enumerate() returns a tuple containing a count (from start which defaults to 0) and the values obtained from iterating over sequence:

>>>
>>> seasons = ['Spring', 'Summer', 'Fall', 'Winter']
>>> list(enumerate(seasons))
[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
>>> list(enumerate(seasons, start=1))
[(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]
Equivalent to:

def enumerate(sequence, start=0):
    n = start
    for elem in sequence:
        yield n, elem
        n += 1
New in version 2.3.


eval(expression[, globals[, locals]])

The arguments are a Unicode or Latin-1 encoded string and optional globals and locals. If provided, globals must be a dictionary. If provided, locals can be any mapping object.


The expression argument is parsed and evaluated as a Python expression (technically speaking, a condition list) using the globals and locals dictionaries as global and local namespace. If the globals dictionary is present and lacks ‘__builtins__’, the current globals are copied into globals before expression is parsed. This means that expression normally has full access to the standard __builtin__ module and restricted environments are propagated. If the locals dictionary is omitted it defaults to the globals dictionary. If both dictionaries are omitted, the expression is executed in the environment where eval() is called. The return value is the result of the evaluated expression. Syntax errors are reported as exceptions. Example:

>>>
>>> x = 1
>>> print eval('x+1')
2
This function can also be used to execute arbitrary code objects (such as those created by compile()). In this case pass a code object instead of a string. If the code object has been compiled with 'exec' as the mode argument, eval()‘s return value will be None.

Hints: dynamic execution of statements is supported by the exec statement. Execution of statements from a file is supported by the execfile() function. The globals() and locals() functions returns the current global and local dictionary, respectively, which may be useful to pass around for use by eval() or execfile().

See ast.literal_eval() for a function that can safely evaluate strings with expressions containing only literals.


execfile(filename[, globals[, locals]])

This function is similar to the exec statement, but parses a file instead of a string. It is different from the import statement in that it does not use the module administration — it reads the file unconditionally and does not create a new module. [1]

The arguments are a file name and two optional dictionaries. The file is parsed and evaluated as a sequence of Python statements (similarly to a module) using the globals and locals dictionaries as global and local namespace. If provided, locals can be any mapping object. Remember that at module level, globals and locals are the same dictionary. If two separate objects are passed as globals and locals, the code will be executed as if it were embedded in a class definition.


If the locals dictionary is omitted it defaults to the globals dictionary. If both dictionaries are omitted, the expression is executed in the environment where execfile() is called. The return value is None.

Note The default locals act as described for function locals() below: modifications to the default locals dictionary should not be attempted. Pass an explicit locals dictionary if you need to see effects of the code on locals after function execfile() returns. execfile() cannot be used reliably to modify a function’s locals.

Built-in Functions In Python - Letter D


delattr(object, name)
The arguments are an object and a string. The string must be the name of one of the object’s attributes. The function deletes the named attribute, provided the object allows it. For example, delattr(x, 'foobar') is equivalent to del x.foobar.
class dict(**kwarg)
class dict(mapping, **kwarg)
class dict(iterable, **kwarg)
Create a new dictionary. The dict object is the dictionary class. See dict and Mapping Types — dict for documentation about this class.
For other containers see the built-in list, set, and tuple classes, as well as the collections module.                                                                                                                                                                   
dir([object])
Without arguments, return the list of names in the current local scope. With an argument, attempt to return a list of valid attributes for that object.
If the object has a method named __dir__(), this method will be called and must return the list of attributes. This allows objects that implement a custom __getattr__() or __getattribute__() function to customize the way dir() reports their attributes.
If the object does not provide __dir__(), the function tries its best to gather information from the object’s __dict__ attribute, if defined, and from its type object. The resulting list is not necessarily complete, and may be inaccurate when the object has a custom __getattr__().
The default dir() mechanism behaves differently with different types of objects, as it attempts to produce the most relevant, rather than complete, information:
If the object is a module object, the list contains the names of the module’s attributes.
If the object is a type or class object, the list contains the names of its attributes, and recursively of the attributes of its bases.
Otherwise, the list contains the object’s attributes’ names, the names of its class’s attributes, and recursively of the attributes of its class’s base classes.
The resulting list is sorted alphabetically. For example:
>>>
>>> import struct
>>> dir()   # show the names in the module namespace
['__builtins__', '__doc__', '__name__', 'struct']
>>> dir(struct)   # show the names in the struct module
['Struct', '__builtins__', '__doc__', '__file__', '__name__',
 '__package__', '_clearcache', 'calcsize', 'error', 'pack', 'pack_into',
 'unpack', 'unpack_from']
>>> class Shape(object):
        def __dir__(self):
            return ['area', 'perimeter', 'location']
>>> s = Shape()
>>> dir(s)
['area', 'perimeter', 'location']
Note Because dir() is supplied primarily as a convenience for use at an interactive prompt, it tries to supply an interesting set of names more than it tries to supply a rigorously or consistently defined set of names, and its detailed behavior may change across releases. For example, metaclass attributes are not in the result list when the argument is a class.                   
divmod(a, b)
Take two (non complex) numbers as arguments and return a pair of numbers consisting of their quotient and remainder when using long division. With mixed operand types, the rules for binary arithmetic operators apply. For plain and long integers, the result is the same as (a // b, a % b). For floating point numbers the result is (q, a % b), where q is usually math.floor(a / b) but may be 1 less than that. In any case q * b + a % b is very close to a, if a % b is non-zero it has the same sign as b, and 0 <= abs(a % b) < abs(b).
Changed in version 2.3: Using divmod() with complex numbers is deprecated.
enumerate(sequence, start=0)
Return an enumerate object. sequence must be a sequence, an iterator, or some other object which supports iteration. The next() method of the iterator returned by enumerate() returns a tuple containing a count (from start which defaults to 0) and the values obtained from iterating oversequence:
>>>
>>> seasons = ['Spring', 'Summer', 'Fall', 'Winter']
>>> list(enumerate(seasons))
[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
>>> list(enumerate(seasons, start=1))
[(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]
Equivalent to:
def enumerate(sequence, start=0):
    n = start
    for elem in sequence:
        yield n, elem
        n += 1





Difference between method Overriding and Overloading in Java


1)
Method overloading is used to increase the readability of the program.
Method overriding is used to provide the specific implementation of the method that is already provided by its super class.
2)
Method overloading is performed within class.
Method overriding occurs in two classes that have IS-A (inheritance) relationship.
3)
In case of method overloading, parameter must be different.
In case of method overriding, parameter must be same.
4)
Method overloading is the example of compile time polymorphism.
Method overriding is the example of run time polymorphism.
5)
In java, method overloading can't be performed by changing return type of the method only. Return type can be same or different in method overloading. But you must have to change the parameter.
Return type must be same or covariant in method overriding.
Java Method Overloading example

  1. class OverloadingExample{  
  2. static int add(int a,int b){return a+b;}  
  3. static int add(int a,int b,int c){return a+b+c;}  
  4. }  
Java Method Overriding example

  1. class Animal{  
  2. void eat(){System.out.println("eating...");}  
  3. }  
  4. class Dog extends Animal{  
  5. void eat(){System.out.println("eating bread...");}  
  6. }  

How to set ADB Path in System Variable ? : Android , Mobile automation testing

Check the installation path and if it's installed in C:\Program Files (x86)\Android . This is the default installation location.
So update the PATH variable with following line.
C:\Program Files (x86)\Android\android-sdk\tools\;C:\Program Files (x86)\Android\android-sdk\platform-tools\

Now you can start ADB server from CMD regardless of where the prompt is at.

Android SDK ADB server in CMD screen

How to edit a system variable

Here's a short how-to for the newbies. What you need is the Environment Variables dialog.
  1. Click Start (Orb) menu button.
  2. Right click on Computer icon.
  3. Click on Properties. This will bring up System window in Control Panel.
  4. Click on Advanced System Settings on the left. This will bring up the System Properties window with Advanced tab selected.
  5. Click on Environment Variables button on the bottom of the dialog. This brings up the Environment Variables dialog.
  6. In the System Variables section, scroll down till you see Path.
  7. Click on Path to select it, then the Edit button. This will bring up the Edit System Variable dialog.
  8. While the Variable value field is selected, press the End key on your keyboard to go to the right end of the line, or use the arrow keys to move the marker to the end.
  9. Type in ;C:\Program Files (x86)\Android\android-sdk\tools\;C:\Program Files (x86)\Android\android-sdk\platform-tools\ and click OK.
  10. Click OK again, then OK once more to save and exit out of the dialogs.
That's it! You can now start any Android SDK tool, e.g. ADB or Fastboot, regardless of what your current directory is in CMD. For good measure here's what the dialog looks like. This is where you edit the Path variable.

environment variables

List of tools used for automated cross-browser testing of Ajax websites


Sahi (http://sahi.co.in/) can also be added to this list. Some good points about Sahi:

1) It handles AJAX/page load delays automatically. No need for explicit wait statements in code.

2) It can handle applications with dynamically generated ids. It has easy identification mechanisms to relate one element to another (example. click the delete button near user "Ram"). ExtJS, ZkOSS, GWT, SmartGWT etc. have been handled via Sahi.
Sample link:
http://books.zkoss.org/wiki/Smal...

3) It traverses frames/iframes automatically.

4) It can record or spy on objects on all browsers. Particularly useful if Internet Explorer is a target browser.

For standalone tools, you are pretty much limited to the following two choices:

- Webdriver / Selenium 2.0 : http://code.google.com/p/selenium/
- Watir:  http://watir.com/

Note that these are two low-level tools that let you control browsers, they are not complete automation frameworks on their own.  To complete the framework check out wrappers including:
- Capybara  https://github.com/jnicklas/capy...
- Webrat   https://github.com/brynary/webra...
- Cucumber  http://cukes.info/

*Note that the above frameworks are not mutually exclusive, it is possible to create a cucumber / capybara framework for example.

There is also at least one cloud based service which seems to offer a complete solution:
http://saucelabs.com/


So out of all that, what is the best?  It depends on your needs and skills.
In my opinion Webdriver offers the best support for AJAX heavy websites and the most flexibility overall to do any kind of testing you might need (checking emails, interrogating or changing the state of a DB).  The flexibility comes at the price of some complexity however.

I dont have experience with Saucelabs, but alot of people like it, so for a team with limited skills and/or testing infrastucture it might make alot of sense to use a service based solution, Saucelabs is definitely the leader here.


Another good cloud based service which offers cross browser testing by using Selenium ishttp://testingbot.com

You can basically test in all major browsers and even in an Android emulator. You create 1 test with Selenium IDE, upload it to the website and set it up to run on a daily basis. When the test fails they can alert you.


I know a good testing tool-TestingWhiz (http://www.testing-whiz.com). Its quite intuitive and affordable tool as compared to Selenium and QTP but limited to functional testing.The main thing about it is that it requires less or no coding which is not the case with other tools.

In my opinion working with Ajax websites could be quite easier with TestingWhiz also supports cross-browser testing.All you need is to record the test cases and you can run in any browser within few clicks.


Out of my personal experience, working with AJAX based websites is a bit tricky
But WATIN works like a charm

The framework has been written in c# and its easy to learn c# rather than any other framework which needs scripting capabilities like RUBY.

The flow has been seemless with no jerly moments. Since that is also has screen recording facility, you can capture enough no. of flows.



Why is everyone Obsessed with BIG Data ?


What is Big Data?


Big data is data that exceeds the processing capacity of conventional database systems. The data is too big, moves too fast, or doesn’t fit the strictures of your database architectures. To gain value from this data, you must choose an alternative way to process it.


Alerts in Java



JavaScript Alerts


Webdriver has  Alerts API to handle JavaScript Alerts. Alert is an interface. 


// Get a handle to the open alert, prompt or confirmation
Alert alert = driver.switchTo().alert();
Alert is an interface. There below are the methods that are used
//Will Click on OK button.
alert.accept();
// Will click on Cancel button.
alert.dismiss()
//will get the text which is present on the Alert.
alert.getText();
//Will pass the text to the prompt popup
alert.sendkeys();
//Is used to Authenticate by passing the credentials
alert.authenticateUsing(Credentials credentials)

Would you like to see you post published here ?

Want reach out to millions of readers out there? Send in your posts to
softwaretestinganeasyway@gmail.com
We will help you reach out to the vast community of testers and let the world notice you.