Sunday, February 26, 2012

A robot that flies like a bird




Pranav Mistry: The thrilling potential of SixthSense technology




Sunday, February 19, 2012

Page break in HTML/CSS


While printing an html web page might require to display the specific content in different pages like below. The paragraph 1must be displayed on page1, paragraph 2 should move to page-2 and paragraph 3 should move to page-3. 

         <p> paragraph 1: some text here</p>
         <p> paragraph 2: some other text</p>
         <p>paragraph 3: some other extra text </p>
This would be more easier with the “page-break-before:always” or “page-break-after:always” properties which were there in the CSS from the CSS Version 2.0.
To move the above paragraphs into different pages by writing the style classes as below:


               <style>
                 .pageBreak{
                             page-break-after:always;
                }
               </style>
               <p class=” pageBreak”> paragraph 1: some text here</p>
               <p class=” pageBreak”> paragraph 2: some other text</p>
               <p>paragraph 3: some other extra text </p>
In place of above code, we can also write as below:


              <style>
               .pageBreak{
                   page-break-before:always;
                  }
               </style>
               <p> paragraph 1: some text here</p>
               <p class=” pageBreak”> paragraph 2: some other text</p>
               <p class=” pageBreak”>paragraph 3: some other extra text </p>
Sometimes the above may cause discrepancies while printing the page, So It would be more suggestible to use the media type above the style class as mentioned below:
                <style>
              @media print
                {
                     .pageBreak {page-break-after:always}
                 }
              </style>
              <p class=” pageBreak”> paragraph 1: some text here</p>
              <p class=” pageBreak”> paragraph 2: some other text</p>
              <p>paragraph 3: some other extra text </p>

The above paragraphs can also be written as below:


            <style>
            @media print
               {
                    .pageBreak
                  {
                      page-break-after:always;
                      page-break-before:always;
                  }
                }
            </style>
           <p> paragraph 1: some text here</p>
           <p class=” pageBreak”> paragraph 2: some other text</p>
           <p>paragraph 3: some other extra text </p>
Page break can be implemented dynamically by using the dom function as mentioned below:

            document.getElementById("someElementId").style.pageBreakAfter="always"; 

Limitations:
  • The page-break styles work with the following block elements: BLOCKQUOTE, BODY, CENTER, DD, DIR, DIV, DL, DT, FIELDSET, FORM, Hn, LI, LISTING, MARQUEE, MENU, OL, P, PLAINTEXT, PRE, UL, XMP.
  • Only applicable to Cascading Style Sheets 2 specification
  • Only applicable to Internet Explorer 4.x and later at this stage - adding page breaks will not cause any ill effects on other browsers.
  • Do NOT try and use within a table - they won't work. To make use of this functionality try to close the table and place the page break and open a new table and continue with it.

Saturday, February 18, 2012

Dartium - Google New Browser

Google launched a new browser called Dartium by intregrating the dart technology into Chrome. In this browser Developers can have the Technology preview of his code. They have already released the Mac and Linux version of the browser and Windows version is coming soon and no time lines has been specified for the Windows version of the browser


The Technical overview of the Dart browser mentioned as, "Dart is a new class-based programming language for creating structured web applications. Developed with the goals of simplicity, efficiency, and scalability, the Dart language combines powerful new language features with familiar language constructs into a clear, readable syntax", on the dart official website.


You can download the Mac and Linux versions of the browser by clicking here.


The browser looks like below:






Sample examples which were developed using the dart browser have been placed on the dart official site. You can fined the GPS enable application which was developed in HTML 5 is here.


We have to wait few more days to get complete versions of dart and lets hope for the best and all the best for google.

Sunday, February 12, 2012

Difference between SAX and DOM


SAX  stands for Simple API for XML. It is a standard interface for event based XML parsing. Programmers provide handlers to deal with different events as the document is passed.

If we use SAX API to pass XML documents have full of control over what happens when the event occur as result, customizing the parsing process extensively. For example a programmer might decide to stop an XML document as as soon as the parser encounters an error that indicate that the document is invalid rather than waiting until the document is parsed. Thus improve the performance.

DOM stands for Document Object Model. DOM reads an xml document into memory and represents as it as tree. Each node of tree represents a particular piece of data from the original document. The main drawback is that the entire xml document has to be read into memory for DOM to create the tree which might decrease the performance of an application as the xml document get larger.

About Isolation levels & Transaction levels


The isolation level measures concurrent transaction's capacity to view data that have been updated, but not yet committed, by another transaction if other transactions were allowed to read data that are as yet uncommitted, those transactions could end up with inconsistent data were the transaction to roll back, or end up waiting unnecessarily were the transaction to commit successfully.

A higher isolation level means less concurrence and a greater likelihood of performance bottleneck, but also a decreased chance of reading inconsistent data. A good rule of thumb is to use the highest isolation level that yields an acceptable performace level. The following are commin issilation levels, arranged from lowest to highest.

  1. ReadUncommitted: Data that have been updated but not yet committed by a transaction my be read by other transactions
  2. Readcommitted: Only data that have been committed by a transaction can be read by other transactions.
  3. Repeatable Read: Only data that have been commited by a trasaction can be read by other transactions, and multiple reads will yield the same result as log as the data have been committed.
  4. Serializable: This highest possible iosolation level, ensures a transaction's execlusive read-write access to data, it includes the conditions of ReadCommitted and Repeatable Read and stiplulates that all transactions run serially to achieve maximum data integrity. This yields the slowest performance and least concurrency. The term serializable in this context is absolutely unrelated to the database.

Saturday, February 11, 2012

HTML5 More Useful Links


Recent days HTML5 became more popular and good presentation web technology due to its excellent features. Currently we are unable to see most of the HTML5 based applications in the web as it is not using completely around the world. But we can believe that, in future HTML 5 replaces the most of the web presentation technologies. As a developer I have tried to look into it and tried to implement the some of the examples in HTML5 and I found that HTML5 has excellent features like canvas implementation, GPS integration tags, Audio and Vedio play tags.

As we have a greater scope or greater future for the HTML 5 designers, it is better to digest the things from now onwards. In my research I found so many examples in number of websites. As per my understanding I took some sites and I have classified them into three categories as mentioned below. This is only my experience over the sites and I feel, if a person wants to learn HTML 5 he has to go through the below step.

Basic:
http://www.w3schools.com/html5/default.asp
http://www.html5rocks.com/en/tutorials/video/basics/
http://www.gilbertocortez.com/blog/html5/sample-html5-structure
https://seogadget.co.uk/html5-examples-in-the-wild/


Medium:
http://html5demos.com/
http://www.w3schools.com/html/html_examples.asp
http://html5tutorial.net/
http://www.rgraph.net/examples/index.html
http://www.html5samples.com/category/new-features-in-html-5/html-5-and-css-3/
http://www.web3mantra.com/2011/09/12/30-best-html5-websites-inspirations/
http://www.html5tuts.co.uk/
http://blog.genggao.net/inspiration/beautiful-html5-web-design-showcases/


Extream:
http://webdesignledger.com/inspiration/30-examples-of-websites-using-html5
http://html5gallery.com/
http://html5websites.net/
http://www.devlounge.net/code/10-awesome-html5-canvas-examples
http://alteredqualia.com/canvasmol/#Anandamide
http://www.chromeexperiments.com/
http://www.webdesignersblog.net/inspiration/45-inspirational-examples-html5-websites/
http://www.web3mantra.com/2011/09/12/30-best-html5-websites-inspirations/
http://www.designfloat.com/blog/2011/08/11/html5-websites-best-capabilities/
http://101besthtml5sites.com/

Saturday, February 4, 2012

HTML DTD for ICE faces JSPX


Resolving the browser compatibility issues while developing the web applications is a bit complex. Most of the times developer tries to write the browser specific code. But, it is not possible to implement the browser specific code for all the pages of the application in all the scenarios and it is not required if we specify the DOCTYPE. Specifying the doctype for the page will decrease the most of the browser compatibility issues.


A doctype declaration refers to the rules for the markup language, so that the browsers render the content correctly.


The doctype declaration is not an HTML tag; it is an instruction to the web browser about what version of the markup language the page is written in.
The doctype declaration refers to a Document Type Definition (DTD). The DTD specifies the rules for the markup language, so that the browsers render the content correctly.


The doctype declaration should be the very first thing in an HTML document, before the tag.


There are different DTDs for the HTML page as specified below:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/transitional.dtd">



Specifying the DTD on JSF page which developed using ICE faces might not accept as you specify on the normal HTML page. You have to place it after the declaration of f:view tag.



<jsp:root version="2.1" xmlns:jsp="http://java.sun.com/JSP/Page"          xmlns:f="http://java.sun.com/jsf/core"          xmlns:h="http://java.sun.com/jsf/html"          xmlns:ice="http://www.icesoft.com/icefaces/component">   
<jsp:directive.page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"/>   
<f:view>   
<ice:outputDeclaration doctypeRoot="HTML" doctypePublic="-//W3C//DTD HTML 4.01 Transitional//EN" doctypeSystem="http://www.w3.org/TR/html4/strict.dtd" />
<!-- Place the required code here --> 
</f:view>
</jsp:root>


Click here To Read more about fixing the browser compatibility issues.

Tuesday, January 24, 2012

equals() and hashCode() methods of Object Class

HashTable, HashMap and HashSet are the Collection classes in java.util package that make use of hashing algorithm to store objects. In all these Collection classes except HashSet, objects are stored as key-value pairs. For the storage and the retrieval of any user-defined objects it is a good practice to override the following methods which is mentioned below,
  • hashCode()
  • equals()
These methods are available in the Object class and hence available to all java classes.Using these two methods, an object can be stored or retrieved from a Hashtable, HashMap or HashSet.
hashCode() method
This method returns a hashcode value as an int for the object. Default implementation for hashcode() should be overridden in order to make searching of data faster. The implementation of hashCode() method for an user-defined object should be calculated based on the properties of the class which we wish to consider.
equals() method
This method returns a boolean which specifies whether two objects are equal or not. The default implementation of equals() method given by the Object Class uses the '==' operator to compare two object references, and returns true only if they refer to the same object. But, we can meaningfully re-define this equals() method to have en equality check based on our own criterias.
Consider the following code, which defines two user defined classes Employee and EmployeeId which are supposed to be stored in a Map.
Employee.java

public class Employee {
        private String name;

        public Employee(String name){
               this.name = name;
        }

        public String toString(){
        return name;
        }
}
EmployeeId.java

public class EmployeeId {

        private String id;

        public EmployeeId(String id){
               this.id = id;
        }

        public String toString(){
               return id;
        }      
}
The following class makes use of the above classes by storing it in a Map for later retrieval. We are adding Employee objects into the Map keyed with Employee Id.
HashCodeTest.java

public class HashCodeTest {

        public static void main(String[] args) {

               Map employees = new HashMap();

               employees.put(new EmployeeId("111"), new Employee("Johny"));
               employees.put(new EmployeeId("222"), new Employee("Jeny")); // Line A
               employees.put(new EmployeeId("333"), new Employee("Jessie"));

               Employee emp =  employees.get(new EmployeeId("222")); // Line B
               System.out.println(emp); // Line C
        }
}
In Line B, we try to retrieve the Employee object who has Employee Id with a value of 222. We expect the output to be 'Jeny', because the Employee with Employee Id (222) was already there in the Collection, but surprisingly, the output of the above code is null. The reason is that we did not override the equals() method for EmployeeId and Employee classes because the default implementation of equals() in the Object class considers the new EmployeeId("222") in the put statement and new EmployeeId("222") in the get statement as two different instances, and hence the call to get() in Line B returns null.
Let us look at how the same code works when we provide our desired implementation for hashcode() and equals() methods. We basically override hashcode() here just to make the object to be searched fast.
Employee.java

public class Employee {

        private String name;

        public Employee(String name){
               this.name = name;
        }

        public String toString(){
               return name;
        }

        @Override
        public boolean equals(Object obj){

               if(obj == null) {
                       return false;
               }
               if(obj.getClass() != getClass()){
                       return false;
               }

                Employee emp = (Employee)obj;
               if(this.name == emp.name){
                       return true;
               }
               return false;
        }

        @Override
        public int hashCode(){
               return name.hashCode();
        }
}
EmployeeId.java

public class EmployeeId {

        private String id;

        public EmployeeId(String id){
               this.id = id;
        }

        public String toString(){
               return id;
        }      

        public boolean equals(Object obj){

        if(obj == null)
               return false;

        if(obj.getClass() != getClass()){
               return false;
        }

        EmployeeId empId = (EmployeeId)obj;
        if(this.id == empId.id){
               return true;
        }
        return false;
        }

        @Override
        public int hashCode(){
               return id.hashCode();
        }
}
Now, we get the desired output 'Jeny', because as per our implementation for the equals() method, the new EmployeeId("222") in the put statement and new EmployeeId("222") in the get statement are considered one and the same.

Monday, January 16, 2012

Introduction to RESTful Web Services

REST is a “Representational state transfer” and it is firstly introduced by Roy Fielding (Fielding is one of the principal authors of the HTTP specification and a co-founder of the Apache HTTP Server project) in his 2000 doctoral dissertation.

REST-style services (i.e., RESTful services) adhere to a set of constraints and architectural principles that include the following:
  1.  RESTful services are stateless. As Fielding writes in Section 5.1.3 of his thesis, “each request from client to server must contain all the information necessary to understand the request, and cannot take advantage of any stored context on the server.”
  2. RESTful services have a uniform interface. This constraint is usually taken to mean that the only allowed operations are the HTTP operations: GET, POST, PUT, and DELETE.
  3. REST-based architectures are built from resources (pieces of information) that are uniquely identified by URIs. For example, in a RESTful purchasing system, each purchase order has a unique URI.
  4. REST components manipulate resources by exchanging representations of the resources. For example, a purchase order resource can be represented by an XML document. Within a RESTful purchasing system, a purchase order might be updated by posting an XML document containing the changed purchase order to its URI