MS.NET Interview Questions -19

MS.NET Interview Questions -19

1.What’s the difference between Response.Write() andResponse.Output.Write()?

Response.Output.Write() allows you to write formatted output.

2.What methods are fired during the page load?

Init() - when the page is instantiated
Load() - when the page is loaded into server memory
PreRender() - the brief moment before the page is displayed to the user as HTML
Unload() - when page finishes loading.

3.When during the page processing cycle is ViewState available?
  
After the Init() and before the Page_Load(), or OnLoad() for a control.

4.What namespace does the Web page belong in the .NET Framework class hierarchy?
  
System.Web.UI.Page

5.Where do you store the information about the user’s locale?
  
System.Web.UI.Page.Culture

6. What’s a bubbled event?
  
When you have a complex control, like DataGrid, writing an event processing routine for each object (cell, button, row, etc.) is quite tedious. The controls can bubble up their
eventhandlers, allowing the main DataGrid event handler to take care of its constituents.
          
7.What data types do the RangeValidator control support?
  
Integer, String, and Date.

8. What is the difference between Server.Transfer and Response.Redirect? Why would I choose  one over the other? 
  
Server.Transfer transfers page processing from one page directly to the next page without making a  round-trip back to the client's browser. This provides a faster response with a little less overhead on the server. Server.Transfer does not update the clients url history list or current url. Response.Redirect is used to redirect the user's browser to another page or site. This performas a trip back to the client where the client's browser is redirected to the new page. The user's browser history list is updated to reflect the new address.

9. What base class do all Web Forms inherit from?
 
The Page class.

10. What is ViewState?
 
ViewState allows the state of objects (serializable) to be stored in a hidden field on the page. ViewState is transported to the client and back to the server, and is not stored on the server or any other external source. ViewState is used the retain the state of server-side objects between postabacks.

11. What does the "EnableViewState" property do? Why would I want it on or off?
 
It allows the page to save the users input on a form across postbacks. It saves the server-side values for a given control into ViewState, which is stored as a hidden value on the page before sending the page to the clients browser. When the page is posted back to the server the server control is recreated with the state stored in viewstate.     

12.  How to manage state in Asp.Net Web applications?
 
State management is done at client side and server side
Client Side: Client Side it can achieved with the help of View state, Cookies, Query String,hidden fields    and control state.
Server Side: with the help of Cache, Application,Session and Database.

13. What is smart navigation? 
  
The cursor position is maintained when the page gets refreshed due to the server side validation and the page gets refreshed.

14. What is System.Web.Mail?

System.Web.Mail (SWM) is the .Net namespace used to send email in .Net Framework applications.  SWM contains three classes:

1. MailMessage - used for creating and manipulating the mail message contents.
2. MailAttachments - used for creating a mail attachment to be added to the mail message.
3. SmtpMail - used for sending email to the relay mail server.

15. How many objects does ADO.Net have and what are they?

There are 5 objects in ADO.Net.
They are Connection, Adapter, Command, Reader and Dataset.
  
16.  How does ASP.Net page works?
   
1. When a browser requests an HTML file, the server returns the file
2. When a browser requests an ASP.Net file, IIS passes the request to the ASP.Net engine on the server.
3. The ASP.Net engine reads the file, line by line, and executes the scripts in the file
4. Finally, the ASP.Net file is returned to the browser as plain HTML.

17.How do you debug an ASP.Net Web application?
    
Attach the aspnet_wp.exe process to the DbgClr debugger.

18. In order to get assembly info which namespace we should have import?
    
System.Reflection Namespace

19.What is an interface and what is an abstract class?Please, expand by examples of using both. Explain why.

In a interface class, all methods are abstract with out implementation where as in an abstract class some methods we can define concrete. In inter face, no accessibility modifiers are allowed.
An abstract class may have accessibility modifiers. Interface and abstract class are basically a set of rules which u have to follow in case you are using them (inheriting them).

20.What is an Interface?

An interface is not a class. It is an entity that is defined by the word Interface. An interface has no implementation; it only has the signature or inother words, just the definition of the
methods without the body. As one of the similarities to Abstract class, it is a contract that isused to define hierarchies for all subclasses or it defines specific set of methods and their
arguments. The main difference between them is that a class can implement more than one interface but can only inherit from one abstract class. Since C# doesn?t support multipleinheritance, interfaces are used to implement multiple inheritance.

21. Why The JavaScript Validation Not Run on the Asp.Net?

The Asp.Net Button Is post backed on the server & not yet Submit & when It goes to the server its states is lost So if we r using JavaScript in o
ur application so we always use the Input Button in the asp Button.

22. What is Delegation?

A delegate acts like a strongly type function pointer. Delegates can invoke the methods thatthey reference without making explicit calls to those methods.Delegate is an entity that is entrusted with the task of representation,
assign or passing on information. In code sense, it means a Delegate is entrusted with a Method to report information back to it when a certain task (which the Method expects) is accomplished outside
the Method's class.

23. What is Reflection?

It extends the benefits of metadata by allowing developers to inspect and use it at runtime. Forexample, dynamically determine all the classes contained in a given assembly and invoke theirmethods.
Reflection provides objects that encapsulate assemblies, modules, and types. You can use reflection to dynamically create an instance of a type, bind the type to an existing object, or get
the type from an existing object. You can then invoke the type's methods or access its fields and properties.

24. What is the root class in .Net ?

Object

25. Which property of the textbox cannot be changed at runtime?

Locked Porperty.

26. With respect to security, which one is the better choice?Net or J2EE? Explain.

As per majority programmers .NET is the best one whch have single vendor compare to ,the eace of use, more use friendly can send any problem,it'll be solved.

27.Which method do you invoke on the DataAdapter control to load your generated dataset with data?

dataAdapter.Fill(ds). The beauty of this method is it automatically implicitly opens the connection to database and closes it once done.We dont need to worry about opening and
closing the connection to the database.

28.What is GAC?

GAC (Global Assembly Cache) is used where shared .NET assembly reside. GAC is used in the following situations:-

    If the application has to be shared among several application.
    If the assembly has some special security requirements like only administrators can remove the assembly.

29.How to add and remove an assembly from GAC?

There are two ways to install .NET assembly in GAC:-

    Using Microsoft Installer Package.
    Using Gacutil. Goto “Visual Studio Command Prompt” and type “gacutil –i (assembly_name)”, where (assembly_name) is the DLL name of the project.

30.Can we force garbage collector to run?

System.GC.Collect () forces garbage collector to run. This is not recommended but can be used if situations arise.

31.What is reflection?

All .NET assemblies have metadata information stored about the types defined in modules. This metadata information can be accessed by mechanism called as “Reflection”.
System. Reflection can be used to browse through the metadata information.

32.What are Value types and Reference types?

Value types directly contain their data which are either allocated on the stack or allocated in-line in a  structure.
Reference types store a reference to the value's memory address, and are allocated on the heap. Reference types can be self-describing types, pointer types, or interface types.

33.What is concept of Boxing and UnBoxing?

Boxing is converting a value type to a reference type (Object Type).
Unboxing is vice versa of boxing operation where the value is copied from the instance in to appropriate storage location.

34.What is concept of Casting?

Casting is converting a reference type to a reference type or a value type as another value type

35.What is Exception? What is the difference between System exceptions and Application exceptions?

An exception is what happens when something goes wrong with the code at runtime. All exception derives from Exception Base class. Exceptions can be generated programmatically or can be generated by system.
Application exception is used when we want to define user defined exception.
System exception is all which is defined by .NET.

36.What is the difference between Convert.toString and .toString () method?

The basic difference between them is “Convert” function handles NULLS while “i.ToString ()” does not, it will throw a NULL reference exception error.

37.What is the difference between Convert.toString and .toString () method?

The basic difference between them is “Convert” function handles NULLS while “i.ToString ()” does not, it will throw a NULL reference exception error.

38.What is Native Image Generator (Ngen.exe)?

The Native Image Generator utility (Ngen.exe) allows you to run the JIT compiler on your assembly's MSIL and generate native machine code which is cached to disk. After the image is created .NET runtime will use the image to run the code rather than from the hard disk.

39.What is CodeDom?

“CodeDom” is an object model which represents actually a source code. It is designed to be language independent - once you create a “CodeDom” hierarchy for a program we can then generate the source code in any .NET compliant language.
The Native Image Generator utility (Ngen.exe) allows you to run the JIT compiler on your assembly's MSIL and generate native machine code which is cached to disk. After the image is created .NET runtime will use the image to run the code rather than from the hard disk.

40.What is CodeDom?

“CodeDom” is an object model which represents actually a source code. It is designed to be language independent - once you create a “CodeDom” hierarchy for a program we can then generate the source code in any .NET compliant language.

41.How can we use COM Components in .NET?

.NET components communicate with COM using RCW (Runtime Callable Wrapper). Following are the ways with which you can generate RCW :-
 Adding reference in Visual Studio.net. See figure below (Adding reference using VS.NET 2005). Wrapper class is generated and placed in the “BIN” directory.
                               
42.When we use windows API in .NET is it managed or unmanaged code?

Windows API in .NET is unmanaged code.

43.What is COM ?

Microsoft’s COM is a technology for component software development. It is a binary standard which is language independent. DCOM is a distributed extension of COM.

44. What is Multi-tasking ?

It’s a feature of modern operating systems with which we can run multiple programs at same time example Word, Excel etc.

45. What is Multi-threading ?

Multi-threading forms subset of Multi-tasking. Instead of having to switch between programs this feature switches between different parts of the same program. Example you are writing in word and at the same time word is doing a spell check in background.

46.What is a Thread ?

A thread is the basic unit to which the operating system allocates processor time.

47. Did VB6 support multi-threading ?

While VB6 supports multiple single-threaded apartments, it does not support a freethreading model, which allows multiple threads to run against the same set of data.

48. Can we have multiple threads in one App domain ?

One or more threads run in an AppDomain. An AppDomain is a runtime representation of a logical process within a physical process. Each AppDomain is started with a single thread, but can create additional threads from any of its threads.

49. Which namespace has threading ?

Systems.Threading has all the classes related to implement threading. Any .NET application who wants to implement threading has to import this namespace.

50. What does AddressOf operator do in background ?

The AddressOf operator creates a delegate object to the BackgroundProcess method. A delegate within VB.NET is a type-safe, object-oriented function pointer. After the thread has been instantiated, you begin the execution of the code by calling the Start() method of the thread.

51. How can you reference current thread of the method ?

"Thread.CurrentThread" refers to the current thread running in the method."CurrentThread" is a public static property.

52.  What's Thread.Sleep() in threading ?

Thread's execution can be paused by calling the Thread.Sleep method. This method takes an integer value that determines how long the thread should sleep. Example Thread.CurrentThread.Sleep(2000).

53. How can we make a thread sleep for infinite period ?

You can also place a thread into the sleep state for an indeterminate amount of time by calling Thread.Sleep (System.Threading.Timeout.Infinite). To interrupt this sleep you can call the Thread.Interrupt method.

54.  What is Suspend and Resume in Threading ?

It is Similar to Sleep and Interrupt. Suspend allows you to block a thread until another thread calls Thread.Resume. The difference between Sleep and Suspend is that the latter does not immediately place a thread in the wait state. The thread does not suspend until the .NET runtime determines that it is in a safe place to suspend it. Sleep will immediately place a thread in a wait state.

55. What the way to stop a long running thread ?

Thread.Abort() stops the thread execution at that moment itself.

56. Can we use events with threading ?

Yes, you can use events with thread; this is one of the techniques to synchronize one thread with other.

57. How can we know a state of a thread?

"ThreadState" property can be used to get detail of a thread. Thread can have one or a combination of status.System.Threading. Threadstate enumeration has all the values to detect a state of thread. Some sample states are Isrunning, IsAlive, suspended etc.

58. What is use of Interlocked class ?

Interlocked class provides methods by which you can achieve following functionalities :
     Increment Values.
     Decrement values.
     Exchange values between variables.
     Compare values from any thread.

59. What is a monitor object?

Monitor objects are used to ensure that a block of code runs without being interrupted by code running on other threads. In other words, code in other threads cannot run until code in the synchronized code block has finished. SyncLock and End SyncLock statements are provided in order to simplify access to monitor object.

60. What is the sequence in which ASP.NET events are processed ?

Following is the sequence in which the events occur :

     Page_Init.
    Page_Load.
    Control events
     Page_Unload event.

Page_init event only occurs when first time the page is started, but Page_Load occurs in subsequent request of the page.

61.Explain the differences between Server-side and Clientside code?

Server side code is executed at the server side on IIS in ASP.NET framework, while client side code is executed on the browser.

62. How can you avoid deadlock in threading?

A good and careful planning can avoid deadlocks.There are so many ways Microsoft has provided by which you can reduce deadlocks example Monitor, Interlocked classes, Wait handles, Event raising from one thread to other thread, ThreadState property which you can poll and act accordingly etc.

63. What is the difference between thread and process?

A thread is a path of execution that run on CPU, a process is a collection of threads that share the same virtual memory. A process has at least one thread of execution, and a thread always run in a process context.
A good and careful planning can avoid deadlocks.There are so many ways Microsoft has provided by which you can reduce deadlocks example Monitor, Interlocked classes, Wait handles, Event raising from one thread to other thread, ThreadState property which you can poll and act accordingly etc.

64. What is the difference between thread and process?

A thread is a path of execution that run on CPU, a process is a collection of threads that share the same virtual memory. A process has at least one thread of execution, and a thread always run in a process context.

65.What is an application object ?

Application object ca be n used in situation where we want data to be shared across users globally.

66.What’s the difference between Cache object and application object ?

The main difference between the Cache and Application objects is that the Cache object provides cache-specific features, such as dependencies and expiration policies.

67.How can get access to cache object ?

The Cache object is defined in the System.Web.Caching namespace. You can get a reference to the Cache object by using the Cache property of the HttpContext class in the System.Web namespace or by using the Cache property of the Page object.

68.What are dependencies in cache and types of dependencies ?

When you add an item to the cache, you can define dependency relationships that can force that item to be removed from the cache under specific activities of dependenci es.Example if the cache object is dependent on file and when the file data changes you want the cache object to be update. Following are the supported dependency :-

File dependency :- Allows you to invalidate a specific cache item when a diskbased file or files change.
Time-based expiration :- Allows you to invalidate a specific cache item depending on predefined time.
Key dependency :-Allows you to invalidate a specific cache item depending when another cached item changes.

69. What is view state and use of it?

The current property settings of an ASP.NET page and those of any ASP. NET server controls contained within the page. ASP.NET can detect when a form is requested for the first time versus when the form is posted (sent to the server), which allows you to program accordingly.

70. What are the validation controls?

A set of server controls included with ASP.NET that test user input in HTML and Web server controls for programmer-defined requirements. Validation controls perform input checking in server code. If the user is working with a browser that supports DHTML. the validation controls can also petform validation using client script.

71. What is the difference between Response.Write() and Response.Output.WriteO?

The latter one allows you to write formatted output.

72. What methods are fired during the page load? Init()

When the page is instantiated, Load() - when the page is loaded into server memory,PreRender () - the brief moment before the page is displayed to the user as HTML, Unload() - when page finishes loading.

73. Where does the Web page belong in the .NET Framework class hierarchy?

ystem.Web.U1.Page

74. How do you read an XML file into a DataSet?

Using the DataSet object’s ReadXML method.

75. When do you use ExecuteReader, ExecuteNonQuery, ExecuteScalar methods?

    If the command or stored procedure that is being executed returns a set of rows, then we use ExecuteReader method.
    If the command or stored procedure that is being executed returns a single value then we use ExecuteScalar method.
    If the command or stored procedure performs INSERT, DELETE or UPDATE operations, then we use ExecuteNonQuery method. ExecuteNonQuery method returns an integer specifying the number of rows inserted, deleted or updated.

76. What is Microsoft ADO.NET?

Visual Studio .NET provides access to databases through the set of tools and namespaces collectively referred to as Microsoft ADO.NET

77. Can you reuse a SqlCommand object?

Yes, you can reset the CommandText property and reuse the SqlCommand object.

78. What are the methods that can ensure asynchronous execution of the Transact-SQL statement or stored procedure?

BeginExecuteNonQuery
BeginExecuteReader

79. Give an example scenario of using a DataSet and a DataReader?

If you want to just read and display the data(No updates, deletes, or inserts) then use a DataReader.
If you want to do a batch inserts, updates and deletes then use a DataSet.

80. What is AppSetting Section in “Web.Config” file ?

Web.config file defines configuration for a webproject. Using “AppSetting” section we can define user defined values. Example below defined is “ConnectionString” section which will be used through out the project for database connection.
<configuration>
<appSettings>
<add key="ConnectionString" value="server=xyz;pwd=www;database=testing" />
</appSettings>

81. How can we create custom controls in ASP.NET ?

User controls are created using .ASCX in ASP.NET. After .ASCX file is created you need to two things in order that the ASCX can be used in project

82. How can you enable automatic paging in DataGrid ?

Following are the points to be done in order to enable paging in Datagrid :-

Set the “AllowPaging” to true.
In PageIndexChanged event set the current pageindex clicked

83. How do you upload a file in ASP.NET ?

I will leave this to the readers … Just a hint we have to use System.Web.HttpPostedFile
class.

84. How do I send email message from ASP.NET ?

ASP.NET provides two namespaces System.WEB.mailmessage class and System.Web.Mail.Smtpmail class. Just a small homework create a Asp.NET project and send a email at shiv_koirala@yahoo.com. Do not Spam.

85. How do you programatically check if a specified SqlDataReader instance has been closed?

Use the IsClosed property of SqlDataReader to check if a specified SqlDataReader instance has been closed. If IsClosed property returns true, the SqlDataReader instance has been closed else not closed.

86. How do you get the total number of columns in the current row of a SqlDataReader instance?

FieldCount property can be used to get the total number of columns in the current row of a SqlDataReader instance.

87. What is the use of SqlParameter.Direction Property?

SqlParameter.Direction Property is used to specify the Sql Parameter type - input-only, output-only, bidirectional, or a stored procedure return value parameter. The default is Input.

88.What is a Managed Code?

Managed code runs inside the environment of CLR i.e. .NET runtime. In short all IL are managed code. But if you are using some third party software example VB6 or VC++ component they are unmanaged code as .NET runtime (CLR) does not have control over the source code execution of the language.

89.What is an Assembly?

Assembly is unit of deployment like EXE or a DLL. An assembly consists of one or more files (dlls, exe’s, html files etc.), and represents a group of resources, type definitions, and implementations of those types.An assembly may also contain references to other assembles.

90.What are the different types of Assembly?

There are two types of assembly Private and Public assembly (Shared Assembly).

A private assembly is normally used by a single application, and is stored in the application's directory, or a sub-directory beneath.
A shared assembly is normally stored in the global assembly cache, which is a repository of assemblies maintained by the .NET runtime.

91.What is a Manifest?

Assembly metadata is stored in Manifest. Manifest contains all the metadata needed to do the following things:
Version of assembly
Security identity
Scope of the assembly
Resolve references to resources and classes.

92. What is NameSpace?

Namespace has two basic functionalities:-

Namespace logically group types. Ex: - System.Web.UI logically groups our UI related features.
In Object Oriented world many times it’s possible that programmers will use the same class name. By qualifying NameSpace with class name this collision is able to be removed.

93.Can we force garbage collector to run?

System.GC.Collect () forces garbage collector to run. This is not recommended but can be used if situations arise.

94.What is reflection?

All .NET assemblies have metadata information stored about the types defined in modules. This metadata information can be accessed by mechanism called as “Reflection”.
System. Reflection can be used to browse through the metadata information.

95. What is the difference between SqlCommand and SqlCommandBuilder?
     
SQLCommand is used to retrieve or update the data from database.
SQLCommandBuilder object is used to build & execute SQL (DML) queries like select insert update& delete.

96.What is the use of SqlCommandBuilder?
     
SQL CommandBuilder object is used to build & execute SQL (DML) queries like select insert update& delete.

97.What are managed providers?
     
A managed provider is analogous to ODBC driver or OLEDB provider. It performs operation of communicating with the database. ADO.NET currently provides two distinct managed providers. The SQL Server managed provider is used with SQL server and is a very efficient way of communicating with SQL Server. OLEDB managed provider is used to communicate with any OLEDB compliant database like Access or Oracle.

98.How do I delete a row from a DataTable?
     
ds.Tables("data_table_name").Rows(i).Delete
dscmd.update(ds,"data_table_name")

99. What inside in DataSet?
     
Inside DataSet much like in Database, there are tables, columns, constraints, relationships, views and so forth.

100. What is the role of the DataReader class in ADO.NET connections?
     
It returns a read-only, forward-only rowset from the data source. A DataReader provides fast access when a forward-only sequential read is needed.

101. What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET?
     
SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix. OLE-DB.NET is a .NET layer on top of the OLE layer, so it’s not as fastest and efficient as SqlServer.NET.

0 comments:

Post a Comment