Posts

Showing posts from September, 2012

Wrapper Classes example

public class WrapperTest {     public static void main(String[] args) {           Long l1 =new Long(123214124);       System.out.println(l1.hashCode());         Character c21 = new Character('c');         Integer intvalu = new Integer("123");         Integer intvalue2 = new Integer(1234);         Integer int2 = -128;         Integer int3 = -128;         System.out.println(intvalue2.hashCode());         System.out.println(intvalu.hashCode());         System.out.println(int2.hashCode());         System.out.println(int2==intvalue2);         System.out.println(int2==int3);         Character c1= 97;         Character c2 = 65;         System.out.println(c1=...

Vector Class Example

import java.util.Vector; public class VectorTestClass {     public static void main(String[] args) {         Vector v = new Vector();         v.add(new String("Test"));         v.add(new Integer("123"));         v.add(new Boolean("true"));         v.add(6789);         v.add(new Float(67.78));         System.out.println("Element at index position 1:  "+v.elementAt(1));         // to remove element stored at index 3 ie. 6789             v.remove(3);         for (int i=0; i<v.size(); i++ )         {             System.out.println(v.get(i));         }         //or         /* for (Object a : v.toArray())         ...

Enumeration Example

public enum Apple {         GoldenDel(2),  YellowDel(5), Jonathan(7), GreenDel(12), RedDel(4);         private int price;         Apple(int price)     {         this.price = price;         }         public int getPrice()     {             return price;         }         public void setPrice(int p)     {             this.price = p;         } } //Testing Enumeration Class for enum type public class TestEnum {          public static void main(String[] args) {         Apple ap,ap2=Apple.GoldenDel;         ap=Apple.GoldenDel;         for (Apple ap1 : Apple.values())         {...

Generic Programming Example -2

class GenericDemo2<T, E> {     T obj;     E obj2;     // Pass the constructor a reference to an Object of type T     public GenericDemo2(T obj, E obj2) {         this.obj = obj;         this.obj2= obj2;     }     // return Object     public T getObj() {         return obj;     }     public E getObj2() {         return obj2;     }     void showType()     {         System.out.println("Type of T is :" + obj.getClass().getName());         System.out.println("Type of E is :" + obj2.getClass().getName());     } } public class GenericTypeTesting2 {     public static void main(String[] args) {         GenericDemo2<Integer, String> intojb = new GenericDemo2<Integer,Stri...

Generic Programming example -1

//Here T is name of type parameter // this name is used as a placeholder for the actual type //that will be passed to Gen when an object is created class GenericDemo<T> {     T obj;     // Pass the constructor a reference to an Object of type T     public GenericDemo(T obj) {         this.obj = obj;     }     // return Object     public T getObj() {         return obj;     }     void showType()     {         System.out.println("Type of T is :" + obj.getClass().getName());     }     } public class GenericTypeTesting {     public static void main(String[] args) {         GenericDemo<Integer> intojb = new GenericDemo<Integer>(210);         System.out.println(intojb.getObj());         intojb.showType();...

Content on Linux