• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

wrapper classes

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1)IS Wrapper classes there prior to java 1.5?

2)prior to java 1.5 java doesnt support parameterized ArrayLists like ArrayList<int> etc
then prior to 1.5 what type of objects can i store in the ArrayLists? I suppose String references are objects and i can store them .

can i store anythin other than String earlier to 1.5 version ?

3)Prior to 1.5 can i store a primitive value like int in ArrayList ?? (if wrapper classes there then without using wrapperclasses)

4) Prior to 1.5 is it mandatory to say like this ArrayList<Object> list = new ArrayList<Objects> (); in order to store Objects ?

can i remove <object> from the above line while Storing

5)Now in the latest version 1.6 iam storing like this

ArrayList < Integer> a = new ArrayList<Integer> ();
a.add(5);
int b=a.get(0);

if i dont keep <Integer> in the above line Is that an error while adding integer value ?

whats the difference of keeping <Integer>and not keeping it in the above line ?
Is the effect same ?

6) I f i want to add 4.5 then can i write like this ArrayList a = new ArrayList ();
a.add(4.5);
int b=a.get(0);

or do i need to write like this ArrayList < Float > a = new ArrayList<Float> ();
a.add(4.5);
int b=a.get(0);

whats the difference ?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1)IS Wrapper classes there prior to java 1.5?



Yes. The Wrapper classes existed since the beginning. It was autoboxing that was added with Java 5.

Henry
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

2)prior to java 1.5 java doesnt support parameterized ArrayLists like ArrayList<int> etc
then prior to 1.5 what type of objects can i store in the ArrayLists? I suppose String references are objects and i can store them .

can i store anythin other than String earlier to 1.5 version ?




Well, technically, Java still doesn't support ArrayList<int> -- even with Java 5. Generics are for Objects, not for primatives.

Prior to generics, no type checking is done. The ArrayList can hold any object types -- just like after generics was added. It was the type checking that was added.

Henry
 
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1)IS Wrapper classes there prior to java 1.5?


Yes after seeing Henry reply.


2)prior to java 1.5 java doesnt support parameterized ArrayLists like ArrayList<int> etc
then prior to 1.5 what type of objects can i store in the ArrayLists? I suppose String references are objects and i can store them .

can i store anythin other than String earlier to 1.5 version ?



Any java Object leaving primitives.

3)Prior to 1.5 can i store a primitive value like int in ArrayList ?? (if wrapper classes there then without using wrapperclasses)



No as there were no boxing support.

4) Prior to 1.5 is it mandatory to say like this ArrayList<Object> list = new ArrayList<Objects> (); in order to store Objects ?

can i remove <object> from the above line while Storing



Prior to java 5 there was no generic parameter you can specify.
You must say only:
ArrayList list=new ArrayList();

5)Now in the latest version 1.6 iam storing like this
ArrayList < Integer> a = new ArrayList<Integer> ();
a.add(5);
int b=a.get(0);

if i dont keep <Integer> in the above line Is that an error while adding integer value ?

whats the difference of keeping <Integer>and not keeping it in the above line ?
Is the effect same ?



not keeping means:
ArrayList a=new ArrayList();
this is same like ArrayList<Object> a=new ArrayList<Object>();, it can take any objects, wrapper objects also.
a.add(5);//ok
Only thing you will get here is the compiler warning, when you call a.add(5);


6) I f i want to add 4.5 then can i write like this ArrayList a = new ArrayList ();
a.add(4.5);
int b=a.get(0);

or do i need to write like this ArrayList < Float > a = new ArrayList<Float> ();
a.add(4.5);
int b=a.get(0);

whats the difference ?



First one will take String also, or any other objects also. While second one will only take Float Object. Try it out.

 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

3)Prior to 1.5 can i store a primitive value like int in ArrayList ?? (if wrapper classes there then without using wrapperclasses)



Of course, you can -- but you needed the wrapper classes.

And technically, you can't store primative values into an ArrayList, even with Java 5, without the wrapper classes either. It is just that Java 5's autoboxing hides all the details from you. It just looks like you can with Java 5 and above.

Henry
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


2)prior to java 1.5 java doesnt support parameterized ArrayLists like ArrayList<int> etc
then prior to 1.5 what type of objects can i store in the ArrayLists? I suppose String references are objects and i can store them .

can i store anythin other than String earlier to 1.5 version ?



Any java Object leaving primitives.


yes you are right but any java object in the sense in the data types only string is possible na?
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

srikanth mycherla wrote:
yes you are right but any java object in the sense in the data types only string is possible na?



Any java objects means any java objects.

How do you see any java Object?
 
santosh pilla
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks henry and punit

regards
 
srikanth mycherla
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As this topic is leading to Generics..can someone post a small example for generics!
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

srikanth mycherla wrote:As this topic is leading to Generics..can someone post a small example for generics!




Let's try to keep topics somewhat focused... as these topics will be searched in the future, by other users, looking for particular issues.

And asking for "example for generics", isn't really asking a specfic question either.

Henry
 
reply
    Bookmark Topic Watch Topic
  • New Topic