- Vector is synchronized, ArrayList is not.
- Vector is having a constructor to specify the incremental capacity. But ArrayList don't have.
- By default Vector grows by 100% but ArrayList grows by 50% only.
Saturday, June 7, 2008
What is the difference between Vector and ArrayList ?
What is final ?
- A final is a keyword in java.
- If final keyword is applied to a variable, then the variable will become a constant.
- If final keyword is applied to method, sub classes cannot override the method.
- If final keyword is applied to a class we cannot extend from that class.
What are the different ways in which a thread can enter into waiting state?
There are three ways for a thread to enter into waiting state. By invoking its sleep() method, by blocking on I/O, by unsuccessfully attempting to acquire an object's lock, or by invoking an object's wait() method.
What is static ?
static means one per class. static variables are created when the class loads. They are associated with the class. In order to access a static we don't need objects. We can directly access static methods and variable by calling classname.variablename.
What does wait method do ?
It causes current thread to wait until either another thread invokes notify or notifyAll method of the current object, or a specified amount of time has elapsed.
What is the difference between notify and notifyAll method ?
notify wakes up a single thread that is waiting for object's monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. notifyAll Wakes up all threads that are waiting on this object's monitor. A thread waits on an object's monitor by calling one of the wait methods.
What is the difference between a continue statement and a break statement?
Break statement results in the immediate termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement.
What is thread priority?
Thread Priority is an integer value that identifies the relative order in which it should be executed with respect to others. The thread priority values ranging from 1- 10 and the default value is 5. But if a thread have higher priority doesn't means that it will execute first. The thread scheduling depends on the OS.
Does garbage collection guarantee that a program will not run out of memory?
Garbage collection does not guarantee that a program will not run out of memory. It is also possible for programs to create objects that are not subject to garbage collection. And there is no guarantee that Garbage Collection thread will be executed.
What is the difference between time slicing and preemptive scheduling ?
In preemptive scheduling, highest priority task continues execution till it enters a not running state or a higher priority task comes into existence. In time slicing, the task continues its execution for a predefined period of time and reenters the pool of ready tasks.
What is the difference between yield() and sleep()?
When a object invokes yield() it returns to ready state. But when an object invokes sleep() method enters to not ready state.
Considering the basic properties of Vector and ArrayList, where will you use Vector and where will you use ArrayList?
The basic difference between a Vector and an ArrayList is that, vector is synchronized while ArrayList is not. Thus whenever there is a possibility of multiple threads accessing the same instance, one should use Vector. While if not multiple threads are going to access the same instance then use ArrayList. Non synchronized data structure will give better performance than the synchronized one.
Subscribe to:
Posts (Atom)