Q & A

Some Common .NET and SQL Server Interview Questions and Answers

1. What is Agile software development?

Agile software development refers to a group of software development methodologies based on iterative development, where requirements and solutions evolve through collaboration between self-organizing cross-functional teams. The term was coined in the year 2001 when the Agile Manifesto was formulated.

Agile methods generally promote a disciplined project management process that encourages frequent inspection and adaptation, a leadership philosophy that encourages teamwork, self-organization and accountability, a set of engineering best practices intended to allow for rapid delivery of high-quality software, and a business approach that aligns development with customer needs and company goals. Conceptual foundations of this framework are found in modern approaches to operations management and analysis, such as lean manufacturing, soft systems methodology, speech act theory (network of conversations approach), and Six Sigma.

2. What are Cascading Style Sheets?

A Cascading Style Sheet (CSS) is a list of statements (also known as rules) that can assign various rendering properties to HTML elements. Style rules can be specified for a single element occurrence, multiple elements, an entire document, or even multiple documents at once. It is possible to specify many different rules for an element in different locations using different methods. All these rules are collected and merged (known as a "cascading" of styles) when the document is rendered to form a single style rule for each element.

What is Inheritance?

Inheritance, in C#, is the ability to create a class that inherits attributes and behaviors from an existing class. The newly created class is the derived (or child) class and the existing class is the base (or parent) class. Inheritance is one of the key features of object-oriented programming.

3. What is Method Overriding and Method overloading?

Method overloading means having two or more methods with the same name but different signatures in the same scope. These two methods may exist in the same class or another one in base class and another in derived class.

Method overriding means having a different implementation of the same method in the inherited class. These two methods would have the same signature, but different implementation. One of these would exist in the base class and another in the derived class. These cannot exist in the same class.

4. Explain Three-Tire architecture?

'Three-tier' is a client-server architecture in which the user interface,functional process logic ("business rules"), computer data storage and data access are developed and maintained as independent modules, most often on separate platforms.

The three-tier model is considered to be[weasel words] a software architectureand a software design pattern.

Apart from the usual advantages of modular software with well defined interfaces, the three-tier architecture is intended to allow any of the three tiers to be upgraded or replaced independently as requirements or technologychange. For example, a change of operating system in the presentation tierwould only affect the user interface code.

Typically, the user interface runs on a desktop PC or workstation and uses a standard graphical user interface, functional process logic may consist of one or more separate modules running on a workstation or application server, and an RDBMS on a database server or mainframe contains the computer data storage logic. The middle tier may be multi-tiered itself (in which case the overall architecture is called an "n-tier architecture").

Three-tier architecture has the following three tiers:

Presentation tier

This is the topmost level of the application. The presentation tier displays information related to such services as browsing merchandise, purchasing, and shopping cart contents. It communicates with other tiers by outputting results to the browser/client tier and all other tiers in the network.

Application tier (Business Logic/Logic Tier/Data Access Tier/Middle Tier)

The logic tier is pulled out from the presentation tier and, as its own layer, it controls an application’s functionality by performing detailed processing.

Data tier

This tier consists of Database Servers. Here information is stored and retrieved. This tier keeps data neutral and independent from application servers or business logic. Giving data its own tier also improves scalability and performance.

5. What is the importance of Stored procedures?

Storing this SQL select statement as a stored procedure is good because:
You only need to write the procedure once, and you can then access it very simply just by using its name. Imagine if this was a complicated select command. Using just its name is like using a short-cut.

A stored procedure exposes a very simple interface to a query, and hides the query details from the user. Maybe the underlying database gets changed later, but as long as you change the stored procedure to match, people can keep using the stored procedure without any changes to their code.

You can hide the names of tables or exact details about them from your users, only allowing them access to the data through stored procedures.

Any user can be given access to use the stored procedure, but only sysadmin.db_owners and db_ddladmins can create stored procedures.

Database performance can be improved because the stored procedure is compiled when it is first used, and doesn't need to be re-examined by SQL Server every time it is called. 

They can be used to enforce data integrity rules and business logic. For example, if users can only add records to the 'houses' table via a stored procedure, then this procedure can perform any validation checks it like on the data before allowing the new records to be created.
6. What are static variables?

Variables declared static are commonly shared across all instances of a class. Only static variables exist before objects are created

7. What is the Difference between interface and abstract class?

An Abstract Class can contain default Implementation, where as an Interface should not contain any implementation at all. An Interface should contain only definitions but no implementation. where as an abstract class can contain abstract and non-abstract methods. When a class inherits from an abstract, the derived class must implement all the abstract methods declared in the base class. an abstract class can inherit from another non-abstract class.

-abstract class can not be instantiated, interface can be instantiated.

-interface only contains the declaration of the method.

C# doesn't support multiple inheritance, so there's no way to have a given class selectively derive from multiple classes. The answer is interfaces. Interfaces give you the ability to define a set of semantically related methods and properties that selected classes can implement regardless of the class hierarchy.

An interface contains only the signatures of methods, delegates or events. The implementation of the methods is done in the class that implements the interface.

8. What's an Interface?

An interface is a reference type object with no implementation. You can think of it as an abstract class with all the implementation stripped out and everything that is not public removed. Abstract classes are classes that can not be instantiated. No properties or methods are actually coded in an interface, they are only defined. So the interface doesn't actually do anything but only has a signature for interaction with other classes or interfaces. A good analogy for an interface is a pencil and a pencil sharpener. When we talk of a pencil and a pencil sharpener we generally know what they do and how they interact. We don't have to know the inner workings of a particular sharpener or pencil, only how to use them through their interface.

public interface IPencil
void Write();
bool IsSharp { get; }

public interface IPencilSharpener
void Sharpen(IPencil pencil);

9. What are Enums? 

The enum keyword is used to declare an enumeration, a distinct type consisting of a set of named constants called the enumerator list. Every enumeration type has an underlying type, which can be any integral type except char. The default underlying type of the enumeration elements is int. By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 1.

10. What is the Main Method in C#?

Entry Point in C# program

The first function to be called in any C#program is Main. We can have as many as four different ways to declareMain in our program. They are as follows:

static void Main() {…}
static int Main() {…}
static void Main(string[] a) {…}
static int Main(string[] args) {…}

note :- String and string words are similar to use. They are alias!

The operating system calls Main and waits for it to return a value. This value denotes the success or failure of the program.

Main can either return a number or result inno return value, that is, void. If it returns an int, by convention, avalue of zero means success and any other value indicates an error. Nointernational authority can standardize the error numbers, it largelydepends on the programmer himself.

Java programs start executing at the main method, which has the following method heading: public static void main(String[] args)
public static void main(String... args)
public static void main(String args[5])

11. What is a delegate?

A delegate is a type that references a method. Once a delegate is assigned a method, it behaves exactly like that method. The delegate method can be used like any other method, with parameters and a return value, as in this example: public delegate int PerformCalculation(int x, int y);

· Delegates are similar to C++ function pointers, but are type safe.
· Delegates allow methods to be passed as parameters.
· Delegates can be used to define callback methods.
· Delegates can be chained together; for example, multiple methods can be called on a single event.
· Methods don't need to match the delegate signature exactly. For more information, see Co-variance and Contravariance

12. What is a thread?

Threads are often called lightweight processes. However they are not process.es A Thread is a small set of executable instructions, which can be used to isolate a task from a process.

13. Explain Having clause in SQL

The HAVING clause is used in combination with the GROUP BY clause. It can be used in a SELECT statement to filter the records that a GROUP BY returns.

The syntax for the HAVING clause is:

SELECT column1, column2, ... column_n, aggregate_function (expression)
FROM tables
WHERE predicates
GROUP BY column1, column2, ... column_n
HAVING condition1 ... condition_n;

14. What is a Concrete class?

An abstract class is meant to be used as the base class from which other classes are derived. The derived class is expected to provide implementations for the methods that are not implemented in the base class. A derived class that implements all the missing functionality is called a concrete class.

15. What is JavaScript? 

JavaScript was designed to add interactivity to HTML pages
JavaScript is a scripting language
A scripting language is a lightweight programming language
JavaScript is usually embedded directly into HTML pages
JavaScript is an interpreted language (means that scripts execute without preliminary compilation)
Everyone can use JavaScript without purchasing a license

16. What is AJAX? 

AJAX = Asynchronous JavaScript and XML.
AJAX is not a new programming language, but a new way to use existing standards.
AJAX is the art of exchanging data with a server, and update parts of a web page - without reloading the whole page.

17. What is dynamic binding and static binding?

Dynamic binding means knowing the state of an object at runtime is k/as Dynamic binding.It is also k/as Late Binding.
Static binding means knowing the state of an objects at compile time , also k/as Early Binding.

18. What is Coupling and Cohesion?

Coupling describes the relationship between software components
Goal: Reduce coupling, increase cohesion
cohesion is a measure of how strongly-related is the functionality expressed by the source code of a software module.

19. What is a Session?

Session is server side state management technique
Putting the state in a server-side database
Very secure
Everything kept on server - browser sees only what it needs
Cookie/URL only used to store session ID; hard to guess IDs
Cannot be blocked by client (since it’s on the server)
Can use an in-memory database for speed
Can store lots of data and keep it in original (object) form
Scalability issues: server must store state of all clients
Potentially millions of Web clients = serious load on server
Must use timeouts to detect and clean up dead sessions
Client browser won’t tell you when it is exiting
The default behavior is to store session variables in the memory space of theASP.NET worker process

20. What is a Web Service? 

A web service is typically an application programming interface (API) or Web API that is accessed via Hypertext Transfer Protocol (HTTP) and executed on a remote system, hosting the requested service. Web services tend to fall into one of two camps: big web services and RESTful web services.

21. What is polymorphism? 

Generally, the ability to appear in many forms. In object-oriented programming, polymorphism refers to a programming language's ability to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes. For example, given a base class shape, polymorphism enables the programmer to define different area methods for any number of derived classes, such as circles, rectangles and triangles. No matter what shape an object is, applying the area method to it will return the correct results. Polymorphism is considered to be a requirement of any true object-oriented programming language (OOPL).

22. What is Encapsulation? 

Encapsulation means as much as shielding. Each OO object has a shield around it. Objects can't 'see' each other. They can exchange things though, as if they are interconnected through a hatch.

Customer, waiter and kitchen are three shielded objects in the 'cup of coffee' example. Customer and kitchen do not know each other. The waiter is the intermediary between those two. Objects can't see each other in an Object Oriented world. The 'hatch' enables them to communicate and exchange coffee and money.

Encapsulation keeps computer systems flexible. The business process can change easily. The customer does not care about the coffee brew process. Even the waiter does not care. This allows the kitchen to be reconstructed, is only the 'hatch' remains the same. It is even possible to change the entire business process. Suppose the waiter will brew coffee himself. The customer won't notice any difference.

Encapsulation enables OO experts to build flexible systems. Systems that can extend as your business extends. Every module of the system can change independantly, no impact to the other modules.

23. What is SOAP?

SOAP is a lightweight protocol for exchange of information in a decentralized, distributed environment. It is an XML based protocol that consists of three parts: an envelope that defines a framework for describing what is in a message and how to process it, a set of encoding rules for expressing instances of application-defined datatypes, and a convention for representing remote procedure calls and responses. SOAP can potentially be used in combination with a variety of other protocols; however, the only bindings defined in this document describe how to use SOAP in combination with HTTP and HTTP Extension Framework.

24. What is the difference between HTML and XHTML?

* XHTML elements must be properly nested* XHTML elements must always be closed
* XHTML elements must be in lowercase
* XHTML documents must have one root element
* Attribute names must be in lower case
* Attribute values must be quoted
* Attribute minimization is forbidden
* The id attribute replaces the name attribute
* The XHTML DTD defines mandatory elements

XHTML Elements Must Be Properly Nested

In HTML, some elements can be improperly nested within each other, like this:
This text is bold and italic

In XHTML, all elements must be properly nested within each other

Attribute Names Must Be In Lower Case
Attribute Values Must Be Quoted
Attribute Minimization Is Forbidden

25. What is the difference between .NET remoting and Webservices?

Web service can be accessed only over http protocol but .net remoting can be accessed over
TCP,HTTP ,SMTP etc.Web service are stateless architechture but .net remoting support stateful
and state less environment.Dot net remoting provides fast communication than web service when use tcp
channel and binary formatter.web service is easy to create and deploy but .net remoting bit
complex to program.Web service can be cross platform and open protocol.remoting is tight
coupled and web service for disconnected loosely coupled.

26. What are UML diagrams?

Unified Modeling Language (UML) is a standardized general-purpose modeling language in the field of object-oriented software engineering. The standard is managed, and was created, by the Object Management Group. It was first added to the list of OMG adopted technologies in 1997, and has since become the industry standard for modeling software-intensive systems.

27. Explain DataSet and DataReader?

A DataSet if the bucket here; it allows you to carry around a disconnected set of data and work with it - but you need to incur the cost of carrying the bucket (so best to keep it to a size you are comfortable with).

A data-reader is the hose: it provides one-way/once-only access to data as it flies past you; you don't have to carry all of the available water at once, but it needs to be connected to the tap/database.

And in the same way that you can fill a bucket with a hose, you can fill the DataSet with the data-reader.

28. what is an asynchronous call?

A function that enables processing to continue without waiting for the function to return a value.

29. REST Web Service

In a nutshell, REST is based on the representation of resources. A resource is an object that we can access over the World Wide Web. It can be a document, an image, or anything. When we request a resource (an object) from a server, the server returns the representation of that resource. In REST architecture, a client requests an operation (CRUD) on an object (resource) on the server, and the server returns data as per requirements.

Example – Let us consider a Web Service that returns Employee information. The Web Service responds to client calls by polling a database and returning a result. In classical Web Services or WCF Services, we would have a method exposed to clients, like GetEmployee(). The REST architecture is different from this as it does not work with the methods but with nouns (resources / objects) and allow verbs (HTTP Methods) to operate on them.
So if we want to get Employee information, we send an HTTP GET on the object Employee rather than query a method like GetEmployee(). The advantage is manifold, the most important being the power and flexibility that we get in our hands to play around with the object.

30. ASP.NET MVC Page life cycle

  1. An instance of the RouteTable class is created on application start. This happens only once when the application is requested for the first time.
  2. The UrlRoutingModule intercepts each request, finds a matching RouteData from a RouteTable and instantiates a MVCHandler (an HttpHandler).
  3. The MVCHandler creates a DefaultControllerFactory (you can create your own controller factory also). It processes the RequestContext and gets a specific controller (from the controllers you have written). Creates a ControllerContext. es the controller a ControllerContext and executes the controller. 
  4. Gets the ActionMethod from the RouteData based on the URL. The Controller Class then builds a list of parameters (to to the ActionMethod) from the request.
  5. The ActionMethod returns an instance of a class inherited from the ActionResult class and the View Engine renders a view as a web page.

Page request
The page request occurs before the page life cycle begins. When the page is requested by a user, ASP.NET determines whether the page needs to be parsed and compiled (therefore beginning the life of a page), or whether a cached version of the page can be sent in response without running the page.
In the start stage, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a postback or a new request and sets the IsPostBack property. The page also sets the UICulture property.
During page initialization, controls on the page are available and each control's UniqueID property is set. A master page and themes are also applied to the page if applicable. If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state.
During load, if the current request is a postback, control properties are loaded with information recovered from view state and control state.
Postback event handling
If the request is a postback, control event handlers are called. After that, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page. (There is an exception to this sequence: the handler for the event that caused validation is called after validation.)
Before rendering, view state is saved for the page and all controls. During the rendering stage, the page calls the Render method for each control, providing a text writer that writes its output to the OutputStream object of the page's Response property.
The Unload event is raised after the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and cleanup is performed.
C# Access Modifiers
The type or member can be accessed by any other code in the same assembly or another assembly that references it.
The type or member can be accessed only by code in the same class or struct.
The type or member can be accessed only by code in the same class, or in a class that is derived from that class.
The type or member can be accessed by any code in the same assembly, but not from another assembly.
protected internal The type or member can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly.
private protected The type or member can be accessed only within its declaring assembly, by code in the same class or in a type that is derived from that class.

c# value type vs reference type

Difference between a Value Type and a Reference Type. ... A Value Type holds the data within its own memory allocation and a Reference Type contains a pointer to another memory location that holds the real data. Reference Type variables are stored in the heap while Value Type variables are stored in the stack.

C# Class vs Struct

Structs are value types and classes are reference types.