Give an example of a program that uses the nongeneric version of a class from the STL and the equivalent program that uses the generic version. How do the two implementations differ? Why is having the syntax of generics better? Solution //non-generic version class StringFunc{ String func(String n) { String result=\" \"; int i; for(i=str.length()-1;i>=0;i--) result +=str.charAt(i); return result; } } class demo{ public static void main(String args[]){ StringFunc ssf=new StringFunc(); System.out.println(\"reverse:\"+ssf.func(\"hie\")); } } //generic functional interface class gener<T>{ T fun(T t); } class geneDemo{ public static void main(String args[]){ gener<String> reverse=(str) -> { String result=\" \"; int i; for(i=str.length()-1;i>=0;i--) result+=str.charAt(i); return result; }; System.out.println(\"revers\"+reverse.fun(\"hie\")); geneDemo<Integer> add=(n) -> { return n+n; }; System.out.println(\"add:\"+add.fun(3)); } } If you observe the above given two programs, the program in which includes generic implementation a class and functions in the class are doing the job for two different kinds of datatypes and implementation. Generic classes are used in scenario in which same function and definition is used for more than one implementation.. Syntax of generic is better because in the above program two different fucntionalities one with integer type and oter with string type are done by a single function whereas in genral scenario there is a need to write two different functions wit respective return types even though two classes have same type of declaration body if we want to do string reverse and addition of number to itself both of these have same function declaration that is string func(string) int func1(int) So in genral case we write two different functions, whereas in genric implementaion this can be done by class Class_name<T>{ T func(T t) } instead of two functions we can do the work using one function .