Tuesday, 6 September 2011

.NET Interview Question & Answers

What are design patterns? Define basic classification of patterns.
A design pattern in Software is used to solve similar problems that occur in different scenarios.

What is the difference between Factory and Abstract Factory Patterns?
The difference between Factory and Abstract Factory Patterns lies in object instantiation. In Abstract factory pattern Composition is used to delegate object instantiation by a class to some object. On the other hand in Factory pattern, inheritance is used in which the subclass is responsible for object instantiation.

What is MVC pattern?
Model View Controller is used to separate the interface from the business logic so as to give a better visual appearance. It helps to modularize the application to modify the identified models without affecting the data.

Model - Model is responsible for representing the application specific data. Model can also be used to respond to change of its state.

View - Turns the model (data) into a desired look and feel or an interface. It is used to manage the information to be displayed.

Controller - Controller is used to control or manage the view and model deepening on the user actions like mouse clicks etc.

How can we implement singleton pattern in .NET?
Singleton pattern restricts only one instance running for an object.

Singleton pattern is commonly used in print spoolers.

Following are the three steps needed to implement singleton pattern in .NET:-

•A class with static members needs to be created.
Public class SampleStaticClass
        Private shared objemployee as clsemployee
End class
•A private constructor to the class above should be defined.
•A static method can be used to access the singleton object.

How do you implement prototype pattern in .NET?

Prototype pattern is used to create copies of original instances known as clones. It is used when creating instances of a class is very complex.
In .Net, cloning can be achieved my making use of the ICloneable of the system namespace. Using the clone method, we can create clones or copies of instances with the same value of the existing instance. Shallow copy is used here which simply creates a reference of the original. Deep copy can be used when a duplicate instance needs to be created.

What is aspect oriented programming?

When A computer program is broken into distinct features that overlap in functionality is called as Separation of concerns. Aspect oriented programming (AOP) aims to improve the process of Separation of concerns thereby increasing modularity. Data logging is a common example of such separation of concern by crosscutting the logged classes and methods. Any AOP implementation encapsulates each concern in one place.

What is cross cutting in AOP?

A cross cutting concern in AOP is an aspect of a program affecting other concerns. Login can be an Aspect as it affects other parts of the code. A cross cutting concern is of such nature that it can be easily separated from the system. This separation is possible both in design and implementation

Difference between a Layer and Tier?

It refers to the separation of the logic (i.e the code and design) that is developed for an application in different files.

It refers to the physical location of the Layer files.

In an ASP.NET web site, we create GUI web forms, business logic , data access
logic, database all in one computer. In this case, we have 4 layers and 1 Tier.
if the GUI Web Forms,business logic, data access logic and database are all in
different computers, we have 4 layers and 4 Tiers.

In what scenarios we should not use Design Patterns ?

We should not not use design patterns in following scenarios

• When the software is being designed and it would not change with time and new requirements.

• When the requirements of the source code of a particular application are unique and same.

What is Windows DNA architecture?

Windows Distributed internet Applications architecture provides a robust, efficient solution to enable Windows platform and Internet to work together using certain technologies like DHTML and COM.

What is Service Oriented architecture?

Service oriented architecture is based on services. Service is a unit of some task performed by a service provider in order to satisfy the consumer. Example of such a service is the web services used in .NET. Even though the main purpose of web services is to enable communication, it may differ from application to application. SOA provides a set of policies and frameworks to ensure the desired services are delivered to the consumer.

What is three tier architecture?

Three tier architecture typically consists of a client, server and “agent” between them. The agent is responsible for gathering the results and returning a single response to the agent. Such architecture increases performance, reusability and scalability of the application.
The three layers include:-
Presentation layer – This is the topmost layer used to display the information to the user (client). Information is retrieved by communicating with the other layers depending on user events.
Application layer – This is where the logic resides. Processing on the business logic is done thereby controlling applications functionality.
Data layer - This is where the data resides. Typically consists of the database servers. The data here is independent of the business logic.

Explain the situations you will use a Web Service and Remoting in projects.

Web services should be used if the application demands communication over a public network and require to work across multiple platforms. Remoting is faster comparatively and hence can be used in .Net components when performance is a high priority. Few applications can also make use of BOTH web services and Remoting to send and receive data not just across multiple platforms but also between .Net applications where performance and speed is a key priority.

Overview of ADO.NET architecture.

Data Provider provides objects through which functionalities like opening and closing connection, retrieving and updating data can be availed.
It also provides access to data source like SQL Server, Access, and Oracle).
Some of the data provider objects are:
*       Command object which is used to store procedures.
*       Data Adapter which is a bridge between datastore and dataset.
*       Datareader which reads data from data store in forward only mode.
*       A dataset object is not in directly connected to any data store. It represents disconnected and cached data. The dataset communicates with Data adapter that fills up the dataset. Dataset can have one or more Datatable and relations.  
*       DataView object is used to sort and filter data in Datatable.
ADO.NET architecture - June 06, 2009 at 10:00 AM by Shuchi Gauri

Overview of ADO.NET architecture.

ADO.NET provides access to all kind of data sources such as Microsoft SQL Server, OLEDB, Oracle, XML.
ADO.NET separates out the data access and data manipulation componenets. ADO.NET includes some providers from the .NET Framework to connect to the database, to execute commands, and finally to retrieve results. Those results are either directly used or can be put in dataset and manipulate it.

Define connected and disconnected data access in ADO.NET

Data reader is based on the connected architecture for data access. Does not allow data manipulation
Dataset supports disconnected data access architecture. This gives better performance results.
Define connected and disconnected data access in ADO.NET
Data reader is based on the connected architecture for data access. Does not allow data manipulation
Dataset supports disconnected data access architecture. This gives better performance results.

Describe CommandType property of a SQLCommand in ADO.NET.

CommandType is a property of Command object which can be set to Text, Storedprocedure. If it is Text, the command executes the database query. When it is StoredProcedure, the command runs the stored procedure. A SqlCommand is an object that allows specifying what is to be performed in the database.

Access database at runtime using ADO.NET

SqlConnection sqlCon = new SqlConnection(connectionString)
string strQuery = "select CategoryName from abcd";
SqlCommand cmd = new SqlCommand(strQuery, conn);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
        Console.WriteLine(reader [0]);

Difference between dataset and datareader.

DataSet object can contain multiple rowsets from the same data source as well as from the relationships between them
Dataset is a disconnected architecture
Dataset can persist data.
DataReader provides forward-only and read-only access to data.
Datareader is connected architecture
Datareader can not persist data.

Explain the use of data adapter.

The data adapter objects connect a command objects to a Dataset object.
They provide the means for the exchange of data between the data store and the tables in the DataSet.
An OleDbDataAdapter object is used with an OLE-DB provider
A SqlDataAdapter object uses Tabular Data Services with MS SQL Server.

What are the steps involved to fill a dataset?

a. Create a connection object.
b. Create an adapter by passing the string query and the connection object as parameters.
c. Create a new object of dataset.
d. Call the Fill method of the adapter and pass the dataset object.
VB.NET Code:-
Dim strSQL as String
strSQL = "SELECT * from tbl"
Dim sqlCmd As New SqlCommand(strSQL, sqlConn)
Dim sda As New SqlDataAdapter(sqlCmd)
Dim ds As New DataSet

How can we check that some changes have been made to dataset since it was loaded?

The changes made to the dataset can be tracked using the GetChanges and HasChanges methods.
The GetChanges returns dataset which are changed since it was loaded or since Acceptchanges was executed.
The HasChanges property indicates if any changes were made to the dataset since it was loaded or if acceptchanges method was executed.
The RejectChanges can be used to revert thee changes made to the dataset since it was loaded.

How do we use stored procedure in ADO.NET and how do we provide parameters to the stored procedures?

SqlCommand command = new SqlCommand("RUPDATE",con);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@RID",SqlDbType.Int,0,"RID"));
command.Parameters.Add(new SqlParameter("@RDESC",SqlDbType.NChar,50,"RDESC"));
int i=command.ExecuteNonQuery(); 

Explain the basic use of “DataView” and explain its methods.

It is a customizable view of a datatable that allows filtering, searching, editing, navigation.
A DataView is a representation of a full table or a small section of rows.
It is used to sort and find data within Datatable.
Following are the methods of a DataView:
Find : Parameter: An array of values; Value Returned: Index of the row
FindRow : Parameter: An array of values; Value Returned: Collection of DataRow
AddNew : Adds a new row to the DataView object.
Delete : Deletes the specified row from DataView object 

What’s difference between “Optimistic” and “Pessimistic” locking?

Pessimistic locking: On updating the data, the record gets locked and no one else can access that record for updating. It becomes a read-only record till the lock is released. Once the lock gets released, the record can be locked again and get updated for a different user.
Optimistic locking: This allows multiple user to open up the same record for updation . Record gets locked only while updating the record. This is the most preferred way of locking for the web application

How can we perform transactions in .NET?

Following are the general steps that are followed during a transaction:
*       Open connection
*       Begin Transaction: the begin transaction method provides with a connection object this can be used to commit or rollback.
*       Execute the SQL commands
*       Commit or roll back
*       Close the database connection 

What is connection pooling and what is the maximum Pool Size in ADO.NET Connection String?

Connection pooling is a method of reusing the active database connections instead of creating new ones every time the user request one. Connection pool manager keeps track of all the open connections. When a new request comes in, the pool manager checks if there exists any unused connections and returns one if available. If all connections are busy and the maximum pool size has not been reached, a new connection is formed and added to the pool. And if the max pool size is reached, then the requests gets queued up until a connection in the pool becomes available or the connection attempt times out.
Connection pooling behavior is controlled by the connection string parameters. The following are four parameters that control most of the connection pooling behavior:
Default max pool size is 100.

Can you explain how to enable and disable connection pooling?

Set Pooling=true. However, it is enabled by default in .NET.
To disable connection pooling set Pooling=false in connection string if it is an ADO.NET Connection. 
If it is an OLEDBConnection object set OLEDB Services=-4 in the connection string.
To enable connection pooling:
SqlConnection myConnection = new SqlConnection(@"Data Source=(local)\SQLEXPRESS;Initial Catalog=TEST;Integrated Security=SSPI;");
This has connection pooling on by default
To disable connection pooling:
SqlConnection myConnection = new SqlConnection(@"Data Source=(local)\SQLEXPRESS;Initial Catalog=TEST;Integrated Security=SSPI;Pooling=false;");

Explain the namespaces in which .NET has the data functionality class.

System.data contains basic objects. These objects are used for accessing and storing relational data. Each of these is independent of the type of data source and the way we connect to it.
These objects are:
System.Data.OleDB objects are used to connect to a data source via an OLE-DB provider

Explain the .Net Framework.

The .Net framework allows infrastructural services to all the applications developed in .net compliant language. It is an engine that provides runtime services using its component like Common Runtime Language. It consists of two main components such as Common Language Runtime and Framework Class Library.

Describe the .Net Framework Architecture. 

The .Net Framework has two main components:
.Net Framework Class Library: It provides common types such as data types and object types that can be shared by all .Net compliant language.

The Common language Runtime: It provides services like code execution, type safety, security, thread management, interoperability services.

What are the components of the .Net Framework?

Class Loader, Compiler, Garbage Collection, Type checker, Debug engine, Exception Manager, Security engine, Thread manager, COM Marshallar, Class Library.

Explain the role of assembly in the .Net Framework.

.Net Framework keeps executable code or DLL in the form of assembly. .Net Framework maintains multiple versions of the application in the system through assembly. The assemblies have MSIL code and manifest that contains metadata. The metadata contains version information of the assembly.

Describe the GAC in the .Net Framework. 

.Net Framework provides Global Assembly cache, a machine-wide cache. It stores shared assemblies that can be accessed by multiple languages.
GAC stands for global assembly cache. It is an area of memory reserved to store the assemblies of all .NET applications that are running on a certain machine. It shares assemblies among multiple .NET applications. The assemblies must have a strong name and must be publicly shared to be installed in the GAC.

What is the advantage of packaging over xcopy in .NET?

The most trivial technique to publish a website is to simply copy your web application files to the production server and create a virtual directory there through xcopy command. With packaging it creates a self executable MSI which is very easy and convenient to deploy and install. This allows the end users to install a web application with ease. You could also include custom license needs, agreements, registry entries and other custom tasks such as installation folder etc for ease of the end users. The MSI can also be rolled out to many computers at once by the administrator which is a very big advantage.

Define .Net Assembly.

An Assembly is a collection, either an executable (.exe) or a dynamic link library (.dll), that forms a logical unit of functionality and built to efficiently work together. .NET Framework can be used to compile assemblies.
It is a primary unit of deployment in a Microsoft .NET Framework application. It is called as building block of an application which provides all required execution information to common language runtime.

An assembly perform following functions:
It contains IL code that gets executed by common language runtime.
It forms a security boundary.
An assembly is the unit at which permissions are requested and granted.
It ensures type safety by establishing name scope for types at the runtime.
It contains version information.
It allows side-by-side execution of multiple versions of same assembly.

Assemblies can be static or dynamic.
Static assemblies are created when the program is compiled using .Net compiler. It exists as PE file either in .exe or .dll. However, dynamic assemblies are created at runtime and run from the memory without getting saved on the disk.

What does an assembly contain?

An assembly contains following information:
Assembly manifest: Information about the assembly.
Type metadata: Information about the types.
IL Code
Resource files.
An assembly manifest contains the following information:
Identity of the assembly
Types and resources
Security permissions

Define private assembly and a shared assembly.

A private assembly is stored in the application’s directory and used by a single application. A share assembly can be used by multiple applications and is stored in the Global assembly cache, a repository of assemblies maintained by the .Net Framework.

What are Satellite Assemblies?

A satellite assembly contains resources specific to a given language.
With the help of these, the resources of different languages can be kept in different assemblies. However, at the runtime the chosen option generates the output in the desired language. The implementation code is kept different from the resource files that are used for conversion.
Satellite assemblies provide an application the multilingual support. Satellite assemblies contain alternate sets of resources to be used in the application for different cultures.

What do you understand by side-by-site execution of assembly?

This means multiple version of same assembly to run on the same computer. This feature enables to deploy multiple versions of the component.

How do you create a resource-only assembly?

Resources are nonexecutable data in an application and the data can be updated without recompiling application. Resource assemblies can be created as follows:
Add resource files to an empty project.
Built the project.
The resource will get compiled into assembly.

Explain how to retrieve resources using ResourceManager class.

ResourceManager class is used to retrieve resources at run time.
Create a ResourceManager with resource file name and the resource assembly as parameters.
After having created, you can use ResourceManager.GetString method to retrieve a string.
Use the ResourceManager.GetObject method to retrieve images and objects from a resource file.

What is code security? What are the types?

Framework provides the security features to secure code from unauthorized users and unauthorized uses.
There are two types of code security:
Role based security: This authorizes user.
Code access security: This protects system resources from unauthorized calls.

Define Principal object.

The Principal object represents authenticated users. It contains information about user’s identity and role. You have PrincipalPermission object in .Framework that specifies user and its role. It has Demand method that checks the current user or Principal against the name and role specified in the PrincipalPermission.

What is garbage collection?

The applications created acquire memory. Memory management includes deallocating this acquired resources and acquiring them. This is done by garbage collector and this concept of automatically reclaiming the memory is called Garbage Collection.

Is it possible to force garbage collection to run?     

Yes, it is possible to force Garbage Colletcion . The way to do it is by using GC.Collect().
However, it is also necessary to run the finalizers of the objects that need to be deallocated. So, it is necessary to use GC.WaitForPendingFinalizers() along with GC.Collect() so that the finalizers threads are not executed separately.

Define Dispose().

It is a method for releasing resources that an object acquires. The Dispose method is called by the destructor

Explain how garbage collection manages reclamation of unused memory in .NET.

CLR performs garbage collection on small objects and large objects separately. It maintains separate heaps for these two types of objects. Large Objects are maintained in LO
Heap and small objects are kept in multiple heaps which are compacted regularly.
It uses the JIT compiler which provides it the references of live objects indicating that they are alive. The rest of the objects are then subject to garbage collection.
Then the free memory is merged and the occupied memory is compacted so that the live objects are contiguous.

What is break mode? What are the options to step through code?

When changes are made to the code in an application, the way to be able to view how those changes have changed the way of execution is Break Mode. In break mode, a snapshot of the running application is taken in which the status and values of all the variables is stored. 
Break mode lets you to observe code line to line in order to locate error.
VS.NET provides following option to step through code.
Step Into
Step Over
Step Out
Run To Cursor
Set Next Statement

Debug Vs Trace.

Both these objects are found in the System.Diagnostics namespace.
Both are used for diagnose problems without interrupting application execution. 
Debug statement can only be used in debug mode while trace statement can be used both in debug and released mode.
Debug statements can't be compiled into a release version.

Define Listeners collection of Trace and Debug objects.

The Trace and Debug objects contain a Listeners collection.
These Listeners collection collect output from the trace statements.
There are three types of predefined listeners: 
DefaultTraceListener: This is default listener and writes trace statements in the Output window.
TextWriterTraceListener: can write output to the text file or to the console window.
EventLogTraceListener: can write messages to the Event Log.

Define Trace Switches.

Trace switches are used to configure tracing behavior.
There are two kinds of trace switches: BooleanSwitch and TraceSwitch.
BooleanSwitch: It is either on or off.
TraceSwitch : It has property to determine trace behaviour.
Trace switches can be configured through application's .config file even after the application is compiled
Trace switches are used to enable, disable and filter the tracing output. They are objects can be configured through the .config file.

Explain how to create a read-only or write-only property.

You can either use fields or property procedure to add properties.
To create a property that can only be read and not altered, you need to declare it as ReadOnly. After doing this, if you try to assign value to the property, an error will occur.
The next step is to write a get procedure to retrieve the value contained by the variable.
Nb: The set procedure should not be written in this case.
To create a WriteOnly property like in case of passwords, you need to declare it as WriteOnly. Then, this value cannot be used for reading purposes. After the declaration, you need to write only a set procedure without writing a get to be able to just set the value of the variable

1. What are your technical and non technical skills?
I have got Microsoft certification in .NET. I have proficiency in ASP.NET, AJAX framework and Cruise Control .Net. Apart from this I have excellent communicational, interpersonal, and problem solving skills.

2. What is your technical experience?
I have worked on various big projects in my 7 year career. I have ample experience in designing and developing complex applications. I have supervised development activities for numerous projects. I have participated many times in architecture, design and code reviews.

3. Differentiate between static class static member and static function?
A static class cannot be instantiated. In other words, you cannot use the new keyword to create a variable of the class type. A static class consists of only static members.

A C# class can contain both static and non-static members. If we declare a member with keyword static it becomes static member. They belong to the class rather than to the objects of the class. They are also called class member.
Static function is defined by using the keyword static before the member function. The functions declared static or static functions are accessed using only the class name and the scope resolution and not by dot member access operator.
4. What is CLR?
CLR stand for Common Language Runtime. It is the core component of .NET framework. It defines an execution environment for program code. It runs a form of byte code called the Common Intermediate Language (CIL). It provides compile time and runtime service. It works with the CLS (Common Language Specification) and CTS (Common Type Systems) to ensure language interoperability.

5. What is Reflection?
Reflection is the mechanism of discovering class information at run time or it is a technique of reading Meta data at run time. It allows us to create new types at runtime. Using reflection, it is possible to uncover the methods, properties, and events of a type, and to invoke them dynamically.

6. How much salary are you expecting?
I expect salary that should reflect the experience and contribution that I bring to the job. Provide the interviewer a specific details regarding salary. However, tell him that you are willing to negotiate and compromise.

No comments:

Post a Comment