Friday, March 26, 2010

Interview Panel : Mostly Asked Interview Questions in .Net

What is 
Polymorphism?
Polymorphism - Poly means "many" So it is one name and many forms.
In C# we have two types of polymorphism compile time and run time. 
Compile time polymorphism is achieved through Function Overloading (Same function but different parameters or signatures) and 
Run time polymorphism is achieved through function overriding also called shadowing in VB.net where a
child class method overrides the base class function.
How is the memory managed in C#?
By garbage collector or using dispose method of objet u can do memory management in c# .garbage collector is automatically remove object which is not use. This is new concept in c#.

Can two catch blocks be executed?

using System;

class a
{
            public static void Main()
            {
                        int a=8;
                        int b=0;
                        int [] arr=new int[]{1,2};
                        try
                        {
                                     Console.WriteLine(a/b);
                        }
                        catch(Exception e)
                        {
                                     Console.WriteLine(e.ToString());
                                     Console.WriteLine("Hello");
                        }
                        finally
                        {           try
                                     {                       
                                     Console.WriteLine(arr[2]);  
                                     }
                                     catch(IndexOutOfRangeException d)
                                     {
                                                 Console.WriteLine(d.ToString 
()+  "hello");
                                                 Console.WriteLine("Hello");
                                     }
                        }
            }
}
output will be 
----------------
System.DivideByZeroException: Attempted to divide by zero.
   at a.Main()
Hello
System.IndexOutOfRangeException: Index was outside the 
bounds of the array.
   at a.Main()
H
ello
What is Sealed Class?
 
Sealed Class:
When applied to a class, the sealed modifier prevents other classes from inheriting from it.
In the following example, 
class B inherits from class A, but no class can inherit 
from class B.
class A {}    
sealed class B : A {}
You can also use the sealed modifier on a method or property that overrides a virtual method or property in a base class. This enables you to allow classes to derive 
from your class and prevent them from overriding specific virtual methods or properties.
What is early binding and late binding?

Early binding - Assigning values to variables during design time or exposing object model at design time.

Late Binding - Late binding has the same effect as early binding.  The difference is that you bind the object library in code at run-time.
What is master pages how to use it. Please give one example 
In code vice?
Master page is inbuilt functionality in .Net2.0 or above. While in .Net1.1 you must be create custom master page using web user controls.
If you want to display the same section on more then one page in your application then you can use master page. A master page have content place holder where you can put your code for different pages.
To use master page in your web application pages, you must be include master page file name in the page directive. Like:
<@ page MasterPage="MyMasterpage.master" .......>
How to delete duplicate records from table in sql server 2005?
SELECT col1,col2 FROM  GROUP BY col1,col2 HAVING COUNT(*) > 1 

Any exceptions are there which are not caught by any catch blocks? What are they?

Yes,"StackOverFlowException" 
doesn't get catch by any catch block and Fatal Errors, Virtual memory.

What are the two kinds of properties?

Read only (with no 'set')

Write only (with no 'get')

What is read only and constant?

Constant : it will take the values at compile time, In constant u cant change values.

Read-Only : it will take 
values at run time especially u can use this for date functions.

Wednesday, March 24, 2010

Interview Panel : Mostly Asked Interview Questions in Sql Server


Main difference between Stored procedure vs User Functions :

  • Procedure may return none or more values.Function must always return one value either a scalar value or a table.
  • Procedure have input,output parameters.Functions have only input parameters.
  • Stored procedures are called independently by EXEC command whereas Functions are called from within SQL statement.
  • Functions can be called from procedure.Procedures cannot be called from function.
  • Exception can be handled in Procedure by try-catch block but try-catch block cannot be used in a function.(error-handling)
  • Transaction management possible in procedure but not in function.
Main difference between Cluster Index vs Non - Cluster Index :

Cluster Index

1 A cluster index is a form of tables which consist of column and rows.
2 Cluster index exists on the physical level
3 It sorts the data at physical level
4 It works for the complete table
5 There is a whole table in form of sorted data
6 A table can contain only one cluster index

Non Cluster Index

1 A non cluster index is in the form of a report about the tables.
2 They are not created on the physical level but at the logical level
3 It does not sort the data at physical level
4 A table has 255 non clustered indexes
5 A table has many non clustered indexes.
6 It work on the order of data

Main difference between Truncate vs Delete :

Truncate and Delete both are used to delete data from the table. These both command will only delete data of the specified table, they cannot remove the whole table data structure. Both statements delete the data from the table not the structure of the table.

  • TRUNCATE is a DDL (data definition language) command whereas DELETE is a DML (data manipulation language) command.
  • You can use WHERE clause (conditions) with DELETE but you can't use WHERE clause with TRUNCATE.
  • You can’t rollback data in TRUNCATE but in DELETE you can rollback data. TRUNCATE removes (delete) the record permanently.
  • A trigger doesn’t get fired in case of TRUNCATE whereas Triggers get fired in DELETE command.
  • If tables which are referenced by one or more FOREIGN KEY constraints then TRUNCATE will not work.
  • TRUNCATE resets the Identity counter if there is any identity column present in the table where delete not resets the identity counter.
  • Delete and Truncate both are logged operation. But DELETE is a logged operation on a per row basis and TRUNCATE logs the deallocation of the data pages in which the data exists.
  • TRUNCATE is faster than DELETE.
How to Select Duplicate Records in a table using single Query?

SELECT col1, col2, count(*)
FROM t1
GROUP BY col1, col2
HAVING count(*) > 1

How to Delete duplicate records from a table :
declare @UserId int 
declare @Count int 
declare @Name varchar(50)
declare @temp table(id int,name varchar(50))

set @Count = 0 

declare cur cursor
       for select userid,count(userid) as UserIdRepeat ,name from test group by userid,name having count(userid) > 1 
open cur
       fetch next from cur into @UserId,@Count,@Name  

while (@@fetch_status = 0) 
begin 
       
       if(@Count > 1)
       begin   
                 insert into @temp (id,name) values (@UserId,@Name)
                 print @UserId
                 delete from test where userid = @UserId
       end
       fetch next from cur into @UserId,@Count,@Name
end
       select * from @temp
close cur
deallocate cur
       insert into test select id,name from @temp
       select * from test order by userid

Types of ADO.NET Command Object Methods :

1.ExecuteReader - Select statements
2.ExecuteNonQuery - DML statements(Insert Update and Delete)
3.ExecuteScalar - Returns a single value from Aggragate functions like SUM AVG COUNT etc

Types of User Defined functions in SQl server :
1.) Scalar function
2.) Inline table valued function
3.) Multi statement table valued function
Scalar function :
A scalar user defined function returns one of the scalar Data type .text, ntext, etc
Inline table Value :
An inline table value function return a table data type
Multi -statement table value function :
 A multi -statement table value function return a table and Is also an exceptional alternative to a view as the function
 Can support multiple t-sql statements to build the final result.

What is Sub Query?

Sub-query means a Query within a Query. 
This is the Example: 
Select Employee_Id, Employee_name From Employees Where Employee_Id IN (Select Mgr_Id from Manager)

Difference between Where and Having Clause :

Here both are filter conditions

Where clause is used when from is used in the select condition...

Having clause is used when group by function in the select condition....

e.g:

WHERE applies to rows HAVING applies to summarize rows (summarized with GROUP BY) if you wanted to find the average salary in each department GREATER than 333 you would code:

SELECT

DEPARTMENT

AVG (SALARY) FROM EMP

WHERE DEPARTMENT > 333

GROUP BY DEPARTMENT

IF you then wanted to filter the intermediate result to contain departments where the average salary was greater that 50 000 you would code:

SELECT

DEPARTMENT

AVG (SALARY) FROM EMP

WHERE DEPARTMENT > 333

GROUP BY DEPARTMENT

HAVING AVG (SALARY) > 50000.

Where executes first

GROUP BY next and

finally HAVING

What is Magic Table?

Magic tables nothing but inserted and deleted which are temporary objects created by server internally to hold recently inserted values in the case of insert, to hold recently deleted values in the case of delete, to hold before updating values or after updating values in the case of update.

Difference between Primary Key and Unique Key?

Primary key:

1) Primary key is nothing but it is uniqly identified each roe in Table.
2) Primary key does not Allows Duplicate values and Null values.
3) Primary key is default Clustered indexes.
4) one table can have only one Primary key.

Unique Key:

1) Unique Key is nothing but it is uniqly identified each roe in Table.

2) Unique Key does not Allows Duplicate values but allows only one Null value.

3) Unique Key is default Non- Clustered indexes.

Tuesday, March 23, 2010

Interview Panel : Mostly Asked Interview Questions in .Net

What is .Net Frame Work?


The .NET Framework has two main components: the common language runtime and the .NET Framework class library.


You can think of the runtime as an agent that manages code at execution time, providing core services such as memory management, thread management, and remoting, while also enforcing strict type safety and other forms of code accuracy that ensure security and robustness.

The class library, is a comprehensive, object-oriented collection of reusable types that you can use to develop applications ranging from traditional command-line or graphical user interface (GUI) applications to applications based on the latest innovations provided by ASP.NET, such as Web Forms and XML Web services.

Main Difference between Interface and Abstract Class :

Feature

Interface

Abstract class

Multiple inheritance

A class may inherit several interfaces.

A class may inherit only one abstract class.

Default implementation

An interface cannot provide any code, just the signature.

An abstract class can provide complete, default code and/or just the details that have to be overridden.

Access Modfiers

An interface cannot have access modifiers for the subs, functions, properties etc everything is assumed as public

An abstract class can contain access modifiers for the subs, functions, properties

Core VS Peripheral

Interfaces are used to define the peripheral abilities of a class. In other words both Human and Vehicle can inherit from a IMovable interface.

An abstract class defines the core identity of a class and there it is used for objects of the same type.

Homogeneity

If various implementations only share method signatures then it is better to use Interfaces.

If various implementations are of the same kind and use common behaviour or status then abstract class is better to use.

Speed

Requires more time to find the actual method in the corresponding classes.

Fast

Adding functionality (Versioning)

If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method.

If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly.

Fields and Constants

No fields can be defined in interfaces

An abstract class can have fields and constrants defined


Main Difference between Dispose and Finalize method :


1> CLR uses the Dispose and Finalize methods for performing garbage collection of runtime objects of .Net applications.

2> Clr has a Garbage Collector(GC) which periodically checks for unused and unreferenced objects in Heap.It call Finalize() method to free the memory used by such objects.

3> Dispose is another method which is invoked by Garbage Collector to release the memory occupied by an object.Dispose method needs to be explicitly called in code for removing an object from Heap.

4> Dispose method can be invoked only by the classes that IDisposable interface.

What is .NET Partial Classes?

Using Partial Classes we can have same class span across multiple files.

However it is considered as a single class by CLR. Infact if we can take a look into IL code we will find a single class only. So two developers can work on their own copy of partial class.

Some More things that we can do with partial class say Employee.

We can keep all properties related to Employee in one Employee Partial Class.

We can keep all Methods related to Employee in one Employee Partial Class.

We can keep all constants and fields related to Employee in one Employee Partial Class and so on.

How does Cookies differ from Session Variables?

Cookies:

1) Cookies can hold small amount of data in text format.

2) Cookies created on browser.

3) Cookies can be disabled by user computer.

Session:

1) Session can hold large amount of data.

2) Session created on the Server.

3) Session can not be disabled ...

What is portable executable (PE)?

The file format defining the structure that all executable files (EXE) and Dynamic Link Libraries (DLL) must use to allow them to be loaded and executed by Windows. PE is derived from the Microsoft Common Object File Format (COFF). The EXE and DLL files created using the .NET Framework obey the PE/COFF formats and also add additional header and data sections to the files that are only used by the CLR.

What is Application Domain?


The primary purpose of the AppDomain is to isolate an application from other applications. Win32 processes provide isolation by having distinct memory address spaces. This is effective, but it is expensive and doesn't scale well. The .NET runtime enforces AppDomain isolation by keeping control over the use of memory - all memory in the AppDomain is managed by the .NET runtime, so the runtime can ensure that AppDomains do not access each other's memory.

Objects in different application domains communicate either by transporting copies of objects across application domain boundaries, or by using a proxy to exchange messages.


MarshalByRefObject is the base class for objects that communicate across application domain boundaries by exchanging messages using a proxy. Objects that do not inherit from MarshalByRefObject are implicitly marshal by value. When a remote application references a marshal by value object, a copy of the object is passed across application domain boundaries.


How does an AppDomain get created?

AppDomains are usually created by hosts. Examples of hosts are the Windows Shell, ASP.NET and IE. When you run a .NET application from the command-line, the host is the Shell. The Shell creates a new AppDomain for every application.

AppDomains can also be explicitly created by .NET applications. Here is a C# sample which creates an AppDomain, creates an instance of an object inside it, and then executes one of the object's methods. Note that you must name the executable 'appdomaintest.exe' for this code to work as-is.
using System;
using System.Runtime.Remoting;

public class CAppDomainInfo : MarshalByRefObject
{
public string GetAppDomainInfo()
{
return "AppDomain = " + AppDomain.CurrentDomain.FriendlyName;
}
}
public class App
{
public static int Main()
{
AppDomain ad = AppDomain.CreateDomain( "Andy's new domain", null, null );
ObjectHandle oh = ad.CreateInstance( "appdomaintest", "CAppDomainInfo" );
CAppDomainInfo adInfo = (CAppDomainInfo)(oh.Unwrap());
string info = adInfo.GetAppDomainInfo();
Console.WriteLine( "AppDomain info: " + info );
return 0;
}
}


What is Code Access Security (CAS)?

CAS is the part of the .NET security model that determines whether or not a piece of code is allowed to run, and what resources it can use when it is running.

What is Event - Delegate? Clear Syntax for writing a Event Delegate


The event keyword lets you specify a delegate that will be called upon the occurrence of some "event" in your code. The delegate can have one or more associated methods that will be called when your code indicates that the event has occurred. An event in one program can be made available to other programs that target the .NET Framework Common Language Runtime.


// keyword_delegate.cs
// delegate declaration
delegate void MyDelegate(int i);
class Program
{
public static void Main()
{
TakesADelegate(new MyDelegate(DelegateFunction));
}
public static void TakesADelegate(MyDelegate SomeFunction)
{
SomeFunction(21);
}
public static void DelegateFunction(int i)
{
System.Console.WriteLine("Called by delegate with number: {0}.", i);
}
}

What is Strong Name?


A name that consists of an assembly's identity—its simple text name, version number, and culture information (if provided)—strengthened by a public key and a digital signature generated over the assembly.

What is CLR, CTS and CLS?


The .NET Framework provides a runtime environment called the Common Language Runtime or CLR (similar to the Java Virtual Machine or JVM in Java), which handles the execution of code and provides useful services for the implementation of the program. CLR takes care of code management at program execution and provides various beneficial services such as memory management, thread management, security management, code verification, compilation, and other system services. The managed code that targets CLR benefits from useful features such as cross-language integration, cross-language exception handling, versioning, enhanced security, deployment support, and debugging.


Common Type System (CTS) describes how types are declared, used and managed in the runtime and facilitates cross-language integration, type safety, and high performance code execution.


The CLS is simply a specification that defines the rules to support language integration in such a way that programs written in any language, yet can interoperate with one another, taking full advantage of inheritance, polymorphism, exceptions, and other features.


Difference Between in Web Farm and Web Garden :

Web Farm is running an application in more than one computer.

Web Garden is running an application in single computer with multiple processor.

What is Typed Dataset in C#?

A typed dataset is similar to dataset with only difference is that the schema is already present in typed dataset. So if any mismatch in the column will generate compile time errors rather than runtime errors as in the case of normal dataset. Also accessing the column value is much easier then the normal dataset as the column definition will be available in the schema.

What is Load balancing?

In computer networking, load balancing is a technique (usually performed by load balancers) to spread work between many computers, processes, hard disks or other resources in order to get optimal resource utilization and decrease computing time.

Difference between Clone and Copy?

Dataset.Clone :- It only copies structure, does not copy data.

Dataset. Copy  :-  Copies both Structure and data.

Main Difference between Array list and Hash Table?

Array list:

Array list is a collection of objects (may be of different types).


Array list is very much similar to array but it can take values of different data types.


If you want to find something in a array list you have to go through each value in array list, theres no faster way out.


Array List’s size can be changed dynamically.

Hash table:


Hash table is also collection which takes a key corresponding to each value.
If you want to find something in a hash table you don’t have to go through each value in hash table, instead search for key values and is faster.

Secondly Array list is slower as compare to Hash table.

Hash table is basically use for maintaining huge data but array list don’t have.

The difference is also on the interfaces they implement.

The Array List Class implements the ICollection (allows us to use the Count property to count the number of items in the List), IList (allows for the use of Add , Remove, Clear, Insert methods to maipulate the items in the List) and IEnumerable and IEnumerator(allows for using the [for each - in] to traverse through the items)

The Hash table implements the IDictionary interface that instead of mapping the items with indexes represents the items as key/value pairs.

The ICollection extends the IEnumerable;

The IDictionary and the IList extend the ICollection


Main Difference between Application and Session and Cookies?

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. It doesn't differ

State Management in APS.NET is managed by two ways:
 
Client-Side or Server-Side
 
Client-Side:Cookies,HiddenFields,ViewState and Query Strings.
 
Serve-Side:Application,Session and Database.
 
COOKIE:
 
A cookie is a small amount of data stored either in a text file on the client's file system or in-memory in the client browser session. Cookies are mainly used for tracking data settings. Let’s take an example: say we want to customize a 
welcome web page, when the user request the default web page, the application first to detect if the user has logined before, we can retrieve the user informatin from 
cookies:
 
[c#]
 
if (Request.Cookies[“username”]!=null)
            lbMessage.text=”Dear “+Request.Cookies[“username”].Value+”, 
Welcome shopping here!”;
 
else
            lbMessage.text=”Welcome shopping here!”;
 
If you want to store client’s information, you can use the following code:
 
[c#]
 
Response.Cookies[“username’].Value=username;
 
So next time when the user request the web page, you can easily recongnize the user again.
 
SESSION:
 
Session object can be used for storing session-specific information that needs to be maintained between server round trips and between requests for pages. Session object is per-client basis, which means different clients generate different session object.The ideal data to store in session-state variables is short-lived, sensitive data that is specific to an individual session.
 
Each active ASP.NET session is identified and tracked using a 120-bit SessionID string containing URL-legal ASCII characters. 
 
Every web application must have a configuration file named 
web.config, it is a XML-Based file, there is a section 
name ‘sessionState’, the following is an example:
 
sqlConnectionString="data source=127.0.0.1;user id=sa;password=" cookieless="false" timeout="20" />
‘cookieless’ option can be ‘true’ or ‘false’. When it is ‘false’(default value), ASP.NET will use HTTP cookie to identify users. When it is ‘true’, ASP.NET will randomly 
generate a unique number and put it just right ahead of the requested file, this number is used to identify users
 
[c#]
 
//to store information
Session[“myname”]=”Mike”;
 
//to retrieve information
myname=Session[“myname”];
 
this is briefly about cookies and sessions in ASP.NET
 
Cookies :
 
1.          Cookies can store only "string" datatype 
2.          They are stored at Client side 
3.          Cookie is non-secure since stored in text format at client side 
4.          Cookies may or may not be individual for every client 
5.                      Due to cookies network traffic will increase.Size of cookie is limited to 40 and number of cookies to be used is restricted to 20. 
6.          Only in few situations we can use cookies because of no security 
7.          We can disable cookies 
8.          Since the value is string there is no security 
9.          We have persistent and non-persistent cookies
 
Session :
 
1.         Session can store any type of data because the value is of datatype of     "object" 
2.         These are stored at Server side 
3.         Session are secure because it is stored in binary format/encrypted form and it gets decrypted at server 
4.         Session is independent for every client i.e individual for every client 
5.         There is no limitation on size or number of sessions to be used in an application 
6.          For all conditions/situations we can use sessions 
7.       we cannot disable the sessions. Sessions can be used without cookies   also(by  disabling cookies)
8.          The disadvantage of session is that it is a burden/overhead on server 
9. Sessions are called as Non-Persistent cookies because its life time can be set manually