Saturday, January 26, 2008

What are the different types of assemblies available and their purpose?

Private, Public/shared and Satellite Assemblies.

Private Assemblies : Assembly used within an application is known as private assemblies

Public/shared Assemblies : Assembly which can be shared across applicaiton is known as shared assemblies. Strong Name has to be created to create a shared assembly. This can be done using SN.EXE. The same has to be registered using GACUtil.exe (Global Assembly Cache).

Satellite Assemblies : These assemblies contain resource files pertaining to a locale (Culture+Language). These assemblies are used in deploying an Gloabl applicaiton for different languages.

OOPS Interview Questions:

1. What is Class?
A user-defined data structure that groups properties and methods. Class doesn’t occupy memory.

2. What is Object?
Instance of Class is called object. An object is created in memory using keyword “new”.

3. Difference between Struct and Class?
i) Struct are Value type and are stored on stack, while Class are Reference type and are stored on heap
ii) Struct “do not support” inheritance, while class supports inheritance. However struct can implements interface
iii) Struct should be used when you want to use a small data structure, while Class is better choice for complex data structure.

4. What is Encapsulation?
Wrapping up of data and function into a single unit is known as Encapsulation.

5. What is Properties?
Attribute of object is called properties. Eg1:- A car has color as property.
eg.: private string m_Color;
public string Color
{
get
{
return m_Color;
}
set
{
m_Color = value;
}
}
Car Maruti = new Car();
Maruti.Color= “White”;
Console.Write(Maruti.Color);

6. Use of "this" Keyword?
Each object has a reference “this” which points to itself. Two uses of this keyword are 1)Can be used to refer to the current object, 2)It can also be used by one constructor to explicitly invoke another constructor of the same class.

7. What is Constructor?
- A constructor is a special method whose task is to initialize the object of its class
- It is special because its name is the same as the class name.
- They do not have return types, not even void and therefore they cannot return values.
- They cannot be inherited, though a derived class can call the base class constructor
- Constructor is invoked whenever an object of its associated class is created
Note: There is always atleast one constructor in every class. If you do not write a constructor, C# automatically provides one for you, this is called default constructor. Eg: class A, default constructor is A().

8. What is Static Members of the class?
-Static members belong to the whole class rather than to individual object
-Static members are accessed with the name of class rather than reference to objects.
Eg:
class Test
{
public int rollNo;
public int mathsMarks;
public static int totalMathMarks;
}
class TestDemo
{
public static void main()
{
Test stud1 = new Test();
stud1.rollNo = 1;
stud1.mathsMarks = 40;
stud2.rollNo = 2;
stud2.mathsMarks = 43;
Test.totalMathsMarks = stud1.mathsMarks + stud2.mathsMarks;
}
}

9. What is Static Method of the class?
Methods that you can call directly without first creating an instance of a class.
Eg: Main() Method, Console.WriteLine()

10. what is Destructor?
A destructor is just opposite to constructor. It has same as the class name, but with prefix ~ (tilde). They do not have return types, not even void and therefore they cannot return values.

11. What is Garbage Collection?
Garbage collection is the mechanism that reclaims the memory resources of an object when it is no longer referenced by a variable.
.Net Runtime performs automatically performs garbage collection, however you can force the garbage collection to run at a certain point in your code by calling System.GC.Collect()

12. Use of Enumeration?
Enumeration improves code readability. It also helps in avoiding typing mistake.

13. Concept of Heap and Stack:
The Program Instruction and Global and Static variables are stored in a region known as permanent storage area and the local variables are stored in another area called stack. The memory space located between these two regions is available for dynamic memory allocation during execution of program. This free memory region is called heap. The size of heap keeps on changing when program is executed due to creation and death of variables that are local to functions and blocks. Therefore, it is possible to encounter memory “overflow” during dynamic allocation process.

14. What is Value Type and Reference Type?
A variable is value type or reference type is solely determined by its data type.
Eg: int, float, char, decimal, bool, decimal, struct, etc are value types,
object type such as class, String, Array, etc are reference type.

15. what is Boxing and Un-Boxing?
Boxing: means converting value-type to reference-type.
Eg:
int I = 20;
string s = I.ToSting();
UnBoxing: means converting reference-type to value-type.
Eg:
int I = 20;
string s = I.ToString(); //Box the int
int J = Convert.ToInt32(s); //UnBox it back to an int.
Note: Performance Overheads due to boxing and unboxing as the boxing makes a copy of value type from stack and place it inside an object of type System.Object in the heap.

16. What is Inheritance?
The process of sub-classing a class to extend its functionality is called Inheritance.It provides idea of reusability.

17. What are Sealed Classes in C#?
The sealed modifier is used to prevent derivation from a class. A compile-time error occurs if a sealed class is specified as the base class of another class. (A sealed class cannot also be an abstract class)

18. Can you prevent your class from being inherited by another class?
Yes. The keyword “sealed” will prevent the class from being inherited.

19. Can you allow a class to be inherited, but prevent the method from being over-ridden?
Yes. Just leave the class public and make the method sealed.

20. List of Facts in Inheritance?
- Multiple inheritance of classes is not allowed in C#.
- In C# you can implements more than one interface, thus multiple inheritance is achieved through interface.
- The Object class defined in the System namespace is implicitly the ultimate base class of all the classes in C# (and the .NET framework)
- Structures (struct) in C# does not support inheritance, it can only implements interfaces.

21. What is Polymorphism?
Polymorphism means same operation may behave differently on different classes.
Eg:
Method Overloading is an example of Compile Time Polymorphism.
Method Overriding is an example of Run Time Polymorphism

22. How many types of Access Modifiers?
1) Public – Allows the members to be globally accessible
2) Private – Limits the member’s access to only the containing
3) Protected – Limits the member’s access to the containing type and all classes derived from the containing type
4) Internal – Limits the member’s access to within the current project

23. What is Method Overloading?
Method with same name but with different arguments is called method overloading. Method Overloading forms compile-time polymorphism.
Eg. class A1
{
void hello()
{
Console.WriteLine(“Hello”);
}
void hello(string s)
{
Console.WriteLine(“Hello {0}”,s);
}
}

24. What is Method Overriding?
Method overriding occurs when child class declares a method that has the same type arguments as a method declared by one of its superclass. Method overriding forms Run-time polymorphism.
Eg.
Class parent
{
virtual void hello()
{
Console.WriteLine(“Hello from Parent”);
}
}
Class child : parent
{

override void hello()
{
Console.WriteLine(“Hello from Child”);
}
}
static void main()

{
parent objParent = new child();
objParent.hello();
}
//Output

Hello from Child.

25. What is Virtual Method?
By declaring base class function as virtual, we allow the function to be overridden in any of derived class.
Eg:
Class parent
{
virtual void hello()
{
Console.WriteLine(“Hello from Parent”);
}
}
Class child : parent
{
override void hello()
{ Console.WriteLine(“Hello from Child”);
}
}
static void main()
{
parent objParent = new child();
objParent.hello();
}
//Output
Hello from Child.

26. What is Interface?
- Interface states “what” to do, rather than “how” to do.
- An interface defines only the members that will be made available by an implementing object. The definition of the interface states nothing about the implementation of the members, only the parameters they take and the types of values they will return. Implementation of an interface is left entirely to the implementing class. It is possible, therefore, for different objects to provide dramatically different implementations of the same members.

Eg.
public interface IDrivable
{
void GoForward(int Speed);
}
public class Truck : IDrivable
{
public void GoForward(int Speed)
{
// Implementation omitted
}
}
public class Aircraft : IDrivable
{
public void GoForward(int Speed)
{
// Implementation omitted
}
}
public class Train : IDrivable
{
public void GoForward(int Speed)
{
// Implementation omitted
}
}

27. Difference between Interface and Abstract Class?
Multiple inheritance:
A class may implement several interfaces.
A class may extend only one abstract class.
Default implementation:
An interface cannot provide any code at all, much less default code.
An abstract class can provide complete code, default code, and/or just stubs that have to be overridden.
Third party convenience:
An interface implementation may be added to any existing third party class.
A third party class must be rewritten to extend only from the abstract class.

Wednesday, January 23, 2008

Types of Multitasking

There are two types of multitasking:

1. Process Based:
- Process-based multitasking handles the concurrent execution of programs.
eg.:running word processor the same time you are browsing the net.
2. Thread Based
- Thread-based multitasking deals with the concurrent execution of pieces of the same program.
eg.: A text editor can be formatting text at the same time that it is printing.

Sunday, January 20, 2008

What is reflection?

Reflection is the mechanism of discovering class information solely at run time

What’s the use of SmartNavigation property?

Its a feature provided by ASP .NET to prevent the flickering and the redrawing when the page is posted back. Gets or sets a value indicating whether smart navigation is enabled.
VB: Public Property SmartNavigation As Boolean
C#: Public bool SmartNavigation {get; set;}

What is concept of Boxing and Unboxing?

Boxing and unboxing is a essential concept in. NET’s type system. With Boxing and unboxing one can link between value-types and reference-types by allowing any value of a value-type to be converted to and from type object. Boxing and unboxing enables a unified view of the type system wherein a value of any type can ultimately be treated as an object.

Converting a value type to reference type is called Boxing. Unboxing is the opposite operation and is an explicit operation.

Various State Management in a Page:

There are Nine ways by which we can Maintain State of Page:

1. Application
2. Cookies
3. Hidden Fields
4. Query String
5. Session
6. Cache
7. Context
8. ViewState
9. Web.Config and Machine.Config

Keys Concept in DBMS.

1) PRIMARY KEY:-A primary key is a field that uniquely identifies each record in a table. As it uniquely identify each entity, it cannot contain null value and duplicate value.eg:-Consider the customer table, which has field :customer_number, customer_socialsecurity_number, and customer_address.here customer_number of each entity in customer table is distinct so customer-number can be a primary key of customer-table.
2) SUPER KEY :- If we add additional attributes to a primary key, the resulting combination would still uniquely identify an instance of the entity set. Such augmented keys are called superkey.A primary key is therefore a minimum superkey.
3) CANDIDATE KEY:-A nominee's for primary key field are know as candidate key.eg:-From above example of customer table, customer_socialsecurity_number is candidate key as it has all characteristics of primary key.
4) ALTERNATE KEY:-A candidate key that is not the primary key is called an Alternate key.eg:- In above example, customer_socialsecurity_number is a candidate key but not a primary key so it can be considered as alternate key.
5) COMPOSITE KEY:- Creating more than one primary key are jointly known as composite key.eg:-In above example, if customer_number and customer_socialsecurity_number are made primary key than they will be jointly known as composite key.
6) FOREIGN KEY:- Foreign key is a primary key of master table, which is reference in the current table, so it is known as foreign key in the current table. A foreign key is one or more columns whose value must exist in the primary key of another table.eg:-Consider two tables emp(contains employees description) and emp_edu(contains details of employee's education), so emp_id which is primary key in emp table will be referred as foreign key in emp_edu table.

Friday, January 18, 2008

What is viewstate?

View State is the built in structure for automatically retain the values amoung multiple requests for the same page. Viewstate is internally maintained in the HiddenField on the page.

Thursday, January 17, 2008

Define candidate key, alternate key, composite key?

A candidate key is one that can identify each row of a table uniquely.Generally a candidate key becomes the primary key of the table. If thetable has more than one candidate key, one of them will become theprimary key, and the rest are called alternate keys.

A key formed by combining at least two or more columns is called composite key.

What is Canditate Key?

A table which is having more that one combination of column that could uniqly identify the rows in a table. Each combination is a canditate key.
Eg. In the supplier table SupplierID, Supplier name are the canditate key but we can pick up only the supplierID as a primary key.

Enabling an asynchronous web page

Step 1. Add the Async="true" attribute the page directive:


eg: Page Language="C#" Async="true" AutoEventWireup="true"

Step 2. Create events to start and end the asynchronous code that implements the System.Web.IHttpAsyncHandler.BeginProcessRequest and System.Web.IHttpAsyncHandler.EndProcessRequest


eg: IAsyncResult BeginGetAsyncData(Object src, EventArgs args, AsyncCallback cb,

Object state)
{ }

void EndGetAsyncData(IAsyncResult ar)
{ }



Step 3. call the AddOnPreRenderCompleteAsync method to declare the event handlers:


eg: BeginEventHandler bh=new BeginEventHandler(this.BeginGetAsyncData);
EndEventHandler eh= new EndEventHandler(this.EndGetAsyncData);
AddOnPreRenderCompleteAsync (bh,eh)