Java Generic Programming ...

Hello everyone Specially Java experts;

I want to do Generic programming in Java . I am familiar with Java but not with Generic programming .
I want to know what kind of contents it have , and how to start generic programming in java.
I know that we have to solve all Data Structure Problem with Java but someone told me that Generic Programming is a different way of doing programming in Java .
Please guys suggest me topic’s that i have to cover in Generic Programming with Java .
Also I want to know best online site’s for Generic Programming in java.
Please Suggest me any Links and any good points about Generic Programming .

Happy Coding!!!


@upendra1234 I would suggest you to start from CORE JAVA VOLUME I by HORTSMANN good and basic content here. Will definitely help you.

Max_Size : Natural; – a generic formal value
type Element_Type is private; – a generic formal type; accepts any nonlimited type
package Stacks is
type Size_Type is range 0 … Max_Size;
type Stack is limited private;
procedure Create (S : out Stack;
Initial_Size : in Size_Type := Max_Size);
procedure Push (Into : in out Stack; Element : in Element_Type);
procedure Pop (From : in out Stack; Element : out Element_Type);
Overflow : exception;
Underflow : exception;
subtype Index_Type is Size_Type range 1 … Max_Size;
type Vector is array (Index_Type range <>) of Element_Type;
type Stack (Allocated_Size : Size_Type := 0) is record
Top : Index_Type;
Storage : Vector (1 … Allocated_Size);
end record;
end Stacks;

A notable behavior of static members in a generic .NET class is static member instantiation per run-time type (see example below).

//A generic class
public class GenTest<T>
    //A static variable - will be created for each type on refraction
    static CountedInstances OnePerType = new CountedInstances();

    //a data member
    private T mT;

    //simple constructor
    public GenTest(T pT)
        mT = pT;

//a class
public class CountedInstances
    //Static variable - this will be incremented once per instance
    public static int Counter;

    //simple constructor
    public CountedInstances()
        //increase counter by one during object instantiation

//main code entry point
//at the end of execution, CountedInstances{{Not a typo|.}}Counter = 2
GenTest g1 = new GenTest(1);
GenTest g11 = new GenTest(11);
GenTest g111 = new GenTest(111);
GenTest g2 = new GenTest(1.0);

I know writing code in java i wanna know about Generic programming dude…

1 Like

@upendra1234 I guess 12th or 13th chapter of the book is dedicated to generic programming and it has really good content in it …