Tuesday, March 29, 2011

.NET interview questions: - What are the different principle of OOPS?

Answer:
Different principles of OOPS are Abstraction, Encapsulation, Polymorphism and Inheritance.
1. Abstraction:- It is a thought process which show only the necessary properties.
2. Encapsulation:- Hiding complexity of a class.
3. Inheritance:- Defining a Parent-Child Relationship.
4. Polymorphism:- Object Changes it's behaviour according to the situation.
Regards,
Please click here to see .NET and C# interview questions and answers

Monday, March 28, 2011

.NET and Java J2ee Design pattern interview question: - What is the difference between Template and Strategy pattern

Answer:
Below are the main differences between these two design patterns: -

Template Design pattern

Defines outline for algorithms and allows sub class to override some steps.
Efficient in terms of less redundant code.

Depends on super class for methods.

Strategy Design pattern

Uses object composition to provide variety of algorithm implementation.
Flexible in terms of allowing users to change algorithm at run time.

All the algorithms can be itself implemented.

Regards,

Do visit our .NET design pattern and Java J2EE design pattern interview questions.

Saturday, March 26, 2011

.NET interview questions :- What is the difference between class and structures ?

Answer:
1. Classes are reference types and structs are value types. So in other words class will be allocated on a heap and structs will be allocated on the stack.
2. You cannot have instance Field initializers in structs. Example

class MyClass1
{
int myVar =10; // no syntax error.
public void MyFun(
)
{
// statements
}
} 

struct MyStruct1
{
int myVar = 10; // syntax error.
public void MyFun(
)
{
// statements
}
}

3. Classes can have explicit parameter less constructors. But struts cannot have

4. Classes must be instantiated using the new operator. But struts can be

5. Classes support inheritance. But there is no inheritance for struts.( structs don’t support inheritance polymorphism )

6. Since struct does not support inheritance, access modifier of a member of a struct cannot be protected or protected internal.11. A class is permitted to declare a destructor. But a struct is not

7. classes are used for complex and large set data. structs are for simple data structures.

Regards,
Please click here to see .NET and C# interview questions and answers

Friday, March 25, 2011

Design pattern interview questions :- Which design patterns have you used in your project ?

Answer:

First thing what ever you say , for heaven sake do not say we had used all design patterns ;-) . Look at your project and see which design pattern have you used. Almost all projects use design patterns knowingly or unknowingly , until the project is complete disorganized.

While explaining do ensure to make a 1 line comment atleast to say why that design pattern was used.

Below goes a decent answer of explaining things collectively. Please note answer will change as per your project implementation.

In my current project we had used MVC, Singleton, factory , iterator and template pattern.

My project was tier architecture, divided in to 3 main sections, UI, Business layer and data access layer.

At the presentation level we had used MVC pattern, so the UI and model was separated using controller class.

To share common data across all tiers we had used the singleton pattern.

Factory classes where used between each layer for decoupling and centralizing object creation to avoid code complication.

Iterator pattern was used to browse through middle tier objects thus providing a tight encapsulation.

The middle tier objects and their child objects where standardized using template pattern for consistent vocabulary and naming convention for business objects.

Watch the below design pattern video which explains factory pattern.



Regards,

Please click here to see .NET interview questions and J2EE design pattern questions

Thursday, March 24, 2011

.NET interview questions :- What are Regex / regular expressions ?

Answer:
Regex or regular expression helps us describe complex patterns in texts. Once you have described these patterns you can use them to do searching, replacing, extracting and modifying text data.

Below is a simple sample of regex. The first step is to import the namespace for regular expressions.
using System.Text.RegularExpressions;
The next thing is to create the regex object with the pattern. The below pattern specifies to search for alphabets between a-z with 10 length.
Regex obj = new Regex(“[a-z]{10}”);
Finally search the pattern over the data to see if there are matches. In case the pattern is matching the ‘IsMatch’ will return true.
MessageBox.Show(obj.IsMatch(“shivkoirala”).ToString());
Regards,
View our 21 important .NET interview questions and answers from .NET Interview questions

Wednesday, March 23, 2011

.NET and Java J2ee Design pattern interview question :- What is the difference between Decorator and Adapter pattern?

Answer:
Below is the main difference between these two design patterns.
Decorator Design pattern
Used to deal with new behavior or responsibilities without affecting existing code.

Provides a wrapper over objects to apply same method which yields different results based on whether the object invoked is granular or composite.

Change of interface does not happen.

Adapter Design pattern

Mainly involved in converting interfaces as per the requirement of client

Allows use of new libraries without changing existing methods

Change of interface happens in this case

Regards,

Do visit our .NET design pattern and Java J2EE design pattern interview questions.

.NET and Java J2ee design pattern interview question :-What is the difference between Object and class adapters?


Answer:

Below are the main difference between these 2 patterns.
Object adapter
Can adapt classes as well as sub classes since uses composition

More flexible since dynamic polymorphism can be used with composition
Class adapter

Can adapt classes or sub classes not both. As a result no need to re implement the entire adaptee
More efficient since class adapter acts as adapter and adaptee

Please do visit my .NET Design patterns and Java J2EE design pattern interview questions

Tuesday, March 22, 2011

B- Ball, C- Cat, D – dog: - Learning (REGEX) regular expression the easy way.

Contents
So, what’s the agenda?

Just in case if you are new comer, what is regex?

3 important regex commands

Check if the user has entered shivkoirala?


Let’s start with the first validation, enter character which exists between a-g?


Enter characters between [a-g] with length of 3?

Enter characters between [a-g] with maximum 3 characters and minimum 1 character?

How can I validate data with 8 digit fix numeric format like 91230456, 01237648 etc?

How to validate numeric data with minimum length of 3 and maximum of 7, ex -123, 1274667, 87654?

Validate invoice numbers which have formats like LJI1020, the first 3 characters are alphabets and remaining is 8 length number?

Check for format INV190203 or inv820830, with first 3 characters alphabetscase insensitive and remaining 8 length numeric?

Can we see a simple validation for website URL’s?

Let’s see if your BCD works for email validation?

Short cuts

Quick references for regex


So, what’s the agenda?

Regex has been the most popular and easiest way of writing validations. The only big problem with regex has been the cryptic syntax. Developers who are working on projects with complicated validation always refer some kind of cheat sheet to remember the syntaxes and commands.
In this article we will try to understand what regex is and how to remember those cryptic syntaxes easily.


You can watch my .NET interview questions and answers videos on various sections like WCF, Silver light, LINQ, WPF, Design patterns, Entity framework etc

Just in case if you are new comer, what is regex?

Regex or regular expression helps us describe complex patterns in texts. Once you have described these patterns you can use them to do searching, replacing, extracting and modifying text data.
Below is a simple sample of regex. The first step is to import the namespace for regular expressions.

using System.Text.RegularExpressions;
The next thing is to create the regex object with the pattern. The below pattern specifies to search for alphabets between a-z with 10 length.

Regex obj = new Regex(“[a-z]{10}”);

Finally search the pattern over the data to see if there are matches. In case the pattern is matching the ‘IsMatch’ will return true.

MessageBox.Show(obj.IsMatch(“shivkoirala”).ToString());

3 important regex commands

The best way to remember regex syntax is by remembering three things Bracket, carrot and Dollars.






Now once you know the above three syntaxes you are ready to write any validation in the world. For instance the below validation shows how the above three entities fit together.



• The above regex pattern will only take characters which lies between ‘a’ to ‘z’. The same is marked with square bracket to define the range.

• The round bracket indicates the minimum and maximum length.

• Finally Carrot sign at the start of regex pattern and dollar at the end of regex pattern specifies the start and end of the pattern to make the validation more rigid.

So now using the above 3 commands let’s implement some regex validation.


Check if the user has entered shivkoirala?


shivkoirala

Let’s start with the first validation, enter character which exists between a-g?


[a-g]

Enter characters between [a-g] with length of 3?


[a-g]{3}

Enter characters between [a-g] with maximum 3 characters and minimum 1 character?


[a-g]{1,3}

How can I validate data with 8 digit fix numeric format like 91230456, 01237648 etc?


^[0-9]{8}$

How to validate numeric data with minimum length of 3 and maximum of 7, ex -123, 1274667, 87654?

We need to just tweak the first validation with adding a comma and defining the minimum and maximum length inside curly brackets.

^[0-9]{3,7}$

Validate invoice numbers which have formats like LJI1020, the first 3 characters are alphabets and remaining is 8 length number?




Now butting the whole thing together.

^[a-z]{3}[0-9]{7}$

Check for format INV190203 or inv820830, with first 3 characters alphabets case insensitive and remaining 8 length numeric?

In the previous question the regex validator will only validate first 3 characters of the invoice number if it is in small letters. If you put capital letters it will show as invalid. To ensure that the first 3 letters are case insensitive we need to use ^[a-zA-Z]{3} for character validation.
Below is how the complete regex validation looks like.

^[a-zA-Z]{3}[0-9]{7}$

Can we see a simple validation for website URL’s?





^www.[a-z]{1,15}.(com|org)$

Let’s see if your BCD works for email validation?




^[a-zA-Z0-9]{1,10}@[a-zA-Z]{1,10}.(com|org)$

Short cuts

You can also use the below common shortcut commands to shorten your regex validation.


Quick references for regex

Great concise cheat sheet http://www.dijksterhuis.org/csharp-regular-expression-operator-cheat-sheet/



Monday, March 21, 2011

.Net Interview Questions :- Can you explain template pattern?

Template pattern is a behavioral pattern. Template pattern defines a main process template and this main process template has sub processes and the sequence in which the sub processes can be called. Later the sub processes of the main process can be altered to generate a different behavior.

Punch :- Template pattern is  used in scenarios where we want to create  extendable
behaviors in generalization and specialization relationship.

For example below is a simple process to format data and load the same in to
oracle. The data can come from various sources like files, SQL server etc.
Irrespective from where the data comes, the overall general process is to load
the data from the source, parse the data and then dump the same in to oracle.


Figure: - General Process
Now we can alter the general process to create a CSV file load process or SQL server load process by overriding ‘Load’ and ‘Parse’ sub process implementation.




Figure: - Template thought Process

You can see from the above figure how we have altered ‘Load’ and ‘Parse’ sub process to generate CSV file and SQL Server load process. The ‘Dump’ function and the sequence of how the sub processes are called are not altered in the child processes.
In order to implement template pattern we need to follow 4 important steps:-

  1. Create the template or the main process by creating a parent abstract class.
  2. Create the sub processes by defining abstract methods and functions.
  3. Create one method which defines the sequence of how the sub process methods will be called. This method should be defined as a normal method so that we child methods cannot override the same.
  4. Finally create the child classes who can go and alter the abstract methods or sub process to define new implementation.
public abstract class GeneralParser
   {
       protected abstract void Load();

       protected abstract void Parse();
       protected virtual void Dump()
       {
           Console.WriteLine("Dump data in to oracle");
       }
       public void Process()
       {
           Load();
           Parse();
           Dump();
       }
   }
The ‘SqlServerParser’ inherits from ‘GeneralParser’ and overrides the ‘Load’ and ‘Parse’ with SQL server implementation.
public class SqlServerParser : GeneralParser
   {
       protected override void Load()
       {
           Console.WriteLine("Connect to SQL Server");
       }
       protected override void Parse()
       {
           Console.WriteLine("Loop through the dataset");
       }   
    
   }
The ‘FileParser’ inherits from General parser and overrides the ‘Load’ and ‘Parse’ methods with file specific implementation.
public class FileParser : GeneralParser
   {
       protected override void Load()
       {
           Console.WriteLine("Load the data from the file");
       }
       protected override void Parse()
       {
           Console.WriteLine("Parse the file data");
       }
  
   }
From the client you can now call both the parsers.
FileParser ObjFileParser = new FileParser();
ObjFileParser.Process();
Console.WriteLine("-----------------------");
SqlServerParser ObjSqlParser = new SqlServerParser();
ObjSqlParser.Process();
Console.Read();
The outputs of both the parsers are shown below.
Load the data from the file
Parse the file data
Dump data in to oracle
-----------------------
Connect to SQL Server
Loop through the dataset
Dump data in to oracle


View my 21 important .NET Interview questions and answers

.Net Interview Questions:- Can you explain composite pattern?

GOF definition :- A tree structure of simple and composite
Many times objects are organized in tree structure and developers have to understand the difference between leaf and branch objects. This makes the code more complex and can lead to errors.
For example below is a simple object tree structure where the customer is the main object which has many address objects and every address object references lot of phone objects.



Figure: - General Process
Now let’s say you want to insert the complete object tree. The sample code will be something as shown below. The code loops through all the customers, all addresses inside the customer object and all phones inside the address objects. While this loop happens the respective update methods are called as shown in the below code snippet.

foreach (Customer objCust in objCustomers)
{
objCust.UpDateCustomer();
foreach (Address oAdd in objCust.Addresses)
{
oAdd.UpdateAddress();
}
foreach (Phone ophone in oAdd.Phones)
{
  ophone.UpDatePhone();
}
}

The problem with the above code is that the update vocabulary changes for each object. For customer its ‘UpdateCustomer’ , for address its ‘UpdateAddress’ and for phone it is ‘UpdatePhone’. In other words the main object and the contained leaf nodes are treated differently. This can lead to confusion and make your application error prone.

The code can be cleaner and neat if we are able to treat the main and leaf object uniformly. You can see in the below code we have created an interface (IBusinessObject) which forces all the classes i.e. customer, address and phone to use a common interface. Due to the common interface all the object now have the method name as “Update”.

foreach (IBusinessObject ICust in objCustomers)
{
ICust.Update();
foreach (IBusinessObject Iaddress in ((Customer)(ICust)).ChildObjects)
{
  Iaddress.Update();
foreach (IBusinessObject iphone in ((Address)(Iaddress)).ChildObjects)
   {
      iphone.Update();
}
}
}

In order to implement composite pattern first create an interface as shown in the below code snippet.

public interface IBusinessObject
{
     void Update();
     bool isValid();
     void Add(object o);
 
}

Force this interface across all the root objects and leaf / node objects as shown below.

public class Customer : IBusinessObject
 {

     private List<Address> _Addresses;
     public IEnumerable<Address> ChildObjects
     {
         get
         {
             return (IEnumerable<Address>)_Addresses;
         }
     }
     public void Add(object objAdd)
     {
         _Addresses.Add((Address) objAdd);
     }
     public void Update()
     {
      
     }
     public bool isValid()
     {
         return true;
     }
}

Force the implementation on the address object also.

public class Address : IBusinessObject
  {
      private List<Phone> _Phones;

      public IEnumerable<Phone> ChildObjects
      {
          get
          {
              return (IEnumerable<Phone>)_Phones.ToList<object>();
          }
      }

      public void Add(object objPhone)
      {
          _Phones.Add((Phone)objPhone);
      }



      public void Update()
      {
      
      }

      public bool isValid()
      {
          return true;
      }

 
  }
Force the implementation on the last node object i.e. phone.
public class Phone : IBusinessObject
  {
      public void Update()
      {}
      public bool isValid()
      {return true;}
      public void Add(object o)
      {
          // no implementaton
      }      }
  }

View my 21 important .NET Interview questions and answers

Friday, March 18, 2011

.NET and SQL Server interview question: - What is difference between truncate and delete?

Answer:

Both Truncate and Delete are used to delete data from the tables. Below are
some important differences.
TRUNCATE is a DDL (data definition language) statment whereas DELETE is a DML (data manipulation language) statement.

  • In DELETE command we can use where condition in TRUNCATE you cannot.

  • TRUNCATED data cannot be rolled back while delete can be.

  • When there are triggers on table and when you fire truncate trigger do not fire . When you fire delete command triggers are executed.

  • TRUNCATE resets the identity counter value where DELETE does not.

  • Delete and Truncate both are logged operation. Delete operation is logged on row basis while TRNCATE logs at page level.

  • TRUNCATE is faster than DELETE.


    Regards,

    View my 21 important .NET interview questions and answers

Thursday, March 17, 2011

.NET Interview questions :- How did you do unit testing in your project?

Answer:

In today’s software industry people do not just look how good you are in coding but they would like to know how good you are in processes.
This C# interview question touches one of the important aspects of SDLC processes which is “Unit testing” or you can say white box testing.

Note: - Many developers answer that they did unit testing manually. Many interviewers of bigger companies will not be pleased with this answer. The whole point about unit testing is to automate white box testing. The time you say you have done manual testing which means you have done integration testing.

There are two important testing tools which are widely used to do unit test in Microsoft technologies, first is VSTS Unit test and second is NUNIT.So if you have used one of these tools, do talk about the same. Below is a simple sample answer by a developer who has used VSTS unit test for testing.

“Our project was divided in three layers UI, BO and Data access layer. Asa developer I was responsible to write unit test code on the middle layer or the business object. We used VSTS unit test suite to write our test. So for each important functions and methods of the middle layer stubs where generated by right clicking on the middle layer functions. Inside the stub we went and put proper assert function as needed by the test”.

View my 21 important .NET Interview questions and answers

Wednesday, March 16, 2011

Comparison of MVC implementation between J2EE and ASP.NET, Who is the best? Part 1

Comparison of MVC implementation between J2EE and ASP.NET, Who is the best? Part 1


Contents

So, what’s the agenda?
This is not for beginners

Overall Comparison without framework

The Sample for comparison

The model – Javabean in J2EE and .NET class in ASP.NET

The Controller – Servlet in J2ee and HttpHandler in ASP.NET

The mapping XML files – Web.xml in J2ee and Web.config in ASP.NET

The View –Servlet in J2ee and HttpHandler in ASP.NET

Summarizing the Final Comparison table

Next steps comparing using frameworks


So, what’s the agenda?

Some times back I was discussing MVC with one of my Java friends. The talk ended up with a fight trying to prove how one technology is better than other in implementing MVC. For whatever reasons good or bad I was trying to prove that Microsoft technology is the best but…hmm,aaahh and ooohh.
The fact is both the technologies have their own way of doing things. So I ended up writing this comparison article which talks about the differences between how MVC is implemented in J2EE as compared to ASP.NET.

To do full justice in terms of comparison I have divided the article in two parts. In the first part we will compare MVC implementation without using framework and tools.

In the second part I will bring up the comparison of MVC using j2EE struts as compared to ASP.NET MVC visual studio template.

You can watch our Java and J2EE design pattern videos on various topics like Model view controller, front controller, intercepting filter, factory patterns and lot more. Do not miss my .NET design pattern videos which covers 24 patterns including MVC, MVP and MVVM.



This is not for beginners

Well this article is definitely not for beginners, in case you are lookingfor MVC fundamental articles you can see my MVC implementation using core HttpHandler @ MVC using HttpHandler ASP.NET

Overall Comparison without framework

So as we all know in MVC the first hit comes to the controller and the controller binds the view with the model and sends it to the end user.
Model, view and controller form the three core pillars for MVC. From 30,000 feet
level (That number makes every architect feel good…) below is how these three
modules are implemented in each of these technologies:-




Below is simple pictorial representation of how things actually look like.





The Sample for comparison

In order to do a proper comparison we have taken a common example. In this example we will do the following:-
• When the user comes to the web site, the first page he will see is the Index page. So if it’s ASP.NET he will see index.aspx page, if its j2EE he will see index.jsp page.

• Index page is nothing but a simple page which takes username and password and sends a login command to the controller.

• Once the controller gets the login command, he creates the object of the model and checks if the user is proper or not.

• If the user is proper he sends them to welcome view page or else he redirects them to the error view page.


The model – Javabean in J2EE and .NET class in ASP.NET

Let’s start with the simplest part of MVC i.e. model.
For the above example we will create a simple class called as “User”, this class will have two properties “Username” and “Password”. The client, which for now the controller will set these two properties can call the “IValid” function to check if the user is valid or not.

In J2EE the model is nothing but the Java bean class , in .NET its a simple class with setter and getters. Below is the sample code for the same.

J2EE Model using Javabean

public class UserBean
{
public UserBean()
{
     this.username="user";
     this.password="pass";
}

public String getPassword()
{
     return password;
}

public void setPassword(String password)
{
      this.password = password;
}

public String getUsername()
{
     return username;
}

public void setUsername(String
username) {
     this.username = username;
}
public boolean IsValid
(String username,String password)
{
return this.username.equals(username)
&& this.password.equals(password);
}
}

ASP.NET Model using .NET class

public class User
{
public string UserName
{
set
{
_strUserName = value;
}
get
{
return _strUserName;
}
}
     public string Password
     {
        set
        {
        _strPassword = value;
        }
        get
        {
            return _strPassword;
         }
      }
      public bool IsValid()
     {
 if (_strUserName == "user"
&& _strPassword == "pass")
        {
              return true;
        }
         else
        {
              return false;
        }
    }
}

The Controller – Servlet in J2ee and HttpHandler in ASP.NET

The next important part is the controller. The controller forms the heart of MVC.
To create a controller in J2EE we create a class which inherits from ‘HttpServlet’ class. The logic of the controller is written in the “processrequest” method. You can access the request and response object using the ‘HttpServletRequest’ class and ‘HttpServletResponse’ class.

To create a controller in ASP.NET we implement the “IHttpHandler” class and override the “processrequest” with the controller logic. Below is the simple code of how the controllers are implemented in both the technologies. To Access the request and response object we need to use the context class in ASP.NET while in J2EE its available as the part of function with different objects as shown in the below code snippet.

J2EE Controller using Servlet

public class LoginServlet extends
HttpServlet

{

protected void
processRequest(HttpServletRequest
request, HttpServletResponse response)

throws ServletException, IOException
{
// In this will go the code for
// connecting the model to the view.
}
}

ASP.NET controller using HttpHandler

public class LoginHandler :
IHttpHandler,IRequiresSessionState
{
public void ProcessRequest(HttpContext
context)
{
// In this will go the code for
// connecting the model to the view.

}
}

In the controller we can get the data from request and response using in both
technologies using the below code.

J2EE Taking data from the JSP form

String username =
(String)request.getParameter("username")
;
String password =
(String)request.getParameter("password")
;
UserBean model = new UserBean();

Taking data from the .aspx page

User obj = new User();
obj.UserName =
context.Request.Form["txtUser"].ToString(
);
obj.Password =
context.Request.Form["txtPassword"].ToString( );

We then call the “isValid” function of the model and redirect to welcome page or to the home page depending on if he is a valid user or not. To redirect in J2EE we use the “RequestDispatcher” class and to redirect in ASP.Net we use the“response.redirect” function.


J2EE checking if user is valid and redirecting

boolean isValidUser = model.isValid();
if(isValidUser)
{
request.setAttribute("welcome","Welcom
e"+username);
}
else
nextJsp ="Error.jsp";
RequestDispatcher dispatch =
request.getRequestDispatcher(nextJsp);
dispatch.forward(request,response);

ASP.NET checking if the user id valid and redirecting.

if (obj.IsValid())
{

context.Session["Welcome"] = "welcome " +
obj.UserName;

context.Response.Redirect("Welcome.aspx");
}
else
{

context.Response.Redirect("Error.aspx");

}

The mapping XML files – Web.xml in J2ee and Web.config in ASP.NET

Now that we have created the controller, we need to map the actions or the URL pattern with the controller. In other words when someone sends an action or URL pattern as “Login” we need to ensure that it invokes the appropriate controller.
Mapping of pattern / action to the controller in both technologies is done by using a configuration XML file. In J2EE this configuration file is called as the “Web.xml” file and in ASP.NET it’s called as “Web.config”.

In J2EE in web.xml we first need to map which URL pattern maps with which servlet. For instance you can see in the below web.xml code snippet we have mapped the Login pattern with LoginServlet servlet name.

<servlet-mapping>

<servlet-name>
LoginServlet
</servlet-name>

<url-pattern>
/Login
</url-pattern>

</servlet-mapping>

Once the pattern is matched with the servlet name, we then need to map the servlet name with the servlet / controller class as shown in the below code snippet.

<servlet-name>
LoginServlet
</servlet-name>
<servlet-class>
com.questpond.controller.LoginServlet
</servlet-class>

In ASP.NET the controller or the handler is mapped with the URL pattern using the web.config file. Below is a web.config file simple XML file code snippet which shows how the Login URL pattern is mapped with the httphandler ‘Loginhandler’.

<httpHandlers>
<add verb="POST" path="Login" type="MVCAspWithoutFramework.LoginHandler"/>
</httpHandlers>
Below is how the overall config file looks in both technologies.

J2EE Web.XML

   <servlet-name>LoginServlet</servlet-
name>
  <servlet-
class>com.questpond.controller.LoginServlet
</servlet-class>
 </servlet>
 <servlet-mapping>
       <servlet-
name>LoginServlet</servlet-name>
      <url-pattern>/Login</url-pattern>
 </servlet-mapping>

ASP.NET Web.config

<httpHandlers>
    <add verb="POST" path="Login"
type="MVCAspWithoutFramework.LoginHan
dler"/>

   </httpHandlers>

The View – Servlet in J2ee and HttpHandler in ASP.NET

The next important part is the view. The view is nothing but a simple page with the form tag and action having the URL pattern.
You can see how the index.jsp and the index.aspx have the action to Login URL
pattern. This URL pattern is then mapped in the web.xml and web.config file to
the appropriate controller.

J2EE view index.jsp


<form action="Login" method="post">
         Username<input type="text"
name="username" value="" />
        <br/>
        Password<input type="password"
name="password" value="" />
       <br/>
       <input type="submit"
value="Submit" />

  </form>

ASP.NET view index.aspx


<form id="form1" runat="server"
action="Login" method=post>
 <div>

<asp:TextBox ID="txtUser"
runat="server"></asp:TextBox>
<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server"
Text="Button" />

</div>
</form>

Summarizing the Final Comparison table


Next steps comparing using frameworks

This article compared MVC implementation in both technologies without framework, in the next article we will see how MVC differs when frameworks are used. Struts is the most popular framework in J2EE for MVC and the Microsoft VS MVC template is the most used way if implementing MVC in Microsoft.
Let’s see who wins, who is better ….

Tuesday, March 15, 2011

ASP.NET and .NET Interview question video :- What is Authentication and Authorization ?

ASP.NET and .NET Interview question video :- What is
Authentication and Authorization ?


Answer:
Authentication is the process where we identify who the user is.
Authorization is the process where we check what kind of role the identified user has.
Below is a simple video which describes these two vocabularies in a precise manner.



View my 21 important .NET Interview questions and answers

Monday, March 14, 2011

ASP.NET Interview questions :- What is the advantage of using MVC pattern?

Answer:


MVC is one of the most used architecture pattern in ASP.NET and this is one of
those ASP.NET interview question to test that do you really understand the
importance of model view controller.

  • It provides a clean separation of concerns between UI and model.

  • UI can be unit test thus automating UI testing.

  • Better reuse of views and model. You can have multiple views which can
    point to the same model and also vice versa.

  • Code is better organized.

Get my 21 important .NET interview questions and answers

C# interview question :- What is Serialization in .NET ?

Answer:

Serialization is a process by which we can save the state of the object by converting the object in to stream of bytes.These bytes can then be stored in database, files, memory etc.

Below is a simple code of serializing the object.

MyObject objObject = new MyObject();

objObject.Value = 100;
// Serialization using SoapFormatter

SoapFormatter formatter = new SoapFormatter();

Stream objFileStream = new FileStream("c:\\MyFile.xml", FileMode.Create,
FileAccess.Write, FileShare.None);

formatter.Serialize(objFileStream, objObject);

objFileStream.Close();

Below is simple code which shows how to deserialize an object.

//De-Serialization

Stream objNewFileStream = new FileStream("c:\\MyFile.xml", FileMode.Open,
FileAccess.Read, FileShare.Read);

MyObject objObject =(MyObject)formatter.Deserialize(objNewFileStream);

objNewFileStream.Close();

View my top 21 .NET Interview questions and answers

Thursday, March 10, 2011

SQL Server interview question: - What is the difference between unique key and primary key?

Answer:
This is a typical SQL Server interview question and below is the comparison sheet.

Below is a nice video which demonstrates the same in a much precise manner...Enjoy.

You can see my 21 important .NET interview questions

Wednesday, March 9, 2011

.NET interview question video :-what is the difference between convert.tostring() and tostring() functions ?

Answers

This is one of those famous .NET interview question which keeps coming up now and then. To answer precisely and shortly convert.tostring handles nulls while simple tostring() function does not handle null. Below video demonstrates the same practically.



See my 21 important .NET and C# interview questions

Tuesday, March 8, 2011

C# interview questions :- In ADO.NET What is connection, command, datareader and dataset object ?

Answer:
Connection: - This object creates a connection to the database. If you want to do any operation on the database you have to first create a connection object.
Command: - This object helps us to execute SQL queries against database. Using command object we can execute select, insert, update and delete SQL command.
Data reader: - This provides a recordset which can be browsed only in forward direction. It can only be read but not updated. Data reader is goodfor large number of records where you want to just browse quickly and display it.
Dataset object: - This provides a recordset which can be read back and in forward direction. The recordset can also be updated. Dataset is like a in memory database with tables, rows and fields.
Data Adapter: - This object acts as a bridge between database and dataset; it helps to load the dataset object.
See my 21 important .NET interview question and answers

Monday, March 7, 2011

.NET interview questions :- Can you explain architecture of your project ?

.NET interview questions :- Can you explain architecture of your project ?


Answer:



This is normally the first .NET interview question which pops up in .NET and C# interviews. Personally i think your full .NET interview ahead depends on how you will answer this question.

Common mistakes :- Many developers make a common mistake of answering this question by saying that we have used C# , SQL server , ASP.NET etc. But please do note that the question is, what is the architecture of your project and not technology.

So a typical answer will be something as below. Please note your answer will vary as per your architecture and structure.

"My current architecture is a simple 3 tier architecture with UI in ASP.NET , middle layer are simple .NET classes and DAL is using enterprise application blocks.
The UI is responsible to take user inputs , all my business validations are centrally located in middle layer and the data access layer is responsible to execute stored procedured and SQL queries to SQL Server.

Strongly typed business objects are used to pass data from one layer to other layer. The database of the project is in a 3rd normal form."

So first start with the overall architecture , talk about each layer , how data is passed between each layer and the database design structure.

One very important tip if you can draw a diagram and explain....I think you have the job.










Saturday, March 5, 2011

C# Interview Questions:-What is MVVM ( Model view view model) Design pattern ?

C# Interview Questions:-What is MVVM ( Model view view model) Design pattern?


Answers

This is a good c# interview questions which is asked around design pattern.

MVVM is a UI design pattern. The main use of this pattern to remove UI cluttered code like bindings , synchronization etc.

In this pattern we create a extra class called as view model or model which acts as a bridge between model and view. The view sends the actions and data to the model view class who in turns sends the data to model. Any changes in the model is replicated or informed to the UI using the INotifyPropertyChanged interface.


Regards,

View my 21 important C#Interview Questions and Answers

Friday, March 4, 2011

.NET interview questions :- What is the use of private constructor ?

.NET interview questions :- What is the use of private constructor ?


Answer:

Below is the video and text which explains everything






This is one of those .NET interview question which is asked from the perspective to test if you understand the importance of private constructors in a class.
When we declare a class constructor as private , we can not do 2 things:-

  • We can not create a object of the class.

  • We can not inherit the class.
Now the next question which the interviewer will ask , whats the use of such kind of class which can not be inherited neither instantiated.
Many times we do not want to create instances of certain classes like utility , common routine classes. Rather than calling as shown below

clsCommon common = new clsCommon();
common.CheckDate("1/1/2011");

You would like to call it as

clsCommon.CheckDate("1/1/2011");
Check my 21 important .NET interview questions and answers

Thursday, March 3, 2011

C# interview questions :- What are the benefits of three tier architecture ?

C# interview questions :- What are the benefits of three tier architecture ?


Answer:

This is a very popular c# interview question. In 3 tier architecture / layer we divide the project in to 3 layers UI , Middle and DAL. Due the modular approach we have 2 big advantages
Reusability :- You can reuse the middle layer with different user interfaces like ASP.NET , windows etc. You can also reuse you DAL with different projects.

Maintainability :- When we change in one layer due to the modular approach it does not have ripple effect on other layers. we have to do less amount of changes in other layer when we change logic of one layer.


Regards,

See my most important c# interview questions and answers

.NET Interview question :- What coding standards did you followed your projects ?

.NET Interview question :- What coding standards did you followed your projects ?



Answer:
This is a very general .NET interview question.

Normally properly planned companies have a checklist of what kind of naming convention to follow. In .NET interview its very difficult to speak about the whole checklist as we have limited time.

The expectation of the interviewer is that you should speak about pascal,camel and hungarian naming conventions and where did you use what. So below goes a short answer.
Our organization had a naming convention document which was supposed to be followed by all projects in the organization. As per the document we where using three types of naming conventions across the project :- Pascal , Camel and Hungarian.
All class names , function names , method names , namespace names where using pascal convention. i.e. the first letter capital with every first word capital.ex CustomerCode
All variables , input/output variable , local variables , class level variable , global variables where using Camel notation. i.e. the first letter small and then the first letter of the subsequent words capital.ex count , customerData
For the UI object we where using hungarian notation. In this the prefix defines the datatypes i.e. txtCode , cmbCountries.
For database we used Hungarian notation where the prefix defines the data base object types. i.e. tblCustomer , uspSelectCustomer,fngetValue,trgInsert.
Regards,

Check out my 22 top .NET interview questions and answers

Wednesday, March 2, 2011

C# Interview question :- Can you explain difference between Pascal notation, Camel notation and hungarian notation ?

C# Interview question :- Can you explain difference between Pascal notation, Camel notation and hungarian notation ?

Answer:

The above c# interview question is asked to ensure if you have used coding standards in your project. All the above 3 things are nothing but naming conventions which are followed in programming languages to ensure a clean code. Below is the explanation of each naming convention.
Pascal Notation- In this naming convention all starting letter of the words are in Upper Case and other characters are lower case.
Example: SupplierCode
Camel Notation- In this naming convention first character of all words, except the first word are Upper Case and other characters are lower case.
Example: supplierCode
Hungarian Notation - In this naming convention the variable name starts with group of small letter which indicate data type.
Example: bLoop ( b indicates its a Boolean type), Sum ( i indicated its a integer data type).
Regards,

See our 21 important interview questions at c# interview questions and answers

Tuesday, March 1, 2011

.NET interview question :- Who is faster hashtable or dictionary ?

.NET interview question :- Who is faster hashtable or dictionary ?


Answer:
This is again a typical collection .NET interview question. Dictionary is faster than hashtable as dictionary is a generic strong type. Hashtable is slower as it takes object as data type which leads to boxing and unboxing.

Below goes the same code for hashtable and dictionary.

Hashtable hashtable = new Hashtable();
hashtable[1] = "One";
hashtable[2] = "Two";
hashtable[13] = "Thirteen";

var dictionary = new Dictionary<string, int>();
dictionary.Add(i.ToString("00000"), 10);
dictionary.Add(i.ToString("00000"), 11);

See my top .NET interview questions and answers