Blogger Theme Design (Chapter 1)

This tutorial teaches you how to design a blogger template from scratch.
  1. Go to 'Theme' and 'Edit HTML' in Blogger.


  2. Now add the basic HTML code.
     <html>
         <head>
             <title>Title</title>
         </head>
         <body>
             <p>Hello World</p>
         </body>
     </html>

    By clicking Preview button, It will show an error message
    Could not load theme preview: There should be one and only one skin in the theme, and we found: 0
    Add the below code in head to avoid this error.
    <b:skin><![CDATA[
    /****CSS CODE*****/
    ]]></b:skin>
    After adding the above code it will show the error message like
    We did not find any section in your theme. A theme must have at least one b:section tag.
    Add the below code in body to avoid this error
    <b:section id="1"></b:section>
    Now the whole code will look like
    <html>
        <head>
            <title>Title</title>
            <b:skin><![CDATA[
            /****CSS CODE*****/
            ]]></b:skin>
        </head>
        <body>
    <b:section id="1"></b:section>
            <p>Hello World</p>
        </body>
    </html>
    The output of this code will be like this
  3. Add the below code in body to display all blog posts.
    <b:section class='main' id='main' showaddelement='yes'>
    <b:widget id='Blog1' locked='false' title='Blog Posts' type='Blog' version='1'/>
    </b:section>
  4. Next, I am going to add a sidebar. First add the styles of main and sidebar in the CSS.
    #main-wrapper {
    float:left;
    width:70%;
    }
    #sidebar-wrapper {
    float:right;
    width:30%;
    }
    Then use these styles for main and sidebar. Complete code is shown below.
    <?xml version="1.0" encoding="UTF-8" ?>
    <html xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr'>
        <head>
            <title>Title</title>
            <b:skin><![CDATA[
    /****CSS CODE*****/
    #main-wrapper {
    float:left;
    width:70%;
    }
    #sidebar-wrapper {
    float:right;
    width:30%;
    }
            ]]></b:skin>
        </head>
        <body>
    <div>
    <div id='main-wrapper'>
    <b:section class='main' id='main' showaddelement='yes'>
    <b:widget id='Blog1' locked='false' title='Blog Posts' type='Blog' version='1'></b:widget>
    </b:section>
    </div>
    <div id='sidebar-wrapper'>
    <b:section class='sidebar' id='sidebar' preferred='yes' showaddelement='yes'/>
    </div>
    </div>  
        </body>
    </html>

How to add third party ads in Blogger

This post describes how to add ads in Blogger from Amazon Affiliate Program.
I started blog writing in August 2017. Then I applied for Google Adsense after creating 5 posts in my blog. But that application is rejected due to insufficient content. Again I applied for Adsense after some days. But again application is rejected. Then I searched for an alternative for Adsense and I found that Amazon Affiliate Program is better to use in the beginning of blog writing. I got approval from Amazon Affiliate Program when I have only 7 blog posts and 726 views. Below figures shows status of my blog when I got approval from Amazon.



Follow the below steps to add ads in your blog from Amazon Affiliate Program.
  1. Apply for Amazon Affiliate Program.
  2. Go to Amazon Affiliate Program after getting approval from Amazon. I got approval within 1 day after applying.
  3. Go to Product Linking -> Banners.


  4. Copy the HTML code of any banner from this page. I have selected 728 X 90 banner.


  5. Go to Layout tab in Blogger. Then click Add a gadget button.


  6. Then add an HTML/Javascript gadget.


  7. Then paste the copied HTML code here and save.


  8. Then you can see the ads in your blog.

Don't track your own page views in Blogger

This post gives the technique to avoid counting of your own page views in Blogger. First login to your blog and then go to https://[yourblog].blogspot.in/b/statsCookieManage.


Then tick the check box 'Don't track my views for this blog'. Then go to Status -> Overview to check your page views.


But unfortunately blogger still tracking my pageviews. This issue can be resolved by a small technique. Go to https://[yourblog].blogspot.in/b/statsCookieManage. Then click F12. Then go to console in the newly opened window.


Then copy the below code and paste into the console.

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}
createCookie("_ns", "2", 999);




Then click enter. Now this code will be executed. Thus tracking of my own page views issue is resolved for me.

Introduction to Java

Java is a high level programming language.

Features of Java

  1. Object Oriented
    Java is an Object Oriented Programming(OOPs) language. The main concepts of OOPs are
    • Object
    • Class
    • Inheritance
    • Polymorphism
    • Abstraction
    • Encapsulation

  2. PLatform Independent
    Java is a platform independent programming language. Java code can be run on different platforms like Windows, Linux, Mac etc.

  3. Secured
    Java is a secured programming language compared to C programming. One of the main feature of C programming is pointers. Using pointers we can access memory location directly. This is main threat to the security of the application. But in Java there is no pointers. So Java is more secure compared to C. Java program run inside the Virtual Machine(JVM). But C programs run directly in the operating system. So Java is more secure than C.

  4. Architecture Neutral
    In C programming, int data type occupies 2 bytes of memory for 32 bit architecture and 4 bytes for 64 bit architecture. But in Java, it occupies 4 bytes of memory for both 32 and 64 bit architecture. So Java is architecture neutral.

  5. Distributed
    We can create distributed applications in Java. We can access files or data by calling the methods from any machine on the internet. Distributed applications can be created using EJB, Web services etc.

  6. Multithreaded
    We can run multiple tasks simultaneously in Java using Multithreading.

Difference between JVM, JRE and JDK

  1. Java Virtual Machine (JVM)
    Compiler converts the Java code into byte code. JVM loads this byte code and execute this code.

  2. Java Run time Environment (JRE)
    JRE is the implementation of JVM. JRE contains JVM and other libraries for supporting JVM.

  3. Java Development Kit (JDK)
    JDK contains JRE and development tools.
  • JVM, JRE and JDK is platform dependent. But Java is platform independent.
  • For running a Java application JRE is enough. But for developing a Java application JDK is required.

OOPs Concepts

  1. Inheritance
    When one object acquires all the properties and behavior of parent object is known as inheritance. It provides code re-usability.

  2. Polymorphism
    One task is performed by different ways is known as polymorphism. Method Overloading and Method Overriding are two types of polymorphism.

  3. Abstraction
    Hiding internal details and showing functionality is known as abstraction. We use abstract class and interface to achieve abstraction.

  4. Encapsulation
    Binding code and data together into a single unit is known as encapsulation.

Variable

Variable is the name of a reserved memory area. There are three types of variables in Java.
  1. Local Variable
    A variable which is declared inside the method is called local variable.

  2. Instance Varriable
    A variable which is declared inside the class but outside the method is called instance variable. It is not declared as static.

  3. Static Variable
    A variable that is declared as static is called as static variable. It cannot be local.




How to add menu in Blogger

  1. Go to Layout and click on Add a Gadget button


  2. Then click Add Pages button


  3. Then click 'Add external link' button


  4. Then give Page title and URL


  5. Then click 'Save' button


  6. Then the menu will display in your blog

The HTTP Protocol

Hypertext transfer protocol (HTTP) is the core communications protocol used by all of today’s web applications. HTTP uses a message based model in which a client sends a request message and the server returns a response message. HTTP is a connectionless protocol. HTTP does not keep a connection between client and server. HTTP client sent a request to the server and disconnects from server and wait for the response. Then server processes the request and re-establishes the connection with the client to send a response back.

HTTP Request

A typical HTTP request is as follows

GET https://www.google.com/ HTTP/1.1
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Cookie: NID=111=EQraZU6M1YUVbgmDmX5pd4nY0AW_Mcx5aWESUF0IAtM_LhVG9b1eS5BS1QOHiNGOZYc18Oc9nqb4N_0i0x80JBm55l1XG09WdUy0np47HXzQSudz77ffECFR2DOrhaozENu9_8mSJ9WMJP7wCJpfRJihrUuFwKvqgowphg7sJTt0Q_c7eLPu0BNnQrBeD4OZYJUMXgH0B66myTeXpns143_I2UF9I5zwzgKuE9iW36CZCU; CONSENT=YES+IN.en+20170730-08-0; 1P_JAR=2017-9-11-5; SID=JwXw8_vGlJLJvnqCpwHWz_20KjirKT1cpUZ0CIssOgPdLxq6bxA-xjJkjs6bQN0bGhz46Q.; HSID=AqFT6ElGGVCgSr72w; SSID=AdVd1vj4LK7BBhWra; APISID=j8eJHZNwrBW3WXmN/A2s1TVYVBOl0s3DrP; SAPISID=U5Y4q0Bs6LWeTH9R/AwP60cJC64fd281oL; SIDCC=AE4kn79CPSO5gYTQzqGAb4ZvinlfPXDT18PQ35G1p4_QDKaMmPR8FUM9V218diBh0QJ5nN04YRd1EpJV8npZ
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Host: www.google.com

The first line of this request consists of 3 parts. In the above example first part is GET, second part is https://www.google.com/ and third part is HTTP/1.1.The first part represent a verb indicating HTTP method, second part represents the requested URL and third part represents the HTTP version. The only HTTP versions in common use on the Internet are 1.0 and 1.1.

HTTP Response

A typical HTTP response is as follows

HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Referrer-Policy: no-referrer
Location: https://www.google.co.in/?gfe_rd=cr&dcr=0&ei=gzW2WYeiFp_rugS51IiADg
Content-Length: 272
Date: Mon, 11 Sep 2017 07:04:35 GMT
Alt-Svc: quic=":443"; ma=2592000; v="39,38,37,35"

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="https://www.google.co.in/?gfe_rd=cr&amp;dcr=0&amp;ei=gzW2WYeiFp_rugS51IiADg">here</A>.
</BODY></HTML> 

The first line of every HTTP response consists of three parts. In the above example the first part is 'HTTP/1.1', second part is '302' and third part is 'Found'. The first part represents the HTTP version, second part is the numeric status code indicating the result of the request and third part is the textual reason phrase further describing the status of the response.

HTTP Methods

Some of the common HTTP methods are given below
  1. GET
    The GET method is used to retrieve resources. Requests using GET should only retrieve data and should have no other effect on the data.
  2. POST
    The POST method is designed to perform actions.
  3. HEAD
    HEAD function is same as GET. Except that HEAD will not return the message body.
  4. PUT
    PUT function replaces all current representation of target resource with the content contained in the body of the request.
  5. DELETE
    DELETE function deletes the target resource.
  6. OPTIONS
    Describes the HTTP methods that are available for a particular resource.

HTTP Headers

HTTP headers provide required information about request or response. There are three types of HTTP headers.
  1. General headers

    General headers can be used with request or response. Some of the general headers are given below
    • Connection : It tells whether the connection will keep alive or close after completing the message transmission.
    • Content-Length : It specifies the length of the message body.
    • Content-Type : Specifies the type of the content in the message body.
    • Content-Encoding : It specifies what type of encoding applied to the content of the message body.
    • Transfer-Encoding : It is different from Content-Encoding. It specifies what type of encoding applied to the message body.
  2. Request headers

    Some of the request headers are given below.
    • Accept : It tells to the server what type of content will client accept.
    • Accept-Encoding : It tells to the server what kind of content encoding will accept by the client.
    • Cookie : It submits cookies to the server that the server previously issued.
  3. Response headers

    Some of the response headers are given below.
    • Cache-Control : It passes caching directives to the browser (for example, private).
    • Location : It is used in redirection responses (those that have a status code starting with 3) to specify the target of the redirect.
    • Expires : It tells the browser for how long the contents of the message body are valid. The browser may use the cached copy of this resource until this time.