Sunday, October 6

How to make a website SEO friendly , Search engine optimization

                         How to make a website SEO friendly , Search engine optimization


Page Title
Your title should be from 20 to 70 characters length. However up to 120 characters can be considered as correct.
Make sure that title is correct and includes most important keyword.
Each page should have it's own, unique title.

Meta Description
Meta description should be from 100 to 160 characters length. However up to 200 characters can be considered as correct.
Use all characters to describe your page using most important keyword.
Each page should have it’s own, unique description.
Meta description usually shows in search engine results as a description of page and it should encourage to visit your site.

Meta Keywords
Meta keywords has no influence on website positioning.
You can remove all meta keywords or limit them to only few describing your content.

Meta Robots
Meta tag robots has crucial impact on page indexing by search engine robots.
Value "noindex" prevents from indexing of page. Value "nofollow" prevents robots from following all links at page.
Most common and default (if empty) values are index, 

Encoding
 Encoding has an impact on the correct display of special characters.
Popular encodings are UTF-8, Latin1, ISO-8859-2 etc.
Encoding has no influence on website positioning, but incorrect encoding can cause problems with display special characters.
Body Content

Words and Chars
 Make sure that the text on page was not less than 250 words.
 
Text / HTML Ratio
The TEXT / HTML ratio is the ratio of the number of characters of plain text to the page's HTML code, expressed as a percentage.
The higher the number, the greater amount of content is on your site, and lesser HTML code.
A value below 10% means that there is too little text or that the HTML code is "littered" or negligent.
Make sure that the TEXT / HTML ratio is not below 10%.

Headers
H1
H2
H3
H4
H5
H6
Headers are very important factor of on-page optimization.
Correct document should contain most important

and second-level

.
Remember to insert important keyword in header.


Bolds
 The and bold type indicate the important keywords on the page.
Search engines take into account emphasized keywords that are in the text.



-->


Images
 Images enrich the content of the website.
No images on the page may be a warning signal against spam, or the page is of low quality.
Publish interesting pictures, photos or diagrams related to the content of the page.
Using the ALT attribute describe accurately each picture.

Frames
 Frames can cause problems to search engines and make your website works slow.
Avoid use of frames on websites.

Internal and External Links
External Links
1                    External Links
Outbound links (external links) are all links leading outside your website.
It is worth to link to other sites that contain high quality content related to the theme of your site.
Do not link to sites which you do not trust, in particular the spam pages.
Limit the number of outbound links to a maximum of 15 links.
Internal Links
2                    Internal Links
Internal links are any links pointing to the other pages of your website.
By placing links to other pages you are reinforcing internal linking and strengthening the usability of your website.
Always link to the most important pages of your website.

Additional Files
Robots.txt
The robots.txt file instructs search engine robots by allowing or restricting access to selected folders and pages of your website.
The robots.txt file has a huge impact on the correct page indexing in search engine results.
Make sure your website has a valid robots.txt file.

Sitemap.xml
The sitemap.xml file should contain a list of all pages of your website that need to be indexed by search engines.
Sitemap.xml file informs the search engine about relevant pages on your site, their latest update and significance in the context of the entire site.
Ensure the correctness of sitemap.xml

Social Media Signals
Facebook Likes

The number of gained "Likes" can have a positive impact on the position of your site in search results.
Install the Facebook Like button on your website and encourage your users to like your site.
Facebook Shares






By sharing your site with friends on Facebook you have a chance to gain new visitors. A large number of "shares" may have a positive impact on the position of your site in search engines.
Google +1

The number of gained Google +1 has a positive impact on the position of your site in search results.
Install Google +1 button on your website and encourage your users to click on +1.

HTTP Headers
HTTP headers is the server return information, not visible on the website.
SEO audit can be performed only on sites that have an HTTP 200 OK header, which indicates proper functioning of the page.
Any other value of the HTTP code prevents from page positioning.

Domain and Server
IP Address
IP Address has no influence on website positioning.
On one IP address can work hundreds of different websites.
Avoid sharing IP address with spam websites.
Name Servers
DNS servers has no influence on website positioning.
Like IP address, many websites can use the same DNS servers.
Avoid sharing DNS names with spam websites.
Server Geolocation
 Geographical localization of server has no direct influence on website positioning.
Use hosting companies located in regions where you are making your business.







'javac' is not recognized as an internal or external command, operable program or batch file.

'javac' is not recognized as an internal or external command, operable program or batch file.

This error might occur as JDK is not set in path System variable in environment variable


-->


To set this find out where Java is installed on your system

Let's say you have Java 7 installed on your system , copy bin directory path as below :

\jdk1.7.0\bin

Now access the path variable in environment variable from :

Control Panel\System and Security\System



Set Java_Home as
\jdk1.7.0\bin

then set  path variable value as : %Java_Home%;(current value in path)

OR

set path directly as
\jdk1.7.0\bin;(current value in path)


If Still it does not work and throw same error , Access command line 

and check the path with path command 

Now see if \jdk1.7.0\bin is there in the output ..

If it is not there then set path from command line using command 

set path =%path%;\jdk1.7.0\bin

Now check again the value of path variable , \jdk1.7.0\bin should be there 

Try executing program again , it should work now.. 












Builder Design Pattern

What is builder design pattern ?

This is used to segregate the logic for creation of complex objects. 

For example

 If we want to create an object of class representing real Estate residential project . We need to take into account lot of factors in building full fledged object . Object will consist of features like 
 payment plan 
layout 
construction plan 
builder information 
land details 
finance details 
location details
salient features 

and so on.....




So we won't prefer to embed the logic of creation of this instance in actual business logic and unnecessarily clutter the business logic flow Instead It would be good to have a dedicated service which can build up this object and once prepared can return it to business logic . Thus actual business logic remains agnostic of all object creation complexities..

So how do we achieve that in Object oriented language . 


Let us try to understand this with code. As usual I have written lot of System.out.println statements in the code to bring are execution flow steps in print statements . This code can be directly copied and executed .All steps of design pattern will be clearly written on console.


-----------------------------------------------------------------------------------------------

//This is the Client class which basically place an order. Here this client first place an order of //commercial project and after it's successful delivery It approaches for residential project and //place an order for that.



package realEstate;

public class Client {

    /**
     * @param args
     */
    public static void main(String[] args) {
      
        projectOwner owner=new projectOwner(new CommercialProjectBuilder());
        owner.placeRoder();
        owner.getProject();
        System.out.println("CLIENT :::: Thank you for timely delivry of commerical project");
        System.out.println("===============================================================");
        System.out.println("CLIENT :::: Now let's deal in residenrial");
         owner=new projectOwner(new ResidentialProjectBuilder());
        owner.placeRoder();
        owner.getProject();
        System.out.println("CLIENT :::: Thank you for timely delivry of Residential project.. Rocking performance");
    }

}

// This is project Owner . Client passes the type of project It is looking for : commercial or residential //and creates Project Owner instance . Owner will further place order of construction to Commercial //or Residential department based of which object is passed by client 
class projectOwner{
    ProjectBuiding building;
    projectOwner(ProjectBuiding building){
        this.building=building;
        }
   
  void  placeRoder(){
      building.constructBase();
      building.constructFloors();
      building.doFinishing();
      building.decorate();

   }
 
  ProjectBuiding  getProject(){
      return building;
  }
  
   
}

// Interface for Residential and commercial project builder classes 
interface ProjectBuiding{
   
   
   
    void constructBase();
   
    void constructFloors();
   
    void doFinishing();
   
    void decorate();
   
   
}

// entire process and logic of building a residential project is encapsulated in this class
class ResidentialProjectBuilder implements ProjectBuiding {
   
    ResidentialProjectBuilder(){
        System.out.println("ResidentialProjectBuilder:::Thank you for reaching us..We deal in Residential Projects..");
    }

    public void constructBase() {
      
        System.out.println("ResidentialProjectBuilder:::Construction is already started.. Promise to deliver on time ");
    }

    public void constructFloors() {
        System.out.println("ResidentialProjectBuilder::::Construction is on full Swing.. Pay installments timely ");
       
    }

    public void doFinishing() {
        System.out.println("ResidentialProjectBuilder::::About to deliver .. Have litte more Patience ");
       
    }

    public void decorate() {
        System.out.println("ResidentialProjectBuilder:::IT is well decorated.. Ready to move");
       
    }
   
}


// entire process and logic of building a Commercial project is encapsulated in this class


class CommercialProjectBuilder implements ProjectBuiding{

    CommercialProjectBuilder(){
        System.out.println("CommercialProjectBuilder ::: Thank you for reaching us..We deal in Commercial Projects..");
    }
   
    public void constructBase() {
        System.out.println("CommercialProjectBuilder :::Construction is already started.. Promise to deliver on time ..");
       
    }

    public void constructFloors() {
        System.out.println("CommercialProjectBuilder :::Construction is on full Swing.. Pay installments timely ");
       
    }

    public void doFinishing() {
        System.out.println("CommercialProjectBuilder :::About to deliver .. Have litte more Patience ");
       
    }

    public void decorate() {
        System.out.println("CommercialProjectBuilder :::IT is well decorated.. Ready to move");
       
    }
   
}


 Below would be the output of console on program execution
-------------------------------------------------------------------------------------------










CommercialProjectBuilder ::: Thank you for reaching us..We deal in Commercial Projects..
CommercialProjectBuilder :::Construction is already started.. Promise to deliver on time ..
CommercialProjectBuilder :::Construction is on full Swing.. Pay installments timely
CommercialProjectBuilder :::About to deliver .. Have litte more Patience
CommercialProjectBuilder :::IT is well decorated.. Ready to move
CLIENT :::: Thank you for timely delivry of commerical project

===============================================================



CLIENT :::: Now let's deal in residenrial
ResidentialProjectBuilder:::Thank you for reaching us..We deal in Residential Projects..
ResidentialProjectBuilder:::Construction is already started.. Promise to deliver on time
ResidentialProjectBuilder::::Construction is on full Swing.. Pay installments timely
ResidentialProjectBuilder::::About to deliver .. Have litte more Patience
ResidentialProjectBuilder:::IT is well decorated.. Ready to move
CLIENT :::: Thank you for timely delivry of Residential project.. Rocking performance

 


-->

Friday, October 4

Blocking Queue and Consumer pattern for fixed resources

                                 Blocking Queue and Consumer pattern for fixed resources

What is blocking Queue 

Blocking Queue is a collection   introduced in java 1.6 . It provides lot of useful methods to write efficient mutithreaded and concurrent program . 

We will discuss here two very important methods of blocking  Queue here 

1. put() : this method put an object in the queue only If there is capacity to add. In blocking queue ,we can define the maximum possible size of the queue at Queue instance construction time. 

So If we say : 

    BlockingQueue tokensQueue = new LinkedBlockingQueue(10);

maximum allowed Token objects in queue is 10 . 

Blocking Queue is interface and LinkedBlockingQueue is one of it's implementation. 

So if current size of queue is 10 and we call put method like queue.put(Object) , this call will be blocked until an object is consumed from the queue by one of the consumer . After consumption , current size will reduce and queue will have capacity to add more objects. Then queue.put(Object) cal will succeed . 

2. take() : This method retrieves the Object from Queue. This is also blocking call If there is no object available in the queue and queue is empty . It will continue waiting until and object is inserted in the queue by some other thread . Once at least once object is available in queue , queue.take() method will succeed and blocking will break.

One more method I would like to discuss is offer() . offer() is method that puts object in the queue But that is not a blocking call. It simply returns false If object is not added due to capacity and does not wait for Queue getting space for another object. 





-->



Before starting my code example I would like to touch upon one more thing : 

AtomicInteger : this is class available in java now to provide atomic operations while accessing and modifying value of a primitive type. It provides certain methods to provide synchronization and atomicity . Will see in the example How to use that ..

 So now lets move to our code example :

Consider there is a class of 1000 odd students. Now being summer season students keep of going out of class to take water . Teacher can not send a lot of students together So a rule is maintained that at one time maximum of only 10 students can stay outside . 

So implement this practically , 10 tokens are created. Every time student goes outside has to carry a token . After returning will put the token back in pool for someone else to use. 





So how can we implement this using Blocking Queue : 

As usual below code has lot of System.out.println statements . Executing this program will print them on console and they will take you through all the steps followed. 

------------------------------------


import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;


// This is the class where tokens are created . It interact with other classes to create and overall //flow.
 
public class Class {


    BlockingQueue tokensQueue = new LinkedBlockingQueue(10);

    public static void main(String[] args) {

        Class Class = new Class();
        Class.generateTokens();

    }
// this method is doing nothing but adding 10 instances of Token //class in queue
    public void generateTokens() {

        for (int i = 0; i < 10; i++) {
            System.out.println("generating token no" + i);

            try {
                tokensQueue.put(new Token());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }

        System.out.println("Now all 10 tokens are created and are stored in blocking queue ");


// Here consumer thread is started to start using tokens
        Thread BCC = new Thread(new Student(tokensQueue));
        BCC.start();

    }

}
// This is Token class . These tokens are allotted to students 

 
class Token {

    public static AtomicInteger tokenNumber = new AtomicInteger(0);

    public int number_Of_Token_Assigned;

    void useToken(Token token) {
        System.out.println("Student is using token " + token.number_Of_Token_Assigned);
   
}

    Token() {
        this.number_Of_Token_Assigned = tokenNumber.incrementAndGet();
    }

}

// Students are continuously using the tokens So infinite while loop is executed... 
 
class Student implements Runnable {
    BlockingQueue tokenQueue;

    Student(BlockingQueue tokenQueue) {
        this.tokenQueue = tokenQueue;
    }

    public void run() {

        try {
            while (true) {
                System.out.println("student request for a token..");
                Token token = tokenQueue.take();
                System.out.println(token.number_Of_Token_Assigned + " is the token no alloted ...");
                token.useToken(token);
                System.out.println("token" + token.number_Of_Token_Assigned
                        + "is used .Now putting that back into tokenQueue");


                tokenQueue.offer(token);
            }
        } catch (InterruptedException e) {

            e.printStackTrace();
        }

    }

}
 


This will print on console something like :





-----------------------------
2 is the token no alloted ...
Student is currently using token
token2is used .Now putting that back into tokenQueue
student request for a token..
3 is the token no alloted ...
Student is currently using token
token3is used .Now putting that back into tokenQueue
student request for a token..
4 is the token no alloted ...
Student is currently using token
token4is used .Now putting that back into tokenQueue
student request for a token..
5 is the token no alloted ...
Student is currently using token
token5is used .Now putting that back into tokenQueue
student request for a token..
6 is the token no alloted ...
Student is currently using token
token6is used .Now putting that back into tokenQueue
student request for a token..
7 is the token no alloted ...
Student is currently using token
token7is used .Now putting that back into tokenQueue
student request for a token..
8 is the token no alloted ...
Student is currently using token
token8is used .Now putting that back into tokenQueue
student request for a token..
9 is the token no alloted ...
Student is currently using token
token9is used .Now putting that back into tokenQueue
student request for a token..
10 is the token no alloted ...
Student is currently using token
token10is used .Now putting that back into tokenQueue
student request for a token..
1 is the token no alloted ...
Student is currently using token
token1is used .Now putting that back into tokenQueue
student request for a token..
2 is the token no alloted ...
Student is currently using token
token2is used .Now putting that back into tokenQueue
student request for a token..
3 is the token no alloted ...
Student is currently using token
token3is used .Now putting that back into tokenQueue
student request for a token..
4 is the token no alloted ...
Student is currently using token
token4is used .Now putting that back into tokenQueue
student request for a token..
5 is the token no alloted ...
Student is currently using token
token5is used .Now putting that back into tokenQueue
------------

----------
--------

 You can repeat tis example with more consumer by creating more consumer classes as below and see how output comes 

public void generateTokens() {

        for (int i = 0; i < 10; i++) {
            System.out.println("generating token no" + i);

            try {
                tokensQueue.put(new Token());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }

        System.out.println("Now all 10 tokens are created and are stored in blocking queue ");

        Thread BCC = new Thread(new Student(tokensQueue));
        BCC.start();

  Thread BCC1 = new Thread(new Student(tokensQueue));
        BCC1.start();

  Thread BCC2 = new Thread(new Student(tokensQueue));
        BCC2.start();


    }