Steps to Create Your Website

January 5, 2011

Step 1: Reserve Your Domain Name
You cannot create a website without owning a domain name. It is the address and foundation of any website.

Step 2:  Select a Web Hosting Solution
After you’ve registered your domain name, you need to select a company to host your site so you can create your web pages.  This is like getting harddisk space and memory so that you can setup database/web server/ aplication server,

Step 3:  Create Your Web Pages
You can use an HTML editor or use the free website tools provided by your web hosting company.

Step 4:  Upload the web pages on server where you have hosted your application
This is like moving the web pages to server using FTP or otherwise so that user can see the updated pages when they browse through your website.

Generics

September 14, 2009

Generics allows you to define classes that can work with any defined type very similar to the use of templates in C++.
This provide type safety of the collection i.e. When you use collections like the vector and the stack you do not have to do any typecasting to get the correct value. This ensures that you cannot make silly errors with getting items from a collection.
Without generics we had to use typecasting to get the correct data out of structures. The other problem is we are going to have problems if try to add the wrong data type. Generics ensure that we use the right data type and that we do not have any typecasting to do.

If we use the wrong data type then the program will not compile.

Here is a simple example taken from the existing Collections tutorial:

// Removes 4-letter words from c. Elements must be strings
static void expurgate(Collection c) {
    for (Iterator i = c.iterator(); i.hasNext(); )
      if (((String) i.next()).length() == 4)
        i.remove();
}

Here is the same example modified to use generics:

// Removes the 4-letter words from c

static void expurgate(Collection<String> c) {

    for (Iterator<String> i = c.iterator(); i.hasNext(); )

      if (i.next().length() == 4)

        i.remove();

}

Creating generic classes
We can make our own generic classes. To do this we are going to make our own Stack class it is going to be a very simple Stack. If you don’t know, the Stack is a structure that has restricted access. You can only access the top item of the Stack. The stack provides a first-in, last-out order meaning you can only access the top item of the stack. Our stack will use a Vector as the underlying structure so it will be able to resize. Note that we cannot use an array as the underlying structure?

Why? This is because generic classes are compiled at runtime and the parameters are replaced with the appropriate type. However, arrays are initalized with a type at declaration and thus they cannot be generic. So our underlying structure will be a vector.

Creating a stack is really easy. All we need is a member variable that keeps track of the index of the top item. We store all the items in a private vector but only provide a method that can access the top item of the stack. The use of the private keyword in front of the Vector is what makes this structure possible. If we didn’t include it then we would just be creating a wrapper of the Vector and what is the purpose of that?

Creating the stack

To define that our stack is generic we use angle brackets after the class name and in those brackets we place the names of different parameters. These parameters will define what type of data the stack holds.

So the class skeleton looks like this:

Code:

 public class Stack<E> {  

}

 Now what instance members do we need? We need a vector, and a counter for the index of the top. That is all. The vector will be of type E indicating that it holds a user defined data type and the index variable will be an integer set to -1.

So add these just after the class declaration.

 Code:

private Vector<E> stack; // holds the contents of the stack

private int top; // the index of the top item in the stack. -1 indicates empty.

Now to declare the constructor.

Code:

public Stack() {

            this.stack = new Vector<E>();

            this.top = -1;

}

We create a new Vector that is empty, this is going to hold the stack. We will initalize the top variable to -1 which indicates that the stack is empty.

Now the next two methods we will define are push and pop. The push method adds an item to the top of the stack and the pop method removes an item from the stack and returns it. The push method:

 Code:

public void push(E obj) {

    stack.add(obj);

    top++;

}

We use the add method in the vector to add the parameter to the stack. The parameter is of type E which will be replaced with the type defined by the programmer when it is used. We increase the top variable by 1 so we have the index of the top item stored.

The pop method is very similar to this, it returns type E and returns the item at the top of the stack. However we have to remove this item from the stack so we need to store it in a temporary variable.

We can’t just do

 Code:

return stack.get(top);

Why? We have to do two other things, decrease the top variable by 1 so it points to the new top of the stack. We also have to remove the item from the Vector. If we don’t we will run into problems if we add a new item later. We will see this item again which is not what we want. The problem with this I illustrated in my tutorial about Vectors. We have to copy the vector contents into a new array every time we erase the end item. This can take a really long time for big stacks. We will only remove an item from the Stack if it is not empty. The pop method returns null if the stack is empty.

So the pop method looks like this:

 Code:

public E pop() {

            if (top == -1) {

        return null; // stack is empty

    }

     E temp = stack.get(top);

     stack.remove(top);

     top–;

     return temp;

}

This covers everything the Stack needs to do but it might be useful to define two methods that check if the stack is empty and how many items are in the stack. The stack is empty if top = -1. So the empty method looks like this:

Code:

public boolean isEmpty(){

        return top == -1;

}

The number of items in the stack then is top+1. If the stack is empty (top = -1) and the number of items is 0.

Code:

public int size() {

        return top+1;

}

So the full class looks like this:

Code:

import java.util.Vector;

 public class Stack<E> {

    private Vector<E> stack;

    private int top = -1; // index of the top item of the stack

    public Stack() {

        stack = new Vector<E>();

    }

    public void push(E obj) {

        stack.add(obj);

        top++;

    }

    public E pop() {

        if (top == -1) {

            return null; // stack is empty

        }

        E temp = stack.get(top);

        stack.remove(top);

        top–;

        return temp;

    }

     public boolean isEmpty(){

        return top == -1;

    }

     public int size() {

        return top+1;

    }

}

Now to test this class you can use this code:

Code:

public class Generics {

     /**

     * @param args the command line arguments

     */

    public static void main(String[] args) {

        Stack<Integer> st = new Stack<Integer>();

         st.push(500);

        st.push(400);

        st.push(300);

        st.push(900);

         if (st.size() == 0) {

            System.out.println(“Stack is empty.”);

        } else {

            System.out.println(“Stack contains ” + st.size() + ” items.”);

        }

         while (!st.isEmpty()) {

            System.out.println(st.pop());

        }

         if (st.size() == 0) {

            System.out.println(“Stack is empty.”);

        } else {

            System.out.println(“Stack contains ” + st.size() + ” items.”);

        }

        st.push(700);

         System.out.println(“Size: ” + st.size());

        System.out.println(st.pop());

     }

 }

Output of the Generics is

Stack contains 4 items.

 

Notice how in the angle brackets I have included Integer? This means that the stack can only hold integer objects. Next we add 4 items to the stack. If you run the code you will notice that the items are outputted in reverse order. This is how the stack works. Now notice how the size method works. If displays how many items are in the stack.

Output of the Generics is

Stack contains 4 items.

900We can note that st.size() == 0 is the same as isEmpty.

300

400

500

Stack is empty.

Size: 1

700

 

!Enjoy!

900

300

400

500

Stack is empty.

Size: 1

700

Starting a Software Consulting Business

August 10, 2009

Starting a software Consulting Business

some suggestions for anyone considering starting a software consulting business, including people who are out of work and have been approached by someone they know to do a bit of freelance work.

Recommended books and resources

  • Entrepreneurship for Dummies, by Kathleen Allen, is another good reference, a little more oriented towards “making it big”.
  • The Concise Guide to Becoming an Independent Consultant, by Herman Holtz, is a good guide on how to start and run your consulting business.
  • Crossing the Chasm, by Geoffrey A. Moore, is the excellent standard reference on high-tech marketing
  • Guerrilla Marketing, by Jay Conrad Levinson, is a guide to marketing on a budget, focused on what will help you make a profit in your business

Skills you will need

said, here is a list of skills you will also need:

  • The specific skill you are selling as a consultant (i.e., your niche of software development) — you will need to have lots of skill and experience (not just a degree) to establish credibility so that people will want to hire you as a consultant.
  • General organization skills — you may be able to hire a professional organizer to help you.
  • Self-motivation — the ability to get things done once you’ve decided they need to get done, stay on task, etc. without anyone prodding you — you may be able to hire a business coach to prod you.
  • Willingness to live with uncertainty — at least at first your income will not be steady, and you will probably never have certainty about your income level. If you aren’t willing to live with that, you might want to consider getting a regular job, rather than going into business for yourself.
  • Flexibility — if the initial idea of the services you want to provide doesn’t work out, or if your initial business plan proves to be unsound, you will need to be flexible enough to change course.

What and when to charge

I can’t include any discussion of specific amounts to charge, as that might be construed as price fixing. But here is a suggestion for how to figure out what to charge:

  1. Start with what you think you would be making, or should be making, in a full-time regular job, as a reasonable annual salary. That is, your gross annual pay, not including benefits, and assuming that the job comes with the usual benefits (health, dental, and life insurance, sick leave, vacation, etc.).
  2. Divide that amount by 1000, to get a reasonable hourly consulting rate. For instance, if you think your reasonable annual salary is $30,000, then your reasonable consulting rate is $30/hour.

This is just a “rule of thumb” calculation. It takes into account that you have to pay for the fringe benefits a job would provide yourself, and that you will have some “overhead” time (time spent finding, rather than working for, clients).

Contracts

I don’t think it’s necessary to have a long contract filled with legal terms. It’s better to not work for anyone that you don’t trust, unless you are willing to take the risk of not getting paid, or of getting sued. And if you do get sued, a long legal-language-filled contract is not going to help you. At least, I don’t think it will, but I’m not an attorney, so you might want to contact one to get their opinion.

Getting clients (Marketing)

In order to stay in business, you will need to have clients, and in order to have clients, you will need to do some marketing. My suggestion is that you develop a marketing plan, and this section discusses some aspects of creating a plan. You may want to hire a marketing consultant to help you through this process, or attend a business planning workshop — your local SBA office is a good place to check for workshops.

Accounting and records

Note: Consult a professional — this is not advice from an accounting professional, just some things to think about.


Follow

Get every new post delivered to your Inbox.