Asp.Net Q&A

What is a DataReader object?
Ans: The DataReader object helps in retrieving the data from a database in a forward-only, read-only mode. The base class for all the DataReader objects is the DbDataReader class.
The DataReader object is returned as a result of calling the ExecuteReader() method of the Command object. TheDataReader object enables faster retrieval of data from databases and enhances the performance of .NET applications by providing rapid data access speed. However, it is less preferred as compared to the DataAdapter object because the DataReader object needs an Open connection till it completes reading all the rows of the specified table.
An Open connection to read data from large tables consumes most of the system resources. When multiple client applications simultaneously access a database by using the DataReader object, the performance of data retrieval and other related processes is substantially reduced. In such a case, the database might refuse connections to other .NET applications until other clients free the resources.

What is the use of the Connection object?
Ans: The Connection object is used to connect your application to a specific data source by providing the required authentication information in connection string. The connection object is used according to the type of the data source. For example, the OleDbConnection object is used with an OLE-DB provider and the SqlConnection object is used with an MS SQL Server.

Explain the architecture of ADO.NET in brief.
Ans:  AD0.NET consists of two fundamental components: 
      *>  The DataSet, which is disconnected from the data source and does not need to know where the data that it holds is retrieved from. 
    *>The .net data provider, which allows you to connect your application to the data source and execute the SQL commands against it.
The data provider contains the Connection, Command, DataReader, and DataAdapter objects. The Connectionobject provides connectivity to the database. The Command object provides access to database commands to retrieve and manipulate data in a database. The DataReader object retrieves data from the database in the readonly and forward-only mode. The DataAdapter object uses Command objects to execute SQL commands. The DataAdapterobject loads the DataSet object with data and also updates changes that you have made to the data in the DataSetobject back to the database.

 Describe the disconnected architecture of ADO.NET's data access model.
Ans:  ADO.NET maintains a disconnected database access model, which means, the application never remains connected constantly to the data source. Any changes and operations done on the data are saved in a local copy (dataset) that acts as a data source. Whenever, the connection to the server is re-established, these changes are sent back to the server, in which these changes are saved in the actual database or data source.

What are the usages of the Command object in ADO.NET?
Ans:  The following are the usages of the Command object in AD0.NET:

The Command object in AD0.NET executes a command against the database and retrieves a DataReader or DataSetobject.
It also executes the INSERT, UPDATE, or DELETE command against the database.
All the command objects are derived from the DbCommand class.
The command object is represented by two classes: SqlCommand and OleDbCommand.
The Command object provides three methods to execute commands on the database:
  The ExecuteNonQuery() method executes a Transact-SQL statement against the connection and returns the number of rows affected.
       The ExecuteScalar() method returns a single value from a database query.
        The ExecuteReader() method returns a result set by using the DataReader object.

What is the use of DataView?
Ans:  User-defined view of a table is contained in a DataView. A complete table or a small section of table depending on some criteria can be presented by an object of the DataView class. You can use this class to sort and find data withinDataTable.
The DataView class has the following methods:

    Find() - Finds a row in a DataView by using sort key value.
    FindRows() - Uses the sort key value to match it with the columns of DataRowView objects. It returns an array of all the corresponding objects of DataRowView whose columns match with the sort key value.
                AddNew() - Adds a new row to the DataView object.
                Delete() - Deletes the specified row from the DataView object according to the specified index.

How can you add or remove rows from the DataTable object of DataSet?
Ans:  The DataRowCollection class defines the collection of rows for the DataTable object in a DataSet. TheDataTable class provides the NewRow() method to add a new DataRow to DataTable. The NewRow method creates a new row, which implements the same schema as applied to the DataTable. The following are the methods provided by the DataRowCollection object:
    Add() - Adds a new row to DataRowCollection.
     Remove()- Removes a DataRow object from DataRowCollection.
   RemoveAt() - Removes a row whose location is specified by an index number.

Explain in brief DataAdapter class in ADO.NET.
Ans:  The DataAdapter class retrieves data from the database, stores data in a dataset, and reflects the changes made in the dataset to the database. The DataAdapter class acts as an intermediary for all the communication between the database and the DataSet object. The DataAdapter Class is used to fill a DataTable or DataSet Object with data from the database using the Fill() method. The DataAdapter class applies the changes made in dataset to the database by calling the Update() method.

The DataAdapter class provides four properties that represent the database command:

SelectCommand, InsertCommand, DeleteCommand, and UpdateCommand.

State the differences between the Dispose() and Finalize().
Ans:  CLR uses the Dispose and Finalize methods to perform garbage collection of run-time objects of .NET applications. The Finalize method is called automatically by the runtime. CLR has a garbage collector (GC), which periodically checks for objects in heap that are no longer referenced by any object or program. It calls the Finalize method to free the memory used by such objects. The Dispose method is called by the programmer. Dispose is another method to release the memory used by an object. The Dispose method needs to be explicitly called in code to dereference an object from the heap. The Dispose method can be invoked only by the classes that implement the IDisposableinterface.

Differentiate between managed and unmanaged code?
Ans:  Managed code is the code that is executed directly by the CLR instead of the operating system. The code compiler first compiles the managed code to intermediate language (IL) code, also called as MSIL code. This code doesn't depend on machine configurations and can be executed on different machines.
Unmanaged code is the code that is executed directly by the operating system outside the CLR environment. It is directly compiled to native machine code which depends on the machine configuration.
In the managed code, since the execution of the code is governed by CLR, the runtime provides different services, such as garbage collection, type checking, exception handling, and security support. These services help provide uniformity in platform and language-independent behavior of managed code applications. In the unmanaged code, the allocation of memory, type safety, and security is required to be taken care of by the developer. If the unmanaged code is not properly handled, it may result in memory leak. Examples of unmanaged code are ActiveX components and Win32 APIs that execute beyond the scope of native CLR.

 What is garbage collection?
Ans:  Garbage collection prevents memory leaks during execution of programs. Garbage collector is a low-priority process that manages the allocation and deallocation of memory for your application. It checks for the unreferenced variables and objects. If GC finds any object that is no longer used by the application, it frees up the memory from that object.

How does CAS works?
Ans:  There are two key concepts of CAS security policy- code groups and permissions. A code group contains assemblies in it in a manner that each .NET assembly is related to a particular code group and some permissions are granted to each code group. For example, using the default security policy, a control downloaded from a Web site belongs to the Zone, Internet code group, which adheres to the permissions defined by the named permission set. (Normally, the named permission set represents a very restrictive range of permissions.)

What is Difference between NameSpace and Assembly?
Ans:  Following are the differences between namespace and assembly: 
·         Assembly is physical grouping of logical units, Namespace, logically groups classes.
·         Namespace can span multiple assembly.

What is Microsoft Intermediate Language (MSIL)?
Ans:  The .NET Framework is shipped with compilers of all .NET programming languages to develop programs. There are separate compilers for the Visual Basic, C#, and Visual C++ programming languages in .NET Framework. Each .NET compiler produces an intermediate code after compiling the source code. The intermediate code is common for all languages and is understandable only to .NET environment. This intermediate code is known as MSIL.

What is Common Language Specification (CLS)?
Ans:  CLS is a set of basic rules, which must be followed by each .NET language to be a .NET- compliant language. It enables interoperability between two .NET-compliant languages. CLS is a subset of CTS; therefore, the languages supported by CLS can use each other's class libraries similar to their own. Application programming interfaces (APIs), which are designed by following the rules defined in CLS can be used by all .NET-compliant languages.

What is the role of the JIT compiler in .NET Framework?
Ans:  The JIT compiler is an important element of CLR, which loads MSIL on target machines for execution. The MSIL is stored in .NET assemblies after the developer has compiled the code written in any .NET-compliant programming language, such as Visual Basic and C#.

JIT compiler translates the MSIL code of an assembly and uses the CPU architecture of the target machine to execute a .NET application. It also stores the resulting native code so that it is accessible for subsequent calls. If a code executing on a target machine calls a non-native method, the JIT compiler converts the MSIL of that method into native code. JIT compiler also enforces type-safety in runtime environment of .NET Framework. It checks for the values that are passed to parameters of any method. 

What is difference between System.String and System.StringBuilder classes?
Ans:  String and StringBuilder classes are used to store string values but the difference in them is that String is immutable (read only) by nature, because a value once assigned to a String object cannot be changed after its creation. When the value in the String object is modified, a new object is created, in memory, with a new value assigned to the String object. On the other hand, the StringBuilder class is mutable, as it occupies the same space even if you change the value. The StringBuilder class is more efficient where you have to perform a large amount of string manipulation.

Describe the roles of CLR in .NET Framework.
Ans:  CLR provides an environment to execute .NET applications on target machines. CLR is also a common runtime environment for all .NET code irrespective of their programming language, as the compilers of respective language in .NET Framework convert every source code into a common language known as MSIL or IL (Intermediate Language).

CLR also provides various services to execute processes, such as memory management service and security services. CLR performs various tasks to manage the execution process of .NET applications.

The responsibilities of CLR are listed as follows:
·         Automatic memory management
·         Garbage Collection
·         Code Access Security
·         Code verification
·         JIT compilation of .NET code

Explain the basic features of OOPs.
Ans:  The following are the four basic features of OOP:
Abstraction - Refers to the process of exposing only the relevant and essential data to the users without showing unnecessary information.
Polymorphism - Allows you to use an entity in multiple forms.
Encapsulation - Prevents the data from unwanted access by binding of code and data in a single unit called object.
Inheritance - Promotes the reusability of code and eliminates the use of redundant code. It is the property through which a child class obtains all the features defined in its parent class. When a class inherits the common properties of another class, the class inheriting the properties is called a derived class and the class that allows inheritance of its common properties is called a base class.

What are collections and generics?
Ans:  A collection can be defined as a group of related items that can be referred to as a single unit. TheSystem.Collections namespace provides you with many classes and interfaces. Some of them are - ArrayList,List, Stack, ICollection, IEnumerable, and IDictionary. Generics provide the type-safety to your class at the compile time. While creating a data structure, you never need to specify the data type at the time of declaration. The System.Collections.Generic namespace contains all the generic collections.

 How is method overriding different from method overloading?
Ans:  Overriding involves the creation of two or more methods with the same name and same signature in different classes (one of them should be parent class and other should be child).

Overloading is a concept of using a method at different places with same name and different signatures within the same class.

What is a multicast delegate?
Ans:  Each delegate object holds reference to a single method. However, it is possible for a delegate object to hold references of and invoke multiple methods. Such delegate objects are called multicast delegates or combinable delegates.

Define enumeration?
Ans:  Enumeration is defined as a value type that consists of a set of named values. These values are constants and are called enumerators. An enumeration type is declared using the enum keyword. Each enumerator in an enumeration is associated with an underlying type that is set, by default, on the enumerator. 

Explain the concept of constructor?
Ans:  Constructor is a special method of a class, which is called automatically when the instance of a class is created. It is created with the same name as the class and initializes all class members, whenever you access the class.
  
What is a delegate?
Ans:  A delegate is similar to a class that is used for storing the reference to a method and invoking that method at runtime, as required. A delegate can hold the reference of only those methods whose signatures are same as that of the delegate. Some of the examples of delegates are type-safe functions, pointers, or callbacks.

State the features of an interface.
Ans:  An interface is a template that contains only the signature of methods. The signature of a method consists of the numbers of parameters, the type of parameter (value, reference, or output), and the order of parameters. An interface has no implementation on its own because it contains only the definition of methods without any method body. An interface is defined using the interface keyword.

Define an array.
Ans:  An array is defined as a homogeneous collection of elements, stored at contiguous memory locations, which can be referred by the same variable name. All the elements of an array variable can be accessed by index values. An Index value specifies the position of a particular element in an array variable.

What is the function of the Try-Catch-Finally block?
Ans:  The try block encloses those statements that can cause exception and the catch block handles the exception, if it occurs. Catch block contains the statements that have to be executed, when an exception occurs. The finally block always executes, irrespective of the fact whether or not an exception has occurred. The finally block is generally used to perform the cleanup process. If any exception occurs in the try block, the program control directly transfers to its corresponding catch block and later to the finally block. If no exception occurs inside the try block, then the program control transfers directly to the finally block.

 What are abstract classes? What are the distinct characteristics of an abstract class?
Ans:  An abstract class is a class that cannot be instantiated and is always used as a base class.
The following are the characteristics of an abstract class:
·         You cannot instantiate an abstract class directly. This implies that you cannot create an object of the abstract class; it must be inherited.
·         You can have abstract as well as non-abstract members in an abstract class.
·         You must declare at least one abstract method in the abstract class.
·         An abstract class is always public.
·         An abstract class is declared using the abstract keyword.
The basic purpose of an abstract class is to provide a common definition of the base class that multiple derived classes can share.

What is a hashtable?
Ans:  Hashtable is a data structure that implements the IDictionary interface. It is used to store multiple items and each of these items is associated with a unique string key. Each item can be accessed using the key associated with it. In short, hashtable is an object holding the key-value pairs.

What do you mean by data encapsulation?
Ans:  Data encapsulation is a concept of binding data and code in single unit called object and hiding all the implementation details of a class from the user. It prevents unauthorized access of data and restricts the user to use the necessary data only.

 Explain the concept of destructor?
Ans:  A destructor is a special method for a class and is invoked automatically when an object is finally destroyed. The name of the destructor is also same as that of the class but is followed by a prefix tilde (~).

What is a static constructor?
Ans:  Static constructors are introduced with C# to initialize the static data of a class. CLR calls the static constructor before the first instance is created.

The static constructor has the following features:
·         No access specifier is required to define it.
·         You cannot pass parameters in static constructor.
·         A class can have only one static constructor.
·         It can access only static members of the class.
·         It is invoked only once, when the program execution begins.

Define an event.
Ans:  Whenever an action takes place in a class, that class provides a notification to other classes or objects that are assigned to perform particular tasks. These notifications are called events. For example, when a button is clicked, the class generates an event called Click. An event can be declared with the help of the event keyword.

What are structures?
Ans:  Structure is a heterogeneous collection of elements referenced by the same name. A structure is declared using the struct keyword.

What is IIS? Why is it used?
Ans:  Internet Information Services (IIS) is created by Microsoft to provide Internet-based services to ASP.NET Web applications. It makes your computer to work as a Web server and provides the functionality to develop and deploy Web applications on the server. IIS handles the request and response cycle on the Web server. It also offers the services of SMTP and FrontPage server extensions. The SMTP is used to send emails and use FrontPage server extensions to get the dynamic features of IIS, such as form handler.

What is tracing? Where is it used?
Ans:  Tracing displays the details about how the code was executed. It refers to collecting information about the application while it is running. Tracing information can help you to troubleshoot an application. It enables you to record information in various log files about the errors that might occur at run time. You can analyze these log files to find the cause of the errors.

What is the difference between authentication and authorization?
Ans:  Authentication verifies the identity of a user and authorization is a process where you can check whether or not the identity has access rights to the system. In other words, you can say that authentication is a procedure of getting some credentials from the users and verify the user's identity against those credentials. Authorization is a procedure of granting access of particular resources to an authenticated user. You should note that authentication always takes place before authorization.

Differentiate globalization and localization.
Ans:  The globalization is a technique to identify the specific part of a Web application that is different for different languages and make separate that portion from the core of the Web application. The localization is a procedure of configuring a Web application to be supported for a specific language or locale.

 What is ViewState?
Ans:  The ViewState is a feature used by ASP.NET Web page to store the value of a page and its controls just before posting the page. Once the page is posted, the first task by the page processing is to restore the ViewState to get the values of the controls.

What are HTTP handlers in ASP.NET?
Ans:  HTTP handlers, as the name suggests, are used to handle user requests for Web application resources. They are the backbone of the request-response model of Web applications. There is a specific event handler to handle the request for each user request type and send back the corresponding response object.

Each user requests to the IIS Web server flows through the HTTP pipeline, which refers to a series of components (HTTP modules and HTTP handlers) to process the request. HTTP modules act as filters to process the request as it passes through the HTTP pipeline. The request, after passing through the HTTP modules, is assigned to an HTTP handler that determines the response of the server to the user request. The response then passes through the HTTP modules once again and is then sent back to the user.

What are the events that happen when a client requests an ASP.NET page from IIS server?
Ans:  The following events happen when a client requests an ASP.NET page from the IIS server:
·         User requests for an application resource.
·         The integrated request-processing pipeline receives the first user request.
·         Response objects are created for each user request.
·         An object of the HttpApplication class is created and allocated to the Request object.
·         The HttpApplication class processes the user request.

 Describe the complete lifecycle of a Web page.
Ans:  When we execute a Web page, it passes from the following stages, which are collectively known as Web page lifecycle:
Page request - During this stage, ASP.NET makes sure the page either parsed or compiled and a cached version of the page can be sent in response
Start - During this stage sets the Request and Response page properties and the page check the page request is either a postback or a new request
Page Initialization - During this stage, the page initialize and the control's Unique Id property are set
Load - During this stage, if the request is postback, the control properties are loaded without loading the view state and control state otherwise loads the view state
Validation - During this stage, the controls are validated
Postback event handling - During this stage, if the request is a postback, handles the event
Rendering - During this stage, the page invokes the Render method to each control for return the output
Unload - During this stage, when the page is completely rendered and sent to the client, the page is unloaded.

What is a Cookie? Where is it used in ASP.NET?
Ans:  Cookie is a lightweight executable program, which the server posts to client machines. Cookies store the identity of a user at the first visit of the Web site and validate them later on the next visits for their authenticity. The values of a cookie can be transferred between the user's request and the server's response.

What is State Management? How many ways are there to maintain a state in .NET?
Ans:  State management is used to store information requests. The state management is used to trace the information or data that affect the state of the applications.

There are two ways to maintain a state in .NET, Client-Based state management and Server-Based state management.

The following techniques can be used to implement the Client-Based state management:
View State, Hidden Fields, Cookies, Query Strings, Control State.
The following techniques can be used to implement Server-Based state management:
Application State, Session State, Profile Properties

What are the major built-in objects in ASP.NET?
Ans:  The major built-in objects in ASP.NET are as follows:
Application, Request, Response, Server, Session, Context, Trace.

What is the difference between HTML and Web server controls?
Ans:  HTML controls are client-side controls; therefore, all the validations for HTML controls are performed at the client side. On the other hand, Web server controls are server-side controls; therefore, all the validations for Web server controls are performed at the server side.

Explain the validation controls. How many validation controls in ASP.NET 4.0?
Ans: Validation controls are responsible to validate the data of an input control. Whenever you provide any input to an application, it performs the validation and displays an error message to user, in case the validation fails.

ASP.NET 4.0 contains the following six types of validation controls:
·         CompareValidator - Performs a comparison between the values contained in two controls.
·         CustomValidator - Writes your own method to perform extra validation.
·         RangeValidator- Checks value according to the range of value.
·         RegularExpressionValidator - Ensures that input is according to the specified pattern or not.
·         RequiredFieldValidator - Checks either a control is empty or not.
·         ValidationSummary - Displays a summary of all validation error in a central location.

What events are fired when a page loads?
Ans:  The following events fire when a page loads:
·         Init() - Fires when the page is initializing.
·         LoadViewState() - Fires when the view state is loading.
·         LoadPostData() - Fires when the postback data is processing.
·         Load() - Fires when the page is loading.
·         PreRender() - Fires at the brief moment before the page is displayed to the user as HTML.
·         Unload() - Fires when the page is destroying the instances of server controls.

 What is cross-page posting in ASP.NET?
Ans:  The Server.Transfer() method is used to post data from one page to another. In this case, the URL remains the same. However, in cross page posting, data is collected from different Web pages and is displayed on a single page. To do so, you need to set the PostBackUrl property of the control, which specifies the target page. In the target page, you can access the PreviousPage property. For this, you need to use the @PreviousPageType directive. You can access the controls of previous page by using the FindControl() method.

Explain the Application and Session objects in ASP.NET.
Ans: Visit google and enjo. J

 What are Web server controls in ASP.NET?
Ans:  The ASP.NET Web server controls are objects on the ASP.NET pages that run when the Web page is requested. Many Web server controls, such as button and text box, are similar to the HTML controls. In addition to the HTML controls, there are many controls, which include complex behavior, such as the controls used to connect to data sources and display data.

Explain the concept of states in ASP.NET.
Ans:  State is quite an innovative concept in Web development because it eliminates the drawback of losing state data due to reloading of a Web page. By using states in a Web application, you can preserve the state of the application either at the server or client end. The state of a Web application helps you to store the runtime changes that have been made to the Web application. For example, as already described earlier, a change in the data source of the Web application might be initiated by a user when he/she selects and saves some products in the shopping cart.  

More Details:http://goo.gl/LV46sP

No comments:

Post a Comment