File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why Vector is made as a Legacy Class

 
Praveen Srinivasan
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why vector is made as a legacy class , what are the complexities in using Vector nowadays, what are the reasons to make it obsolete..anyone explain it...
 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vector is the same as ArrayList, except it is synchronized. In most cases you don't need this synchronization. In the few cases where you do, you can either use Vector or use an ArrayList wrapped using Collections.synchronizedList.
 
Praveen Srinivasan
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it the only reason...
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For General:
vector is having intial capacity of 10.but in some cases we donot need to add that much element in a vector.
So this is the disadvantage of using vector.

Note:-Thats a differnt thing that you having a construtors by which you can choose your own capacity and also capacity increment
 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shanky Sohar wrote:For General:
vector is having intial capacity of 10.but in some cases we donot need to add that much element in a vector.
So this is the disadvantage of using vector.

Note:-Thats a differnt thing that you having a construtors by which you can choose your own capacity and also capacity increment

With your note you immediately invalidate your earlier "reason". I can create both an ArrayList and a Vector with a capacity of just 1 if needed.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
using vector in a class doesnot make the class as Thread safe until and unless whole the methods of the class is not synchronized.

 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:
Shanky Sohar wrote:For General:
vector is having intial capacity of 10.but in some cases we donot need to add that much element in a vector.
So this is the disadvantage of using vector.

Note:-Thats a differnt thing that you having a construtors by which you can choose your own capacity and also capacity increment

With your note you immediately invalidate your earlier "reason". I can create both an ArrayList and a Vector with a capacity of just 1 if needed.


Yes ,i know that..that is the reason why i put a note
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shanky Sohar wrote:using vector in a class doesnot make the class as Thread safe until and unless whole the methods of the class is not synchronized.
That totally depends on the situation.

Vector and Collections.synchronized*() are not deprecated but it's recommended to use the classes in the java.util.concurrent.* package;
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouter Oet wrote:
Shanky Sohar wrote:using vector in a class doesnot make the class as Thread safe until and unless whole the methods of the class is not synchronized.
That totally depends on the situation.

Vector and Collections.synchronized*() are not deprecated but it's recommended to use the classes in the java.util.concurrent.* package;


Agreed.
But when we have to apply a high level synchronization on the class .and make the class as highly ThreadSafe
then we have to make each and every method as synchronized.
 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Making each and every method synchronized is just bad practice. You only synchronize the methods where your program's state might be corrupted by concurrent access; or where concurrent access might render imprecise or faulty data to the user at a given time.

In fact, I think Oracle might really improve this situation in Java. Their databases are known for their brilliance in concurrency.
 
Paul Clapham
Sheriff
Pie
Posts: 20196
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dieter Quickfend wrote:Making each and every method synchronized is just bad practice. You only synchronize the methods where your program's state might be corrupted by concurrent access; or where concurrent access might render imprecise or faulty data to the user at a given time.

In fact, I think Oracle might really improve this situation in Java. Their databases are known for their brilliance in concurrency.


I agree with you about blindly synchronizing every method. But we don't need to wait for Oracle to act; it was about 12 years ago that Sun engineers dealt with that problem by releasing the Java Collections framework. Java 2, I believe, was when that was released. And then in Java 5 (what was that, 5 years ago now?) the java.util.concurrent package was added with even better concurrency options. So there really isn't much use for Vector any more, except as a topic for discussion by generations of beginners.
 
Yogesh Tyagi
Ranch Hand
Posts: 40
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Praveen Srinivasan wrote:Why vector is made as a legacy class , what are the complexities in using Vector nowadays, what are the reasons to make it obsolete..anyone explain it...


Praveen, Try to understand the meaning of the word "Legacy", then you will understand it yourself in case of Vector, Hashtable or in some other contexts.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic