Wednesday, September 9, 2009

SharePoint Interview Questions - Part 2

Introduction

This article is the Part 2 of the SharePoint. Please feel free to download my free 500 question and answer ebook which covers .NET, ASP.NET, SQL Server, WCF, WPF, WWF @ http://www.questpond.com/

SharePoint Quick Start FAQ Part 2

Pre-requisite
You need to read the previous article to understand the basics

In the previous session of SharePoint article we had discussed about the basics of SharePoint. In this session we will:-
• create site / site collection
• Understand the ready made functional reusable modules
• Learn how we can display a simple page and later apply master pages of SharePoint.
• Host a Inline code and behind code page in SharePoint
• Understand the concept of features and understand step by step how to enable / disable a feature
• How do display a feature in Admin

How can I create my first site in SharePoint?

When you want to create any site in SharePoint we need to prepare a site collection and define site inside the site collection. Ok, that’s a simple four step procedure and can be easily achieved by using the SharePoint central administration.

Step 1:- Click on start and you should find the SharePoint central administration menu.


Step 2:- Once you click on the central administration menu you need to click on the ‘application management’ tab and then click ‘Create site collection’.
Step 3:- Once you click ‘Create site collection’ you should see a form which needs all necessary details to create a site. All details are almost self-understandable. We have just stressed on three points one is the site name, the other is a template and the last is the username in which SharePoint will run. All sites in SharePoint need to be inherited from some master they can not stand on their own.

Step 4:- Once you have clicked ‘Ok’ you can now run the URL with your SharePoint name you should see something as shown below. As we have created from a blank site currently we do not have anything. Below is how a blank site looks like.


What is Quick Launch menu?

Below figure shows what is the quick launch menu. In this question we just wanted to make sure you know the terminology and where it maps to. In the further section we will be using this terminology for the left hand menu shown in the figure below.

We have heard that we can customize SharePoint sites how do we do that?
We will continue with the same example of our blank site which we discussed previously. On the left hand side corner you will see a site actions menu. So click on the site action menu and click on site settings menu link. Once you click on the link you will be popped with different settings by which you can do customization. We will not discuss right now what every setting is, but in the later section we will understand some important settings by which we can achieve customization.

To increase your confidence you can play around with the ‘Look and feel’ settings. But this will be the landing page when we want to implement customization in SharePoint.


We have heard it has ready made functional modules for collaboration?
Oh, yes you have heard it loud, right and clear. The best part about SharePoint is collaboration. Collaboration has four major entities people, task, data and communication.
So below are some key points of enterprise:-
• We have people in our organizations.
• People are assigned task.
• To complete task we need to exchange data.
• We also need to plan/monitor tasks.
• To communicate data we need a communication channel like email, WIKI etc.

SharePoint has lot of ready made function which can help us to accommodate all the requirements of collaboration. To see those ready made functionalities click on site actions and click on create. You will be popped with a list of reusable functionality page which you can pick up and achieve collaboration.
Now let’s map the ready made functionalities with collaboration requirements.


How can we enable these reusable components in my site?

Ok, now that we are familiar with the reusable components and how they map to the collaboration requirements. Its time add one reusable functionality in your website. We will add a link inside the documents menu called as ‘SharePoint tutorial’. In this section team can upload tutorials for SharePoint in word document format. It’s a simple three step process so let’s understand the same step by step.
Step 1:- Click on the site actions and click on create link from the menu. You will be displayed reusable functionalities provided by SharePoint. Select ‘Document library’ from the libraries section.
Step 2 :- Give the link name as ‘SharePoint tutorial’ and select document types to be unloaded as word format. For this you need to select the document template to be of type ‘Microsoft word’.
Step 3:- Bravo! You can now see the SharePoint tutorial link and you can click on upload to push in a word document inside this library collection.

You can see from the figure below how we have uploaded a word document i.e. “SharePoint tutorial”. You can right click and experiment with more functionalities like check out , versioning , workflow , send alerts when document is modified etc etc.
Note: - You can try adding other functionalities like WIKI, announcement board, picture library and lot more. So feel free to experiment and see how you can easily leverage the reusable functionalities to meet the collaboration requirements.

How can we display a simple custom page in SharePoint?


Ok first thing there is no concept of simple page in SharePoint. There are two types of pages in SharePoint as we discussed in the previous article one is an Application page and the other is the site page.
Application page is a generic page while site pages are custom to a website. To just cool you off lets display a simple Application page first.
Some points to be noted about Application pages:-
• They are pages which are shared across sites like ‘settings.aspx’ , which will helps us set generic properties across sites in a site collection.
• The second important part is that we need to save application pages in ‘C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS’ folder. If you browse to the folder you will find SharePoint’s own application pages.

Ok, what we will do is that to build confidence let’s make a simple page called as ‘SimplePage.aspx’. We are not doing anything great in this we will just write this simple sentence inside the page.
 Ohhhh I never Knew SharePoint is so easy 
Once you have saved the page just browse to the IIS application and browse to the _layouts folder as shown in the figure below. If you open the page in browser you should see your display message.
Note: - For the next question you need to understand the concept of master pages. If you have not please read it once. Consistent look and feel is one of the most important factor in enterprise portal and SharePoint achieves the same using Master pages.

The above page does not look like a standard SharePoint page?

In order to get the SharePoint look and feel we need to inherit from a SharePoint master page. As a rule you should always inherit from a SharePoint master page so that your sites have a consistent look and feel. So let’s modify our ‘SimplePage.aspx’. To get the SharePoint style we need to inherit from the SharePoint master page ‘Application.Master’.

We have now tailored the ‘simplepage.aspx’ source code as shown below. We need to do the following:-
• First refer the assembly using the ‘Assembly directive.
• Refer the masterpage files as ‘Application.master’.
• Import the sharepoint namespace. If we had used the behind code we would have imported this in the behind code itself.
• There are three placeholder one for title , one for centre area and one for the page title. We need to define the placeholders in the child page.

<!— First refer the assembly using the Assembly directive ->
<%@ Assembly Name="Microsoft.SharePoint,Version=12.0.0.0, Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>

<!— Refer the master page from the _layouts directory ->
<%@ Page Language="C#" MasterPageFile="~/_layouts/application.master"
Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase" %>

<!—Import the sharepoint namespace ->
<%@ Import Namespace="Microsoft.SharePoint" %>

<!—This is the content holder for page title ->
<asp:Content ID="Content3" ContentPlaceHolderId="PlaceHolderPageTitle" runat="server">
Let's learn SharePoint....
</asp:Content>

<!- This is the place holder for data for main page area ->
<asp:Content ID="Content1" ContentPlaceHolderId="PlaceHolderMain" runat="server">
Oh its Damn Simple.....
</asp:Content>

<!- This is the placeholder for page title area ->
<asp:Content ID="Content2" ContentPlaceHolderId="PlaceHolderPageTitleInTitleArea" runat="server">
SharePoint is Simple.....
</asp:Content>



LOL !...Your SharePoint page now looks like a page.

You can get the source of the simple inline ASPX file attached at the end of the article.

Above code is completely inline, how can we implement behind code in SharePoint?

Some couple of points we need to take care regarding implementing behind code in ASP.NET are the following:-

• The first and foremost requirement is that behind code should be registered in to the GAC assembly. In other words we need to code the behind code in a separate assembly / namespace and then compile the same in a DLL. Later we need to register the DLL in GAC.
• Second we need to use the assembly directive to refer the behind code.

Step 1:- So the first step is to make two solution files one is the behind code which goes in separate assembly ‘ClassLibrary1’ namespace and the other is the ASP.NET web project which has the ‘SimplePageCodeBehind.aspx’. We also need to register this DLL in a GAC. So you need to generate a strong name give to the assembly and register the same using the ‘GACUTIL’ provided by the .NET framework.


Step 2:- The behind code is in a separate assembly as need to register the same in the GAC. We have kept the behind code simple. We have create two label objects and set the value. One of the important points to be noted is that we have referenced the ‘System.Web.UI’ namespace DLL and ‘Microsoft.SharePoint’ namespace DLL. The other point to be noted is that the class inherits from ‘LayoutsPageBase’ class which belongs to ‘Microsoft.SharePoint’ namespace.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;

// need to refer the UI objects of ASP.NET
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

// Need to refer the SharePoint DLL
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace ClassLibrary1
{

// Inherit the behind code from ‘LayoutsPageBase’ class of SharePoint

public partial class _Default : LayoutsPageBase
{

protected Label lblSiteQuestion;
protected Label lblSiteAnswer;

protected override void OnLoad(EventArgs e)
{
lblSiteQuestion.Text = " How can we implement behind code in SharePoint ?";
lblSiteAnswer.Text = " We need to register the behind DLL in GAC";
}
}
}



We need to also register the above DLL in GAC. So we need to generate a strong name and register the same using GACUTIL.

Step 3:- Now comes the UI part of the ASP.NET i.e. the ASPX page. Below is the code snippet which shows how the ASP.NET UI looks like.

The first thing to note is that behind code is not referred as code behind but is referred using the GAC public token key. In order to refer it using GAC key we need to use the ‘Assembly’ attribute for the same.

We have also inherited from the master page file i.e. ‘Application.Master’ so that we have a consistent look and feel.



<!—Refer the sharepoint assembly ->

<%@ Assembly Name="Microsoft.SharePoint,Version=12.0.0.0, Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>

<!—Refer the behind code, Note that the behind code is coded in a different assembly and registered in the GAC -> 

<%@ Assembly Name="ClassLibrary1, Version=1.0.0.0, Culture=neutral,PublicKeyToken=af6d081bf267e17e" %>

<!— In order to maintain consistent look and feel we need to inherit from the Application.Master page ->

<%@ Page Language="C#" MasterPageFile="~/_layouts/application.master" Inherits="ClassLibrary1._Default" EnableViewState="false" EnableViewStateMac="false" %>



Once we have referred the Assembly and set the Page attributes. Its time to fill the content in the placeholders defined in the master page ‘Application.Master’.


<asp:Content ID="Main" contentplaceholderid="PlaceHolderMain" runat="server">
<table border="1" cellpadding="4" cellspacing="0" style="font-size:12">
<tr>
<td>Question</td>
<td><b><asp:Label ID="lblSiteQuestion" runat="server" /></b></td>
</tr>
<tr>
<td>Answer</td>
<td><asp:Label ID="lblSiteAnswer" runat="server" /></td>
</tr>
</table>
</asp:Content>

<asp:Content ID="PageTitle" runat="server"
contentplaceholderid="PlaceHolderPageTitle" >
SharePoint Behind code implementation
</asp:Content>

<asp:Content ID="PageTitleInTitleArea" runat="server"
contentplaceholderid="PlaceHolderPageTitleInTitleArea" >
When we want to implement behind code we need to register the same in GAC.
</asp:Content>





Note: - Do not try to compile the project in VS.NET IDE. You can only compile the class assembly. The ASPX file you need to later paste it to the ‘_layout’ directory i.e. ‘C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS’.

Once you have copied the ASPX file and registered the behind code assembly in GAC, you can run and enjoy how it looks like.

If you are thinking that behind code pages implementation is lot of pain in SharePoint. Hang on as we move ahead you will see better way of implementation. Second we can not rule out the benefits as compared to the pain incurred in implementing behind code pages in ASP.NET.

What is the concept of features in SharePoint?

Whenever we think about SharePoint think in terms of collaboration. One of the much needed features in collaboration is on-demand functionality / feature activation. Feature makes it easier to activate and deactivate functionality in SharePoint.

Some points which you should note about features:-
• All features needs to be copied in “C:\Program Files\Common Files\Microsoft Shared\Web server extensions\12\Template\FEATURES\” directory. Microsoft Share reads the features from this directory. If you open the directory you can find pre-installed features by Share Point as shown below.


• Every feature will have two XML files one is the ‘Feature.xml’ and the other is ‘ElementManifest.xml’.

• Share point understands there is a feature by reading the feature XML file from the features folder.
• All features are identified by a unique GUID number.
• Features emit events which can be captured to write custom code. These events are captured in assembly which needs to be registered in a GAC.
kya
• Summarizing what we discussed we have a ‘feature.xml’ which points to an assembly which captures the feature events for custom code. It also other XML file which defines what exactly this feature will do.


Can you explain the broader steps for deploying / activating a feature?

In order to understand the feature concepts lets deploy the simple application page i.e. ‘SimplePageCodeBehind.aspx’ as feature. So when the user activates this feature he will be able to browse the ‘SimplePageCodeBehind.aspx’.

Step 1:- Let’s create a project ‘SharePointFeature’. You can find the source code of the same attached with this article. So below is the project tree which has the two XML files and a class file which will process the four events i.e. ‘FeatureInstalled’,’FeaturesUnInstalling’ , ‘FeatureActivated’ and ‘FeatureDeactivating’.


Let’s understand these three files first.
Feature.XML :- This is the most important file because it helps SharePoint identify the feature. All features in SharePoint are identified by the GUID key.

<Feature Id="48DEF2C4-33F9-4885-B0DE-6FE82E9FDCD8"
Title="Go to Custom Pages"
Description="This features enables us to goto Custom Page"
Scope="Web"
Hidden="FALSE"
ImageUrl="menuprofile.gif"
ReceiverAssembly="SharePointFeature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=af83741e324f585c"
ReceiverClass="SharePointFeature.clsFeatureReceiver"
xmlns="http://schemas.microsoft.com/sharepoint/" >
<ElementManifests>
<ElementManifest Location="ElementManifest.xml" />
</ElementManifests>
</Feature>





To generate a new GUID click on Tools à Create GUID and click ‘New GUID’. Tools menu you will get from within the IDE. We have marked the GUID value which you need to copy and paste in the ‘feature.xml ‘file.


Other than feature description and title there are two important things in the XML file. The first it points towards some other XML file and second it points to an assembly which captures events.
ElementManifest.XML file :- ElementManifest.xml file actually specifies how the implementation will look like. There are two important points to be noted for the ElementManiFest.XML file. The custom action tag specifies on which control the feature will be activated. The control we are targeting at this moment is the ‘SiteActionsToolBar’. This tool bar is the one which you see on the right hand side corner of your SharePoint portal. There is also a URLaction property which specifies which URL it redirect to.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="SiteActionsToolbar"
GroupId="SiteActions"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="10"
Title="Display Custom Pages"
Description="This links helps to display Custom Page"
ImageUrl="_layouts/SharePoint2/menuprofile.gif">
<UrlAction Url="_layouts/SimplePageCodeBehind.aspx"/>
</CustomAction>
</Elements>




In other words ‘ElementManifest.xml’ specifies the location of the feature and which page it should redirect to.

FeatureReceiver.cs :- This class listens and implements custom actions of the feature.

We need to first refer the share point namespace as shown in the below code snippet.

using System;
using System.Collections.Generic;
using System.Text;
// Refer the SharePoint namespace
using Microsoft.SharePoint;





We need to implement the ‘SPFeatureReceiver’ class and implement all the events.


namespace SharePointFeature
{
// Inherit from the 'SPFeatureReceiver" class
public class clsFeatureReceiver : SPFeatureReceiver
{
// Implement the four events of SPFeatureReceiver class
public override void FeatureInstalled(SPFeatureReceiverProperties properties){}
public override void FeatureUninstalling(SPFeatureReceiverProperties properties) { }
// This event fires when the feature is activated
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
....
....
....
....
}
// This event fires when the feature is deactivated
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
....
....
....
...
}
}
}





As a sample in the ‘FeatureActivated’ event we have set the description and title of the website.



public override void FeatureActivated(SPFeatureReceiverProperties properties)
{

// get the object of SharePoint Web
SPWeb site = (SPWeb)properties.Feature.Parent;
// Set the description ,properties , titile and update the SpWeb object
site.Description = "Click on the SiteActions to See how the custom page display";
site.Properties["OriginalTitle"] = "Display CustomPage";
site.Properties.Update();
site.Title = "This Site now has the custom page display";
site.Update();
}




In ‘FeatureDeactivating’ we have reverted back the title and description.



public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
// Get hold of the SharePoint web object and reset back the values
SPWeb site = (SPWeb)properties.Feature.Parent;
site.Description = "Custom Page display is disabled";
site.Title = site.Properties["OriginalTitle"];
site.Update();
}

Step 2 :- We need to register the compiled assembly in GAC and provide the token value in the ‘Feature.XML’ file. You need to use GACUTIL to register. You can get the token by browsing to ‘c:\Windows\Assembly’ and then viewing the properties of the assembly.



Step 3:- Copy the two XML file i.e. ‘Feature.xml’ and ‘ElementManisfest.xml’ in the ‘C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\DisplayCustomPage’ directory.


Step 4:- Now we need to install the feature using STSADM.exe. So go to dos prompt à and go to ‘C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN’ directory.

>cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN
To install the feature run the below command using ‘STSADM’. Please note that you need to specify the relative directory path and not the physical path of ‘Feature.xml’ file.

>stsadm -o installfeature -filename DisplayCustomPage\Feature.xml

To ensure that SharePoint registers about this feature run IISRESET on the machine.

Step 5:- Now click on the Site Action à Site Settings à Site Features and Activate the feature.


Now you can see your feature enabled in the site actions menu. If you click on the feature i.e ‘Display Custom Pages’ it will redirect you to ‘SimplePageCodeBehind.aspx’.

The other point to be noted is that the events have fired and set the title and description as described in the code.

Try to experiment and deactivate the feature and you will see the title and description changing.
Note: - You can get the source for the feature in the ZIP file provided with the article


I want that the feature should be only displayed to admin?

If you want only administrators to view the features set RequireSiteAdministrator="True" as shown in the below ‘ElementManifest.XML’ file.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="SiteActionsToolbar"
GroupId="SiteActions"
RequireSiteAdministrator="True"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="10"
Title="Display Custom Pages"
Description="This links helps to display Custom Page"
ImageUrl="_layouts/SharePoint2/menuprofile.gif">
<UrlAction Url="_layouts/SimplePageCodeBehind.aspx"/>
</CustomAction>
</Elements>

Source code

The source code has the following things:-
• Simple SharePoint behind code.
• Inline Share Point behind code
• SharePoint feature code

Download The Source Code Click here

SharePoint Interview Questions - Part 1

Introduction

This article is the Part 1 of the SharePoint. Please feel free to download my free 500
question and answer ebook which covers .NET, ASP.NET, SQL Server, WCF, WPF,
WWF @ http://www.questpond.com/

You can visit and download the complete architecture Interview questions PDF
which covers SOA, UML, Design patterns, Togaf, OOPs etc

Happy job hunting......


SharePoint Interview Questions Part 1

What is SharePoint?

Share point helps team members to connect and exchange information in a collaborative manner. It helps to centralize enterprise information for efficient functioning. For instance below is how a normal organization works. Files and documents scattered in individual PC and data is transported according to custom protocols. The communication protocol for sending these data is also person dependent. Some body would use a email , some body would share a drive etc etc.


Share point unites all the documents in to one centralize place and unifies the data transport mechanism. In one words a central enterprise information portal.



What is WSS and MOSS?

Microsoft has divided share point products in two parts. One is called as WSS (Windows SharePoint services) and the other is MOSS (Microsoft Office SharePoint server). WSS is the platform on which MOSS is built. The WSS part is licensed through Windows 2003 server and it does not cost. MOSS is separate product by itself and it needs licensing and it has a good amount of cost J . WSS is good for small team and small projects. MOSS has extra functionalities in other words value added services. So the choice between WSS and MOSS will depend on budget of the project and the VAS provided by MOSS.


How does WSS actually work?

WSS does not work in an isolated fashion. It needs help of two more products IIS (Internet Information Server) and SQL Server.

How does WSS work with IIS?


In order to understand how WSS works with IIS we need first understand the concept of “HttpHandlers and HttpModules”.

Using the HttpHandlers and HttpModules request is first passed through the Share Point runtime and then passed to the ASP.NET runtime (aspnet_isapi.dll).

If you open the web.config file of a WSS enabled IIS web application you can see the application run time handlers and modules.

We have highlighted the application runtime module.

What is site and site collection?


Share point is all about enterprise data. When we talk about enterprise data it looks some as shown in the figure below. In other words grouping and sub groupings of data.
SharePoint extends the IIS web application structure to accommodate the above defined data structure using site and site collections. We will see in the later section how to create site collections.

What is the main advantage of using site collections?
As said previously SharePoint is all about data and data should properly authenticated / authorized to proper users. By defining the structure in site and site collection we can now define roles and responsibilities according to data. For instance in the above figure we will assign all HR user to payroll, recruitment and assessment site. These users will not be assigned to account site collection. Same holds true for accounts user.

So when you design your hierarchy of site and site collection you need to keep in mind the enterprise hierarchy structure and design the same accordingly.

What is the use of SQL Server in share point?


SQL Server is used to store content and configuration information. We have two types of databases one is the content database and the other is the configuration database. We had said previously that content is according to every site. So every site has his own content database. For instance if we have a payroll site and recruitment site they have their own content database. Configuration database is for the entire site as they are used in web farms, site configuration and lot of other things which are generic and common across all the sites.
What is the concept of virtual path provider?

Any project has two parts one is the standard and common part and the other is the customized version. In ASP.NET we have two types of pages for any project one is common ASPX pages and the other is customized ASPX pages. Common pages are stored on file directories while customized versions of pages are stored in content database.
So in other words we need an abstract mechanism by which we can render pages from SQL Server content database and also from the virtual directories. This is achieved by using the virtual provider provided by SharePoint. So for all customized pages virtual provider reads from the content database and passes the same to the ASP.NET runtimes. For all common pages it goes to the directory, parses it and the passes the same across to the ASP.NET runtime.

Virtual provider is an abstraction which loads the page from the content or the file system depending on whether it’s customized or common pages and passes the same to the ASP.NET runtime.

What is the concept of ghosting and unghosting in SharePoint?
In SharePoint most of the site pages derive from templates. The custom pages only store the difference between them. The template is loaded in memory and applied to the custom pages on fly. In other words the template is stored in a cache. This definitely brings in performance and flexibility. Flexibility is in terms that when we change the template page it’s applied to all custom pages. These pages are loaded from the file system. So pages which are loaded from the file system are termed as ghosted pages.

If the page data is loaded from the content database it’s termed as unghosted pages.

As a note let me clarify the concept of document and content table as we are already trying to understand the concept of ghosting and unghosting. As we know that SharePoint stores all pages in the database. Looking from a 50,000 feet it has two tables one is the document table which has the entry of page and the other is the content which has the source code of the ASPX page.

So when a page is requested it first checks in the document table and then goes to the content table to load the page. If it does not find data of the page it goes to the file directory to load the page. This loading is done by ASP.NET runtime himself. But if there is data present in the content table then it’s loaded by the ‘safe mode’ parser.



What is the concept of safemodeparser in ASP.NET?As said the previous section there are two tables one is the document and the other content. If the page is stored in the content database it’s loaded by the SafeModeParser which is page parser provided by SharePoint. If there is no data found in the content it’s loaded from the file directory by simple ASP.NET runtime.
What is the concept of Site pages and Application pages?

Site pages are customized pages and are saved in to content database. So when you use the SharePoint designer to make custom changes it saves the changes in to content database. If you want to make generic pages in a site collection which will be used by every one, like for instance the ‘Settings.aspx’ page then you need to use application pages.

In other words Site pages are nothing but customized pages stored in content, while application pages are generic pages which will be used by all the sites in a site collection.

What Next?
In Part 2 we will try to get hands on share point, create site collections, create application pages and understand the concept of features.



UML Interview Questions - Part 2

Introduction

This article is the Part 2 of the UML. Please feel free to download my free 500
question and answer ebook which covers .NET, ASP.NET, SQL Server, WCF, WPF,
WWF @
http://www.questpond.com/

You can visit and download the complete architecture Interview questions PDF
which covers SOA, UML, Design patterns, Togaf, OOPs etc

Happy job hunting......

Unified modeling language ( UML ) interview questions part 2

(I) Can you explain collaboration diagrams ?
(I) Can you explain activity diagrams?
(I) What is state chart diagram?
(I) Can you explain stereotypes in UML?
(I) Can you explain package diagrams?
(B) Can you explain component diagrams?
(B) Can you explain deployment diagrams?
(I) Can you explain how UML flows in actual project?

(I) Can you explain collaboration diagrams ?

Collaboration diagrams
Collaboration diagrams provide the same information as shown by sequence diagram but they show it in a different way. In sequence diagram we pay more attention to the time and sequence order, but in collaboration diagram we pay more emphasis on the interaction messages between the objects.

Figure ‘Collaboration diagrams’ shows how a collaboration diagram looks like. Below are some points you can easily pick up looking at the figure:-
• Objects are represented in rectangle.
• Messages are represented by an arrow and sequence number. For instance in figure ‘collaboration diagrams’ we can see the ‘order product’ has a arrow which shows that the message is sent from the customer object to the product and ‘1’ represents that it’s the first messages.
• Conditional statements are denoted by square brackets ‘[‘.
• We can also group sequence numbers by grouping them using decimals. For instance ‘Pay by master’ and ‘Pay by Visa’ are all grouped in to message sequence number ‘3’ (‘Do payment’). So they are denoted by 3,3.1 and 3.2 respectively.
Figure: - Collaboration diagrams
You can represent the for each loop using the ‘for each’ keyword as shown in below figure ‘for each in collaboration’.
Figure: - For each in collaboration
Note: - Try drawing a collaboration diagram for the same voucher data entry screen. Sequence and collaboration diagrams are also called as iteraction diagrams.

(I) Can you explain activity diagrams?

Activity diagrams
Activity diagram are used to capture complicated process flows in a system. Below figure ‘Activity’ shows a simple activity diagram. Some of the points which you can easily note from the activity diagram figure are:-

• Start of an activity is denoted by a dark circle.
• End of an activity is denoted by a dark circle inside a white circle.
• Activities are denoted by simple oval rectangles.

Figure: - Activity
A decision in activity diagram is as shown figure ‘Decision in Activity Diagram’. Figure shows the condition in a ‘[‘ (Square bracket). So the first activity is ‘Check Age’, if the age is greater than 16 then we can go for ‘Adult Movie’ activity or else we need to execute the ‘Kids Movie’ activity.

Figure: - Decision in Activity Diagram
There are situations in project where we need to execute two parallel activities in a project. A solid bold line represents from where the activities will split and execute in parallel and then again a solid line is where the parallel activities will meet. For instance in the below figure ‘Parallel Processing’ we can see how ‘Make lemon juice’ and ‘Make Ginger Juice’ activities are executed in parallel.

Figure: - Parallel Processing
In big and complex activity diagrams it’s very difficult to figure out which object is responsible for which activities. This problem is solved by ‘Swimlanes’. Consider the below figure ‘Without Swimlanes’. The whole activity diagram looks very complex and it’s very difficult to figure out which object is responsible for which activity.
Figure: - Without Swimlanes
Now see the below figure ‘With Swimlanes’ we have partitioned the activity to the respective objects like Customer, Stock, Order processing, Payment and Invoice. These partitions are termed as ‘Swimlanes’ , so if you feel that the activity diagram is complex think about using ‘Swimlanes’ it can really make your activity diagram readable.
Figure: - With Swimlanes

(I) What is state chart diagram?

State Chart Diagram

State diagram depicts different states that an object goes through during their life cycle. State diagram depicts how an object responds to events. We think state diagrams as optional and should be used if your project has scenarios where the object goes through lot of complicated states and transitions. If your project does not have such kind of scenarios then sequence, collaboration or activity would be sufficient to meet your needs. So all objects have states and an object moves from one state to other state when there is some event or transition.

There are three important things when we consider state of an object event, guard and action. Let’s first define these three things: - .

Action: - Action triggers an object state from one state to another.

Event: - Event triggers the action.

Guard: - Guard is condition on which it evaluates which action to be triggered.

These three things are principle component of state chart diagrams. Below figure ‘Types of event and action’ shows how they are represented in state chart diagrams.

Figure: - Types of Event and Action
There are three ways by which we can represent the same.

Type 1:- This methodology of writing is used when we need to map an event with action using a guard. For instance in the above figure ‘Types of Event and Action’ shows the event à mouse click, guard à double click and the resulting action à open folder.

Type 2:- The guard is optional. For instance sometimes we only have events and actions, i.e. with out the guard. For instance when the even ‘On’ happens the action is that ‘Light Bulb is on’.

Type 3:- This type of representation shows an infinite loop for an action. For instance the ‘Watch will be running’ infinitely during a state, as shown in figure ‘Type of Event and Action’.

Now that we know how to write event, actions and guard, let’s see how state diagram looks like. Below figure ‘State example’ shows how a state looks like. It’s an oval rectangle as shown below. In order to show a transition we need to show an arrow from one state to other state as shown in figure ‘State example’.

Figure: - State example
Below figure ‘Sample state chart’ shows a simple state chart diagram. Some points which are immediately visible from the diagrams are as follows:-

• A dark black arrow indicates start of a state chart diagram.
• A dark circle with a white circle outside indicates end of a state chart diagram.
• Circular rectangle indicates state while arrows indicate events / transitions.

Figure: - Sample state chart
State is represented as shown in figure ‘Basic element of state diagram’. It’s a simple rectangle which is rounded. In the top section we give the state name. The below section is optional which has ‘do/action’. It represents a long running activity when the object goes through this state.

(I) Can you explain stereotypes in UML?

Stereotypes are a way to define variations on existing UML model. This variation is brought in to place to extend UML in a consistent manner. They are displayed in double less than and double greater than sign with a simple text as shown below. The below figure shows at the left hand side a class diagram with out stereo types while the right hand side shows with stereo types. You can easily make out how the class diagram is readable with stereo types. For instance the ‘Customer()’ can be mistaken for a method but we have clarified that it’s a constructor by using stereo types.
Figure: - Stereotypes
Below are some of the commonly used stereo types while writing UML.

<<Application>>:- Used to represent a UI system in a application.
<<Database>> :- represents a database in a application.
<<Table>> :- A table with in database.
<<Library>> :- A reusable library or function.
<<File>> :- Physical file on a folder.
<<Executable>> :- A software component which can be executed.
<<Web services>> :- Represents a web service.
<<JDBC>> :- Java database connectivity , a JAVA API to connect to database.
<<ODBC>> :- Open database connectivity , a Microsoft API to connect to database.

(I) Can you explain package diagrams?

Packages are like folders in a system which allows you to logically group UML diagrams. They make complex UML diagram readable. In actual projects they are used to logically group use cases and classes. So we can say there are two types of package diagrams one is class package diagram and other is use case package diagram. Package diagram depict a high level of overview for class and use cases.

Class package diagram: - Class package diagram are used to logical group classes. You can think that package technically map to ‘Package’ in JAVA and ‘Namespaces’ in C# and VB.NET. Packages are denoted by small rectangle on a big rectangle as shown in figure ‘Package diagram’. One of the points to be noted is the stereotypes. We have numbered the figure so that we can understand it better.

1 – We are using the MVC (Model View controller) framework. So we have denoted this package using the << Framework >> stereo type. Refer the commonly used stereo type table discussed in the previous sections.

2 and 3 – ‘Book tickets’ is the second package which inherits from the MVC model. The stereo type is ‘<<application>>’ which means it’s a user interface.

4 – A simple line shows a link between two classes stating that one class package uses the other class package.

5 – This package is collection of the booking engine library.

6 – The final package is the database.

Figure: - Package diagram
As said before packages are nothing but collection of logical classes or any UML entity. We have shown the detail of the above package diagram. We should restrict from using package diagram for showing the in depth architecture as it can become very complicated. For instance the below diagram ‘Detail Package diagram’ shows how complicated it can look if use the package diagram to show in depth architecture. To avoid complication its good to only draw an over all diagram as shown in ‘Package diagram’.
Figure: - Detail Package diagram
Use case package diagram: - The way we have logically grouped classes we can also use the package diagram to logically group use cases. Below figure shows how a use case package diagram looks like.
Figure: - Use Case Package

(B) Can you explain component diagrams?

Component diagrams achieve the same objective like package diagrams. They show the dependencies among software components. Below figure ‘Component diagram’ shows a sample component diagram for simple data entry application which uses a web service to interact with the database. We have numbered the steps to understand the details of the component diagram.

1 – Two rectangles are shown to represent a component of a system.
2 – Stereo types are used to denote what kind of system it represents.
3 – A line with a circle denotes an interface by which the external world can interact with the component. For instance in the figure we have represented a ‘Customer Web service’ which can is interacted by using XML.

Figure: - Component Diagram

(B) Can you explain deployment diagrams?

Deployment diagrams represents an overall static view of how software and hardware nodes in the application. They show what the hardware is and which components are installed on which hardware. In deployment diagram we represent the hardware with a solid box and simple underlined text description showing which hardware is it. You can have more than one component on a single hardware. So the browser is an application UI which resides on the workstation computer and the database and web server resides on the web server hardware. Deployment diagram can be more complex with firewalls, payment gateways, PDA devices, VPN etc.
Figure: - Deployment diagram

(I) Can you explain how UML flows in actual project?

In actual projects we do not draw all the diagrams. Every UML diagram is made for a purpose. It completely depends on what’s the nature of the project. In short you should ask yourself questions like, is this diagram important, what’s my need etc. So below is a flow which you can follow in your project, again as we said it depends on what kind of scenario you want to depict.
Figure: - UML flow in actual projects
• The first step is to derive use cases from the requirement documents.
• Once use cases are derived we need to decide the messages which will flow in the system. This can be done using interaction diagrams. If you need to know the object creation life times we use the sequence diagram and if we want to concentrate on the messages we use the collaboration diagrams. So depending on scenario we need to make a choice which diagram we need to draw.
• Now that we are clear about messages we can draw class diagrams to depict the static part of the project i.e. classes.
• If we find any complicated class relationships we draw object diagrams.
• If we need to depict any complicated code we need to represent same with a activity diagram.
• Finally to give an overview of the project we can use package diagram, component or deployment diagram. As said before we can use combination of component and deployment diagram to give a overview of the architecture.

Note: - Never say in a interview that we have used all UML diagrams in the technical document. It can give a very bad impression. As said every UML diagram is drawn according to the scenario of the project.

Other Interview question PDF's