Wednesday, 9 October 2013

What is Tripleton design pattern , and write a tripleton class ?

Instanciate your class via a factory (see design patterns) and limit it to 3 instances using a simple counter.


public class LimitClass {

    private static LimitClass limInstance;
    public static int objCount = 0;

    private LimitClass(){
        objCount++;
    }

    public static synchronized LimitClass getLimInstance(){
        if(objCount < 3 ){
            limInstance = new LimitClass();
        }
        return limInstance;
    }
}

public class LimitObjectCreationTest {

    public static void main(String[] args) {

        LimitClass obj1 = LimitClass.getLimInstance();
        LimitClass obj2 = LimitClass.getLimInstance();
        LimitClass obj3 = LimitClass.getLimInstance();
        LimitClass obj4 = LimitClass.getLimInstance();
        LimitClass obj5 = LimitClass.getLimInstance();
        LimitClass obj6 = LimitClass.getLimInstance();

        System.out.println(obj1);
        System.out.println(obj2);

        System.out.println(obj3);
        System.out.println(obj4);
        System.out.println(obj5);
        System.out.println(obj6);
      }
}
Output of above code is like:
com.pack2.LimitClass@19821f
com.pack2.LimitClass@addbf1
com.pack2.LimitClass@42e816
com.pack2.LimitClass@42e816
com.pack2.LimitClass@42e816
com.pack2.LimitClass@42e816

Tuesday, 10 September 2013

Understanding the New Way to Present Content on the Web- Using “Article” Markup Element in your HTML Pages


As discussed in an earlier article on Javaguerrier, HTML5 introduced a lot of new markup elements to enable rich web authoring.

The “article” markup element is one of the new sectioning elements introduced in HTML5.
The HTML5 specification defines “article” markup element as a self-contained composition in a document, page that is independently reusable in syndication.
It can be used for a newspaper article, a blog entry or a forum post, or any independent item of content.

Few notes facts about “article” markup element

  •       Article markup element can be used where flow content is expected.
  •      The “article” markup elements are global attributes.
  •      The “article” element uses “HTMLElement”.
  •      An “article” markup element can have headers
  •       An “article” markup element can have footers.
  •        "Article” markup elements can be nested.
  •       When “article” elements are nested, the nested elements should be principally related to the parent      article. A classic example would be comments on a blog post are related to the blog post.
  •       “Article” markup elements can work with “section” markup elements. However, note that “article” is used when the content is self-contained. HTML5 specification does not dictate that “section” element should have the content which is self-contained.


Using “article” markup element
Simply put, a simple HTML5 webpage using article markup element looks as under.


<!DOCTYPE html>
<html>
<meta charset="utf-8">
<title>Article sample</title>
<body>
    <article>
        <header>
            <h1>Article sample</h1>
            <p>The First sample using Article markup element</p>
        </header>
        <footer>
            <h1></h1>
            <p>HTML Goodies</p>
        </footer>
    </article>
</body>
</html>

This will result in a display on the web page as under:



Nested “article” markup elements need to put under a section element.
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<title>Article sample 2</title>
<body>
    <article>
        <header>
            <h1>Article sample using nested articles</h1>
            <p>The Second sample using Article markup element</p>
        </header>
        <footer>
            <h1></h1>
            <p>HTML Goodies</p>
        </footer>
        <section>
            <h1>Comments</h1>
            <article id="comment1">
                <footer>
                    <p>Posted by: Commenter 1</p>
                    <p><time datetime="2013-07-26">1 day ago</time></p>
                </footer>
                <p>This is a a very trivial example</p>
            </article>
            <article id="comment2">
                <footer>
                    <p>Posted by: Commentor 2</p>
                    <p><time datetime="2013-07-27">1 minute ago</time></p>
                </footer>
                <p>Nah, this looks like an advanced concept.</p>
            </article>
        </section>
    </article>
</body>
</html>

The webpage above will look as under:





Monday, 9 September 2013

A 5 Minute Overview of All New HTML5 Markup Elements

Introduction 

With the announcement of the recommended specification of HTML5, we are even closer than ever to the announcement of the final specification of HTML5 (which can happen at any moment). HTML5 introduces a bunch of new markup elements as well as support for programmatic APIs which can be used with JavaScript to build web pages which can act as web applications.
         
    In this article, we will do a quick rundown of all the new markup elements new in HTML5.

  • Article - The article element is a new sectional element and is used to represent a self-contained entry in a document, page, application or site. 
  • Aside - The aside element is used to represent content which is tangentially related to the content which is around aside element, sometimes, represented as sidebars. 
  • audio - The audio element is a type of media element used to represent an audio stream. 
  • canvas - The canvas element is used for rendering graphs, game graphics, art images or other visual images using a resolution dependent bitmap canvas. 
  • command - The command element represents a command which can be invoked by a user. It can be part of a menu element (explicitly part of a context menu or toolbar); alternately it can be placed anywhere else on the page to define a keyboard shortcut or to define other commands. 
  • datalist - The datalist element is used to represent a set of option elements which can act as options of other controls. datalist elements are wired to input elements using the list attribute on the input element. 
  • details - The details element is used to represent an area where users can go to obtain additional information. The details element in an interactive element represented as a widget. 
  • embed - The embed element is used to represent an integration point for a non-HTML application or interactive content. 
  • summary - The summary element is an interactive element used to represent a summary or legend for the rest of the content. 
  • Figure - The figure element is a grouping element is used to group content that is self-contained and is typically referenced as a single unit from the main flow of the document. 
  • Figcaption - The figcaption element represents the caption for a figure element. 
  • Footer - The footer element is used to represent a footer of the preceding sectional content. 
  • Header - The header element is used to represent a header for the succeeding sectional content. 
  • keygen - The keygen element is used to represent a key pair generator control which is used to store the private key in the local keystore and send the public key to the server when the form is submitted. The keygen element is a form element. 
  • mark - The mark element is used to highlight a range of text in a document for reference purpose. It is equivalent of using a highlighter to highlight a bunch of text. 
  • meter - The meter element is used to represent a scalar measurement within a known range, for example, how many respondents were male with kids. It should not be used to indicate progress. 
  • nav - The nav element is a section with navigation links and represents a section of page that links to other pages. 
  • output - The output element is used to represent the result of a calculation or user action. It supports representation of explicit relationship between itself and the elements that represent the values that went into the calculation of the output value. 
  • progress - The progress element is used to represent the progress of a task. It supports both indeterminate situations as well as determinate situations. 
  • Ruby - The ruby element is used to support one or more spans of content to be marked with ruby annotations. 
  • rt - The rt element is used to mark the ruby text component for a ruby annotation. 
  • rp - The rp element is used to provide parenthesis around a ruby text component of a ruby annotation. 
  • Section - The section element is used to represent a generic section of a document or application, usually containing a heading. E.g. chapters in a book. 
  • Source - The source element is used to specify to alternate media resources for media elements. It is not supposed to be dynamically modified, as that will have no effect. 
  • Summary- The summary element is an interactive element which is used to represent a summary, or caption for a details element. 
  • Time - The time element represents datetime attribute contents in a machine readable form (limited to various kinds of dates, times, time-zone offsets, and durations). 
  • Video - The video element is a type of media element used to represent a video stream. 
  • wbr - The wbr element is used to represent a line break in a web page. 
Summary 
In this article, we learned about all the new markup elements in HTML5. I hope you have found this information useful. In upcoming articles, we will review these new markup elements in more detail.