11 February, 2009

Getting Started on your First Web Page

Creating your first web page can be a daunting and confusing task. Where do I get started? What should I do? However, it does not have to be this way, creating a web page can be a fun and rewarding experience if you just follow a few simple guidelines, which we will outline for you here.

The first thing that you should do when getting ready to construct your first web page is to define it. What do you want your web page to do? Do not just start constructing your page, really think about it. You should think about how you want it to look, what information you want to provide to your prospective customer in order to persuade him to buy your product or service rather than going elsewhere.

Be sure that you organize the page well, think of your Home Page like the Table of Contents page in a book, it is there so that your customers know where to go in your site for their particular needs, or just to familiarize themselves with your product. Lastly, when defining your site you should do your research. Always visit your competitions web site to see how they have organized their site, so you can make yours better, whether it is just including more information about your product, or simply making a better designed site.

Now that you have given some serious thought to how you want your web site to look, and what you want to include in it, you need to think of a name for it. There are various approaches to finding the right name for your web site. The first is to make the name logical, for instance, ****’s web site is ****.com. Another approach is to make the name memorable so that your customers can type it in without thought, the name does not have to be descriptive of the product you sell, for example amazon.com sells books. Further, you should keep the name as short as possible so that it is easy for your customers to type into the url field.

Now that you have your web page named and given some thought into how you want it to look, here are some pointers for building your site. If you have pictures on your web page go over them first with a photo editing program so that the customer’s browser does not have to crunch them. This will also speed up the download speed of your page so that the customer can view quickly without having to wait for large picture files to appear on the screen.

One of the most annoying things for people surfing the web are pages that take a long time to download. All those fancy graphics will not do you any good if instead of waiting for the page to download the viewer closes his browser and goes elsewhere, so consider going light on the pictures and heavy on the information content.

You should also put some serious thought into what color fonts you are going to use, and the background color as well. When in doubt, remember that a white background with black text has been successful for thousands of years!

Your website should also be easy to navigate, all your links should be obvious to the viewer, and should be self explanatory or have information about where the link will take them. Try to keep the number of links you have low, the viewer does not want to spend a lot of time waiting for links to download, chances are, like you, he is pretty busy! Further, always link back to your homepage in order to make navigating your web page easier for your potential customers.

Decide the number of pages you want to have inside of your site, and determine logical titles for them. Think of any pictures that you might want to put on each page and where you are going to put them in order to be most effective. You should plan out your hyperlinks now, as it will make keeping track of them later a lot easier and save you time trying to figure out why they are not working properly. Decide where you want to put any buttons that you might create for hyperlinks as well. Lastly write out any information content you will be putting onto your web page in Microsoft Word first so you can detect any spelling errors you might have made. You can cut and paste parts into your favorite editor later.

So be sure to prepare before you start, think of the content you want to put in, think about your links, think about your web site’s name, draw up an outline on paper before you start constructing the page and most importantly

“Plan Your Work and Work Your Plan”

05 February, 2009

Practical difference between Interface and Abstract class

Interface

Interface is used to collect similarities. Wherever we have to implement in the class means follow that similarities

Wherever we have to use (Real life scenario)

- Two person using same code but connection to the database methods only differ to each other. One person use sql based connection another one use oracle based connection. This type of scenario we can use Interface.
- A human and a parrot can both whistle, however it would not make sense to represent Humans and Parrots as subclass of a Whistle class, rather they would most likely be subclasses of an Animal class (likely with intermediate classes), but would both implement the Whistle interface.

What is Interface ?
  • The behavior of a class
  • All methods of an Interface are abstract methods.
  • They cannot have bodies
  • You cannot create an instance from an interface
  • An interface can only be implemented
  • This is the concept of encapsulation
  • During runtime, actual object instance is associated with the interface type
  • It needs only the interface at the compile time
  • Interface does not contain constructor
  • Multiple inheritance feature can be achieved through interface
  • Cannot be versioned.

Abstract Class
  • It is a class that contains one or more abstract methods
  • It may contain constructor but interface does not contain constructor.
  • In Interface all methods should be public but not in abstract class
  • Abstract class we can put sharable code
  • Its not Possible to create instance of Abstract class
  • It cannot be instantiated on it’s own, it must be inherited.
  • It can use One Overriding method
  • It can specify members that must be implemented in inheriting classes
  • A class can inherit only one abstract class
  • It enables us to place common instance behavior.
  • Offer versioning benefits.
  • Used for sharing common features among verious objects.

04 February, 2009

Static Contructors in .Net

What is a static constructor?

As part of my job I conduct technical interviews for my company. One of the stock question in my interview is can constructors be declared static? Most of the time I get a blunt, no, as the answer. Even some argue that one cannot use the static word along with constructors. A very few who say yes are asked further questions on static constructors like what is the difference between a static constructors and normal constructors? For this also I have got lots of answers like static constructors can be called without creating an object, only static variables can be use etc. Some say static constructors are called only once and when I ask when is that once, People don’t have an answer. So I thought I will try to clear some confusion related to static constructors.

Can constructors be declared Static?

YES

What is the difference between a static constructor and normal constructors?

As we know Normal constructors are used to initialize class variables whereas static constructors are used to initialize class level static variables. Static constructors cannot access any other objects other than static as similar to static methods. Similar to static method, static constructors are class level and not instance level. Static constructors do not take any access modifiers, like public, private, protected etc. They also don’t take any arguments. Static constructors are called only once.

Static constructors are called only once, when is that once?

Static constructors are called only once throughout the life time of the program, i.e. when the first instance of the class having static constructors is created or when a static member is accessed/used whichever happens first.Let me explain further, suppose you have a class called StaticConstructor with a static constructor as shown below.

/***********Code*****************/

using System;
namespace StaticConstructorDemo
{
class StaticConstructor
{
private static string someText;
private static int counter;

static StaticConstructor()
{
someText = "Static constructor executed. No of times: ";
counter++;
}

public static void PrintSomeText()
{
Console.WriteLine(someText + counter.ToString());
}
}

class MainClass
{
static void Main(string[] args)
{
StaticConstructor sc1 = new StaticConstructor();
StaticConstructor sc2 = new StaticConstructor();
StaticConstructor sc3 = new StaticConstructor();
StaticConstructor.PrintSomeText();
}
}
}
/***********End******************/

The above code will print “Static constructor executed. No of times: 1”. The reason is static constructor is called only once when the first instance for the class is created i.e. when sc1 is created.If the above code inside the main method is rewritten like this

/***************Code**************/

class MainClass
{
static void Main(string[] args)
{
StaticConstructor.PrintSomeText();
StaticConstructor sc1 = new StaticConstructor();
StaticConstructor sc2 = new StaticConstructor();
>StaticConstructor sc3 = new StaticConstructor();
}
}
/***************End****************/

The above code will have the same output as the previous code i.e. “Static constructor executed. No of times: 1”. Static constructor is called before the code inside the static method, PrintSomeText(), is executed. As we know static methods can use static members and if a static constructor is not executed then there is every possibility of the system throwing “object reference not set to an instance” error. So static constructors are called before the first instance of the class is created or any static members are accessed/used.

Hope from the above e.g. gives a clear idea...