About Me

Hyderabad, Andhra Pradesh, India

Wednesday, June 20, 2012

Interivew Question and Answers





http://www.dotnetcurry.com/ShowArticle.aspx?ID=63

http://www.dotnetcurry.com/ShowArticle.aspx?ID=70

http://www.dotnetfunda.com/interview/


---------------------------------------------------------------------------------


Below are some useful questions:


1. What is ViewState? 

2. What is Application Object?


3.
What is the use of GAC?

4.
What are the differences between Abstract Class and Interface?

5.
Difference between DataSet and DataReader?  

6.
Difference between Server.Transfer and Response.Redirect?

7.  Types of Session state mode?

8.  Types of Caching?

9.  What is Replication?


10. What is Transactions?

11. 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.

12. In which event are the controls fully loaded?

Page load event guarantees that all controls are fully loaded. Controls are also accessed in Page_Init events but you will see that view state is not fully loaded during this event.5
(B) How can we identify that the Page is Post Back?
Page object has an “IsPostBack” property, which can be checked to know that is the page posted back.

13. What is event bubbling?

Server controls like Data grid, Data List, and Repeater can have other child controls inside them. Example Data Grid can have combo box inside data grid. These child control do not raise there events by themselves, rather they pass the event to the container parent (which can be a data grid, data list, repeater), which passed to the page as “ItemCommand” event. As the child control send events to parent it is termed as event bubbling.

14. How do we assign page specific attributes?

Page attributes are specified using the @Page directive.

15. How do we ensure view state is not tampered?

Using the @Page directive and setting ‘EnableViewStateMac’ property to True.

16. What is the use of @ Register directives?

@Register directive informs the compiler of any custom server control added to the page.

17. What is the use of Smart Navigation property?

It’s a feature provided by ASP. NET to prevent flickering and redrawing when the page is posted back.
Note:- This is only supported for IE browser. Project is who have browser compatibility as requirements have to think some other ways of avoiding flickering.

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

Web.config file defines configuration for a web project. Using “AppSetting” section, we can define user-defined values. Example below defined is “Connection String” 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>

19. Where is View State information stored?

In HTML Hidden Fields.

20. what is the use of @ Output Cache directive in ASP.NET.

It is used for caching.

21. 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:.

• Register the ASCX control in page using the <percentage@ Register directive.Example

<%@ Register tag prefix="Accounting" Tag name="footer" Src="Footer.ascx" %>

• Now to use the above accounting footer in page you can use the below directive.

<Accounting: footer runat="server" />

22. How many types of validation controls are provided by ASP.NET?

There are six main types of validation controls:-

RequiredFieldValidator

It checks whether the control have any value. It is used when you want the control should not be empty.

RangeValidator

It checks if the value in validated control is in that specific range. Example TxtCustomerCode should not be more than eight lengths.

CompareValidator

It checks that the value in controls should match some specific value. Example Textbox TxtPie should be equal to 3.14.

RegularExpressionValidator

When we want the control, value should match with a specific regular expression.

CustomValidator
It is used to define User Defined validation.
Validation Summary
It displays summary of all current validation errors on an ASP.NET page.
Note: - It is rare that some one will ask step by step all the validation controls. Rather they will ask for what type of validation which validator will be used. Example in one of the interviews i was asked how will you display summary of all errors in the validation control...just uttered one word Validation summary.

23. Can you explain “AutoPostBack”?

If we want the control to automatically post back in case of any event, we will need to check this attribute as true. Example on a Combo Box change we need to send the event immediately to the server side then set the “AutoPostBack” attribute to true.

24. How can you enable automatic paging in Data Grid?

Following are the points to be done in order to enable paging in Data grid:-
• Set the “Allow Paging” to true.
• In PageIndexChanged event set the current page index clicked.
Note: - The answers are very short, if you have implemented practically its just a revision. If you are fresher, just make sample code using Datagrid and try to implement this functionality.

25. What is the use of “GLOBAL.ASAX” file?

It allows to execute ASP.NET application level events and setting application-level variables.

26. What is the difference between “Web.config” and “Machine.Config”?

“Web.config” files apply settings to each web application, while “Machine.config” file apply settings to all ASP.NET applications.

27. What is a SESSION and APPLICATION object?

Session object store information between HTTP requests for a particular user, while application object are global across users.

28. What is IL code, CLR, CTS, GAC & GC? 

29. How can we do Assembly versioning? 

30. can you explain how ASP.NET application life cycle and page life cycle events fire? 

31. What is the problem with Functional Programming? 

32. Can you define OOP and the 4 principles of OOP? 

33. What are Classes and Objects? 

34. What is Inheritance? 

35. What is Polymorphism, overloading, overriding and virtual? 

36. Can you explain encapsulation and abstraction? 

37. What is an abstract class? 

38. Define Interface & What is the diff. between abstract & interface? 

39. What problem does Delegate Solve ? 

40. What is a Multicast delegate ? 

41. What are events and what's the difference between delegates and events?
  
42. How can we make Asynchronous method calls using delegates ? 

43. What is a stack, Heap, Value types and Reference types ? 

44. What is boxing and unboxing ? 

45. Can you explain ASP.NET application and Page life cycle ? 

46. What is Authentication, Authorization, Principal & Identity objects? 

47. How can we do Inproc and outProc session management ? 

48. How can we windows , forms and passport authentication and authorization in ASP.NET ? 

49. In a parent child relationship which constructor fires first ? 

50. How to create a simple "Hello World" using ASP.NET MVC template? 

51. How to pass data from controller to views? 

52. Can we see a simple sample of model using MVC template? 

53. How can we create simple input screens using MVC template? 

54. How can we create MVC views faster and make them strong typed by using HTML helper?

55. Can we see how easy it is do unit testing for MVC application?

56. What is MVC routing?

57. How can we set default values & validate MVC routes?

Tuesday, January 3, 2012

Why are the get/set properties so useful?

Lots of reasons, but the biggest one is control and conversion.

Control:
Let's assume that for some reason, my value can only be from 1-10.
If I allow the user to assign a value outside that range, my program
may
crash or do weird things. If the setter does not allow a value outside
the
range 1-10, I don't have this problem. Likewise, let's say that I want
to
change some OTHER variable when you set one of the values. I can do
that in the setter. Finally, suppose that I don't want to do things if
the
value you give me is the same as the current value. I can do that in a
setter.

Conversion:
If I have a set routine that takes a value of another type, such as a
string
instead of an integer, I can convert it to whatever I want without the
user
being aware of what my internal representation is.

Thursday, December 15, 2011

MCTS E-book for Microsoft Certification Exam

Here I am attaching the most useful book for Microsoft Certification Exam Preparation.
The book contains all the concepts of ASP.Net and is very useful for .Net Developers.


https://docs.google.com/open?id=0B9TnMbt-PylYMDMzOGZlYTEtZTIxZS00NDU2LWIzNzAtNWNmYjUwNGQ0NTgy



Monday, August 22, 2011

Tuesday, August 9, 2011

Garbage Collector in .NET

How it really works

Garbage collection is a process of releasing the memory used by the objects, which are no longer referenced. This is done in different ways and different manners in various platforms and languages. We will see how garbage collection is being done in .NET.

Garbage Collection basis
  • Almost every program uses resources such as database connection, file system objects etc. In order to make use of these things some resources should be available to us.
  • First we allocate a block of memory in the managed memory by using the new keyword.
  • Use the constructor of the class to set the initial state of the object.
  • Use the resources by accessing the type's members
  • At last CLEAR THE MEMORY
But how many times have programmers forgotten to release the memory. Or how many times the programmers try to access the memory which was cleaned.

These two are the serious bugs, which will lead us to memory leak and commonly occurring. In order to overcome these things the concept of automatic memory management has come. Automatic memory management or Automatic garbage collection is a process by which the system will automatically take care of the memory used by unwanted objects (we call them as garbage) to be released. Hurrah... Thanks to Microsoft's Automatic Garbage collection mechanism.

Automatic Garbage Collection in .NET


When Microsoft planned to go for a new generation platform called .NET with the new generation language called C#, their first intention is to make a language which is developer friendly to learn and use it with having rich set of APIs to support end users as well. So they put a great thought in Garbage Collection and come out with this model of automatic garbage collection in .NET.

They implemented garbage collector as a separate thread. This thread will be running always at the back end. Some of us may think, running a separate thread will make extra overhead. Yes. It is right. That is why the garbage collector thread is given the lowest priority. But when system finds there is no space in the managed heap (managed heap is nothing but a bunch of memory allocated for the program at run time), then garbage collector thread will be given REALTIME priority (REALTIME priority is the highest priority in Windows) and collect all the un wanted objects.

How does Garbage collector locate garbage


When an program is loaded in the memory there will be a bunch of memory allocated for that particular program alone and loaded with the memory. This bunch of memory is called Managed Heap in .NET world. This amount of memory will only be used when an object is to be loaded in to the memory for that particular program.

This memory is separated in to three parts :
  • Generation Zero
  • Generation One
  • Generation Two
Ideally Generation zero will be in smaller size, Generation one will be in medium size and Generation two will be larger.

When we try to create an object by using NEW keyword the system will,
  • Calculate the number of bytes required for the object or type to be loaded in to the managed heap.
  • The CLR then checks that the bytes required to allocate the object are available in the reserved region (committing storage if necessary). IF the object fits, it is allocated at the address pointed to by NextObjPtr.
  • These processes will happen at the Generation zero level.
When Generation Zero is full and it does not have enough space to occupy other objects but still the program wants to allocate some more memory for some other objects, then the garbage collector will be given the REALTIME priority and will come in to picture.

Now the garbage collector will come and check all the objects in the Generation Zero level. If an object's scope and lifetime goes off then the system will automatically mark it for garbage collection.

Note:

Here in the process the object is just marked and not collected. Garbage collector will only collect the object and free the memory.

Garbage collector will come and start examining all the objects in the level Generation Zero right from the beginning. If it finds any object marked for garbage collection, it will simply remove those objects from the memory.

Here comes the important part. Now let us refer the figure below. There are three objects in the managed heap. If A and C are not marked but B has lost it scope and lifetime. So B should be marked for garbage collection. So object B will be collected and the managed heap will look like this.
But do remember that the system will come and allocate the new objects only at the last. It does not see in between. So it is the job of garbage collector to compact the memory structure after collecting the objects. It does that also. So the memory would be looking like as shown below now.
But garbage collector does not come to end after doing this. It will look which are all the objects survive after the sweep (collection). Those objects will be moved to Generation One and now the Generation Zero is empty for filling new objects.

If Generation One does not have space for objects from Generation Zero, then the process happened in Generation Zero will happen in Generation one as well. This is the same case with Generation Two also.

You may have a doubt, all the generations are filled with the referred objects and still system or our program wants to allocate some objects, then what will happen? If so, then the MemoryOutofRangeException will be thrown.

Dispose

Instead of declaring a Finalizer, exposing a Dispose method is considered as good.

public void Dispose()

{
// all clean up source code here..
GC.SuppressFinalize(this);
}
If we clean up a object, using Dispose or Close method, we should indicate to the runtime that the object is no longer needed finalization, by calling GC.SuppressFinalize() as shown above.

If we are creating and using objects that have Dispose or Close methods, we should call these methods when we’ve finished using these objects. It is advisable to place these calls in a finally clause, which guarantees that the objects are properly handled even if an exception is thrown.