<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3008166024805877968</id><updated>2012-01-29T12:29:25.327-08:00</updated><category term='image input/output'/><category term='mouseadapter'/><category term='fifo'/><category term='glyphs'/><category term='package'/><category term='java'/><category term='event dispatching'/><category term='swing'/><category term='bugs'/><category term='clipping coordinates'/><category term='Swingutilities'/><category term='boolean logicals'/><category term='operand'/><category term='fonts'/><category term='javax'/><category term='listener lists'/><category term='graphicsenvironment'/><category term='event'/><category term='api'/><category term='graphicsconfiguration'/><category term='thread'/><category term='queue'/><category term='awt'/><category term='conditional'/><category term='buffer stream'/><category term='buffer'/><category term='truirty'/><category term='timers and swing'/><category term='color'/><category term='sRGB'/><category term='african girl'/><category term='standards'/><category term='operators'/><category term='bufferedinputstream'/><category term='binary file'/><category term='canvas'/><category term='components'/><category term='code'/><category term='cellspacing'/><category term='jcomponent'/><category term='jpanel'/><title type='text'>Java for serious and fun</title><subtitle type='html'>MY BLOG, MY READINGS ON JAVA, MY PASSION. WE SHARE.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>77</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-3026841682573315475</id><published>2007-08-14T08:28:00.000-07:00</published><updated>2007-08-14T08:41:38.601-07:00</updated><title type='text'>Can I Count The Ways? Let me...</title><content type='html'>&lt;p&gt;I lost my lunch writing this, so in recompense, I decided to play some games online. There were so many options. “Like the Mahjong game?” Smiled. “I speak of it all the time, right?” “Okay which now?” “Won't tell. Since you can be Harry Porter, how soon will Oz be at your doorstep?” “What's the game, Cyp?”&lt;br&gt;But before you play, the code is long, your fingers have need some getting used to the typing.Nice day. &lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;/*&lt;br /&gt; *I JUST TRIED DOING A LITTLE BINARY OPERATORS&lt;br /&gt; *HERE AFTER HAVING A LOOK AT SOME OLD CALC&lt;br /&gt; *MACHINE. HOPY YOU LIKE IT.&lt;br /&gt; */&lt;br /&gt;&lt;br /&gt;package overall;&lt;br /&gt;&lt;br /&gt;import java.io.*;&lt;br /&gt;import java.util.*;&lt;br /&gt;import java.lang.*;&lt;br /&gt;&lt;br /&gt;public class Postfix {    &lt;br /&gt;    static List&lt;Integer&gt; stackList = new ArrayList&lt;Integer&gt;();&lt;br /&gt;    static List operatorList = new ArrayList(); //ignore generics.&lt;br /&gt;    //the index counts to tail lof list&lt;br /&gt;    static int listCounter = -1;   &lt;br /&gt;    &lt;br /&gt;    protected static void checkInput(String keyedIn){&lt;br /&gt;        //check for exit character once and for all&lt;br /&gt;        if (keyedIn.equals("@")){&lt;br /&gt;            System.exit(0);&lt;br /&gt;        }&lt;br /&gt;        //not ready to exit?&lt;br /&gt;        //make sure first number is a number        &lt;br /&gt;        if (listCounter == -1){ //nothing in list at all&lt;br /&gt;            try{&lt;br /&gt;                //see if we can parse the keyed in figure to int&lt;br /&gt;                int received = Integer.parseInt(keyedIn);&lt;br /&gt;                //insert first number into the list&lt;br /&gt;                stackList.add(received);&lt;br /&gt;                //increase the counter&lt;br /&gt;                ++listCounter;&lt;br /&gt;                System.out.println("Key in an operator, please.");&lt;br /&gt;            }&lt;br /&gt;            catch(NumberFormatException e){&lt;br /&gt;                System.err.println("First number must be a number. Thanks.");&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        //where the keyedin number is not the first number i.e something in stack&lt;br /&gt;        //we expect an operator for next number&lt;br /&gt;        //check if an operator is already waiting for an operand&lt;br /&gt;        int opCheck = operatorList.size();&lt;br /&gt;        if (opCheck == 0) {&lt;br /&gt;            //no operator waiting! if operand replace it with previous.&lt;br /&gt;                try{&lt;br /&gt;                    int checking = Integer.parseInt(keyedIn);&lt;br /&gt;                    //replace first number and count is still 0&lt;br /&gt;                    stackList.remove(0);&lt;br /&gt;                    stackList.add(checking);&lt;br /&gt;                }&lt;br /&gt;                //if operator, what was expected&lt;br /&gt;                catch(NumberFormatException e){&lt;br /&gt;                    //send to operator then&lt;br /&gt;                    doOperation(keyedIn);                    &lt;br /&gt;                }&lt;br /&gt;        }&lt;br /&gt;        //operator waiting, waiting for a number.&lt;br /&gt;        //number expected&lt;br /&gt;        if(opCheck &gt; 0){&lt;br /&gt;            try{&lt;br /&gt;                int checked = Integer.parseInt(keyedIn);&lt;br /&gt;                //if number add to list and increase count&lt;br /&gt;                stackList.add(checked);&lt;br /&gt;                ++listCounter;&lt;br /&gt;                compResult();&lt;br /&gt;            }&lt;br /&gt;            //if not number ask for number&lt;br /&gt;            catch(NumberFormatException e){&lt;br /&gt;                System.out.println("Input a valid number please.");&lt;br /&gt;            }&lt;br /&gt;        }        &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    protected static void doOperation(String ourOperator){&lt;br /&gt;        //whenever any character is assumed operator, check for&lt;br /&gt;        //validity of operator&lt;br /&gt;        if (ourOperator.equals("/") || ourOperator.equals("*") || ourOperator.equals("%")&lt;br /&gt;                || ourOperator.equals("-") || ourOperator.equals("+")){&lt;br /&gt;            //perform required operation. operator valid&lt;br /&gt;            char calc = ourOperator.charAt(0);&lt;br /&gt;            //do calculation now&lt;br /&gt;            doCalculate(calc);&lt;br /&gt;        }&lt;br /&gt;        else {&lt;br /&gt;            //ask for valid operator&lt;br /&gt;            System.out.println("Key in a valid operator please.");&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    protected static void doCalculate(final char theOperator){&lt;br /&gt;        //store in operator list&lt;br /&gt;        operatorList.add(theOperator);        &lt;br /&gt;        //if only one operand in list, wait for next input&lt;br /&gt;        //lock on stack size&lt;br /&gt;        int contains = stackList.size();&lt;br /&gt;        if (contains == 1){&lt;br /&gt;            //lock on the size&lt;br /&gt;            System.out.println("Insert next number for operation.");                   &lt;br /&gt;        }&lt;br /&gt;        else if(contains == 2){&lt;br /&gt;            compResult();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public static void compResult(){&lt;br /&gt;        //get the last two elements in the stack list&lt;br /&gt;        //get the head of the operator list&lt;br /&gt;        //do the binary operation&lt;br /&gt;        //output the result&lt;br /&gt;        //get stack list tail&lt;br /&gt;        int stackTail = stackList.remove(listCounter);&lt;br /&gt;        --listCounter;&lt;br /&gt;        int tailAfterLast = stackList.remove(listCounter);&lt;br /&gt;        --listCounter;&lt;br /&gt;        //get operator list head&lt;br /&gt;        Object opHead = operatorList.remove(0);&lt;br /&gt;        System.out.print(tailAfterLast + " " + opHead + " "+stackTail + " is = ");&lt;br /&gt;        //do the binary operation&lt;br /&gt;        //check what operator we're using first though&lt;br /&gt;        if (opHead.equals('+')){&lt;br /&gt;            tailAfterLast += stackTail;&lt;br /&gt;            System.out.println(tailAfterLast);&lt;br /&gt;            //keep the result in head of operand list&lt;br /&gt;            stackList.add(tailAfterLast);&lt;br /&gt;            ++listCounter;&lt;br /&gt;        }&lt;br /&gt;        else if (opHead.equals('-')){&lt;br /&gt;            tailAfterLast -= stackTail;&lt;br /&gt;            System.out.println(tailAfterLast);&lt;br /&gt;            //keep the result in head of operand list&lt;br /&gt;            stackList.add(tailAfterLast);&lt;br /&gt;            ++listCounter;&lt;br /&gt;        }&lt;br /&gt;        else if (opHead.equals('%')){&lt;br /&gt;            tailAfterLast %= stackTail;&lt;br /&gt;            System.out.println(tailAfterLast);&lt;br /&gt;            //keep the result in head of operand list&lt;br /&gt;            stackList.add(tailAfterLast);&lt;br /&gt;            ++listCounter;&lt;br /&gt;        }&lt;br /&gt;        else if (opHead.equals('*')){&lt;br /&gt;            tailAfterLast *= stackTail;&lt;br /&gt;            System.out.println(tailAfterLast);&lt;br /&gt;            //keep the result in head of operand list&lt;br /&gt;            stackList.add(tailAfterLast);&lt;br /&gt;            ++listCounter;&lt;br /&gt;        }&lt;br /&gt;        else if (opHead.equals('/')){&lt;br /&gt;            tailAfterLast /= stackTail;&lt;br /&gt;            System.out.println(tailAfterLast);&lt;br /&gt;            //keep the result in head of operand list&lt;br /&gt;            stackList.add(tailAfterLast);&lt;br /&gt;            ++listCounter;&lt;br /&gt;        }        &lt;br /&gt;        else {&lt;br /&gt;            System.out.println("We're going nowhere.");&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public static void main(String[] args) throws IOException{        &lt;br /&gt;        BufferedReader bufR = new BufferedReader(new InputStreamReader(System.in));&lt;br /&gt;        System.out.println("Enter any character. First character must be a number");&lt;br /&gt;        System.out.println("Enter @ to end the program.");&lt;br /&gt;        boolean keepOn = true;&lt;br /&gt;        //keep getting input until single @ entered or end of operation&lt;br /&gt;        while (keepOn){&lt;br /&gt;            //get the input from keyboard&lt;br /&gt;            String dInserted = bufR.readLine();&lt;br /&gt;            //check whether it is an operator, operand or @ sign&lt;br /&gt;            checkInput(dInserted);            &lt;br /&gt;        }&lt;br /&gt;    }    &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-3026841682573315475?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/3026841682573315475/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=3026841682573315475' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/3026841682573315475'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/3026841682573315475'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/08/can-i-count-ways-let-me.html' title='Can I Count The Ways? Let me...'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-4665139752507344677</id><published>2007-08-14T08:04:00.000-07:00</published><updated>2007-08-14T08:27:57.476-07:00</updated><title type='text'>What Angle Does Three Make?</title><content type='html'>&lt;p&gt;Am sure you guessed the answer, a triangle. Take three edges and join them by their edges, what you get is a triangle. Measure the angle if you can. We're following up on our staircase faces to build a triangle. You just have to think in alternation. How? Twist the stairs 180 degrees to the left, leave the first one remaining and voila!, you have a triangle. That's what three makes. Now four? &lt;a href="http://www.mahjongtime.com/?btag=a_12891b_3533"&gt;A Mahjong game;&lt;/a&gt; read my lips, there is even a &lt;a href="http://www.mahjongtime.com/?btag=a_12891b_3533"&gt;Mahjong messenger online.&lt;/a&gt; Officially. But if you go for poker...&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;/*&lt;br /&gt; *TRY DOING A DIAMOND AFTER THIS CODE&lt;br /&gt; *  :-)&lt;br /&gt; */&lt;br /&gt;package overall;&lt;br /&gt;&lt;br /&gt;public class AtTriangle {&lt;br /&gt;    &lt;br /&gt;    public static void main(String[] args){&lt;br /&gt;        //@ character unicode representation as char&lt;br /&gt;        char c = '\u0040';&lt;br /&gt;        //declaring our array&lt;br /&gt;        char[][] atTriangleArray;&lt;br /&gt;        //we now allocate only the rows&lt;br /&gt;        atTriangleArray = new char[6][];&lt;br /&gt;        //next the columns are allocated&lt;br /&gt;        for (int i=0; i&amp;lt;atTriangleArray.length; i++){&lt;br /&gt;            //for the six rows there are eleven columns&lt;br /&gt;            atTriangleArray[i] = new char[11];&lt;br /&gt;            //if this is the first column assign at to the &lt;br /&gt;            //6th column&lt;br /&gt;            switch(i){&lt;br /&gt;                case 0: atTriangleArray[i][5] =c; break;&lt;br /&gt;                case 1: atTriangleArray[i][4] =c; &lt;br /&gt;                        atTriangleArray[i][5] =c;&lt;br /&gt;                        atTriangleArray[i][6] =c;&lt;br /&gt;                        break;&lt;br /&gt;                case 2: atTriangleArray[i][3] =c;&lt;br /&gt;                        atTriangleArray[i][4] =c;&lt;br /&gt;                        atTriangleArray[i][5] =c;&lt;br /&gt;                        atTriangleArray[i][6] =c;&lt;br /&gt;                        atTriangleArray[i][7] =c;&lt;br /&gt;                        break;&lt;br /&gt;                case 3: atTriangleArray[i][2] =c;&lt;br /&gt;                        atTriangleArray[i][3] =c;&lt;br /&gt;                        atTriangleArray[i][4] =c;&lt;br /&gt;                        atTriangleArray[i][5] =c;&lt;br /&gt;                        atTriangleArray[i][6] =c;&lt;br /&gt;                        atTriangleArray[i][7] =c;&lt;br /&gt;                        atTriangleArray[i][8] =c;&lt;br /&gt;                        break;&lt;br /&gt;                case 4: atTriangleArray[i][1] =c;&lt;br /&gt;                        atTriangleArray[i][2] =c;&lt;br /&gt;                        atTriangleArray[i][3] =c;&lt;br /&gt;                        atTriangleArray[i][4] =c;&lt;br /&gt;                        atTriangleArray[i][5] =c;&lt;br /&gt;                        atTriangleArray[i][6] =c;&lt;br /&gt;                        atTriangleArray[i][7] =c;&lt;br /&gt;                        atTriangleArray[i][8] =c;&lt;br /&gt;                        atTriangleArray[i][9] =c;&lt;br /&gt;                        break;&lt;br /&gt;                case 5: atTriangleArray[i][0] =c;&lt;br /&gt;                        atTriangleArray[i][1] =c;&lt;br /&gt;                        atTriangleArray[i][2] =c;&lt;br /&gt;                        atTriangleArray[i][3] =c;&lt;br /&gt;                        atTriangleArray[i][4] =c;&lt;br /&gt;                        atTriangleArray[i][5] =c;&lt;br /&gt;                        atTriangleArray[i][6] =c;&lt;br /&gt;                        atTriangleArray[i][7] =c;&lt;br /&gt;                        atTriangleArray[i][8] =c;&lt;br /&gt;                        atTriangleArray[i][9] =c;&lt;br /&gt;                        atTriangleArray[i][10] = c;&lt;br /&gt;                        break;&lt;br /&gt;                default : break;&lt;br /&gt;            }            &lt;br /&gt;        }&lt;br /&gt;        for(int i=0; i&amp;lt;atTriangleArray.length;i++){&lt;br /&gt;                for(int j=0; j&amp;lt;atTriangleArray[i].length; j++){&lt;br /&gt;                    System.out.print(atTriangleArray[i][j]);&lt;br /&gt;                }&lt;br /&gt;                System.out.println();&lt;br /&gt;            }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Life is easy when you're on rails, especially when you are three: you, your girl beside you and your dog. I'd take a vacation to anywhere i'd call home. Now if you mind my &lt;a href="http://www.vacationhomerentals.com/specials.html"&gt;talking about a home,&lt;/a&gt; I've been watching the prices of some real estate here. I can tell you without blinking that they are &lt;a href="http://www.vacationhomerentals.com/specials.html"&gt;SPECIAL OFFERS&lt;/a&gt; and for you.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-4665139752507344677?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/4665139752507344677/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=4665139752507344677' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/4665139752507344677'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/4665139752507344677'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/08/what-angle-does-three-make.html' title='What Angle Does Three Make?'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-8168778315790557767</id><published>2007-08-14T07:42:00.000-07:00</published><updated>2007-08-14T08:02:38.709-07:00</updated><title type='text'>AM FEELILNG LIKE WOW!</title><content type='html'>&lt;p&gt;Just finished watching the TV and a commercial was ringing in my head: Move On Up! I really didn't understand if they were to move me up or if my savings account was to move them up, so I wrote a code for steps and ladders which if you take the initiative, you're surely going on up.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt; /* &lt;br /&gt; *we're building a staircase based on java's native handling&lt;br /&gt; *of multidimensional arrays, as arrays of arrays&lt;br /&gt; *&lt;br /&gt; */&lt;br /&gt;package overall;&lt;br /&gt;&lt;br /&gt;public class TFaces {&lt;br /&gt;        &lt;br /&gt;    public static void main(String[] args){&lt;br /&gt;        char c = '\u0040';&lt;br /&gt;        char[][] atArray;&lt;br /&gt;        //declare the 2-dim array first with only the rows&lt;br /&gt;        //columns for each row are unallocated&lt;br /&gt;        atArray = new char[5][];&lt;br /&gt;    &lt;br /&gt;        //now allocate columns for rows&lt;br /&gt;        for(int i=0; i&amp;lt;atArray.length; i++){&lt;br /&gt;            //each row has one step greater than &lt;br /&gt;            //its preceding one&lt;br /&gt;            atArray[i]= new char[i+2];&lt;br /&gt;        }&lt;br /&gt;        //initialise and print out the array&lt;br /&gt;        for(int i=0; i&amp;lt;atArray.length; i++){&lt;br /&gt;            for(int j=0; j&amp;lt;atArray[i].length; j++){&lt;br /&gt;                atArray[i][j] = c;&lt;br /&gt;                System.out.print(atArray[i][j]);                &lt;br /&gt;            }&lt;br /&gt;            System.out.println();&lt;br /&gt;        }&lt;br /&gt;    }    &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;If you can, pick as many images as you can find and put them faces on the staircases. You'll love the wow! effect. Picasa just popped out on my desktop. With picasa, you can make your computer images all searchable. Searchable. You don't need to think: where was that picture of I and Micheal taken in  1996 at Mimmy's matriculation? Nope. Picasa has it; straight in ya face! &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-8168778315790557767?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/8168778315790557767/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=8168778315790557767' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/8168778315790557767'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/8168778315790557767'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/08/am-feelilng-like-wow.html' title='AM FEELILNG LIKE WOW!'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-699630250342423783</id><published>2007-08-14T07:34:00.000-07:00</published><updated>2007-08-14T07:40:53.001-07:00</updated><title type='text'>Never Multi-thread Your System Clock 4</title><content type='html'>&lt;h3&gt;MAYBE THE FINAL SOLUTION&lt;/h3&gt;&lt;p&gt;Threads. Threads. Threads. Do you need a real nice and cool loan for a house from your best bank? Have to check your credit score first, right? Well, for this you just have to do no checking. A trip to Hawaii or to New Zealand or to Malaysia or anywhere in the world. Anywhere in the world. Is it for free? Yes, but for your time. How? Right from the labs of google comes, &lt;a href="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q=london+england&amp;ie=UTF8&amp;ll=51.50511,-0.126343&amp;spn=0.103644,0.232086&amp;z=12&amp;iwloc=addr&amp;om=1 &lt;br /&gt;"&gt;Google Maps.&lt;/a&gt; It's just absolutely wonderful. I fell in love with google maps from the word go. Go anywhere. Let's see. Why not try &lt;a href="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q=london+england&amp;ie=UTF8&amp;ll=51.50511,-0.126343&amp;spn=0.103644,0.232086&amp;z=12&amp;iwloc=addr&amp;om=1 &lt;br /&gt;"&gt;the city of London?&lt;/a&gt;&lt;br&gt;Yeah, the final solution. Back from that travel, you can use just one thread and get as much time in any time zone that you so desire. The code below diverts off the piggy-backing threads class on these aspects: I removed the constructors for time zone threads and used a single thread in the run method. Then formatted the time instance in a single method, zoned(). Therefore, within this method, I can and you can create as many time zone instances as you like. &lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;package overall;&lt;br /&gt;&lt;br /&gt;import java.text.DateFormat;&lt;br /&gt;import java.util.Date;&lt;br /&gt;import java.util.SimpleTimeZone;&lt;br /&gt;&lt;br /&gt;public class SingleThread implements Runnable {&lt;br /&gt;    &lt;br /&gt;    public void run() {&lt;br /&gt;        //the limit on time&lt;br /&gt;        final long LIMIT = 1000*60*5;&lt;br /&gt;        //guard on time spent doing this shit&lt;br /&gt;        long timeSpent = 0;&lt;br /&gt;        //present time guard&lt;br /&gt;        Date dater = new Date();&lt;br /&gt;        //we'll catch an exception on this computation&lt;br /&gt;        try{&lt;br /&gt;            while(timeSpent &lt; LIMIT){&lt;br /&gt;                //call the time formatter &lt;br /&gt;                zoned();&lt;br /&gt;                //sleep three second&lt;br /&gt;                Thread.sleep(1000*3);&lt;br /&gt;                //update the system time&lt;br /&gt;                Date now = new Date();&lt;br /&gt;                //compute time difference between start and now&lt;br /&gt;                timeSpent = now.getTime() - dater.getTime();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        //catch any exception please&lt;br /&gt;        catch(Exception e){&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    protected void zoned(){&lt;br /&gt;        //an hour of time&lt;br /&gt;        long oneHour = 1000*60*60;&lt;br /&gt;        //get the date formatter&lt;br /&gt;        DateFormat formatter = DateFormat.getTimeInstance();&lt;br /&gt;        //declare the time zone. set initially to utc&lt;br /&gt;        SimpleTimeZone simp = new SimpleTimeZone((int)oneHour*0, "UTC");&lt;br /&gt;        //set the timezone of our dates to utc&lt;br /&gt;        formatter.setTimeZone(simp);&lt;br /&gt;        //print out the utc time at this moment in time&lt;br /&gt;        System.out.println("Time in UTC (London) is: "+ formatter.format(new Date()));&lt;br /&gt;        //set the time zone to hawaii time&lt;br /&gt;        simp.setID("HST");&lt;br /&gt;        simp.setRawOffset((int)oneHour*10);&lt;br /&gt;        formatter.setTimeZone(simp);&lt;br /&gt;        System.out.println("Time in HST (Hawaii) is: "+formatter.format(new Date()));&lt;br /&gt;        //set time zone new zealand time&lt;br /&gt;        simp.setID("NST"); //new zealand standard time&lt;br /&gt;        simp.setRawOffset(-(int)oneHour*12);&lt;br /&gt;        formatter.setTimeZone(simp);&lt;br /&gt;        System.out.println("Time in NST (Fiji) is: "+formatter.format(new Date()));&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public static void main(String[] args){&lt;br /&gt;        //declare an instance of our time&lt;br /&gt;        SingleThread instar = new SingleThread();&lt;br /&gt;        //call its thread&lt;br /&gt;        Thread t = new Thread(instar);&lt;br /&gt;        //start the thread&lt;br /&gt;        t.start();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;When I was young, we piggy-backed to get into the movie theater. This is how: A buys the ticket for the film, enters theater, the innocent one, wraps ticket on his pen, runs to the first floor of the building and throws it to B. Yeah, the ticket's already marked but the film house has a toilet that is at the outside. If B has a good tongue and can give and take shit, B can enter and so can C, and so can D, and so... The timing just has to be right. Piggy-backing and fond memories...!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-699630250342423783?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/699630250342423783/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=699630250342423783' title='138 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/699630250342423783'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/699630250342423783'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/08/never-multi-thread-your-system-clock-5.html' title='Never Multi-thread Your System Clock 4'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>138</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-1559577740040816886</id><published>2007-07-28T11:40:00.000-07:00</published><updated>2007-07-28T12:01:06.639-07:00</updated><title type='text'>Never Multi-Thread Your System Clock 3</title><content type='html'>&lt;h4 align="center"&gt;A FAIR ENOUGH IMPLEMENTAION.&lt;/h4&gt;&lt;p&gt;Am sure you did read the first blog on this topic? Let me remind you a point from it: any number of men can pass through a door which is supposed to allow only one man at any time if they can all piggyback into the door, provided the height of the door is sufficient to take as much piggybackers. &lt;br&gt;I can implement piggybacking for this time zone problem by creating three separate threads for each time zone, such that the first thread calls the second and the second calls the third. You can create any number of time zone references this mind. &lt;b&gt;&lt;a href="http://www.mahjongtime.com/"&gt;Like the Mahjong game, you can even create four.&lt;/a&gt;&lt;/b&gt; But caution! Sshhh... read to the end first. This thread calling is best done with ThreadGroups. A ThreadGroup makes it possible that where one thread gets interrupted or a parent thread gets interrupted, all the threads die together. &lt;br&gt;Now for the code. For a challenge, write a third thread that is declared in the second thread or the Hawaii standard time thread in the code below.  &lt;br /&gt;&lt;/p&gt;&lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;google_ad_client = "pub-9881297527037360";&lt;br /&gt;google_ad_width = 468;&lt;br /&gt;google_ad_height = 60;&lt;br /&gt;google_ad_format = "468x60_as";&lt;br /&gt;google_cpa_choice = "CAEQABoIE9nBkxgRyqQozNnUjgE";&lt;br /&gt;//--&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import java.lang.*;&lt;br /&gt;import java.util.*;&lt;br /&gt;import java.text.*;&lt;br /&gt;&lt;br /&gt;public class FairEnough implements Runnable {&lt;br /&gt;    String dZone = "Local";&lt;br /&gt;    //every thread exists in a group such that &lt;br /&gt;    //they all die together&lt;br /&gt;    ThreadGroup dGroup = new ThreadGroup("myGroup");&lt;br /&gt;    //the time zones am going to use, simp for UTC and &lt;br /&gt;    //zHst for Hawaii Standard Time.&lt;br /&gt;    SimpleTimeZone simp = null;&lt;br /&gt;    SimpleTimeZone zHst = null;&lt;br /&gt;    //computing this long now prevents future recursive &lt;br /&gt;    //computing&lt;br /&gt;    long oneHour = 1000*60*60;&lt;br /&gt;    &lt;br /&gt;    /** Creates a new instance of FairEnough */&lt;br /&gt;    public FairEnough(String zoner) {&lt;br /&gt;        //if string is utc, run utc else if hst run hst&lt;br /&gt;        if (zoner == "UTC"){&lt;br /&gt;            this.dZone = zoner;&lt;br /&gt;            //set the time zone to utc&lt;br /&gt;            simp = new SimpleTimeZone((int)oneHour*0, dZone);&lt;br /&gt;            //create the utc thread in a a thread group and start it&lt;br /&gt;            Thread utc = new Thread(dGroup, this);&lt;br /&gt;            //start our thread&lt;br /&gt;            utc.start();&lt;br /&gt;            //utc  object now calls the hst object&lt;br /&gt;            FairEnough second = new FairEnough("HST");            &lt;br /&gt;        }else{&lt;br /&gt;            //this here is constructor code for hst object&lt;br /&gt;            this.dZone = "HST";&lt;br /&gt;            zHst = new SimpleTimeZone((int)oneHour*10, dZone);&lt;br /&gt;            //create hst thread&lt;br /&gt;            Thread hst = new Thread(dGroup, this);&lt;br /&gt;            hst.start();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    //the run method defines the thread itself. &lt;br /&gt;    public void run() {&lt;br /&gt;        //LIMIT means i don't want this thread to run for&lt;br /&gt;        //more than five minutes&lt;br /&gt;        long LIMIT = 1000*60*5;&lt;br /&gt;        //this is the guard on five minutes limit&lt;br /&gt;        long timeSpent = 0;&lt;br /&gt;        //this is the guard on timer, reference to the&lt;br /&gt;        //instance in time when run started, +/- nanoseconds&lt;br /&gt;        Date dater = new Date();&lt;br /&gt;        //our thread could be interrupted, so let's put&lt;br /&gt;        //it in a try&lt;br /&gt;        try{&lt;br /&gt;            while(timeSpent &lt; LIMIT ){&lt;br /&gt;                //create date formatter formatting only time&lt;br /&gt;                DateFormat formatter = DateFormat.getTimeInstance();&lt;br /&gt;                //specify time zone to use&lt;br /&gt;                if(this.dZone == "UTC"){&lt;br /&gt;                    formatter.setTimeZone(simp);&lt;br /&gt;                }else if(this.dZone == "HST"){&lt;br /&gt;                    formatter.setTimeZone(zHst);&lt;br /&gt;                }       &lt;br /&gt;                //print out our time&lt;br /&gt;                System.out.println(this.dZone +" time is "+formatter.format(new Date()));&lt;br /&gt;                //sleep 3 seconds&lt;br /&gt;                Thread.sleep(1000*3);&lt;br /&gt;                //update system time&lt;br /&gt;                Date now = new Date();&lt;br /&gt;                //compute the time spent doing this stuff&lt;br /&gt;                timeSpent = now.getTime() - dater.getTime();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        catch(Exception e){&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public static void main(String[] args){&lt;br /&gt;        //specify time zone to start with. if utc or hst.&lt;br /&gt;        //use upper case please!!Mine!!&lt;br /&gt;        FairEnough fair = new FairEnough("UTC");&lt;br /&gt;    }   &lt;br /&gt;}&lt;/pre&gt;&lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;google_ad_client = "pub-9881297527037360";&lt;br /&gt;google_ad_width = 336;&lt;br /&gt;google_ad_height = 280;&lt;br /&gt;google_ad_format = "336x280_as";&lt;br /&gt;google_cpa_choice = "CAEQ6P787wEaCMVnn0MJu2OiKIT0jYMB";&lt;br /&gt;//--&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;br /&gt;&lt;/script&gt;&lt;p&gt;Caution: I ran the code above on a 1.2 Ghz Pentium III Intel and was my puter humming all the time. Not to worry, he's just complaining to deaf ears. That goes to show you that this is not a very good candidate for implementing this concept, just a solution just made it. If you're really that bold, try getting &lt;b&gt;&lt;a href="http://www.symplisit.com/en/drivermagic.html"&gt;driver magic &lt;/a&gt;&lt;/b&gt;if you're experimenting with clocks and threads first.  &lt;br&gt;In my magic bag is a simple, affordable solution that you'll make use of and your puter wouldn't realise you came into its machine space. Ready for the last and final blog on this topic? I sure am. &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-1559577740040816886?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/1559577740040816886/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=1559577740040816886' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/1559577740040816886'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/1559577740040816886'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/07/never-multi-thread-your-system-clock-3.html' title='Never Multi-Thread Your System Clock 3'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-3403471014490756844</id><published>2007-07-28T07:29:00.000-07:00</published><updated>2008-12-11T02:01:48.926-08:00</updated><title type='text'>Never Multi-thread Your System Clock 2</title><content type='html'>&lt;h4 align="center"&gt;HOW NOT TO GO ABOUT IT.&lt;/h4&gt;&lt;p&gt;A little on threading. A thread is like a process that is running inside another process. Imagine the wheels of your car running when the car starts. But never imagine &lt;b&gt;&lt;a href="http://www.mimousa.com"&gt;the beautiful baby &lt;/a&gt;&lt;/b&gt;on the left could ever be yours. Now, in Java programming, when a thread wants to access or reference a variable, it has to acquire the lock on the object or variable, which we'll refer to here as its monitor. And no two threads can acquire the same lock on a monitor. Rather, if a thread wants the lock on a monitor and another thread has it, it has to wait for that owner thread to release the lock first. &lt;/p&gt;&lt;br /&gt;&lt;script type="text/javascript" language="Javascript"&gt;&lt;br /&gt;function whenClicked()&lt;br /&gt;{&lt;br /&gt;window.open("http://www.mimousa.com/");&lt;br /&gt;}&lt;br /&gt;function anotherClick()&lt;br /&gt;{&lt;br /&gt;window.open("http://www.thehealthstore.co.nz/");&lt;br /&gt;}&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;google_ad_client = "pub-9881297527037360";&lt;br /&gt;google_ad_width = 468;&lt;br /&gt;google_ad_height = 60;&lt;br /&gt;google_ad_format = "468x60_as";&lt;br /&gt;google_cpa_choice = "CAEQ8u7Q4QIaCGB5bZHLVomnKLbXkqQB";&lt;br /&gt;//--&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_-vb8zdpkvpo/RqtTFTU6KQI/AAAAAAAAAAs/iNEQwB-nj94/s1600-h/vdoors.jpg"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_-vb8zdpkvpo/RqtTFTU6KQI/AAAAAAAAAAs/iNEQwB-nj94/s320/vdoors.jpg" border="0" alt="I love small cars"id="BLOGGER_PHOTO_ID_5092255154224900354" longdesc="http://www.mimousa.com" onclick="whenClicked()"/&gt;&lt;/a&gt; &lt;br /&gt;&lt;p&gt; Our clock has to be in three time zones, one in the New Zealand Standard time, another in Universal Time and the other in Hawaii Standard Time. It looks simple to just create separate threads, taking from our example in the first blog for this title. No, creating three threads for the three time zones will not necessarily run. There are issues to consider. &lt;/p&gt;&lt;p&gt; Issue of monitor locking. If we have say three threads, thread A, B and C and A starts executing first. Other threads have to wait for it but they have already been called to start. There is no way we should expect B and C to return the same time as A. Clocking is dynamic and time never waits for any man. The error reporting chain gets propagated indefinitely as B gets the baton and as C acquires a subsequent lock. &lt;/p&gt;&lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;google_ad_client = "pub-9881297527037360";&lt;br /&gt;google_ad_width = 300;&lt;br /&gt;google_ad_height = 250;&lt;br /&gt;google_ad_format = "300x250_as";&lt;br /&gt;google_cpa_choice = "CAEQz9XM4gMaCPYjjELu3zkUKIuKsOMB";&lt;br /&gt;//--&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;br /&gt;&lt;/script&gt;&lt;b&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_-vb8zdpkvpo/RqtUCTU6KRI/AAAAAAAAAA0/x_KQN2aFnIM/s1600-h/100x262.44444444444_images_PMH009-Herbal-Throat-Formula-50ml.jpg"&gt;&lt;img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_-vb8zdpkvpo/RqtUCTU6KRI/AAAAAAAAAA0/x_KQN2aFnIM/s320/100x262.44444444444_images_PMH009-Herbal-Throat-Formula-50ml.jpg" border="0" alt="Fighting with your throat? It stops right here."id="BLOGGER_PHOTO_ID_5092256202196920594" longdesc="http://www.thehealthstore.co.nz/" onclick="anotherClick()"/&gt;&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;p&gt; Issue of thread sleeping. It would seem some solution to ask A to sleep and pass the baton to B and then to C and then to receive the baton or lock later. That was what we would all assume the normal should be. But this is no solution at all because if thread A enters a sleep state, are we sure it will ever recover from one? Will it not sleep forever? Let's say, A starts sleeping, to sleep for 1 second. B begins to run and then enters a sleep that lasts for also one second. Are we not to assume that A and B will ask for the lock at the same instance? Even if they have to sleep for any second at all! Both threads will have to eventually fight for the lock. We are setting the stage for a fight on the system time or our monitor. If B wins, A ends up fighting with C. Will A win? As in life and in threading, no thread can fight for long. One would give up and throw an interrupted exception and stop executing. So, why not put a usage clause on our thread. Imagine that! We'd rather never have to implement a thread in the first place.&lt;/p&gt;&lt;p&gt; But we'll never give up here. There's a solution for our threading problem. I found on the bottle to your right &lt;a href="http://thehealthstore.co.nz/"&gt;a natural solution to a throat problem,&lt;/a&gt; and it's the New Zealand way. That was while googling on New Zealand. In a new way, I'll demonstrate two ways this problem can be solved.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-3403471014490756844?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/3403471014490756844/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=3403471014490756844' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/3403471014490756844'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/3403471014490756844'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/07/never-multi-thread-your-system-clock-2.html' title='Never Multi-thread Your System Clock 2'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_-vb8zdpkvpo/RqtTFTU6KQI/AAAAAAAAAAs/iNEQwB-nj94/s72-c/vdoors.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-2223379164377094479</id><published>2007-07-26T04:00:00.000-07:00</published><updated>2007-07-26T04:04:58.912-07:00</updated><title type='text'>NEVER MULTI-THREAD YOUR SYSTEM CLOCK</title><content type='html'>&lt;h4 style="text-align:center"&gt;THE BREEZE SECTION.&lt;/h4&gt; &lt;br /&gt;If three men have to pass through a door that can take only one, how many men can pass through at  any one time?&lt;br&gt; &lt;br /&gt;“Hey, you? ”&lt;br&gt;&lt;br /&gt;“One.”&lt;p&gt;&lt;br /&gt;“Why one?”&lt;br&gt;&lt;!-- put ad here --&gt;&lt;p&gt;That's the question, why only one? Can't they piggyback through the door, like the one in front having another on his back and another on his back and another ad infinitum, provided the height of the door can accommodate as many? Well, convention and dynamism are two ends of the same stick. The longer one stays it becomes the other.&lt;/p&gt; &lt;br /&gt;&lt;p&gt;Now before we enter the door of seriosity, &lt;a href="http://www.theteafarm.com/"&gt;&lt;b&gt;I'll like to unwind with a cup of Chinese tea.&lt;/b&gt;&lt;/a&gt; I like the ginseng blend. Which do you prefer? Choose yours. &lt;/p&gt;&lt;p&gt;&lt;br /&gt;I had this question thrown to me recently: How can one implement three threads such that they reference the same time while preventing deadlock and other issues known with threads. &lt;br /&gt;&lt;br /&gt;What would you answer? As they always say, &lt;acronym title="Keep It Simple, Stupid. Being intrigued about who brought that acro up." style="color:#9900FF"&gt;KISS.&lt;/acronym&gt; Keep it simple, stupid. So I decided to write a simple class that displays just one time, just one thread, my system time converted to UTC time. Foremost on my mind was what the thread was going to do: simple, just update my system time, convert it to Universal Time and format it in a simple human-readable format.&lt;br /&gt;&lt;/p&gt;&lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;google_ad_client = "pub-9881297527037360";&lt;br /&gt;google_ad_width = 468;&lt;br /&gt;google_ad_height = 60;&lt;br /&gt;google_ad_format = "468x60_as";&lt;br /&gt;google_cpa_choice = "";&lt;br /&gt;//--&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import java.text.DateFormat;&lt;br /&gt;import java.util.*;&lt;br /&gt;import java.lang.*;&lt;br /&gt;&lt;br /&gt;public class Availables implements Runnable {&lt;br /&gt;    &lt;br /&gt;    DateFormat firstFormatter; &lt;br /&gt;    &lt;br /&gt;    public void run() {&lt;br /&gt;        //get my present instance&lt;br /&gt;        Date date = new Date();&lt;br /&gt;        //an a simple utc time zone converter&lt;br /&gt;        SimpleTimeZone utcZone = new SimpleTimeZone(0, "UTC");&lt;br /&gt;        //i don't want this timer to run just five minutes&lt;br /&gt;        final long LIMIT = 1000*60*5;&lt;br /&gt;        //then i'll set a time guard on our time&lt;br /&gt;        long timeSpent = 0;&lt;br /&gt;        //while the thread is running, i expect to receive an &lt;br /&gt;        //interrupted exception. maybe from my puter&lt;br /&gt;        try{&lt;br /&gt;            //what next? until five minutes runs out&lt;br /&gt;            while(timeSpent &lt; LIMIT){&lt;br /&gt;                //set the time zone for our time&lt;br /&gt;                firstFormatter = DateFormat.getTimeInstance();&lt;br /&gt;                firstFormatter.setTimeZone(utcZone);&lt;br /&gt;                //print out what the present time is&lt;br /&gt;                System.out.println(firstFormatter.format(new Date()));&lt;br /&gt;                //ask the thread to sleep for 3s seconds, to&lt;br /&gt;                //simulate a real timer&lt;br /&gt;                Thread.sleep(1000*3);&lt;br /&gt;                //update our thread, compute the elapsed time&lt;br /&gt;                Date now = new Date();&lt;br /&gt;                timeSpent = now.getTime()- date.getTime();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        catch(InterruptedException e){&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        }&lt;br /&gt;        //little checker. unecessary, but you never can tell&lt;br /&gt;        if (Thread.interrupted()){System.out.println("Finished.");}&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public static void main(String[] args){&lt;br /&gt;        Availables newbie = new Availables();&lt;br /&gt;        Thread tre = new Thread(newbie);&lt;br /&gt;        tre.start();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;google_ad_client = "pub-9881297527037360";&lt;br /&gt;google_ad_width = 336;&lt;br /&gt;google_ad_height = 280;&lt;br /&gt;google_ad_format = "336x280_as";&lt;br /&gt;google_cpa_choice = "";&lt;br /&gt;//--&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;Now, how about the other threads that had to show different time zones, say Hawaii standard time or New Zealand Standard Time? And to talk of Hawaii, if you had to choose between a &lt;a href="http://www.vacationhomerentals.com/vacation-rentals/Hutchinson-Island-Florida-Hutchinson-Island-Townhouse-Rental-proID-28902.html"&gt;&lt;b&gt;special Home in Florida &lt;/b&gt;&lt;/a&gt;and a week in Hawaii, which would it be. I saw this&lt;a href="http://www.vacationhomerentals.com/vacation-rentals/Hutchinson-Island-Florida-Hutchinson-Island-Townhouse-Rental-proID-28902.html"&gt;&lt;b&gt; lovely house,&lt;/b&gt;&lt;/a&gt; and my, did i fall in love with it. Would you still go to Hawaii? &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-2223379164377094479?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/2223379164377094479/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=2223379164377094479' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/2223379164377094479'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/2223379164377094479'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/07/never-multi-thread-your-system-clock.html' title='NEVER MULTI-THREAD YOUR SYSTEM CLOCK'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-3476614047243896227</id><published>2007-07-23T06:35:00.000-07:00</published><updated>2007-07-25T02:08:50.394-07:00</updated><title type='text'>DOES A PICTURE SAY A THOUSAND WORDS 3?</title><content type='html'>&lt;p&gt;I won't bore you any longer with steps  to take, you already know them. After the &lt;a href="http://genericjava.blogspot.com/2007/07/does-picture-really-say-thousand-words.html"  name="first"&gt;First&lt;/a&gt; and &lt;a name="second" href="http://genericjava.blogspot.com/2007/07/does-picture-say-thousand-words-2.html"&gt;Second&lt;/a&gt; blog on this topic, this here is the last and am sure you'll appreciate coming here. The javax.imageio package provides a  custom decoder (what I thought the CharsetDecoder class would do for  me!) through the ImageIO class. &lt;br /&gt;&lt;br/&gt;This here is the code. Before Coding, have you played some high performance games lately?&lt;/p&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;google_ad_client = "pub-9881297527037360";&lt;br /&gt;google_ad_width = 1000;&lt;br /&gt;google_ad_height = 90;&lt;br /&gt;google_ad_format = "728x90_as";&lt;br /&gt;google_cpa_choice = "CAEQ2MTxgAQaCDIpqGbGvCxvKNi55qUC";&lt;br /&gt;//--&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;  &lt;pre&gt;&lt;br /&gt;  package examples;&lt;br /&gt;  &lt;br /&gt;  import javax.imageio.*;&lt;br /&gt;  import java.awt.image.*;&lt;br /&gt;  import java.io.*;&lt;br /&gt;  &lt;br /&gt;  public class Byter {&lt;br /&gt;   &lt;br /&gt;   BufferedImage buffer;&lt;br /&gt;   File f;&lt;br /&gt;   &lt;br /&gt;   protected void doThis(){&lt;br /&gt;    try{&lt;br /&gt;     //grab the file in a file reference, handle exception also&lt;br /&gt;     f = new File("amelipassport.jpg");&lt;br /&gt;     //use a static method read of ImageIO to buffer file&lt;br /&gt;     buffer = ImageIO.read(f);&lt;br /&gt;     //test buffer. You'll get two results, the ColorModel and Raster&lt;br /&gt;     //try and see&lt;br /&gt;     System.out.println(buffer.toString());&lt;br /&gt;    }&lt;br /&gt;    catch(IOException e){&lt;br /&gt;     e.printStackTrace();&lt;br /&gt;     System.err.println("File not found");&lt;br /&gt;    }&lt;br /&gt;    finally{&lt;br /&gt;     //finally call the raster for character rep. &lt;br /&gt;     //of the pixels in each cell. int returned by getRGB is 8 bits&lt;br /&gt;     for (int i=0; i&lt;314;i++){&lt;br /&gt;      for(int j=0; j&lt;274; j++){&lt;br /&gt;       System.out.print(buffer.getRGB(j,i)+",");&lt;br /&gt;      }&lt;br /&gt;      System.out.println();&lt;br /&gt;     }&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;  &lt;br /&gt;   public static void main(String[] args){&lt;br /&gt;    Byter by = new Byter();&lt;br /&gt;    by.doThis();&lt;br /&gt;   }&lt;br /&gt;   &lt;br /&gt;  }&lt;br /&gt;  &lt;/pre&gt;&lt;br /&gt;        &lt;p&gt;little challenge: send the output of  Sysout to a &amp;ldquo;.txt&amp;rdquo; file and you'll see the table arrangement of  the character representation of the colors you saw in the picture  above.&lt;br /&gt;&lt;br/&gt;A picture doesn't say a thousand words,  you'll never understand them unless you know the language it was  speaking in.&lt;br /&gt;&lt;br/&gt;When the code ran, what I read from the output was that the picture has two components, a ColorModel and a Raster of image data. The results i got for the young beautiful dark african in the picture above is: This image is one of 8 bits in RGB colors, in windows style BGR color model with Red, Green and Blue of 3 bytes. There is no alpha value in the picture because this is false. The picture is set to 100% transparency and has a width of 274 pixels with a height of 314 pixels. &lt;br /&gt;Try your hands on any picture of your choice and try reading what was said. &lt;br /&gt;&lt;br/&gt;But for sure, appreciate colors,  appreciate beauty and appreciate the picture even if the language seems difficult for you to understand. &lt;/p&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;google_ad_client = "pub-9881297527037360";&lt;br /&gt;google_ad_width = 1200;&lt;br /&gt;google_ad_height = 90;&lt;br /&gt;google_ad_format = "728x90_as";&lt;br /&gt;google_cpa_choice = "CAEQ2MTxgAQQABoIRxScQkDEK3Uo2LnmpQIozNnUjgE";&lt;br /&gt;//--&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;br /&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-3476614047243896227?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/3476614047243896227/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=3476614047243896227' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/3476614047243896227'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/3476614047243896227'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/07/does-picture-say-thousand-words-3.html' title='DOES A PICTURE SAY A THOUSAND WORDS 3?'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-3888923776058698483</id><published>2007-07-23T06:16:00.000-07:00</published><updated>2007-07-25T02:12:49.434-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='image input/output'/><category scheme='http://www.blogger.com/atom/ns#' term='standards'/><category scheme='http://www.blogger.com/atom/ns#' term='african girl'/><category scheme='http://www.blogger.com/atom/ns#' term='javax'/><category scheme='http://www.blogger.com/atom/ns#' term='bufferedinputstream'/><title type='text'>DOES A PICTURE SAY A THOUSAND WORDS 2?</title><content type='html'>&lt;p&gt;Faced with the task of decoding that &lt;a href="http://genericjava.blogspot.com/2007/07/does-picture-really-say-thousand-words.html"&gt;picture of a young african girl&lt;/a&gt;, I said to myself, small fry.  It'll be handled in a breeze. After I finished writing the first blog  of this series, I went outside to the fresh air, drank some water and  popped some gums into my mouth. How long should this take me? An  hour, two, or three at most. Trust me, this is work just for a  Gothamite.&lt;br /&gt;  &lt;br/&gt;First course of action : I'd grab the  image files through a Bufferedinputstream, decode the files using the  default charset decoder and maybe a decoder also of the utf-8 charset  and then write the decoded data out through a BufferedWriter. That  should do it. I'd get a character representation of the image data.  So, I set out coding and this is what i wrote. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;Standards are what we'll be living by in our codes, like engineering standards, Web standards...etc&lt;/p&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;google_ad_client = "pub-9881297527037360";&lt;br /&gt;google_ad_width = 728;&lt;br /&gt;google_ad_height = 90;&lt;br /&gt;google_ad_format = "728x90_as";&lt;br /&gt;google_cpa_choice = "CAEQ2MTxgAQQABAAEAAaCAbTpTAn_HkCKNi55qUCKMzZ1I4BKLyXzdMBKL6Zlb4B";&lt;br /&gt;//--&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;  &lt;pre&gt;&lt;br /&gt;  package examples;&lt;br /&gt;  &lt;br /&gt;  import java.io.*;&lt;br /&gt;  import java.nio.BufferOverflowException;&lt;br /&gt;  import java.nio.ByteBuffer;&lt;br /&gt;  import java.nio.CharBuffer;&lt;br /&gt;  import java.nio.charset.*;&lt;br /&gt;  &lt;br /&gt;  public class Tunes {&lt;br /&gt;   &lt;br /&gt;   CharBuffer charBuf;&lt;br /&gt;   ByteBuffer byteBuf;&lt;br /&gt;   BufferedInputStream bin = null; &lt;br /&gt;   //writer wasn't called. i used Sysout to look ahead.&lt;br /&gt;   BufferedWriter bufWriter;&lt;br /&gt;   String strChar;&lt;br /&gt;   //default character set for my machine is windows-1252.&lt;br /&gt;   //tried default and also utf-8&lt;br /&gt;   Charset cs = Charset.defaultCharset(); &lt;br /&gt;   byte[] toUse;&lt;br /&gt;   public void doFinal() throws FileNotFoundException,IOException {&lt;br /&gt;    try{&lt;br /&gt;     //create a buffered file inputstream&lt;br /&gt;     bin = new BufferedInputStream(new FileInputStream("amelipassport.jpg"));&lt;br /&gt;     //we want to use the default character encoding &lt;br /&gt;     //and the default byte buffer size&lt;br /&gt;     //we'll use a file writer on a file output stream'&lt;br /&gt;     bufWriter = new BufferedWriter (new FileWriter("writeout.txt"));&lt;br /&gt;     int c;  // check on int returned by file read&lt;br /&gt;     //provided there are data in the file, &lt;br /&gt;     //keep reading your file and writing to output until &lt;br /&gt;     //you get to end of file&lt;br /&gt;     toUse = new byte[bin.available()];&lt;br /&gt;     while ((c =bin.read(toUse)) != -1){&lt;br /&gt;      byteBuf = ByteBuffer.wrap(toUse); //i have a byte buffer now&lt;br /&gt;      charBuf = byteBuf.asCharBuffer();&lt;br /&gt;     }            &lt;br /&gt;    }&lt;br /&gt;    finally{&lt;br /&gt;      //call the charset decoder reset method&lt;br /&gt;      Tunes newTunes = new Tunes();&lt;br /&gt;      //i used a helper class, HelpDecode &lt;br /&gt;      Tunes.HelpDecode helpDecode = newTunes.new HelpDecode();&lt;br /&gt;      //follow api instructions to letter. first reset(), decode(), &lt;br /&gt;      //final decode(), then flush()&lt;br /&gt;      helpDecode.reset();&lt;br /&gt;      CoderResult coder = helpDecode.decode(byteBuf, charBuf,true); &lt;br /&gt;      //never used the buffer writer since i had to lookahead on&lt;br /&gt;      //what my machine was supposed to do&lt;br /&gt;      //decode returned malformed&lt;br /&gt;      //input byte sequence not legal for this character set, &lt;br /&gt;      //even on utf-8&lt;br /&gt;      System.out.println(coder.toString());  &lt;br /&gt;      coder = helpDecode.flush(charBuf);&lt;br /&gt;      System.out.println(coder.toString());&lt;br /&gt;      System.out.println(charBuf.toString());&lt;br /&gt;      //close all your two streams if any is still open&lt;br /&gt;      if (bin != null) {bin.close();}     &lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;   &lt;br /&gt;   //helper class HelpDecode extends CharsetDecoder&lt;br /&gt;   private class HelpDecode extends CharsetDecoder{&lt;br /&gt;    protected HelpDecode(){&lt;br /&gt;     //let max and avg charsperbyte be similar&lt;br /&gt;     super(cs, 255.0f, 255.0f);&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {&lt;br /&gt;     //used underflow as a check on result&lt;br /&gt;     return CoderResult.UNDERFLOW;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;   }&lt;br /&gt;   public static void main(String[] args) &lt;br /&gt;                     throws FileNotFoundException, IOException  {&lt;br /&gt;    Tunes nTunes = new Tunes();&lt;br /&gt;    nTunes.doFinal();&lt;br /&gt;   }   &lt;br /&gt;  }&lt;br /&gt;  &lt;/pre&gt;&lt;br /&gt; &lt;p&gt;From the code above you should realise  that I can't decode the image file that way. It's not possible. I  took a step from the code and asked myself: &amp;ldquo;what erroneous  presumptions do I have about decoding this file?&amp;rdquo;&lt;br /&gt;&lt;br /&gt;One, the &amp;ldquo;.jpg&amp;rdquo; file can be  referenced by a File object.&lt;br/&gt;Two, image files should be binary data. &lt;br /&gt;&lt;br/&gt;The decoding process just can't do what  I want it to do and by the way, my decoder class that was supposed to  inherit from CharsetDecoder doesn't inherit any method that reads  bytes and decodes them straight to char values, just as I expected. &lt;br /&gt;&lt;br/&gt;Bad day. There goes my lunch. There  must be a way. &lt;br /&gt;&lt;br/&gt;Yes there is. I found one late at  night. The java.awt.image package and the javax.imageio packages have  just what I wanted. They can even decode images. Great. I had to write the &lt;a href="http://genericjava.blogspot.com/2007/07/does-picture-say-thousand-words-3.html"&gt;third and definitive&lt;/a&gt; piece just for you.&lt;/p&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;google_ad_client = "pub-9881297527037360";&lt;br /&gt;google_ad_width = 728;&lt;br /&gt;google_ad_height = 90;&lt;br /&gt;google_ad_format = "728x90_as";&lt;br /&gt;google_cpa_choice = "CAEQ2MTxgAQQABAAGghwvjNjQ7cRrijYuealAijM2dSOASi8l83TAQ";&lt;br /&gt;//--&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;br /&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-3888923776058698483?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://genericjava.blogspot.com/2007/07/does-picture-really-say-thousand-words.html' title='DOES A PICTURE SAY A THOUSAND WORDS 2?'/><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/3888923776058698483/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=3888923776058698483' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/3888923776058698483'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/3888923776058698483'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/07/does-picture-say-thousand-words-2.html' title='DOES A PICTURE SAY A THOUSAND WORDS 2?'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-4073263333822856505</id><published>2007-07-20T03:52:00.000-07:00</published><updated>2008-12-11T02:01:49.132-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='api'/><category scheme='http://www.blogger.com/atom/ns#' term='binary file'/><category scheme='http://www.blogger.com/atom/ns#' term='buffer'/><category scheme='http://www.blogger.com/atom/ns#' term='buffer stream'/><title type='text'>DOES A PICTURE REALLY SAY A THOUSAND WORDS?</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_-vb8zdpkvpo/RqCWmnvi4VI/AAAAAAAAAAk/jsazjwiY82E/s1600-h/amelipassport.jpg"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;" src="http://3.bp.blogspot.com/_-vb8zdpkvpo/RqCWmnvi4VI/AAAAAAAAAAk/jsazjwiY82E/s320/amelipassport.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5089233169176256850" /&gt;&lt;/a&gt;&lt;p&gt;I took a look at a picture, a picture  of a young beautiful dark african lady on my laptop and decided, what  if i see how the computer translates this simple picture into text.  What would the computer say about this lady? I had to go about it. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;I delved into the Java API and was  told, just read the image binary file, buffer the input stream and  then write it out in another buffered output stream. Pronto. I  checked the java tutorials and was told the same story. Just do that  and you'll be fine. So i tried it and am giving you the result.&lt;br/&gt;If you love chinese games, you really might be interested in &lt;a href="http://www.4windsmj.com/"&gt;Mahjong.&lt;/a&gt; There is also one for PocketPCs. &lt;/p&gt;&lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;google_ad_client = "pub-9881297527037360";&lt;br /&gt;google_ad_width = 728;&lt;br /&gt;google_ad_height = 90;&lt;br /&gt;google_ad_format = "728x90_as";&lt;br /&gt;google_cpa_choice = "CAEQ2MTxgAQQABoIRxScQkDEK3Uo2LnmpQIozNnUjgE";&lt;br /&gt;//--&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;pre style="font-size:12px"&gt;&lt;br /&gt; package examples;&lt;br /&gt;  &lt;br /&gt; import java.io.BufferedInputStream;&lt;br /&gt; import java.io.BufferedOutputStream;&lt;br /&gt; import java.io.*;&lt;br /&gt;  &lt;br /&gt; public class Google {&lt;br /&gt;  BufferedInputStream bin;&lt;br /&gt;  BufferedOutputStream bout;&lt;br /&gt;   &lt;br /&gt;  public void doingThis() throws FileNotFoundException, IOException{&lt;br /&gt;   try{&lt;br /&gt;    //create the input stream&lt;br /&gt;    bin = new BufferedInputStream(new      &lt;br /&gt;                                     FileInputStream(&amp;quot;amelipassport.jpg&amp;quot;));&lt;br /&gt;    //create the output stream&lt;br /&gt;    bout = new BufferedOutputStream(new &lt;br /&gt;                                     FileOutputStream(&amp;quot;pix2words.txt&amp;quot;));&lt;br /&gt;    //now there's this int type that i'll use to read the &lt;br /&gt;                                //bytes coming from the buffered input stream&lt;br /&gt;    int c;&lt;br /&gt;    //we'll keep reading the stream and writing to output&lt;br /&gt;    //until we each end of file, eof&lt;br /&gt;    while((c = bin.read()) != -1){&lt;br /&gt;     bout.write(c);&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;   }&lt;br /&gt;   finally{&lt;br /&gt;    //at the end of everything, close all streams&lt;br /&gt;    if (bin != null){ bin.close();}&lt;br /&gt;    if (bout != null) {bout.close();}&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;   &lt;br /&gt;  //now this is the class loader&lt;br /&gt;  public static void main(String[] args) throws FileNotFoundException, IOException{&lt;br /&gt;   Google blogger = new Google();&lt;br /&gt;   blogger.doingThis(); &lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;p&gt;I had the honor of asking the unholy question: What would the computer say? Now these are a few lines of my result. &lt;/p&gt;&lt;br /&gt;&lt;pre style="font-size:14px"&gt;&amp;yuml;&amp;Oslash;&amp;yuml;&amp;thorn; WANG2&amp;yuml;&amp;agrave; JFIF  x x  &amp;yuml;&amp;Ucirc; C  &lt;br /&gt;  (1#%(:3=&amp;lt;9387@H\N@DWE78PmQW_bghg&amp;gt;Mqypdx\egc&amp;yuml;&amp;Ucirc; C//cB8Bcccccccccccccccccccccccccccccccccccccccccccccccccc&amp;yuml;&amp;Agrave; :! &amp;yuml;&amp;Auml;               &amp;yuml;&amp;Auml; &amp;micro;   } !1AQa&amp;quot;q2&amp;#129;&amp;lsquo;&amp;iexcl;#B&amp;plusmn;&amp;Aacute;R&amp;Ntilde;&amp;eth;$3br&amp;sbquo;&lt;br /&gt;  %&amp;amp;'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz&amp;fnof;&amp;bdquo;&amp;hellip;&amp;dagger;&amp;Dagger;&amp;circ&lt;br /&gt;;&amp;permil;&amp;Scaron;&amp;rsquo;&amp;ldquo;&amp;rdquo;&amp;bull;&amp;ndash;&amp;mdash;&amp;tilde;&amp;trade;&amp;scaron;&amp;cent;&amp;pound;&lt;br /&gt;&amp;curren;&amp;yen;&amp;brvbar;&amp;sect;&amp;uml;&amp;copy;&amp;ordf;&amp;sup2;&amp;sup3;&amp;acute;&amp;micro;&amp;para;&amp;middot;&amp;cedil;&lt;br /&gt;&amp;sup1;&amp;ordm;&amp;Acirc;&amp;Atilde;&amp;Auml;&amp;Aring;&amp;AElig;&amp;Ccedil;&amp;Egrave;&amp;Eacute;&amp;Ecirc;&amp;Ograve;&amp;Oacute;&lt;br /&gt;&amp;Ocirc;&amp;Otilde;&amp;Ouml;&amp;times;&amp;Oslash;&amp;Ugrave;&amp;Uacute;&amp;aacute;&amp;acirc;&amp;amp;atild&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;I really don't know what the computer  said. I can see WANG2 and then after...Gibber-gibber-gabber-dash? Or  something like that?There must be a way to understand this  gibber language. Yes, there is, i have to decode the gibberish stuff. Going back to ask the API.&amp;ldquo;Hey, API, you told me some half  truth. Now, wise man, how do i translate this gibber?&amp;rdquo;&lt;/p&gt;I've already written a solution. It's a &lt;a href="http://genericjava.blogspot.com/2007/07/does-picture-say-thousand-words-2.html"&gt;breeze away&lt;/a&gt;. &lt;p&gt;And for those who cannot do without being mobile, here's something you might like, &lt;a href="http://software.brighthand.com/product.asp?id=11051"&gt;Mundu for Mobiles.&lt;/a&gt; &lt;/p&gt; &lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;google_ad_client = "pub-9881297527037360";&lt;br /&gt;google_ad_width = 728;&lt;br /&gt;google_ad_height = 90;&lt;br /&gt;google_ad_format = "728x90_as";&lt;br /&gt;google_cpa_choice = "CAEQ2MTxgAQQABAAGghwvjNjQ7cRrijYuealAijM2dSOASi8l83TAQ";&lt;br /&gt;//--&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;br /&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-4073263333822856505?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/4073263333822856505/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=4073263333822856505' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/4073263333822856505'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/4073263333822856505'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/07/does-picture-really-say-thousand-words.html' title='DOES A PICTURE REALLY SAY A THOUSAND WORDS?'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_-vb8zdpkvpo/RqCWmnvi4VI/AAAAAAAAAAk/jsazjwiY82E/s72-c/amelipassport.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-475130291278102711</id><published>2007-07-17T04:08:00.000-07:00</published><updated>2007-07-25T01:58:18.102-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bugs'/><category scheme='http://www.blogger.com/atom/ns#' term='boolean logicals'/><category scheme='http://www.blogger.com/atom/ns#' term='conditional'/><category scheme='http://www.blogger.com/atom/ns#' term='code'/><category scheme='http://www.blogger.com/atom/ns#' term='operand'/><category scheme='http://www.blogger.com/atom/ns#' term='truirty'/><category scheme='http://www.blogger.com/atom/ns#' term='operators'/><category scheme='http://www.blogger.com/atom/ns#' term='cellspacing'/><title type='text'>EXPLORING TWO BOOLEAN OPERATORS</title><content type='html'>Two operators that are quite similar in  functionality but for which a developer has to be conscious of bugs  creeping into his code are the boolean logical inclusive or, | and  conditional-or, ||, operators. &lt;br/&gt;&lt;br /&gt;The operands for both operators should  be of type boolean or the boolean wrapper, Boolean. One difference  between both of them is that the conditional-or || operator evaluates  its operands differently and in a subtle fashion than its  counterpart, the boolean logical inclusive-or | operator.&lt;br/&gt;&lt;br /&gt;Let's illustrate this with a truth  table.&lt;table border="1" align="center" cellspacing="2" &gt;&lt;br /&gt;  &lt;caption&gt;&lt;br /&gt;    table illustrating both boolean operators&lt;br /&gt;  &lt;/caption&gt;&lt;br /&gt;  &lt;tr&gt;&lt;br /&gt;    &lt;td width="10%" align="center"&gt;T&lt;/td&gt;&lt;br /&gt;    &lt;td width="10%" align="center"&gt;F&lt;/td&gt;&lt;br /&gt;    &lt;td width="40%"&gt;Result: Logical inclusive-or | operator &lt;/td&gt;&lt;br /&gt;    &lt;td width="40%"&gt;Result: conditional-or operator ||&lt;/td&gt;&lt;br /&gt;  &lt;/tr&gt;&lt;br /&gt;  &lt;tr&gt;&lt;br /&gt;    &lt;td width="10%" align="center"&gt;T&lt;/td&gt;&lt;br /&gt;    &lt;td width="10%" align="center"&gt;T&lt;/td&gt;&lt;br /&gt;    &lt;td width="40%" align="center"&gt;T&lt;/td&gt;&lt;br /&gt;    &lt;td width="40%"&gt;T. Ignores right operand and proceeds to next expression.&lt;/td&gt;&lt;br /&gt;  &lt;/tr&gt;&lt;br /&gt;  &lt;tr&gt;&lt;br /&gt;    &lt;td width="10%" align="center"&gt;T&lt;/td&gt;&lt;br /&gt;    &lt;td width="10%" align="center"&gt;F&lt;/td&gt;&lt;br /&gt;    &lt;td width="40%" align="center"&gt;T&lt;/td&gt;&lt;br /&gt;    &lt;td width="40%"&gt;T. ignores right operand; proceeds to next expression&lt;/td&gt;&lt;br /&gt;  &lt;/tr&gt;&lt;br /&gt;  &lt;tr&gt;&lt;br /&gt;    &lt;td width="10%" align="center"&gt;F&lt;/td&gt;&lt;br /&gt;    &lt;td width="10%" align="center"&gt;T&lt;/td&gt;&lt;br /&gt;    &lt;td width="40%" align="center"&gt;T&lt;/td&gt;&lt;br /&gt;    &lt;td width="40%"&gt;T. evaluates right operand which is true where left operand if false and proceeds to next expression.&lt;br /&gt;&lt;/td&gt;&lt;br /&gt;  &lt;/tr&gt;&lt;br /&gt;  &lt;tr&gt;&lt;br /&gt;    &lt;td width="10%" align="center"&gt;F&lt;/td&gt;&lt;br /&gt;    &lt;td width="10%" align="center"&gt;F&lt;/td&gt;&lt;br /&gt;    &lt;td width="40%" align="center"&gt;F&lt;/td&gt;&lt;br /&gt;    &lt;td width="40%"&gt;F. evaluates right operand which is false where left operand is false. Proceeds to next expression.&lt;/td&gt;&lt;br /&gt;  &lt;/tr&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This is the difference between both operators: although they give the same result for truth or falsity, operand evaluation is different. From the table, realize that where the left operand is false for a conditional-or operand, the right operand is then evaluated, else where the left operand is true, the right operand is ignored. &lt;br/&gt;&lt;br /&gt;So what's the consequence of this effect?&lt;br/&gt;&lt;br /&gt;Let's take a simple question: which of the options below is not robust enough to throw a null pointer exception?&lt;/p&gt;&lt;br /&gt;&lt;pre style="font-family:Verdana, Arial, Helvetica, sans-serif"&gt;Option A: if ( (myArray != null) | (num == myArray.length()) );&lt;br /&gt;Option B: if ( (myArray != null) || (num == myArray.length()) );&lt;br /&gt;Option C: if ( (myArray == null) | (num == myArray.length()) );&lt;br /&gt;Option D: if ( (myArray == null) || (num == myArray.length()) );&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Answers:&lt;br/&gt;&lt;br /&gt;Option A: if left operand is true and right operand is true or false, the if-statement evaluates to true and the expression after the if statement is next evaluated. If left operand is false, the if-statement will always throw a null pointer exception.&lt;br/&gt;&lt;br /&gt;Option B: if left operand is true, execution jumps to the expression following the if statement, else a null pointer exception is immediately thrown. &lt;br/&gt;&lt;br /&gt;Option C: if left operand is true, a null pointer exception is immediately thrown because the right operand would never be evaluated. If left operand is false, if statement evaluates to true if the right operand is true, false otherwise. &lt;br/&gt;&lt;br /&gt;Option D: if left operand is true, execution immediately jumps to the statement following the if-statement. If left operand is false, right operand is then evaluated. If right operand is true or false, no null pointer exception will ever be executed.&lt;br/&gt;&lt;br /&gt;So which option will never throw a null pointer? You guessed right, option D.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-475130291278102711?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/475130291278102711/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=475130291278102711' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/475130291278102711'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/475130291278102711'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/07/exploring-two-boolean-operators.html' title='EXPLORING TWO BOOLEAN OPERATORS'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-6857524979257141121</id><published>2007-07-16T04:35:00.000-07:00</published><updated>2007-07-16T05:15:51.744-07:00</updated><title type='text'>Generating Random Numbers</title><content type='html'>&lt;p&gt;Quest: a trivial exercise in generating  random integers that one can class as either zero, even or odd  between zero (inclusive) and eleven exclusive. After these integers, nine in all,  are generated, classification is done and the result of the number of  zeros, evens and odds in the total numbers generated is then printed  to the screen.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Find: i&amp;rdquo;ll use an instance of a  RandGenerator class to reach the above goal. Importing the class  Random from the package, java.util, the following fields are declared  by our RandGenerator class: &lt;/p&gt;&lt;br /&gt;  &lt;pre style="background-color:006600; color:FFFF00"&gt;&lt;br /&gt;  import java.util.*;&lt;br /&gt;  &lt;br /&gt;  public class RandGenerator {&lt;br /&gt;        //the array to hold the numbers generated&lt;br /&gt;        private int[] boxArray = new int[9];&lt;br /&gt;        //declaring an instance of our random number class&lt;br /&gt;        private Random rand;&lt;br /&gt;        //counters for the integers generated&lt;br /&gt;        private int oddCount=0, evenCount=0, zeroCount=0;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;we'll make use of two methods, a  generator() that uses the Random class to generate nine integers from  between zero (0) and ten (10) and then inserting the integers into an  array. &lt;/p&gt;&lt;br /&gt;  &lt;pre style="background-color:006600; color:FFFF00"&gt;&lt;br /&gt;        //method that generates random numbers as int values&lt;br /&gt;        private void generator(){&lt;br /&gt;             rand = new Random();&lt;br /&gt;             //this for loop generates 9 consecutive random numbers&lt;br /&gt;             for (int i =0; i&lt;9; i++){&lt;br /&gt;                  //get a random number between 0 and 11 exclusive&lt;br /&gt;                  //and store in an array of ints&lt;br /&gt;                  boxArray[i] = rand.nextInt(11);&lt;br /&gt;             }&lt;br /&gt;        }&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Another method, probing(), accesses the array for its int values, maps each int trivially to either a zero, even or odd class and increases the count for each class so mapped. Note that the mapping is assumed. Finally, this class prints out the numeric value of the numbers generated for each of zero, even or odd classes from accessing the array. &lt;br /&gt;&lt;/p&gt;&lt;br /&gt; &lt;pre style="background-color:006600; color:FFFF00"&gt;&lt;br /&gt;        //method that evaluates the numeric count of the integers&lt;br /&gt;       //generated randomly according to a zero, even and odd class&lt;br /&gt;       private void probing(){&lt;br /&gt;             //starting from the first to the last element in the array find out &lt;br /&gt;            //what integer was generated&lt;br /&gt;            for (int i=0; i&amp;#8249;boxArray.length; i++){&lt;br /&gt;                 int take = boxArray[i];&lt;br /&gt;                 //if integer generated is zero, increase zero count&lt;br /&gt;                 if (take == 0) {&lt;br /&gt;                   zeroCount++;&lt;br /&gt;                 }&lt;br /&gt;                 //if even integer generated, increase even count&lt;br /&gt;                 //by one&lt;br /&gt;                 else if (take % 2 == 0){&lt;br /&gt;                    evenCount++;&lt;br /&gt;                 }&lt;br /&gt;                 //otherwise odd integer generated, increase count&lt;br /&gt;                 else {&lt;br /&gt;                   oddCount++;&lt;br /&gt;                 }&lt;br /&gt;            }&lt;br /&gt;   //print out the result of the count values&lt;br /&gt;   System.out.println("Number of odd values"+ &lt;br /&gt;                    "generated were "+ oddCount+" .");&lt;br /&gt;   System.out.println("Number of even values"+ &lt;br /&gt;                    "generated were "+evenCount+" .");&lt;br /&gt;   System.out.println("The zeros generated were" +&lt;br /&gt;                    zeroCount+" in number.");&lt;br /&gt;  }&lt;br /&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Finally, you can run this code by instantiating the class and just calling the two methods. &lt;br /&gt;&lt;/p&gt;&lt;br /&gt;  &lt;pre style="background-color:006600; color:FFFF00"&gt;&lt;br /&gt;  public static void main(String[] args){&lt;br /&gt;            RandGenerator random = new RandGenerator();&lt;br /&gt;            random.generator();&lt;br /&gt;            random.probing();&lt;br /&gt;  }&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Thinking of another quest for next blog. Promise it'll be great&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-6857524979257141121?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/6857524979257141121/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=6857524979257141121' title='29 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/6857524979257141121'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/6857524979257141121'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/07/random-integers-generator.html' title='Generating Random Numbers'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>29</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-4797384902563862673</id><published>2007-06-11T11:35:00.000-07:00</published><updated>2008-12-11T02:01:49.812-08:00</updated><title type='text'>my pix</title><content type='html'>&lt;A HREF='http://2.bp.blogspot.com/_-vb8zdpkvpo/Rm2V5IMSDmI/AAAAAAAAAAc/YUmk5lp7tAA/s1600-h/david.jpg'&gt;&lt;IMG SRC='http://2.bp.blogspot.com/_-vb8zdpkvpo/Rm2V5IMSDmI/AAAAAAAAAAc/YUmk5lp7tAA/s320/david.jpg' border=0 alt='' id='BLOGGER_PHOTO_ID_' style='clear:both;float:left; margin:0px 10px 10px 0;'&gt;&lt;/A&gt;&amp;nbsp;&lt;div style='clear:both; text-align:LEFT'&gt;&lt;a href='http://picasa.google.com/blogger/' target='ext'&gt;&lt;img src='http://photos1.blogger.com/pbp.gif' alt='Posted by Picasa' style='border: 0px none ; padding: 0px; background: transparent none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;' align='middle' border='0' /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-4797384902563862673?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/4797384902563862673/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=4797384902563862673' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/4797384902563862673'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/4797384902563862673'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/06/my-pix.html' title='my pix'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_-vb8zdpkvpo/Rm2V5IMSDmI/AAAAAAAAAAc/YUmk5lp7tAA/s72-c/david.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-5019151533272158764</id><published>2007-06-09T09:56:00.000-07:00</published><updated>2007-06-09T09:59:02.899-07:00</updated><title type='text'>GRAPHICS DEBUGGING.</title><content type='html'>GRAPHICS DEBUGGING.&lt;br /&gt;&lt;br /&gt;Debugging graphics involves the ability to observe every painting operation as it occur during the rendering of a  component and all of its children. Intended for problem finding with rendering, layout and container hierarchies. i.e everything display related. &lt;br /&gt;&lt;br /&gt;When graphics debugging is enabled, the graphics object used in painting is an instance of DebugGraphics class which extends the Graphics class. JComponent and every swing component support graphics debugging which can be turned on or off with Jcomponent's setDebugGraphicsOption( ) method. This methods takes an int parameter that details the debug options.   This parameter determines how the component should display the information:&lt;br /&gt;&lt;br /&gt;if :&lt;br /&gt;1.DebugGraphics.LOG_OPTION – a text message is printed.&lt;br /&gt;2.DebugGraphics.FLASH_OPTION - The display flashes several times. &lt;br /&gt;3.DebugGraphics.BUFFERED_OPTION - It creates an external window that displays the operations performed on this view's offscreen buffer. &lt;br /&gt;4.DebugGraphics.NON_OPTION - Debug disabled. &lt;br /&gt;5.If 0 no change is issued to the debugging option. &lt;br /&gt;&lt;br /&gt;Note that these values can be bitwise OR'd into the current value. &lt;br /&gt;&lt;br /&gt;Let's explore the options one after the other:&lt;br /&gt;&lt;br /&gt;1.DebugGraphices.FLASH_OPTION.&lt;br /&gt; &lt;br /&gt;Each paint operation flashes a specified number of times, in a specified flash color, with a specified flash interval.&lt;br /&gt; &lt;br /&gt;You set this values with the following methods from the DebugGraphcics static  methods :&lt;br /&gt;&lt;br /&gt;setFlashTime(int flashTime)&lt;br /&gt;setFlashCount (int flashCount)&lt;br /&gt;setFlashColor (Color flashColor)&lt;br /&gt;&lt;br /&gt;to see the flashing as it occurs you must disable buffering like this:&lt;br /&gt;&lt;br /&gt;RepaintManager.currentManager(null).setDoubleBuffereingEnabled(false).&lt;br /&gt;&lt;br /&gt;After this every component's doubleBuffered properyty will henceforth be ignored.&lt;br /&gt;&lt;br /&gt;I loved the flashing at first instance and have been flashing my computer since. &lt;br /&gt;&lt;br /&gt;So let me drop a code for that. See how the buttons changed color. &lt;br /&gt;&lt;br /&gt;package tests;&lt;br /&gt;import java.awt.*;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;import javax.swing.event.*;&lt;br /&gt;&lt;br /&gt;public class Property extends JPanel{ &lt;br /&gt;    &lt;br /&gt;    //declaring an instance&lt;br /&gt;    static Color dColor = new Color(0, 255, 100, 125);&lt;br /&gt;    &lt;br /&gt;    //the dimension&lt;br /&gt;    static Dimension dim = new Dimension(400, 400);&lt;br /&gt;    &lt;br /&gt;    static JButton jButton1 = new JButton(" ");&lt;br /&gt;    static JTextArea jText;&lt;br /&gt;    &lt;br /&gt;    /** Creates a new instance of Property */&lt;br /&gt;    public Property() {&lt;br /&gt;        jButton1 = new JButton("click me");&lt;br /&gt;        add(jButton1);&lt;br /&gt;        &lt;br /&gt;        //we'll use the instance as foreground.&lt;br /&gt;        jButton1.setBackground(dColor);&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    private static void dButton(){&lt;br /&gt;        JFrame.setDefaultLookAndFeelDecorated(true);&lt;br /&gt;        JFrame frame = new JFrame("Property");&lt;br /&gt;        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;        Property nProp = new Property();&lt;br /&gt;        &lt;br /&gt;        //buffering and opaque value for painting and updating&lt;br /&gt;        nProp.setOpaque(true);&lt;br /&gt;        nProp.setDoubleBuffered(true);&lt;br /&gt;        &lt;br /&gt;        //graphics debugging&lt;br /&gt;        nProp.setDebugGraphicsOptions(DebugGraphics.FLASH_OPTION);&lt;br /&gt;        DebugGraphics.setFlashColor(Color.red);&lt;br /&gt;        DebugGraphics.setFlashCount(5);&lt;br /&gt;        DebugGraphics.setFlashTime(10);&lt;br /&gt;        RepaintManager.currentManager(null).setDoubleBufferingEnabled(false);&lt;br /&gt;        &lt;br /&gt;        &lt;br /&gt;        //set max, min and preferred sizes&lt;br /&gt;        nProp.setMaximumSize(dim);&lt;br /&gt;        nProp.setMinimumSize(dim);&lt;br /&gt;        nProp.setPreferredSize(dim);&lt;br /&gt;       &lt;br /&gt;        frame.setContentPane(nProp);&lt;br /&gt;        &lt;br /&gt;        //let the above size stay 4ever &lt;br /&gt;        frame.setResizable(false);&lt;br /&gt;        &lt;br /&gt;        frame.pack();&lt;br /&gt;        frame.setVisible(true);   &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public static void simplyText(String txt){&lt;br /&gt;        jText.append(txt+"\n");&lt;br /&gt;        &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public void paintComponent(Graphics g){&lt;br /&gt;        super.paintComponent(g);&lt;br /&gt;        &lt;br /&gt;        //counter&lt;br /&gt;        int c = 0;&lt;br /&gt;        &lt;br /&gt;        //for use below&lt;br /&gt;        int w=0;&lt;br /&gt;        int h=0;&lt;br /&gt;        int d=0;&lt;br /&gt;        &lt;br /&gt;        //get damaged region&lt;br /&gt;        Rectangle r = g.getClipBounds();&lt;br /&gt;        int clipx = r.x;&lt;br /&gt;        int clipy = r.y;&lt;br /&gt;        int clipw = r.width;&lt;br /&gt;        int cliph = r.height;&lt;br /&gt;        &lt;br /&gt;        //fill only damaged region&lt;br /&gt;        g.setColor(Color.white);&lt;br /&gt;        g.fillRect(clipx, clipy, clipw, cliph);&lt;br /&gt;        &lt;br /&gt;        //filled yellow circle only if bounding region is damaged&lt;br /&gt;        if (clipx &lt;= 240 &amp;&amp; clipy &lt;= 240){&lt;br /&gt;            g.setColor(Color.yellow);&lt;br /&gt;            g.fillOval(0, 0, 240, 240);&lt;br /&gt;            c++;&lt;br /&gt;        }&lt;br /&gt;        &lt;br /&gt;        //filled magenta cirlce if bounding region has been damaged&lt;br /&gt;        if (clipx + clipw&gt;=160 &amp;&amp; clipx&lt;=400 &amp;&amp; clipy+cliph&gt;=160 &amp;&amp; clipy&lt;=400){&lt;br /&gt;            g.setColor(Color.magenta);&lt;br /&gt;            g.fillOval(160, 160, 240, 240);&lt;br /&gt;            c++;&lt;br /&gt;        }&lt;br /&gt;        &lt;br /&gt;        &lt;br /&gt;    }&lt;br /&gt;    public static void main(String[] args){&lt;br /&gt;        javax.swing.SwingUtilities.invokeLater(new Runnable(){&lt;br /&gt;            public void run(){&lt;br /&gt;                dButton();&lt;br /&gt;            }&lt;br /&gt;        });&lt;br /&gt;    }    &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;2.DebugGraphics.LOG_OPTION: each paint operation is messaged as they occur and by default are directed to standard output i.e System.out. Note that these output can be redirected with DebugGraphic's static setLogStream() method which method takes a PrintStream instance as a parameter.&lt;br /&gt; &lt;br /&gt;we can also instance any string into the log using the debuggraphics static logStream () method. &lt;br /&gt;3.DebugGraphics.BUFFERED_OPTION . This pops up a frame that gives offscreen rendering. Double-buffering must be enabbled.&lt;br /&gt;4.DebugGraphics.NONE_OPTION. Basically shuts down graphics debugging by nullifying the settings. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Caveats in graphics debugging. &lt;br /&gt;&lt;br /&gt;You'll notice that the button color changed from the default to brown due to its being blended with the flash color, red. Yeah, that's a caveat in graphics debugging. &lt;br /&gt;1. Where the UI delegate of the component is null. If  a component's UI delegate is null, graphics debugging will not work. The best way to go around this is if you declared a class without a UI delegate so as to define a trivial (empty) UI delegate. &lt;br /&gt;&lt;br /&gt;2. DebugGraphics does not properly clean up after itself. A flash results in painting over of the color of the components and it does not get erased. This presents a problem because transparent rendering now becomes alpha blended with the flash color. You can hide the flash color though by giving its color an alpha value of invisible, i.e 0 or 0.0. we can sidestep this blending by making the flash time and flashcount to wait long enough between operations. &lt;br /&gt;&lt;br /&gt;To implement the above we can rewrite the above code adding the below:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;package tests;&lt;br /&gt;&lt;br /&gt;import javax.swing.plaf.ComponentUI;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;&lt;br /&gt;public class EmptyUI extends ComponentUI {&lt;br /&gt;    &lt;br /&gt;    private static final EmptyUI sharedInstance = new EmptyUI();&lt;br /&gt;    &lt;br /&gt;    public static ComponentUI createUI(JComponent c){&lt;br /&gt;        return sharedInstance;&lt;br /&gt;    }    &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;then to the Property class we add this code as the first line in its constructor:&lt;br /&gt;&lt;br /&gt;super.setUI(EmptyUI.createUI(this));&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-5019151533272158764?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/5019151533272158764/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=5019151533272158764' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/5019151533272158764'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/5019151533272158764'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/06/graphics-debugging.html' title='GRAPHICS DEBUGGING.'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-2552879652204999151</id><published>2007-06-08T10:38:00.000-07:00</published><updated>2007-06-08T10:45:06.078-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='color'/><category scheme='http://www.blogger.com/atom/ns#' term='clipping coordinates'/><category scheme='http://www.blogger.com/atom/ns#' term='canvas'/><category scheme='http://www.blogger.com/atom/ns#' term='awt'/><title type='text'>DEALING WITH GRAPHICS AND TEXT</title><content type='html'>DEALING WITH GRAPHICS AND TEXT&lt;br /&gt;&lt;br /&gt;first of all know that every component owns its own graphics context, which context is defined in the Graphics class of java.awt package and has the following properties:&lt;br /&gt;&lt;br /&gt;1.the component object on which to draw&lt;br /&gt;2.a translation origin for rendering and clipping coordinates&lt;br /&gt;3.the current clip&lt;br /&gt;4.the current color&lt;br /&gt;5.the current font &lt;br /&gt;6.the current logical pixel operation function (XOR or paint)&lt;br /&gt;7.the current XOR alternation color&lt;br /&gt;&lt;br /&gt;although in AWT to paint we typically override component's paint() method, to do rendering we use the update() method for implementing our own double buffering and background filling before calling paint(), but in swing, if any component wants to take charge of its rendering, it should override the paintComponent() method and not the paint() method and should always begin the paintComponent() method with a call to super.paintComponent() thereby it acts as its own lightweight canvas. &lt;br /&gt;&lt;br /&gt;Note before: the above is useful for simple custom components but for normal swing component, since the UI delegate is in charge of rendering, never attempt it. &lt;br /&gt;&lt;br /&gt;Inside the paintComponent() method, we have access to the component's graphics object or its graphics context used for painting shapes and drawing lines and text. Check the graphics class for useful methods. &lt;br /&gt;&lt;br /&gt;Some code that illustrates the above. &lt;br /&gt;&lt;br /&gt;package tests;&lt;br /&gt;import java.awt.*;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;import javax.swing.event.*;&lt;br /&gt;&lt;br /&gt;public class Property extends JPanel{ &lt;br /&gt;    &lt;br /&gt;    //declaring an instance&lt;br /&gt;    static Color dColor = new Color(0, 255, 100, 125);&lt;br /&gt;    static Color mainRed = new Color(255, 0, 0, 150);&lt;br /&gt;    static Color mainGreen = new Color(0, 255, 0, 150);&lt;br /&gt;    static Color mainBlue = new Color (0, 0, 255, 150);&lt;br /&gt;    &lt;br /&gt;    static Font mainBIFont = new Font("Monospace", Font.BOLD| Font.ITALIC, 36);&lt;br /&gt;    static Font mainPFont = new Font("SansSerif", Font.PLAIN, 12);&lt;br /&gt;    static Font mainBFont = new Font("Serif", Font.BOLD, 24);&lt;br /&gt;    &lt;br /&gt;    //the dimension&lt;br /&gt;    static Dimension dim = new Dimension(400, 400);&lt;br /&gt;    &lt;br /&gt;    static JButton jButton1 = new JButton(" ");&lt;br /&gt;    static JTextArea jText;&lt;br /&gt;    &lt;br /&gt;    /** Creates a new instance of Property */&lt;br /&gt;    public Property() {&lt;br /&gt;        jButton1 = new JButton("click me");&lt;br /&gt;        add(jButton1);&lt;br /&gt;        &lt;br /&gt;        //we'll use the instance as foreground.&lt;br /&gt;        jButton1.setBackground(dColor);&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    private static void dButton(){&lt;br /&gt;        JFrame.setDefaultLookAndFeelDecorated(true);&lt;br /&gt;        JFrame frame = new JFrame("Property");&lt;br /&gt;        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;        Property nProp = new Property();&lt;br /&gt;        &lt;br /&gt;        //buffering and opaque value for painting and updating&lt;br /&gt;        nProp.setOpaque(true);&lt;br /&gt;        nProp.setDoubleBuffered(true);&lt;br /&gt;        &lt;br /&gt;        //set max, min and preferred sizes&lt;br /&gt;        nProp.setMaximumSize(dim);&lt;br /&gt;        nProp.setMinimumSize(dim);&lt;br /&gt;        nProp.setPreferredSize(dim);&lt;br /&gt;       &lt;br /&gt;        frame.setContentPane(nProp);&lt;br /&gt;        &lt;br /&gt;        //let the above size stay 4ever &lt;br /&gt;        frame.setResizable(false);&lt;br /&gt;        &lt;br /&gt;        frame.pack();&lt;br /&gt;        frame.setVisible(true);   &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public static void simplyText(String txt){&lt;br /&gt;        jText.append(txt+"\n");&lt;br /&gt;        &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public void paintComponent(Graphics g){&lt;br /&gt;        super.paintComponent(g);&lt;br /&gt;        &lt;br /&gt;        //fill entire component white&lt;br /&gt;        g.setColor(Color.white);&lt;br /&gt;        g.fillRect(0, 0, getWidth(), getHeight());&lt;br /&gt;        &lt;br /&gt;        //fills yellow circle&lt;br /&gt;        g.setColor(Color.yellow);&lt;br /&gt;        g.fillOval(0, 0, 240, 240);&lt;br /&gt;        &lt;br /&gt;        //filled magenta circle&lt;br /&gt;        g.setColor(Color.magenta);&lt;br /&gt;        g.fillOval(160, 160, 240, 240);&lt;br /&gt;        &lt;br /&gt;        g.setColor(Color.black);&lt;br /&gt;        &lt;br /&gt;        //text is bold, italic, 36-point, "Nigeria"&lt;br /&gt;        g.setFont(mainBIFont);&lt;br /&gt;        FontMetrics fm = g.getFontMetrics();&lt;br /&gt;        int w = fm.stringWidth("NIGERIA");&lt;br /&gt;        int h = fm.getAscent();&lt;br /&gt;        g.drawString("NIGERIA", 120-(w/2), 120+(h/4));&lt;br /&gt;        &lt;br /&gt;        //plain, 12-point, "go"&lt;br /&gt;        g.setFont(mainPFont);&lt;br /&gt;        fm = g.getFontMetrics();&lt;br /&gt;        w = fm.stringWidth("go");&lt;br /&gt;        h = fm.getAscent();&lt;br /&gt;        g.drawString("go", 200-(w/2), 200+(h/4));&lt;br /&gt;        &lt;br /&gt;        //bold, 24-point, "SURVIVE"&lt;br /&gt;        g.setFont(mainBFont);&lt;br /&gt;        fm = g.getFontMetrics();&lt;br /&gt;        w = fm.stringWidth("GO");&lt;br /&gt;        h = fm.getAscent();&lt;br /&gt;        g.drawString("SURVIVE", 280-(w/2), 280+(h/4));&lt;br /&gt;    &lt;br /&gt;    }&lt;br /&gt;    public static void main(String[] args){&lt;br /&gt;        javax.swing.SwingUtilities.invokeLater(new Runnable(){&lt;br /&gt;            public void run(){&lt;br /&gt;                dButton();&lt;br /&gt;            }&lt;br /&gt;        });&lt;br /&gt;    }    &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;If you run the above code, it'll display: “NIGERIA go SURVIVE” in bright colors that illustrates the power of the rendering and painting properties of every graphics context for swing component. Worthy of note though is that not the totality of the area of a component is painted but for the sake of efficiency there are some so-called “dirtied” areas or damaged areas which are defined as the bounds of the clipping area which are not painted. You can get a Rectangle object showing this by calling getClipBounds() method of the Graphics class.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-2552879652204999151?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/2552879652204999151/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=2552879652204999151' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/2552879652204999151'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/2552879652204999151'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/06/dealing-with-graphics-and-text.html' title='DEALING WITH GRAPHICS AND TEXT'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-6950144180960520867</id><published>2007-06-08T06:30:00.000-07:00</published><updated>2007-06-08T06:38:43.552-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='swing'/><category scheme='http://www.blogger.com/atom/ns#' term='sRGB'/><title type='text'>COLORS IN SWING</title><content type='html'>COLORS IN SWING&lt;br /&gt;&lt;br /&gt;the color class encapsulates colors in the default sRGB color space or colors in the arbitrary color spaces identified by a ColorSpace class. Every color has an implicit alpha value of 1.0 or an explicit one provided in the constructor, which alpha values denote the color's transparency and 1.0 means totally transparent if denoted with a float range or 255 if an int range. Also alpha values of 0 or 0.0 means completely transparent color. Note that color classes do not pre-multiply alpha values. &lt;br /&gt;&lt;br /&gt;Information on the sRGB color space is defined by the &lt;a href="http://w3.org/pub/WWW/Graphics/Color/sRGB.html"&gt;World Wide Web consortium&lt;/a&gt; &lt;br /&gt;the overloaded constructors for color take a colorspace parameter, float or int values. Check this out in the api. &lt;br /&gt;&lt;br /&gt;Like the font accessor methods, getXX() methods are specified for the color class but in modifying any color instance, one is usually expected to create a new one. By specifying an alpha value, we can use a color instance on a component's background to make it transparent. Note that when setting the foreground of a component the look and feel may ignore the color specified. &lt;br /&gt;&lt;br /&gt;Our button and textareas colored with Color.&lt;br /&gt;&lt;br /&gt;package tests;&lt;br /&gt;import java.awt.*;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;import javax.swing.event.*;&lt;br /&gt;&lt;br /&gt;public class Property extends JPanel{ &lt;br /&gt;    &lt;br /&gt;    //declaring an instance&lt;br /&gt;    static Color dColor = new Color(0, 255, 100, 125);&lt;br /&gt;    &lt;br /&gt;    static JButton jButton1 = new JButton(" ");&lt;br /&gt;    static JTextArea jText;&lt;br /&gt;    /** Creates a new instance of Property */&lt;br /&gt;    public Property() {&lt;br /&gt;        jButton1 = new JButton("click me");&lt;br /&gt;        add(jButton1);&lt;br /&gt;        &lt;br /&gt;        //we'll use the instance as foreground.&lt;br /&gt;        jButton1.setBackground(dColor);&lt;br /&gt;        &lt;br /&gt;        jText = new JTextArea(" ", 10, 20);&lt;br /&gt;        add(jText);&lt;br /&gt;        GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();&lt;br /&gt;        String[] fontNames = genv.getAvailableFontFamilyNames();&lt;br /&gt;        for (int i=0; i&lt;fontNames.length;i++){&lt;br /&gt;            simplyText(fontNames[i]);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    private static void dButton(){&lt;br /&gt;        JFrame.setDefaultLookAndFeelDecorated(true);&lt;br /&gt;        JFrame frame = new JFrame("Property");&lt;br /&gt;        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;        Property nProp = new Property();&lt;br /&gt;        nProp.setOpaque(true);&lt;br /&gt;        &lt;br /&gt;        //and also use it here too&lt;br /&gt;        nProp.setBackground(dColor);&lt;br /&gt;        &lt;br /&gt;        frame.setContentPane(nProp);&lt;br /&gt;        frame.pack();&lt;br /&gt;        frame.setVisible(true);   &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public static void simplyText(String txt){&lt;br /&gt;        jText.append(txt+"\n");&lt;br /&gt;        &lt;br /&gt;    }&lt;br /&gt;    public static void main(String[] args){&lt;br /&gt;        javax.swing.SwingUtilities.invokeLater(new Runnable(){&lt;br /&gt;            public void run(){&lt;br /&gt;                dButton();&lt;br /&gt;            }&lt;br /&gt;        });&lt;br /&gt;    }    &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;keywords: color, swing, colorspace, alpha value, sRGB, GraphicsEnvironment&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-6950144180960520867?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/6950144180960520867/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=6950144180960520867' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/6950144180960520867'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/6950144180960520867'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/06/colors-in-swing.html' title='COLORS IN SWING'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-1351825712007650755</id><published>2007-06-08T04:20:00.000-07:00</published><updated>2007-06-08T04:24:57.988-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='glyphs'/><category scheme='http://www.blogger.com/atom/ns#' term='package'/><category scheme='http://www.blogger.com/atom/ns#' term='graphicsconfiguration'/><category scheme='http://www.blogger.com/atom/ns#' term='fonts'/><category scheme='http://www.blogger.com/atom/ns#' term='jpanel'/><category scheme='http://www.blogger.com/atom/ns#' term='graphicsenvironment'/><title type='text'>FONTS</title><content type='html'>FONTS&lt;br /&gt;&lt;br /&gt;to work with fonts, two classes are worth noting, the GraphicsEnvironment and Font classes which are both in the java.awt package.&lt;br /&gt; &lt;br /&gt;GraphicsEnvironment: this class describes a collection of GraphicsDevices and font objects that are available to a java application on a particular platform and note that the resources might be local or remote. GraphicsDevices might be screens, printers or image buffers. Each GraphicsDevice has a number of Graphicsconfiguration objects associated with it that specifies configuration usage for different GraphicsDevices.&lt;br /&gt; &lt;br /&gt;Font: this represents a class for rendring text in a visible way. A font provides information needed to map sequence of characters to sequence of glyphs and to render a sequence of glyphs as Graphics on component classes. &lt;br /&gt;&lt;br /&gt;we can retrieve font related properties from a local or remote machine using the GraphicsEnvironment and font classes working together. &lt;br /&gt;&lt;br /&gt;Here is a code that demonstrates the fonts available on my windows xp machine:&lt;br /&gt;&lt;br /&gt;package tests;&lt;br /&gt;import java.awt.*;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;import javax.swing.event.*;&lt;br /&gt;&lt;br /&gt;public class Property extends JPanel{ &lt;br /&gt;    &lt;br /&gt;    static JButton jButton1 = new JButton(" ");&lt;br /&gt;    static JTextArea jText;&lt;br /&gt;    /** Creates a new instance of Property */&lt;br /&gt;    public Property() {&lt;br /&gt;        jButton1 = new JButton("click me");&lt;br /&gt;        add(jButton1);&lt;br /&gt;        jText = new JTextArea(" ", 10, 20);&lt;br /&gt;        add(jText);&lt;br /&gt;        GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();&lt;br /&gt;        String[] fontNames = genv.getAvailableFontFamilyNames();&lt;br /&gt;        for (int i=0; i&lt;fontNames.length;i++){&lt;br /&gt;            simplyText(fontNames[i]);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    private static void dButton(){&lt;br /&gt;        JFrame.setDefaultLookAndFeelDecorated(true);&lt;br /&gt;        JFrame frame = new JFrame("Property");&lt;br /&gt;        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;        Property nProp = new Property();&lt;br /&gt;        nProp.setOpaque(true);&lt;br /&gt;        frame.setContentPane(nProp);&lt;br /&gt;        frame.pack();&lt;br /&gt;        frame.setVisible(true);   &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public static void simplyText(String txt){&lt;br /&gt;        jText.append(txt+"\n");&lt;br /&gt;        &lt;br /&gt;    }&lt;br /&gt;    public static void main(String[] args){&lt;br /&gt;        javax.swing.SwingUtilities.invokeLater(new Runnable(){&lt;br /&gt;            public void run(){&lt;br /&gt;                dButton();&lt;br /&gt;            }&lt;br /&gt;        });&lt;br /&gt;    }    &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Although we can use the classic getXX() accessor methods for font objects note that to set them we have to derive fonts using an overloaded deriveFont() method.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-1351825712007650755?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/1351825712007650755/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=1351825712007650755' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/1351825712007650755'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/1351825712007650755'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/06/fonts.html' title='FONTS'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-8749336056405017754</id><published>2007-06-08T04:19:00.000-07:00</published><updated>2007-06-08T04:20:05.965-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='timers and swing'/><title type='text'>USING TIMERS WITH SWING.</title><content type='html'>USING TIMERS WITH SWING.&lt;br /&gt;&lt;br /&gt;A timer instance can be considered as a unique thread that fires one or more action events at specified intervals. The timer class for use in GUI contexts in java is defined in the javax.swing.Timer class. &lt;br /&gt;&lt;br /&gt;Let's write a code for creating a Timer class. &lt;br /&gt;&lt;br /&gt;package tests;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;import javax.swing.event.*;&lt;br /&gt;&lt;br /&gt;public class Property extends JPanel{ &lt;br /&gt;    &lt;br /&gt;    static JButton jButton1 = new JButton(" ");&lt;br /&gt;    static JTextArea jText;&lt;br /&gt;    /** Creates a new instance of Property */&lt;br /&gt;    public Property() {&lt;br /&gt;        jButton1 = new JButton("click me");&lt;br /&gt;        add(jButton1);&lt;br /&gt;        jText = new JTextArea("welcome", 2, 50);&lt;br /&gt;        add(jText);&lt;br /&gt;        &lt;br /&gt;        //start the timer &lt;br /&gt;        int delay = 10000; // 3 sec. delay initially and between firing&lt;br /&gt;        &lt;br /&gt;        //the action listener that processes the timer event&lt;br /&gt;        ActionListener al = new ActionListener(){&lt;br /&gt;            public void actionPerformed(ActionEvent ae){&lt;br /&gt;                simplyText("Don't forget me.");&lt;br /&gt;            }&lt;br /&gt;        };&lt;br /&gt;        &lt;br /&gt;        //create an instance of a timer with delay and action listener&lt;br /&gt;        //then start timer thread&lt;br /&gt;            Timer tim = new Timer (delay, al);&lt;br /&gt;            tim.start();&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    private static void dButton(){&lt;br /&gt;        JFrame.setDefaultLookAndFeelDecorated(true);&lt;br /&gt;        JFrame frame = new JFrame("Property");&lt;br /&gt;        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;        Property nProp = new Property();&lt;br /&gt;        nProp.setOpaque(true);&lt;br /&gt;        frame.setContentPane(nProp);&lt;br /&gt;        frame.pack();&lt;br /&gt;        frame.setVisible(true);   &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public static void simplyText(String txt){&lt;br /&gt;        jText.setText(txt);&lt;br /&gt;        &lt;br /&gt;    }&lt;br /&gt;    public static void main(String[] args){&lt;br /&gt;        javax.swing.SwingUtilities.invokeLater(new Runnable(){&lt;br /&gt;            public void run(){&lt;br /&gt;                dButton();&lt;br /&gt;            }&lt;br /&gt;        });&lt;br /&gt;    }    &lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-8749336056405017754?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/8749336056405017754/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=8749336056405017754' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/8749336056405017754'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/8749336056405017754'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/06/using-timers-with-swing.html' title='USING TIMERS WITH SWING.'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-7083654090317949145</id><published>2007-06-08T03:56:00.000-07:00</published><updated>2007-06-08T04:00:16.389-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='thread'/><category scheme='http://www.blogger.com/atom/ns#' term='queue'/><category scheme='http://www.blogger.com/atom/ns#' term='mouseadapter'/><category scheme='http://www.blogger.com/atom/ns#' term='event dispatching'/><category scheme='http://www.blogger.com/atom/ns#' term='fifo'/><title type='text'>THE EVENT DISPATCHING THREAD</title><content type='html'>THE EVENT DISPATCHING THREAD&lt;br /&gt;&lt;br /&gt;Listeners, as we've mentioned before, process every event and every event is in an event-dispatching thread. In the api, a FIFO queue of events is associated with this thread, an EventQueue instance, that is the system events queue and defined in the java.awt.EventQueue class. This queue is filled in a serial fashion, FIFO-like. As events are executed, this is done serially too, whether the event is a component property update or repainting . &lt;br /&gt;&lt;br /&gt;Please ensure that all your events are within this thread and none should be dispatched outside this event dispatching thread. Also ensure that event handling code and painting codes will be executed quickly, i.e keep them simple. Otherwise, one event that takes up time could block the whole queue and your application gets frozen or locked up. &lt;br /&gt;&lt;br /&gt;I have written a code here that makes use of the event dispatching threads on two listeners that listen for the same type of event, a mouse click.&lt;br /&gt;&lt;br /&gt;package tests;&lt;br /&gt;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;public class FirstListener extends MouseAdapter {&lt;br /&gt;    &lt;br /&gt;    public void mouseClicked(MouseEvent e){&lt;br /&gt;        //after this listener processes event, remove from queue&lt;br /&gt;        //and just add the second to make sure we did not remove &lt;br /&gt;        //it earlier also&lt;br /&gt;        Property.simplyText("the first listener at attention.");&lt;br /&gt;        Property.jButton1.removeMouseListener(this);&lt;br /&gt;        Property.jButton1.addMouseListener(new SecondListener());&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;public class SecondListener extends MouseAdapter {&lt;br /&gt;    &lt;br /&gt;    public void mouseClicked(MouseEvent e){&lt;br /&gt;       //after this listener processes event, remove from queue&lt;br /&gt;       //and just add the second to make sure we did not remove &lt;br /&gt;       //it earlier also&lt;br /&gt;       Property.simplyText("the second listener at attention.");&lt;br /&gt;       Property.jButton1.removeMouseListener(this);&lt;br /&gt;       Property.jButton1.addMouseListener(new FirstListener());&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;import javax.swing.event.*;&lt;br /&gt;&lt;br /&gt;public class Property extends JPanel{ &lt;br /&gt;    &lt;br /&gt;    EventListenerList listenerList = new EventListenerList();&lt;br /&gt;    FirstListener fl = new FirstListener();&lt;br /&gt;    SecondListener sl = new SecondListener();&lt;br /&gt;    MouseEvent me;&lt;br /&gt;    &lt;br /&gt;    static JButton jButton1 = new JButton(" ");&lt;br /&gt;    static JTextArea jText;&lt;br /&gt;    /** Creates a new instance of Property */&lt;br /&gt;    public Property() {&lt;br /&gt;        jButton1 = new JButton("click me");&lt;br /&gt;        add(jButton1);&lt;br /&gt;        &lt;br /&gt;        //here are the two listeners added to the event dispatching&lt;br /&gt;        //queue&lt;br /&gt;        jButton1.addMouseListener(fl);&lt;br /&gt;        jButton1.addMouseListener(sl);&lt;br /&gt;        &lt;br /&gt;        jText = new JTextArea("welcome", 5, 50);&lt;br /&gt;        add(jText);&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    private static void dButton(){&lt;br /&gt;        JFrame.setDefaultLookAndFeelDecorated(true);&lt;br /&gt;        JFrame frame = new JFrame("Property");&lt;br /&gt;        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;        Property nProp = new Property();&lt;br /&gt;        nProp.setOpaque(true);&lt;br /&gt;        frame.setContentPane(nProp);&lt;br /&gt;        frame.pack();&lt;br /&gt;        frame.setVisible(true);   &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public static void simplyText(String txt){&lt;br /&gt;        jText.setText(txt);&lt;br /&gt;        &lt;br /&gt;    }&lt;br /&gt;    public static void main(String[] args){&lt;br /&gt;        javax.swing.SwingUtilities.invokeLater(new Runnable(){&lt;br /&gt;            public void run(){&lt;br /&gt;                dButton();&lt;br /&gt;            }&lt;br /&gt;        });&lt;br /&gt;    }    &lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-7083654090317949145?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/7083654090317949145/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=7083654090317949145' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/7083654090317949145'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/7083654090317949145'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/06/event-dispatching-thread.html' title='THE EVENT DISPATCHING THREAD'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-6045369996559852825</id><published>2007-06-08T03:50:00.000-07:00</published><updated>2007-06-08T03:52:59.466-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='event'/><category scheme='http://www.blogger.com/atom/ns#' term='Swingutilities'/><category scheme='http://www.blogger.com/atom/ns#' term='listener lists'/><category scheme='http://www.blogger.com/atom/ns#' term='jcomponent'/><title type='text'>EVENT LISTENER LIST.</title><content type='html'>EVENT LISTENER LIST.&lt;br /&gt;&lt;br /&gt;The EventListenerList class is defined in the javax,swing.event package. An EventListernerList is an array of XXEvent/XXListener pairs. JComponent and each of its descendants use an EventListenerList to maintain their listeners. All default models also maintain listeners and an EventListenerList. &lt;br /&gt;&lt;br /&gt;On adding a listener to a swing component or model, the associated event's Class instance (used to identify event type) is added to its EventListenerList array followed by the listener itself. &lt;br /&gt;Since these pairs are stored in an array rather than a mutable collection, a new array is created on each addition or removal using the System.arrayCopy() methods.&lt;br /&gt; &lt;br /&gt;When events are received, the list is walked through and events are sent to each listener with a matching type. Because the array is ordered in an XXEvent, XXListener, YYEvent, YYListener fashion, a listener corresponding to a given event type is always next in the array. This gives for very efficient event-dispatching routines.&lt;br /&gt; &lt;br /&gt;For thread safety, the methods for adding and removing listeners from an event listener synchronises access to the array when it is manipulated. &lt;br /&gt;&lt;br /&gt;In JComponent, the EventListenerList is a protected field called listenerList so that all subclasses inherit it and most listeners are managed through listenerList.&lt;br /&gt;&lt;br /&gt;Here is a code where the class itself handles the event and is the sole occupant of the component's event listener list. &lt;br /&gt;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;import javax.swing.event.*;&lt;br /&gt;import java.lang.*;&lt;br /&gt;&lt;br /&gt;public class Property extends JPanel implements ActionListener{ &lt;br /&gt;    &lt;br /&gt;    JButton jButton1 = new JButton(" ");&lt;br /&gt;    JTextField jText;&lt;br /&gt;    /** Creates a new instance of Property */&lt;br /&gt;    public Property() {&lt;br /&gt;        jButton1 = new JButton("click me");&lt;br /&gt;        add(jButton1);&lt;br /&gt;        &lt;br /&gt;        //this object is its own action listener&lt;br /&gt;        jButton1.addActionListener(this);&lt;br /&gt;        &lt;br /&gt;        jText = new JTextField("welcome", 50);&lt;br /&gt;        add(jText);&lt;br /&gt;        &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    private static void dButton(){&lt;br /&gt;        JFrame.setDefaultLookAndFeelDecorated(true);&lt;br /&gt;        JFrame frame = new JFrame("Property");&lt;br /&gt;        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;        Property nProp = new Property();&lt;br /&gt;        nProp.setOpaque(true);&lt;br /&gt;        frame.setContentPane(nProp);&lt;br /&gt;        frame.pack();&lt;br /&gt;        frame.setVisible(true);   &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public void actionPerformed(ActionEvent e){ &lt;br /&gt;        //get the action listeners associated with this object, here one&lt;br /&gt;        ActionListener[] al = jButton1.getActionListeners();&lt;br /&gt;        &lt;br /&gt;        jText.setText("the "+al[0].getClass().toString()+" is the action listener " +&lt;br /&gt;                "in the list");&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public static void main(String[] args){&lt;br /&gt;        javax.swing.SwingUtilities.invokeLater(new Runnable(){&lt;br /&gt;            public void run(){&lt;br /&gt;                dButton();&lt;br /&gt;            }&lt;br /&gt;        });&lt;br /&gt;    }    &lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-6045369996559852825?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/6045369996559852825/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=6045369996559852825' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/6045369996559852825'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/6045369996559852825'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/06/event-listener-list.html' title='EVENT LISTENER LIST.'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-1766600016523574347</id><published>2007-06-08T03:43:00.000-07:00</published><updated>2007-06-08T03:45:21.261-07:00</updated><title type='text'>EVENT HANDLING AND DISPATCHING.</title><content type='html'>EVENT HANDLING AND DISPATCHING.&lt;br /&gt;&lt;br /&gt;Pressing a key or mouse button generates events. The type of events that swing components can generate whether in java.awt.event or javax.swing.event packages are of different types. Some event types are component specific.&lt;br /&gt; &lt;br /&gt;Each event type is represented by an object that identifies the source of the event and other additional information about what specific kind of event it is and information about the state of the source before and after the event was generated. Sources of events are most commonly components or models but also different kinds of objects can generate events.&lt;br /&gt; &lt;br /&gt;To receive notification of events, we need to register listeners with the target object . A listener is an implementation of any of the XXListener classes (where XX is an event type) defined in the java.awt.event, java.beans and javax.swing.event packages. There is at least one method defined in each interface that takes a corresponding XXEvent as parameter. Any class supporting XXEvents notification generally implements the XXListener interface and have support for registering those listeners through addXXListener methods and unregistering those listeners through removeXXLister methods. Most event targets allow any number of listeners to be registered with them. Also any listener  instance can be registered to receive events for any number of event source. Usually classes that support XXEvents() provide protected fireXX() methods used for constructing event objects and sending them to the event handlers for processing.&lt;br /&gt;&lt;br /&gt;The code below was repeated from an earlier one but with comments that emphasis some aspects of events handling. &lt;br /&gt;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;//implementing listeners that processes this event type &lt;br /&gt;public class Property extends JPanel implements ActionListener{ &lt;br /&gt;    &lt;br /&gt;    JButton jButton1 = new JButton(" ");&lt;br /&gt;    JTextField jText;&lt;br /&gt;    /** Creates a new instance of Property */&lt;br /&gt;    public Property() {&lt;br /&gt;        jButton1 = new JButton("button1");&lt;br /&gt;        add(jButton1);&lt;br /&gt;        &lt;br /&gt;        //registering instances of this class to receive this events&lt;br /&gt;        jButton1.addActionListener(this);&lt;br /&gt;        jText = new JTextField("welcome", 20);&lt;br /&gt;        add(jText);&lt;br /&gt;        &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    private static void dButton(){&lt;br /&gt;        JFrame.setDefaultLookAndFeelDecorated(true);&lt;br /&gt;        JFrame frame = new JFrame("Property");&lt;br /&gt;        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;        Property nProp = new Property();&lt;br /&gt;        nProp.setOpaque(true);&lt;br /&gt;        frame.setContentPane(nProp);&lt;br /&gt;        frame.pack();&lt;br /&gt;        frame.setVisible(true);   &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public void actionPerformed(ActionEvent e){  &lt;br /&gt;            //event handler with associated object as parameter&lt;br /&gt;            jText.setText(jButton1.getMaximumSize().toString());&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public static void main(String[] args){&lt;br /&gt;        javax.swing.SwingUtilities.invokeLater(new Runnable(){&lt;br /&gt;            public void run(){&lt;br /&gt;                dButton();&lt;br /&gt;            }&lt;br /&gt;        });&lt;br /&gt;    }    &lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-1766600016523574347?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/1766600016523574347/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=1766600016523574347' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/1766600016523574347'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/1766600016523574347'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/06/event-handling-and-dispatching.html' title='EVENT HANDLING AND DISPATCHING.'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-5009286765450316143</id><published>2007-06-06T06:05:00.000-07:00</published><updated>2007-06-06T06:06:01.270-07:00</updated><title type='text'>JCOMPONENT SIZING AND POSITIONING METHODS.</title><content type='html'>JCOMPONENT SIZING AND POSITIONING METHODS. &lt;br /&gt;&lt;br /&gt;Since JComponent extends java.awt.container, it inherits the sizing and positioning functionality of the AWT (for those familiar with AWT). &lt;br /&gt;&lt;br /&gt;To manage a component's preferred, minimum and maximum size, the following methods are used:&lt;br /&gt;&lt;br /&gt;the setters: setPreferred size(), setMinimumSize(), setMaximumsize().&lt;br /&gt;The getters: getPreferredSize(), getMinimumSize(), getMaximumSize().&lt;br /&gt; &lt;br /&gt;All these methods return a Dimension instance. Note that the size of components in a container is layout manager specific (the layout manager is the class responsible for laying out the components of a a container. ) The layout manager might ignore or respect sizing commands. &lt;br /&gt;&lt;br /&gt;To assign a component both a size and a position with its parent container, we use JComponent's setBounds() method. The method takes a rectangle parameter or 4 int parameters that represent the x-coordinate, y-coordinate, width and height. Note that layout managers always have the first crack at component sizing, so setBounds() might be ignored in some cases. Use setBounds though if your component has no layout manager. &lt;br /&gt;&lt;br /&gt;You can query a component's size using its getHeight() and getWidth() methods. &lt;br /&gt;&lt;br /&gt;Also we can set a component's position within its container using the setLocation(int x, int y) method. &lt;br /&gt;&lt;br /&gt;JComponent also maintains an alignment. Horizontal and vertical alignment can be specified by float values between 0.0 and 1.0. 0.5 means center, close to 0.0 means left or top and closer to 1.0 means right or bottom. The JComponent methods are : setAlignmentX(float f), setAlignmentY(float f).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-5009286765450316143?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/5009286765450316143/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=5009286765450316143' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/5009286765450316143'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/5009286765450316143'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/06/jcomponent-sizing-and-positioning.html' title='JCOMPONENT SIZING AND POSITIONING METHODS.'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-4415199412037105707</id><published>2007-06-06T06:01:00.000-07:00</published><updated>2007-06-06T06:04:10.455-07:00</updated><title type='text'>JCOMPONENT PROPERTIES.</title><content type='html'>JCOMPONENT PROPERTIES.&lt;br /&gt;&lt;br /&gt;All swing components conform to the javabeans specification. The javabeans specification will be discussed later. Among the five features a javabean is expected to support are a set of properties and associated accessor methods for them. &lt;br /&gt;&lt;br /&gt;Property: a property is a global variable. Accessor methods, if any, of a property are of the setPropertyName(), getPropertyName(), or isPropertyName() methods. &lt;br /&gt;&lt;br /&gt;a. Simple, bound and constrained properties. &lt;br /&gt;&lt;br /&gt;A simple property is a property that has no event firing associated with a change in its value. &lt;br /&gt;&lt;br /&gt;A bound property is a property from which a property change event is/are fired after it changes state. We can register propertyChangeListeners to listen for propertyChangeEvents through JComponent's addPropertyChangeListener method. &lt;br /&gt;&lt;br /&gt;Constrained porperty is a property for which propertyChangeEvents are fired before a change in state occurs. We can register vetoableChangeListeners to listen for propertyChangeEvents through JComponent's addVetoableChangeListener method. A change can be vetoed in the event handling code of a vetoableChangeListener by throwing a propertyVetoException. Only one swing class has constrained properties, the JInternalFrame class. &lt;br /&gt;&lt;br /&gt;PropertyChangeEvents carry three pieces of information: name of the property, old value and new values. Beans can use an instance of propertyChangeSuppport to manage the dispatching of propertyChangeEvents corresponding to each bound property to each registered listener. Also, an instance of vetoabableChangeSupport can be used to manage the sending of all propertyChangeEvents corresponding to each constrained property. There is a class in swing, swingPropertyChangeSupport in the javax.swing.events package that extends the propertyChangeSupport class and provides more efficient methods. &lt;br /&gt;&lt;br /&gt;Code for a class that demonstrates bound properties.&lt;br /&gt;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;public class Property extends JPanel implements ActionListener{&lt;br /&gt;    &lt;br /&gt;    JButton jButton1 = new JButton(" ");&lt;br /&gt;    JTextField jText;&lt;br /&gt;    /** Creates a new instance of Property */&lt;br /&gt;    public Property() {&lt;br /&gt;        jButton1 = new JButton("button1");&lt;br /&gt;        add(jButton1);&lt;br /&gt;        jButton1.addActionListener(this);&lt;br /&gt;        jText = new JTextField("welcome", 20);&lt;br /&gt;        add(jText);&lt;br /&gt;        &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    private static void dButton(){&lt;br /&gt;        JFrame.setDefaultLookAndFeelDecorated(true);&lt;br /&gt;        JFrame frame = new JFrame("Property");&lt;br /&gt;        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;        Property nProp = new Property();&lt;br /&gt;        nProp.setOpaque(true);&lt;br /&gt;        frame.setContentPane(nProp);&lt;br /&gt;        frame.pack();&lt;br /&gt;        frame.setVisible(true);   &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public void actionPerformed(ActionEvent e){&lt;br /&gt;            jText.setText(jButton1.getText());&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public static void main(String[] args){&lt;br /&gt;        javax.swing.SwingUtilities.invokeLater(new Runnable(){&lt;br /&gt;            public void run(){&lt;br /&gt;                dButton();&lt;br /&gt;            }&lt;br /&gt;        });&lt;br /&gt;    }    &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;b. Change properties. &lt;br /&gt;&lt;br /&gt;Change properties carry information about the source of a change. We use changeListeners to listen for changeEvents that get fired when these properties change state. ChangeEvents carry only one information, the source of the event. &lt;br /&gt;&lt;br /&gt;c. client property&lt;br /&gt;this property is implemented on a list such that for every propertyChange associated with a propertyChangeEvent, a list of propertyChangeListeners sought to notify all listeners for that event that a change has occurred. &lt;br /&gt;&lt;br /&gt;Properties of swing components will be discussed in the course of these discussion.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-4415199412037105707?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/4415199412037105707/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=4415199412037105707' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/4415199412037105707'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/4415199412037105707'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/06/jcomponent-properties.html' title='JCOMPONENT PROPERTIES.'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-6785665612601001248</id><published>2007-06-06T05:57:00.000-07:00</published><updated>2007-06-06T06:00:31.008-07:00</updated><title type='text'>HOW SWING IMPLEMENTS MVC.</title><content type='html'>HOW SWING IMPLEMENTS MVC.&lt;br /&gt;&lt;br /&gt;Swing packages each component's view and controller into an object called a user interface (UI) delegate, that is why, while reading the online java tutorial you'll be told that swing's architecture is not really MVC but a model-delegate. Model-delegate communication is indirect, like the MVC conception therefore one UI delegate can be associated with more than one model. &lt;br /&gt;&lt;br /&gt;The base class of all UI delegates is in the swing pluggable look and feel architecture,  i.e  javax.swing.plaf.ComponentUI or in brief, ComponentUI class. &lt;br /&gt;&lt;br /&gt;Important methods of the ComponentUI class although this class is not invoked directly are:&lt;br /&gt;a. createUI. This method is a static public method and it returns a ComponentUI while accepting a JComponent as its parameter. The method returns an instance of the UI delegate for the specified component. Each subclass of this class must provide a static createUI method. &lt;br /&gt;b. installUI. This method configures the specified component appropriate for the look and feel. Invoked when the ComponentUI instance is being installed as the UI delegate on the specified component. This method completely configures the component for the look and feel.&lt;br /&gt;&lt;br /&gt;Read up the above method and others in the api. UI delegate and their use in swing components will be discussed in forthcoming discussions. &lt;br /&gt;&lt;br /&gt;In swing, there are sets of UI delegates which contains ComponentUI implementation of most swing components, and each of the sets is called a look and feel or a pluggable look and feel (PLAF). From the api, you'll realize that there are four pluggable look and feel packages, basic, metal, multiplexing and synth. Basic is the set from which every component implements&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-6785665612601001248?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/6785665612601001248/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=6785665612601001248' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/6785665612601001248'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/6785665612601001248'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/06/how-swing-implements-mvc.html' title='HOW SWING IMPLEMENTS MVC.'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-6548950868210451903</id><published>2007-06-06T05:54:00.000-07:00</published><updated>2007-06-06T05:56:46.588-07:00</updated><title type='text'>MVC ARCHITECTURE:</title><content type='html'>MVC ARCHITECTURE:&lt;br /&gt;&lt;br /&gt;Model view controller, (MVC), is a user interface design decomposition that breaks down components into three parts: a model, a view and a controller. &lt;br /&gt;&lt;br /&gt;In this three-way separation model, a mode l is responsible for maintaining all aspects of the component state e.g whether a button was pressed or unpressed, the character data of a text component, the opacity value of a window. A model communicates indirectly with the view and the controller i.e this communication is carried out  without the model knowing its view or controller. &lt;br /&gt;&lt;br /&gt;The view is the visual representation of the component's model or what is called the “look”. One noticeable example is the font of a character on a button or color of a label. The view receives indirect messages from the model and direct messages from the controller and is responsible for keeping its on-screen representation updated. &lt;br /&gt;&lt;br /&gt;The controller is responsible for event management or the reaction of the component to events such as input devices such as the keyboard or mouse. The controller is the “feel” of the component, determining component actions. The controller receives direct messages from the view, and indirect messages from the model. &lt;br /&gt;&lt;br /&gt;Let's illustrate the MVC concept: imagine a button with the state unpressed. On the model, this is the state and the view shows a button that is unpressed, idle. If a user clicks on the button, an event received by the controller, the controller translates this as a press or the button sends a direct message to the view, the view now looks “pressed” and send a message to the model to change its state to press = true. &lt;br /&gt;&lt;br /&gt;Advantages of the MVC architecture:&lt;br /&gt;1.we can customize the “look”(view) and “feel”(controller) of a component without affect the model.&lt;br /&gt;2.We can customize specific parts of a component without affecting the model. &lt;br /&gt;3.We can customize and replace a component's data model. &lt;br /&gt;&lt;br /&gt;If you check the api there are various interfaces for the swing components that implement models and you will find references to the models that are implemented. In the course of the following weeks we will also be implementing this models in our classes for the swing components.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-6548950868210451903?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/6548950868210451903/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=6548950868210451903' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/6548950868210451903'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/6548950868210451903'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/06/mvc-architecture.html' title='MVC ARCHITECTURE:'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-5532355071792368605</id><published>2007-06-06T05:53:00.001-07:00</published><updated>2007-06-06T05:53:54.798-07:00</updated><title type='text'>Z-ORDER IN SWING.</title><content type='html'>Z-ORDER IN SWING.&lt;br /&gt;&lt;br /&gt;According to the api, swing components are lightweight. On the other hand AWT components are heavyweight. The difference between the two terms is z-order i.e the notion of depth or layering. &lt;br /&gt;&lt;br /&gt;A heavyweight component occupies its own z-order layer while all lightweight components are contained inside heavyweight components and maintain their own layering scheme as defined by swing. If a heavyweight container is placed inside another heavyweight container, it will, by definition, overlap all lightweights in that container. Therefore, avoid using both heavyweight and lightweight components in the same container wherever possible. Although they can both be mixed one has to be careful while doing so. &lt;br /&gt;&lt;br /&gt;Note though that:&lt;br /&gt;1.you should not place heavyweight components inside lightweight containers that commonly support overlapping children.&lt;br /&gt;2.If using  popup menus in a container holding a heavyweight component, force that popup to be heavyweight. On the other hand, swing has much functionality that makes the use of AWT heavyweight components really less useful. &lt;br /&gt; &lt;br /&gt;One useful reason why swing is preferred over AWT is due to its platform independence. On the other hand there are swing container classes like JApplet, JDialog, JFrame and JWindow which are direct AWT class subclasses that are platform dependent.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-5532355071792368605?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/5532355071792368605/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=5532355071792368605' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/5532355071792368605'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/5532355071792368605'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/06/z-order-in-swing.html' title='Z-ORDER IN SWING.'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-5079822303044886664</id><published>2007-06-06T05:50:00.000-07:00</published><updated>2007-06-06T05:51:27.689-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='swing'/><category scheme='http://www.blogger.com/atom/ns#' term='javax'/><category scheme='http://www.blogger.com/atom/ns#' term='components'/><title type='text'>SWING PACKAGE DESCRIPTION:</title><content type='html'>SWING PACKAGE DESCRIPTION:&lt;br /&gt;&lt;br /&gt;Swing components range from the very simple, e.g. JLabel, to the very complex, e.g JTable, JTree. Almost all swing components are derived from a single parent called JComponent which extends the AWT Container class. You now see why swing is called a layer on top of AWT. Top-level containers though like JFrame, JDialogue and JApplet do not inherit from JComponent but rather serve as places where any class that inherits from JComponent can paint itself. We'll explain swing components and the containment hierarchy later. &lt;br /&gt;&lt;br /&gt;Am sure you must have realised that every class in swing that compares to an AWT equivalent is prefixed with 'J', this is because all the names have already been taken.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-5079822303044886664?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/5079822303044886664/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=5079822303044886664' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/5079822303044886664'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/5079822303044886664'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/06/swing-package-description.html' title='SWING PACKAGE DESCRIPTION:'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-501390746044806276</id><published>2007-06-06T05:44:00.000-07:00</published><updated>2007-06-06T05:49:13.924-07:00</updated><title type='text'>INTRODUCTION TO SWING.</title><content type='html'>INTRODUCTION TO SWING. (I had to diverge from the JLS to swing because i fell in love with it.)&lt;br /&gt;&lt;br /&gt;Each user of an application want to use a software that not only is pleasing to the eyes but which usage is simple to discover. Back in the day, before user interfaces became so glorified, computers were horrible mammoths reserved for just scientists. Today, a youth in  a garage can devise glorious graphical functionalities on the internet using ajax and flex and likewise make an application speak with user interfaces, one of them being the java user interface which is not left out in the conference. &lt;br /&gt;&lt;br /&gt;Before the swing revolution, the designers of the java language created a set of classes called the abstract window toolkit (AWT)  used for creating user interfaces, painting graphics and rendering images on computer screens and other devices. But the AWT had platform compatibility problems that make it frustrating and not up to par with its competition in the user interface space. So back to the drawing board went the designers and they came out with swing, a set of revolutionary user interfaces that along with the java component reusability feature of beans is comparable to the visual modeling capabilities of VB. &lt;br /&gt;&lt;br /&gt;Swing is incorporated into the java foundation class or JFC which comprises of AWT, Swing, Accessibility, Java 2D, and Drag and Drop. &lt;br /&gt;&lt;br /&gt;Swing is built on top of AWT and the naming of its classes follows the AWT. These two libraries are one the two important libraries any java programmer will never do without. &lt;br /&gt;&lt;br /&gt;The swing classes are in the javax.swing package of the api and according to the api, this package provides a set of lightweight components that to the maximum degree possible, work on all platforms.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-501390746044806276?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/501390746044806276/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=501390746044806276' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/501390746044806276'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/501390746044806276'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/06/introduction-to-swing.html' title='INTRODUCTION TO SWING.'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-8071985562922862416</id><published>2007-04-13T03:24:00.000-07:00</published><updated>2007-04-13T03:25:09.150-07:00</updated><title type='text'>SNIPPET, java.lang.Math</title><content type='html'>SNIPPET, java.lang.Math&lt;br /&gt;&lt;br /&gt;Sometimes it is necessary to take time off from the usual and play with the application programming interface. We’ll be using some of the functionalities here when we start real time coding. &lt;br /&gt;&lt;br /&gt;package transkawa;&lt;br /&gt;&lt;br /&gt;class MathAPI {&lt;br /&gt; static double container = 2.0098765d;&lt;br /&gt; public static void main(String[] args){&lt;br /&gt;  System.out.println("Base log to e is: "+Math.E);&lt;br /&gt;  System.out.println("PI is "+Math.PI+" in double &lt;br /&gt;primitive.");&lt;br /&gt;  &lt;br /&gt;  //the absolute value of PI is&lt;br /&gt;  System.out.println("PI in absolute values &lt;br /&gt;is:"+Math.abs(Math.PI));&lt;br /&gt;  System.out.println("log e in abs value is: &lt;br /&gt;"+Math.abs(Math.E));&lt;br /&gt;  System.out.println("Absolute value of our container &lt;br /&gt;"+Math.abs(container));&lt;br /&gt;  &lt;br /&gt;  //the smallest double value that is greater than or equal&lt;br /&gt;  //to the double value of container and equal to an integer&lt;br /&gt;  System.out.println("The ceiling value of container is: &lt;br /&gt;"+Math.ceil(container));&lt;br /&gt;  System.out.println("While the floor is: &lt;br /&gt;"+Math.floor(container));&lt;br /&gt;  &lt;br /&gt;  //raising the floor by 2&lt;br /&gt;  System.out.println("Let's raise the floor of container to &lt;br /&gt;2: "+Math.pow(Math.floor(container), 2));&lt;br /&gt;  &lt;br /&gt;  //the cosine assuming container is an angle&lt;br /&gt;  System.out.println("The cosine of container is: &lt;br /&gt;"+Math.cos(container));&lt;br /&gt;  &lt;br /&gt;  //we can test for mathematical greater than&lt;br /&gt;  System.out.println("The greater of PI and log e is: &lt;br /&gt;"+Math.max(Math.PI, Math.E));&lt;br /&gt;  &lt;br /&gt;  //a random number generator also exists for Math class&lt;br /&gt;  //you get random numbers all the time:)&lt;br /&gt;  System.out.println("What u see is what u get: &lt;br /&gt;"+Math.random());&lt;br /&gt;  &lt;br /&gt;  //let's do a narrowing primitive conversion on container&lt;br /&gt;  System.out.println("double to long gives: &lt;br /&gt;"+Math.round(container));&lt;br /&gt;  &lt;br /&gt;  //a little square root pleae&lt;br /&gt;  System.out.println("square root of 2.0098756 is: &lt;br /&gt;"+Math.sqrt(container));&lt;br /&gt;  &lt;br /&gt;  System.out.println(Math.ulp(container));&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-8071985562922862416?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/8071985562922862416/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=8071985562922862416' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/8071985562922862416'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/8071985562922862416'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/snippet-javalangmath.html' title='SNIPPET, java.lang.Math'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-227448954923937923</id><published>2007-04-13T03:13:00.001-07:00</published><updated>2007-04-13T03:24:00.139-07:00</updated><title type='text'>SNIPPET, java.lang.StringBuilder</title><content type='html'>SNIPPET, java.lang.StringBuilder&lt;br /&gt;&lt;br /&gt;This class defines a mutable sequence of characters. It was created as a drop-in replacement for StringBuffer class in places where the StringBuffer would be used for single threaded actions. &lt;br /&gt;&lt;br /&gt;The principal operations in a StringBuilder are the append and insert methods which are overloaded and accept data of any type. A given datum is effectively converted to a string and the characters of that string inserted or appended to the StringBuilder where the append method add these characters at the end of the builder and the insert method at a specified point. &lt;br /&gt;&lt;br /&gt;Here is a simple class, BuilderExample, that is based on the principles of the StringBuilder class. &lt;br /&gt;&lt;br /&gt;package transkawa;&lt;br /&gt;&lt;br /&gt;class BuilderExample {&lt;br /&gt; static StringBuilder stringchain = new StringBuilder("A");&lt;br /&gt; static final String initialchain = stringchain.toString();&lt;br /&gt; String spaces = " ";&lt;br /&gt; static String current="Current string chain: ";&lt;br /&gt; &lt;br /&gt; //to append strings in this class, first attach a space&lt;br /&gt; //then attach the string. Append always at the last position&lt;br /&gt; void appendString(String str){&lt;br /&gt;  stringchain.append(spaces);&lt;br /&gt;  stringchain.append(str);&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //this method appends a char without spaces &lt;br /&gt; void appendChar(char ch){&lt;br /&gt;  stringchain.append(ch);&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //insertString at any position before the last string in chain&lt;br /&gt; void insertString(String str, String insertbefore){&lt;br /&gt;  int theindex = stringchain.indexOf(insertbefore);&lt;br /&gt;  stringchain.insert(theindex, str);&lt;br /&gt;  theindex += str.length();&lt;br /&gt;  stringchain.insert(theindex, spaces);&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //properties method&lt;br /&gt; int propMethod(char ch){&lt;br /&gt;  int resultvar = 0;&lt;br /&gt;  for (int i=0; i&lt;stringchain.length(); i++){&lt;br /&gt;   if(stringchain.charAt(i) == ch ){&lt;br /&gt;    resultvar +=1;&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;  return resultvar;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; &lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  //an instance of our class&lt;br /&gt;  BuilderExample build = new BuilderExample();&lt;br /&gt;  &lt;br /&gt;  //on instantiating the string contains only "A"&lt;br /&gt;  System.out.println("Initial chain is "+initialchain);&lt;br /&gt;  &lt;br /&gt;  //we're appending the string "Teaching" to the chain&lt;br /&gt;  build.appendString("Teaching");&lt;br /&gt;  System.out.println(current+BuilderExample.stringchain);&lt;br /&gt;  &lt;br /&gt;  //we'll insert a string at a chosen position&lt;br /&gt;  build.insertString("Tremendous", "Teaching");&lt;br /&gt;  System.out.println(current+BuilderExample.stringchain);&lt;br /&gt;  &lt;br /&gt;  //let's add "Tool" after "Teaching"&lt;br /&gt;  build.appendString("Tool");&lt;br /&gt;  System.out.println(current+BuilderExample.stringchain);&lt;br /&gt;  &lt;br /&gt;  //suppose we made a mistake, we didn't insert '!' in "Tool"&lt;br /&gt;  build.appendChar('!');&lt;br /&gt;  System.out.println(current+BuilderExample.stringchain);&lt;br /&gt;  &lt;br /&gt;  //if we want to know the properties of the string built&lt;br /&gt;  System.out.print("There are "+(build.propMethod(' ')+1)+" &lt;br /&gt;words");&lt;br /&gt;  System.out.println(" and &lt;br /&gt;+BuilderExample.stringchain.length()+" characters in the chain");    &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Enjoy!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-227448954923937923?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/227448954923937923/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=227448954923937923' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/227448954923937923'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/227448954923937923'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/snippet-javalangstringbuilder_13.html' title='SNIPPET, java.lang.StringBuilder'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-3643999581950825565</id><published>2007-04-13T03:13:00.000-07:00</published><updated>2007-04-13T03:14:12.787-07:00</updated><title type='text'>SNIPPET, java.lang.StringBuilder</title><content type='html'>SNIPPET, java.lang.StringBuilder&lt;br /&gt;&lt;br /&gt;This class defines a mutable sequence of characters. It was created as a drop-in replacement for StringBuffer class in places where the StringBuffer would be used for single threaded actions. &lt;br /&gt;&lt;br /&gt;The principal operations in a StringBuilder are the append and insert methods which are overloaded and accept data of any type. A given datum is effectively converted to a string and the characters of that string inserted or appended to the StringBuilder where the append method add these characters at the end of the builder and the insert method at a specified point. &lt;br /&gt;&lt;br /&gt;Here is a simple class, BuilderExample, that is based on the principles of the StringBuilder class. &lt;br /&gt;&lt;br /&gt;package transkawa;&lt;br /&gt;&lt;br /&gt;class BuilderExample {&lt;br /&gt; static StringBuilder stringchain = new StringBuilder("A");&lt;br /&gt; static final String initialchain = stringchain.toString();&lt;br /&gt; String spaces = " ";&lt;br /&gt; static String current="Current string chain: ";&lt;br /&gt; &lt;br /&gt; //to append strings in this class, first attach a space&lt;br /&gt; //then attach the string. Append always at the last position&lt;br /&gt; void appendString(String str){&lt;br /&gt;  stringchain.append(spaces);&lt;br /&gt;  stringchain.append(str);&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //this method appends a char without spaces &lt;br /&gt; void appendChar(char ch){&lt;br /&gt;  stringchain.append(ch);&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //insertString at any position before the last string in chain&lt;br /&gt; void insertString(String str, String insertbefore){&lt;br /&gt;  int theindex = stringchain.indexOf(insertbefore);&lt;br /&gt;  stringchain.insert(theindex, str);&lt;br /&gt;  theindex += str.length();&lt;br /&gt;  stringchain.insert(theindex, spaces);&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //properties method&lt;br /&gt; int propMethod(char ch){&lt;br /&gt;  int resultvar = 0;&lt;br /&gt;  for (int i=0; i&lt;stringchain.length(); i++){&lt;br /&gt;   if(stringchain.charAt(i) == ch ){&lt;br /&gt;    resultvar +=1;&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;  return resultvar;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; &lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  //an instance of our class&lt;br /&gt;  BuilderExample build = new BuilderExample();&lt;br /&gt;  &lt;br /&gt;  //on instantiating the string contains only "A"&lt;br /&gt;  System.out.println("Initial chain is "+initialchain);&lt;br /&gt;  &lt;br /&gt;  //we're appending the string "Teaching" to the chain&lt;br /&gt;  build.appendString("Teaching");&lt;br /&gt;  System.out.println(current+BuilderExample.stringchain);&lt;br /&gt;  &lt;br /&gt;  //we'll insert a string at a chosen position&lt;br /&gt;  build.insertString("Tremendous", "Teaching");&lt;br /&gt;  System.out.println(current+BuilderExample.stringchain);&lt;br /&gt;  &lt;br /&gt;  //let's add "Tool" after "Teaching"&lt;br /&gt;  build.appendString("Tool");&lt;br /&gt;  System.out.println(current+BuilderExample.stringchain);&lt;br /&gt;  &lt;br /&gt;  //suppose we made a mistake, we didn't insert '!' in "Tool"&lt;br /&gt;  build.appendChar('!');&lt;br /&gt;  System.out.println(current+BuilderExample.stringchain);&lt;br /&gt;  &lt;br /&gt;  //if we want to know the properties of the string built&lt;br /&gt;  System.out.print("There are "+(build.propMethod(' ')+1)+" &lt;br /&gt;words");&lt;br /&gt;  System.out.println(" and &lt;br /&gt;+BuilderExample.stringchain.length()+" characters in the chain");    &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Enjoy!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-3643999581950825565?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/3643999581950825565/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=3643999581950825565' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/3643999581950825565'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/3643999581950825565'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/snippet-javalangstringbuilder.html' title='SNIPPET, java.lang.StringBuilder'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-5679886009829988548</id><published>2007-04-13T03:12:00.000-07:00</published><updated>2007-04-13T03:13:10.238-07:00</updated><title type='text'>INTERFACES(4)</title><content type='html'>INTERFACES(4)&lt;br /&gt;&lt;br /&gt;ANNOTATIONS&lt;br /&gt;Annotations provide data about a program that is not part of the program itself. They have no direct effect on the operation of the code they annotate. &lt;br /&gt;&lt;br /&gt;Annotations have a number of uses, among which are:&lt;br /&gt;1. they provide information for compilers and can be used to detect or suppress warnings. &lt;br /&gt;2. can be used for compiler-time and deployment-time processing. Software tools can process annotations to generate code, XML files and so forth. &lt;br /&gt;3. for runtime processing. Some annotations are available for examination at runtime. &lt;br /&gt;&lt;br /&gt;Note that annotations may be used as modifiers in any declaration, whether package, class, interface, field, method, parameter, constructor or local variable. &lt;br /&gt;&lt;br /&gt;package examples;&lt;br /&gt;&lt;br /&gt;public @interface Author {&lt;br /&gt; String name();&lt;br /&gt; String date();}&lt;br /&gt;&lt;br /&gt;//annotation as modifier for class MyClass&lt;br /&gt;//annotations *must* contain an element-value pair for&lt;br /&gt;//every element of the corresponding annotation type&lt;br /&gt;@Author (&lt;br /&gt;  name="nnaemeka david",&lt;br /&gt;  date="10/04/2007"&lt;br /&gt;  )&lt;br /&gt;public class MyClass {}&lt;br /&gt;&lt;br /&gt;annotations may also be used on enum constants. &lt;br /&gt;&lt;br /&gt;A compile time error is more than one annotation is specified for a declaration. &lt;br /&gt;&lt;br /&gt;There are 3 kinds of annotations:&lt;br /&gt;1. normal annotations – these are fully general annotations&lt;br /&gt;2. marker annotations – these are shorthand annotations&lt;br /&gt;3. single-element annotations  - these are shorthand annotations&lt;br /&gt;&lt;br /&gt;Normal annotations: normal annotations are used to annotate program elements. &lt;br /&gt;&lt;br /&gt;Notation:  @TypeName (ElementValuePairsopt)&lt;br /&gt;&lt;br /&gt;Where ElementValuePairs are notated as:   Identifier = ElementValue&lt;br /&gt;&lt;br /&gt;And ElementValue is either:&lt;br /&gt;a. a conditional expression&lt;br /&gt;b. an annotation&lt;br /&gt;c. an element value array initialiser which is notated as {ElementValueopt,opt}&lt;br /&gt;&lt;br /&gt;example:&lt;br /&gt;public @interface Author {&lt;br /&gt;String name(); //return type of this method defines the element type &lt;br /&gt;  //of the element-value pair &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//here, TypeName is Author; identifier is name, Element&lt;br /&gt;//value conforms to the return type for method name in&lt;br /&gt;//Author annotation, which is String. &lt;br /&gt;@Author(name="nnaemeka david")&lt;br /&gt;public class MyClass {}&lt;br /&gt;&lt;br /&gt;the element type T of the element-value pair is commensurate with an element value V if and only if one of the following conditions is true:&lt;br /&gt;1. T is an array type E[] and either &lt;br /&gt;a. V is an ElementValueArrayInitialiser and each ElementValue initialized in V is commensurate with E, or&lt;br /&gt;b. V is an element value that is commensurate with T&lt;br /&gt;&lt;br /&gt;2. The type of V is assignment compatible with T  and therefore&lt;br /&gt;a. If T is a primitive type or String, V is a constant expression&lt;br /&gt;b. V is not null&lt;br /&gt;c. If T is Class, or an invocation of Class, and V is a class literal&lt;br /&gt;d. If T is an enum type and V is an enum constant. &lt;br /&gt;Element types must always be commensurate with element values. &lt;br /&gt;Little example:&lt;br /&gt;&lt;br /&gt;package examples;&lt;br /&gt;&lt;br /&gt;public @interface Author {&lt;br /&gt; int[] number();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public @interface Author {&lt;br /&gt; int[] number();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;An annotation on an annotation type declaration is called a meta-annotation. &lt;br /&gt;&lt;br /&gt;import java.lang.annotation.*;  //these type on demand import necessary &lt;br /&gt; //to use @Document annotation&lt;br /&gt;&lt;br /&gt;//a meta-annotation&lt;br /&gt;@Documented&lt;br /&gt;public @interface Author {&lt;br /&gt; int[] number();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Marker annotations: marker annotations notated as:    @TypeName     &lt;br /&gt;are simply shorthands for the normal annotation, @TypeName(). &lt;br /&gt;&lt;br /&gt;package examples;&lt;br /&gt;&lt;br /&gt;import java.lang.annotation.*;&lt;br /&gt;&lt;br /&gt;@Documented&lt;br /&gt;public @interface Author {}&lt;br /&gt;&lt;br /&gt;//marker annotation&lt;br /&gt;@Author()&lt;br /&gt;public class MyClass {}&lt;br /&gt;&lt;br /&gt;Simple-element annotation: this is a shorthand designed for use with single-element annotation types. Note that by convention, single-element annotation types have a single method, value. &lt;br /&gt;&lt;br /&gt;The notation for single-element annotation is:     @TypeName(ElementValue) which is the shorthand for the normal annotation: @TypeName(value = ElementValue). &lt;br /&gt;&lt;br /&gt;package examples;&lt;br /&gt;&lt;br /&gt;import java.lang.annotation.*;&lt;br /&gt;&lt;br /&gt;@Documented&lt;br /&gt;public @interface Author {&lt;br /&gt; String value();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//single-element annotation&lt;br /&gt;@Author("david")&lt;br /&gt;public class MyClass {}&lt;br /&gt;&lt;br /&gt;there are lots of examples in section §9.7 that illustrates this three types of annotations.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-5679886009829988548?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/5679886009829988548/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=5679886009829988548' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/5679886009829988548'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/5679886009829988548'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/interfaces4.html' title='INTERFACES(4)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-4595718077390908523</id><published>2007-04-13T03:10:00.000-07:00</published><updated>2007-04-13T03:11:00.724-07:00</updated><title type='text'>INTERFACES(3)</title><content type='html'>INTERFACES(3)&lt;br /&gt;&lt;br /&gt;ANNOTATION TYPES&lt;br /&gt;An annotation type declaration is a special type of interface declaration using the at sign @ along with the keyword interface.&lt;br /&gt;&lt;br /&gt;Notation: &lt;br /&gt;InterfaceModifiersopt    @interface     Identifier     AnnotationTypeBody&lt;br /&gt;&lt;br /&gt;AnnotationTypeBody:     {AnnotationTypeElementDeclarationopt}&lt;br /&gt;&lt;br /&gt;Where the annotation type element declarations can be one or many and notated as either one or many of:&lt;br /&gt;AbstractMethodModifiersopt     Type     Identifier()     DefaultValueopt;&lt;br /&gt;ConstantDeclaration&lt;br /&gt;ClassDeclaration&lt;br /&gt;InterfaceDeclaration&lt;br /&gt;EnumDeclaration&lt;br /&gt;AnnotationTypeDeclaration&lt;br /&gt;;&lt;br /&gt;&lt;br /&gt;The default values are notated thus:   default     ElementValue&lt;br /&gt;&lt;br /&gt;By virtue of its context free syntax, the following restrictions are imposed on annotation type declarations:&lt;br /&gt;1. annotation type declarations cannot be generic&lt;br /&gt;2. no extends clause is permitted (annotation types (denoted with the sign @) implicitly extend annotation.Annotation.)&lt;br /&gt;3. methods cannot have any parameter&lt;br /&gt;4. methods cannot have any type parameter.&lt;br /&gt;5. method declarations cannot have a throws clause.&lt;br /&gt;&lt;br /&gt;Take note: unless explicitly modified, all the rules applying to ordinary interface declarations apply to annotation type declarations. &lt;br /&gt;&lt;br /&gt;The identifier in an annotation type declaration specifies the annotation type name and it cannot be the same simple name as any of its enclosing classes or interfaces. &lt;br /&gt;&lt;br /&gt;If an annotation a on an annotation type declaration corresponds to an annotation type T, and T has a (meta-)annotation m that corresponds to annotation.Target, then m must have an element whose value is annotation.ElementType.ANNOTATION_TYPE or annotation.ElementType.TYPE or a compile time error occurs. &lt;br /&gt;&lt;br /&gt;The direct superinterface of an annotation type is always annotation.Annotation.&lt;br /&gt;&lt;br /&gt;The return type of a method declared in an annotation type is either:&lt;br /&gt;1. one of the primitive types&lt;br /&gt;2. String&lt;br /&gt;3. Class and any invocation of Class&lt;br /&gt;4. an enum type&lt;br /&gt;5. an annotation type&lt;br /&gt;6. an array of any of the types above,&lt;br /&gt;otherwise a compile time error occurs. &lt;br /&gt;&lt;br /&gt;If any method declaration in an annotation type has a signature that is override-equivalent to that of any public or protected method declared in the class Object or in the interface annotation.Annotation, then a compile time error occurs. &lt;br /&gt;&lt;br /&gt;Each method declaration in an annotation type declaration defines an element of the annotation type. Annotation types can have zero or more elements which are only those defined by the methods it explicitly declares. &lt;br /&gt;&lt;br /&gt;A compile time error for an annotation of type T to contain an element of type T, either directly or indirectly. &lt;br /&gt;&lt;br /&gt;An annotation type element may have a default value specified. This is done by following the empty parameter list with the keyword default and then the default value of the element. &lt;br /&gt;&lt;br /&gt;An ElementValue is used to specify a default value and must be correctly typed otherwise a compile time error. An ElementValue is always FP-strict. &lt;br /&gt;&lt;br /&gt;(see jls for example. No need to duplicate it here. )&lt;br /&gt;&lt;br /&gt;By convention, value is the name of the sole element in a single-element annotation type. &lt;br /&gt;&lt;br /&gt;Predefined annotation types:&lt;br /&gt;Target: this predefined annotation type is used in meta-annotations to indicate that the kind of program element an annotation type is applicable to. &lt;br /&gt;&lt;br /&gt;Target has one element of, annotation.ElementType[]&lt;br /&gt;&lt;br /&gt;The meta-annotation below indicates that the declared type is itself a meta-annotation type. It can only be used on annotation type declarations.&lt;br /&gt; &lt;br /&gt;@Target (ElementType.ANNOTATION_TYPE)&lt;br /&gt;public @interface MetaAnnotationtype { ... }&lt;br /&gt;&lt;br /&gt;the meta-annotation below indicates that the declared type is intended solely for use as a member type in complex annotation type declarations. It cannot be used to annotate anything directly. &lt;br /&gt;&lt;br /&gt;@Target ({})&lt;br /&gt;public @interface MemberType { ... }&lt;br /&gt;&lt;br /&gt;note: a single ElementType cannot appear more than once in a Target annotation. &lt;br /&gt;&lt;br /&gt;Retention: indicates if annotations may be present only in the source code or in the binary form of a class or interface. The annotation type, annotation.Retention is used to choose between the above two.&lt;br /&gt;&lt;br /&gt;If an annotation a corresponds to type T and T has a meta-annotation m that corresponds to annotation.Retention, then&lt;br /&gt;- if m has an element whose value is annotation.RetentionPolicy.SOURCE, then a java compiler must ensure that a is not present in the binary representation of the class and interface in which it appears. &lt;br /&gt;- If m has an element with value annotation.RetentionPolicy.CLASS , or annotation.RetentionPolicy.RUNTIME, then a java compiler must ensure that a is represented in the binary representation of the class or interface in which a appears, unless m annotates a local variable declaration, then it won’t be retained in the binary representation.&lt;br /&gt;&lt;br /&gt;Inherited: this indicates that annotations on this class are automatically inherited.&lt;br /&gt;&lt;br /&gt;Override: this annotation is useful for early detection of programmers mistaking an overload for an override for a method. &lt;br /&gt;&lt;br /&gt;If a method declaration is annoted with the annotation @override, but this method does not in fact override any method declared in a superclass, a compile time error will occur. &lt;br /&gt;&lt;br /&gt;SuppressWarnings: used to indicate that the named compiler warnings should be suppressed in the annotated element (and in all program elements contained in the annotated element). It contains a single element that is an array of String.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-4595718077390908523?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/4595718077390908523/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=4595718077390908523' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/4595718077390908523'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/4595718077390908523'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/interfaces3.html' title='INTERFACES(3)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-976975089946587966</id><published>2007-04-13T03:09:00.000-07:00</published><updated>2007-04-13T03:10:01.506-07:00</updated><title type='text'>INTERFACES(2)</title><content type='html'>INTERFACES(2)&lt;br /&gt;&lt;br /&gt;INTERFACE MEMBERS:&lt;br /&gt;The members of an interface are:&lt;br /&gt;1. those members declared in the interface&lt;br /&gt;2. members inherited from direct superinterfaces&lt;br /&gt;3. where there is no direct superinterface, then the interface implicitly declares a public abstract member m with signature s return type r and throws clause t corresponding to each public instance method m with signature s return type r and throws clause t declared in Object unless an explicit declaration of a method with the same signature, return type and compatible throws clause exists. If m is declared to be final in Object and the interface explicitly declares me, then a compile time error results.&lt;br /&gt; &lt;br /&gt;It is a compile time error if the interface declares a method with a signature that is override-equivalent to a public method of Object, but has a different return type or incompatible throws clause.  &lt;br /&gt;&lt;br /&gt;Except for those fields, classes and interfaces that is hides and methods it overrides, an interface inherits members of an interface it extends. &lt;br /&gt;&lt;br /&gt;FIELD (CONSTANT) DECLARATION:&lt;br /&gt;Constant declaration:&lt;br /&gt;&lt;br /&gt; ConstantModifiersopt          Type          VariableDeclarators;&lt;br /&gt;&lt;br /&gt;Where constant modifiers are one of:&lt;br /&gt; Annotation     public     static     final&lt;br /&gt;&lt;br /&gt;Note: every field declaration in the body of an interface is implicitly public static final. Redundant modifier specification is allowed. &lt;br /&gt;&lt;br /&gt;If an annotation a on a field declaration corresponds to an annotation type T, and T has a (meta-)annotation m that corresponds to annotation.Target, then m must have an element whose value is annotation.ElementType.FIELD, or a compile time error occurs. &lt;br /&gt;&lt;br /&gt;A same name field in an interface with its superinterface hides the field of the superinterface provided they are accessible and the field exists. &lt;br /&gt;&lt;br /&gt;Although an interface can inherit two fields with the same name, referencing this fields using their simple names will result in compile time error due to ambiguous referencing. &lt;br /&gt;&lt;br /&gt;If inheritance of a field can be done through several paths, inheritance is considered to be just once and the field’s simple name can be used to referenced it. &lt;br /&gt;&lt;br /&gt;Initialisation of fields in interfaces:&lt;br /&gt;Every field in the body of an interface must have an initialization expression, which need not be a constant expression. When the interface is initialized, the variable initialiser is evaluated  and the assignment performed exactly once. &lt;br /&gt;&lt;br /&gt;Note:  &lt;br /&gt;1. initialization expression for an interface field cannot contain a reference by simple name, a. to itself; or b. to another field whose declaration occurs textually later in the same interface.&lt;br /&gt;2. the keywords this or super cannot occur in the initialization expression for a field of an interface unless this occurrence is within the body of an anonymous class.&lt;br /&gt; &lt;br /&gt;(the jls contains some straight-to-the-point examples for the above, at section §9.3) &lt;br /&gt;&lt;br /&gt;ABSTRACT METHOD DECLARATION:&lt;br /&gt;Notation:  &lt;br /&gt;AbstractMethodModifiersopt     TypeParametersopt     ResultType     MethodDeclarator     Throwsopt&lt;br /&gt;&lt;br /&gt;Abstract method modifiers can be one of the following:&lt;br /&gt;Annotation       public      abstract&lt;br /&gt;&lt;br /&gt;Modifier appearance redundancy is not allowed. &lt;br /&gt;&lt;br /&gt;Every method declaration in an interface body is implicitly abstract, so its body is always represented by a semicolon, ;, and not a block. &lt;br /&gt;&lt;br /&gt;Every method declaration in the body of an interface is implicitly public. &lt;br /&gt;&lt;br /&gt;Abstract methods cannot be static and vice versa, so member interface methods can never be static. &lt;br /&gt;&lt;br /&gt;Annotation rules also apply to interface methods i.e if an annotation a on a method declaration corresponds to an annotation type T, and T has a (meta-)annotation m that corresponds to annotation.Target, then m must have an element whose value is annotation.ElementType.METHOD, or a compile time error occurs. &lt;br /&gt;&lt;br /&gt;These are known compile time errors:&lt;br /&gt;1. for an interface to declare two methods with override-equivalent signatures, whether implicitly or explicitly. However, an interface may inherit several methods with such signatures. &lt;br /&gt;2. interface methods must not be declared final although implementing classes can declare its implementation as final&lt;br /&gt;3. interface methods may be generic. &lt;br /&gt;&lt;br /&gt;Inheritance and overriding.&lt;br /&gt;If an interface I has an instance method m1 and interface J has an instance method m2, m1 overrides m2 if and only if the following are true:&lt;br /&gt;- I is a subinterface of J&lt;br /&gt;- The signature of m1 is a subsignature of the signature of m2.&lt;br /&gt;&lt;br /&gt;Note that overriding and hiding implies return type substitutability along with subtyping on the overriding type which can issue an unchecked warning. &lt;br /&gt;&lt;br /&gt;A method declaration does not have a throws clause that conflicts with that of any method it overrides, otherwise, compile time error occurs. &lt;br /&gt;&lt;br /&gt;If a type declaration T has a member method m1 and another method m2 exists, declared in T or a supertype of T, a compile time error occurs if all if all the following holds:&lt;br /&gt;1. m1 and m2 have same name&lt;br /&gt;2. m2 is accessible from T&lt;br /&gt;3. the signature of m1 is not a subsignature of the signature of m2&lt;br /&gt;4. m1 or some method m1 overrides (directly or indirectly) has the same erasure as m2 or some method m2 overrides (directly or indirectly.)&lt;br /&gt;&lt;br /&gt;notes: &lt;br /&gt;a. methods are overridden on a signature-by-signature basis. &lt;br /&gt;b. All methods not overridden by an interface in the supertype are automatically inherited. &lt;br /&gt;c. An interface can inherit several methods with override-equivalent signatures, however, one of the inherited methods must be return-type substitutable for any other inherited method, otherwise a compile time error occurs. &lt;br /&gt;d. A method can be inherited from several paths, inheritance is considered as being only once. &lt;br /&gt;&lt;br /&gt;Overloading: overloading of interface member methods similar to as detailed for class methods overloading. &lt;br /&gt;&lt;br /&gt;MEMBER TYPE DECLARATIONS&lt;br /&gt;Interfaces may contain member type declarations; a member type declaration in an interface is implicitly static and public.&lt;br /&gt;&lt;br /&gt;A member type C enclosed in an interface N has a fully qualified name N.C.&lt;br /&gt;&lt;br /&gt;Member type hiding can occur between an interfaces and its superinterface. &lt;br /&gt;&lt;br /&gt;An interface will inherit all non-private accessible non-hidden member types of its superinterface. &lt;br /&gt;&lt;br /&gt;An interface can inherit 2 or more type declarations with the same name, but on referencing them with their simple names, ambiguity results. &lt;br /&gt;&lt;br /&gt;If the same type declaration is inherited with different paths by an interface, then inheritance is assumed to be but once.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-976975089946587966?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/976975089946587966/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=976975089946587966' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/976975089946587966'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/976975089946587966'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/interfaces2.html' title='INTERFACES(2)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-7629850279050067366</id><published>2007-04-13T03:08:00.000-07:00</published><updated>2007-04-13T03:09:01.652-07:00</updated><title type='text'>INTERFACES</title><content type='html'>INTERFACES&lt;br /&gt;&lt;br /&gt;An interface declaration introduces new reference types whose members are classes, interfaces, constants and abstract methods. Being without implementation, unrelated classes can implement interfaces by providing a definition for its abstract methods. &lt;br /&gt;&lt;br /&gt;There are two kinds of interfaces, normal interfaces and annotation types, and they both can either be top level interfaces or nested interfaces (i.e with their declaration in the body of another class or interface). &lt;br /&gt;&lt;br /&gt;Interface Declarations&lt;br /&gt;An interface declaration specifies a new named reference type. There are two kinds of interface declarations:&lt;br /&gt;   NormalInterfaceDeclaration&lt;br /&gt;   AnnotationTypeDeclaration&lt;br /&gt;A normal interface declaration is notated thus:&lt;br /&gt;InterfaceModifiersopt     interface     Identifier     TypeParameteropt     ExtendsInterfacesopt     InterfaceBody &lt;br /&gt;&lt;br /&gt;Annotation type declarations will be broached later. &lt;br /&gt;&lt;br /&gt;The identifier in an interface declaration denotes the name of the interface which name should not be the same as an enclosing class or interface otherwise, a compile time error will result. &lt;br /&gt;&lt;br /&gt;Interface Modifiers&lt;br /&gt;The interface declaration may include interface modifiers which may be one of:&lt;br /&gt;public      protected      private      abstract      static      strictfp&lt;br /&gt;&lt;br /&gt;not all modifiers are applicable to all interfaces. Protected and private are applicable only to member interfaces within a directly enclosing  class declaration; static applies only to member interfaces; the same modifier should not appear more than once in the same interface declaration. &lt;br /&gt;&lt;br /&gt;If an annotation a for an interface declaration corresponds to an annotation type T, and T has a (meta-)annotation m such that m corresponds to annotation.Target, then m must have an element whose value is annotation.ElementType.TYPE, otherwise a compile time error results. &lt;br /&gt;&lt;br /&gt;Note that every interface is implicitly abstract, but the use of this modifier is obsolete; a strictfp interface declaration is to make all double and float expressions in the interface be explicitly FP-strict, including nested types declared in the interface. &lt;br /&gt;&lt;br /&gt;Generic interfaces and type parameters&lt;br /&gt;Generic interfaces are interfaces which declare one or more type variables which are known as the type parameters of the interface and delimited by angle brackets, ‘&lt;’ and ‘&gt;’. A generic interface declaration defines a set of types, one for each possible invocation of the type parameter section. All type parameters share the same interface at runtime. &lt;br /&gt;&lt;br /&gt;The scope of an interface’s type parameter is the entire declaration of the interface including the type parameter section itself. Therefore, type parameters can appear as part of their own bounds, or as bounds of other type parameters declared in the same section. &lt;br /&gt;&lt;br /&gt;Never refer to the type parameter of an interface anywhere in a member field or member type of an interface. &lt;br /&gt;&lt;br /&gt;Superinterfaces and subinterfaces:&lt;br /&gt;If the extends clause is provided, then the interface being declared extends each of the other named interfaces and therefore inherits the member types, methods and constants of each of the other named interfaces, called the direct superinterfaces of the interface being declared. &lt;br /&gt;&lt;br /&gt;If a class implements the declared interface, it is also considered to implement all the interfaces this interface extends.&lt;br /&gt;&lt;br /&gt;Notation:     extends  InterfaceType(s)&lt;br /&gt;&lt;br /&gt;Note that interface types can be generic and must be accessible. &lt;br /&gt;&lt;br /&gt;An interface I directly depends on a type T if T is mentioned in the extends clause of I either as a superinterface or as a qualifier within a superinterface name.&lt;br /&gt;&lt;br /&gt;An interface I depends on a reference type T if any of the following conditions hold:&lt;br /&gt;1. I directly depends on T&lt;br /&gt;2. I directly depends on a class C that depends on T&lt;br /&gt;3. I directly depends on an interface J that depends on T (using this definition recursively.)&lt;br /&gt;An interface cannot directly depend on itself. &lt;br /&gt;&lt;br /&gt;While every class is an extension of the Object class, there is no interface such that all interfaces implicitly extends it. &lt;br /&gt;&lt;br /&gt;The suerinterface relationship is a transitive closure of the direct superinterface relationship.  An interface K is a superinterface of interface I if either of the following is true:&lt;br /&gt;1. K is a direct superinterface of I&lt;br /&gt;2. an interface J exists such that K is an interface of J, and J is a superinterface of I, applying this definition recursively. &lt;br /&gt;Where K is a superinterface of J then J is said to be a subinterface of K. &lt;br /&gt;&lt;br /&gt;Interface Body and member declarations: the body of an interface may declare members of the interface where the members are either:&lt;br /&gt;1. a constant declaration&lt;br /&gt;2. an abstract method declaration&lt;br /&gt;3. a class declaration&lt;br /&gt;4. an interface declaration.&lt;br /&gt;The scope of the declaration of a member m declared in or inherited by an interface type I is the entire body of I, including any nested type declarations. &lt;br /&gt;&lt;br /&gt;Access to interface member names: all interface members are implicitly public and access to them is allowed if the interface is also declared public or protected.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-7629850279050067366?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/7629850279050067366/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=7629850279050067366' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/7629850279050067366'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/7629850279050067366'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/interfaces.html' title='INTERFACES'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-8478952250409757672</id><published>2007-04-13T03:07:00.001-07:00</published><updated>2007-04-13T03:07:56.615-07:00</updated><title type='text'>CLASSES(8)</title><content type='html'>CLASSES(8)&lt;br /&gt;&lt;br /&gt;ENUMS&lt;br /&gt;The notation form for enum type is:&lt;br /&gt;ClassModifiersopt     enum     Identifier     Interfacesopt     EnumBody&lt;br /&gt;&lt;br /&gt;Where Enum body is:&lt;br /&gt;{ EnumConstantsopt,opt       EnumBodyDeclarationsopt }&lt;br /&gt;&lt;br /&gt;The body of an enum type may contain enum constants which defines instances of the enum type.&lt;br /&gt;&lt;br /&gt;Notes:&lt;br /&gt;1. never explicitly instantiate an enum type&lt;br /&gt;2. enum constants can never be cloned due the the clone method of Enum&lt;br /&gt;3. the special treatment of the serialization mechanism ensures that duplicate instances are never created as a result of deserialisation. &lt;br /&gt;4. reflective instantiation of enum types is prohibited. &lt;br /&gt;Notes 1-4 above ensures that only an enum constant can define instances of enum types. &lt;br /&gt;&lt;br /&gt;Enum constants thus have the following notation:&lt;br /&gt;Annotations     Identifier     Argumentsopt     ClassBodyopt&lt;br /&gt;Where Arguments:   (ArgumentListopt)&lt;br /&gt;&lt;br /&gt;Also the optional enum body declaration is declared thus:  ;ClassBodyDeclarationsopt&lt;br /&gt;&lt;br /&gt;An enum constant when preceded by annotation modifiers, say a, corresponding to an annotation type T, and T has a (meta-)annotation m such that the m corresponds to annotation.Target, then m must have an element whose value is annotation.ElementType.FIELD, or a compile time error results. &lt;br /&gt;&lt;br /&gt;An enum constant may be followed by arguments and these arguments are passed to the constructor of the enum type when the constant is created during class initialization. If the arguments are omitted, an empty argument list is assumed. If the enum type has no constructor declarations, a parameterless default constructor is provided (matching the implicit empty argument list) and the default constructor is private.&lt;br /&gt;&lt;br /&gt;The optional class body of an enum constant implicitly defines an anonymous class declaration that extends the enclosing enum type. The class body is governed by the usual anonymous class rules, in particular, it cannot contain constructors. &lt;br /&gt;&lt;br /&gt;Compile time error scenarios, brief:&lt;br /&gt;1. a compile time error if an enum type is declared abstract&lt;br /&gt;2. an enum type, E, cannot have abstract methods unless E has one or more enum constants and all these enum constants have class bodies that provide concrete implementations of the abstract method. &lt;br /&gt;3. the class body of an enum constant cannot declare an abstract method. &lt;br /&gt;&lt;br /&gt;An enum type is implicitly final unless it contains an enum constant that has a class body, but does not have to be explicitly so defined otherwise compile time error. &lt;br /&gt;&lt;br /&gt;Nested enum types are implicitly static and one can explicitly declare them thus. &lt;br /&gt;&lt;br /&gt;Any constructor or member declaration declared with an enum declaration applies to the enum type exactly as if they had been present in the class body of a normal class declaration unless explicitly stated otherwise. &lt;br /&gt;&lt;br /&gt;The direct superclass of an enum type named E is Enum&lt;E&gt;. in addition to members inherited from Enum&lt;E&gt;, for each declared enum constant n the enum type has an implicitly declared public static final field named n of type E. these fields are considered to be declared in the same order as the corresponding enum constant and initialized to the corresponding enum constant. Each such field is also considered annotated by the same annotations as the corresponding enum constants. The enum constant is said to be created when the corresponding field is initialized. &lt;br /&gt;&lt;br /&gt;The following implicitly declared static method exists for any enum type:&lt;br /&gt;public static E[] values();  //this returns an array containing the constants of the enum &lt;br /&gt;type in the order declared.&lt;br /&gt;&lt;br /&gt;public static E valueOf(String name);   //returns the enum constant with the specified &lt;br /&gt;name&lt;br /&gt;&lt;br /&gt;read the specific examples in the jls!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-8478952250409757672?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/8478952250409757672/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=8478952250409757672' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/8478952250409757672'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/8478952250409757672'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/classes8.html' title='CLASSES(8)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-6245656516200742343</id><published>2007-04-13T03:06:00.001-07:00</published><updated>2007-04-13T03:06:50.386-07:00</updated><title type='text'>CLASSES(7)</title><content type='html'>CLASSES(7)&lt;br /&gt;&lt;br /&gt;MEMBER TYPE DECLARATIONS&lt;br /&gt;Member classes or member interfaces are nested classes or interfaces. The name of a member type hides any and all accessible declarations of member types with the same name in superclasses and superinterfaces. &lt;br /&gt;&lt;br /&gt;If there exists a declaration of a member type in scope before the declaration of another member type with the same name, then these other member type declaration will shadow the earlier one. &lt;br /&gt;&lt;br /&gt;If a member class or interface with simple name C is directly enclosed in another class declaration with fully qualified name N, then N.C is the fully qualified name of the member class or interface. &lt;br /&gt;&lt;br /&gt;INSTANCE INITIALISERS&lt;br /&gt;An instance initialiser declared in a class is executed when an instance of the class is created. &lt;br /&gt;&lt;br /&gt;A named class’ instance initialiser should not throw any exceptions unless the following conditions hold: a. that exception or its supertype must be explicitly declared in the throws clause of the constructor, b. the class must have at least one explicitly declared constructor. &lt;br /&gt;&lt;br /&gt;An anonymous class’ instance initialiser can throw any number of exceptions. &lt;br /&gt;&lt;br /&gt;An instance initiliser must complete normally. &lt;br /&gt;&lt;br /&gt;There must be no return statement in an instance initialiser. &lt;br /&gt;&lt;br /&gt;Try to declare instance variables used in instance initialiser before usage even though these instance variable declarations are in scope.&lt;br /&gt;&lt;br /&gt;Instance initialisers can refer to the current object this, to any variable that is in scope and can use the keyword super. &lt;br /&gt;&lt;br /&gt;STATIC INITIALISERS&lt;br /&gt;Any static initialisers declared in a class are executed when the class is initialized, and together with any field initialisers for class variables, may be used to initialize the class variables of the class. &lt;br /&gt;&lt;br /&gt;Notation for static initialisers is:  static Block&lt;br /&gt;&lt;br /&gt;Static initialisers and class variable initialisers are executed in textual order. Declaration after usage of class variables is discouraged even though the variables may be in scope. &lt;br /&gt;&lt;br /&gt;No return statement must appear inside the block of a static initialiser. &lt;br /&gt;&lt;br /&gt;The keywords this, super or any type variable declared outside the initialiser are not allowed and produce compile time errors. &lt;br /&gt;&lt;br /&gt;CONSTRUCTOR DECLARATIONS&lt;br /&gt;a constructor is used in the creation of an object that is an instance of a class. &lt;br /&gt;&lt;br /&gt;Notation: &lt;br /&gt;ConstructorModifiersopt     ConstructorDeclarator    Throwsopt     ConstructorBody&lt;br /&gt;&lt;br /&gt;Where the Constructor Declarator is notated thus:&lt;br /&gt;TypeParametersopt     SimpleTypeName  (FormalParameterListopt)&lt;br /&gt;&lt;br /&gt;The simple name of the constructor declarator must be the simple name of the class in which the constructor is declared, otherwise compile time error. Except for the simple name requirement, the constructor looks like a method declaration without any return type. &lt;br /&gt;&lt;br /&gt;Very simple example of a constructor:&lt;br /&gt;&lt;br /&gt;class Loader {&lt;br /&gt; int x, y;&lt;br /&gt; Loader(){}&lt;br /&gt;}&lt;br /&gt;Constructors are invoked by:&lt;br /&gt;1. class instance creation expressions. &lt;br /&gt;2. conversions and concatenations caused by the string concatenation operator, +.&lt;br /&gt;3. explicit constructor invocations from other constructors. &lt;br /&gt;&lt;br /&gt;Access to constructors is governed by access modifiers. &lt;br /&gt;&lt;br /&gt;Constructor declarations are not members. They are not inherited and therefore cannot be overridden or hidden. &lt;br /&gt;&lt;br /&gt;The formal parameters and formal type parameters of constructors are identical in structure and behaviour to those of a method. &lt;br /&gt;&lt;br /&gt;It is a compile time error to declare two constructors whose signatures are override-equivalent or have the same erasure types in a class. &lt;br /&gt;&lt;br /&gt;Constructor Modifiers: the choice of constructor modifiers are either one of public, protected or private, and a single one can never be declared twice nor can more than one of the choice above be chosen. If a normal class has a constructor without an access modifier, then the default is chosen. An enum type has default access modifier of private and cannot ever be declared public or protected.&lt;br /&gt;&lt;br /&gt;If an annotation a on a constructor corresponds to an annotation type T and T has a meta-annotation m such that m corresponds to annotation.Target, then m must have an element whose value is annotation.ElementType.CONSTRUCTOR, otherwise a compile time error results. &lt;br /&gt;&lt;br /&gt;Unlike methods, a constructor cannot be:&lt;br /&gt;a. abstract, because it would not be implemented &lt;br /&gt;b. final, because it is never inherited. &lt;br /&gt;c. Static, because since a constructor is invoked with respect to an object, it makes no sense to declare it static. &lt;br /&gt;d. Synchronized, because it would lock the object under construction, making it unavailable to other threads until all constructors for the object have finished their work. &lt;br /&gt;e. Native, a design decision in java to ensure proper superclass constructor invocations.&lt;br /&gt;f. Strictfp, a design decision to ensure that unlike in method modifiers, the class determines the fp-strictness of the results of the constructor. &lt;br /&gt;&lt;br /&gt;Generic constructors: whether or not the class a constructor is in is generic or not, a constructor can be declared generic. A generic constructor must declare one or more type variables known as the formal type parameters of the constructor which form is identical to the type parameter list of a generic class or interface. &lt;br /&gt;&lt;br /&gt;The scope of a constructor’s type parameter is the entire declaration itself, including the type parameter section. Type parameters can therefore appear as part of their own bounds or as bounds of other type parameters in the same section.&lt;br /&gt;&lt;br /&gt;On invoking a generic constructor, you need not provide the type parameters explicitly, and when not provided, they are inferred. &lt;br /&gt;&lt;br /&gt;Constructor throws: identical to that of a method. &lt;br /&gt;&lt;br /&gt;The type of a constructor: consists of its signature and exception types given its throws clause. &lt;br /&gt;&lt;br /&gt;Constructor body: the first statement of a constructor body may be the explicit invocation of another constructor of the same class or of the direct superclass. &lt;br /&gt;&lt;br /&gt;{ExplicitConstructorInvocationopt          BlockStatementsopt}&lt;br /&gt;&lt;br /&gt;A constructor using this should not directly or indirectly invoke itself, otherwise a compile time error results. &lt;br /&gt;&lt;br /&gt;If the constructor is a constructor for an enum type, it is a compile time error for it to invoke the superclass constructor explicitly. &lt;br /&gt;&lt;br /&gt;If a constructor does not begin with a. an explicit constructor invocation, b. and the constructor being declared is not part of the primordial class of Object, then the compiler assumes the constructor begins with “super();”, an invocation of the constructor of its direct superclass that takes no arguments. &lt;br /&gt;&lt;br /&gt;Except for possible explicit constructor invocations, the body of a constructor is similar to that of a method. &lt;br /&gt;&lt;br /&gt;See examples in §8.8.7 of the jls. &lt;br /&gt;&lt;br /&gt;Explicit constructor invocations: notations are of this form&lt;br /&gt;1. alternate constructor invocations, beginning with this are used to invoke an alternate constructor for the class and may be prefaced with explicit type arguments. &lt;br /&gt;nonWildTypeopt     this(ArgumentListopt);&lt;br /&gt;&lt;br /&gt;2. Superclass constructor invocations are either, a. unqualified, or b. qualified. &lt;br /&gt;a. unqualified superclass constructor invocations,  begin with super and may be prefaced with explicit type arguments. &lt;br /&gt;nonWildTypeopt      super(ArgumentListopt);&lt;br /&gt; b. &lt;br /&gt;Primary.nonWildTypeopt    super(ArgumentListopt);&lt;br /&gt;&lt;br /&gt;Where nonWildTypes  are notated as &lt;ReferenceTypeList&gt; where the list of reference types are one or many. &lt;br /&gt;&lt;br /&gt;package examples;&lt;br /&gt;&lt;br /&gt;public class A {&lt;br /&gt; A(){&lt;br /&gt;  System.out.println("I am your super man.");&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class C extends A {&lt;br /&gt; String color;&lt;br /&gt; C(){&lt;br /&gt;  this("white");  //call alternate constructor&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //the alternate constructor&lt;br /&gt; C(String givencolor){&lt;br /&gt;  this.color = givencolor;  &lt;br /&gt; } &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Loader {&lt;br /&gt; &lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  //create an instance without arguments and it'll give&lt;br /&gt;  //us white.&lt;br /&gt;  C newc = new C();&lt;br /&gt;  System.out.println("without arguments default color is &lt;br /&gt;"+newc.color);&lt;br /&gt;  &lt;br /&gt;  //creating one with argument, alternate to customise color&lt;br /&gt;  C customc = new C("red");&lt;br /&gt;  System.out.println("we've chosen to use the color &lt;br /&gt;"+customc.color);&lt;br /&gt;  &lt;br /&gt;  //not that an implicit call to the super is done each &lt;br /&gt;  //time the the subclass constructor is invoked. &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Constructor overloading: constructor overloading similar to method overloading. &lt;br /&gt;&lt;br /&gt;Default constructor: if a class contains no default constructor, then one is automatically provided that takes no parameters. &lt;br /&gt;&lt;br /&gt;If class is Object, then the constructor an empty body, else the default takes no parameters and simply invokes the superclass constructor with no arguments. &lt;br /&gt;&lt;br /&gt;A default constructor has no throws clause. &lt;br /&gt;&lt;br /&gt;In an enum type, the default constructor is implicitly private. The default constructor is implicitly given the access modifier that is specified for the class! &lt;br /&gt;&lt;br /&gt;Preventing instantiation of a class: &lt;br /&gt;&lt;br /&gt;A class can prevent code outside of the class declaration from creating instances of the class by: &lt;br /&gt;1. declaring at least one constructor. &lt;br /&gt;2. preventing the creation of an implicit constructor.&lt;br /&gt;3. declaring all constructors to be private. &lt;br /&gt;&lt;br /&gt;A public  class can likewise prevent the creation of instances outside the package by:&lt;br /&gt;1. declaring at least one constructor&lt;br /&gt;2. preventing the creation of a default constructor with public access.&lt;br /&gt;3. declaring no constructor that is public.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-6245656516200742343?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/6245656516200742343/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=6245656516200742343' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/6245656516200742343'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/6245656516200742343'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/classes7.html' title='CLASSES(7)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-8092168187037652181</id><published>2007-04-13T03:04:00.000-07:00</published><updated>2007-04-13T03:05:14.386-07:00</updated><title type='text'>CLASSES(6)</title><content type='html'>CLASSES(6)&lt;br /&gt;&lt;br /&gt;Method throws: a throws clause is used to declare any checked exceptions that can result from the execution of a method or constructor. &lt;br /&gt;&lt;br /&gt;The notation is:   throws ExceptionTypeList&lt;br /&gt;Where ExceptionTypeList can be one or more and the types are either a class type or a type variable. &lt;br /&gt;&lt;br /&gt;Note: &lt;br /&gt;1. the type of exception mentioned in a throws clause must be a subtype of Throwable.&lt;br /&gt;2. any checked exception that will be encountered in the body of a method or constructor must be mentioned in a throws clause in the declaration of the method or constructor. &lt;br /&gt;3. if a throws clause does not contain that exception type, then the compiler will fail to handle the exception and this will result in a compile time error. &lt;br /&gt;&lt;br /&gt;Two exceptions that are not checked because declaring their every occurrence would be inconvenient are:&lt;br /&gt;a. exceptions that are represented by subclasses of the class Error.&lt;br /&gt;b. Exceptions that are represented by subclasses of the class, RuntimeException.&lt;br /&gt;&lt;br /&gt;if a method declaration n in a class or interface B overrides or hides a method declaration m in A where A is a superclass or superinterface of B. if n has a throws clause that mentions any checked exception types, then m must have a throws clause, and for every checked exception type listed in the throws clause of n, that same exception class or one of its supertypes must exist in the erasure of the throws clause of m; otherwise a compile time error will result. &lt;br /&gt;&lt;br /&gt;If there exists a throws clause in n such that no throws clause in an unerased m is a supertype of this throws clause, then an unchecked warning must be issued. &lt;br /&gt;&lt;br /&gt;Method body: a method body is a block of code that implements the method, or simply a semicolon indicating the lack of an implementation. Note that the body of a method must be a semicolon, ;, if and only if the method is declared abstract or native. &lt;br /&gt;&lt;br /&gt;If an implementation is to be provided for a method declared void, but the implementation requires no executable code, the method body should be written as a block that contains no executable code, {}.&lt;br /&gt;&lt;br /&gt;A  method declared void must not contain a return statement in its code, a method declared with a return type must have a return statement in its body that returns a value of type return type. &lt;br /&gt;&lt;br /&gt;A method that specifies a return type could in some cases not return anything. &lt;br /&gt;&lt;br /&gt;Inheritance, overriding, hiding: a class C can inherit from its direct superclasses and superinterfaces (a) all non-private methods (whether abstract or not) of the superclass and superinterface that are public, protected or the default (i.e package-private), (b) in the same package as C, and (c) are neither overridden nor hidden by a declaration in the class. &lt;br /&gt;&lt;br /&gt;Overriding (by instance methods): the example below illustrates this. &lt;br /&gt;Note: &lt;br /&gt;1. an instance method does not override a static method. &lt;br /&gt;&lt;br /&gt;package examples;&lt;br /&gt;&lt;br /&gt;public class A {&lt;br /&gt; void m1(int enter){&lt;br /&gt;  System.out.println("A enters with "+enter);  &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//C is a subclass of A&lt;br /&gt;public class C extends A{&lt;br /&gt; &lt;br /&gt; //both methods have the same signatures, zero parameters&lt;br /&gt; void m1(int enter){&lt;br /&gt;  System.out.println("C enters with with "+enter);&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //to access the overridden method, we use super&lt;br /&gt; void overridden(int enter){&lt;br /&gt;  super.m1(enter);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Loader {&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  //let's show overriding of instance methods&lt;br /&gt;  C thec = new C();&lt;br /&gt;  thec.m1(35);&lt;br /&gt;  &lt;br /&gt;  //the printout will show that C.m1 overrides A.m1&lt;br /&gt;  //although C inherits A.m1&lt;br /&gt;  &lt;br /&gt;  //to access the overridden method, let's call the&lt;br /&gt;  //method that uses super&lt;br /&gt;  thec.overridden(56); &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Hiding (by class methods): &lt;br /&gt;Note:&lt;br /&gt;1. a static method does not hide an instance method otherwise a compile time error. &lt;br /&gt;&lt;br /&gt;package examples;&lt;br /&gt;&lt;br /&gt;public class A {&lt;br /&gt; static void m1(int enter){&lt;br /&gt;  System.out.println("A enters with "+enter);  &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class C extends A{&lt;br /&gt; static void m1(int enter){&lt;br /&gt;  System.out.println("C enters with "+enter);&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //accessing the static method, m1 of A&lt;br /&gt; void overridden(int enter){&lt;br /&gt;  super.m1(enter);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Loader {&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  //m1 of A is overridden&lt;br /&gt;  C.m1(30);&lt;br /&gt;  &lt;br /&gt;  //we can access A.m1 though these ways&lt;br /&gt;  //a. using the qualified name&lt;br /&gt;  A.m1(60);&lt;br /&gt;  &lt;br /&gt;  //b. calling the super through method overridden&lt;br /&gt;  C thec = new C();&lt;br /&gt;  thec.overridden(60);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Requirements in Overriding and Hiding: 2 requirements are:&lt;br /&gt;1. return type substitutability for the overriding method on the overridden&lt;br /&gt;2. the throws clause should be a subtype of the throws in the overridden method. &lt;br /&gt;3. the access modifier on an overriding or hiding method must provide at least as much access as the overridden method, d4&lt;br /&gt;a. if the overridden method is declared public, then the overriding method must be declared public otherwise a compile time error&lt;br /&gt;b. if the overridden method is declared protected, then the overriding method must be declared protected or public.&lt;br /&gt;c. If the overridden method has default access (package-private), then the overriding method cannot be private. &lt;br /&gt;&lt;br /&gt;Overloading: overloading occurs when two methods of a class (whether both are declared, or both are inherited, or one is declared and the other inherited) have the same name but signatures that are not override equivalent. &lt;br /&gt;Note that overriding on methods occurs on a signature-by-signature basis&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-8092168187037652181?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/8092168187037652181/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=8092168187037652181' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/8092168187037652181'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/8092168187037652181'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/classes6.html' title='CLASSES(6)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-5304659129163743130</id><published>2007-04-13T03:02:00.000-07:00</published><updated>2007-04-13T03:03:59.629-07:00</updated><title type='text'>CLASSES(5)</title><content type='html'>CLASSES(5)&lt;br /&gt;&lt;br /&gt;Method Signature: two methods have the same signature if they have the same name and argument types. Two methods M and N may be said to have the same argument types if the following conditions hold: &lt;br /&gt;- if they have the same number of formal parameters (possibly zero)&lt;br /&gt;- if they have the same number of type parameters (possibly zero)&lt;br /&gt;- if the formal parameters of M are &lt;A1, …, An&gt; and of N are &lt;B1, …, Bn&gt; if it is possible to replace each Bi in N with the As in M and you get a formal parameter list equal to that in M, &lt;br /&gt;then, M and N have the same signatures. &lt;br /&gt;&lt;br /&gt;The signature of a method m1 could be said to be the subsignature of a method m2 if either: &lt;br /&gt;- m2 has the same signature as m1&lt;br /&gt;- the signature of m1 is the same as the erasure of the signature of m2.&lt;br /&gt;Note on subsignatures: this feature was incorporated into the java programming language to express a relationship between two signatures although not identical but one can override the other, a good example is allowing a method without generic types to override one with generic types. &lt;br /&gt;&lt;br /&gt;it is a compile time error to declare two methods with override-equivalent signatures where override-equivalent signatures operate on two methods m1 and m2 if m1 is a subsignature of m2 or m2 is a subsignature of m1.  &lt;br /&gt;&lt;br /&gt;Method Modifiers: the method modifiers are:&lt;br /&gt;&lt;br /&gt;public      protected      private      abstract      static      final      synchronized      native strictfp&lt;br /&gt;&lt;br /&gt;notes: &lt;br /&gt;1. the same modifier cannot appear more than once for a method and public protected private have exclusive usage on each other. &lt;br /&gt;2. if a method declaration contains the keyword abstract it cannot contain any of private static final native strictfp or synchronized.&lt;br /&gt;3. if a keyword native is contained in a declaration it cannot contain strictfp any longer. &lt;br /&gt;4. if there is an annotation a on a method declaration that corresponds to an annotation type T, and T has a meta-annotation m such that m corresponds to annotation.Target, then m has an element with value annotation.ElementType.METHOD, or a compile time error results. &lt;br /&gt;5. the other specified above for method modifiers is customary but not a must. &lt;br /&gt;&lt;br /&gt;Abstract methods:  the abstract modifier introduces a method as a class member, providing its signature, return type and throws clause but providing no implementation for the method. Abstract methods must appear within abstract classes otherwise a compile time error results. An Enum declaration though can contain an abstract method. If an abstract class is to be subclassed, then that subclass must provide an implementation for its abstract methods, otherwise, a compile time error results. &lt;br /&gt;&lt;br /&gt;A private method cannot be declared abstract because a private method cannot be implemented from outside the class. &lt;br /&gt;&lt;br /&gt;It is an error for a static method to be declared abstract because invocation of such a method through its qualified name will return a compile time error. &lt;br /&gt;&lt;br /&gt;It is a compile time error for a final method to be declared abstract because final methods will never allow a subclass to implement this method or any other method because the implementation is finished and perfect. &lt;br /&gt;&lt;br /&gt;An abstract class can override another abstract class by providing an abstract method declaration, giving a facility for detailed specification or loosened specification to be attached to that method.&lt;br /&gt;&lt;br /&gt;An instance method that is not abstract can be overridden by an abstract method. &lt;br /&gt;&lt;br /&gt;Static methods: a method that is declared static is called a class method. A static method cannot be declared abstract. A static method is invoked with reference to the class and not to any particular object. Use of the keywords this or super in referencing a class method will result in compile time error. &lt;br /&gt;&lt;br /&gt;On the other hand, a method that is not declared static is called an instance method and is invoked with respect to a particular object, which is the object which the keywords this or super refer to during execution of the method. &lt;br /&gt;&lt;br /&gt;Final methods: a method is declared final to prevent subclass overriding or hiding of the method, attempting to do so results in compile time error. A private method and all methods declared within a final class all behave as if they are final because they cannot be overridden. &lt;br /&gt;&lt;br /&gt;A final method can never be declared abstract.&lt;br /&gt;&lt;br /&gt;Note that final methods on invocation are inlined by the optimizer or machine code generator. &lt;br /&gt;&lt;br /&gt;Native methods: a method that is native is implemented in platform-dependent code, typically written in another programming language, typically C, C++, FORTRAN or Assembly language. The body of a native method is given as a semicolon only, indicating that the implementation is omitted, in place of the method’s body or block. &lt;br /&gt;&lt;br /&gt;See §8.4.3.4 of the jls for an example. &lt;br /&gt;&lt;br /&gt;Strictfp methods: the effect of strictfp modifier in methods is to make sure that all float or double expressions within the method body are FP-strict. &lt;br /&gt;&lt;br /&gt;Synchronized methods: a synchronized method acquires a monitor of an object or class before it executes. If the method is a class (static) method, the monitor associated with the Class object for the method’s class is used, else if an instance method, the monitor associated with the this object is used. &lt;br /&gt;&lt;br /&gt;Generic methods: a method is generic if it declares one or more type variables, these being the formal type parameters of the method. The form of the formal type parameter list is identical to that of a class or interface. &lt;br /&gt;&lt;br /&gt;The scope of a method’s type parameter is the entire declaration of the method, including the type parameter section. Hence, type parameters can appear as part of their own bounds, or as bounds of other type parameters declared in the same section. &lt;br /&gt;&lt;br /&gt;Type parameters for methods are almost always inferred on invocation of the method, so they need not be explicitly provided. &lt;br /&gt;&lt;br /&gt;Method return type: the return type of a method states whether the method doesn’t return a value, declared as void, or the type of value a method returns, if it returns a value. &lt;br /&gt;&lt;br /&gt;Notion of return type substitutability: two methods are return type substitutable is the following conditions hold for both methods return types:&lt;br /&gt;1. if one of the return types is a primitive type, then the second return type is identical to the first. &lt;br /&gt;&lt;br /&gt;//return types for both methods identical&lt;br /&gt;  int myMethod(){}&lt;br /&gt;  &lt;br /&gt;  int yourMethod(){}&lt;br /&gt;  &lt;br /&gt;2. if one of the return types is a reference type, then the other is substitutable to the first if it is a subtype of the earlier or can be converted to a subtype of the earlier by an unchecked conversion. &lt;br /&gt;&lt;br /&gt;//where Lagos class was declared to extend Nigeria&lt;br /&gt;//these two methods are return type substitutable&lt;br /&gt;  Nigeria myMethod(){}&lt;br /&gt;  &lt;br /&gt;  Lagos yourMethod(){}&lt;br /&gt;  &lt;br /&gt;3. if the erasure of one of the return types is equal to the raw type of the other. &lt;br /&gt;4. if one is void, then the other is void. &lt;br /&gt;&lt;br /&gt;(to be continued)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-5304659129163743130?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/5304659129163743130/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=5304659129163743130' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/5304659129163743130'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/5304659129163743130'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/classes5.html' title='CLASSES(5)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-1809730352121906427</id><published>2007-04-13T03:01:00.000-07:00</published><updated>2007-04-13T03:02:22.522-07:00</updated><title type='text'>CLASSES(4)</title><content type='html'>CLASSES(4)&lt;br /&gt;&lt;br /&gt;Initialization of fields: a field declaration with a variable initialiser has the semantics of an assignment to the declared variable and, &lt;br /&gt;- if the declaration is for a class variable (i.e not a static field), then the variable initialiser is evaluated and exactly a single-time assignment performed, when the class is initialized. If the evaluation of a variable initialiser for a static field of a named class(or an interface) can complete abruptly with a checked exception, then this is a compile-time error. &lt;br /&gt;- If the declaration is for an instance variable, (i.e a field that is not static,), then the variable initialiser is evaluated and the assignment performed each time an instance of the class is created. If an instance variable initialiser of a named class can throw a checked exception, then there is a compile time error, otherwise that exception or one of its supertypes is explicitly declared in the throws clause of each constructor of its class and the class has at least one explicitly declared constructor. &lt;br /&gt;An instance variable initialiser in an anonymous class can throw any exception. &lt;br /&gt;&lt;br /&gt;Initialization of class variables: &lt;br /&gt;a. any reference to the simple name of an instance variable will result in an error in a class variable initialization expression.. &lt;br /&gt;b. use of the keyword this or super in a class variable initialization expression will result in an error. &lt;br /&gt;c. Class variables declared final and initialized with compile time constants will always be initialized first, whether in classes or interfaces. &lt;br /&gt;d. A restriction is  placed on using a class variable before its textual declaration, whether or not the class variable is in scope.&lt;br /&gt;&lt;br /&gt;Initialization of instance variables:&lt;br /&gt;a. initialization expressions for instance variables may refer to the simple names of class variables. &lt;br /&gt;b. The expression may use the keyword this and super .&lt;br /&gt;c. Restrictions exist on the use of an instance variable before its textual declaration. &lt;br /&gt;&lt;br /&gt;Restrictions on the use of fields during initialization:&lt;br /&gt;The declaration of a member of a class needs to appear textually before usage only if the member is an instance (respectively static) field of a class that directly encloses it and the following conditions hold:&lt;br /&gt;a. the usage occurs in an instance variable initialiser(respectively static) of the enclosing class or in an instance initialiser (respectively static) of the enclosing class.&lt;br /&gt;b. The usage is not on the leftmost side of an assignment&lt;br /&gt;c. The usage is via a simple name&lt;br /&gt;d. This class is the innermost class enclosing the usage. &lt;br /&gt;&lt;br /&gt;Note: take usage to refer to the main method’s class and you’ll understand why following the rule that you should try to textually declare before usage can really save you some grief. If usage was within same class as instance variable, then static modifiers for the variable would be a must requirement. &lt;br /&gt;&lt;br /&gt;METHOD DECLARATIONS:&lt;br /&gt;A method declares executable code that can be invoked, passing a fixed number of values as arguments. &lt;br /&gt;&lt;br /&gt;The formal notation for method declaration is:  MethodHeader     MethodBody&lt;br /&gt;&lt;br /&gt;We’ll treat MethodHeader first. &lt;br /&gt;&lt;br /&gt;The MethodHeader consists of :&lt;br /&gt;MethodModifiersopt     TypeParametersopt     ResultType     MethodDeclarator     Throwsopt  &lt;br /&gt;&lt;br /&gt;The MethodModifiers, TypeParameters and Throws sections will be discussed shortly. The ResultType signifies the type of value that the method returns and this could be void, that means, it doesn’t return any value, or a recognized type. &lt;br /&gt;&lt;br /&gt;The MethodDeclarator has the following notation:  identifier (FormalParameterListopt)&lt;br /&gt;The identifier is used in a name to refer to a method. &lt;br /&gt;&lt;br /&gt;Try to avoid using same names for methods, classes, fields, member classes or interfaces even if they do not result in compile time errors.&lt;br /&gt;&lt;br /&gt;Using two methods with the same signatures (name, number of parameters and types of parameters), will result in a compile time error. &lt;br /&gt;&lt;br /&gt;Formal Parameters: the formal parameters of a method or constructor, if any, are specified by a list of comma-separated parameter specifiers. &lt;br /&gt;&lt;br /&gt;The parameter specifiers have the notation: &lt;br /&gt;VariableModifiers   Type   VariableDeclaratorId &lt;br /&gt;&lt;br /&gt;Taking them one by one, the VariableModifiers are one or both of final and an annotation. The type specifies the allowed type of the arguments for the method and the VariableDeclaratorId could be an identifier or an array of the specified type. The specification here is for a fixed arity parameter or a case where the number of parameters that are allowed are known, finite and specified as to number. Where the number of allowed formal parameters are not specified, the method is said to have a variable arity parameter of the form  methodname(Type… id ) where id is either a simple name or an array of the specified type. &lt;br /&gt;  A compile time error occurs if two methods or constructors possess the same formal parameters when they have the same identifier or names. &lt;br /&gt;&lt;br /&gt;If an annotation a on a formal parameter corresponds to an annotation type T, and T has a (meta-)annotation, m such that m corresponds to annotation.Target, then m must have an element whose value is element.ElementType.PARAMETER, otherwise a compile time error is issued. &lt;br /&gt;&lt;br /&gt;When the parameter of a method is declared final, it is a compile time error to attempt to assign the parameter within the body of the method. &lt;br /&gt;&lt;br /&gt;Note that on invocation of a method or constructor, the arguments passed to the method initialize newly created parameter variables each of the Type mentioned in the formal parameter of the method and passed as their simple names before usage in the method body. Note that the identifier mentioned as a parameter in the method declaration may be used to refer to the formal parameter in the body of the method. &lt;br /&gt;&lt;br /&gt;Never declare parameter names in local variables of a method or as exception parameters of catch clauses in a try statement of the method or parameter. However, if a method contains a nested class declaration, the parameters of the method may be shadowed inside the nested class. Note though that the nested class should be a local class or an anonymous class. &lt;br /&gt;&lt;br /&gt;Never use a qualified name to refer to a formal parameter, only simple names. &lt;br /&gt;&lt;br /&gt;If a parameter contains a parameter of type float the value of the float should be in the float value set, and if in the extended-exponent value set this should map well to the float value set otherwise a compile time error results. Same goes for parameters of type double. &lt;br /&gt;&lt;br /&gt;But where an actual argument expression corresponding to a parameter variable is not FP-strict, during evaluation of the actual argument expression, intermediate values from the extended-exponent-value set can be used, but prior to being passed to the parameter variable par value, these values have to be mapped to the corresponding value set by method invocation conversion. &lt;br /&gt;&lt;br /&gt;An example that illustrates other features pertaining this topic: &lt;br /&gt;&lt;br /&gt;package examples;&lt;br /&gt;&lt;br /&gt;public class MyMethod {&lt;br /&gt; String terms; &lt;br /&gt; &lt;br /&gt; //this method returns no value and has fixed arity parameters, &lt;br /&gt; //which are 1 in number.&lt;br /&gt; void simpleMethod(final String builder){&lt;br /&gt;  //we'll refer to the arguments passed with the name&lt;br /&gt;  //builder and because of final, it can not be assigned&lt;br /&gt;  System.out.println("What was passed was a String, &lt;br /&gt;"+builder);&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //this method has variable arity parameters, which is considered&lt;br /&gt; //to define a String[]. so am querying the length here. &lt;br /&gt; void variablearity(String... somestrings){&lt;br /&gt;  System.out.println(somestrings.length+" parameters were &lt;br /&gt;passed.");&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //this method has no parameters, empty pair therefore in &lt;br /&gt; //parentheses&lt;br /&gt; String noparam(){&lt;br /&gt;  return terms;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Loader {&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  MyMethod thema = new MyMethod();&lt;br /&gt;  &lt;br /&gt;  //new variable initiallized on invocation of simpleMethod&lt;br /&gt;  //with type String&lt;br /&gt;  thema.simpleMethod("foobar");&lt;br /&gt;  &lt;br /&gt;  //on invocations of a variable arity method, you can define&lt;br /&gt;  //how much parameters to pass yourself&lt;br /&gt;  thema.variablearity("oh boy", "terrific!", "humdrum");&lt;br /&gt;  System.out.print("later ");&lt;br /&gt;  thema.variablearity("naughty", "ohlolo", "tellme", &lt;br /&gt;"finale");&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;(to be continued)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-1809730352121906427?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/1809730352121906427/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=1809730352121906427' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/1809730352121906427'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/1809730352121906427'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/classes4.html' title='CLASSES(4)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-2108838812711574398</id><published>2007-04-13T03:00:00.000-07:00</published><updated>2007-04-13T03:01:06.291-07:00</updated><title type='text'>CLASSES(3)</title><content type='html'>CLASSES(3)&lt;br /&gt;&lt;br /&gt;Superinterface: the optional implements clause in a class declaration introduces the names of interfaces that are direct superinterfaces of the class being declared. &lt;br /&gt;&lt;br /&gt;Notation:  interfaces:&lt;br /&gt;    implements InterfaceTypeList &lt;br /&gt;where InterfaceTypeList may be one or many and are denoted by a TypeParameter specification which might be generic i.e TypeDeclSpecific TypeArgumentsopt&lt;br /&gt;&lt;br /&gt;Given a class that could possibly be generic (C&lt;F1, …, Fn&gt;, n≥0, c≠Object),the direct superinterfaces of that class type are the types given in the implements clause of the declaration of C where C is a generic class declaration i.e (C&lt;F1, …, Fn&gt;, n&gt;0), given a parameterized class type C&lt;T1, …, Tn&gt; where each T, denoted Ti, for 1≤i≤n, is a type, the direct superinterface of these parameterized class type are all types in the form I&lt;Ui theta, Uk  theta&gt; where I&lt;Ui, …, Uk&gt; is a direct superinterface of C&lt;F1, …, Fn&gt; and theta is the substitution [F1 := T1, …, Fn := Tn]. &lt;br /&gt;&lt;br /&gt;Note:&lt;br /&gt;1. each interface must name an accessible interface type&lt;br /&gt;2. if type name is followed by type arguments, it must be invoked as-is, i.e as declared. &lt;br /&gt;3. type arguments can never be wildcard if 2 is true. &lt;br /&gt;4. an interface can not occur in an implements clause more than once.&lt;br /&gt;&lt;br /&gt;An interface I is a superinterface of class type C if any of the following is true:&lt;br /&gt;- I is a direct superinterface&lt;br /&gt;- C has some direct superinterface J for which I is a superinterface. &lt;br /&gt;- I is a direct superinterface of the direct superclass of C&lt;br /&gt;&lt;br /&gt;(see jls for a simple, beautiful illustration in the section §8.1.5)&lt;br /&gt;&lt;br /&gt;A class may not at the same time be a subtype of two interface types which are different invocations of the same generic interface (because they have similar erasures), or an invocation of a generic interface and a raw type naming that same generic interface.&lt;br /&gt;&lt;br /&gt;class B implements I&lt;Integer&gt;  //erasure is /I/&lt;br /&gt;class C extends B implements I&lt;String&gt; //erasure /I/, similar to above&lt;br /&gt; &lt;br /&gt;therefore, C cannot implement a type erasure twice.&lt;br /&gt;&lt;br /&gt;Class body and Member declarations: a class body may contain declaration of members of a class, that is, fields, methods, nested class and interface declarations. A class body may also contain instance initialisers, static initializers, and constructor declarations.&lt;br /&gt;&lt;br /&gt;The scope of member declarations in any class, whether explicitly declared or inherited, is the entire body of the class. &lt;br /&gt;&lt;br /&gt;On shadowing, see the “Names, scope of a declaration” blog.&lt;br /&gt;&lt;br /&gt;CLASS MEMBERS:&lt;br /&gt;The members of a class type are all one of the following:&lt;br /&gt;- members inherited from its direct superclass, except for class Object, which has no direct superclass. &lt;br /&gt;- Members inherited from any direct superinterface.&lt;br /&gt;- Members declared in the class body. &lt;br /&gt;&lt;br /&gt;If a member is declared private, it cannot be inherited by subclasses of that class, but where declared as protected or public, other packages other than the one in which it is declared can inherit it. &lt;br /&gt;&lt;br /&gt;The types of members of a class are denoted as:&lt;br /&gt;a. for a field, its type&lt;br /&gt;b. for a method, an ordered 3-tuple consisting of:&lt;br /&gt;a. argument types: a list of the types of the arguments to the member method.&lt;br /&gt;b. Return type: a return type of the method member&lt;br /&gt;c. Throws clause: exception types declared in the throws clause of the method member. &lt;br /&gt;Note: constructors, static initialisers and instance initialisers are not members and therefore are not inherited. &lt;br /&gt;&lt;br /&gt;(there are fine examples in the jls at section §8.2 that well illustrate this concept.)&lt;br /&gt;&lt;br /&gt;FIELD DECLARATORS: the variables of a class type are introduced by field declarations. Field declaration is of the notation:&lt;br /&gt; FieldModifiersopt  Type  VariableDeclarators ;&lt;br /&gt;Variable declarations can be one or many and are indicated by a variable identifier that could be a simple or qualified name or a name that is an array type. If a field is initialized on being declared, then it is done so with an expression or an appropriate array initialiser. &lt;br /&gt;&lt;br /&gt;package examples;&lt;br /&gt;&lt;br /&gt;public class AnyClassWithVariable {&lt;br /&gt; //myfirstvar, mysecondvariable, simple named variables&lt;br /&gt; //am sure you can do qualified names easily!!!&lt;br /&gt; int myfirstvar; &lt;br /&gt; float mysecondvar = 0.006453f; //initialised and declared&lt;br /&gt; &lt;br /&gt; //an array variable stringer, not initialised&lt;br /&gt; String[] stringer = new String[3];&lt;br /&gt; &lt;br /&gt; //another that is initialised&lt;br /&gt; int[] twoshort = {3, 5, 7};&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Note: &lt;br /&gt;1. a compile time error is reported if the body of a class declaration declares 2 fields with the same name, but methods, types and fields may have the same name since they are used in different context and disambiguated by different lookup.&lt;br /&gt;2. Hiding fields: a field declared in a subclass with the same name as another in a superclass will hide the field in the superclass or superinterface. Hiding here corresponds to resolution mechanism for field name conflicts. In hiding, the 2 fields may have different type. &lt;br /&gt;3. Shadowing fields: declarations of any accessible field in enclosing classes or interfaces, and any local variable, formal method parameter and exception handler parameter with the same names as that field will result in shadowing. &lt;br /&gt;An illustration:&lt;br /&gt;&lt;br /&gt;package examples;&lt;br /&gt;&lt;br /&gt;public class AnyClassWithVariable {&lt;br /&gt; //myfirstvar, mysecondvariable, simple named variables&lt;br /&gt; //am sure you can do qualified names easily!!!&lt;br /&gt; int myfirstvar; &lt;br /&gt; float mysecondvar = 0.006453f; //initialised and declared&lt;br /&gt; &lt;br /&gt; //an array variable stringer, not initialised&lt;br /&gt; String[] stringer = new String[3];&lt;br /&gt; &lt;br /&gt; //another that is initialised&lt;br /&gt; int[] twoshort = {3, 5, 7};&lt;br /&gt; &lt;br /&gt; //shadowing of mysecondvar, reflected in main of Loader&lt;br /&gt; void shadowMethod(){&lt;br /&gt;  float mysecondvar = 0.098765f;&lt;br /&gt;  System.out.println(mysecondvar); //sure to shadow&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class ClassAndVariable extends AnyClassWithVariable {&lt;br /&gt; int myfirstvar = 400;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Loader {&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  AnyClassWithVariable tester = new AnyClassWithVariable();&lt;br /&gt;  &lt;br /&gt;  //mysecondvar in scope of class declaration&lt;br /&gt;  System.out.println("global mysecondvar is: &lt;br /&gt;"+tester.mysecondvar);&lt;br /&gt;  &lt;br /&gt;  //here shadowed in shadowMethod&lt;br /&gt;  System.out.print("global mysecondvar is shadowed by &lt;br /&gt;method's mysecondvar: ");&lt;br /&gt;  tester.shadowMethod();&lt;br /&gt;  &lt;br /&gt;  //to start to show hiding, we instantiate the subclass&lt;br /&gt;  ClassAndVariable test2 = new ClassAndVariable();&lt;br /&gt;  &lt;br /&gt;  //which myfirstvar int field will test2 give us&lt;br /&gt;  System.out.println("Of the two myfristvar fields, test2 &lt;br /&gt;gives: "+test2.myfirstvar);&lt;br /&gt;  System.out.println("which is hiding the uninitialised one, &lt;br /&gt;AnyClassWithVariable.myfristvar.");&lt;br /&gt;  &lt;br /&gt;  //to get this field, use the qualified name within the &lt;br /&gt;//method scope&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Field modifiers:  field modifiers are one of the following:&lt;br /&gt;&lt;br /&gt;public          protected          private          static          final          transient          volatile&lt;br /&gt;&lt;br /&gt;the appearance of a field modifier must be distinct although ordering is not defined, the above order is customary in java programming. &lt;br /&gt;&lt;br /&gt;If an annotation a corresponds to an annotation type T, then T has a (meta-)annotation m that corresponds to annotation.Target, then m must have an element whose value is annotation.ElementType.FIELD, or a compile-time error results. &lt;br /&gt;&lt;br /&gt;Static fields:  if a field is declared static, there exists exactly one incarnation of the field, no matter how many instances (or zero) of the class that may eventually be instantiated. A static field is sometimes called a class variable and is instantiated on class initialization. &lt;br /&gt;&lt;br /&gt;A field not declared static (or called a non-static field) is called an instance variable. An instance variable has distinct incarnations for every instance of a class. &lt;br /&gt;(see the example in §8.3.1.1 for class and instance variable distinction. Well explained. )&lt;br /&gt;&lt;br /&gt;Final fields: class and instance variables can be declared final. &lt;br /&gt;&lt;br /&gt;It is a compile time error if a blank final (a final variable whose declaration lacks an initializer) class variable is not definitely assigned by a static initialiser of the class in which it is declared. &lt;br /&gt;&lt;br /&gt;A blank final instance variable must be definitely assigned at the end of every constructor of the class in which it is declared, otherwise, a compile time error results. &lt;br /&gt;&lt;br /&gt;Transient fields: variables declared transient will never be part of the persistent state of an object, such that the system service does not save this variable in persistent storage. &lt;br /&gt;&lt;br /&gt;Volatile fields: when a variable is accessed by more than one thread with at least one write operation on the variable followed by any number of reads, the java programming language gives the programmer the facility of locking the variable to ensure consistent and reliable updating of the variable. The modifier volatile supplements this locking making sure that the java memory model gives all threads a consistent value for this variable. &lt;br /&gt;&lt;br /&gt;(to be continued)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-2108838812711574398?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/2108838812711574398/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=2108838812711574398' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/2108838812711574398'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/2108838812711574398'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/classes3.html' title='CLASSES(3)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-9065641918984695199</id><published>2007-04-13T02:58:00.000-07:00</published><updated>2007-04-13T02:59:40.773-07:00</updated><title type='text'>CLASSES(2)</title><content type='html'>CLASSES(2)&lt;br /&gt;&lt;br /&gt;Inner classes and enclosing instances: any class within another class is said to be nested, but a nested class that is not implicitly or explicitly declared static is said to be an inner class. &lt;br /&gt;Examples illustrating rules on inner classes:&lt;br /&gt;&lt;br /&gt;package examples;&lt;br /&gt;&lt;br /&gt;class ByTheWay {&lt;br /&gt; static int x = 4;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class MyOuter {&lt;br /&gt; &lt;br /&gt; //nested class declared static&lt;br /&gt; static class NotInnerClass{&lt;br /&gt;  &lt;br /&gt;  //nested non-inner class can declare static members &lt;br /&gt;  //freely&lt;br /&gt;  static void trialMethod(){}&lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //nested class, not declared static, d4 inner class&lt;br /&gt; //extending ByTheWay makes Inner inherit a static member, note&lt;br /&gt; class InnerClass extends ByTheWay {&lt;br /&gt;  &lt;br /&gt;  //if inner classes are to declare static members, they &lt;br /&gt;  //must be constants&lt;br /&gt;  static final String candeclare = "declared";&lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //nested member, interface, implicitly static&lt;br /&gt; interface ImplicitStaticMember{&lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;And here’s another example that deals with enclosing instances and static contexts. &lt;br /&gt;&lt;br /&gt;package examples;&lt;br /&gt;&lt;br /&gt;class AnotherExample {&lt;br /&gt; String name="david";&lt;br /&gt; //this inner class, MyInner, occurs in a static context&lt;br /&gt; //due to static oldmethod. therefore it's lexically enclosing&lt;br /&gt; //block that of oldmethod and it has no lexically enclosing &lt;br /&gt; //class&lt;br /&gt; static void oldmethod(){&lt;br /&gt;  final int m = 6;&lt;br /&gt;  class MyInner {&lt;br /&gt;   int y = m; //to use m in MyInner, declare it final&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //inner class without a static context and the immediately&lt;br /&gt; //lexically enclosing class of Without in AnotherExample &lt;br /&gt; class Without {&lt;br /&gt;  String name="micheal";  &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Loader {&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  //since the immediately enclosin instance of Without is&lt;br /&gt;  //AnotherExample, reflected in the instance creation&lt;br /&gt;  //constructor invocation for any object of type, Without. &lt;br /&gt;  //the name field exists for both classes&lt;br /&gt;  //creator attaches to its local field in scope&lt;br /&gt;  //i.e no naming conflict in same variable for inner and &lt;br /&gt;  //its enclosing variable&lt;br /&gt;  AnotherExample.Without creator = new AnotherExample().new &lt;br /&gt;Without();&lt;br /&gt;  System.out.println("creator knows its name which is: &lt;br /&gt;"+creator.name);&lt;br /&gt;  &lt;br /&gt;  //AnotherExample is the 0th lexically enclosing instance &lt;br /&gt;  //of itself, i.e associated only with itself. &lt;br /&gt;  AnotherExample myself = new AnotherExample();&lt;br /&gt;  System.out.println("Associated with myself, i am: &lt;br /&gt;"+myself.name);&lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Superclasses and Subclasses: the optional extends clause in a normal class declaration specifies the direct superclass of the current class. &lt;br /&gt;&lt;br /&gt;Notation:  super:&lt;br /&gt;   extends ClassType&lt;br /&gt;a class is said to be a direct subclass of its direct superclass where the direct superclass is the class from whose implementation the implementation of the subclass is derived. &lt;br /&gt;&lt;br /&gt;The direct superclass of an enum type E is Enum&lt;E&gt;.&lt;br /&gt;&lt;br /&gt;The extends clause must not appear in the definition of the class Object, because Object is a primordial class and has no direct superclass. &lt;br /&gt;&lt;br /&gt;Given a class declaration which could possibly be or not be generic, i.e (C&lt;F1,…,Fn&gt;, n&gt;0, c≠Object), the direct superclass of the class type is the type given in the extends clause when C is declared else Object becomes the direct superclass. &lt;br /&gt;&lt;br /&gt;If C is a generic class declaration (C&lt;F1, …, Fn&gt;,n&gt;0), given a parameterized class type C&lt;T1, …, Tn&gt; where for each T, i.e Ti,  1≤i≤n, T is a type, the direct superclass is D&lt;U1 theta, …, Uk theta&gt;, where D&lt;U1, …, Uk&gt; is the direct superclass of C&lt;F1, …, Fn&gt; and theta is the substitution [F1 := T1, …, Fn := Tn].&lt;br /&gt;&lt;br /&gt;Notes:&lt;br /&gt;1. the class type must be an accessible, existing class type. &lt;br /&gt;2. the class type must allow subclassing i.e should never be declared final&lt;br /&gt;3. the class type must never name the class Enum or any of its invocations&lt;br /&gt;4. you should always invoke parameterized types correctly, as declared and never invoke a wildcard type variable. &lt;br /&gt;&lt;br /&gt;A subclass relationship is a transitive closure of the direct subclass relationship i.e if class A is a subclass of class C, then either of the following is true:&lt;br /&gt;- A is direct subclass of C&lt;br /&gt;- There exists a B such that A is a subclass of B and B is a subclass of C, applying this definition recursively. &lt;br /&gt;&lt;br /&gt;A class C directly depends on a type T if T is mentioned as an extends or implements clause of C either as a superclass or superinterface, or as a qualifier of a superclass or superinterface name. &lt;br /&gt;&lt;br /&gt;A class C depends on a reference type T if any of the following are true:&lt;br /&gt;- C directly depends on T&lt;br /&gt;- C directly depends on an interface I that depends on T&lt;br /&gt;- C directly depends on a class D that depends on T.&lt;br /&gt;Note: a class cannot depend on itself. &lt;br /&gt;&lt;br /&gt;(to be continued)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-9065641918984695199?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/9065641918984695199/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=9065641918984695199' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/9065641918984695199'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/9065641918984695199'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/classes2.html' title='CLASSES(2)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-5831410913704497580</id><published>2007-04-13T02:57:00.000-07:00</published><updated>2007-04-13T02:58:18.063-07:00</updated><title type='text'>CLASSES</title><content type='html'>CLASSES&lt;br /&gt;Class declarations define new reference types and describe their implementation. This chapter dwells on members of a class, class semantics as well as meanings of access modifiers applied to classes and members of classes. &lt;br /&gt;&lt;br /&gt;Class declarations: a class declaration defines new reference types. A class declaration can be either a normal class declaration or an enum declaration. &lt;br /&gt;The notation for a normal class declaration is as below: &lt;br /&gt;ClassModifiersopt class identifier TypeParametersopt Superopt Interfacesopt ClassBody&lt;br /&gt;&lt;br /&gt;A class declaration is introduced by the keyword class which can be preceded by an optional access modifier. The identifier in a class declaration specifies the name of a class. We’ve discussed names and meaning of names in an earlier blog. If a class declaration has TypeParameters specified, which is optional, then it is a generic class and in a class declaration, only one optional superclass can exist while any number of interfaces, also optional, can be implemented. The ClassBody is enclosed in opening ‘{‘ and closing ‘}’ wherein the codes for class behaviour and storage spaces are defined. &lt;br /&gt;&lt;br /&gt;Class Modifiers: more than one class modifier can be specified for a class. The modifiers that can be attached to class declarations are:&lt;br /&gt;&lt;br /&gt;public (applied only to top level classes and member classes. )&lt;br /&gt;protected (applies only to member classes)&lt;br /&gt;private (applies only to member classes)&lt;br /&gt;abstract&lt;br /&gt;static (applies to member classes)&lt;br /&gt;final&lt;br /&gt;strictfp&lt;br /&gt;&lt;br /&gt;please note that a compile time error will occur if the same modifier appears more than once in a class declaration. If an annotation on a class declaration, a, corresponds to an annotation type, T and T has a (meta-)annotation m such that m corresponds to annotation.Target, then m must have an element whose value is annotation.ElementType.TYPE or a compile time error occurs. &lt;br /&gt;&lt;br /&gt;Abstract classes: an abstract class is a class that is considered incomplete. Note that only a class declared abstract is allowed to have abstract methods, otherwise, a compile time error occurs. &lt;br /&gt;&lt;br /&gt;Enum types (in a later blog, please) must not be declared abstract, otherwise, a compile time error occurs. An Enum type is only allowed to declare a method as abstract if it has one or more enum constants with class bodies that provide concrete implementation of the abstract method. &lt;br /&gt;&lt;br /&gt;A class C can have abstract methods from any of the 3 ways:&lt;br /&gt; - if C explicitly declares an abstract method (remember, from what we discussed, to do this C has to be abstract itself.)&lt;br /&gt; - if any of C’s superclasses have an abstract method and C neither declares nor inherits a method that implements this method. &lt;br /&gt; - a direct superinterface of C declares or inherits a method (interface are necessarily abstract; to be discussed later) and C neither declares nor inherits the method that implements it. &lt;br /&gt;&lt;br /&gt;The example in the jls will be restated here, not for redundancy’s sake but to clarify some points explained therein. &lt;br /&gt;&lt;br /&gt;package examples;&lt;br /&gt;&lt;br /&gt;//Point is declared abstract because it contains &lt;br /&gt;//an abstract method, alert()&lt;br /&gt;abstract class Point {&lt;br /&gt; int x=1, y=1;&lt;br /&gt; void move(int dx, int dy){&lt;br /&gt;  x += dx;&lt;br /&gt;  y += dy;&lt;br /&gt;  alert();&lt;br /&gt; }&lt;br /&gt; abstract void alert();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//ColoredPoint must be declared abstract since it&lt;br /&gt;//inherits alert() from Point and doesn't implement it&lt;br /&gt;abstract class ColoredPoint extends Point {&lt;br /&gt; int color;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//SimplePoint although subclass of Point is not abstract&lt;br /&gt;//because it implements alert()&lt;br /&gt;class SimplePoint extends Point{&lt;br /&gt; void alert(){&lt;br /&gt;  System.out.print("X is now: "+this.x+". ");&lt;br /&gt;  System.out.println("Y is now: "+this.y);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Loader {&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  Point p = new SimplePoint();&lt;br /&gt;  &lt;br /&gt;  //field initialisers and methods of Point can &lt;br /&gt;  //now be invoked. try it and see.&lt;br /&gt;  p.move(2, 2); &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;A class is declared abstract with the intent that subclasses can be created to complete the implementation but where one wants to create a class that needs not be instantiated, a better way to do this is to declare the class’ constructor as private, never invoke the constructor, declare it without arguments and declare no other constructor. &lt;br /&gt;Final classes: a final class is a class whose definition is complete and no subclasses are desired or required for it. &lt;br /&gt;Note:&lt;br /&gt;1. a final class can be a superclass of another class&lt;br /&gt;2. a class declared final can never be overridden because it doesn’t have subclasses&lt;br /&gt;3. a class declared final can never be declared abstract&lt;br /&gt;&lt;br /&gt;strictfp classes: the effect of modifying a class with the strictfp modifier is to make all float or double expressions within the class declaration to be explicitly FP-strict i.e strictly within the floating-point value set.&lt;br /&gt;&lt;br /&gt;Generic Class and Type Parameters: a class is generic if it declares one or more type variables. These type variables are known as the type parameters of the class.&lt;br /&gt;The type parameter section follows the class name and its delimited by angle brackets, ‘&lt;’ and ‘&gt;’. Note that the type parameters are sectioned in the type and their definition is within the generic class declaration. They share the same class at run-time. &lt;br /&gt;&lt;br /&gt;Note: &lt;br /&gt;1. generic classes do not throw exceptions i.e they can never be direct or indirect subclasses of the class Throwable. &lt;br /&gt;2. the scope of a class’ type parameter is the entire declaration of the class including the type parameters section itself. Therefore, type parameters can appear as parts of their own bounds, and as bounds of other type parameters declared in the same section. &lt;br /&gt;3. parameterized class declarations can be nested inside other declarations. &lt;br /&gt;&lt;br /&gt;I tried to write a little example to this effect. &lt;br /&gt;&lt;br /&gt;package examples;&lt;br /&gt;&lt;br /&gt;public class Nigeria {&lt;br /&gt; String name, gmt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class Ghana {&lt;br /&gt; String name, gmt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class Africa&lt;T&gt; {&lt;br /&gt; //note: the field declaration for this class will be&lt;br /&gt; //within the scope of the type variables&lt;br /&gt; String name, gmt;&lt;br /&gt; Africa(String countryname, String countrygmt){&lt;br /&gt;  this.name = countryname;  //type has fields in scope&lt;br /&gt;  this.gmt = countrygmt;&lt;br /&gt; } &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Loader {&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  Africa&lt;Nigeria&gt; naija = new Africa&lt;Nigeria&gt;("Nigeria", &lt;br /&gt;"+1");&lt;br /&gt;  Africa&lt;Ghana&gt; kwama = new Africa&lt;Ghana&gt;("Ghana", "0");&lt;br /&gt;  &lt;br /&gt;  //the sections in our generic class share same run-time&lt;br /&gt;  //class.&lt;br /&gt;  boolean b = naija.getClass()== kwama.getClass();&lt;br /&gt;  System.out.println(b);&lt;br /&gt;  &lt;br /&gt;  //let's create a nigerian object&lt;br /&gt;  Nigeria mortar = new Nigeria();&lt;br /&gt;  &lt;br /&gt;  //type variable Nigeria not same as class type Nigeria,note&lt;br /&gt;  System.out.println("Is type variable same as class type? &lt;br /&gt;"+mortar.equals(naija));&lt;br /&gt;  &lt;br /&gt;  //but class type can reference type variable&lt;br /&gt;  mortar.name = naija.name;&lt;br /&gt;  System.out.println("Mortar took a name which is: " &lt;br /&gt;+mortar.name);&lt;br /&gt;  &lt;br /&gt;  //we're certain now that we have the right name&lt;br /&gt;  System.out.println("In a section of africa there is a &lt;br /&gt;country called: "+naija.name);    &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;(to be continued)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-5831410913704497580?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/5831410913704497580/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=5831410913704497580' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/5831410913704497580'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/5831410913704497580'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/classes.html' title='CLASSES'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-2254685771688171820</id><published>2007-04-13T02:54:00.001-07:00</published><updated>2007-04-13T02:54:38.246-07:00</updated><title type='text'>PACKAGES (3)</title><content type='html'>PACKAGES (3)&lt;br /&gt;&lt;br /&gt;TOP LEVEL TYPE DECLARATIONS: &lt;br /&gt;Top level type declarations declare a top level class type or a top level interface type. &lt;br /&gt;&lt;br /&gt;Accessibility: the default accessibility (package-private) applies to this declaration, but if the declaration is public, access is granted to the type by codes from other packages. &lt;br /&gt;&lt;br /&gt;Scope: the scope of this declaration is all type declarations in the package in which the top level type is  declared. &lt;br /&gt;&lt;br /&gt;For instance, where the package has name P and the type is named T, therefore , the fully qualified name is P.T, otherwise the fully qualified name is T, i.e where the type is in an unnamed package. &lt;br /&gt;&lt;br /&gt;Note: &lt;br /&gt;1. a restriction can always be enforced by a host system that if a type is not associated with a type name plus an extension (.java or .jav) and either:&lt;br /&gt;a. the type is referred to by code in other compilation units of the package in which the type is declared&lt;br /&gt;b. or the type is declared public (quite sure this’ your piece of cake!)&lt;br /&gt;is true, then the host system should return a compile time error. So, there must be at most one such type per compilation unit. &lt;br /&gt;&lt;br /&gt;In a database storage, this restriction might not be imposed. &lt;br /&gt;&lt;br /&gt;2. a compile time error occurs if the name of a top level type appears as the name of any other top level class or interface type declared in the same package. &lt;br /&gt;&lt;br /&gt;3. also, if (2) is also declared as a type by a single-type-import declaration in the compilation unit containing the type declaration, a compile time error occurs. &lt;br /&gt;Please, see the examples in §7.6 of the jls; they are very instructive and I don’t want to create a redundancy. &lt;br /&gt;&lt;br /&gt;UNIQUE PACKAGE NAMES:&lt;br /&gt;Unique package names are essentially necessary when a package is not for local or casual usage but to be widely distributed for easy and automatic installation and cataloguing of packages. &lt;br /&gt;&lt;br /&gt;Suggestions of usage: &lt;br /&gt;1. unique package names are usually formed form internet domain names of the organization one belongs to. Example: if your internet domain is mydomain.com, these are usually used to derive unique package names. You reverse this name, component by component to obtain, com.mydomain and use this as a prefix for your package names. Usally, a convention is developed within organizations on how to administer package names using this domain name as base. &lt;br /&gt;&lt;br /&gt;Where the internet domain name is not a valid package name for your case you can do the following:&lt;br /&gt;a. where the domain name contains a hyphen or any other special character not allowed in an identifier, convert it into an underscore _ .&lt;br /&gt;b. if any resulting package name components are keywords, then append an underscore to them. &lt;br /&gt;c. If any of the resulting package name components start with a digit, or any other character not allowed as an initial character of an identifier, have an underscore prefixed to the component. &lt;br /&gt;&lt;br /&gt;2. the first component of unique package names is always written in all lower-case ASCII letters and should be a top level domain name (currently com, edu, mil, net and org) or one of the English two-letter codes identifying countries as specified in ISO standard 3166, 1981. &lt;br /&gt;com.mydomain.myjavafiles.me&lt;br /&gt;edu.myschool.myschoolfiles._us&lt;br /&gt;&lt;br /&gt;3. the name of a package is not meant to imply where the package is stored within the internet. The suggested convention above merely a convenience to piggyback a package naming convention on top of an existing, widely known unique name registry instead of having to create a separate registry for package names.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-2254685771688171820?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/2254685771688171820/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=2254685771688171820' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/2254685771688171820'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/2254685771688171820'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/packages-3.html' title='PACKAGES (3)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-5098766524132664848</id><published>2007-04-13T02:48:00.000-07:00</published><updated>2007-04-13T02:50:00.702-07:00</updated><title type='text'>PACKAGES(2)</title><content type='html'>PACKAGES(2)&lt;br /&gt;&lt;br /&gt;IMPORT DECLARATIONS:&lt;br /&gt;An import declaration allows a static member (in another type) or a named type (in another package) to be referred to by a simple name that consists of a single identifier. The appropriate word, import, is used in the declaration. &lt;br /&gt;There are four types of import declarations:&lt;br /&gt;1. single-type-import declaration (imports a single named type by mentioning its canonical name.)&lt;br /&gt;2. type-import-on-demand declaration (imports all the accessible types of a named type as needed.)&lt;br /&gt;3. single-static-import declaration (imports all accessible static members with a  given name from a type, by giving its canonical name.)&lt;br /&gt;4. static-import-on-demand declaration (imports all accessible static members of a named type as needed.)&lt;br /&gt;&lt;br /&gt;the scope of any type imported is all the class and interface type declaration in the compilation unit in which the import declaration appears. It does not include, in its scope:&lt;br /&gt;1. the package statement&lt;br /&gt;2. other import declarations in the current compilation unit&lt;br /&gt;3. other compilation units in the same package. &lt;br /&gt;&lt;br /&gt;Single-type-import declaration:  a single-type-import declaration imports a single type by giving its canonical name, making it available under a simple name in the class and interface declaration in the compilation unit in which the single-type-import declaration appears.&lt;br /&gt;&lt;br /&gt;Denoted in this :   import TypeName ; &lt;br /&gt;Given a single-type-import declaration, d, the type imported, n, in a compilation unit, c, of package , p, shadows:&lt;br /&gt;- any top level same-named type, d, in another compilation unit of p throughout c.&lt;br /&gt;- any type with same name, n, imported by a type-import-on-demand declaration in  c throughout c. &lt;br /&gt;- any type with same name, n, imported by a static-import-on-demand declaration in c throughout c. &lt;br /&gt;&lt;br /&gt;Type-import-on-demand declaration: a type import-on-demand declaration allows all accessible types declared in the type or package named by a canonical name to be imported as needed. &lt;br /&gt;&lt;br /&gt;Denoted as:  import PackageOrTypeName.* ; &lt;br /&gt;&lt;br /&gt;Note:&lt;br /&gt;1. the type or package must be accessible or a compile time error is the result. &lt;br /&gt;2. when redundancy in importing is encountered, i.e where 2 or more type import-on-demand declaration names the same type or package, the effect is as if that type were imported only once. &lt;br /&gt;3. if a type-import-on demand declaration and a static-import-on-demand declaration both import the same type in a compilation unit, the effect is as if the static member type of that type were imported only once. &lt;br /&gt;4. a type import on demand declaration will never shadow any other declaration. &lt;br /&gt;Considering a type imported as: import java.util.* ; into the class or interface type of this compilation unit, &lt;br /&gt;5. a simple name Vector refers to a type Vector  in java.util.Vector, provided Vector is a. not shadowed, b. obscured in its scope. &lt;br /&gt;6. a single-type-import declaration with simple name Vector might shadow, java.util.Vector; an explicit declaration of a type Vector in the class or interface might shadow java.util.Vector; a nested class or interface with simple name Vector might also shadow it. &lt;br /&gt;7. declaration of a field, parameter or local variable named Vector might obscure java.util.Vector.&lt;br /&gt;&lt;br /&gt;Single static import declaration: a single-static-import declaration imports all accessible static members with a given simple name from a type. &lt;br /&gt;&lt;br /&gt;Denoted as:  import static TypeName.identifier; &lt;br /&gt;&lt;br /&gt;The TypeName must be the canonical name of a class or interface type which exists  and is accessible, otherwise a compile time error is the result. &lt;br /&gt;&lt;br /&gt;The identifier must name at least one existing static member of the named type which is accessible, otherwise a compile time error occurs. &lt;br /&gt;Note:&lt;br /&gt;&lt;br /&gt;1. a static member, n, whether field or method name imported this way will shadow every other static-import-on-demand member n whether field or method with the same signature as the single static member. &lt;br /&gt;&lt;br /&gt;2. any static type with the same name n imported by a static-import-on-demand declaration is also shadowed i.e &lt;br /&gt;o any static type with same name n imported by static-import-on-demand declaration throughout the compilation unit. &lt;br /&gt;o Any top level type named n declared in another compilation unit throughout the compilation unit&lt;br /&gt;o Any type named n imported in a type import on demand declaration in the compilation unit throughout the compilation unit.&lt;br /&gt;&lt;br /&gt;3. redundancy is allowed. &lt;br /&gt;&lt;br /&gt;4. if the simple name of a member and a type imported by a single-static-import declaration and a single-type-import declaration respectively, a compile time error occurs. &lt;br /&gt;&lt;br /&gt;5. if a single-static-import declaration imports a type n and the compilation unit explicitly declares same type n, a compile time error results. &lt;br /&gt;&lt;br /&gt;Static import on demand declaration:  a static-import-on-demand declaration allows all accessible type members declared in the type named by a canonical name to be imported as needed. &lt;br /&gt;&lt;br /&gt;Denoted as:   import static TypeName.* ;&lt;br /&gt;Note:&lt;br /&gt;&lt;br /&gt;1. the type used for importing must exist. &lt;br /&gt;&lt;br /&gt;2. redundancy is allowed, either in types or members. &lt;br /&gt;&lt;br /&gt;3. if a compilation unit contains a static-import-on-demand declaration and a type-import-on-demand declaration that name the same type, the effect is as if the static member types of that type were imported only once. &lt;br /&gt;&lt;br /&gt;Automatic imports: all the public type names declared in the predefined package, java.lang are automatically imported.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-5098766524132664848?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/5098766524132664848/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=5098766524132664848' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/5098766524132664848'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/5098766524132664848'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/packages2.html' title='PACKAGES(2)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-2053845276989535594</id><published>2007-04-13T02:43:00.000-07:00</published><updated>2007-04-13T02:47:47.752-07:00</updated><title type='text'>PACKAGES</title><content type='html'>PACKAGES&lt;br /&gt;&lt;br /&gt;Programs are organized as set of packages, with each package having its own set of names for types, which will help prevent name conflicts. We know by now that if a type is top level and declared public it is generally accessible outside the package. The sections below discusses other features of packages.&lt;br /&gt;&lt;br /&gt;Package Members: package members are:&lt;br /&gt;1. subpackages&lt;br /&gt;2. all top level class types&lt;br /&gt;3. top level interface types&lt;br /&gt;where 2 and 3 are declared in all the compilation units of the package. &lt;br /&gt;Note: &lt;br /&gt;a. if a package P has a subpackage Q, then the fully qualified name of the subpackage is P.Q&lt;br /&gt;b. a package may not contain 2 members of the same name or a compile-time error results.&lt;br /&gt;c. The hierarchical naming structure for packages is intended for convenience in related-packages organization but has no significance except to prevent package members from being same name. &lt;br /&gt;&lt;br /&gt;Host support for packages:&lt;br /&gt;&lt;br /&gt;Each host determines how packages, compilation units and subpackages are created and started, and which compilation units are observed in a particular compilation. &lt;br /&gt;&lt;br /&gt;Compilation unit observability in turn determines which packages are observable and which packages are in scope. &lt;br /&gt;&lt;br /&gt;Packages may be stored in a local file system or use a distributed file system or some form of database to store source and/or binary code. &lt;br /&gt;&lt;br /&gt;Storing packages in a file system: imagine that a directory is used to store the packages that are used for a project, then each immediate subdirectory of the directory would represents a top level package i.e one whose fully qualified name consists of a single simple name.&lt;br /&gt;&lt;br /&gt;e.g subdirectories might be java or com or one you created yourself, like api_package. The directory java might contain, amongst others, the subdirectories applet, awt, io, lang or util. these subdirectories then correspond to the packages java.applet; java.awt; java.io; java.lang; java.util which are defined as part of the java API. &lt;br /&gt;&lt;br /&gt;Inside the util directory, we might get the following files:&lt;br /&gt;BitSet.java, BitSet.class where the .java files contain the source code and the .class files contain the binary compiled files for a compilation unit that defines the class or interface. &lt;br /&gt;&lt;br /&gt;So if we had something like: java.util.BitSet, then the  directory structure in same a Windows file system will be java\util\BitSet i.e each package is said to have a top level directory where it is the subdirectory. &lt;br /&gt;&lt;br /&gt;If a package name component or class name contains characters outside the allowed ranges (usually ASCII) of an Operating System’s directory naming scheme, the character outside the range can be escaped using the @ character followed by four hexadecimal digits giving the numeric value of the character, similar to the \uxxxx escape we earlier encountered in Unicode escaping. &lt;br /&gt;&lt;br /&gt;Supposing we have a package name like this: children.activities.craft.papierM\u00e2ch\u00e9 &lt;br /&gt;&lt;br /&gt;which in Unicode will give us:&lt;br /&gt;children.activities.craft.papierMâché &lt;br /&gt;&lt;br /&gt;and this might be mapped to the directory name:&lt;br /&gt;children\activities\craft\papierM@00e2ch@00e9 in Windows. &lt;br /&gt;&lt;br /&gt;Note: if the @ character is not a valid character in a file name for some given host file system, then some other character that is not identifier-valid could be used instead. &lt;br /&gt;&lt;br /&gt;Storing packages in a database: &lt;br /&gt;&lt;br /&gt;When a host system stores programs, their compilation units and subpackages in a database, such a database must relax some restrictions on compilation units as found in file-based implementation, but provision should exist so that such a program can be exported to file-based implementation. &lt;br /&gt;&lt;br /&gt;COMPILATION UNITS&lt;br /&gt;&lt;br /&gt;A compilation unit is the goal symbol for the syntactic grammar of java. Note here that type dependence can be created amongst different compilation units i.e where a type contains another type as its member and that other type contains this type as its member. &lt;br /&gt;&lt;br /&gt;A compilation unit consists of three parts, each of which is optional:&lt;br /&gt;&lt;br /&gt;1. a package declaration, giving the fully qualified name of the package to which the compilation unit belongs. If there is no package declaration, then the package is an unnamed package. &lt;br /&gt;&lt;br /&gt;2. import declaration that allows simple names use of types, given other packages and static members of types to be referred. &lt;br /&gt;&lt;br /&gt;3. top level type declarations of class and interface types. &lt;br /&gt;&lt;br /&gt;A host system determines which compilation units are observable but all compilation units  of the package java and its subpackages java.lang and java.io must always be observable. The observability of a compilation unit affects the observability of the package. &lt;br /&gt;&lt;br /&gt;Named Packages: a named package is one with a package declaration. A package declaration is  defined thus:&lt;br /&gt;Annotationsopt package PackageName ;&lt;br /&gt;&lt;br /&gt;The keyword package may optionally be preceded by annotation modifiers. If an annotation a on a package declaration corresponds to an annotation type T, T has a (meta)annotation m that corresponds to annotation.Target, then m must have an element whose value is annotation.ElementType.PACKAGE, otherwise a compile time error occurs. &lt;br /&gt;&lt;br /&gt;The PackageName in a package declaration must be the fully qualified name of the package.&lt;br /&gt;&lt;br /&gt;Package annotations: annotations may be used on package declaration with the restriction that at most one  annotated package declaration is permitted for a given package. &lt;br /&gt;&lt;br /&gt;Unnamed Packages: a compilation unit where there is not package declaration is unnamed. Unnamed packages do not have subpackages.&lt;br /&gt;&lt;br /&gt;Observability of a package: a package is observable if and only if either:&lt;br /&gt;- a compilation unit containing a declaration of the package is observable. &lt;br /&gt;- A subpackage of the package is observable. &lt;br /&gt;&lt;br /&gt;Scope of a package declaration: provided that a package declaration is observable, the scope is all observable compilation units. Subpackage declarations are never in scope. Package declarations never shadow other declarations.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-2053845276989535594?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/2053845276989535594/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=2053845276989535594' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/2053845276989535594'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/2053845276989535594'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/packages.html' title='PACKAGES'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-2641949832177344333</id><published>2007-04-10T04:01:00.000-07:00</published><updated>2007-07-23T06:13:45.207-07:00</updated><title type='text'></title><content type='html'>&lt;P CLASS=MsoNormal&gt;   &lt;B STYLE=""&gt;NAMES(4)&lt;/B&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;B STYLE=""&gt;Meaning of PackageNames: &lt;/B&gt; &lt;/P&gt; &lt;OL START=1 STYLE=MARGIN-TOP:0in TYPE=1&gt;   &lt;LI CLASS=MsoNormal STYLE=""&gt;     if package name a simple name. then it denotes a package that exists at compile time otherwise error.   &lt;/LI&gt;   &lt;LI CLASS=MsoNormal STYLE=""&gt;     if a qualified name, Q.id, then Q is a package that has id as a member package of Q, i.e a subpackage, that exists at compile time otherwise a compile time error results.   &lt;/LI&gt; &lt;/OL&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;B STYLE=""&gt;Meaning of PackageOrTypeNames:&lt;/B&gt; &lt;/P&gt; &lt;OL START=1 STYLE=MARGIN-TOP:0in TYPE=1&gt;   &lt;LI CLASS=MsoNormal STYLE=""&gt;     if a simple name. then it denotes a TypeName if the name Q occurs in the scope of a type named Q, else a PackageName.   &lt;/LI&gt;   &lt;LI CLASS=MsoNormal STYLE=""&gt;     let qualified name be Q.id. if member id of a type or package exists, then a TypeName, otherwise, a PackageName.   &lt;/LI&gt; &lt;/OL&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;B STYLE=""&gt;Meaning of TypeNames:&lt;/B&gt; &lt;/P&gt; &lt;OL START=1 STYLE=MARGIN-TOP:0in TYPE=1&gt;   &lt;LI CLASS=MsoNormal STYLE=""&gt;     if simple name. if name consists of a single identifier, then the identifier must exist in the scope of exactly one visible declaration of a type with this name, or a compile time error occurs. The meaning of a type is a type.   &lt;/LI&gt;   &lt;LI CLASS=MsoNormal STYLE=""&gt;     if qualified name of the form Q.id. if id names exactly one type that is a member of the type or package denoted by Q, then the qualified type name denotes that type. A compile time error occurs if id does not name a member type within Q, or is not accessible in Q or id occurs more than once in Q, then compile time error occurs.   &lt;/LI&gt; &lt;/OL&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;B STYLE=""&gt;Meaning of ExpressionNames:&lt;/B&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   1. simple name or single identifier. There must be exactly one visible declaration denoting either a field, parameter or local variable in scope at the point at which the identifier occurs.&lt;SPAN STYLE=""&gt;  &lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   If declaration declares a &lt;I STYLE=""&gt;final&lt;/I&gt; field, the name’s meaning is its value, otherwise meaning of the expression name is the variable declared by the declaration. &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   If the field is an instance variable, the expression name must appear within the declaration of an instance method, constructor, instance initializer or instance variable initializer. If within a static method, static initializer or initializer for a &lt;I STYLE=""&gt;static&lt;/I&gt; variable, then a compile time error occurs. &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   2. qualified, of form Q.id. in this situation, the expression name, Q.id has already been classified as package, type or expression name. &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   - if Q is a package name, then a compile time error occurs. &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   - if Q a type name naming a class type, then &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=TEXT-INDENT:0.5in&gt;   - there must be exactly one accessible member that is the field id otherwise a compile time error occurs. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=TEXT-INDENT:0.5in&gt;   -&lt;SPAN STYLE=""&gt;  &lt;/SPAN&gt;otherwise if the single accessible member is not a class variable (i.e declared &lt;I STYLE=""&gt;stastic&lt;/I&gt;) then a compile time error occurs. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=TEXT-INDENT:0.5in&gt;   - otherwise if the class variable is declared &lt;I STYLE=""&gt;final&lt;/I&gt;, then Q.id denotes the value of the class variable. The type of the expression Q.id is the declared type of the class variable after capture conversion. Note that Q.id should not appear in a context that requires a variable. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=TEXT-INDENT:0.5in&gt;   - otherwise, Q.id denotes the class variable. The type of the expression Q.id being the declared type of the class variable after capture conversion. This clause also covers the enum constants since these always have a corresponding &lt;I STYLE=""&gt;final&lt;/I&gt; class variable. &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   - if Q is a type name that names an interface type &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;SPAN STYLE=""&gt;            &lt;/SPAN&gt;- there must be exactly one accessible member of the interface type, the field named id. &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;SPAN STYLE=""&gt;            &lt;/SPAN&gt;- otherwise Q.id denotes the value of the field. The declared type being the type of the field after capture conversion. If Q.id appears in a context that requires a variable and not a value, then a compile time error ensures. &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   - if Q is an expression name, let T be the type of the expression Q: &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;SPAN STYLE=""&gt;            &lt;/SPAN&gt;- T must be a reference type &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;SPAN STYLE=""&gt;            &lt;/SPAN&gt;- there must be exactly one accessible member of the type T named id. &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;SPAN STYLE=""&gt;            &lt;/SPAN&gt;- otherwise if this field is any of the following: &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;SPAN STYLE=""&gt;                        &lt;/SPAN&gt;- a field of an interface type, or &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;SPAN STYLE=""&gt;                        &lt;/SPAN&gt;- a &lt;I STYLE=""&gt;final&lt;/I&gt; field of a class type (either a class or an instance variable) &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;SPAN STYLE=""&gt;                        &lt;/SPAN&gt;- the &lt;I STYLE=""&gt;final&lt;/I&gt; field &lt;I STYLE=""&gt;length&lt;/I&gt; of an array type &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;SPAN STYLE=""&gt;            &lt;/SPAN&gt;Then Q.id denotes the value of the field. The declared type being the type after capture conversion. If the context requires a variable, a compile time error. &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;SPAN STYLE=""&gt;            &lt;/SPAN&gt;- otherwise Q.id is a variable, id, (class or instance variable). The type of the expression Q.id is the type of the field member after capture conversion. &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;B STYLE=""&gt;MEANINGS OF METHOD NAMES&lt;/B&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   A method name appears only in a method invocation expression or as an element name in an element-value pair for annotations. Determination of the meaning of a name classified as a method name is as follows: &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   1. &lt;I STYLE=""&gt;Simple Method Names:&lt;/I&gt; a simple method name appears as the element name in an element-value pair. The &lt;I STYLE=""&gt;identifier&lt;/I&gt; in an element-value pair must be the simple name of one of the elements of the annotation type identified by &lt;I STYLE=""&gt;TypeName&lt;/I&gt; in the containing annotation, otherwise a compile time error occurs. &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   Otherwise, a simple method name appears in the context of a method invocation expression. &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   2. &lt;I STYLE=""&gt;Qualified Method Names: &lt;/I&gt;a qualified method name can only appear in the context of a method invocation expression. If given Q.id then Q has already been classified as a package name, a type name or an expression name. if Q is a package name, then compile time error results, otherwise id is the method name to be used for method invocation. If Q is a type name, then id must name at least one &lt;I STYLE=""&gt;static&lt;/I&gt; method of the type Q. if Q is an expression name, then let T be the type of the expression Q; id must name one method of the type T.&lt;SPAN STYLE=""&gt;  &lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;B STYLE=""&gt;ACCESS CONTROL: &lt;/B&gt;accessibility is a feature of the java programming language whereby access to details of entities in the language is allowed or otherwise disallowed. If allowed, the entity is said to be &lt;I STYLE=""&gt;accessible. &lt;/I&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   Note: a. accessibility depends on type and declaration modifiers. &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   b. means of access to members of package and reference types are &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=TEXT-INDENT:0.25in&gt;   – qualified names, &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;field access expressions &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;method invocation expressions &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   the three means above are called constructs for &lt;I STYLE=""&gt;qualified access. &lt;/I&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   Access control applies to: &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;qualified access &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;the invocation of constructors by class instance creation expressions &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;explicit constructor invocations &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;B STYLE=""&gt;Determining accessibility: &lt;/B&gt; &lt;/P&gt; &lt;OL START=1 STYLE=MARGIN-TOP:0in TYPE=1&gt;   &lt;LI CLASS=MsoNormal STYLE=""&gt;     package is always accessible   &lt;/LI&gt;   &lt;LI CLASS=MsoNormal STYLE=""&gt;     if a class or interface type is declared &lt;I STYLE=""&gt;public&lt;/I&gt;, thus provided it is observable in its compilation unit, it may be accessed by any code, otherwise, where not &lt;I STYLE=""&gt;public&lt;/I&gt;, access is from within the package in which it is declared.   &lt;/LI&gt;   &lt;LI CLASS=MsoNormal STYLE=""&gt;     an array type is accessible if and only if its element type is accessible   &lt;/LI&gt;   &lt;LI CLASS=MsoNormal STYLE=""&gt;     a member (class, interface, field or method) of a reference (class, interface or array) type or a constructor of a class type is accessible only if the type is accessible and the member or constructor is declared to permit access:   &lt;/LI&gt; &lt;/OL&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE='FONT-FAMILY:"Courier New"'&gt;&lt;SPAN STYLE=""&gt;o&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;       &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;if declared &lt;I STYLE=""&gt;public&lt;/I&gt; (note: all members of interfaces are implicitly &lt;I STYLE=""&gt;public&lt;/I&gt;) &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE='FONT-FAMILY:"Courier New"'&gt;&lt;SPAN STYLE=""&gt;o&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;       &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;if declared &lt;I STYLE=""&gt;protected&lt;/I&gt;, thus access is permitted for one of the following situations: &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=FONT-FAMILY:Wingdings&gt;&lt;SPAN STYLE=""&gt;§&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;where access occurs from within the package containing the class in which the &lt;I STYLE=""&gt;protected&lt;/I&gt; member or constructor is declared. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=FONT-FAMILY:Wingdings&gt;&lt;SPAN STYLE=""&gt;§&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;Access conforms to the section “&lt;B STYLE=""&gt;details on protected access&lt;/B&gt;” (immediately below.) &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=FONT-FAMILY:Wingdings&gt;&lt;SPAN STYLE=""&gt;§&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;  &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1in&gt;   &lt;SPAN STYLE=""&gt; &lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE='FONT-FAMILY:"Courier New"'&gt;&lt;SPAN STYLE=""&gt;o&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;       &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;If declared &lt;I STYLE=""&gt;private,&lt;/I&gt; access is permitted only within the body of the top level class that encloses the declaration of the member or constructor. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE='FONT-FAMILY:"Courier New"'&gt;&lt;SPAN STYLE=""&gt;o&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;       &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;Otherwise, there is default access (or &lt;I STYLE=""&gt;package-private.&lt;/I&gt;) where access occurs only from within the package in which the type is declared. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.75in&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;B STYLE=""&gt;Details on protected access: &lt;/B&gt;a &lt;I STYLE=""&gt;protected &lt;/I&gt;member or constructor of an object may be accessed from outside the package (like &lt;I STYLE=""&gt;public&lt;/I&gt;) in which it is declared &lt;I STYLE=""&gt;only&lt;/I&gt; by code that is responsible for the implementation of that object, otherwise access is defined as: &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   An example: &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;B STYLE=""&gt; &lt;/B&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=""&gt;   &lt;B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#7f0055'&gt;package&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt; api_package;&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New"'&gt;&lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=""&gt;   &lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New"'&gt; &lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=""&gt;   &lt;B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#7f0055'&gt;public&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt; &lt;/SPAN&gt;&lt;B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#7f0055'&gt;class&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt; T {&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New"'&gt;&lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=""&gt;   &lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;&lt;SPAN STYLE=""&gt;      &lt;/SPAN&gt;String &lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#0000c0'&gt;monkey&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;;&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New"'&gt;&lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=""&gt;   &lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;&lt;SPAN STYLE=""&gt;      &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#7f0055'&gt;protected&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt; T(){ &lt;/SPAN&gt;&lt;B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#7f0055'&gt;super&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;();}&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New"'&gt;&lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=""&gt;   &lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;&lt;SPAN STYLE=""&gt;      &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#7f0055'&gt;protected&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt; &lt;/SPAN&gt;&lt;B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#7f0055'&gt;void&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt; throway(){} &lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New"'&gt;&lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;}&lt;/SPAN&gt;&lt;B STYLE=""&gt;&lt;/B&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;B STYLE=""&gt; &lt;/B&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=""&gt;   &lt;B STYLE=""&gt;&lt;SPAN STYLE=""&gt; &lt;/SPAN&gt;&lt;/B&gt;&lt;B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#7f0055'&gt;public&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt; &lt;/SPAN&gt;&lt;B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#7f0055'&gt;class&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt; S &lt;/SPAN&gt;&lt;B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#7f0055'&gt;extends&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt; T {&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New"'&gt;&lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=""&gt;   &lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;&lt;SPAN STYLE=""&gt;      &lt;/SPAN&gt;String &lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#0000c0'&gt;jungle&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;;&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New"'&gt;&lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=""&gt;   &lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;&lt;SPAN STYLE=""&gt;      &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New"'&gt;&lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=""&gt;   &lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;&lt;SPAN STYLE=""&gt;      &lt;/SPAN&gt;S(){&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#7f0055'&gt;super&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;();} &lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#3f7f5f'&gt;//access permitted to T's constructor&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New"'&gt;&lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=""&gt;   &lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;&lt;SPAN STYLE=""&gt;      &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#3f7f5f'&gt;//access to T's member, throway permitted from&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New"'&gt;&lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=""&gt;   &lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;&lt;SPAN STYLE=""&gt;      &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#3f7f5f'&gt;//within this subclass. &lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New"'&gt;&lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=""&gt;   &lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;&lt;SPAN STYLE=""&gt;      &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#7f0055'&gt;void&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt; getFromT(){&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New"'&gt;&lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=""&gt;   &lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;&lt;SPAN STYLE=""&gt;            &lt;/SPAN&gt;throway(); &lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#3f7f5f'&gt;//from T&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New"'&gt;&lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=""&gt;   &lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;&lt;SPAN STYLE=""&gt;            &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#0000c0'&gt;jungle&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt; = &lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#0000c0'&gt;monkey&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;; &lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#3f7f5f'&gt;//monkey from T&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New"'&gt;&lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=""&gt;   &lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;&lt;SPAN STYLE=""&gt;            &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#7f0055'&gt;new&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt; T(); &lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#3f7f5f'&gt;//anonymous class instance creation expression, &lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New"'&gt;&lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=""&gt;   &lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;&lt;SPAN STYLE=""&gt;                        &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:#3f7f5f'&gt;//allowed from protected superclass, T.&lt;SPAN STYLE=""&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New"'&gt;&lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=""&gt;   &lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;&lt;SPAN STYLE=""&gt;      &lt;/SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New"'&gt;&lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=""&gt;   &lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New";COLOR:black'&gt;}&lt;/SPAN&gt;&lt;SPAN STYLE='FONT-SIZE:10pt;FONT-FAMILY:"Courier New"'&gt;&lt;/SPAN&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;B STYLE=""&gt; &lt;/B&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;B STYLE=""&gt;You can make up examples for all other modifiers or study that on the jls. Happy coding. &lt;/B&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;B STYLE=""&gt; &lt;/B&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;B STYLE=""&gt;FULLY QUALIFIED NAMES AND CANONICAL NAMES: &lt;/B&gt;just read the jls. I can’t be rewriting what has already been written down. Redundancy in writing, methinks. &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1in&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-2641949832177344333?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/2641949832177344333/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=2641949832177344333' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/2641949832177344333'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/2641949832177344333'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/names4-meaning-of-packagenames-if.html' title=''/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-6105131785762033896</id><published>2007-04-10T03:54:00.000-07:00</published><updated>2007-07-23T06:13:45.215-07:00</updated><title type='text'></title><content type='html'>&lt;P CLASS=MsoNormal&gt;   &lt;B STYLE=""&gt;NAMES (3)&lt;/B&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;B STYLE=""&gt; &lt;/B&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;B STYLE=""&gt;DETERMINING THE MEANING OF A NAME: &lt;/B&gt;the meaning of a name depends on the context of usage. Name meaning determination requires 3 steps: &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   First step: context causes a name to syntactically fall into 1 of 6 categories of: &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;PackageName &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;TypeName &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;ExpressionName &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;MethodName &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;PackageOrTypeName &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;AmbigousName &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   Second step: if a name is initially categorized as PackageOrTypeName or AmbigousName, it is then reclassified to be either a &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;PackageName &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;TypeName &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;ExpressionName &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   Third step: the resulting category then dictates the final determination of the meaning of the name (or a compilation error if the name has no meaning.) &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   Why use contexts for name determination? To minimize name conflicts between entities of different kinds. &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;B STYLE=""&gt;Syntactic classification of a name according to context: &lt;/B&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   Syntactic classification of PackageName: either in a package declaration or to the left of the dot ‘.’ in a qualified PackageName. &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   Syntactic classification of TypeName: either of the following contexts, &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;in a single-type-import declaration e.g import java.util.Vector &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;to the left of the dot ‘.’ in a single static import declaration, &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.25in&gt;   e.g import static Loader.name; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;to the left of the dot ‘.’ in a static import-on-demand declaration, &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.25in&gt;   e.g import static Loader.*; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;to the left of the “&amp;lt;” in a parameterized type. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;In an actual type argument list of a parameterized type. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;In an explicit actual type argument list in a generic method or constructor invocation &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;In an &lt;I STYLE=""&gt;extends&lt;/I&gt; clause in a type variable declaration. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;In an &lt;I STYLE=""&gt;extends&lt;/I&gt; clause of a wildcard type argument. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;In a &lt;I STYLE=""&gt;super&lt;/I&gt; clause of a wildcard type argument. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;In an &lt;I STYLE=""&gt;extends&lt;/I&gt; clause in a class declaration. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;In an &lt;I STYLE=""&gt;implements&lt;/I&gt; clause in a class declaration. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;In an &lt;I STYLE=""&gt;extends&lt;/I&gt; clause in an interface declaration. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;After the “@” sign in an annotation &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;As a Type in any of the following: &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;1.&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;      &lt;/SPAN&gt;&lt;/SPAN&gt;in a field declaration &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;2.&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;      &lt;/SPAN&gt;&lt;/SPAN&gt;as the result type of a method &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;3.&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;      &lt;/SPAN&gt;&lt;/SPAN&gt;as the type of a formal parameter of a method or constructor &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;4.&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;      &lt;/SPAN&gt;&lt;/SPAN&gt;as the type of an exception that can be thrown by a method or constructor &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;5.&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;      &lt;/SPAN&gt;&lt;/SPAN&gt;as the type of a local variable &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;6.&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;      &lt;/SPAN&gt;&lt;/SPAN&gt;as the type of an exception parameter in a &lt;I STYLE=""&gt;catch&lt;/I&gt; clause of a &lt;I STYLE=""&gt;try&lt;/I&gt; statement. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;7.&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;      &lt;/SPAN&gt;&lt;/SPAN&gt;as the type in a class literal &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;8.&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;      &lt;/SPAN&gt;&lt;/SPAN&gt;as the qualifying type of a qualified &lt;I STYLE=""&gt;this&lt;/I&gt; expression &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;9.&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;      &lt;/SPAN&gt;&lt;/SPAN&gt;as the class type which is to be instantiated in an unqualified class instance creation expression &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;10.&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;  &lt;/SPAN&gt;&lt;/SPAN&gt;as the direct superclass or direct superinterface of an anonymous class which is to be instantiated in an unqualified class instance creation expression. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;11.&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;  &lt;/SPAN&gt;&lt;/SPAN&gt;as the element type of an array to be created in an array creation expression. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;12.&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;  &lt;/SPAN&gt;&lt;/SPAN&gt;as the qualifying type of field access using the keyword &lt;I STYLE=""&gt;super.&lt;/I&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;13.&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;  &lt;/SPAN&gt;&lt;/SPAN&gt;as the qualifying type of a method invocation using the keyword &lt;I STYLE=""&gt;super.&lt;/I&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;14.&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;  &lt;/SPAN&gt;&lt;/SPAN&gt;as the type mentioned in the cast operator of a cast expression. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:1.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;15.&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;  &lt;/SPAN&gt;&lt;/SPAN&gt;as the type that follows the &lt;I STYLE=""&gt;instanceof&lt;/I&gt; relational operator &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   Syntactic classification of ExpressionName: &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;as the qualifying expression in a qualified superclass constructor invocation. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;As the qualifying expression in a qualified class instance creation expression. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;As the array reference expression in an array access expression. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;As a &lt;I STYLE=""&gt;PostfixExpression.&lt;/I&gt; &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;As the left hand operand of an assignment operator. &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   Syntactic classification of a MethodName, &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;before the “(“ in a method invocation expression. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;To the left of the&lt;SPAN STYLE=""&gt;  &lt;/SPAN&gt;“=”&lt;SPAN STYLE=""&gt;  &lt;/SPAN&gt;sign in annotation’s element value pair. &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   Syntactic classificatioin of a PackageOrTypeName, &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;to the left of the “.” in a TypeName &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;in a type-import-on-demand declaration e.g import PackageOrTypeName.*; &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   Syntactic classification of an AmbiguousName, &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;to the left of the “.” in a qualified ExpressionName &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;to the left of the “.” in a qualified MethodName &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;to the left of the “.” in a qualified AmbiguousName &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;in the default value clause of an annotation type element declaration. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;To the right of a&lt;SPAN STYLE=""&gt;  &lt;/SPAN&gt;“=”&lt;SPAN STYLE=""&gt;  &lt;/SPAN&gt;in an element value pair. &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;     &lt;/P&gt; &lt;P CLASS=MsoNormal&gt;   &lt;B STYLE=""&gt;Reclassification of contextually ambiguous names:&lt;/B&gt; &lt;/P&gt; &lt;OL START=1 STYLE=MARGIN-TOP:0in TYPE=1&gt;   &lt;LI CLASS=MsoNormal STYLE=""&gt;     if the AmbiguousName is a simple name, i.e a single identifier   &lt;/LI&gt; &lt;/OL&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;if the appearance of the simple name is within the scope of a local variable, parameter declaration or field declaration, then reclassification as an ExpressionName. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;Otherwise, If a single-static-import declaration or static-import-on-demand declaration declares a field of that name, then reclassified as ExpressionName. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;Otherwise, if the identifier appears within the scope of a top-level class or interface type declaration, a local class declaration or member type declaration with that name, then reclassification as TypeName. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;Otherwise, if a type of that name is declared in a single-type-import declaration, type-import-on-demand declaration, single-static-import declaration or static-import-on-demand declaration, then reclassification of identifier as TypeName. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;Otherwise, reclassification as PackageName which is to be determined against existence. &lt;/P&gt; &lt;OL START=2 STYLE=MARGIN-TOP:0in TYPE=1&gt;   &lt;LI CLASS=MsoNormal STYLE=""&gt;     if AmbiguousName is a qualified name, the name to the left of the dot “.” is first reclassified,   &lt;/LI&gt; &lt;/OL&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;if reclassified as a PackageName, check if a type declaration exists in the package that is similar to the identifier to the right of the “.”, if yes, then qualified name a TypeName, else a PackageName. Check for package existence. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;If reclassified as a TypeName, check if a member or field declaration exists in the class that is similar to the identifier to the right of the “.”, if yes, then qualified name an ExpressionName, else a TypeName. Check for compile time error. &lt;/P&gt; &lt;P CLASS=MsoNormal STYLE=MARGIN-LEFT:0.5in;TEXT-INDENT:-0.25in&gt;   &lt;SPAN STYLE=""&gt;-&lt;SPAN STYLE='FONT-FAMILY:"Times New Roman";FONT-STYLE:normal;FONT-VARIANT:normal;FONT-WEIGHT:normal;FONT-SIZE:7pt;LINE-HEIGHT:normal;font-size-adjust:none;font-stretch:normal'&gt;         &lt;/SPAN&gt;&lt;/SPAN&gt;If reclassified as an ExpressionName, note the type T of the ExpressionName. If the identifier denotes a member or field in the type T, then classify as ExpressionName, else as TypeName if the identifier is a member type of T. check for compile time error. &lt;/P&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-6105131785762033896?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/6105131785762033896/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=6105131785762033896' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/6105131785762033896'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/6105131785762033896'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/names-3-determining-meaning-of-name.html' title=''/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-834943637709563699</id><published>2007-04-10T03:44:00.000-07:00</published><updated>2007-04-10T03:45:26.623-07:00</updated><title type='text'>NAMES (2)</title><content type='html'>NAMES (2)&lt;br /&gt;Shadowing declarations: when a declaration is in scope and visible at a point and another declaration using that name comes into being at the point, we say that the second same-named declaration shadows the first scoped and visible declaration at that point.&lt;br /&gt;&lt;br /&gt;The example in §6.3.1 I believe is quite illustrative if you’ve been following this blog religiously. Questions?&lt;br /&gt;&lt;br /&gt;Obscured declarations: where a simple name may potentially be referring to a variable, type or package, java will chose a variable in preference for a type and a type in preference to a package. Thus, in this situation, it may be impossible to refer to a visible type or package declaration via its simple name. &lt;br /&gt;(Sorry, I tried obscuring in my favorite java compiler and it just keeps refusing my request. Maybe I was doing something wrong. Check yourself. )&lt;br /&gt;&lt;br /&gt;MEMBERS AND INHERITANCE: Packages and reference types have members. &lt;br /&gt;&lt;br /&gt;Members of type variables, parameterized types, raw types and intersection types: treated on earlier blogs. &lt;br /&gt;&lt;br /&gt;Members of a package: the example below summarizes it.&lt;br /&gt;&lt;br /&gt;package api_package;&lt;br /&gt;&lt;br /&gt;//members of api_package are&lt;br /&gt;//all top level class type of api_package&lt;br /&gt;public class T {}&lt;br /&gt;&lt;br /&gt;//all top level interface type of api_package&lt;br /&gt;public interface IT{}&lt;br /&gt;&lt;br /&gt;//all subpackages declared thus&lt;br /&gt;package api_package.anotherpackage;&lt;br /&gt;&lt;br /&gt;//Note: because a member of the package is T no other&lt;br /&gt;//class type or interface type or subpackage which is&lt;br /&gt;//member of this package can be so named!&lt;br /&gt;&lt;br /&gt;The members of a class type: members of a class type are classes, interfaces, fields and methods. Members of a class are one of the following:&lt;br /&gt;- members inherited from its direct superclass (if there is a superclass, otherwise from Object )&lt;br /&gt;- members inherited from any direct superinterfaces&lt;br /&gt;- members declared in the body of the class. &lt;br /&gt;Note: constructors and type variables are not members of a class type. &lt;br /&gt;&lt;br /&gt;package api_package;&lt;br /&gt;&lt;br /&gt;public interface Colors {&lt;br /&gt; int WHITE =0, BLACK = 1;}&lt;br /&gt;&lt;br /&gt;public interface Separates {&lt;br /&gt; int CYAN = 0, MAGENTA =1, YELLOW =2, BLACK =3;}&lt;br /&gt;&lt;br /&gt;//TheClass inherits some fields from implemented interfaces&lt;br /&gt;public class TheClass implements Colors, Separates{&lt;br /&gt; //these are member fields declared&lt;br /&gt; int x,y;&lt;br /&gt; String mobi;&lt;br /&gt; &lt;br /&gt; //this is a member method declared&lt;br /&gt; void setClass(){}&lt;br /&gt; &lt;br /&gt; //another member method declared with same name, setClass&lt;br /&gt; //but different signature, note.the signature of a method&lt;br /&gt; //is the simple name and the parameters of the method. setClass&lt;br /&gt; //is said to be overloaded. &lt;br /&gt; void setClass (int i){&lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //there is no restriction against a field, the String&lt;br /&gt; //above and a method having same simple name, mobi!&lt;br /&gt; void mobi (){}&lt;br /&gt; &lt;br /&gt; //this is a member class declared&lt;br /&gt; class InnerClass{}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class Loader { &lt;br /&gt; public static void main(String[] args){&lt;br /&gt;  //a class can only have two fields with the &lt;br /&gt;  //same simple names if they are declared in different&lt;br /&gt;  //interfaces and inherited, note!&lt;br /&gt;  &lt;br /&gt;  //interface Colors, field BLACK&lt;br /&gt;  System.out.println("TheClass inherits a BLACK field from " &lt;br /&gt;+ "Colors with value: "+Colors.BLACK);&lt;br /&gt;  &lt;br /&gt;  //interface Separates, field BLACK&lt;br /&gt;  System.out.println("TheClass also inherits a BLACK field &lt;br /&gt;from " +"Separates with value: "+Separates.BLACK); &lt;br /&gt; }&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;The members of an interface type: the members of an interface type may be classes, interfaces, fields and methods. Members of an interface are:&lt;br /&gt;- members declared in the interface&lt;br /&gt;- those members inherited from direct superinterfaces&lt;br /&gt;- every interface has an implicit undeclared method that is implemented by Object unless explicitly declared by the interface and if a method m is declared final in Object, no interface can explicitly declare it.&lt;br /&gt;Note: type variables are not members. &lt;br /&gt;&lt;br /&gt;Members of an array type: these section will be discussed in a later blog though, just illustrating with an example. &lt;br /&gt;&lt;br /&gt;package api_package;&lt;br /&gt;&lt;br /&gt;public class Loader { &lt;br /&gt; public static void main(String[] args){&lt;br /&gt;  //aone array declared&lt;br /&gt;  int[] aone = new int[3];&lt;br /&gt;  &lt;br /&gt;  //public final field, length, is a member of an array&lt;br /&gt;  System.out.println("aone array length is: "+aone.length);&lt;br /&gt;  for (int i=0; i&lt;3;i++){&lt;br /&gt;   aone[i]=i;&lt;br /&gt;   System.out.println("Index "+i+" is "+aone[i]);&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  //the public method clone is a member that overrides&lt;br /&gt;  //same method in Object. &lt;br /&gt;  int[] atwo = aone.clone();&lt;br /&gt;  int pun = atwo.length;&lt;br /&gt;  System.out.println("atwo array length is: "+pun);  &lt;br /&gt; }&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-834943637709563699?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/834943637709563699/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=834943637709563699' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/834943637709563699'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/834943637709563699'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/names-2.html' title='NAMES (2)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-8476189728191584458</id><published>2007-04-10T03:40:00.002-07:00</published><updated>2007-04-10T03:41:34.635-07:00</updated><title type='text'>NAMES</title><content type='html'>NAMES&lt;br /&gt;&lt;br /&gt;Introduction: names are used to refer to entities declared in a program. Declared entities are package, class type (normal or enum type), interface type (normal or annotation type), member (class, interface, fields or methods) of a reference type, type parameters (of a class, interface, method or constructor), parameter (to a method, constructor or exception handler) or local variable. &lt;br /&gt;&lt;br /&gt;This chapter discusses on types of names, scope of the declaration that introduces a name, members of entities such as package and reference types, and access control modifiers for the members of named entities. &lt;br /&gt;&lt;br /&gt;The uses and meanings of names are also discussed. &lt;br /&gt;&lt;br /&gt;Declaration: (these section should be retained as referential; most of the entities have already been discussed in blogs before this). A declaration introduces an entity into a program and it includes an identifier that can be used in a name to refer to this entity. A declared entity is one of the following:&lt;br /&gt;&lt;br /&gt;1. a package, declared in a package declaration&lt;br /&gt;2. an imported type, declared in a single-type-import declaration or a type-import-on-demand declaration. &lt;br /&gt;3. a class, declared in a class type declaration. &lt;br /&gt;4. a type variable, declared in a formal type parameter of a generic class, interface, method or constructor. &lt;br /&gt;5. a member of a reference type, one of the following:&lt;br /&gt;- a member class&lt;br /&gt;- a member interface&lt;br /&gt;- an enum constant&lt;br /&gt;- a field, one of the following, &lt;br /&gt;o a field declared in a class type&lt;br /&gt;o a constant field declared in an interface type&lt;br /&gt;o the field length which is implicitly a member of every array type&lt;br /&gt;- a method, one of the following,&lt;br /&gt;o a method (abstract or others) declared in a class type&lt;br /&gt;o a method (always abstract) declared in an interface type&lt;br /&gt;6. a parameter, one of the following,&lt;br /&gt;- a parameter of a method or constructor of a class. &lt;br /&gt;- a parameter of an abstract method of an interface&lt;br /&gt;- a parameter of an exception handler declared in a catch clause of a try statement. &lt;br /&gt;7. a local variable, one of the following,&lt;br /&gt;- a local variable declared in a block&lt;br /&gt;- a local variable declared in a for statement. &lt;br /&gt;&lt;br /&gt;Note: constructors are also introduced by declarations, but use the name of the class in which they are declared rather than introducing a new name. &lt;br /&gt;&lt;br /&gt;Names and identifiers:&lt;br /&gt;&lt;br /&gt;First take it to heart that every name is an identifier but not all identifiers are names. &lt;br /&gt;Where an identifier is also a name:&lt;br /&gt;1. when the reference is to an entity declared in a program. These names can be simple names i.e single identifiers, or qualified names i.e a name with a ‘.’ token followed by an identifier. &lt;br /&gt;Rules for determining the meaning of names will be in a later blog. &lt;br /&gt;Where reference is not to an entity, then an identifier is not a name. identifiers that are not names are:&lt;br /&gt;a. field acess expressions. &lt;br /&gt;b. Method invocation expressions&lt;br /&gt;c. In qualified class instance creation expressions. &lt;br /&gt;d. As labels in labeled statements and in break and continue statements that refer to statement labels. &lt;br /&gt;&lt;br /&gt;package api_package;&lt;br /&gt;&lt;br /&gt;//we'll use a simple example here&lt;br /&gt;//Loader is a name, refers to an entity&lt;br /&gt;public class Loader {&lt;br /&gt; String name; //name is also a name, entity variable&lt;br /&gt; &lt;br /&gt; Loader(String givenname){&lt;br /&gt;  this.name=givenname;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; int ageCounter(int anynumber){ //listPosition is a name&lt;br /&gt;  return anynumber*2;&lt;br /&gt; }&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  //create an instance of Loader&lt;br /&gt;  //the qualified class instance creation expression&lt;br /&gt;  //is an identifier&lt;br /&gt;  Loader ourman = new api_package.Loader("Koro"); &lt;br /&gt;  &lt;br /&gt;  //method invocation expression is an identifier&lt;br /&gt;  int guessedage = ourman.ageCounter(15);&lt;br /&gt;  &lt;br /&gt;  //we'll guess Koro's age&lt;br /&gt;  //the field access expression is identifier&lt;br /&gt;  System.out.print("This man "+ourman.name); //field access&lt;br /&gt;  System.out.print(" is really unbelievable for someone");&lt;br /&gt;  System.out.println(" above "+guessedage+" years.");  &lt;br /&gt; } &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Scope of a declaration: the scope of a declaration is the region of a program within which the entity declared by the declaration can be referred to using a simple name(provided it is visible). A declaration is in scope at a particular point in a program if and only if the declaration’s scope includes that point. &lt;br /&gt;&lt;br /&gt;Examples: &lt;br /&gt;//api_package package is declared here, scope starts here&lt;br /&gt;//and is observable here. scope ends on completion of every&lt;br /&gt;//compilation unit in this package ends &lt;br /&gt;package api_package;&lt;br /&gt;&lt;br /&gt;//import declaration here, scope starts here, global type import&lt;br /&gt;import java.io.Serializable;&lt;br /&gt;&lt;br /&gt;public class Loader {&lt;br /&gt; //scope of String type starts with its declaration here&lt;br /&gt; //member scopesearcher has scope that is global, i.e in the&lt;br /&gt; //entire body of class Loader&lt;br /&gt; String scopesearcher; &lt;br /&gt; &lt;br /&gt; //scope of parameter, expression is confined to the &lt;br /&gt; //body of the method, setSearcher&lt;br /&gt; void setSearcher(String expression){&lt;br /&gt;  try {&lt;br /&gt;   scopesearcher = expression;&lt;br /&gt;   //scope of myindex, local variable, starts from here&lt;br /&gt;   //to the end of this block&lt;br /&gt;   Integer myindex = 2;&lt;br /&gt;  &lt;br /&gt;  //scope of n, exception handler parameter, is the entire catch clause block.&lt;br /&gt;  }catch (NumberFormatException n) {&lt;br /&gt;   &lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //scope of type parameter, T&lt;Integer&gt; in matchCase&lt;br /&gt; //is the entire declaration of the method, and the &lt;br /&gt; //type parameter's section itself.&lt;br /&gt; void matchCase(T&lt;Integer&gt; givennumber){&lt;br /&gt;  &lt;br /&gt;  //scope of Forinit part, i.e i, includes the statements in&lt;br /&gt;  //parenthesis and the statements enclosed in the block. &lt;br /&gt;  //ends on block’s end therefore i can still be used&lt;br /&gt;  //outside the for statement. &lt;br /&gt;  for (int i=0; i&lt;34; i++){&lt;br /&gt;   System.out.println(i);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //scope of HelpLoad, a local class, starts with its declaration&lt;br /&gt; //to the end of the immediately onclosed block.&lt;br /&gt; class HelpLoad{&lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  } &lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-8476189728191584458?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/8476189728191584458/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=8476189728191584458' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/8476189728191584458'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/8476189728191584458'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/names.html' title='NAMES'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-546839820376146383</id><published>2007-04-10T03:40:00.001-07:00</published><updated>2007-04-10T03:40:38.598-07:00</updated><title type='text'>CONVERSIONS AND PROMOTIONS(4)</title><content type='html'>CONVERSIONS AND PROMOTIONS(4)&lt;br /&gt;&lt;br /&gt;Assignment Conversions:  assignment conversions occur when the value of an expression is assigned to a variable; the type of the expression must be converted to the type of the variable. &lt;br /&gt;&lt;br /&gt;(as always, read the relevant sections of the jls, it’ll do u lots of good.)&lt;br /&gt;&lt;br /&gt;public class Loader {&lt;br /&gt; //note constants.&lt;br /&gt; static byte first = 125;&lt;br /&gt; static short second = 126;&lt;br /&gt; static int fourth;&lt;br /&gt; &lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  //assignment expression, by value.&lt;br /&gt;  fourth = first; //here, a widening primitive&lt;br /&gt;  &lt;br /&gt;  //boxing conversion&lt;br /&gt;  Integer boxer = fourth; &lt;br /&gt;  System.out.println("value of boxer is: "+boxer);&lt;br /&gt;  &lt;br /&gt;  //take the short constant, do narrowing primitive&lt;br /&gt;  //and then box it for an assignment conversion. if &lt;br /&gt;  //our short was outside byte range, it'll overflow&lt;br /&gt;  Byte firstbyte = (first = (byte)second );&lt;br /&gt;  System.out.println("Value of firstbyte is: "+firstbyte);&lt;br /&gt;  &lt;br /&gt;  //therefore we can say the expressions above are &lt;br /&gt;  //assignable to the variables on the left by assignment&lt;br /&gt;  //conversion or assignment compatible&lt;br /&gt; } &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;We’ve been doing assignment conversions since we encountered variables. This’ easy, right?&lt;br /&gt;&lt;br /&gt;Method invocation expression: method invocation expression is applied to each argument value in a method or constructor invocation; the type of the argument expression must be converted to the type of the corresponding parameter. &lt;br /&gt;&lt;br /&gt;public class Loader {&lt;br /&gt; //first expression is constant, note.&lt;br /&gt; static byte first = 125;&lt;br /&gt; static short second = 126;&lt;br /&gt; static int fourth;&lt;br /&gt; &lt;br /&gt; void addSum(int thevar){&lt;br /&gt;  System.out.println("The sum is: "+thevar*2);&lt;br /&gt; }&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  //method invocation conversion by identity conversion&lt;br /&gt;  Loader pupil = new Loader(); &lt;br /&gt;  &lt;br /&gt;  //identity conversion&lt;br /&gt;  pupil.addSum(fourth);&lt;br /&gt;  &lt;br /&gt;  //widening primitive conversion, short to int&lt;br /&gt;  pupil.addSum(second);  &lt;br /&gt; } &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Cough up examples of your own. Exciting!&lt;br /&gt;&lt;br /&gt;String conversions: string conversions are effected on operands of binary operations when one of the arguments is a String. The other argument is converted to a String and a new String object, which is the concatenation of the 2 strings is the result of the operator +. &lt;br /&gt;&lt;br /&gt;Casting conversion: casting conversion is applied to the operand of a cast operator; the integer of the operand expression must be converted to the type explicitly named by the cast operator. &lt;br /&gt;&lt;br /&gt;public class Loader {&lt;br /&gt; static Short i;&lt;br /&gt; static Integer var;&lt;br /&gt; &lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  S pss = new S();&lt;br /&gt;  T tee = new T();&lt;br /&gt;  //cast from S to T correct since S subclass&lt;br /&gt;  //of T. &lt;br /&gt;  tee = (T)pss;&lt;br /&gt;  //type from S to parameterized type T is correct&lt;br /&gt;  //but will be checked against erasure.&lt;br /&gt;  T&lt;Integer&gt; mute = (T&lt;Integer&gt;)pss;&lt;br /&gt; } &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The principles explained in detail in this section, §5.5 have been touched before except for arrays. &lt;br /&gt;&lt;br /&gt;Numeric promotions: numeric promotions are applied to the operands of an arithmetic operator. Identity conversion, widening primitive conversion or an unboxing conversion can be used in numeric promotions. &lt;br /&gt;&lt;br /&gt;Usage: used to convert the operands of a numeric operator to a common type so that an operation can be carried out. &lt;br /&gt;&lt;br /&gt;Types: a. unary numeric promotion, b. binary numeric promotion. &lt;br /&gt;&lt;br /&gt;A. UNARY PROMOTION:&lt;br /&gt;&lt;br /&gt;Note: &lt;br /&gt;&lt;br /&gt;1. in unary promotion, if the operand is of type Byte, Short, Character or Integer, it is unboxed and then promoted to type int by widening conversion or an identity conversion, else if byte, short, char, promotion to int is immediately carried out. &lt;br /&gt;&lt;br /&gt;2. if the operand is of type Long, Float or Double, they are unboxed first and primitive type used. Value set conversion is next applied. &lt;br /&gt;&lt;br /&gt;3. else the operand is left as-is. &lt;br /&gt;&lt;br /&gt;Examples of expressions where unary promotion can be applied:&lt;br /&gt;&lt;br /&gt;public class Loader {&lt;br /&gt; &lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  byte b = 2;&lt;br /&gt;  int[] a = new int[b];//dimension expression promotion&lt;br /&gt;  char c = '\u0001';&lt;br /&gt;  a[c] = 1; //index expression promotion&lt;br /&gt;  a[0] = -c; //unary promotion&lt;br /&gt;  System.out.println("a: "+a[0]+" , "+a[1]);&lt;br /&gt;  b = -1;&lt;br /&gt;  int i = ~b; //bitwise complement promotion&lt;br /&gt;  System.out.println("~0x"+Integer.toHexString(b)&lt;br /&gt;    +"==0x"+Integer.toHexString(i));&lt;br /&gt;  i = b&lt;&lt;4L; //shift promotion, left operand&lt;br /&gt;  System.out.println("0x"+Integer.toHexString(b)&lt;br /&gt;    +"&lt;&lt;4L==0x"+Integer.toHexString(i)); &lt;br /&gt; } &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;B. BINARY  NUMERIC PROMOTION: in binary numeric promotion, for a pair of operands, note that each of the operands must denote a value that is convertible to a numeric type. In binary numeric promotions, the following rules are applied, in order, using widening conversions:&lt;br /&gt;- if any of the operands is of a reference type, unboxing conversion is performed then&lt;br /&gt;- if either operand is of type double, then other is converted to double&lt;br /&gt;- otherwise, if either operand is of type float, the other is converted to float.&lt;br /&gt;- otherwise, if either is of type long, the other is converted to long&lt;br /&gt;- otherwise, both operands are converted to type int. &lt;br /&gt;After type conversion, value set conversion is applied to each operand. &lt;br /&gt;&lt;br /&gt;Examples from the jls:&lt;br /&gt;&lt;br /&gt;public class Loader {&lt;br /&gt; &lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  int i = 0;&lt;br /&gt;  float f = 1.0f;&lt;br /&gt;  double d = 2.0;&lt;br /&gt;  //first int*float is promoted to float then&lt;br /&gt;  //float is promoted to double for double==double&lt;br /&gt;  if (i*f == d){System.out.println("oops!");}&lt;br /&gt;  else {System.out.println("correct maths!");}&lt;br /&gt;  &lt;br /&gt;  //c&amp;b is promoted to int&amp;int&lt;br /&gt;  byte b = 0x1f;&lt;br /&gt;  char c = 'G'; //numeric value is 7&lt;br /&gt;  int control = c &amp; b;&lt;br /&gt;  System.out.println(Integer.toHexString(control));&lt;br /&gt;  &lt;br /&gt;  //int:float is promoted to float:float&lt;br /&gt;  f = (b==0)? i : 4.0f;&lt;br /&gt;  System.out.println(1.0/f);&lt;br /&gt; } &lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-546839820376146383?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/546839820376146383/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=546839820376146383' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/546839820376146383'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/546839820376146383'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/conversions-and-promotions4.html' title='CONVERSIONS AND PROMOTIONS(4)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-8623982783619582382</id><published>2007-04-10T03:38:00.000-07:00</published><updated>2007-04-10T03:39:48.193-07:00</updated><title type='text'>CONVERSIONS AND PROMOTIONS(3)</title><content type='html'>CONVERSIONS AND PROMOTIONS(3)&lt;br /&gt;&lt;br /&gt;(Kinds of conversions):&lt;br /&gt;&lt;br /&gt;7. BOXING CONVERSIONS:  boxing conversions converts values of positive types to corresponding values of reference types. &lt;br /&gt;- from type boolean to type Boolean&lt;br /&gt;- from type byte to type Byte&lt;br /&gt;- from type char to type Character&lt;br /&gt;- from type short to type Short&lt;br /&gt;- from type int to type Integer&lt;br /&gt;- from type long to type Long&lt;br /&gt;- from type float to type Float&lt;br /&gt;- from type double to type Double&lt;br /&gt;&lt;br /&gt;public class Loader {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  //boxing from boolean to Boolean!&lt;br /&gt;  boolean p = true; &lt;br /&gt;  Boolean p2 = p;&lt;br /&gt;  System.out.print("According to the jls, ps is: ");&lt;br /&gt;  System.out.println(p2.booleanValue()); &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;8. UNBOXING CONVERSIONS: this is BOXING CONVERSIONS the other way round. Note that a type is said to be convertible to a numeric type if it is a numeric type, or it is a reference type that may be converted to a numeric type by unboxing conversions. A type is said to be convertible to an integral type if it is an integral type, or it is a reference type that may be converted to an integral type by unboxing conversion. &lt;br /&gt;&lt;br /&gt;9. UNCHECKED CONVERSION: if G is a parameterized type with n type parameters. There is an unchecked  conversion from the raw type G to any parameterized type of the form G&lt;T1…Tn&gt;. A mandatory compile-time warning is generated in unchecked conversions. &lt;br /&gt;&lt;br /&gt;public class Loader {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  S pss = new S();&lt;br /&gt;  S&lt;String&gt; maggie = pss;&lt;br /&gt; } &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;10. CAPTURE CONVERSION: (sorry, my compiler does not allow wildcard parameters so at a loss on how to express this section. Will look for a way around this though.)&lt;br /&gt;&lt;br /&gt;11. STRING CONVERSIONS: a string conversion to type String from every other type exists, including the null type. &lt;br /&gt;&lt;br /&gt;12. FORBIDDEN CONVERSIONS: any non-explicitly allowed conversion is forbidden. &lt;br /&gt;&lt;br /&gt;13. VALUE SET CONVERSION: value set conversion is the  process of mapping a floating-point value from one value set to another without changing its type. Value set conversion occurs within expressions that are either or not FP-strict[1].&lt;br /&gt;&lt;br /&gt;If an expression is FP-strict, the value set conversion must be within the float or double value set, to the nearest element, and may result in underflow or overflow. &lt;br /&gt;&lt;br /&gt;If an expression is not FP-strict, the java programming language has optional value set conversion choices for implementation of the expression. &lt;br /&gt;1. if the value is within the the float-extended-exponent value set, the implementation may optionally be to the nearest element of the float value set. &lt;br /&gt;2. if the element is of the double-extended-exponent value set, then the implementation may optionally map the value to the nearest element of the double value set. &lt;br /&gt; &lt;br /&gt;&lt;br /&gt;[1]. FP-strict expressions: these are expressions that are either 1, compile-time constant expressions , or b, if  not the above then they must bear a strictfp modifier in its declaration. All FP-strict expressions provide intermediate values that lie within the floating-point value set.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-8623982783619582382?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/8623982783619582382/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=8623982783619582382' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/8623982783619582382'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/8623982783619582382'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/conversions-and-promotions3.html' title='CONVERSIONS AND PROMOTIONS(3)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-7578372017756163954</id><published>2007-04-10T03:29:00.000-07:00</published><updated>2007-04-10T03:34:27.092-07:00</updated><title type='text'>CONVERSIONS AND PROMOTIONS(2)</title><content type='html'>CONVERSIONS AND PROMOTIONS(2)&lt;br /&gt;&lt;br /&gt;Kinds of conversions:&lt;br /&gt;&lt;br /&gt;1. IDENTITY CONVERSIONS: these are conversions from a type to that same type. Although seemingly trivial, this has 2 practical considerations:&lt;br /&gt;a. to begin with, to ensure desired expression typing&lt;br /&gt;b. implies that programs are permitted to include redundant cast operations for clarity’s sake. &lt;br /&gt; &lt;br /&gt;2. WIDENING PRIMITIVE CONVERSION: examples are:&lt;br /&gt;- byte to short, int, long, float or double&lt;br /&gt;- short to int, long, float or double&lt;br /&gt;- char to int, long, float or double&lt;br /&gt;- int to long, float or double&lt;br /&gt;- long to float or double&lt;br /&gt;- float to double&lt;br /&gt;&lt;br /&gt;public class WideningPrimitive {&lt;br /&gt; //variables that will engage in widening conversion&lt;br /&gt; static byte first;&lt;br /&gt; short second;&lt;br /&gt; char third;&lt;br /&gt; static int fourth;&lt;br /&gt; long fifth;&lt;br /&gt; static float sixth;&lt;br /&gt; double seventh;&lt;br /&gt; &lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  //a.widening primitive conversions do not&lt;br /&gt;  //lose info about the overall magnitude of a &lt;br /&gt;  //numeric value&lt;br /&gt;  first =120;&lt;br /&gt;  fourth = first;&lt;br /&gt;  System.out.print("from byte to int conversion gives: ");&lt;br /&gt;  System.out.println(fourth);&lt;br /&gt;  &lt;br /&gt;  //int to float or double may lose precision in the&lt;br /&gt;  //least significant bit&lt;br /&gt;  fourth = 1234567890;&lt;br /&gt;  sixth = fourth;&lt;br /&gt;  //we should have a zero here.&lt;br /&gt;  System.out.print&lt;br /&gt;   ("Subtracting same values though different types &lt;br /&gt;gives: ");&lt;br /&gt;  System.out.println(fourth - (int)sixth);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;3. NARROWING PRIMITIVE CONVERSIONS: &lt;br /&gt;- short to byte or char&lt;br /&gt;- char to byte or short&lt;br /&gt;- int to byte, short or char&lt;br /&gt;- long to byte, short, char or int&lt;br /&gt;- float to byte, short, char, int, or long&lt;br /&gt;- double to byte, short, char, int, long or float. &lt;br /&gt;&lt;br /&gt;public class NarrowingPrimitive {&lt;br /&gt; // variables for narrowing conversion&lt;br /&gt; static byte first;&lt;br /&gt; static short second;&lt;br /&gt; static char third;&lt;br /&gt; static int fourth;&lt;br /&gt; static long fifth;&lt;br /&gt; static float sixth;&lt;br /&gt; double seventh;&lt;br /&gt; &lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  //narrowing conversion loses magnitude and precision&lt;br /&gt;  fifth = +987654321;&lt;br /&gt;  second = (short)fifth;&lt;br /&gt;  System.out.println("The original, "+fifth+" and the converted, "+second); &lt;br /&gt;  &lt;br /&gt;  third = '\u0098';&lt;br /&gt;  second = (short)third; &lt;br /&gt;  System.out.print("Narrowing a char, "+third+" to a short "+second);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;4. WIDENING AND NARROWING PRIMITIVE CONVERSIONS:&lt;br /&gt;- byte to char&lt;br /&gt;This involve two steps, a widening conversion to int and then a narrowing to char. &lt;br /&gt;&lt;br /&gt;5. WIDENING REFERENCE CONVERSIONS:  widening reference conversions exist for any typye S to any type T, provided S is a subtype of T. &lt;br /&gt;&lt;br /&gt;6. NARROWING REFERENCE CONVERSIONS: narrowing reference conversions consists of the following:&lt;br /&gt;- from any type S to any reference type T, provided S is a proper supertype of T (special case: the narrowing conversion from the class type Object to any other reference type.)&lt;br /&gt;&lt;br /&gt;public class S {}&lt;br /&gt;&lt;br /&gt;public class T extends S {}&lt;br /&gt;&lt;br /&gt;public class Loader {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  S pss = new S();&lt;br /&gt;  T tss = new T();&lt;br /&gt;  tss = (T)pss;  //to prevent run-time error, &lt;br /&gt;      //explicit casting done  &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;- from any class type C to any non-parameterized interface type K, provided C is not final and does not implement K. &lt;br /&gt;&lt;br /&gt;public class S {}&lt;br /&gt;&lt;br /&gt;public interface K {}&lt;br /&gt;&lt;br /&gt;public class Loader {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  S pss = new S();&lt;br /&gt;  K mokay = (K)pss; &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;- from any interface type J to any non-parameterised class type C that is not final. &lt;br /&gt;&lt;br /&gt;public class Loader {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  //this is the above example other way round&lt;br /&gt;  K mokay = null;&lt;br /&gt;  S pss = (S)mokay;  &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;- from the interface type Cloneable or java.io.serializable to any other type T[]. &lt;br /&gt;- from any interface type J to any non-parameterized interface type K, provided that J is not a subinterface of K. &lt;br /&gt;&lt;br /&gt;public class Loader {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  //where K and J are interface types&lt;br /&gt;  K mikay = null;&lt;br /&gt;  J jeekay = (J)mikay;&lt;br /&gt; }&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;- from any array type S[] to any array type T[] provided that S and T are reference types and there is a narrowing conversion from S to T. &lt;br /&gt;&lt;br /&gt;public class Loader {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  //where S[] and T[] are arrays of reference types&lt;br /&gt;  //S and T.&lt;br /&gt;  S[] pss = new S[1];&lt;br /&gt;  T[] tee = new T[1];&lt;br /&gt;  tee[0] = (T)pss[0]; //first components pls.&lt;br /&gt; }&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-7578372017756163954?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/7578372017756163954/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=7578372017756163954' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/7578372017756163954'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/7578372017756163954'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/04/conversions-and-promotions2.html' title='CONVERSIONS AND PROMOTIONS(2)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-6979202515694273135</id><published>2007-03-30T04:57:00.000-07:00</published><updated>2007-03-30T04:58:04.411-07:00</updated><title type='text'>CONVERSIONS AND PROMOTIONS</title><content type='html'>CONVERSIONS AND PROMOTIONS&lt;br /&gt;&lt;br /&gt;INTRODUCTION:&lt;br /&gt;Type conversion is a facility in the java programming language whereby expressions whose type is not appropriately specified in a context can be implicitly converted from the type specified by the programmer to a type acceptable for its surrounding context. &lt;br /&gt;&lt;br /&gt;A specific type conversion can also be asked for by a programmer. There is need for this in some cases:&lt;br /&gt;a. to cause the java machine at run-time[1] to check for the validity of the conversion. &lt;br /&gt;b. to cause a translation of the run-time value of the expression into a form appropriate for the new type. &lt;br /&gt;&lt;br /&gt;The possible set of specific conversions in the java programming language are grouped into several broad categories:&lt;br /&gt;- identity conversion&lt;br /&gt;- widening primitive conversion&lt;br /&gt;- narrowing primitive conversion&lt;br /&gt;- widening reference conversion&lt;br /&gt;- narrowing reference conversion&lt;br /&gt;- boxing conversion&lt;br /&gt;- unboxing conversion&lt;br /&gt;- capture conversion&lt;br /&gt;- String conversion&lt;br /&gt;- Value set conversion&lt;br /&gt;&lt;br /&gt;There are in addition 5 conversion contexts in which the conversion of expressions may occur. Each context allows conversion in some categories noted above but not in others. &lt;br /&gt;&lt;br /&gt;Note that the term “conversion” is also used to describe the process of choosing a specific conversion for such a context. The 5 conversion contexts are:&lt;br /&gt;- Assignment conversion: converts the type of an expression to the type of a specified variable. &lt;br /&gt;- Method invocation conversion:  this is applied to each argument in a method or constructor invocation and except in one case, performs the same conversion that assignment conversion does. &lt;br /&gt;- Casting conversion: converts the type of an expression to the type explicitly specified by a cast operator&lt;br /&gt;- String conversion: allows any type to be converted to type String&lt;br /&gt;- Numeric promotion: brings the operands of a numeric operator to a common type so that ann operation can be performed. &lt;br /&gt;&lt;br /&gt;(§5.1 of the jls has an example for the conversions above that I do not want to repeat. You can get it and study. )&lt;br /&gt;&lt;br /&gt;Footers:&lt;br /&gt;&lt;br /&gt;[1]. A run-time type refers to the classes of the object referred to by the value of the variable or expression at run-time, assuming that the value is not null.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-6979202515694273135?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/6979202515694273135/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=6979202515694273135' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/6979202515694273135'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/6979202515694273135'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/03/conversions-and-promotions.html' title='CONVERSIONS AND PROMOTIONS'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-5628452265383708930</id><published>2007-03-30T04:56:00.000-07:00</published><updated>2007-03-30T04:57:00.690-07:00</updated><title type='text'>TYPES, VALUES AND VARIABLES(11)</title><content type='html'>TYPES, VALUES AND VARIABLES(11)&lt;br /&gt;&lt;br /&gt;KINDS OF VARIABLES:&lt;br /&gt;6. Exception handler parameter: an exception handler parameter is created each time an exception is caught by the catch clause of a try statement. The new variable is initialized with the actual object associated with the exception. The exception handler parameter ceases to exist when execution of the block associated with the catch clause is complete. &lt;br /&gt;&lt;br /&gt;public class ExceptionHandler {&lt;br /&gt; String name;&lt;br /&gt; &lt;br /&gt; void writeName(String typed){&lt;br /&gt;  &lt;br /&gt;  try{&lt;br /&gt;   name = typed;  &lt;br /&gt;  }&lt;br /&gt;  //exception handler created here. variable of&lt;br /&gt;  //type NumberFormatException&lt;br /&gt;  catch (NumberFormatException n){&lt;br /&gt;   System.out.println("Wrong entry, please.");&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;7. Local Variable: is declared by a local variable declaration statement. When the flow of control enters a block or for statement, a new variable is created for each local variable declared in a local variable declaration statement immediately contained in a block or for statement. &lt;br /&gt;&lt;br /&gt;A local variable declaration statement may contain an expression which initializes the variable. The local variable with an initializing expression is not initialized however until the local variable declaration statement that declares it is executed. The local variable effectively ceases to exist when the execution of the block or for statement is complete. &lt;br /&gt;&lt;br /&gt;public class ArrayComponents {&lt;br /&gt; //an array of integers as components&lt;br /&gt;  int[] five = new int[5];&lt;br /&gt; &lt;br /&gt; //this method takes all the default values&lt;br /&gt; //according to jls, 0 and prints them out. &lt;br /&gt; void defaultvalue(){ //local variable declaration block&lt;br /&gt;  for (int i=0;i&lt;5;i++ ){  //new variable i, for statement&lt;br /&gt;   System.out.print("The ");&lt;br /&gt;   switch(i){&lt;br /&gt;   case(0): System.out.print("first ");break;&lt;br /&gt;   case(1): System.out.print("second ");break;&lt;br /&gt;   case(2): System.out.print("third ");break;&lt;br /&gt;   case(3): System.out.print("fourth ");break;&lt;br /&gt;   case(4): System.out.print("fifth ");break;&lt;br /&gt;   default: ;break;&lt;br /&gt;   }&lt;br /&gt;   System.out.println("value is: "+five[i]);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Final Variables: a variable declared final may be assigned to only once. Never assign a once assigned final variable unless it has been unassigned prior to this. &lt;br /&gt;A blank final is a final variable without an initializer in its declaration. &lt;br /&gt;A final variable referring an object refers only to the object which returns its value. See example. &lt;br /&gt;public class FinalExample {&lt;br /&gt; static String bobby = "friend";&lt;br /&gt; static final String drumboy = bobby; //refers to object&lt;br /&gt; &lt;br /&gt; public static void main(String[] args){&lt;br /&gt;  System.out.println("Final drumboy is: "+drumboy);&lt;br /&gt;  &lt;br /&gt;  //let's change the object&lt;br /&gt;  bobby = "enemy";&lt;br /&gt;  &lt;br /&gt;  //but final will still refer to the first object&lt;br /&gt;  //you see why final is very useful?&lt;br /&gt;  System.out.print("Final drumboy after object reference change is: ");&lt;br /&gt;  System.out.println(drumboy);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Initial values of variables:&lt;br /&gt;Every variable in a program must have a value before usage. &lt;br /&gt;1. each class variable, instance variable, or array component is initialized with a default value when it is created. &lt;br /&gt;- for type byte, the default is zero, (byte)0&lt;br /&gt;- for type short, (short)0&lt;br /&gt;- for type int, 0&lt;br /&gt;- for type long, default is 0L&lt;br /&gt;- for type float, default is positive zero, 0.0f&lt;br /&gt;- for type double, default is positive zero, 0.0d&lt;br /&gt;- for type char, the default value is the null character, i.e ‘\u0000’&lt;br /&gt;2. each method parameter is initialized to the corresponding argument value provided by the invoker of the method&lt;br /&gt;3. each constructor parameter is initialized to the corresponding argument value provided by a class instance creation expression or explicit constructor invocation.&lt;br /&gt;4. an exception-handler parameter is initialized to the thrown object representing the exception.&lt;br /&gt;5. a local variable must be explicitly given a value before use, either by initialization or assignment, in a compiler verifiable way using the rules for definite assignment.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-5628452265383708930?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/5628452265383708930/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=5628452265383708930' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/5628452265383708930'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/5628452265383708930'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/03/types-values-and-variables11.html' title='TYPES, VALUES AND VARIABLES(11)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-3560123482094558028</id><published>2007-03-30T04:54:00.000-07:00</published><updated>2007-03-30T04:55:02.431-07:00</updated><title type='text'>TYPES, VALUES AND VARIABLES(10)</title><content type='html'>TYPES, VALUES AND VARIABLES(10)&lt;br /&gt;&lt;br /&gt;Heap pollution: When the possibility exists that a variable of a parameterized type refers to an object that is not of that parameterized type. Heap pollution can only occur if the program performed some operation that would give rise to an unchecked warning at compile time. &lt;br /&gt;&lt;br /&gt;KINDS OF VARIABLES:&lt;br /&gt;There are 7 kinds of variables:&lt;br /&gt;1. class variables: in a class declaration a field is declared using the keyword static ; in an interface declaration, the field can be with(out) the keyword static.&lt;br /&gt;Creation of class variables: when the class or interface is prepared and then initialized to a default value. &lt;br /&gt;&lt;br /&gt;public class ClassVar {&lt;br /&gt; //primitive and reference class variables prepared &lt;br /&gt; static int number;&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  //they are now initialised, after initialisation&lt;br /&gt;  //you've created a class variable&lt;br /&gt;  number = 24;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt; 2. Instance variables: an instance variable is a field declared in a class declaration without the keyword static. When instance variables occur in a class are created and initialized to a default value on the creation of a new object of the class or of any class that subclasses the class. An instance variable effectively ceases to exist when the object of which it is a field is no longer referenced, after any necessary object finalization[1] has been completed.  &lt;br /&gt;&lt;br /&gt;public class InstanceVar {&lt;br /&gt; //primitive and reference class variables prepared &lt;br /&gt; static int number;&lt;br /&gt; &lt;br /&gt; //an instanc variable next&lt;br /&gt; boolean monkey_tail; //default is false a la jls.&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class Loader {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  //create an object of InstanceVar&lt;br /&gt;  InstanceVar mine = new InstanceVar();&lt;br /&gt;  &lt;br /&gt;  //you'll realise that even without initialising&lt;br /&gt;  //it it is given default false&lt;br /&gt;  System.out.println(mine.monkey_tail);&lt;br /&gt;  &lt;br /&gt;  //we can still assign it though&lt;br /&gt;  mine.monkey_tail = true;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;3. Array components: these are unnamed variables that are created and initialized to default values whenever a new object that is an array is created. The array component effectively ceases to exist when the array is no longer referenced. &lt;br /&gt;&lt;br /&gt;public class ArrayComponents {&lt;br /&gt; //an array of integers as components&lt;br /&gt;  int[] five = new int[5];&lt;br /&gt; &lt;br /&gt; //this method takes all the default values&lt;br /&gt; //according to jls, 0 and prints them out. &lt;br /&gt; void defaultvalue(){&lt;br /&gt;  for (int i=0;i&lt;5;i++ ){&lt;br /&gt;   System.out.print("The ");&lt;br /&gt;   switch(i){&lt;br /&gt;   case(0): System.out.print("first ");break;&lt;br /&gt;   case(1): System.out.print("second ");break;&lt;br /&gt;   case(2): System.out.print("third ");break;&lt;br /&gt;   case(3): System.out.print("fourth ");break;&lt;br /&gt;   case(4): System.out.print("fifth ");break;&lt;br /&gt;   default: ;break;&lt;br /&gt;   }&lt;br /&gt;   System.out.println("value is: "+five[i]);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;public class Loader {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  ArrayComponents details = new ArrayComponents();&lt;br /&gt;  details.defaultvalue();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;4. Method parameters: method parameters name argument values passed to a method. For every parameter declaration in a method declaration, a new variable is created each time that method is invoked, which is initialized with the corresponding argument value from the method invocation. The method parameter ceases to exist when the execution of the body of the method is complete. &lt;br /&gt;&lt;br /&gt;public class MethodExample {&lt;br /&gt; String id;&lt;br /&gt; int tag;&lt;br /&gt; &lt;br /&gt; //this method takes as parameters a String name&lt;br /&gt; //and an integer as number. &lt;br /&gt; void setName(String name, int number){&lt;br /&gt;  this.id=name;&lt;br /&gt;  this.tag=number;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;public class Loader {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  MethodExample taketwo = new MethodExample();&lt;br /&gt;  &lt;br /&gt;  //method invocation. this passes the required&lt;br /&gt;  //arguments specified by the method parameter.&lt;br /&gt;  taketwo.setName("adewale", 42); &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;5. Constructor parameters: constructor parameters name argument values passed to a constructor. Each time a class instance expression or explicit constructor invocation invokes a constructor, a new parameter variable is created and initialized with the corresponding argument value from the creation expression or constructor invocation. The constructor parameter effectively ceases to exist when the execution of the body of the constructor is complete. &lt;br /&gt;&lt;br /&gt;public class ConstructorExamples {&lt;br /&gt; String name;&lt;br /&gt; int tag;&lt;br /&gt; &lt;br /&gt; //constructor without parameters&lt;br /&gt; ConstructorExamples(){&lt;br /&gt;  this.name="nobody";&lt;br /&gt;  this.tag=0;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //this constructor has parameters&lt;br /&gt; ConstructorExamples(String up, int number){&lt;br /&gt;  this.name = up;&lt;br /&gt;  this.tag = number;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;public class Loader {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  //invoking the constructor without parameters&lt;br /&gt;  ConstructorExamples beanpole = new ConstructorExamples();&lt;br /&gt;  &lt;br /&gt;  //hey, what does it contain&lt;br /&gt;  System.out.println("Name: "+&lt;br /&gt;    beanpole.name+". Number: "+beanpole.tag);&lt;br /&gt;  &lt;br /&gt;  //invoking the constructor with arguments&lt;br /&gt;  ConstructorExamples magpie = new &lt;br /&gt;ConstructorExamples("elizabeth", 3);&lt;br /&gt;  &lt;br /&gt;  //you contain something too not so?&lt;br /&gt;  System.out.println("Name: "+magpie.name+". Number: &lt;br /&gt;"+magpie.tag);  &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Footers:&lt;br /&gt;&lt;br /&gt;[1]. Object finalization: freeing up resources tat cannot be freed automatically by an automatic storage manager.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-3560123482094558028?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/3560123482094558028/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=3560123482094558028' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/3560123482094558028'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/3560123482094558028'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/03/types-values-and-variables10.html' title='TYPES, VALUES AND VARIABLES(10)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-2501622757204951202</id><published>2007-03-30T04:50:00.000-07:00</published><updated>2007-03-30T04:51:06.882-07:00</updated><title type='text'>TYPES, VALUES AND VARIABLES(9)</title><content type='html'>TYPES, VALUES AND VARIABLES(9)&lt;br /&gt;&lt;br /&gt;Where types are used: &lt;br /&gt;Types are used in declarations and expressions. Each of the usage below will be covered in subsequent blogs:&lt;br /&gt;1. declarations:&lt;br /&gt;- in imported types&lt;br /&gt;- in fields&lt;br /&gt;- as method parameters&lt;br /&gt;- as method results (what a method returns)&lt;br /&gt;- as constructor parameters&lt;br /&gt;- as local variables&lt;br /&gt;- as exception handler parameters&lt;br /&gt;- as type variable&lt;br /&gt;&lt;br /&gt;2. expressions&lt;br /&gt;- class instance creation expressions&lt;br /&gt;- generic class instance creation&lt;br /&gt;- array creation&lt;br /&gt;- generic method and constructor invocation&lt;br /&gt;- casts&lt;br /&gt;- the instanceof operator&lt;br /&gt;- the arguments to parameterized types&lt;br /&gt;&lt;br /&gt;VARIABLES:&lt;br /&gt;A variable is a storage location and has an associated type, sometimes called its compile-time type, that is either a primitive type or a reference type. &lt;br /&gt;All assignments to a variable are checked for assignment compatibility, usually at compile time but when involving arrays, a run-time check is made. &lt;br /&gt;Variables of primitive types: these variables always hold a value of that exact primitive type. &lt;br /&gt;Variables of reference types: let T be our reference type. &lt;br /&gt;If T is a class type. It holds the following values:&lt;br /&gt;A. a null reference e.g T var = null;&lt;br /&gt;B. a reference to an instance of class T. e.g T secondvar = new T();&lt;br /&gt;C. a reference to any class that is a subclass of T e.g &lt;br /&gt;package api_package;&lt;br /&gt;&lt;br /&gt;public class T {…}&lt;br /&gt;&lt;br /&gt;public class Tsub extends T{…}&lt;br /&gt;&lt;br /&gt;public class Loader {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  T avar = new T();&lt;br /&gt;  Tsub anovar = new Tsub();&lt;br /&gt;  avar = anovar;  &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if T is an interface type, it can hold the following values:&lt;br /&gt;a. a null reference &lt;br /&gt;b. a reference to any instance that implements the interface.&lt;br /&gt; &lt;br /&gt;public interface IT {}&lt;br /&gt;&lt;br /&gt;public class T implements IT{}&lt;br /&gt;&lt;br /&gt;public class Loader {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  T avar = new T();&lt;br /&gt;  IT newvar = avar;  &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Note that a variable of  type, array of T, T[], where&lt;br /&gt;1. T is a primitive type can hold the following values:&lt;br /&gt;a. a null reference &lt;br /&gt;b. a reference to any array of type, T[]&lt;br /&gt;public class Loader {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  int[] nob = null;&lt;br /&gt;  int[] hope = nob;  &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;2. T is a reference type, then a variable of type T[ ] can hold:&lt;br /&gt;a. a null reference&lt;br /&gt;b. a reference to any array of type, array of S, S[], such that type S is a subclass or subinterface of type T. &lt;br /&gt;&lt;br /&gt;public class T implements IT{}&lt;br /&gt;&lt;br /&gt;public class Tsub extends T{}&lt;br /&gt;&lt;br /&gt;public class Loader {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  T[] var = null;&lt;br /&gt;  var = new Tsub[1];  &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;A variable of type Object[] can hold any array of any reference type. &lt;br /&gt;&lt;br /&gt;A variable of type Object can hold:&lt;br /&gt;a. a null reference &lt;br /&gt;b. a reference to any object, whether class instance or array.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-2501622757204951202?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/2501622757204951202/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=2501622757204951202' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/2501622757204951202'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/2501622757204951202'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/03/types-values-and-variables9.html' title='TYPES, VALUES AND VARIABLES(9)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-7162942358711710678</id><published>2007-03-30T04:47:00.000-07:00</published><updated>2007-03-30T04:48:43.300-07:00</updated><title type='text'>TYPES, VALUES AND VARIABLES(8)</title><content type='html'>TYPES, VALUES AND VARIABLES(8)&lt;br /&gt;&lt;br /&gt;TYPE ERASURE:&lt;br /&gt;Type erasure is a mapping from types (possibly including parameterized types and type variables) to types (that are never parameterized types or type variables). We write |T| for the erasure of a type T. &lt;br /&gt;Type erasure is defined as:&lt;br /&gt;- erasure of a parameterized type G&lt;T1, …, Tn&gt; as |G|&lt;br /&gt;- erasure of a nested type T.C as |T|.C&lt;br /&gt;- the erasure of an array type T[] as |T|[]&lt;br /&gt;- the erasure of a type variable is the erasure of its leftmost bound. For example, if &lt;br /&gt;T extends M implements N, then its erasure M and if&lt;br /&gt;T implements N, then its erasure is N. &lt;br /&gt;- erasure of every other type in the type itself.  &lt;br /&gt;The erasure of a method signature, m(T  t) is m and erasure of T. &lt;br /&gt;&lt;br /&gt;REIFIABLE TYPES:&lt;br /&gt;Types that are completely available at run-time, after erasures, are known as reifiable types. A type is reifiable if and only if:&lt;br /&gt;- it is a non-reifiable type. &lt;br /&gt;- If parameterized, it has unbounded wildcard as type argument. &lt;br /&gt;- It is an array type whose component type is reifiable. &lt;br /&gt;- It is a raw type&lt;br /&gt;- It is a primitive type&lt;br /&gt;&lt;br /&gt;RAW TYPES:&lt;br /&gt;A raw type is a parameterized type derivation to facilitate interfacing with non-generic legacy code. It is either:&lt;br /&gt;a. the name of a generic type declaration less the actual type arguments i.e S&lt;T,U&gt; has as raw type, S.&lt;br /&gt;b. any non-static type member of a raw type that is not inherited from a superclass or superinterface of R. &lt;br /&gt;&lt;br /&gt;it’s important to note the discussion in the jls for §4.8, particularly the fact that it is better to insert the complete generics for a member of a generic type or the type itself when referring to them, but in interfacing to legacy code, check your erasures very well. &lt;br /&gt;&lt;br /&gt;INTERSECTION TYPES:&lt;br /&gt;An intersection type takes the form T1 … Tn, for positive n, n&gt;0, where each T, Ti, is defined by  1≤ i ≤n , are type expressions. Intersection types arise in the processes of capture conversion[1] and type inference[2].&lt;br /&gt;&lt;br /&gt;Realise that intersection types are not written directly as part of a program. &lt;br /&gt;&lt;br /&gt;Members of an intersection type:&lt;br /&gt;1. a class or interface type without any member and without any inherited members from a superclass is an intersection type. Its values should be null. &lt;br /&gt;2. a superclass, Ck, for a class type, T, such that Ck, has a superclass, Ci, but Ck and Ci have the same and equivalent members. &lt;br /&gt;3. interfaces implemented by a class type are intersection types. &lt;br /&gt;&lt;br /&gt;SUBTYPING:&lt;br /&gt;The subtypes and supertype relations are all binary relations on types. &lt;br /&gt;&lt;br /&gt;A direct supertype relationship is written as &gt;1 if S is a direct supertype of T, then S &gt;1 T. &lt;br /&gt;S :&gt; T indicates that a supertype relationship exists between S &amp; T. S is a proper supertype of T, written S &gt; T, if S :&gt; T and S ≠ T. &lt;br /&gt;&lt;br /&gt;The subtype relationship is denoted by  &lt;: . We write T &lt;: S to denote T has a subtype relationship with S. T is a proper subtype of S, written T &lt; S if T &lt;: S and S ≠ T. &lt;br /&gt;T is a direct subtype of S, written as T &lt;1 S if S &gt;1 T. &lt;br /&gt;&lt;br /&gt;Note: subtyping does not extend through generic types: T &lt;: U does not imply C&lt;T&gt; &lt;: C&lt;U&gt;. &lt;br /&gt;&lt;br /&gt;Subtyping among primitive types:&lt;br /&gt;double &gt;1 float&lt;br /&gt;float &gt;1 long&lt;br /&gt;long &gt;1 int&lt;br /&gt;int &gt;1 char&lt;br /&gt;int &gt;1 short &lt;br /&gt;short &gt;1 byte&lt;br /&gt;&lt;br /&gt;Subtyping among class and interface types:&lt;br /&gt;if we have a declaration like this:&lt;br /&gt;&lt;br /&gt;Given parameterized type, C&lt;F1 extends B1, F2 super B2&gt; where C is defined by C&lt;T1,T2&gt; ,  the two argument types have ranges that are subtypes of their corresponding bounds. That is T1 is bound by an upper bound, B1 and T2 by a lower bound, B2.&lt;br /&gt;&lt;br /&gt;Given C&lt;F1,F2&gt;, the direct supertype of this parameterized type are all of the following:&lt;br /&gt;1. the direct superclass of the erasure of the type or C&lt;br /&gt;2. the direct superinterface of C&lt;br /&gt;3. the type Object, if C is an interface type with no direct superinterface (i.e it has no declaratioin of the form: implements T ).&lt;br /&gt;4. the raw type, C.&lt;br /&gt;&lt;br /&gt;package api_package;&lt;br /&gt;&lt;br /&gt;public class Nigerian {}&lt;br /&gt;&lt;br /&gt;//the container type or supertype of Lagosian is &lt;br /&gt;//Nigerian&lt;br /&gt;public class Lagosian&lt;Yoruba,Igbo,Hausa&gt; extends Nigerian{&lt;br /&gt; public static void main(String[] args){&lt;br /&gt;  Lagosian you = new Lagosian();&lt;br /&gt;  &lt;br /&gt;  //I can cast succesfully to the supertype&lt;br /&gt;  System.out.println((Nigerian)you);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Given a type C&lt;T1,T2&gt; its direct supertype is D&lt;U1 theta, U2 theta&gt; if:&lt;br /&gt;1. D&lt;U1,U2&gt; is a direct supertype of C&lt;T1,T2&gt; and theta represents each C&lt;T1,T2&gt; within each “cage” of D. &lt;br /&gt;Example: &lt;br /&gt;package api_package;&lt;br /&gt;&lt;br /&gt;public class Nigerian&lt;Yoruba&gt; {&lt;br /&gt; String name="tunde"; &lt;br /&gt;}&lt;br /&gt;//the container type or supertype of Lagosian is &lt;br /&gt;//Nigerian&lt;Yoruba&gt;&lt;br /&gt;public class Lagosian&lt;Yoruba,Igbo,Hausa&gt; &lt;br /&gt;  extends Nigerian{&lt;br /&gt;}&lt;br /&gt;public class Loader {&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  Lagosian you = new Lagosian();&lt;br /&gt;  &lt;br /&gt;  //Lagosian can access yoruba&lt;br /&gt;  System.out.println(you.name);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;2. C&lt;S1,S2&gt; is a supertype where S1 contains T1 and S2 contains T2 respectively.&lt;br /&gt;&lt;br /&gt;The direct supertypes of an intersection type are the members of the intersection type. &lt;br /&gt;The direct supertype of a type variable are the types listed in its bound. &lt;br /&gt;The direct supertype of the null type are all reference types other than the null type itself. &lt;br /&gt;&lt;br /&gt;Subtyping among Array types:&lt;br /&gt;The following rules define the direct subtype relation among array types. &lt;br /&gt;&lt;br /&gt;1. if S &amp; T  are both reference types, then &lt;br /&gt;- S[] &gt;1 T[], iff S &gt;1 T. &lt;br /&gt;- Object &gt;1 Object[]&lt;br /&gt;- Cloneable &gt;1 Object[]&lt;br /&gt;- java.io.Serializable &gt;1 Object[]&lt;br /&gt;&lt;br /&gt;2. if p is a primitive type, then&lt;br /&gt;- Object &gt;1 p[]&lt;br /&gt;- Cloneable &gt;1 p[]&lt;br /&gt;- java.io.Serializable &gt;1 p[]&lt;br /&gt; &lt;br /&gt;Footers:&lt;br /&gt;[1]. Capture conversion, to be discussed later, denotes a conversion of generics to their equivalent type variables taking into account the superclasses and subclasses that the type variable will have a contract with. &lt;br /&gt;[2]. This is a process of inferring type arguments from method and constructor invocations.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-7162942358711710678?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/7162942358711710678/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=7162942358711710678' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/7162942358711710678'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/7162942358711710678'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/03/types-values-and-variables8.html' title='TYPES, VALUES AND VARIABLES(8)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-3520277146270153783</id><published>2007-03-30T04:27:00.000-07:00</published><updated>2007-03-30T04:37:00.754-07:00</updated><title type='text'>TYPES, VALUES AND VARIABLES(7)</title><content type='html'>&lt;p class="MsoNormal"&gt;&lt;b style=""&gt;&lt;u&gt;TYPES, VALUES AND VARIABLES(7)&lt;o:p&gt;&lt;span style="text-decoration: none;"&gt; &lt;/span&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;i style=""&gt;This section, §4.5 needs just a little explanation and I’ve found it difficult to come up with an illustration, maybe as we go into later sections, one will spring up. &lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/p&gt;      &lt;p class="MsoNormal"&gt;&lt;b style=""&gt;PARAMETERIZED TYPES:&lt;o:p&gt; &lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;A parameterized type consists of either one of a class or interface name C and an actual type argument list &lt;t&lt;sub&gt;1&lt;/sub&gt;, …, T&lt;sub&gt;N&lt;/sub&gt;&gt;. A compile time error results if C is not a class or interface name. &lt;/p&gt;    &lt;p class="MsoNormal"&gt;Vector&lt;integer&gt;&lt;span style=""&gt;  &lt;/span&gt;&lt;i style=""&gt;//class or interface name, Vector. Arguments: accepts Integer.&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Seq&lt;seq&lt;a&gt;&gt; &lt;i style=""&gt;//class or interface name, Seq. arguments: a generic class, Seq which &lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;i style=""&gt;generic class has argument, A.&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;What this section is saying is that type variables could end up being parameterized types if declared so and that a parameterized type could be bounded by another type which bound is called the supertype. This type and its bound has a binary relation that defines the bound, and it is a proper supertype if the parameterized type is not equal to its bounding type. &lt;/p&gt;      &lt;p class="MsoNormal"&gt;On the other hand a type variable could have a supertype but when it is declared as a parameterized type, it’s supertype is the &lt;i style=""&gt;bounding&lt;/i&gt; on this parameter within this section of the class or interface and not the supertype when it was declared a type variable.&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;b style=""&gt;Type arguments and wildcards:&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Type arguments are either:&lt;/p&gt;    &lt;p class="MsoNormal"&gt;A. Reference types. &lt;/p&gt;    &lt;p class="MsoNormal"&gt;B. Wildcards, which wildcard can be bounded with the words &lt;i style=""&gt;extends&lt;/i&gt; or &lt;i style=""&gt;super&lt;/i&gt; on a reference type.&lt;span style=""&gt; &lt;/span&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Reference types have been dealt with above. &lt;/p&gt;  &lt;p class="MsoNormal"&gt;For a wildcard type argument, &lt;?&gt;, if unbounded like below: &lt;/p&gt;    &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;void&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; printCollection(Collection&lt;?&gt; c){&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;                  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;for&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; (Object o: c){&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;                        &lt;/span&gt;System.out.println(o);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;                  &lt;/span&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Then we say the wildcard allows any kind of Collection to be used as its parameter. &lt;/p&gt;  &lt;p class="MsoNormal"&gt;According to the discussion on §4.5.1 of the jls, assuming Object for a &lt;?&gt;, which is natural, is discouraged in java because:&lt;/p&gt;  &lt;ol style="margin-top: 0in;" start="1" type="1"&gt;&lt;li class="MsoNormal" style=""&gt;Object      would be advisable to be explicitly stated if it is needed. &lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;assuming      acceptability of Object will probably be invalid because Object is rarely      used as an argument.&lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;the      any &lt;?&gt; parameter type is not enough for Object to be assumed&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;/ol&gt;    &lt;p class="MsoNormal"&gt;Features: &lt;/p&gt;      &lt;p class="MsoNormal"&gt;a. Wildcards are useful in situations when only partial knowledge about the type parameters is required.&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;b. wildcards may be given explicit bounds. An upper bound is signified by the syntax:&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;            &lt;/span&gt;? extends B&lt;span style=""&gt;   &lt;/span&gt;&lt;i style=""&gt;//where B is the bound&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.25in;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.25in;"&gt;Using bounds on a wildcard is better than declaring genericity on method, if the type parameter is a method, although both methods could be used. &lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.5in;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.5in;"&gt;? super B &lt;i style=""&gt;//where B is the bound&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;c. 2 type arguments are provably distinct if neither of the arguments is a type variable or wildcard, and the two arguments are not the same type. &lt;/p&gt;      &lt;p class="MsoNormal"&gt;&lt;i style=""&gt;Not distinct&lt;/i&gt;: boolean addAll(Collection&lt;t&gt;&lt;span style=""&gt;  &lt;/span&gt;c)&lt;span style=""&gt;  &lt;/span&gt;not distinct from boolean addAll(Collection&lt;?&gt;&lt;span style=""&gt;  &lt;/span&gt;c)&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;i style=""&gt;Distinct&lt;/i&gt;:&lt;span style=""&gt;  &lt;/span&gt;boolean addAll(Collection&lt;e&gt;&lt;span style=""&gt;  &lt;/span&gt;c)&lt;span style=""&gt;  &lt;/span&gt;distinct from, boolean addAll(Collection&lt;t&gt;&lt;span style=""&gt;  &lt;/span&gt;c)&lt;/p&gt;    &lt;p class="MsoNormal"&gt;TYPE ARGUMENT CONTAINMENT AND EQUIVALENCE:&lt;span style=""&gt;  &lt;/span&gt;We’ll illustrate this using two classes, one NigerianPopulation class and LagosPopulation class. Let’s say NigerianPopulation class is defined by the numeric range i, where 10m ≤ i ≤ 130m and LagosPopulation is defined by the range j, where 3m ≤ j ≤ 5m. let’s assume that LagosPopulation is a subclass of NigerianPopulation, &lt;/p&gt;  &lt;p class="MsoNormal"&gt;Then LagosPopulation &lt;: NigerianPopulation &lt;i style=""&gt;//LagosPopulation is a subtype of &lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 2.5in; text-indent: 0.5in;"&gt;&lt;i style=""&gt;NigerianPopulation&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Where &lt;= defines a contained in relationship&lt;/p&gt;  &lt;ol style="margin-top: 0in;" start="1" type="1"&gt;&lt;li class="MsoNormal" style=""&gt;?      extends LagosPopulation &lt;= ? extends NigerianPopulation is true&lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;?      super LagosPopulation &lt;= ? super NigerianPopulation is true&lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;LagosPopulation      &lt;= LagosPopulation&lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;LagosPopulation      &lt;= ? extends LagosPopulation&lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;LagosPopulation      &lt;= ? super LagosPopulation&lt;o:p&gt; &lt;/o:p&gt;&lt;/li&gt;&lt;/ol&gt;    &lt;p class="MsoNormal"&gt;&lt;b style=""&gt;Members and constructors of parameterized types:&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;I’ll use just an example illustrating the notes in the jls:&lt;/p&gt;      &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;package&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; generic_example;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;class&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; SecondGeneric&lt;object&gt; {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;Boolean &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;makeBelieve&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; = &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;true&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;String &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;name&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//this method will be overridden&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;span style="background: silver none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;String&lt;/span&gt; getName(){&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="background: silver none repeat scroll 0%; font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;return&lt;/span&gt;&lt;/b&gt;&lt;span style="background: silver none repeat scroll 0%; font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt; &lt;/span&gt;&lt;span style="background: silver none repeat scroll 0%; font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;name&lt;/span&gt;&lt;span style="background: silver none repeat scroll 0%; font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//the type parameters for FirstGeneric are&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//String and Integer&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;class&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; FirstGeneric&lt;string,integer&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;                  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;extends&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; SecondGeneric {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;String &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;name&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;FirstGeneric(String &lt;span style="background: silver none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;thename&lt;/span&gt;){&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;this&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;.&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;name&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; = &lt;span style="background: silver none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;thename&lt;/span&gt;;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//Note that the type of a method in this class&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//corresponds to one of the type arguments of &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//the class. type inference makes method genericity&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//somewhat duplicative. the method's type is bound&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//by the arguments that are substituting for each&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//type parameter of the class. on extending&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//the type of this method must be the same as the&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//type of the method whose class is extended.&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;String getName(){&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;return&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;name&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-3520277146270153783?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/3520277146270153783/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=3520277146270153783' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/3520277146270153783'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/3520277146270153783'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/03/types-values-and-variables7.html' title='TYPES, VALUES AND VARIABLES(7)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-8337779311267965226</id><published>2007-03-30T04:18:00.000-07:00</published><updated>2007-03-30T04:21:08.291-07:00</updated><title type='text'>TYPES, VALUES AND VARIABLES(6)</title><content type='html'>&lt;p class="MsoNormal"&gt;&lt;b style=""&gt;&lt;u&gt;TYPES, VALUES AND VARIABLES(6)&lt;o:p&gt;&lt;span style="text-decoration: none;"&gt; &lt;/span&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;b style=""&gt;TYPE VARIABLES:&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;      &lt;p class="MsoNormal"&gt;&lt;i style=""&gt;(Note before: this sectiont contains components that will be expanded on in later blogs. If you have questions about any statement particularly the fact that I decided to produce a skeletal illustration, feel free. )&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;A type variable is an unqualified identifier. They are introduced by generic class declarations, generic interface declarations, generic method declarations and generic constructor declarations&lt;sup&gt;[1]&lt;/sup&gt;.&lt;/p&gt;      &lt;p class="MsoNormal"&gt;Let’s think of typical declarations of type variables assuming our type variable is T and T may have superclass S and there are interfaces I&lt;sub&gt;1&lt;/sub&gt;, I&lt;sub&gt;2&lt;/sub&gt;.&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;a. where T is declaring a class.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;class T extends S implements I&lt;sub&gt;1&lt;/sub&gt;, I&lt;sub&gt;2 &lt;/sub&gt;&lt;span style=""&gt; &lt;/span&gt;{&lt;span style=""&gt;  &lt;/span&gt;}&lt;span style=""&gt;  &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Notes&lt;/p&gt;  &lt;p class="MsoNormal"&gt;1. a class can extend only one class, that is a class can have only one superclass otherwise compile time error. &lt;/p&gt;  &lt;p class="MsoNormal"&gt;2. extending and implementing are optional contracts T can chose to embark upon, if there is none, then superclass is Object. &lt;/p&gt;  &lt;p class="MsoNormal"&gt;3. the order of the bounds S, I&lt;sub&gt;1&lt;/sub&gt;, I&lt;sub&gt;2&lt;/sub&gt; are important. A class implements only interfaces never another class. &lt;/p&gt;  &lt;p class="MsoNormal"&gt;4. if I&lt;sub&gt;1&lt;/sub&gt;, I&lt;sub&gt;2&lt;/sub&gt; are parameterized types, they should not be the same erasures[2]. &lt;/p&gt;    &lt;p class="MsoNormal"&gt;b. where T is declaring an interface. &lt;/p&gt;  &lt;p class="MsoNormal"&gt;Interface T extends I&lt;sub&gt;1&lt;/sub&gt;, I&lt;sub&gt;2&lt;/sub&gt; { }&lt;/p&gt;  &lt;p class="MsoNormal"&gt;1. (2) above applies here. &lt;/p&gt;  &lt;p class="MsoNormal"&gt;2. (4) above also applies here. &lt;/p&gt;    &lt;p class="MsoNormal"&gt;3. an interface can extend any number of interfaces.&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;b style=""&gt;On the jls: &lt;/b&gt;the discussion on §4.4 is quite illustrative but for beginners, might be somewhat confusing, keep this for reference after parameterized types and modifiers are discussed. &lt;/p&gt;      &lt;p class="MsoNormal"&gt;&lt;b style=""&gt;Footers:&lt;o:p&gt; &lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;sup&gt;[1]&lt;/sup&gt;. Genericity: I can best try to define genericity in this terms, as the ability of a type to &lt;span style=""&gt; &lt;/span&gt;define what types it can accept as parameters within its &lt;i style=""&gt;“type entity”&lt;/i&gt; (what I can think of here is xml’s namespace). &lt;/p&gt;  &lt;p class="MsoNormal"&gt;For example, if a house is built with the stipulation that: “N has the first flat and D has the second flat and that is how it should be”, then we can call this house generic and declare it as,&lt;/p&gt;      &lt;p class="MsoNormal"&gt;class house&lt;nfirstflat,&gt; {}&lt;span style=""&gt;       &lt;/span&gt;//house is the type variable.&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Generics will be dwelt with in the next blog and later, we’ll discuss the scope of generics. &lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;sup&gt;[2]&lt;/sup&gt;. Erasures. Erasures are mappings from a generic type to a non-generic one. Assume a parameterized type P&lt;string&gt; and P&lt;integer&gt;, both correspond to the same erasure |P|. Both M&lt;string&gt; and P&lt;string&gt; have different erasures, |M| and |P|.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-8337779311267965226?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/8337779311267965226/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=8337779311267965226' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/8337779311267965226'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/8337779311267965226'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/03/types-values-and-variables6.html' title='TYPES, VALUES AND VARIABLES(6)'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-7589450754806769215</id><published>2007-03-27T08:26:00.000-07:00</published><updated>2007-03-27T08:27:03.768-07:00</updated><title type='text'>SNIPPET: java.lang.String</title><content type='html'>&lt;p class="MsoNormal"&gt;&lt;b style=""&gt;&lt;u&gt;SNIPPET: java.lang.String&lt;o:p&gt;&lt;span style="text-decoration: none;"&gt; &lt;/span&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;The java.lang.String class is final. This class represents character strings. Every string is an instance of this class. Strings are constant, immutable, and the value of a String instance can’t be changed after assignment, although the values can be shared. String buffers though are mutable. &lt;/p&gt;      &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;package&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; api_package;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;class&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; CharacterObjects {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//we'll use our char to make strings&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;static&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;char&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;[] &lt;/span&gt;&lt;i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;slimman&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; = {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;'Y'&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;,&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;'A'&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;,&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;'R'&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;,&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;'\''&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;,&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;'D'&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;,&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;'U'&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;,&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;'A'&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;};&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;static&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;char&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;[] &lt;/span&gt;&lt;i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;fatman&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; = {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;'A'&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;,&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;'T'&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;,&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;'I'&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;,&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;'K'&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;,&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;'U'&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;};&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;static&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;void&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; main(String[] args) {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//we'll use a constructor that takes array of char&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;String slimstring = &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;new&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; String(&lt;/span&gt;&lt;i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;slimman&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;String &lt;span style="background: silver none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;fatstring&lt;/span&gt; = &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;new&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; String(&lt;/span&gt;&lt;i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;fatman&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//we'll play with U like before.let's pick the letter&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;char&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; container = slimstring.charAt(6);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//now what did we pick?&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;System.&lt;/span&gt;&lt;i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;out&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;.println(&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;"We picked "&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;+container);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//i was wrong. i forgot this is index 0. &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//let's ask the all knowing machine for index&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;System.&lt;/span&gt;&lt;i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;out&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;.println(slimstring.indexOf(&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;"U"&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;));&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//5&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//so let's do it again&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;container = slimstring.charAt(5);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;System.&lt;/span&gt;&lt;i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;out&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;.println(&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;"We picked "&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;+container);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//let's join the two strings.&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;System.&lt;/span&gt;&lt;i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;out&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;.print(&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;"Joining the two strings gives "&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;System.&lt;/span&gt;&lt;i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;out&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;.println(slimstring+&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;" "&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; + &lt;span style="background: silver none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;fatstring&lt;/span&gt;);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;If there are any tips and tricks you’d like to share, do. Responses are always welcome. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-7589450754806769215?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/7589450754806769215/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=7589450754806769215' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/7589450754806769215'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/7589450754806769215'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/03/snippet-javalangstring.html' title='SNIPPET: java.lang.String'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-7712938071162323929</id><published>2007-03-27T08:24:00.000-07:00</published><updated>2007-03-27T08:25:35.895-07:00</updated><title type='text'>SNIPPET: java.lang.Float</title><content type='html'>&lt;p class="MsoNormal"&gt;&lt;b style=""&gt;&lt;u&gt;SNIPPET: java.lang.Float&lt;o:p&gt;&lt;span style="text-decoration: none;"&gt; &lt;/span&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;We’ll play a little with floats here. Remember, you’ll love the language by getting worn out using it. One more exercise is not too much. &lt;/p&gt;      &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;package&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; api_package;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;class&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; Lagosian {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;static&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;int&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;ngozi_age&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; = 25;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;static&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;void&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; main(String[] args) {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//note that this is in accord with IEEE 754 &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//floating point single-format bit layout.&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;System.&lt;/span&gt;&lt;i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;out&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;.print(&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;"Ngozi's age in floating point is: "&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;System.&lt;/span&gt;&lt;i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;out&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;.println(Float.&lt;i&gt;intBitsToFloat&lt;/i&gt;(&lt;/span&gt;&lt;i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;ngozi_age&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;));&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//just to check that we are consistent&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//note repetition of above methods&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;System.&lt;/span&gt;&lt;i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;out&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;.print(&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;"Just to be sure we're still on course: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 1in; text-indent: 0.5in;"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;"&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.5in; text-indent: 0.5in;"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;System.&lt;/span&gt;&lt;i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;out&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;.println(Float.&lt;i&gt;floatToRawIntBits&lt;/i&gt;(Float.&lt;i&gt;intBitsToF&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 1in; text-indent: 0.5in;"&gt;&lt;i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;loat&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;(&lt;/span&gt;&lt;i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;ngozi_age&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;)));&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//try other exercises. you have the fundamentals to&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//work with java for the maths inclined&lt;span style=""&gt;   &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;} &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3008166024805877968-7712938071162323929?l=genericjava.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://genericjava.blogspot.com/feeds/7712938071162323929/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3008166024805877968&amp;postID=7712938071162323929' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/7712938071162323929'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3008166024805877968/posts/default/7712938071162323929'/><link rel='alternate' type='text/html' href='http://genericjava.blogspot.com/2007/03/snippet-javalangfloat.html' title='SNIPPET: java.lang.Float'/><author><name>cyprian.ekere</name><uri>http://www.blogger.com/profile/18392388017531884754</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp0.blogger.com/_-vb8zdpkvpo/RhPe46tYFCI/AAAAAAAAAAU/biM4RwbDjsI/s1600/david_old.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3008166024805877968.post-7488940157586688682</id><published>2007-03-27T08:20:00.000-07:00</published><updated>2007-03-27T08:22:09.984-07:00</updated><title type='text'>SNIPPET: java.lang.Integer</title><content type='html'>&lt;p class="MsoNormal"&gt;&lt;b style=""&gt;&lt;u&gt;SNIPPET: java.lang.Integer&lt;o:p&gt;&lt;span style="text-decoration: none;"&gt; &lt;/span&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;The integer class is a final class, i.e it can’t be subclassed by any class. It’s superclass is the Number class. &lt;/p&gt;      &lt;p class="MsoNormal"&gt;The Integer class wraps the value of the primitive type int in an object and contains a single field with type int. This class has several methods for casting int to String and vice versa, as well as other useful methods for playing with int.&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;In the example that follows, since ages are less than 100 we’ll be working with int values that correspond to byte values. This examples assumes you already understand a little of two’s complement binary representation of numerical values. &lt;/p&gt;      &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;package&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; api_package;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;class&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; Lagosian {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//the fields in the class&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;String &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;name&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;, &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;sex&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;int&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;age&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//Class constructor, without parameters&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;Lagosian(){&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;this&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;.&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;name&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; = &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;"jejecy"&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;this&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;.&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;sex&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; = &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(42, 0, 255);"&gt;"dummy"&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;this&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;.&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;age&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; = 120;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//Constructor with parameters&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;Lagosian(String arg, String orientation, &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;int&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; ages){&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;this&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;.&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;name&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; = arg;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;this&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;.&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;sex&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; = orientation;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;this&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;.&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(0, 0, 192);"&gt;age&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; = ages;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;static&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;void&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; main(String[] args) {&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(63, 127, 95);"&gt;//the first object we met in &lt;st1:city st="on"&gt;&lt;st1:place st="on"&gt;Lagos&lt;/st1:place&gt;&lt;/st1:City&gt; was called tunde&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt;&lt;span style=""&gt;            &lt;/span&gt;Lagosian firstobject = &lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 0, 85);"&gt;new&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;"&gt; Lagosian(&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;qu
