Friday 15 November 2013

Magic Table


Magic Table in SQL

While using triggers these Inserted & Deleted tables
(called as magic tables) will be created automatically.

When we insert any record then that record will be added
into this Inserted table initially, similarly while
updating a record a new entry will be inserted into
Inserted table & old value will be inserted into Deleted
table.

In the case of deletion of a record then it will insert
that record in the Deleted table

Thursday 25 July 2013

Jagged Array


Jagged Array
A variation of the multidimensional array is the jagged array: an array of arrays. A jagged array is a single-dimensional array, and each element is itself an array. The element arrays are not required to all be of the same size.
You declare a jagged array like this:
int[][] jaggedArray = new int[3][];
Doing so creates an array of three arrays. These arrays can be initialized like this:
jaggedArray[0] = new int[5];
jaggedArray[1] = new int[4];
jaggedArray[2] = new int[2];

Difference between Arraylist and Generic List


Difference between Arraylist and Generic List

Arraylist
 
Arraylist accept values as object

So We can give any type of data in to that.

Here in this eg: an arraylist object accepting 

values like String,int,decimal, char and a custom object

ArrayList arr = new ArrayList();

arr.Add("Sabu");

arr.Add(234);

arr.Add(45.236);

arr.Add(emp);

arr.Add('s');

This process is known as boxing
 
Geniric
 
Main advantage of Generic List is we can specify the type of data 
List<int> intLst = new List<int>();

intLst.Add(12);
 
Here List accepting values as int only
 
List<Employee> empLst = new List<Employee>();


empLst.Add(new Employee("1", "Sabu"));
Here List accepting Employee Objects only
 
 If constructor is private then we can not create the object and inherit of that
class.
   
 -> Sealed can not be used for virtual, Abstract and static classes.
Non - Generic collection class - which collection can hold the different type of data.
Generic collection class - which collection can hold the same type of data.

Difference between COOKIES AND CACHE?


Difference between COOKIES AND CACHE?

cookies are small bits of files that store your session, and other small data, its pretty much like a database in a sense...

while a cache is temporary storage for files used by a program(typically a browser) to display items.... and to get a quick access to pre-parsed files.....

your browser has to store the webpage, and all pictures, video flash and those things on the cache so that it could display it

while cookies, store only text based data about your browsing stuff.. like passwords, number of pages visited, session number, and so on

Tuesday 23 July 2013

Garbage Collection

Garbage Collection
Memory management is the main concern for any application whether application is window based or web based. In .Net, CLR has garbage collector that executes as a part of our program and responsible for reclaiming the memory of no longer used objects. Garbage collector free the memory for objects that are no longer referenced and keeps the memory for future allocations.
Advantage of Garbage Collector
  1. Allow us to develop an application without having worry to free memory.
  2. Allocates memory for objects efficiently on the managed heap.
  3. -Reclaims the memory for no longer used objects and keeps the free memory for future allocations.
  4. Provides memory safety by making sure that an object cannot use the content of another object.
Memory Allocation in Managed Heap
The managed heap is a series of allocated memory segments (approx 16Mb in size each) to store and manage objects. The memory for newly created object is allocated at the next available location on the managed heap. If there is available free memory, the garbage collector doesn't search the dead objects for memory reclaim and memory allocations has been done very fast. If the memory is insufficient to create the object, the garbage collector search the dead objects for memory reclaim for the newly object.

An object is created using the new operator. This operator first makes sure that the bytes required by the new object fit in the reserved region (committing storage if necessary). If the object fits, NextObjPtr points to the object in the heap and object's constructor is called and the new operator returns the address of the object.
Impotants points
  1. All objects in the heap are allocated from one contiguous range of memory address and heap is divided into generations so that it is easy to eliminate the garbage objects by looking at only a small fraction of the heap.
  2. Gen 0 and Gen 1 occupy a single segment known as the ephemeral segment. Gen 2 is a set of further segments and the large object heap is yet another group of segments.
  3. Almost, all objects with-in a generation are of the same age.
  4. The newest objects are created at higher memory address while oldest memory objects are at lowest memory address with in the heap.
  5. The allocation pointer for the new objects marks the boundary between the allocated and free memory.
  6. Periodically the heap is compacted by removing the dead objects and sliding up the live objects towards the lower memory address end of the heap as shown in above fig.
  7. The order of objects (after memory reclaims) in memory remains the same as they were created.
  8. There are never any gaps among the objects in the heap.
  9. Only some of the free memory is committed when required and more memory is acquired from the OS in the reserved address range.
Generations in Managed Heap
The managed heap is organized into three generations so that it can handle short lived and long lived objects efficiently. Garbage collector first reclaim the short lived objects that occupy a small part of the heap.
  1. Generation 0
    This is the youngest generation and contains the newly created objects. Generation 0 has short-lived objects and collected frequently. The objects that survive the Generation 0 are promoted to Generation 1.
    Example : A temporary object.
  2. Generation 1
    This generation contains the longer lived objects that are promoted from generation 0. The objects that survive the Generation 1 are promoted to Generationen 2. Basically this generation serves as a buffer between short-lived objects and longest-lived objects.
  3. Generation 2
    This generation contains the longest lived objects that are promoted from generation 1 and collected infrequently.
    Example : An object at application level that contains static data which is available for the duration of the process.
Garbage Collector Working Phase
  1. Marking Phase
    In this phase garbage collector finds and creates a list of all live objects.
  2. Relocating Phase
    In this phase garbage collector updates the references to the objects that will be compacted.
  3. Compacting Phase
    In this phase garbage collector reclaims the memory occupied by the dead objects and compacts the surviving objects. The compacting phase moves the surviving objects toward the older end of the memory segment.

Monday 22 July 2013

Page Life Cycle in Asp.net

Page Life Cycle in Asp.net

Methods Description
Page_Init Page Initialization
LoadViewState View State Loading
LoadPostData Postback Data Processing
Page_Load Page Loading
RaisePostDataChangedEvent PostBack Change Notification
RaisePostBackEvent PostBack Event Handling
Page_PreRender Page Pre Rendering Phase
SaveViewState View State Saving
Page_Render Page Rendering
Page_Unload Page Unloading

Page_Init

The Page_Init event is the first event to be triggered in the page life cycle. In this the control tree has been created, the controls declared in the .aspx file are initialized. The viewstate is not available at this stage. We can create or re-create the controls that need to be created or re-created dynamically.

LoadViewState

The Viewstate contains stored information that is set by the page and controls of the page. But the load view state event only occurs when the page has been posted back. Due to viewstate control's and page itself store information that is persistent among web requests. It contains the state of the controls the last time the page was processed on the server.

LoadPostData

After viewstate is loaded the control are updated with posted values or values that are entered or changed by user.

Page_Load

After Loadpostdata the page_load event is fired. In this event code written inside page load is executed once at the beginning of the page.

RaisePostDataChangedEvent

In this event when user clicks submit button or any other button then it changes state of the page and the event related to that button is raised.

RaisePostBackEvent

This methods knows which event has occurred and which related method you need to call like btnsubmit is clicked then it will call method related to it like “btnsubmit_click” to perform its functionality.

Page_PreRender

At this stage page is prepared for Rendering and if user wants to chage anything he can change it here only as in this event viewstate is not saved and output is not rendered.

SaveViewState

In this event values of viewstate is saved to control own viewstate collection. The resultant viewstate is serialized, hashed, base24 encoded and associated with the _viewstate hidden field.

Page_Render

This method takes the HtmlWriter object and uses it to accumulate all HTML text to be generated for the control. For each control the page calls the render method and caches the HTML output.

Page_unload

During this method, data can be released to free up resources on the server for other processes. Once this method is completed, the HTML is sent to the browser for client side processing.

Wednesday 17 July 2013

State managemen


 What are the different levels of State management in ASP.NET?
State management is the process by which you maintain state and page information over multiple requests for the same or different pages.

There are 2 types State Management:
 
1. Client – Side State Management   
2. Server – Side State Management

1. Client – Side State Management
This stores information on the client's computer by embedding the information into a Web page, a uniform resource locator (url), or a cookie. The techniques available to store the state information at the client end are listed down below:

a. View State – Asp.Net uses View State to track the values in the Controls. You can add custom values to the view state. It is used by the Asp.net page framework to automatically save the values of the page and of each control just prior to rendering to the page. When the page is posted, one of the first tasks performed by page processing is to restore view state.

b. Control State – If you create a custom control that requires view state to work properly, you should use control state to ensure other developers don’t break your control by disabling view state.

c. Hidden fields – Like view state, hidden fields store data in an HTML form without displaying it in the user's browser. The data is available only when the form is processed.

d. Cookies – Cookies store a value in the user's browser that the browser sends with every page request to the same server. Cookies are the best way to store state data that must be available for multiple Web pages on a web site.

e. Query Strings - Query strings store values in the URL that are visible to the user. Use query strings when you want a user to be able to e-mail or instant message state data with a URL.

2. Server – Side State Management
a. Application State - Application State information is available to all pages, regardless of which user requests a page.

b. Session State – Session State information is available to all pages opened by a user during a single visit.

Both application state and session state information is lost when the application restarts. To persist user data between application restarts, you can store it using profile properties.