GenericsWhat is Generics?Generics is the capability to param

GenericsWhat is Generics?Generics is the capability to parameterize types. With this capability, you can define a class or a method with generic types that can be substituted using concrete types by the compiler. For example, you may define a generic stack class that stores the elements of a generic type. From this generic class, you may create a stack object for holding strings and a stack object for holding numbers. Here, strings and numbers are concrete types that replace the generic type.Why Use Generics?The key benefit of generics is to enable errors to be detected at compile time rather than at runtime. A generic class or method permits you to specify allowable types of objects that the class or method may work with. If you attempt to use the class or method with an incompatible object, a compile error occurs.Generics Method Example: public static

void reverseList(E[] list) { for (int i1 = 0, i2 = list.length-1; i1 < list.length/2; i1++, i2–){ E temp = list[i1]; list[i1] = list[i2]; list[i2] = temp; } }Generic Class Example:public class GenericStack

{ private java.util.ArrayList

list = new java.util.ArrayList<>(); public int getSize() { return list.size(); } public E peek() { return list.get(getSize() – 1); } public void push(E o) { // puts parameter at the end of the ArrayList list.add(o); } public E pop() { // removes the last item in the ArrayList E o = list.get(getSize() – 1); list.remove(getSize() – 1); return o; } public boolean isEmpty() { return list.isEmpty(); } @Override public String toString() { return ‘stack: ‘ + list.toString(); }}Read Oracle’s Java tutorial pages about Generics by clicking on the link below, and the Liang textbook (Chapter 19 ‘Generics’) for more details about how to use Java Generics, then do Exercise 10.1 below.http://docs.oracle.com/javase/tutorial/java/generics/index.htmlExercise 10.1 (no late submissions allowed, upload the .java document)Write a generic static method in Java that prints each element in a generic array in REVERSE ARRAY ORDER (in which each element is of the generic type), one element per line, but DON’T CHANGE THE ORDER OF THE ARRAY ELEMENTS. This method must have a generic array (NOT ArrayList nor other class) as its ONLY parameter.Write main so it tests this method (put in the class with the generic method). Call the method passing an array of Doubles with at least 5 elements, then an array of Strings with at least 7 elements. RUN THE PROGRAM. Upload the .java file with the output copied and pasted to the end of the file, commented out.