(I)/* Difference Between Array Vs. ArrayList */
1.Array is a primitive data structure, which stores the values in indexed format.
whereas
ArrayList is a mere like a vector. (A re-sizeable array). It is a collection and stores any value as an object.
2.An array can be of any data type and contain one data type
while array list can contain any data type in the form of the object.
(Array is for homogeneous data. i.e data of same data type,
Whereas Arraylist is for Heterogeneous data.The data in the arraylist need not be of same data type)
3.With array you can not dynamically increase or decrease the size of array dynamically.You must the define the size of the array.You can change the size of the array with redim statement but still you have to define type.
While with array list you can make list of any sizes.
When a element or object is added to array list it size is automatically increase the capacity of the array list.It has a default size(16 items).
if u have even 1 item the size will be 16.
After 16 if u add another item, the size increases to 32.
i.e the arrayList size can be increased dynamically.
4.once you delete the item in array it kept that one as empty like a[2]="" but
in case of arraylist a[3]index occupies the position of a[2] and also if you try to insert a[2] value array will throw error if any items reside inside but in case of arraylist a[2] is inserted in same position but at the same time
position of a[2] become a[3] if there is already an item exists
/*--------------End Array VS. ArrayList----------------*/
(II)/*Difference Between String vs. StringBuilder */
1.A String object is called immutable (read-only) because its value cannot be modified once it has been created.Methods that appear to modify a String object actually return a new String object that contains the modification.
whereas
System.StringBuilder was designed with the purpose of
having a mutable string where a variety of operations can be performed.
We use StringBuilder's Append() method to use concatenation.
For eg.name = "Prasad Reddy";
A new name object is creating in memory and the value "Prasad Reddy" is assinging to the newly created space.
But StringBuilder class occupies the same space even if you change the value.
2.StringBuilder gives you better performance than String
class when you perform string manipulations like string
concatenation.
We can use StringBuilder's Append() method to use
concatenation and for String use "+".
The StringBuilder's initial capacity is set to 16 by default. The capacity then increases by an order of 2 whenever the current capacity is passed. Therefore, if the String you append to the StringBuilder causes the capacity to expand, it will
increase.
/*--------------End String VS. StringBuilder----------------*/
/*------------- Abstract Class Vs. Interface ---------------------- */
1.An abstract class is a special kind of class that cannot be instantiated. So the question is why we need a class that cannot be instantiated? An abstract class is only to be sub-classed (inherited from). In other words, it only allows other classes to inherit from it but cannot be instantiated. The advantage is that it enforces certain hierarchies for all the subclasses. In simple words, it is a kind of contract that forces all the subclasses to carry on the same hierarchies or standards
1.An interface is not a class. It is an entity that is defined by the word Interface. An interface has no implementation; it only has the signature or in other words, just the definition of the methods without the body. As one of the similarities to Abstract class, it is a contract that is used to define hierarchies for all subclasses or it defines specific set of methods and their arguments. The main difference between them is that a class can implement more than one interface but can only inherit from one abstract class. Since C# doesn�t support multiple inheritance, interfaces are used to implement multiple inheritance.
2.Abstract class is a class which contain one or more abstract methods which has to be implemented by sub classes. Inteface is a Java Object containing method declaration and doesn't contain implementation. The classes which have implementing the Interfaces must provide the method defination for all the methods.
3. Abstract class is a Class prefix wtih a abstract keyword followed by Class definaton. Interacace is a Interface which starts with interface keyword.
4. Abstract class contatins one or more abstract methods. where as Interface contains all abstract methods and final declarations.
5. Abstract class contains the method defination of the some methods. but Interface contains only method declaration no defination provided.
6. Abstract classes are useful in a situation that Some general methods should be implemented and specialization behaviour should be implemented by child classes. Interafaces are useful in a situation that all properties should be implemented we can use this scenario
/*----------------------------Both Together-----------------------*/
When we create an interface, we are basically creating a set of methods without any implementation that must be overridden by the implemented classes. The advantage is that it provides a way for a class to be a part of two classes: one from inheritance hierarchy and one from the interface.
When we create an abstract class, we are creating a base class that might have one or more completed methods but at least one or more methods are left uncompleted and declared abstract. If all the methods of an abstract class are uncompleted then it is same as an interface. The purpose of an abstract class is to provide a base class definition for how a set of derived classes will work and then allow the programmers to fill the implementation in the derived classes.
/*------------- End Abstract Class Vs. Interface ---------------------- */
/*--------------- Struct Vs. Class ----------------------------------- */
1. Classes contains a referance of the data.
whereas Struct directly contains the original data.
2. Classes are references type that required to allocate of heap.
wheras Struct are values type that do not required to allocate of heap
3. Classes can inherit from other classes and interface.
whereas Struct can inherit from interface only.
4. Classes are used to store larger data(more data 16 bytes)
whereas Struct are used to store less data(16 bytes or less)
5- To instantiate an object of a class, we use the new keyword.
whereas we do not require the new keyword to create a instane of a struct.
/*-------------------End Struct Vs. Class---------------------------*/
/*------------------Structure Vs. Class-----------------------------*/
1)Structure :- In structure have a by default public.
In class have a by default private.
2)Structure cannot be inherited. But class can be
inherit.
3)There is no data hiding features comes with
structures. Classes do, private, protected and public.
4)A structure can't be abstract, a class can.
5)A structure is a value type, while a class is a
reference type.
6)A structure is contain only data member , but class
contain data member and member function.
7)In a Structure we can't initilse the value to the
variable but in class variable we assign the values.
8)Structure are value type, They are stored as a
stack on memory. where as class are reference type. They
are stored as heap on memory.
Important Note
In general, classes can be used when you have more complex behavior or data. And if you think that these behaviour or data to be modified after creating an instance of class, then classes are absolute methods.
Structures can be used for small data structures. If developer feels that data members of structure cannot to be modified after creating structure, then having structure will suit.
/*-------------------End Structure Vs. Class---------------------------*/
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment