Interview Questions

15
What is the difference between a thread and a process? A Process is a collection of Virtual Memory space, code, data and System resources. A Thread is a code that is to be serially executed with in the process. A processor executes Thread, not a Processes, So each application has at least one process and a process always has at least one thread of execution, knowingly as a primary thread. What is strong-typing versus weak-typing? Strong typing: It checks the type of variables as soon as possible, usually at compile time. It prevents mixing operations between mismatched types. A strong-typed programming language is one in which: All variables (or data types) are known at compile time There is strict enforcement of typing rules (a String can't be used where an Integer would be expected) All exceptions to typing rules results in a compile time error Weak Typing: While weak typing is delaying checking the types of the system as late as possible, usually to run-time. In this you can mix types without an explicit conversion. A "weak-typed" programming language is simply one which is not strong-typed. which is preferred depeneds on what you want. for scripts and good stuff you will usually want weak typing, because you want to write as much less code as possible. in big programs, strong typing can reduce errors at compile time. What is boxing? Boxing is the process of converting a value type to the type object or to any interface type implemented by this value type. When the CLR boxes a value type, it wraps the value inside a System.Object and stores it on the managed heap. Unboxing extracts the value type from the object. Boxing is implicit; unboxing is explicit. int i = 123; // The following line boxes i. object o = i; o = 123; i = (int)o; // unboxing Is string a value type or a reference type? It’s a reference type. ALL .Net data typeshas default size except string and user type. So string is reference type, bcos its does not have default allocation size. What are value types and reference types? Value types are stored in the Stack whereas reference types stored on heap. Value Types: int, enum, byte, decimal, double,float, long

description

int

Transcript of Interview Questions

What is the difference between a thread and a process?

A Process is a collection of Virtual Memory space, code, data and

System resources. A Thread is a code that is to be serially executed

with in the process. A processor executes Thread, not a Processes, So

each application has at least one process and a process always has at

least one thread of execution, knowingly as a primary thread.

What is strong-typing versus weak-typing?

Strong typing: It checks the type of variables as soon as possible, usually at compile time. It

prevents mixing operations between mismatched types.

A strong-typed programming language is one in which:

All variables (or data types) are known at compile time

There is strict enforcement of typing rules (a String can't be used where an Integer would be

expected)

All exceptions to typing rules results in a compile time error

Weak Typing: While weak typing is delaying checking the types of the system as late as possible,

usually to run-time. In this you can mix types without an explicit conversion.

A "weak-typed" programming language is simply one which is not strong-typed.

which is preferred depeneds on what you want. for scripts and good stuff you will usually want weak

typing, because you want to write as much less code as possible. in big programs, strong typing can

reduce errors at compile time.

What is boxing?

Boxing is the process of converting a value type to the type object or to any interface type

implemented by this value type. When the CLR boxes a value type, it wraps the value inside a

System.Object and stores it on the managed heap. Unboxing extracts the value type from the object.

Boxing is implicit; unboxing is explicit.

int i = 123;

// The following line boxes i.

object o = i;

o = 123;

i = (int)o; // unboxing

Is string a value type or a reference type?

It’s a reference type.

ALL .Net data typeshas default size except string and user type. So

string is reference type, bcos its does not have default allocation

size.

What are value types and reference types?

Value types are stored in the Stack whereas reference types stored on heap.

Value Types:

int, enum, byte, decimal, double,float, long

Reference Types:String , Class, Interface, Object

What is Reflection?

Reflection provides objects (of type Type) that describe assemblies, modules and types.

// UsingGetType to obtain type information:

int i = 42;

System.Type type = i.GetType();

System.Console.WriteLine(type);

// Using Reflection to get information from an Assembly:

System.Reflection.Assembly info = typeof(System.Int32).Assembly;

System.Console.WriteLine(info);

what is the difference between early-binding and late-binding?

Early Binding

Early Binding describes that compiler knows about what kind of

object it is, what are all the methods and properties it contains.

As soon as you declared the object, .NET Intellisense will populate

its methods and properties on click of the dot button.

Late Binding

Late Binding describes that compiler does not know what kind of

object it is, what are all the methods and properties it contains.

You have to declare it as an object, later you need get the type of

the object, methods that are stored in it. Everything will be known

at the run time.

Difference

Application will run faster in Early binding, since no boxing or

unboxing are done here.

Easier to write the code in Early binding, since the

intellisense will be automatically populated

Minimal Errors in Early binding, since the syntax is checked

during the compile time itself.

Late binding would support in all kind of versions, since

everything is decided at the run time.

Minimal Impact of code in future enhancements, if Late Binding

is used.

Performance will be code in early binding.

What is an Interface and how is it different from a Class?

When would using Assembly.LoadFrom and Assembly.LoadFile?

What's the difference between viewstate and sessionstate?

How to redirect a page to another page?

How to pass values between pages? Query String, Context, Session

Can multiple catch blocks be executed?

No, Multiple catch blocks can’t be executed. Once the proper catch code

executed, the control is transferred to the finally block and then the code

that follows the finally block gets executed.

What is serialization?

When we want to transport an object through network then we have to convert

the object into a stream of bytes. The process of converting an object into

a stream of bytes is called Serialization. For an object to be

serializable, it should inherit ISerialize Interface.

De-serialization is the reverse process of creating an object from a stream

of bytes.

Can “this” be used within a static method?

This is used to access the methods and variables of non-static class. It

behave like an object. For static class we can’t create an object. So it’s

not possible.

What is the difference between Array and Arraylist?

In an array, we can have items of the same type only. The size of the array

is fixed. An arraylist is similar to an array but it doesn’t have a fixed

size.

What are the differences between System.String and

System.Text.StringBuilder classes?

System.String is immutable. When we modify the value of a string variable

then a new memory is allocated to the new value and the previous memory

allocation released. System.StringBuilder was designed to have concept of a

mutable string where a variety of operations can be performed without

allocation separate memory location for the modified string.

How can we sort the elements of the array in descending order?

Using Sort() methods followed by Reverse() method.

What’s the difference between an interface and abstract class?

Interfaces have all the methods having only declaration but no definition.

In an abstract class, we can have some concrete methods. In an interface

class, all the methods are public. An abstract class may have private

methods.

What is the difference between Finalize() and Dispose() methods?

Dispose() is called when we want for an object to release any unmanaged

resources with them. On the other hand Finalize() is used for the same

purpose but it doesn’t assure the garbage collection of an object.

What is the difference between Server.Transfer and Response.Redirect?

In Server.Transfer page processing transfers from one page to the other

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

clients url history list or current url Server does not update in case of

Server.Transfer.

Response.Redirect is used to redirect the user’s browser to another page or

site. It performs 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.

What are the different Session state management options available in

ASP.NET?

1. In-Process

2. Out-of-Process.

In-Process stores the session in memory on the web server.

Out-of-Process Session state management stores data in an external server.

The external server may be either a SQL Server or a State Server. All

objects stored in session are required to be serializable for Out-of-

Process state management.

What is caching?

Caching is a technique used to increase performance by keeping frequently

accessed data or files in memory. The request for a cached file/data will

be accessed from cache instead of actual location of that file.

What are the different types of caching?

ASP.NET has 3 kinds of caching :

1. Output Caching,

2. Fragment Caching,

3. Data Caching.

Is it possible to create web application with both webforms and mvc?

Yes. We have to include below mvc assembly references in the web forms

application to create hybrid application.

System.Web.Mvc

System.Web.Razor

System.ComponentModel.DataAnnotations

Can we add code files of different languages in App_Code folder?

No. The code files must be in same language to be kept in App_code

folder.

Can we have multiple web config files for an asp.net application?

Yes.

What is Cross Page Posting?

When we click submit button on a web page, the page post the data to the

same page. The technique in which we post the data to different pages is

called Cross Page posting. This can be achieved by setting POSTBACKURL

property of the button that causes the postback. Findcontrol method of

PreviousPage can be used to get the posted values on the page to which the

page has been posted.

What is MVC?

MVC is a framework used to create web applications. The web application

base builds on Model-View-Controller pattern which separates the

application logic from UI, and the input and events from the user will be

controlled by the Controller

Differentiate strong typing and weak typing

In strong typing, the data types of variable are checked at compile time.

On the other hand, in case of weak typing the variable data types are

checked at runtime. In case of strong typing, there is no chance of

compilation error. Scripts use weak typing and hence issues arises at

runtime.

List the major built-in objects in ASP.NET?

Application

Request

Response

Server

Session

Context

Trace

What are the different types of cookies in ASP.NET?

Session Cookie – Resides on the client machine for a single session until

the user does not log out.

Persistent Cookie – Resides on a user’s machine for a period specified for

its expiry, such as 10 days, one month, and never.

What are the components of ADO.NET?

The components of ADO.Net are Dataset, Data Reader, Data Adaptor, Command,

connection.

What is the difference between ExecuteScalar and ExecuteNonQuery?

ExecuteScalar returns output value where asExecuteNonQuery does not return

any value but the number of rows affected by the query. ExecuteScalar used

for fetching a single value and ExecuteNonQuery used to execute Insert and

Update statements.

What's the difference between a left join and an inner join?

INNER JOIN gets all records from one table that have some related entry

in a second table

LEFT JOIN gets all records from the LEFT linked table but if you have

selected some columns from the RIGHT table, if there is no related

records, these columns will contain NULL

Printed

What technology enables out-of-proc communication in .NET?

Remoting

Exception Handling?

An exception is a problem that arises during the execution of a program.

Exceptions provide a way to transfer control from one part of a program to

another. C# exception handling is built upon four

keywords: try, catch, finally and throw.

try: A try block identifies a block of code for which particular exceptions

will be activated. It's followed by one or more catch blocks.

catch: A program catches an exception with an exception handler at the

place in a program where you want to handle the problem. The catch keyword

indicates the catching of an exception.

finally: The finally block is used to execute a given set of statements,

whether an exception is thrown or not thrown. For example, if you open a

file, it must be closed whether an exception is raised or not.

throw: A program throws an exception when a problem shows up. This is done

using a throw keyword.

Global assembly chache?

The Global Assembly Cache (GAC) is a folder in Windows directory to

store the .NET assemblies that are specifically designated to be shared

by all applications executed on a system. Assemblies can be shared

among multiple applications on the machine by registering them in

global Assembly cache(GAC). GAC is a machine wide a local cache of

assemblies maintained by the .NET Framework.

statemgmt.?

State management means to preserve state of a control, web page,

object/data,

There are two types of state management techniques: client side and server

side.

Client side

1. Hidden Field 2. View State 3. Cookies 4. Control State 5. Query Strings

Server side

1. Session

2. Application

diff b/w catch (Exception e) {throw e;} and (Exception e) {throw;}?

Simple: the stack trace.

The empty parameter re-throw keeps the existing stack list, the

parametered version creates a new stack trace to the point of the

throw. For debugging, the empty version tells you where the error

actually occurred, the parametered version discards that.

Is it possible nested master pages?

Master pages can be nested, with one master page referencing another as its

master. Nested master pages allow you to create componentized master pages.

For example, a large site might contain an overall master page that defines

the look of the site. Different site content partners can then define their

own child master pages that reference the site master and that in turn

define the look for that partner's content.

diff b/w ToString() and Convert.Tostring()?

Convert.ToString() handles null, while ToString() doesn't.

HTTPHandler?

In the simplest terms, an ASP.NET HttpHandler is a class that

implements theSystem.Web.IHttpHandler interface.

ASP.NET HTTPHandlers are responsible for intercepting requests made to

your ASP.NET web application server. They run as processes in response

to a request made to the ASP.NET Site. The most common handler is an

ASP.NET page handler that processes .aspx files. When users request an

.aspx file, the request is processed by the page through the page

handler.

ASP.NET offers a few default HTTP handlers:

Page Handler (.aspx): handles Web pages

User Control Handler (.ascx): handles Web user control pages

Web Service Handler (.asmx): handles Web service pages

Trace Handler (trace.axd): handles trace functionality

write a sample procedure with body and cursor?

CREATEORREPLACEPROCEDUREmyprocedureAS

TEST_CUR SYS_REFCURSOR;

QUERY VARCHAR2(200);

Cur_DATEDATE;

BEGIN

QUERY :='select sysdate as mydate from dual';

OPEN TEST_CUR FOR QUERY;

LOOP

FETCH TEST_CUR

INTOCur_DATE;

EXITWHEN TEST_CUR%NOTFOUND;

DBMS_OUTPUT.PUT_LINE(Cur_DATE);

ENDLOOP;

CLOSE TEST_CUR;

ENDmyprocedure;

wat is view?

a view (database) is a virtual table, which consists of a stored

query accessible composed of the result set of a query.

CREATEVIEWview_nameAS

SELECTcolumn_name(s)

FROMtable_name

WHERE condition

diff b/w where and having?

HAVING specifies a search for something used in the SELECT statement.

In other words.

HAVING applies to groups.

WHERE applies to rows.

killa users session?

session.abandon()

parent class of the Web server control?

The System.Web.Ul.Control class is the parent class for all Web

server controls.

.net Architecture

What kind of data is passed via HTTP Headers?

diff b/w ASP Session and ASP.NET Session?

How do you create a permanent cookie?

Setting a permanent cookie is similar to Session cookie, except give the

cookie an expiration date too. It is very common that you don't specify any

arbitrary expiration date, but instead expire the cookie relative to

the current date, using the DateAdd() function.

Response.Cookies("Name") = "myCookie"

Response.Cookies("Name").Expires = DateAdd("m", 1, Now())

diff b/w function and procedure?

1. Functions is mainly used in the case where it must return a

value. Whereas a procedure may or may not return a value or many

return more than one value using the OUT Parameter.

2. Function can be called from SQL statements whereas procedure

cannot be called from the sql statements.

3. Function are normally used for computations whereas procedure are

normally used for executing a business logic.

4. Function returns 1 value only. Procedure can return multiple

values(1024).

5. Stored procedure returns always integer value by default zero.

Whereas function return type could be scalar or table or table

values.

Printed

How to avoid application output or yellow page error?

<configuration>

<system.web>

<customErrorsdefaultRedirect=”MyErrorPage.aspx” mode=”on”/>

</system.web>

</configuration>

Or Compilation= true

How to make ViewState secure in ASP.NET ?

You can do this by adding EnableViewStateMAC=true in your page

directive. MAC stands for "Message Authentication Code"

When we use EnableViewStateMac="True", during ViewState save,

ASP.NET internally uses a hash code. This hash code is a

cryptographically strong checksum. This is added with the ViewState

content and stored in a hidden filed. During postback, the checksum

data is verified again by ASP.NET. If there is a mismatch, the

postback will be rejected.

he second option is to set ViewStateEncryptionMode="Always" with

your page directives. This will encrypt the ViewState data.

procedure performance tunning ?

Indexing the table

Optimized Query

Avoid Looping

What is the use of AutoEventWireup?

AutoEventWireup is an attribute of the @ Page directive.

The AutoEventWireup attribute may have a value of true or false. The

value is set to false when you create a new ASP.NET Web Application.

use the AutoEventWireup attribute to code ASP.NET Web Forms and Web

User Controls. When you set the value of

the AutoEventWireup attribute to true, the code in ASP.NET Web Forms

and in Web User Controls is simple. However, when you use

the false value in certain circumstances, you may receive better

performance.

You can specify a default value of the AutoEventWireup attribute in

several places:

The Machine.config file

The Web.config file

Individual ASP.NET Web Forms (.aspx files)

Web User Controls (.ascx files)

When you set the value of the AutoEventWireup attribute to true, the

ASP.NET runtime does not require events to specify event handlers

like the Page_Load event or the Page_Init event. This means that in

Visual C# .NET, you do not have to initialize and to create the

delegate structures.

Can we declare an Abstract method in non-abstract class?

No its not possible

In C# how do you find the last error which occurred ?

This can be done by implementing a method called GetLastError().

Generally this returns aASPError object stating the error condition

that has occurred. This method will work only before the .ASP page

sent any content to the Client.

Exception LastErrorOccured;

String ShowErrMessage;

LastErrorOccured = Server.GetLastError();

if (LastErrorOccured != null)

ShowErrMessage = LastErrorOccured.Message;

else

ShowErrMessage = "No Errors";

Response.Write("Last Error Occured = " + ShowErrMessage);

Which method do you use to redirect the user to another page without

performing a round trip to the client?

Server.Transfer and Server.Execute.

what is the main difference between delegate and an event in c#?

Delegate:-A delegate is basically a reference to a method. A

delegate can be passed like any other variable. This allows the

method to be called anonymously, without calling the method

directly.

delegate declaration defines a reference type that can be used to

encapsulate a method with a specific signature. A delegate instance

encapsulates a static or an instance method. Delegates are roughly

similar to function pointers in C++; however, delegates are type-

safe and secure.

The delegate declaration takes the form:

[attributes] [modifiers] delegate result-type identifier ([formal-

parameters])

Event: An event in one program can be made available to other

programs that target the .NET runtime.

An event is a member that enables an object or class to provide

notifications. Clients can attach executable code for events by

supplying event handlers. Events are declared using event-

declarations:

event-declaration:

event-field-declaration

event-property-declaration

event-modifier:

new

public

protected

internal

private

static

Example:-

public delegate void EventHandler(object sender, Event e);

public class Button: Control

{

public event EventHandler Click;

protected void OnClick(Event e) {

if (Click != null) Click(this, e);

}

public void Reset() {

Click = null;

}

}

What is a sealed class?

It is a class, which cannot be subclassed. It is a good practice to

mark your classes as sealed, if you do not intend them to be

subclassed.

What is the difference between Value Types and Reference Types?

Value Types uses Stack to store the data.

where as Reference type uses the Heap to store the data.

What is web.config file?

Web.config file is the configuration file for the Asp.net web

application. There is one web.config file for one asp.net

application which configures the particular application. Web.config

file is written in XML with specific tags having specific

meanings.It includes databa which includes

connections,SessionStates,ErrorHandling,Security etc.

what is use of web.config?

Web.config is used connect database from front end to back end.

Web.config is used to maintain the Appsettimgs instead of static

variables.

What is smart navigation?

The cursor position is maintained when the page gets refreshed due

to the server side validation

What is the difference between HTTP-Post and HTTP-Get?

The GET method creates a query string and appends it to the script's

URL on the server that handles the request.

The POST method creates a name/value pairs that are passed in the

body of the HTTP request message.

What is Remoting?

Remoting is a means by which one operating system process, or

program, can communicate with another process. The two processes can

exist on the same computer or on two computers connected by a LAN or

the Internet.

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.

Printed