I am new in java. I have a question for which I am not getting suitable answer.
My question is that why vector is called synchronised?
Can anybody please clarify me why vector is synchronised?
don't bother with Vector.
It's a legacy class that's best forgotten.
may be it is a legacy class. but I was asked both the questions in Interview.
That is why I need to know the answers.
If you were asked that in an interview and do not have the answer and cannot figure out how to find that answer, you really should not have the job. A working programmer should know how to find answers to such things on their own through the documentation or other available resources.
I don't say that to be mean. It's just something you need to learn to do if you expect to hold a job programming and the sooner you get used to it the better.
◄ why vector is called synchronised?
Because it's methods are synchronized.
◄ why vector is synchronised?
A decision made by the language implementors.
Take a look at the source code of the Vector class and things will become a bit more clear for you. Just don't be attracted by the 'synchronized data structure' thing, hand craft your synchronization code. It would save you a lot of trouble.
What this means is, if two threads attempt to access a
Vector it will be synchronized. One thread will have to wait until the
other thread is finished accessing the Vector.
when there are some critical business transactions are there in your Application so in such kind of situations Vector is used.refer some other documents for the purpose of Vector.
Do not use Vector even if you need a synchronized list. Use Collections.synchronizedList(List) or CopyOnWriteArrayList.