>> Saturday, June 25, 2011
40).What is final modifier?
A).The final modifier keyword makes that the programmer cannot change the value anymore. The actual meaning depends on whether it is applied to a class, a variable, or a method.
final Classes- A final class cannot have subclasses.
final Variables- A final variable cannot be changed once it is initialized.
final Methods- A final method cannot be overridden by subclasses.
41.What are the uses of final method?
A).There are two reasons for marking a method as final:
Disallowing subclasses to change the meaning of the method.
Increasing efficiency by allowing the compiler to turn calls to the method into inline Java code.
42.What is static block?
A).Static block which exactly executed exactly once when the class is first loaded into JVM. Before going to the main method the static block will execute.
43.What are static variables?
A).Variables that have only one copy per class are known as static variables. They are not attached to a particular instance of a class but rather belong to a class as a whole. They are declared by using the static keyword as a modifier.
static type varIdentifier;
where, the name of the variable is varIdentifier and its data type is specified by type.
Note: Static variables that are not explicitly initialized in the code are automatically initialized with a default value. The default value depends on the data type of the variables.
44.What is the difference between static and non-static variables?
A).A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance.
45.What are static methods?
A).Methods declared with the keyword static as modifier are called static methods or class methods. They are so called because they affect a class as a whole, not a particular instance of the class. Static methods are always invoked without reference to a particular instance of a class.
Note:The use of a static method suffers from the following restrictions:
A static method can only call other static methods.
A static method must only access static data.
A static method cannot reference to the current object using keywords super or this
.What is an Iterator ?
A).The Iterator interface is used to step through the elements of a Collection.
Iterators let you process each element of a Collection.
Iterators are a generic way to go through all the elements of a Collection no matter how it is organized.
Iterator is an Interface implemented a different way for every Collection.
47.How do you traverse through a collection using its Iterator?
A).To use an iterator to traverse through the contents of a collection, follow these steps:
Obtain an iterator to the start of the collection by calling the collection̢۪s iterator() method.
Set up a loop that makes a call to hasNext(). Have the loop iterate as long as hasNext() returns true.
Within the loop, obtain each element by calling next().
48.How do you remove elements during Iteration?
A).Iterator also has a method remove() when remove is called, the current element in the iteration is deleted.
49.What is the difference between Enumeration and Iterator?
Enumeration vs Iterator
Enumeration doesn't have a remove() method
Iterator has a remove() method
Enumeration acts as Read-only interface, because it has the methods only to traverse and fetch the objects
Can be abstract, final, native, static, or synchronized
Note: So Enumeration is used whenever we want to make Collection objects as Read-only.
50.How is ListIterator?
A).ListIterator is just like Iterator, except it allows us to access the collection in either the forward or backward direction and lets us modify an element
51.What is the List interface?
A).The List interface provides support for ordered collections of objects.
Lists may contain duplicate elements.
52.What are the main implementations of the List interface ?
A).The main implementations of the List interface are as follows :
ArrayList : Resizable-array implementation of the List interface. The best all-around implementation of the List interface.
Vector : Synchronized resizable-array implementation of the List interface with additional "legacy methods."
LinkedList : Doubly-linked list implementation of the List interface. May provide better performance than the ArrayList implementation if elements are frequently inserted or deleted within the list. Useful for queues and double-ended queues (deques).
53.What are the advantages of ArrayList over arrays ?
A).Some of the advantages ArrayList has over arrays are:
It can grow dynamically
It provides more powerful insertion and search mechanisms than arrays.
A).The final modifier keyword makes that the programmer cannot change the value anymore. The actual meaning depends on whether it is applied to a class, a variable, or a method.
final Classes- A final class cannot have subclasses.
final Variables- A final variable cannot be changed once it is initialized.
final Methods- A final method cannot be overridden by subclasses.
41.What are the uses of final method?
A).There are two reasons for marking a method as final:
Disallowing subclasses to change the meaning of the method.
Increasing efficiency by allowing the compiler to turn calls to the method into inline Java code.
42.What is static block?
A).Static block which exactly executed exactly once when the class is first loaded into JVM. Before going to the main method the static block will execute.
43.What are static variables?
A).Variables that have only one copy per class are known as static variables. They are not attached to a particular instance of a class but rather belong to a class as a whole. They are declared by using the static keyword as a modifier.
static type varIdentifier;
where, the name of the variable is varIdentifier and its data type is specified by type.
Note: Static variables that are not explicitly initialized in the code are automatically initialized with a default value. The default value depends on the data type of the variables.
44.What is the difference between static and non-static variables?
A).A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance.
45.What are static methods?
A).Methods declared with the keyword static as modifier are called static methods or class methods. They are so called because they affect a class as a whole, not a particular instance of the class. Static methods are always invoked without reference to a particular instance of a class.
Note:The use of a static method suffers from the following restrictions:
A static method can only call other static methods.
A static method must only access static data.
A static method cannot reference to the current object using keywords super or this
.What is an Iterator ?
A).The Iterator interface is used to step through the elements of a Collection.
Iterators let you process each element of a Collection.
Iterators are a generic way to go through all the elements of a Collection no matter how it is organized.
Iterator is an Interface implemented a different way for every Collection.
47.How do you traverse through a collection using its Iterator?
A).To use an iterator to traverse through the contents of a collection, follow these steps:
Obtain an iterator to the start of the collection by calling the collection̢۪s iterator() method.
Set up a loop that makes a call to hasNext(). Have the loop iterate as long as hasNext() returns true.
Within the loop, obtain each element by calling next().
48.How do you remove elements during Iteration?
A).Iterator also has a method remove() when remove is called, the current element in the iteration is deleted.
49.What is the difference between Enumeration and Iterator?
Enumeration vs Iterator
Enumeration doesn't have a remove() method
Iterator has a remove() method
Enumeration acts as Read-only interface, because it has the methods only to traverse and fetch the objects
Can be abstract, final, native, static, or synchronized
Note: So Enumeration is used whenever we want to make Collection objects as Read-only.
50.How is ListIterator?
A).ListIterator is just like Iterator, except it allows us to access the collection in either the forward or backward direction and lets us modify an element
51.What is the List interface?
A).The List interface provides support for ordered collections of objects.
Lists may contain duplicate elements.
52.What are the main implementations of the List interface ?
A).The main implementations of the List interface are as follows :
ArrayList : Resizable-array implementation of the List interface. The best all-around implementation of the List interface.
Vector : Synchronized resizable-array implementation of the List interface with additional "legacy methods."
LinkedList : Doubly-linked list implementation of the List interface. May provide better performance than the ArrayList implementation if elements are frequently inserted or deleted within the list. Useful for queues and double-ended queues (deques).
53.What are the advantages of ArrayList over arrays ?
A).Some of the advantages ArrayList has over arrays are:
It can grow dynamically
It provides more powerful insertion and search mechanisms than arrays.
0 comments:
Post a Comment