10 December 2013

Interview Questions in ASP.NET,C#.NET,SQL Server,.NET Framework Part 1

Here i posting interview questions whatever i have searching websites and collecting from friends.
i think these questions are very helpful for the people who are trying to get the job on .NET
The most common question for experience persons is :

1.Why would you like to change the company?
Ans:
1) I am looking for a more challenging career in a firm with a larger employee base such as yours.
2) Keeping in mind my career goals, the time has come for me to move onto the next rung of
the ladder and make a mark for myself. This can be achieved in a company like this.
3) It is just a career move to enhance my knowledge in my own area of interest.
After completion of this question only interview will go for further questions.

2.Difference between stored procedure and function?
Ans :
1) Procedure can return zero or n values whereas function can return one value which is mandatory.
2) Procedures can have input, output parameters for it whereas functions can have only input parameters.
3) Procedure allows select as well as DML statement in it whereas function allows only select statement in it.
4) Functions can be called from procedure whereas procedures cannot be called from function.
5) Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.
6) We can go for transaction management in procedure whereas we can't go in function.
7) Procedures cannot be utilized in a select statement whereas function can be embedded in a select statement.

3. Difference between Abstract and Interface?
Ans :
Abstract Class:

-Abstract class provides a set of rules to implement next class
-Rules will be provided through abstract methods
-Abstract method does not contain any definition
-While inheriting abstract class all abstract methods must be override
-If a class contains at least one abstract method then it must be declared as an “Abstract Class”
-Abstract classes cannot be instantiated (i.e. we cannot create objects), but a reference can be created
-Reference depends on child class object’s memory
-Abstract classes are also called as “Partial abstract classes”
-Partial abstract class may contain functions with body and functions without body
-If a class contains all functions without body then it is called as “Fully Abstract Class” (Interface)

Interface:

-If a class contains all abstract methods then that class is known as “Interface”
-Interfaces support like multiple inheritance
-In interface all methods r public abstract by default
-Interfaces r implementable
-Interfaces can be instantiated, but a reference cannot be created

Or

What are the differences between Abstract and interface?

Ans:
1) Abstract cannot be instantiated but we can inherit. Interface it cannot be inherit it can be instantiate
2) Interface contain only declarations no definitions. Abstract contain declarations and definitions.
3) The class which contains only abstract methods is interface class. A class which contains abstract method is called abstract class
4) Public is default access specifier for interface we don’t have a chance to declare other specifiers. In abstract we have chance to declare with any access specifier

4.Index types in SQL Server?
Ans :
ClusteredIndex

Only 1 allowed per table physically rearranges the data in the table to confirm to the index constraints for use on columns that are frequently searched for ranges of data for use on columns with low selectivity.

Non-ClusteredIndex

Up to 249 allowed per table creates a separate list of key values with pointers to the location of the data in the data pages For use on columns that are searched for single values.

A clustered index is a special type of index that reorders the way records in the table are physically stored. Therefore table can have only one clustered index. The leaf nodes of a clustered index contain the data pages. A non-clustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows on disk. The leaf node of a non-clustered index does not consist of the data pages. Instead, the leaf nodes contain index rows.

Included Column Index (New in SQL Server 2005)

In SQL Server 2005, the functionality of non-clustered indexes is extended by adding non-key columns to the leaf level of the non-clustered index. Non-key columns can help to create cover indexes. By including non-key columns, you can create non-clustered indexes that cover more queries. The Database Engine does not consider non-key columns when calculating the number of index key columns or index key size. Non-key columns can be included in non-clustered index to avoid exceeding the current index size limitations of a maximum of 16 key columns and a maximum index key size of 900 bytes. Another advantage is that using non-key column in index we can have index data types not allowed as index key columns generally.

In following example column Filename is varchar(400), which will increase the size of the index key bigger than it is allowed. If we still want to include in our cover index to gain performance we can do it by using the Keyword INCLUDE.

USE AdventureWorks
GO
CREATE INDEX IX_Document_Title
ON Production.Document (Title, Revision)
INCLUDE (FileName)

Non-key columns can be included only in non-clustered indexes. Columns can’t be defined in both the key column and they INCLUDE list. Column names can’t be repeated in the INCLUDE list. Non-key columns can be dropped from a table only after the non-key index is dropped first. For Included Column Index to exist there must be at least one key column defined with a maximum of 16 key columns and 1023 included columns.
Avoid adding unnecessary columns. Adding too many index columns, key or non-key as they will affect negatively on performance. Fewer index rows will fit on a page. This could create I/O increases and reduced cache efficiency. More disk space will be required to store the index. Index maintenance may increase the time that it takes to perform modifications, inserts, updates, or deletes, to the underlying table or indexed view.

Another example to test:
Create following Index on Database AdventureWorks in SQL SERVER 2005

USE AdventureWorks
GO
CREATE NONCLUSTERED INDEX IX_Address_PostalCode
ON Person.Address (PostalCode)
INCLUDE (AddressLine1, AddressLine2, City, StateProvinceID)
GO

Test the performance of following query before and after creating Index. The performance improvement is significant.
SELECT AddressLine1, AddressLine2, City, StateProvinceID, PostalCode
FROM Person.Address
WHERE PostalCode BETWEEN '98000'
AND '99999';
GO

5.What are differences between Array list and Hash table?

Ans: 1) Hash table store data as name, value pair. While in array only value is store.
2) To access value from hash table, you need to pass name. While in array, to access value, you need to pass index number.
3) you can store different type of data in hash table, say int, string etc. while in array you can store only similar type of data.

6.What are differences between system.stringbuilder and system.string?
Ans :
The main difference is system.string is immutable and system.stringbuilder is a mutable. Append keyword is used in string builder but not in system.string.
Immutable means once we created we cannot modified. Suppose if we want give new value to old value simply it will discarded the old value and it will create new instance in memory to hold the new value.

7.What are the differences between Application object and session object?

Ans: The session object is used to maintain the session of each user. If one user enter in to the application then they get session id if he leaves from the application then the session id is deleted. If they again enter in to the application they get different session id.
But for application object the id is maintained for whole application.

8.What are the different types of indexes?

Ans: Two types of indexes are there one is clustered index and non-clustered index

9.How many types of memories are there in .net?

Ans: Two types of memories are there in .net stack memory and heap memory

10.Is it possible to set the session out time manually?

Ans: Yes we can set the session out time manually in web.config.


11.What are differences between function and stored procedure?
Ans:
1) Function returns only one value but procedure returns one or more than one value.
2) Function can be utilized in select statements but that is not possible in procedure.
3) Procedure can have an input and output parameters but function has only input parameters only.
4) Exceptions can be handled by try catch block in procedures but that is not possible in function.

12.What are the differences between Abstract and interface?
Ans:
1) Abstract cannot be instantiated but we can inherit. Interface it cannot be inherit it can be instantiate
2) Interface contain only declarations no definitions. Abstract contain declarations and definitions.
3) The class which contains only abstract methods is interface class. A class which contains abstract method is called abstract class
4) Public is default access specifier for interface we don’t have a chance to declare other specifiers. In abstract we have chance to declare with any access specifier

13.Can you Explain Page lifecycle in .net?
Ans :
Page Life Cycle Stages :
There are application stages that occur before and after a request but are not specific to a page.
 The stages are:-
1.Page Request: - Page Request occurs before page life cycle begins. When user requested the page, ASP.Net determines that the page is needed to be parsed and compiled or whether a cached version of the page can be sent in response without running the page.

2.Start: - In the start stage, page properties such as Request and Response is set. At this stage, page also determines that request is post back or a new request and sets the IsPostBack property.

3.Page Initialization: - 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.

4. Load: - During Load, if the current request is postback, control properties are loaded with information recovered from view state.

5.Validation: - During validation, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page.

6.Postback Event Handling: - If the request is a postback, any event handlers are called. The event handling for server controls occurs during this stage.

7.Rendering Unload: - 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.

Page Life Cycle Events :
Within each stage of page life cycle, page raises several events that we can handle to run our own code. Pages also support automatic event wire-up, meaning that ASP.NET looks for methods with particular names and automatically runs those methods when certain events are raised.
These events are:-
PreInit: - Raised after the start stage complete and before initialization stage begins.
Init:- Raised after all controls have been initialized and any skin settings have been applied. The Init event of individual controls occurs before Init event of page.
InitComplete: - Raised at the end of the initialization stage.
PreLoad: - Raised after the page loads view state of itself and all controls.
Load: - OnLoad event is occurred during the Load stage.
Control Events: - Use these events to handle specific control events, such as Button’s Onclick event.
LoadComplete: - Raised at the end of the event-handling stage.
PreRender: - Raised after the Page object has created all controls that are required in order to render the page, including child controls of composite controls.
PreenderComplete: - Raised after each data bound control whose DataSourceID property is set calls its DataBind method.
SaveStateComplete: - Raised after view state and control state have been saved for the page and for all controls.
Render: - This is not an event; instead, at this stage of processing, the Page object calls this method on each control. All ASP.NET Web server controls have a Render method that writes out the control's markup to send to the browser.
Unload: - Raised for each control and then for the page.

14.Can you Explain .NET architecture in .net?

15.What is the difference between primary key and unique key with not null?
Ans:
There is 3 differences between primary key and unique key with not null.

1. primary key wont allow null value but unique key will do
2. in a table there must but only one Primary Key column but in unique key there may be any number of column
3. Unique Key is Clustered index but primary key is non-clustered.

Primary Key are used for referential integrity (pair with FK)
Unique Key are used for data consistency and validation

And  also
 Primary Key:
i) Can be only one in a table
ii) It never allows null values
iii) Primary Key is unique key identifier and can not be null and must be unique.

Unique Key:
i) Can be more than one unique key in one table.
ii) Unique key can have null values
iii) It can’t be candidate key
iv) Unique key can be null and may not be unique.

16.What is boxing and unboxing concepts in .net? 
Ans:
Boxing is a process of converting value type into reference type
Unboxing is a process of converting reference type to value type.

17.What are the differences between value type and reference type?
Ans:
Value type contain variable and reference type are not containing value directly in its memory.
Memory is allocated in managed heap in reference type and in value type memory allocated in stack. Reference type ex-class value type-struct, enumeration

18.Is it possible to host the website from desktop?
Ans: Yes

19.Why we go for page rendering in Asp.Net Page life cycle?
Ans:
Browser understands an only html control that’s why in page rendering we will convert the aspx controls into html controls.

20.Write a sample query for self join?
Ans:
Select e1.ename, e2.empid from emp e1, emp e2 where e1.empid=e2.mgrid;

No comments:

Post a Comment