Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How does Vector implement synchronization?

Answers were Sorted based on User's Feedback



How does Vector implement synchronization?..

Answer / azad bajaj

Almost all the methods in the Vector class are synchronized.
All the methods which either change (read or write) the
values, or change the size or the change the capacity of
the vector.
example method:

public synchronized void setElementAt(E obj, int index) {
if (index >= elementCount) {
throw new ArrayIndexOutOfBoundsException
(index + " >= " + elementCount);
}
elementData[index] = obj;
}

or

public synchronized void removeElementAt(int index) {
modCount++;
if (index >= elementCount) {
throw new ArrayIndexOutOfBoundsException
(index + " >= " +

elementCount);
}
else if (index < 0) {
throw new ArrayIndexOutOfBoundsException
(index);
}
int j = elementCount - index - 1;
if (j > 0) {
System.arraycopy(elementData, index + 1,
elementData, index, j);
}
elementCount--;
elementData[elementCount] = null; /* to let gc
do its work */
}

Is This Answer Correct ?    5 Yes 1 No

How does Vector implement synchronization?..

Answer / swamy

import java.util.Vector;

public class VectorExample {

public static void main(String[] args) {

Vector<String> vc=new Vector<String>();

// <E> Element type of Vector e.g. String, Integer, Object ...

// add vector elements
vc.add("Vector Element 1");
vc.add("Vector Element 2");
vc.add("Vector Element 3");
vc.add("Vector Element 4");
vc.add("Vector Element 5");

// add vector element at index
vc.add(3, "Element at fix position");

// vc.size() inform number of elements in Vector
System.out.println("Vector Size :"+vc.size());

// get elements of Vector
for(int i=0;i<vc.size();i++)
{
System.out.println("Vector Element "+i+" :"+vc.get(i));
}
}
}

Is This Answer Correct ?    1 Yes 1 No

How does Vector implement synchronization?..

Answer / bln

Vector class by defualt is thread safe, thus all methods of
Vector class are synchronized.

Is This Answer Correct ?    4 Yes 8 No

How does Vector implement synchronization?..

Answer / srinu

By default Vector class are Thread safe,thus all methods of
vector class are synchronized

Is This Answer Correct ?    1 Yes 7 No

Post New Answer

More Core Java Interview Questions

Can we change the value of static variable?

0 Answers  


What is the difference between and ?

0 Answers  


How to stop a thread in java? Explain about sleep () method in a thread?

0 Answers  


In Inheritance if we are implementing Multi level inheritance and all class having same name of variable and now i want to access each class variable and how it is possible?

2 Answers  


What is meant by final class, methods and variables?

3 Answers  


what is static import in java? Explain

0 Answers  


Explain about OOPS concepts and fundamentals.

0 Answers   Syntel, Visa,


What is the meaning of variables in research?

0 Answers  


What is the access scope of a protected method?

0 Answers  


What is the common usage of serialization?

0 Answers  


What happens when a class is made static like if a field or member is made static it becomes class variable and is shared by all the object of the class?

1 Answers  


Is age a discrete variable?

0 Answers  


Categories