<?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:blogger='http://schemas.google.com/blogger/2008' 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-4896915819228198386</id><updated>2024-09-14T03:55:06.313-07:00</updated><category term="fundamental"/><title type='text'>Java Sag is under construction</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>41</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-3351564118582006633</id><published>2012-05-09T00:53:00.001-07:00</published><updated>2012-05-09T00:53:13.113-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I create static variables in Java?</title><content type='html'>Class variables or static variable is variable that declared with static modifier. A given class will have only one copy of each of its static variables, regardless of how many times the class has been instantiated.&lt;br /&gt;
&lt;br /&gt;
If the value of a static variable is changed, the new value is available equally in all instances of the class. The final keyword could be added to indicate the value of static variable will never change. If you try to assign a new value to final variable, you will get a compile error.&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.fundametal;

public class StaticDemo {
    // static variable
    static int x = 12;

    // static variable with final value that never change
    final static int Y = 20;

    // non-static variable
    int z;

    public static void main(String[] args) {
        StaticDemo sd0 = new StaticDemo();

        System.out.println(&quot;x before update = &quot; + StaticDemo.x);
        System.out.println(&quot;y= &quot; + StaticDemo.Y);

        sd0.z = StaticDemo.x + StaticDemo.Y;
        System.out.println(&quot;z= &quot; + sd0.z);

        StaticDemo.x = 15;
        System.out.println(&quot;x after update = &quot; + StaticDemo.x);

        StaticDemo sd1 = new StaticDemo();
        StaticDemo sd2 = new StaticDemo();
        StaticDemo.x = 20;

        System.out.println(&quot;StaticDemo.x = &quot; + StaticDemo.x);
        System.out.println(&quot;sd0 = &quot; + sd0.getX());
        System.out.println(&quot;sd1 = &quot; + sd1.getX());
        System.out.println(&quot;sd2 = &quot; + sd2.getX());

        //
        // try to assign value to final variable, it will cause a
        // compile time error
        //
        // StaticDemo.Y = 30;
    }

    public int getX() {
        return StaticDemo.x;
    }
}

&lt;/pre&gt;Here is the output printed by the program:&lt;br /&gt;
&lt;br /&gt;
x before update = 12&lt;br /&gt;
y= 20&lt;br /&gt;
z= 32&lt;br /&gt;
x after update = 15&lt;br /&gt;
StaticDemo.x = 20&lt;br /&gt;
sd0 = 20&lt;br /&gt;
sd1 = 20&lt;br /&gt;
sd2 = 20</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/3351564118582006633/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-create-static-variables-in.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/3351564118582006633'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/3351564118582006633'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-create-static-variables-in.html' title='How do I create static variables in Java?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-8385588296260904006</id><published>2012-05-09T00:52:00.002-07:00</published><updated>2012-05-09T00:52:18.373-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I catch multiple exceptions?</title><content type='html'>If a try block can throw several different kind of exceptions and you want to handle each exception differently, you can put several catch blocks to handle it.&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.fundametal;

public class MultipleCatchExample {
    public static void main(String[] args) {
        int[] numbers1 = {1, 2, 3, 4, 5};
        int[] numbers2 = {1, 2, 3, 4, 5, 6};

        try {
            //
            // This line throws an ArrayIndexOutOfBoundsException
            //
            MultipleCatchExample.printResult(numbers1);

            //
            // This line throws an ArithmeticException
            //
            MultipleCatchExample.printResult(numbers2);
        } catch (ArithmeticException e) {
            e.printStackTrace();
        } catch (ArrayIndexOutOfBoundsException e) {
            e.printStackTrace();
        } finally {
            System.out.println(&quot;Finally block is always executed.&quot;);
        }
    }

    /**
     * Divide the given first number by the second number.
     *
     * @param x the first number.
     * @param y the second number.
     * @return the result of division.
     */
    private static int divide(int x, int y) {
        return x / y;
    }

    /**
     * Print the output result of divide operation by calling the
     * divide() method.
     *
     * @param numbers integer arrays of the divided number
     * @throws ArrayIndexOutOfBoundsException when an exception
     * occurs.
     */
    private static void printResult(int[] numbers) {
        int x, z, y = 1;
        for (int i = 0; i &lt; 6; i++) {
            x = numbers[i];
            if (i == 5) {
                y = 0;
            }
            z = MultipleCatchExample.divide(x, y);
            System.out.println(&quot;z = &quot; + z);
        }
    }
}

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/8385588296260904006/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-catch-multiple-exceptions.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/8385588296260904006'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/8385588296260904006'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-catch-multiple-exceptions.html' title='How do I catch multiple exceptions?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-7434492698826258260</id><published>2012-05-09T00:51:00.002-07:00</published><updated>2012-05-09T00:51:23.116-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I use the super keyword?</title><content type='html'>When a class extends from other class, the class or usually called as subclass inherits all the accessible members and methods of the superclass. If the subclass overrides a method provided by its superclass, a way to access the method defined in the superclass is through the super keyword.&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.fundametal;

public class Bike {
    public void moveForward() {
        System.out.println(&quot;Bike: Move Forward.&quot;);
    }
}

&lt;/pre&gt;In the ThreeWheelsBike&#39;s moveForward() method we call the overridden method using the super.moveForward() which will print the message from the Bike class.&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.fundametal;

public class ThreeWheelsBike extends Bike {
    @Override
    public void moveForward() {
        super.moveForward();
        System.out.println(&quot;Three Wheels Bike: Move Forward.&quot;);
    }

    public static void main(String[] args) {
        Bike bike = new ThreeWheelsBike();
        bike.moveForward();
    }
}

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/7434492698826258260/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-use-super-keyword.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/7434492698826258260'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/7434492698826258260'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-use-super-keyword.html' title='How do I use the super keyword?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-578117149864656592</id><published>2012-05-09T00:48:00.003-07:00</published><updated>2012-05-09T00:48:56.155-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I use the this keyword in Java?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;background-color: white; font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; font-size: 13px; line-height: 20px; margin-bottom: 1.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;The program below demonstrate how to use the&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;switch&lt;/code&gt;&amp;nbsp;statement. The&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;switch&lt;/code&gt;&amp;nbsp;statement can work with the&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;byte&lt;/code&gt;,&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;short&lt;/code&gt;,&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;int&lt;/code&gt;&amp;nbsp;and&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;char&lt;/code&gt;&amp;nbsp;primitive data types and the corresponding wrappers of these data type such as&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;Byte&lt;/code&gt;,&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;Short&lt;/code&gt;,&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;Integer&lt;/code&gt;&amp;nbsp;and&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;Character&lt;/code&gt;. It also work with work with&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;enumerated types&lt;/code&gt;, refer to the following example:&amp;nbsp;&lt;a href=&quot;http://www.kodejava.org/examples/518.html&quot; style=&quot;color: #004000; outline-color: initial; outline-style: none; outline-width: initial;&quot; title=&quot;How do I use enum in switch statement?&quot;&gt;How do I use enum in switch statement?&lt;/a&gt;.&lt;/div&gt;&lt;div style=&quot;background-color: white; font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; font-size: 13px; line-height: 20px; margin-bottom: 1.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;The&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;switch block&lt;/code&gt;&amp;nbsp;or the body can contains one or more&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;case&lt;/code&gt;&amp;nbsp;or&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;default&lt;/code&gt;&amp;nbsp;labels. The&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;switch&lt;/code&gt;&amp;nbsp;statement evaluates its expression and evaluate the appropriate&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;case&lt;/code&gt;.&lt;/div&gt;&lt;div style=&quot;background-color: white; font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; font-size: 13px; line-height: 20px; margin-bottom: 1.5em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;You&#39;ll also notice that after each&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;case&lt;/code&gt;&amp;nbsp;labels we have a&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;break&lt;/code&gt;&amp;nbsp;statement. This&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;break&lt;/code&gt;&amp;nbsp;statement causes the program execution to continue outside the&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;switch&lt;/code&gt;&amp;nbsp;block. Without using a&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;break&lt;/code&gt;&amp;nbsp;the case will fall-through to another&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;case&lt;/code&gt;&amp;nbsp;or&amp;nbsp;&lt;code style=&quot;font-family: Consolas, &#39;Courier New&#39;, Courier, monospace; font-size: 1em; white-space: pre;&quot;&gt;default&lt;/code&gt;&amp;nbsp;label.&lt;/div&gt;&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.lang;

public class SwitchDemo {
    public static void main(String[] args) {
        System.out.println(&quot;The Planets&quot;);
        System.out.println(&quot;===================================&quot;);
        System.out.println(&quot;1. Mercury&quot;);
        System.out.println(&quot;2. Venus&quot;);
        System.out.println(&quot;3. The Earth&quot;);
        System.out.println(&quot;4. Mars&quot;);
        System.out.println(&quot;5. Jupiter&quot;);
        System.out.println(&quot;6. Saturn&quot;);
        System.out.println(&quot;7. Uranus&quot;);
        System.out.println(&quot;8. Neptune&quot;);
        System.out.println(&quot;&quot;);
        System.out.print(&quot;Please choose your favorite destination: &quot;);

        int destionation = 0;
        try {
            destionation = Integer.valueOf(System.console().readLine());
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }

        System.out.print(&quot;Welcome to &quot;);
        switch (destionation) {
            case 1:
                System.out.println(&quot;Mercury&quot;); break;
            case 2:
                System.out.println(&quot;Venus&quot;); break;
            case 3:
                System.out.println(&quot;The Earth&quot;); break;
            case 4:
                System.out.println(&quot;Mars&quot;); break;
            case 5:
                System.out.println(&quot;Jupiter&quot;); break;
            case 6:
                System.out.println(&quot;Saturn&quot;); break;
            case 7:
                System.out.println(&quot;Uranus&quot;); break;
            case 8:
                System.out.println(&quot;Neptune&quot;); break;
            default:
                System.out.println(&quot;Invalid Destination&quot;);
        }
    }
}

&lt;/pre&gt;When you run the program you&#39;ll have to following on the screen:&lt;br /&gt;
&lt;br /&gt;
The Planets&lt;br /&gt;
===================================&lt;br /&gt;
1. Mercury&lt;br /&gt;
2. Venus&lt;br /&gt;
3. The Earth&lt;br /&gt;
4. Mars&lt;br /&gt;
5. Jupiter&lt;br /&gt;
6. Saturn&lt;br /&gt;
7. Uranus&lt;br /&gt;
8. Neptune&lt;br /&gt;
&lt;br /&gt;
Please choose your favorite destination: 3&lt;br /&gt;
Welcome to The Earth&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/578117149864656592/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-create-enumerations-type.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/578117149864656592'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/578117149864656592'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-create-enumerations-type.html' title='How do I use the this keyword in Java?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-6033297886789722103</id><published>2012-05-09T00:47:00.004-07:00</published><updated>2012-05-09T00:47:36.552-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I define a constant variable?</title><content type='html'>To define a constant in Java, use final modifier which combined with static modifier. The final modifier indicates that the value of this field cannot change.&lt;br /&gt;
&lt;br /&gt;
If you change the value of the constant, you need to recompile the class to get the current value. Other feature in Java that provide similar functionality is enumeration (a list of named constants). You can simply create an enumeration by using the enum keyword.&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.fundametal;

public class ConstantDemo {
    public static void main(String[] args) {
        int sunday = DayConstant.SUNDAY;
        System.out.println(&quot;Sunday= &quot; + sunday);

        String dozen = MeasureConstant.DOZEN;
        System.out.println(&quot;Dozen: &quot; + dozen);
    }

}

class DayConstant {
    public final static int SUNDAY = 0;
    public final static int MONDAY = 1;
    public final static int TUESDAY = 2;
    public final static int WEDNESDAY = 3;
    public final static int THURSDAY = 4;
    public final static int FRIDAY = 5;
    public final static int SATURDAY = 6;
}

class MeasureConstant {
    final static String UNIT = &quot;unit&quot;;
    final static String DOZEN = &quot;dozen&quot;;
}

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/6033297886789722103/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-define-constant-variable.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/6033297886789722103'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/6033297886789722103'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-define-constant-variable.html' title='How do I define a constant variable?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-6284149732477691290</id><published>2012-05-09T00:46:00.005-07:00</published><updated>2012-05-09T00:46:31.496-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I use the return keyword in Java?</title><content type='html'>The return keyword is used to return from a method when its execution is complete. When a return statement is reached in a method, the program returns to the code that invoked it.&lt;br /&gt;
&lt;br /&gt;
A method can return a value or reference type or does not return a value. If a method does not return a value, the method must be declared void and it doesn&#39;t need to contain a return statement.&lt;br /&gt;
&lt;br /&gt;
If a method declare to return a value, then it must use the return statement within the body of method. The data type of the return value must match the method&#39;s declared return type.&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.fundametal;

public class ReturnDemo {

    public static void main(String[] args) {
        int z = ReturnDemo.calculate(2, 3);
        System.out.println(&quot;z = &quot; + z);

        Dog dog = new Dog(&quot;Spaniel&quot;, &quot;Doggie&quot;);
        System.out.println(dog.getDog());
    }

    public static int calculate(int x, int y) {
        //
        // return an int type value
        //
        return x + y;
    }

    public void print(){
        System.out.println(&quot;void method&quot;);

        //
        // it does not need to contain a return statement, but it
        // may do so
        //
        return;
    }

    public String getString(){
        return &quot;return String type value&quot;;

        //
        // try to execute a statement after return a value will
        // cause a compile-time error.
        //
        String error = &quot;error&quot;;
    }
}

class Dog {
    private String breed;
    private String name;

    Dog(String breed, String name) {
        this.breed = breed;
        this.name = name;
    }

    public Dog getDog() {
        //
        // return Dog type
        //
        return this;
    }

    public String toString(){
        return &quot;breed: &quot; + breed.concat(&quot;name: &quot; + name);
    }
}

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/6284149732477691290/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-use-return-keyword-in-java.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/6284149732477691290'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/6284149732477691290'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-use-return-keyword-in-java.html' title='How do I use the return keyword in Java?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-5965461760559563544</id><published>2012-05-09T00:45:00.002-07:00</published><updated>2012-05-09T00:46:38.953-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I use the while loop statement?</title><content type='html'>The code below demonstrate how to use the while loop statement. The while statement will check if its expression evaluates to true and execute the while statement block.&lt;br /&gt;
&lt;br /&gt;
The program below will executes while the countDown value is bigger or equals to zero.&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.lang;

public class WhileDemo {
    public static void main(String[] args) {
        //
        // Start the count down from 10
        //
        int countDown = 10;

        //
        // Do the count down process while the value of
        // countDown is bigger or equals to zero.
        //
        while (countDown &gt;= 0) {
            System.out.println(countDown);
            countDown--;

            try {
                //
                // Adds one second delay.
                //
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/5965461760559563544/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-use-while-loop-statement.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/5965461760559563544'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/5965461760559563544'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-use-while-loop-statement.html' title='How do I use the while loop statement?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-5052368596447158581</id><published>2012-05-09T00:43:00.001-07:00</published><updated>2012-05-09T00:43:46.425-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I get constants name of an enum?</title><content type='html'>To get the constants name of an enumeration you can use the values() method of the enumeration type. This method return an array that contains a list of enumeration constants.&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.fundametal;

enum Month {
    JANUARY,
    FEBRUARY,
    MARCH,
    APRIL,
    MAY,
    JUNE,
    JULY,
    AUGUST,
    SEPTEMBER,
    OCTOBER,
    NOVEMBER,
    DECEMBER
}

public class EnumValuesTest {
    public static void main(String[] args) {
        //
        // values() method return an array that contains a list of the
        // enumeration constants.
        //
        Month[] months = Month.values();
        System.out.println(&quot;Month size: &quot; + months.length);
        
        //
        // We can user for each statement to print each enumeration
        // constant.
        //
        for (Month month : Month.values()) {
            System.out.println(&quot;Month: &quot; + month);
        }
    }
}

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/5052368596447158581/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/to-get-constants-name-of-enumeration.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/5052368596447158581'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/5052368596447158581'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/to-get-constants-name-of-enumeration.html' title='How do I get constants name of an enum?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-7912334453653772709</id><published>2012-05-09T00:42:00.001-07:00</published><updated>2012-05-09T00:43:59.722-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I use the do-while loop statement?</title><content type='html'>There is also a do-loop in the Java programming language. Instead of evaluating the expression at the beginning like the while loop does the do-while loop evaluates its expression at the end of the loop. Due to this the loop executes at least once during the program execution.&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.lang;

public class DoWhileDemo {
    public static void main(String[] args) {
        int i = 0;

        //
        // The do-while statement executes at least once because
        // the expression is checked at the end of the loop
        // process.
        //
        do {
            //
            // This block will be executed while i is smaller or
            // equals to 10.
            //
            System.out.println(i);
            i++;
        } while (i &lt;= 10);
    }
}

&lt;/pre&gt;
The program prints the following result:&lt;br /&gt;
&lt;br /&gt;
0&lt;br /&gt;
1&lt;br /&gt;
2&lt;br /&gt;
3&lt;br /&gt;
4&lt;br /&gt;
5&lt;br /&gt;
6&lt;br /&gt;
7&lt;br /&gt;
8&lt;br /&gt;
9&lt;br /&gt;
10&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/7912334453653772709/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-use-do-while-loop-statement.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/7912334453653772709'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/7912334453653772709'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-use-do-while-loop-statement.html' title='How do I use the do-while loop statement?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-1658294495536147899</id><published>2012-05-09T00:40:00.005-07:00</published><updated>2012-05-09T00:40:58.054-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I create a class in Java?</title><content type='html'>A class is a specification or blueprint from which individual objects are created. A class contains fields that represent the object&#39;s states and methods that defines the operations that are possible on the objects of the class.&lt;br /&gt;
&lt;br /&gt;
The file name that contains the definition of a class is always the same as the public class name and the extension is .java to identify that the file contains a Java source code.&lt;br /&gt;
&lt;br /&gt;
A class has constructors, a special method that is used to create an instance or object of the class. When no constructor define a default constructor will be used. The constructor method have the same name with the class name without a return value. The constructors can have parameters that will be used to initialize object&#39;s states.&lt;br /&gt;
&lt;br /&gt;
Here is a Person.java file that defines the Person class.&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.fundametal;

public class Person {
    private String name;
    private String title;
    private String address;

    /**
     * Constructor to create Person object
     */
    public Person() {

    }

    /**
     * Constructor with parameter
     *
     * @param name
     */
    public Person(String name) {
        this.name = name;
    }

    /**
     * Method to get the name of person
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * Method to set the name of person
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Method to get the title of person
     *
     * @return title
     */
    public String getTitle() {
        return title;
    }

    /**
     * Method to set the title of person
     *
     * @param title
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * Method to get address of person
     *
     * @return address
     */
    public String getAddress() {
        return address;
    }

    /**
     * Method to set the address of person
     *
     * @param address
     */
    public void setAddress(String address) {
        this.address = address;
    }

    /**
     * Method to get name with title of person
     *
     * @return nameTitle
     */
    public String getNameWithTitle() {
        String nameTitle;
        if (title != null) {
            nameTitle = name + &quot;, &quot; + title;
        } else {
            nameTitle = name;
        }
        return nameTitle;
    }

    /**
     * Method used to print the information of person
     */
    @Override
    public String toString() {
        return &quot;Info [&quot; +
                &quot;name=&#39;&quot; + name + &#39;\&#39;&#39; +
                &quot;, title=&#39;&quot; + title + &#39;\&#39;&#39; +
                &quot;, address=&#39;&quot; + address + &#39;\&#39;&#39; +
                &#39;]&#39;;
    }
}

&lt;/pre&gt;Here is a ClassExample.java file that defines the ClassExample class that use the Person class&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.fundametal;

public class ClassExample {
    public static void main(String[] args) {
        Person person = new Person();
        person.setName(&quot;Andy&quot;);
        person.setTitle(&quot;MBA&quot;);
        person.setAddress(&quot;NY City&quot;);
        System.out.println(person);

        String nameTitle1 = person.getNameWithTitle();
        System.out.println(&quot;Name with title: &quot; + nameTitle1);

        Person person2 = new Person(&quot;Sarah&quot;);
        String nameTitle2 = person2.getNameWithTitle();
        System.out.println(&quot;Name with title 2: &quot; + nameTitle2);
    }
}

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/1658294495536147899/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-create-class-in-java.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/1658294495536147899'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/1658294495536147899'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-create-class-in-java.html' title='How do I create a class in Java?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-1386389465036287070</id><published>2012-05-09T00:35:00.004-07:00</published><updated>2012-05-09T00:37:44.158-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I use the this keyword in Java?</title><content type='html'>Every instance method has a variable with the name this that refers to the current object for which the method is being called. You can refer to any member of the current object from within an instance method or a constructor by using this keyword.&lt;br /&gt;
&lt;br /&gt;
Each time an instance method is called, the this variable is set to reference the particular class object to which it is being applied. The code in the method will then relate to the specific members of the object referred to by this keyword.&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.fundamental;

public class RemoteControl {
    private String channelName;
    private int channelNum;
    private int minVolume;
    private int maxVolume;

    RemoteControl() {

    }

    RemoteControl(String channelName, int channelNum) {
        // 
        // use the this keyword to call another constructor in the 
        // same class
        //
        this(channelName, channelNum, 0, 0);  
    }

    RemoteControl(String channelName, int channelNum, int minVol, int maxVol) {
        this.channelName = channelName;
        this.channelNum = channelNum;
        this.minVolume = minVol;
        this.maxVolume = maxVol;
    }

    public void changeVolume(int x, int y) {
        this.minVolume = x;
        this.maxVolume = y;
    }

    public static void main(String[] args) {
        RemoteControl remote = new RemoteControl(&quot;ATV&quot;, 10);
        
        // 
        // when the following line is executed, the this variable in
        // changeVolume() is refer to remote object.
        //
        remote.changeVolume(0, 25);
    }
}

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/1386389465036287070/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/every-instance-method-has-variable-with.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/1386389465036287070'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/1386389465036287070'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/every-instance-method-has-variable-with.html' title='How do I use the this keyword in Java?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-3858835086445336481</id><published>2012-05-09T00:35:00.001-07:00</published><updated>2012-05-09T00:36:47.617-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I use the final keyword in Java?</title><content type='html'>The final modifier is used to mark a class final so that it cannot inherited, to prevent a method being overridden, and to prevent changing the value of a variable. Arguments of a method if declared as final is also can not be modified within the method.&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.fundametal;

public class FinalExample {
    //
    // breed is declared final. 
    // can&#39;t change the value assigned to breed
    //
    public final String breed = &quot;pig&quot;;   
    private int count = 0;

    // 
    // sound() method is declared final, so it can&#39;t be overridden
    //
    public final void sound() {     
        System.out.println(&quot;oink oink&quot;);
    }

    // 
    // number parameter is declared final. can&#39;t change the value 
    // assigned to number
    //
    public int count(final int number) {
        //
        // assign a value to number variable will cause a 
        // compile-time error
        //
        number = 1;
        
        count = +number;
        return count;
    }

    public static void main(String[] args) {
        FinalExample fe = new FinalExample();
        // 
        // assign a value to breed variable will cause a 
        // compile-time error
        //
        fe.breed = &quot;dog&quot;;
        
        int number = fe.count(20);
    }
}

final class SubFinalExample extends FinalExample {

    //
    // try to override sound() method of superclass will cause a 
    // compile-time error
    //
    public void sound() {
         System.out.println(&quot;oink&quot;);
    }
}

//
// try to inherit a class that declared final will cause a 
// compile-time error
//
class OtherFinalExample extends SubFinalExample {
}

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/3858835086445336481/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/final-modifier-is-used-to-mark-class.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/3858835086445336481'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/3858835086445336481'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/final-modifier-is-used-to-mark-class.html' title='How do I use the final keyword in Java?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-4549037280121177946</id><published>2012-05-09T00:34:00.003-07:00</published><updated>2012-05-09T00:36:22.643-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I use the boolean negation (!) operator in Java?</title><content type='html'>The ! operator is a logical compliment operator. The operator inverts the value of a boolean expression&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.fundametal;

public class NegationOperator {
    public static void main(String[] args) {
        //
        // negate the result of boolean expressions
        //
        boolean negate = !(2 &lt; 3);
        boolean value = !false;

        System.out.println(&quot;result: &quot; + negate);
        System.out.println(&quot;value : &quot; + value);
    }
}

&lt;/pre&gt;
Here is the result of the program:&lt;br /&gt;
&lt;br /&gt;
result: false&lt;br /&gt;
value : true</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/4549037280121177946/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/operator-is-logical-compliment-operator.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/4549037280121177946'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/4549037280121177946'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/operator-is-logical-compliment-operator.html' title='How do I use the boolean negation (!) operator in Java?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-1895863986044540277</id><published>2012-05-06T04:51:00.000-07:00</published><updated>2012-05-09T00:37:21.771-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I use the for loop statement?</title><content type='html'>The for loop can be use to iterate over a range of values. For instance if you want to iterate from zero to 10 or if you want to iterate through all the items of an array. Below you&#39;ll see two forms of a for loop. The first one is the general form of a for loop and the second one is an enhanced for loop that also known as the for..each loop.&lt;br /&gt;
&lt;br /&gt;
The general form of for loop consists of three parts:&lt;br /&gt;
-----------------------------------------------------&lt;br /&gt;
for (initialization; termination; increment) {&lt;br /&gt;
....&lt;br /&gt;
}&lt;br /&gt;
-----------------------------------------------------&lt;br /&gt;
The initialization: it initializes the loop, it executed once at the beginning of the loop.&lt;br /&gt;
The termination: the loop executes as long as the termination evaluates to true.&lt;br /&gt;
The increment: it executed at the end of every loop, the expression can be either an increment or decrement.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.lang;

public class ForDemo {
    public static void main(String[] args) {
        //
        // Do a loop from 0 to 10.
        //
        for (int i = 0; i &lt;= 10; i++) {
            System.out.println(&quot;i = &quot; + i);
        }

        //
        // Loop through all the array items.
        //
        int[] numbers = new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        for (int number : numbers) {
            System.out.println(&quot;number = &quot; + number);
        }
    }
}

&lt;/pre&gt;
The result of the program is:&lt;br /&gt;
&lt;br /&gt;
i = 0&lt;br /&gt;
i = 1&lt;br /&gt;
i = 2&lt;br /&gt;
i = 3&lt;br /&gt;
i = 4&lt;br /&gt;
i = 5&lt;br /&gt;
i = 6&lt;br /&gt;
i = 7&lt;br /&gt;
i = 8&lt;br /&gt;
i = 9&lt;br /&gt;
i = 10&lt;br /&gt;
number = 0&lt;br /&gt;
number = 1&lt;br /&gt;
number = 2&lt;br /&gt;
number = 3&lt;br /&gt;
number = 4&lt;br /&gt;
number = 5&lt;br /&gt;
number = 6&lt;br /&gt;
number = 7&lt;br /&gt;
number = 8&lt;br /&gt;
number = 9&lt;br /&gt;
number = 10&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/1895863986044540277/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-use-for-loop-statement.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/1895863986044540277'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/1895863986044540277'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-use-for-loop-statement.html' title='How do I use the for loop statement?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-1440602345959855042</id><published>2012-05-06T04:49:00.002-07:00</published><updated>2012-05-06T04:49:35.484-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I define a field in enum type?</title><content type='html'>As we know that Java enumeration type is powerful compared to enum implementation in other programming language. Basically enum is class typed so it can have constructors, methods and fields.&lt;br /&gt;
&lt;br /&gt;
In the example below you&#39;ll see how a field is defined in an enumeration type. Because each constant value for the Fruit enum is a type of Fruit itself it will have its own price field. The price field holds a unique value for each constant such as APPLE, ORANGE, etc.&lt;br /&gt;
&lt;br /&gt;
In the result you&#39;ll see that the constructor will be called for each constant value and initialize it with the value passed to the constructor.&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.fundametal;

enum Fruit {
    APPLE(1.5f), ORANGE(2), MANGGO(3.5f), GRAPE(5);

    private float price;

    Fruit(float price) {
        System.out.println(&quot;Name: &quot; + this.name() + &quot; initialized.&quot;);
        this.price = price;
    }

    public float getPrice() {
        return this.price;
    }
}

public class EnumFieldDemo {
    public static void main(String[] args) {
        //
        // Get the name and price of all enum constant value.
        //
        for (Fruit f : Fruit.values()) {
            System.out.println(&quot;Fruit = &quot; + f.name() + &quot;; Price = &quot; + f.getPrice());
        }
    }
}

&lt;/pre&gt;Our demo result is below:&lt;br /&gt;
&lt;br /&gt;
Name: APPLE initialized.&lt;br /&gt;
Name: ORANGE initialized.&lt;br /&gt;
Name: MANGGO initialized.&lt;br /&gt;
Name: GRAPE initialized.&lt;br /&gt;
Fruit = APPLE; Price = 1.5&lt;br /&gt;
Fruit = ORANGE; Price = 2.0&lt;br /&gt;
Fruit = MANGGO; Price = 3.5&lt;br /&gt;
Fruit = GRAPE; Price = 5.0&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/1440602345959855042/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-define-field-in-enum-type.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/1440602345959855042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/1440602345959855042'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-define-field-in-enum-type.html' title='How do I define a field in enum type?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-608840001563693324</id><published>2012-05-06T04:47:00.003-07:00</published><updated>2012-05-06T06:23:00.629-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I use the if-then-else statement?</title><content type='html'>The if-then-else control flow statement adds a secondary path to the if statement when the expression evaluates to false. When it evaluates to false the else block will be executed.&lt;br /&gt;
&lt;br /&gt;
Below is the program that takes input of user test score and evaluates the score to get the corresponding grade.&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.lang;

import java.io.Console;

public class IfThenElseDemo {
    public static void main(String[] args) {
        //
        // Get an instance of system console for taking user
        // input.
        //
        Console c = System.console();

        int score = 0;
        String grade;

        System.out.print(&quot;Please enter your score: &quot;);

        try {
            //
            // Take user score input and convert the input
            // value into number.
            //
            score = Integer.valueOf(c.readLine());
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }

        if (score &gt;= 90) {
            grade = &quot;A&quot;;
        } else if (score &gt;= 80) {
            grade = &quot;B&quot;;
        } else if (score &gt;= 60) {
            grade = &quot;C&quot;;
        } else if (score &gt;= 50) {
            grade = &quot;D&quot;;
        } else {
            grade = &quot;F&quot;;
        }

        System.out.println(&quot;Grade = &quot; + grade);
    }
}

&lt;/pre&gt;-----------------------------------------------&lt;br /&gt;
When the program executed you&#39;ll need to input the test score and the program will give you the grade.&lt;br /&gt;
&lt;br /&gt;
Please enter your score: 75&lt;br /&gt;
Grade = C&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/608840001563693324/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-use-if-then-else-statement.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/608840001563693324'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/608840001563693324'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-use-if-then-else-statement.html' title='How do I use the if-then-else statement?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-342962296871507185</id><published>2012-05-06T04:46:00.002-07:00</published><updated>2012-05-06T04:46:50.466-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I count the occurrences of a number in an array?</title><content type='html'>&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.lang;

import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;

public class NumberOccurrenceInArray {
    public static void main(String[] args) {
        int[] numbers = new int[] {1, 8, 3, 4, 3, 2, 5, 7, 3, 1, 4, 5, 6, 4, 3};

        Map&lt;Integer, Integer&gt; map = new HashMap&lt;Integer, Integer&gt;();
        for (int i = 0; i &lt; numbers.length; i++) {
            int key = numbers[i];
            if (map.containsKey(key)) {
                int occurrence = map.get(key);
                occurrence++;
                map.put(key, occurrence);
            } else {
                map.put(key, 1);
            }
        }

        Iterator iterator = map.keySet().iterator();
        while (iterator.hasNext()) {
            int key = (Integer) iterator.next();
            int occurrence = map.get(key);

            System.out.println(key + &quot; occur &quot; + occurrence + &quot; time(s).&quot;);
        }
    }
}

&lt;/pre&gt;
The result are:&lt;br /&gt;
&lt;br /&gt;
1 occur 2 time(s).&lt;br /&gt;
2 occur 1 time(s).&lt;br /&gt;
3 occur 4 time(s).&lt;br /&gt;
4 occur 3 time(s).&lt;br /&gt;
5 occur 2 time(s).&lt;br /&gt;
6 occur 1 time(s).&lt;br /&gt;
7 occur 1 time(s).&lt;br /&gt;
8 occur 1 time(s).&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/342962296871507185/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-count-occurrences-of-number-in.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/342962296871507185'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/342962296871507185'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-count-occurrences-of-number-in.html' title='How do I count the occurrences of a number in an array?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-8269446366126913245</id><published>2012-05-06T04:45:00.002-07:00</published><updated>2012-05-06T04:45:53.563-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>What is reference variable in Java?</title><content type='html'>The only way you can access an object is through a reference variable. A reference variable is declared to be of a specific type and that type can never be changed. Reference variables can be declared as static variables, instance variables, method parameters, or local variables.&lt;br /&gt;
&lt;br /&gt;
A reference variable that is declared final can&#39;t ever be reassigned to refer to a different object. The data within the object can be modified, but the reference variable cannot be changed.&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.fundametal;

public class ReferenceDemo {
    public static void main(String[] args) {
        //
        // declaration of reference variable
        //
        Reference ref1, ref2;
        
        // 
        // ref3 is declared final, it will cause it can reassign 
        // or refer to different object
        //
        final Reference ref3; 

        // 
        // assign ref1 with object Reference
        //
        ref1 = new Reference(&quot;This is the first reference variable&quot;, 1);
        
        //
        // access method getNumber() of object Reference through 
        // variable ref1
        //
        int number = ref1.getNumber(); 
        System.out.println(&quot;number= &quot; + number);

        // 
        // assign ref2 with object Reference
        //
        ref2 = new Reference(&quot;This is the second reference variable&quot;, 2);
        
        //
        // passing ref2 as method parameter of printText() method
        //
        ReferenceDemo.printText(ref2); 

        //
        // assign ref3 with object Reference
        //
        ref3 = new Reference(&quot;This is the third reference variable&quot;, 3);
        
        //
        // try to reassign ref3 will cause a compile-time error
        //
        //ref3 = new Reference(&quot;Try to reassign&quot;,3);

    }

    public static void printText(Reference reference) {
        String text = reference.getText();
        System.out.println(text);
    }
}

class Reference {
    private int number;
    private String text;

    Reference(String text, int number) {
        this.text = text;
        this.number = number;
    }

    public String getText() {
        return text;
    }

    public int getNumber() {
        return number;
    }
}

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/8269446366126913245/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/what-is-reference-variable-in-java.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/8269446366126913245'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/8269446366126913245'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/what-is-reference-variable-in-java.html' title='What is reference variable in Java?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-4382457361908214113</id><published>2012-05-06T04:44:00.004-07:00</published><updated>2012-05-06T04:44:40.710-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I use the ternary operator?</title><content type='html'>The ternary operator or conditional operator can be use as a short version of the if-then-else statement. When you have a simple if-then-else statement in your code that return a value you might use the ternary operator, it can make your code easier to read.&lt;br /&gt;
&lt;br /&gt;
The ternary operator is written using the symbol of ?: and it has the following syntax:&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
result = testCondition ? value1 : value2;&lt;br /&gt;
----------------------------------------&lt;br /&gt;
When the test condition evaluates to true the expression value1 will be returned else the expression value2 will be returned. The value1 or value2 is not only for a simple field or variable, it can be a call to a method for example. But it is advisable to use the ternary operator for a simple thing, because if you over do it, it will make your code harder to read.&lt;br /&gt;
&lt;br /&gt;
Let&#39;s see the following code:&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.lang;

public class TernaryOperatorDemo {
    public static void main(String[] args) {
        int a = 10;
        int b = 20;

        //
        // Get the maximum value
        //
        int min = a &lt; b ? a : b;

        //
        // The use of ternary operator above is an alternative
        // of the following if-then-else statement.
        //
        int minValue;
        if (a &lt; b) {
            minValue = a;
        } else {
            minValue = b;
        }

        //
        // Get the minimum value.
        //
        int max = a &gt; b ? a : b;

        //
        // Get the absolute value.
        //
        int abs = a &lt; 0 ? -a : a;

        System.out.println(&quot;min      = &quot; + min);
        System.out.println(&quot;minValue = &quot; + minValue);
        System.out.println(&quot;max      = &quot; + max);
        System.out.println(&quot;abs      = &quot; + abs);
    }
}

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/4382457361908214113/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-use-ternary-operator.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/4382457361908214113'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/4382457361908214113'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-use-ternary-operator.html' title='How do I use the ternary operator?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-4094942470643997706</id><published>2012-05-06T04:43:00.001-07:00</published><updated>2012-05-06T04:51:52.144-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I create custom exception class?</title><content type='html'>You can define your own exception class for your application specific purposes. The exception class is created by extending the java.lang.Exception class for checked exception or java.lang.RuntimeException for unchecked exception. By creating your own Exception classes, you could identify the problem more precisely.&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.fundametal;

public class CustomExceptionExample {
    public static void main(String[] args) {
        int x = 1, y = 0;

        try {
            int z = CustomExceptionExample.divide(x, y);
            System.out.println(&quot;z = &quot; + z);
        } catch (DivideByZeroException e) {
            e.printStackTrace();
        }

    }

    public static int divide(int x, int y)
            throws DivideByZeroException {
        try {
            return (x / y);
        } catch (ArithmeticException e) {
            String m = x + &quot; / &quot; + y + &quot;, trying to divide by zero&quot;;
            throw new DivideByZeroException(m, e);
        }
    }
}

class DivideByZeroException extends Exception {
    DivideByZeroException() {
    }

    DivideByZeroException(String message) {
        super(message);
    }

    DivideByZeroException(String message, Throwable cause) {
        super(message, cause);
    }
}

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/4094942470643997706/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-create-custom-exception-class.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/4094942470643997706'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/4094942470643997706'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-create-custom-exception-class.html' title='How do I create custom exception class?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-4957614668386754141</id><published>2012-05-06T02:03:00.019-07:00</published><updated>2012-05-06T02:03:46.767-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I do bitwise OR operation?</title><content type='html'>&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.lang;

public class ORDemo {
    public static void main(String[] args) {
        int numberA = 16;
        int numberB = 4;

        //
        // Operator &quot;|&quot; is used for doing bitwise OR operation
        //
        int result = numberA | numberB;

        System.out.println(numberA + &quot; | &quot; + numberB + &quot; = &quot; + result);

        //
        // Print the result in binary format
        //
        System.out.println(Integer.toBinaryString(numberA) +
                &quot; | &quot; + Integer.toBinaryString(numberB) +
                &quot; = &quot; + Integer.toBinaryString(result));
    }
}

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/4957614668386754141/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-do-bitwise-or-operation.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/4957614668386754141'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/4957614668386754141'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-do-bitwise-or-operation.html' title='How do I do bitwise OR operation?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-336883754778409694</id><published>2012-05-06T01:59:00.004-07:00</published><updated>2012-05-06T04:52:14.308-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I get name of enum constant?</title><content type='html'>This example demonstrate how to user enum&#39;s name() method to get enum constant name exactly as declared in the enum declaration.&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.fundametal;

enum ProcessStatus {
    IDLE, RUNNING, FAILED, DONE;

    @Override
    public String toString() {
        return &quot;Process Status: &quot; + this.name();
    }
}

public class EnumNameDemo {
    public static void main(String[] args) {
        for (ProcessStatus ps : ProcessStatus.values()) {
            //
            // Gets the name of this enum constant, exactly as
            // declared in its enum declaration.
            //
            System.out.println(ps.name());
            
            //
            // Here we call to our implementation of the toString
            // method to get a more friendly message of the
            // enum constant name.
            //
            System.out.println(ps.toString());
        }
    }
}

&lt;/pre&gt;Our program result:&lt;br /&gt;
&lt;br /&gt;
IDLE&lt;br /&gt;
Process Status: IDLE&lt;br /&gt;
RUNNING&lt;br /&gt;
Process Status: RUNNING&lt;br /&gt;
FAILED&lt;br /&gt;
Process Status: FAILED&lt;br /&gt;
DONE&lt;br /&gt;
Process Status: DONE&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/336883754778409694/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-get-name-of-enum-constant.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/336883754778409694'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/336883754778409694'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-get-name-of-enum-constant.html' title='How do I get name of enum constant?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-6939453412921821857</id><published>2012-05-06T01:59:00.000-07:00</published><updated>2012-05-06T04:52:25.486-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I use static import feature?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;In order to use a static member of a class in Java we have to qualify  the reference with the class name where they came from. For instance to  access the &lt;code&gt;PI&lt;/code&gt; and &lt;code&gt;abs()&lt;/code&gt; from the Math class we should write:&lt;br /&gt;
&lt;code&gt;double circle = Math.PI * 10;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;int absolute = Math.abs(-100);&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
For sometime you might want to call the members without the class name. This is allowed in Java 5.0 by using a feature called &lt;code&gt;static import&lt;/code&gt;.  It&#39;s an import statement that allows you to statically import static  class member. A static import declaration enables you to refer to  imported static members as if they were declared in the class that uses  them, the class name and a dot (.) are not required to use an imported  static member.&lt;br /&gt;
You can write something like the following to static import.&lt;br /&gt;
&lt;code&gt;import static java.lang.Math.PI;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;import static java.lang.Math.*;&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
For a clear code it is better to import each member separately and not using the &quot;*&quot; to import every static member in your code.&lt;br /&gt;
Let&#39;s a a simple static import below:&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.fundametal;

import static java.lang.Math.PI;
import static java.lang.Math.abs;
import static java.lang.System.out;
import java.util.Date;

public class StaticImport {
    public static void main(String[] args) {
        //
        // Using static field PI and static method abs() from the
        // java.lang.Math class.
        //
        double circle = PI * 10;
        int absolute = abs(-100);

        //
        // Using static field of the java.lang.System class to
        // print out the current date.
        //
        out.println(&quot;Today: &quot; + new Date());
    }
}
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/6939453412921821857/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-use-static-import-feature.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/6939453412921821857'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/6939453412921821857'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-use-static-import-feature.html' title='How do I use static import feature?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-1880542141505102583</id><published>2012-05-06T01:58:00.002-07:00</published><updated>2012-05-06T04:52:37.353-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I get the remainder of a division?</title><content type='html'>The remainder or modulus operator (%) let you get the remainder of a division of a two numbers. This operator can be used to obtain a reminder of an integer or floating point types.&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.lang;

public class RemainderOperatorDemo {
    public static void main(String[] args) {
        int a = 10;
        double b = 49;

        //
        // The reminder operator (%) gives your the remainder of
        // an integer or floating point division operation.
        //
        System.out.println(&quot;The result of &quot; + a + &quot; % 5 = &quot; + (a % 5));
        System.out.println(&quot;The result of &quot; + b + &quot; % 9.5 = &quot; + (b % 9.5));
    }
}

&lt;/pre&gt;Here is the result of the program:&lt;br /&gt;
&lt;br /&gt;
The result of 10 % 5 = 0&lt;br /&gt;
The result of 49.0 % 9.5 = 1.5&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/1880542141505102583/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-get-remainder-of-division.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/1880542141505102583'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/1880542141505102583'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-get-remainder-of-division.html' title='How do I get the remainder of a division?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4896915819228198386.post-1394210425186068604</id><published>2012-05-06T01:57:00.001-07:00</published><updated>2012-05-06T04:52:48.409-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="fundamental"/><title type='text'>How do I get ordinal value of enum constant?</title><content type='html'>This example demonstrate the use of enum ordinal() method to get the ordinal value of an enum constant.&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package org.kodejava.example.fundametal;

enum Color {
    RED, GREEN, BLUE
}

public class EnumOrdinal {
    public static void main(String[] args) {
        //
        // Gets the ordinal of this enumeration constant (its 
        // position in its enum declaration, where the initial 
        // constant is assigned an ordinal of zero)
        //
        System.out.println(&quot;Color.RED  : &quot; + Color.RED.ordinal());
        System.out.println(&quot;Color.GREEN: &quot; + Color.GREEN.ordinal());
        System.out.println(&quot;Color.BLUE : &quot; + Color.BLUE.ordinal());
    }
}

&lt;/pre&gt;&lt;br /&gt;
The program print the following result:&lt;br /&gt;
&lt;br /&gt;
Color.RED  : 0&lt;br /&gt;
Color.GREEN: 1&lt;br /&gt;
Color.BLUE : 2&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://javasag.blogspot.com/feeds/1394210425186068604/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-get-ordinal-value-of-enum.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/1394210425186068604'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4896915819228198386/posts/default/1394210425186068604'/><link rel='alternate' type='text/html' href='http://javasag.blogspot.com/2012/05/how-do-i-get-ordinal-value-of-enum.html' title='How do I get ordinal value of enum constant?'/><author><name>ITTube</name><uri>http://www.blogger.com/profile/09037110459849474107</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>