Techhgeekz ™

Monday 30 December 2013

Generics in Java ..!

Generics :-

Enable types (classes and interfaces) to be parameters when defining classes, interfaces and methods. Much like the more familiar formal parameters used in method declarations, type parameters provide a way for you to re-use the same code with different inputs. The difference is that the inputs to formal parameters are values, while the inputs to type parameters are types.

Hope this Quote would resolve yur  Fuzzy about Generics ..! ;) 

Code that uses generics has many benefits over non-generic code:

Stronger type checks at compile time.

A Java compiler applies strong type checking to generic code and issues errors if the code violates type safety.

 Fixing compile-time errors is easier than fixing runtime errors, which can be difficult to find.

For in Depth about Generics visit :-

Monday 2 December 2013

String Reverse Using Recursion in Java!!

class main

{

public static void main(String args[])

{

string str="hey";

 reverseStr = reverseRecursively(str);

public static String reverseRecursively(String str) 

{
        //base case to handle one char string and empty string
        if (str.length() < 2) 

{
            return str;

  }
        return reverseRecursively(str.substring(1)) + str.charAt(0);
 }
  System.out.println("Reverse String in Java using Recursion: " + reverseStr);

}