QSpiders - Major difference

8
Major difference By, Vikas S Kumar Software Engineer

Transcript of QSpiders - Major difference

Page 1: QSpiders - Major difference

Major differenceBy,

Vikas S KumarSoftware Engineer

Page 2: QSpiders - Major difference

Constructors v/s MethodsConstructors MethodsName should be same as class name

Its name can be same as class name or any valid name

Called when we create the object

Called when we make a call externally by its name

Used to create the Object and initialize the instance members of the class

Used to perform the functionality

Compiler gives default constructor No default methods providedWe can declare constructor as final or static or abstract

Methods can be declared as final or static or abstract

We cant override the constructor We can override the methodsConstructor recursion is not allowed Method recursion is allowedThey cannot be inherited They can be inherited

Page 3: QSpiders - Major difference

Abstract class v/s InterfaceAbstract class InterfaceIt can contain both abstract and concrete methods

It can contain only abstract methods

We can declare any type of variable and methods (any way abstract method should not be final or private)

All the methods are by default public abstract and variable are by default public static final

Used when there is some come common property needs be shared among the child class

Used when there is no common property needs to e shared among child class

We cant achieve multiple inheritance using abstract class

We can achieve multiple inheritance using interfaces

Can have constructors They cant have any constructorsWe use extends to inherit abstract class to another class

We use implements to inherit the interface to the class

Page 4: QSpiders - Major difference

Array and CollectionArray Collection

Stores primitive has well has non primitive.

Store only non primitive (Objects)

It’s a fixed size Its dynamically growingWe don’t have any methods to deal with any data hence may not give object oriented approach

We have many utility methods and also many methods that deals with data hence gives object oriented approach

Memory point of view array is not recommended

It is recommended, because memory increases has per the load

Page 5: QSpiders - Major difference

List v/s SetList Set

List allow duplicate elements No duplicates allowed

List maintains insertion order No order

All multiple null values Allow only one null valueList is index based Not index based

Page 6: QSpiders - Major difference

ArrayList and VectorArrayList Vector

ArrayList is not synchronized Vector is synchronizedArrayList is fast Vector is slowArrayList increases by half of its size when its size is increased.

Vector doubles the size of its array when its size is increased.

ArrayList came after JDK 1.2 has a part of collecyion frame work

Vector came along with JDK 1.0, later it became a part of collection frame work

iterator and listIterator returned by ArrayList are fail-fast

Enumeration returned by Vector is not fail-fast.

Page 7: QSpiders - Major difference

Iterator and ListIteratorIterator ListIterator

Iterator to traverse Set and List and also Map type of Objects.

List Iterator can be used to traverse for List type Objects, but not for Set type of Objects.

Methods in Iterator :1.hasNext()2.next()3.remove()

Methods in ListIterator1.hasNext()2.next()3.previous()4.hasPrevious()

iterator you can move only forward

List Iterator you can move back word also while reading the elements.

Not possible with iterator list iterator you can add new element at any point of time

not possible with iterator list iterator you can modify an element while traversing

Page 8: QSpiders - Major difference

ArrayList v/s LinkedList

ArralyList LinkedList

Search operation is pretty fast

search operation is slow when compared to arraylist

Adding and removing the elements is slow

Adding and removing the elements is fast

Iterating the elements is fast

Iterating the elements is slow

Memory consumption is more

Memory consumption is less