Sunday, 22 June 2014

JavaScript Interview Questions for both Freshers and 3 + years of Experienced Programmers

JavaScript Interview Questions for both Fresher's and 3 + years of Experienced Programmers



What is JavaScript? Ans:JavaScript is a scripting language most often used for client-side web development.

Is JavaScript case sensitive? Ans:Yes!
A function getElementById is not the same as getElementbyID.

What are the types used in JavaScript? Ans:String, Number, Boolean, Function, Object, Null, Undefined.
 
How do we add JavaScript onto a web page? Ans:There are several way for adding JavaScript on a web page, but there are two ways which are commonly used by developers
If your script code is very short and only for single page, then following ways are the best:
a) You can place <script type="text/javascript"> tag inside the <head> element.
Code
<head>
<title>Page Title</title>
<script language="JavaScript" type="text/javascript">
   var name = "rajul konkar"
   alert(name);
</script>
</head>
b) If your script code is very large, then you can make a JavaScript file and add its path in the following way:
Code
<head>
<title>Page Title</title>
<script type="text/javascript" src="myjavascript.js"></script>
</head>

How do you submit a form using JavaScript?
Ans:Use document.forms[0].submit();

What is the difference between JavaScript and Jscript?
Ans:Both JavaScript and Jscript are almost similar. JavaScript was developed by Netscape. Microsoft reverse engineered Javascript and called it JScript.

How to access the value of a textbox using JavaScript? Ans: ex:-
Code
<!DOCTYPE html>
<html>
<body>
Full name: <input type="text" id="txtName"
name="FirstName" value="rajul">
</body>
</html>
There are following ways to access the value of the above textbox:
var name = document.getElementById('txtName').value;
alert(name);
or:
we can use the old way:
document.forms[0].mybutton.
var name = document.forms[0].FirstName.value;
alert(name);
Note: This uses the "name" attribute of the element to locate it.

What do you understand by this keyword in JavaScript? Ans: In JavaScript the this is a context-pointer and not an object pointer. It gives you the top-most context that is placed on the stack.
The following gives two different results (in the browser, where by-default the window object is the 0-level context):

var obj = { outerWidth : 20 };
function test() {
    alert(this.outerWidth);
}
test();//will alert window.outerWidth
test.apply(obj);//will alert obj.outerWidth

What looping structures are there in JavaScript? Ans: for, while, do-while loops

What are the boolean operators supported by JavaScript?
And Operator: &&
Or Operator: ||
Not Operator: !

What does "9+2+8 evaluate to? Ans: Since 9 is a string, everything is a string, so the result is 928.

What is the difference between “==” and “===”? Ans:
“==” checks equality only,
“===” checks for equality as well as the type.

Does JavaScript Support automatic type conversion, If yes give example.Ans: Yes! Javascript support automatic type conversion.
Ex.
var s = '12';
var a = s*19
var b = +s;
typeof(s); //"string"
typeof(a); //"number"
typeof(b); //"number"
How will you get the Checkbox status whether it is checked or not? Ans:
var status = document.getElementById('checkbox1').checked;
alert(status);
will return true or false.
Name any two JavaScript functions which are used to convert nonnumeric values into numbers? Ans:
Number()
parseInt()
parseFloat()
Code
var s1 = Number(“Welcome to India!”); //NaN
var s2 = Number(“”);             //0
var s3 = Number(“000080”);       //80
var s4 = Number(true);           //1
var s5= Number(NaN);            //NaN
What does 2+3+"4" evaluate to?
Ans: Since 2 and 3 are integers, this is number arithmetic, since 4 is a string, it is concatenation, so 54 is the result.
How you will add function as a property in a JavaScript object? Give an example. Ans:
Code
var saw = new Object();
saw.name = 'swapneel Waghmare';
saw.living = true;
saw.age = 27;
saw.getName = function() { return saw.name;}
console.log(saw.getName()); // Logs 'Swapneel Waghmare'.

What does isNaN function do? Ans: It returns true if the argument is not a number.
Example:
Code
document.write(isNaN("test")+ "<br>");
document.write(isNaN("2014/09/12")+ "<br>");
document.write(isNaN(982)+ "<br>");
The output will be:
true
true
false
How do you change the style/class on any element using JavaScript? Ans:
Code
document.getElementById(“sawText”).style.fontSize = “25";
-or-
document.getElementById(“sawText”).className = “testclass”;

What is the use of Math Object in JavaScript?
Ans: The math object provides you properties and methods for mathematical constants and functions.
ex:-
Code
var x = Math.PI; // Returns PI
var y = Math.sqrt(49); // Returns the square root of 49
var z = Math.sin(90);    Returns the sine of 90
How to create arrays in JavaScript?
Ans:There are two ways to create array in JavaScript like other languages:
a) The first way to create array
Declare Array:
Code
var names = new Array();
Add Elements in Array:-
names[0] = "rajul";
names[1] = "prabhakar";
names[2] = "konkar";
b) This is the second way:
var names = new Array("rajul", "prabhakar", "konkar");

 

Basic Interview Questions and Answers for ASP .NET

Basic Interview Questions and Answers for ASP .NET
What is asp.net life cycle ?
Life Cycle Events

PreInit
The properties like IsPostBack have been set at this time.
This event will be used when we want to:
1.        Set master page dynamically.
2.        Set theme dynamically.
3.        Read or set profile property values.
4.        This event is also preferred if want to create any dynamic controls.
Init
1.        Raised after all the controls have been initialized with their default values and any skin settings have been applied.
2.        Fired for individual controls first and then for page.
LoadViewState
1.        Fires only if IsPostBack is true.
2.        Values stored in HiddenField with id as _ViewState decoded and stored into corresponding controls.
LoadPostData
Some controls like:
1.        Fires only if IsPostBack is true.
2.        Some controls like Textbox are implemented from IPostBackDataHandler and this fires only for such controls.
3.        In this event page processes postback data included in the request object pass it to the respective controls.
PreLoad
  • Used only if want to inject logic before actual page load starts.
Load
  • Used normally to perform tasks which are common to all requests, such as setting up a database query.
Control events
1.        This event is fired when IsPostBack is true.
2.        Use these events to handle specific control events, such as a Button control's Click event or a TextBox control's TextChanged event.
PreRender
Raised after the page object has created all the controls that are required for rendering which includes child controls and composite controls.
1.        Use the event to make final changes to the contents of the page or its controls before the values are stored into the viewstate and the rendering stage begins.
2.        Mainly used when we want to inject custom JavaScript logic.
SaveViewState
  • All the control values that support viewstate are encoded and stored into the viewstate.
RenderGenerates output (HTML) to be rendered at the client side.
  • We can add custom HTML to the output if we want here.
Unload
1.        Fired for individual controls first and then for page.
2.       Used to perform cleanup work like closing open files and database connections.  
If I have more than one version of one assemblies, then how will I use old version (how/where to specify version number?) in my application?

The version number is stored in the following format: …. The assembly manifest can then contain a reference to which version number we want to use.
What is the difference between Array and LinkedList?
An array is a collection of the same type. The size of the array is fixed in its declaration.
A linked list is similar to an array but it doesn’t have a limited size.
How can you write a class to restrict that only one object of this class can be created (Singleton class)?

Use the singleton design pattern.
 
 public sealed class Singleton 
 { 
   static readonly Singleton Instance=new Singleton(); 
      static Singleton() 
      { 
      } 
      Singleton() 
      { 
      } 
      public static Singleton Instance 
      { 
           get 
           { 
                return Instance; 
           } 
      } 
 }
 
What is close method? How its different from Finalize and Dispose?
 
finalise is the process that allows the garbage collector to clean up any unmanaged resources before it is destroyed.
The finalise method can not be called directly; it is automatically called by the CLR. In order to allow more control over the release of unmanaged resources
the .NET framework provides a dispose method which unlike finalise can be called directly by code.
Close method is same as dispose. It was added as a convenience.
What is Boxing and UnBoxing?
Converting the value type data type in to the Reference type is called as Boxing. Converting the Reference type data type and keep its value to stack is called as the reference type.

byte b= 45;
Object o = b.Tostring();
The Advantage of boxing and unboxing is that we can convert the type of the object in to another type. The disadvantage is that it requires lot of memory and CPU cycles to convert from one type to another type.
Object o=10;
Int i= Convert.ToInt32(o.ToString());
What is AutoPostBack?
If you want a control to postback automatically when an event is raised, you need to set the AutoPostBack property of the control to True
 
 
Why do you use the App_Code folder in ASP.NET?
The App_Code folder is automatically present in the project. It stores the files, such as classes, typed data set, text files, and reports. If this folder is not available in the application, you can add this folder. One of the important features of the App_Code folder is that only one dll is created for the complete folder, irrespective of how many files it contains.
In which event of page cycle is the ViewState available?
After the Init() and before the Page_Load().
 
How long the items in ViewState exists?
They exist for the life of the current page.

Where the viewstate is stored after the page postback?
ViewState is stored in a hidden field on the page at client side. ViewState is transported to the client and back to the server, and is not stored on the server or any other external source.
What is the difference between web config and machine config?
Web config file is specific to a web application where as machine config is specific to a machine or server. There can be multiple web config files into an application where as we can have only one machine config file on a server.
 
When the View state is saved, and when is it loaded? How to enable/ disable View states?
A. View State data is stored in the current page in base64 encoded format. It gets loaded with the page and displays the values to the controls after the decoded. Internally it actually saves the check-sum of all the control data where the view state is enabled.so that when the page gets loaded due to any post back, it again finds the check-sum and then decodes the Base64 encoded string and gets back the same data to the controls. We can see the view state base 64 encoded string in View Source of the page. It will be like _VIEWETATE="DSDSDF8DGDGDFGFD5FDGGDJFF23BNN457M9UJOG" this.
View state won't take the client or server memory to keep the view state data.
Difference between Server Controls and User controls?
User controls are used for the re-usability for the controls in the application. By using the user control, we can use the same control in the various pages. User controls can be created by combining more than one control. To use the user controls, first we need to register them in the web page where we want to use that control. A separate copy is need in each page where we want to use the user control. User controls can't be included in to the toolbox.
Server controls are those controls which can be found in the toolbox and can be directly drag to the application like textbox, button etc. For the server control, only 1 copy of the control is needed irrespective of the number of web pages. If we want 10 text-boxes to be added in our web page, we need only 1 copy of the textbox in the toolbox and can be dragged 10 times.

Saturday, 21 June 2014

State Management interview questions for dot net 3+ Years of Experience


Interview Questions and Answer for Dot Net 3+ Years of Experience

State Management

Http is stateless, What does this mean?
Ans: Stateless protocol is a communications protocol that treats each request as an independent transaction that is unrelated to any previous request so that the communication consists of independent pairs of requests and responses.
What is Session?
Ans: We know that Http is stateless, means when we open a webpage and fill some information and then move to next page then the data which we have entered will lost.
It happed do to Http protocol stateless nature. So here session come into existence, Session provide us the way of storing data in server memory. So you can store your page data into server
memory and retrieve it back during page postbacks.

What are the Advantage and disadvantage of Session?
Ans: Advantages:
Session provide us the way of maintain user state/data.
It is very easy to implement.
One big advantage of session is that we can store any kind of object in it. :eg, datatabe, dataset.. etc
By using session we don't need to worry about data collesp, because it store every client data separately.
Session is secure and transparent from the user.
Disadvantages:
Performance overhead in case of large volumes of data/user, because session data is stored in server memory.
Overhead involved in serializing and de-serializing session data, because in the case of StateServer and SQLServer session modes, we need to serialize the objects before storing them.


What is Session ID in Asp.net?
Ans: Asp.Net use 120 bit identifier to track each session. This is secure enough and can't be reverse engineered. When client communicate with server, only session id is transmitted, between them. When client request for data, ASP.NET looks on to session ID and retrieves corresponding data.

By default where the sessions ID's are stored ?
Ans: By default, the unique identifier for a session is stored in a non-expiring session cookie in the browser. You can specify that session identifiers not be stored in a cookie by setting the cookieless attribute to true in the sessionState configuration element.
We can also configure our application to store it in the url by specifying a "cookieless" session
The ASP Session cookie has this format:-
ASPSESSIONIDACSSDCCC=APHELKLDMNKNIOJONJACDHFN

Where does session stored if cookie is disabled on client’s machine?
Ans: If you want to disable the use of cookies in your ASP.NET application and still make use of session state, you can configure your application to store the session identifier in the URL instead of a cookie by setting the cookieless attribute of the sessionState configuration element to true, or to UseUri, in the Web.config file for your application.
The following code example shows a Web.config file that configures session state to use cookieless session identifiers.
Code:

<configuration>
  <system.web>
    <sessionState
      cookieless="true"
      regenerateExpiredSessionId="true"
      timeout="30" />
  </system.web>
</configuration>

Can you describe all the property set in web.config under session state?
Ans:


Code:

<configuration>
  <sessionstate
      mode="inproc"
      cookieless="false"
      timeout="20"
      sqlconnectionstring="data source=127.0.0.1;
user id=<user id>;password=<password>"
      server="127.0.0.1"
      port="42424"
  />

</configuration>

Mode: The mode setting supports three options: inproc, sqlserver, and stateserver. As stated earlier, ASP.NET supports two modes: in process and out of process. There are also two options for out-of-process state management: memory based (stateserver), and SQL Server based (sqlserver). We'll discuss implementing these options shortly.
Cookieless: The cookieless option for ASP.NET is configured with this simple Boolean setting.
Timeout: This option controls the length of time a session is considered valid. The session timeout is a sliding value; on each request the timeout period is set to the current time plus the timeout value
Sqlconnectionstring: The sqlconnectionstring identifies the database connection string that names the database used for mode sqlserver.
Server: In the out-of-process mode stateserver, it names the server that is
runninghttp://cdncache-a.akamaihd.net/items/it/img/arrow-10x10.png the required Windows NT service: ASPState.
Port: The port setting, which accompanies the server setting, identifies the port number that corresponds to the server setting for mode stateserver.
What are Session Events?
Ans: There are two types of session events available in ASP.NET:
Session_Start
Session_End
You can handle both these events in the global.asax file of your web application. When a new session initiates, the session_start event is raised, and the Session_End event raised when a session is abandoned or expires.
How you can disable session?
Ans: If we set session Mode="off" in web.config, session will be disabled in the application. For this, we need to configure web.config the following way:
Code:

<configuration>
  <sessionstate  Mode="off"/>
</configuration>

Difference Between Query String and Session

Querystring
Session
Querystring is client side state management technique.
Session is server side state management technique.
Querystring data is page specific i.e. can be accessed in that page only.
Session data can be accessed throughout the session.
Querystring data is visible to user and can be seen in browser url.
Session data is not visible to user.
Data is not secured and can be altered hence insensitive data is stored in querystring.
Data is secured hence sensitive data such as user information is stored.
Querystring has constraint of Maxlength.
Session does not have such constraint.

Difference between Query string and Cookies
cookies is a text file stored on client machine when we surf ant thing on internet by the server automatically we dont have to create it

query string is used to transfer data from 1 page to anothe but this is not safe s it shows in url what data we r sending
pen any site and see url after question mark tht is url

Cookies: - Cookies are little pieces of information that a server stores on a browser. They are of two types
1. Temporary cookie
2. Persistent cookie

Temporary cookie: - They are also known as session cookies. These are volatile in nature. When the browser is shutdown they are erased.

Persistent cookie:- These may be called as permanent cookies. These are especially saved in files. It may remain for a month or year. 


Properties of cookies
Some properties of cookie
Name: - represent the name of cookie.
Name value: - represent a collection of key values of cookie
Domain: - represent the domain associated with a specific cookie.
Path: - the path associated with a cookie.
Expires: - expired time of cookie.
Hashkey: - identifies whether the cookie is a cookie dictionary.
Secure: - specifies whether the cookie is to be sent in an encrypted connection or not
Query string is the limited way to pass information to the web server while Transferring from one page to another page. This information is passed in url of the request. see below the code sample

Code Sample

//Retrieving values from query string
String name;
//Retrieving from query string
name = Request.Param["umar"].ToString();

But remember that many browsers impose a limit of 255 characters in query strings. You need to use HTTP-Get method to post a page to server otherwise query string values will not be available.

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.