<?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-4985359605833593940</id><updated>2024-08-30T23:59:04.915+05:30</updated><category term="java"/><category term="jdk"/><category term="java variable"/><category term="datatype"/><category term="programs"/><category term="java application"/><category term="classes"/><category term="applets"/><category term="object"/><category term="literals"/><category term="HTML"/><category term="encapsulation"/><category term="java development"/><category term="java language"/><category term="java method"/><category term="subclasses"/><category term="unicode"/><title type='text'>Book of Java</title><subtitle type='html'>Spread the knowledge of java, java program, java language, programming language, java application, branching statement, looping in java, java method, applet, object, java string, class, java operator, java development, Unicode, java tutorial, java example, jdk</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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-4985359605833593940.post-6996757488338197407</id><published>2013-07-25T11:53:00.001+05:30</published><updated>2013-09-28T10:36:21.805+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java variable"/><title type='text'>Variables with a Fixed Set of Integer Values</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;text-align: justify;&quot;&gt;
You will usually would like variables which will have values solely from a predefined fastened set. for instance, suppose you wish to outline associate degree whole number variable with the name weekday, which can store associate degree whole number worth representing each day of the week. The variable ideally must be restricted to seven potential values, one for every of Monday through Sunday. this is often a state of affairs wherever a facility known as associate degree enumeration may be a natural alternative. you&#39;ll outline associate degree enumeration in Java for this case with the subsequent declaration statement:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
enum Day &lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This defines a replacement kind, Day, for variables which will store only 1 or alternative of the values such that between the braces. The names Monday, Tuesday, and then on through to Sunday square measure known as enumeration constants, and that they establish the sole values that square measure allowed for variables of kind Day. In fact, these names can correspond to whole number values, ranging from zero during this case, however they&#39;re not constant as whole number variables as a result of they exist solely inside the context of the enumeration, Day. Note the absence of a punctuation at the tip of the definition of the Day enumeration. as a result of you&#39;re shaping a kind here, no punctuation is needed once the closing brace. I used a capital D at the start of the kind name, Day,because by convention, sorts that you simply outline begin with a capital. The names for the enumeration constants would sometimes be written starting with a minuscule letter, however during this case I used a capital at the start as a result of that’s however the times of the week square measure sometimes written. you&#39;ll even as well write the enumeration constants with a minuscule letter.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/6996757488338197407/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2013/07/variables-with-fixed-set-of-integer.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/6996757488338197407'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/6996757488338197407'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2013/07/variables-with-fixed-set-of-integer.html' title='Variables with a Fixed Set of Integer Values'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-967569644371572859</id><published>2013-07-25T11:16:00.004+05:30</published><updated>2013-09-28T10:34:44.724+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java method"/><title type='text'>Importing the Math Class Methods</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;text-align: justify;&quot;&gt;
It would be a lot more convenient if you were able to avoid having to qualify the name of every method in the Math class that you use with the class name. The code would be a lot less cluttered if you could write floor(radius) instead of Math.floor(radius) for example. Well, you can. All you need to do is put the following statement at the beginning of the source file:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
import static java.lang.Math.*; // Import static class members&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This statement makes the names of all the static members of the Math class available for use in your &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java program&lt;/a&gt; code without having to qualify them with the class name. This includes constants such as PI as well as static methods. You can try this statement in the PondRadius example. With this statement at the beginning of the source file, you will be able to remove the qualification by the class name Math from all the members of this class that the program uses.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In the statement indicates that all static names are to be imported. If you wanted to import just the names from the Math class that the PondRadius program uses, you would write:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
import static java.lang.Math.floor; // Import floor&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
import static java.lang.Math.sqrt; // Import sqrt&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
import static java.lang.Math.round; // Import round&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
import static java.lang.Math.PI; // Import PI&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
These statements import individually the four names from the Math class that the program references. You could use these four statements at the beginning of the program in place of the previous &lt;a href=&quot;http://www.bookofjava.blogspot.com/2013/07/importing-math-class-methods.html&quot;&gt;import statement&lt;/a&gt; that imports all the static names.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/967569644371572859/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2013/07/importing-math-class-methods.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/967569644371572859'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/967569644371572859'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2013/07/importing-math-class-methods.html' title='Importing the Math Class Methods'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-8153906065609483694</id><published>2013-07-25T11:08:00.001+05:30</published><updated>2013-09-28T10:37:28.338+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="datatype"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><title type='text'>Automatic Type Conversions in Assignments</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;text-align: justify;&quot;&gt;
When the type of the result of an arithmetic expression on the right of an assignment operator differs from the type of the variable on the left, an automatic cast will be applied to the result as long as there is no possibility of losing information in &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java&lt;/a&gt; program. If you think of the basic types that we have seen so far as being in the sequence&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
byte =&amp;gt; short =&amp;gt; int =&amp;gt; long =&amp;gt; float =&amp;gt; double&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
then an &lt;a href=&quot;http://www.bookofjava.blogspot.com/2013/07/automatic-type-conversions-in.html&quot;&gt;automatic conversion&lt;/a&gt; will be made as long as it is upwards through the sequence of types, that is, from left to right. If you want to go in the opposite direction, from type double to type float or long, for example, then you must insert an explicit cast into your code for the result of the expression on&amp;lt; the right of the assignment operator.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/8153906065609483694/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2013/07/automatic-type-conversions-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/8153906065609483694'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/8153906065609483694'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2013/07/automatic-type-conversions-in.html' title='Automatic Type Conversions in Assignments'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-1268950900730012452</id><published>2013-07-24T17:19:00.003+05:30</published><updated>2013-09-28T10:38:50.076+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="datatype"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="jdk"/><title type='text'>Explicit Casting</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;text-align: justify;&quot;&gt;
It may well be that the default treatment of mixed expressions listed in the preceding section is not what you want. For example, suppose you have defined a double variable result; and two variables, three and two, of type int with the values 3 and 2, respectively. If you compute the value of result with the statement&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
result = 1.5 + three/two;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
the value stored will be 2.5, since three/two will be executed as an integer operation and will produce the result 1. You may have wanted the term three/two to produce the value 1.5 in &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java program&lt;/a&gt; so the overall result would be 3.0. You could do this using an &lt;a href=&quot;http://www.bookofjava.blogspot.com/2013/07/explicit-casting.html&quot;&gt;explicit cast&lt;/a&gt;:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
result = 1.5 + (double)three/two;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This causes the value stored in three to be converted to type double before the divide operation takes place. Then rule 1 applies for the divide operation, and the operand two is also converted to type double before the divide operation is executed.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/1268950900730012452/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2013/07/explicit-casting.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/1268950900730012452'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/1268950900730012452'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2013/07/explicit-casting.html' title='Explicit Casting'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-6504520333700565517</id><published>2013-07-24T16:26:00.002+05:30</published><updated>2013-09-28T10:40:06.314+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java variable"/><title type='text'>Fixing the Value of a Variable</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;text-align: justify;&quot;&gt;
Sometimes you will declare and initialize a variable with a value that should never change. For example:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
int feet_per_yard = 3;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
double mm_per_inch = 25.4;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Both these values should be fixed. There are always 3 feet to a yard, and an inch will always be 25.4 millimeters. Although they are fixed values for which you could use a literal in calculations, it is very convenient to store them in a variable because using suitable names makes it clear in your program what they mean. If you use the value 3 in your program code it could mean anything - but the name feet_per_yard leaves no doubt as to what it is.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
However, ideally you’d like to prevent these &lt;a href=&quot;http://www.bookofjava.blogspot.com/2013/07/fixing-value-of-variable.html&quot;&gt;variables&lt;/a&gt; from varying if possible. Accidental changes to the number of feet in a yard could make the results of your program suspect to say the least. &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java&lt;/a&gt; provides you with a way to fix the value of any variable by using the final keyword when you declare it. For example:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
final int FEET_PER_YARD = 3; // Constant values&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
final double MM_PER_INCH = 25.4; // that cannot be changed&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The final keyword specifies that the value of a variable is final and must not be changed. The compiler will check your code for any violations of this and flag them as errors. I’ve used uppercase letters for the names of the variables here because it is a convention in Java to write constants in this way. This makes it easy to see which variables are defined as constant values. Obviously, any variable you declare as final must have an initial value assigned, as you can’t specify it later.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Now that you know how to declare and initialize variables of the basic types, you are nearly ready to write a program. You just need to look at how you express the calculations you want carried out, and you store the results.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/6504520333700565517/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2013/07/fixing-value-of-variable.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/6504520333700565517'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/6504520333700565517'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2013/07/fixing-value-of-variable.html' title='Fixing the Value of a Variable'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-6391824097675603999</id><published>2013-07-24T13:41:00.001+05:30</published><updated>2013-09-28T11:50:30.667+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java variable"/><title type='text'>Declaring Floating-Point Variables</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;text-align: justify;&quot;&gt;
You &lt;a href=&quot;http://www.bookofjava.blogspot.com/2013/07/declaring-floating-point-variables.html&quot;&gt;declare floating-point variables&lt;/a&gt; in a similar way to what you’ve already used for integers. You can declare and initialize a variable of type double with the following statement:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
double sunDistance = 1.496E8;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This declares the variable with the name sunDistance and initializes it with the appropriate value. Declaring a variable of type float is much the same. For example:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
float electronMass = 9E-28F;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This defines and initializes the variable electronMass. You can, of course, declare more than one variable in &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;java program&lt;/a&gt; of a given type in a single statement:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
float hisWeight = 185.2F, herWeight = 108.5F;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Remember that you must put the F or f at the end of literals of type float. If you leave it out, the literal will be of type double, and the compiler won’t convert it automatically to type float.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/6391824097675603999/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2013/07/declaring-floating-point-variables.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/6391824097675603999'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/6391824097675603999'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2013/07/declaring-floating-point-variables.html' title='Declaring Floating-Point Variables'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-6694741264805749380</id><published>2013-07-24T13:36:00.002+05:30</published><updated>2013-09-28T11:50:57.166+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="literals"/><title type='text'>Floating-Point Literals</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;text-align: justify;&quot;&gt;
Floating-point literals are of type double by default, so 1.0 and 345.678 are both of type double. When you want to specify a value of type float, you just append an f, or an F, to the value, so 1.0f and 345.678F are both literals of type float. If you are new to programming it is important to note that you must not include commas as separators when specifying numerical values in your program code. Where you might normally write a value as 99,786.5, in your code you must write it without the comma, as 99786.5.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
When you need to write very large or very small &lt;a href=&quot;http://www.bookofjava.blogspot.com/2013/07/floating-point-literals.html&quot;&gt;floating-point&lt;/a&gt; values, you will usually want to write them with an exponent - that is, as a decimal value multiplied by a power of 10. You can do this in &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java&lt;/a&gt; by writing the number as a decimal value followed by an E, or an e, preceding the power of 10 that you require. For example, the distance from the Earth to the Sun is approximately 149,600,000 kilometers, more conveniently written as 1.496E8. Since the E (or e) indicates that what follows is the exponent, this is equivalent to 1.496 * 108. At the opposite end of the scale, the mass of an electron is around 0.0000000000000000000000000009 grams. This is much more convenient, not to say more readable, when it is written as 9.0E-28 grams.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/6694741264805749380/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2013/07/floating-point-literals.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/6694741264805749380'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/6694741264805749380'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2013/07/floating-point-literals.html' title='Floating-Point Literals'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-6840691274655401935</id><published>2013-07-24T13:30:00.001+05:30</published><updated>2013-09-28T11:51:15.979+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="datatype"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><title type='text'>Floating-Point Data Types</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;text-align: justify;&quot;&gt;
Numeric values that are not integral are stored as &lt;a href=&quot;http://www.bookofjava.blogspot.com/2013/07/floating-point-data-types.html&quot;&gt;floating-point&lt;/a&gt; numbers. A floating-point number has a fixed number of digits of accuracy but with a very wide range of values. You get a wide range of values,even though the number of digits is fixed, because the decimal point can “float.” For example, the values 0.000005, 500.0, and 5000000000000.0 can be written as 5×10-6, 5×102, and 5×1012 respectively - you have just one digit 5 but you get three different numbers by moving the decimal point around.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
There are two primitive floating-point types in Java, type float and type double. These give you a choice in the number of digits precision available to represent your data values, and in the range of values that can be accommodated:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
float : -3.4E38 (-3.4 * 1038) to +3.4E38 (+3.4 * 1038) and occupy 4 bytes&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
double : -1.7E308 (-1.7 * 10308) to +1.7E308 (+1.7 * 10308) and occupy 8 bytes&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
As with integer calculations, floating-point calculations in &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java&lt;/a&gt; will produce the same results on any computer.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/6840691274655401935/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2013/07/floating-point-data-types.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/6840691274655401935'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/6840691274655401935'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2013/07/floating-point-data-types.html' title='Floating-Point Data Types'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-2754095387534484481</id><published>2013-07-24T13:00:00.001+05:30</published><updated>2013-09-28T11:53:21.410+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java variable"/><title type='text'>Declaring Integer Variables</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;text-align: justify;&quot;&gt;
As you saw earlier, you can declare a variable of type long with the statement:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
long bigOne;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This statement is a declaration for the variable bigOne. This specifies that the variable bigOne will store a value of type long. When this statement is compiled, 8 bytes of memory will be allocated for the variable bigOne. &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java&lt;/a&gt; does not automatically initialize a &lt;a href=&quot;http://www.bookofjava.blogspot.com/2013/07/declaring-integer-variables.html&quot;&gt;variable&lt;/a&gt; such as this. If you want your variables to have an initial value rather than a junk value left over from when the memory was last used, you must specify your own value in the declaration. To declare and initialize the variable bigOne to 2999999999, you just write:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
long bigOne = 2999999999L;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The variable will be set to the value following the equal sign. It is good practice to always initialize your variables when you declare them. Note that if you try to use a variable in a calculation that has not had a value assigned to it, your program will not compile. There are also circumstances where the compiler cannot determine whether or not a variable has been initialized before it is used if you don’t initialize it when you declare it, even though it may be obvious to you that it has been. This will also be flagged as an error, but if you get into the habit of always initializing variables when you declare them, you’ll avoid all of these problems.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
You can declare a variable just about anywhere in your program, but you must declare each variable before you use it in a calculation. The placement of the declaration has an effect on whether a particular variable is accessible at a given point in a program, and we will look deeper into the significance of this in the next chapter. Broadly, you should group related variable declarations together, immediately before the block of code that uses them. You can declare and define multiple variables in a single statement. For example:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
long bigOne = 999999999L, largeOne = 100000000L;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Here I have declared two variables of type long. A comma separates each variable from the next. You can declare as many variables as you like in a single statement, although it is usually better to stick to declaring one variable in each statement, as it helps to make your programs easier to read. A possible exception occurs with variables that are closely related - an (x,y) coordinate pair representing a point, for example, which you might reasonably declare as:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
int xCoord = 0, yCoord = 0; // Point coordinates&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
On the same line as the declaration of these two variables, we have a comment following the double slash, explaining what they are about. The compiler ignores everything from the double slash (//) until the end of the line. Explaining in comments what your variables are for is a good habit to get into, as it can be quite surprising how something that was as clear as crystal when you wrote it transmogrifies into something as clear as mud a few weeks later. You can add comments to your programs in other ways that we will see a little later in this blog. You can also spread a single declaration over several lines if you want. This also can help to make your program more readable. For example:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
int miles = 0, // One mile is 8 furlongs&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
furlongs = 0, // One furlong is 220 yards&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
yards = 0, // One yard is 3 feet&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
feet = 0;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This defines four variables of type int in a single statement with the names miles, furlongs, yards, and feet. Each variable has 0 as its initial value. Naturally, you must be sure that an initializing value for a variable is within the range of the type concerned; otherwise, the compiler will complain. Your compiler is intelligent enough to recognize that you can’t get a quart into a pint pot, or, alternatively, a long constant into a variable of type int, short, or byte. Because the statement is spread over four lines, I am able to add a comment on each of the first three lines to explain something about the variable that appears on it. To complete the set of variables that store integers you can declare and initialize a variable of type byte and one of type short with the following two statements:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
byte luckyNumber = 7;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
short smallNumber = 1234;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Here the compiler can deduce that the integer literals are to be of type byte and short, respectively, and convert the literals to the appropriate type. It is your responsibility to make sure the initial value will fit within the range of the variable that you are initializing. If it doesn’t, the compiler will reject the statement and output an error message.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Most of the time you will find that variables of type int will cover your needs for dealing with integers, with type long being necessary now and again when you have some really big integer values to deal with. Variables of type byte and short do save a little memory, but unless you have a lot of values of these types to store, that is, values with a very limited range, they won’t save enough to be worth worrying about. They also introduce complications when you use them in calculations, as you’ll see shortly, so generally you should not use them unless it is absolutely necessary. Of course, when you are reading data from some external source, a disk file for instance, you’ll need to make the type of variable for each data value correspond to what you expect to read.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/2754095387534484481/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2013/07/declaring-integer-variables.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/2754095387534484481'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/2754095387534484481'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2013/07/declaring-integer-variables.html' title='Declaring Integer Variables'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-3505414172644996790</id><published>2013-07-24T12:32:00.000+05:30</published><updated>2013-09-28T11:53:41.108+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="literals"/><title type='text'>Integer Literals</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;text-align: justify;&quot;&gt;
An integer variable stores an integer value, so before you get to use integer variables you need to understand how you write integer values of various types. As I said earlier, a value of any kind in Java is referred to as a literal. So 1, 10.5, and “This is text” are all examples of literals.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Any &lt;a href=&quot;http://www.bookofjava.blogspot.com/2013/07/integer-literals.html&quot;&gt;integer literal&lt;/a&gt; that you specify as a sequence of decimal digits is of type int by default. Thus 1, -9999, and 123456789 are all literals of type int. If you want to define an integer literal of type long, you need to append an L to the value. The values 1L, -9999L, and 123456789L are all of type long. You can also use a lowercase letter l, but don’t - it is too easily confused with the digit 1.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
You are perhaps wondering how you specify literals of type byte or short. Because of the way integer arithmetic works in Java, they just aren’t necessary in the main. You’ll see a couple of instances where an integer literal may be interpreted by the compiler as type byte or short later in this chapter, but these situations are the exception.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
You can also specify integer literals to base 16 - in other words, as hexadecimal numbers. Hexadecimal literals in &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java&lt;/a&gt; have 0x or 0X in front of them and follow the usual convention of using the letters A to F (or a to f) to represent digits with values 10 to 15, respectively. In case you are a little rusty on hexadecimal values.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
If you are not familiar with hexadecimal numbers, you can find an explanation of how these work in Appendix B. All the hexadecimal literals in the preceding table are of type int. If you want to specify a hexadecimal literal of type long, you must append L to the literal just as with decimal literals. For example,0x0FL is a hexadecimal literal that is equivalent to the decimal value 15.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
There is a further possibility for integer literals - you can also define them as octal values, which is to base 8, and legal digits in an octal literal can be from 0 to 7. You write literals that are octal numbers with a leading zero, so 035 and 067 are examples of octal numbers. Each octal digit defines 3 bits, so this number base was used a lot more frequently in the days when machines used words of lengths that were a multiple of 3 bits to store a number. You will rarely find it necessary to use octal numbers these days, but you should take care not to use them by accident. If you put a leading zero at the start of an integer literal,the Java compiler will think you are specifying an octal value. Unless one of the digits is greater than 7, which results in the compiler flagging it as an error, you won’t know that you have done this.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/3505414172644996790/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2013/07/integer-literals.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/3505414172644996790'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/3505414172644996790'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2013/07/integer-literals.html' title='Integer Literals'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-7896268716764841925</id><published>2013-07-24T11:33:00.000+05:30</published><updated>2013-09-28T11:56:28.483+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="datatype"/><category scheme="http://www.blogger.com/atom/ns#" term="java variable"/><title type='text'>Integer Data Types</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;text-align: justify;&quot;&gt;
There are four types of variables that you can use to store &lt;a href=&quot;http://www.bookofjava.blogspot.com/2013/07/integer-data-types.html&quot;&gt;integer data&lt;/a&gt;. All of these are signed; that is,they can store both negative and positive values. The four integer types differ in the range of values they can store, so the choice of type for a variable depends on the range of data values you are likely to need. The four integer types in Java are:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
byte : -128 to +127 and occupy 1 byte (8 bits)&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
short : -32768 to 32767 and occupy 2 bytes (16 bits)&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
int  : -2147483648 to 2147483647 and occupy 4 bytes (32 bits)&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
long : -9223372036854775808 to 9223372036854775807 and occupy 8 bytes (64 bits)&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Although I said the choice of type depends on the range of values that you want to be able to store, in practice you’ll be using variables of type int or type long to store integers most of the time, for reasons that I’ll explain a little later. Let’s take a look at declarations of variables of each of these types:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
byte smallerValue;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
short pageCount;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
int wordCount;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
long bigValue;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Each of these statements declares a variable of the type specified.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The range of values that can be stored by each integer type in &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java&lt;/a&gt;, as shown in the preceding table, is always the same, regardless of what kind of computer you are using. This is also true of the other primitive types that you will see later in this chapter and has the rather useful effect that your program will execute in the same way on computers that may be quite different. This is not necessarily the case with other programming languages.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Of course, although I have expressed the range of possible values for each type as decimal values, integers are stored internally as binary numbers, and it is the number of bits available to store each type that determines the maximum and minimum values.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
For each of the binary numbers shown here, the leftmost bit is the sign bit, marked with an s. When the sign bit is 0 the number is positive, and when it is 1 the number is negative. Binary negative numbers are represented in what is called 2’s complement form. If you are not familiar with this, you will find an explanation of how it works in Appendix B.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/7896268716764841925/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2013/07/integer-data-types.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/7896268716764841925'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/7896268716764841925'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2013/07/integer-data-types.html' title='Integer Data Types'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-2600762583406865834</id><published>2013-07-24T11:16:00.005+05:30</published><updated>2013-09-28T11:57:23.485+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="datatype"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java variable"/><title type='text'>Variables and Types</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;text-align: justify;&quot;&gt;
As I mentioned earlier, each variable that you declare can store values only of a type consistent with the data type of that variable. You specify the type of a particular variable by using a type name in the variable declaration. For instance, here’s a statement that declares a variable that can store integers:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
int numberOfCats;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The data type in this case is int and the &lt;a href=&quot;http://www.bookofjava.blogspot.com/2013/07/variables-and-types.html&quot;&gt;variable&lt;/a&gt; name is numberOfCats. The semicolon marks the end of the statement. The variable, numberOfCats, can only store values of type int. Of course, int is a keyword. Many of your variables will be used to reference objects, but let’s leave those on one side for the moment,as they have some special properties. The only things in Java that are not objects are variables that correspond to one of eight basic data types, defined within the language. These fundamental types are referred to as primitive types, and they allow you to define variables for storing data that fall into one of three categories:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
[1] Numeric values, which can be either integer or floating point&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
[2] Variables that store the code for a single Unicode character&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
[3] Logical variables that can assume the values true or false&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
All of the type names for the basic variable types are keywords in &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java&lt;/a&gt; so you must not use them for other purposes. Let’s take a closer look at each of the primitive data types and get a feel for how you can use them.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/2600762583406865834/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2013/07/variables-and-types.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/2600762583406865834'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/2600762583406865834'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2013/07/variables-and-types.html' title='Variables and Types'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-6908743962821219633</id><published>2013-07-24T11:08:00.001+05:30</published><updated>2013-09-28T11:57:43.289+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java variable"/><title type='text'>Variable Names and Unicode</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;text-align: justify;&quot;&gt;
Even though you may be entering your &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java programs&lt;/a&gt; in an environment that stores ASCII characters,all Java source code is in Unicode. Although the original source code that you create may be ASCII, it is converted to Unicode characters internally, before it is compiled. While you can write any Java language statement using ASCII, the fact that Java supports &lt;a href=&quot;http://www.bookofjava.blogspot.com/2013/07/variable-names-and-unicode.html&quot;&gt;Unicode&lt;/a&gt; provides you with immense flexibility. It means that the identifiers that you use in your source program can use any national language character set that is defined within the Unicode character set, so your programs can use French, Greek, or Russian variable names, for example, or even names in several different languages, as long as you have the means to enter them in the first place. The same applies to character data that your program defines.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/6908743962821219633/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2013/07/variable-names-and-unicode.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/6908743962821219633'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/6908743962821219633'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2013/07/variable-names-and-unicode.html' title='Variable Names and Unicode'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-1314342507733951328</id><published>2013-07-23T12:48:00.000+05:30</published><updated>2013-09-28T11:58:06.237+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="datatype"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java variable"/><title type='text'>Naming Your Variables</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;text-align: justify;&quot;&gt;
The name that you choose for a variable, or indeed the name that you choose for anything in Java, is called an identifier. An identifier can be any length, but it must start with a letter, an underscore (_), or a dollar sign ($). The rest of an identifier can include any characters except those used as operators in &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java&lt;/a&gt; (such as +, –, or *), but you will be generally better off if you stick to letters, digits, and the underscore character.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Java is case-sensitive, so the names republican and Republican are not the same. You must not include blanks or tabs in the middle of a name, so Betty May is out but you could have BettyMay or even Betty_May. Note that you can’t have 6Pack as a name since you cannot start a name with a numeric digit. Of course, you could use sixPack as an alternative.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Subject to the restrictions I have mentioned, you can &lt;a href=&quot;http://www.bookofjava.blogspot.com/2013/07/naming-your-variables.html&quot;&gt;name a variable&lt;/a&gt; almost anything you like, except for two additional restraints - you can’t use keywords in Java as a name for something, and a name can’t be anything that could be interpreted as a constant value - as a literal, in other words. Keywords are words that are an essential part of the Java language. You saw some keywords in the previous chapter,and you will learn a few more in this chapter. If you’d like to know what they all are now, see the complete list in Appendix A. The restriction on constant values is there because, although it is obvious why a name can’t be 1234 or 37.5, constants can also be alphabetic, such as true and false, for example,which are literals of type boolean. Of course, the basic reason for these rules is that the compiler has to be able to distinguish between your variables and other things that can appear in a program. If you try to use a name for a variable that makes this impossible, then it’s not a legal name.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/1314342507733951328/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2013/07/naming-your-variables.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/1314342507733951328'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/1314342507733951328'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2013/07/naming-your-variables.html' title='Naming Your Variables'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-5462288276242861678</id><published>2013-07-23T12:42:00.001+05:30</published><updated>2013-09-28T12:01:28.472+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="datatype"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java variable"/><title type='text'>Data and Variables</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;text-align: justify;&quot;&gt;
A variable is a named piece of memory that you use to store information in your &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java program&lt;/a&gt; a piece of data of some description. Each named piece of memory that you define in your program is able to store data only of one particular type. If you define a variable to store integers, for example,you can’t use it to store a value that is a decimal fraction, such as 0.75. If you’ve defined a &lt;a href=&quot;http://www.bookofjava.blogspot.com/2013/07/data-and-variables.html&quot;&gt;variable&lt;/a&gt; that you use to refer to a Hat object, you can only use it to reference an object of type Hat. Since the type of data that each variable can store is fixed, the compiler can verify that each variable you define in your program is not used in a manner or a context that is inappropriate to its type. If a method in your program is supposed to process integers,the compiler will be able to detect when you inadvertently try to use the method with some other kind of data - for example, a string or a numerical value that is not integral.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Explicit data values that appear in your program are called literals. Each literal will also be of a particular type: 25, for example, is an integer literal of type int. I will go into the characteristics of the various types of literals that you can use as I discuss each variable type.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Before you can use a variable you must specify its name and type in a declaration statement. Before I describe how you write a declaration for a variable, let’s consider what flexibility you have in choosing a name.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/5462288276242861678/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2013/07/data-and-variables.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/5462288276242861678'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/5462288276242861678'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2013/07/data-and-variables.html' title='Data and Variables'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-2179630895887149075</id><published>2013-07-23T12:41:00.003+05:30</published><updated>2013-09-28T12:02:02.589+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="unicode"/><title type='text'>Java and Unicode</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;text-align: justify;&quot;&gt;
Programming to support languages that use anything other than the Latin character set has always been a major problem. There are a variety of 8-bit character sets defined for many national languages, but if you want to combine the Latin character set and Cyrillic in the same context, for example, things can get difficult. If you want to handle Japanese as well, it becomes impossible with an 8-bit character set because with 8 bits you have only 256 different codes so there just aren’t enough character codes to go round. &lt;a href=&quot;http://www.bookofjava.blogspot.com/2013/07/java-and-unicode.html&quot;&gt;Unicode&lt;/a&gt; is a standard character set that was developed to allow the characters necessary for almost all languages to be encoded. It uses a 16-bit code to represent a character (so each character occupies 2 bytes), and with 16 bits up to 65,535 non-zero character codes can be distinguished. With so many character codes available, there is enough to allocate each major national character set its own set of codes, including character sets such as Kanji, which is used for Japanese and which requires thousands of character codes. It doesn’t end there though. Unicode supports three encoding forms that allow up to a million additional characters to be represented.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
I say each Unicode character usually occupies 2 bytes because &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java&lt;/a&gt; supports Unicode 4.0, which allows 32-bit characters called surrogates. You might think that the set of 64K characters that you can represent with 16 bits would be sufficient, but it isn’t. Far-eastern languages such as Japanese, Korean, and Chinese alone involve more than 70,000 ideographs, and surrogates are used to represent characters that are not contained within the basic multilingual set that is defined by 16-bit characters.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/2179630895887149075/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2013/07/java-and-unicode.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/2179630895887149075'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/2179630895887149075'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2013/07/java-and-unicode.html' title='Java and Unicode'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-5506461089068586976</id><published>2013-07-23T12:15:00.002+05:30</published><updated>2013-09-28T12:03:41.175+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java application"/><title type='text'>Java Applications</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;text-align: justify;&quot;&gt;
Every Java application contains a class that defines a method called main(). The name of this class is the name that you use as the argument to the Java interpreter when you run the application. You can call the class whatever you want, but the method which is executed first in an application is always called main(). When you run your &lt;a href=&quot;http://www.bookofjava.blogspot.com/2013/07/java-applications.html&quot;&gt;Java application&lt;/a&gt;, the method main() will typically cause methods belonging to other classes to be executed, but the simplest possible Java application program consists of one class containing just the method main(). As you will see below, the main() method has a particular fixed form, and if it is not of the required form, it will not be recognized by the Java interpreter as the method where execution starts.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
You can see how this works by taking a look at just such a Java program. You need to enter the program code using your favorite plaintext editor, or if you have a Java development system with an editor, you can enter the code for the example using that. When you have entered the code, save the file with the same name as that used for the class and with the extension .java. For this example the file name will be OurFirstProgram.java. The program consists of a definition for a class I have called OurFirstProgram. The class definition contains only one method, the method main(). The first line of the definition for the method main() is always of the form:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
public static void main(String[] args)&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The code for the method appears between the pair of curly braces. This version of the method has only one executable statement:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
System.out.println(“Krakatoa, EAST of Java??”);&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
So what does this statement do? Let’s work through it from left to right:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
[1] System is the name of a standard class that contains objects that encapsulate the standard I/O devices for your system - the keyboard for command-line input and command-line output to the display. It is contained in the package java.lang, so it is always accessible just by using the simple class name System.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
[2] The object out represents the standard output stream - the command line on your display screen - and is a data member of the class System. The member, out, is a special kind of member of the System class. Like the method main() in our OurFirstProgram class, it is static. This means that out exists even though there are no objects of type System. Using the class name, System, separated from the member name out by a period - System.out - references the out member.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
[3] The bit at the rightmost end of the statement, println(“Krakatoa, EAST of Java??”),calls the println() method that belongs to the object out, and that outputs the text string that appears between the parentheses to your display. This demonstrates one way in which you can call a class method - by using the object name followed by the method name, with a period separating them. The stuff between the parentheses following the name of a method is information that is passed to the method when it is executed. As we said, for println() it is the text we want to output to thebcommand line. You can compile this program using the JDK compiler with the command&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
javac OurFirstProgram.java&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
or with the -classpath option specified:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
javac –classpath . OurFirstProgram.java&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
If it didn’t compile, there’s something wrong somewhere. Here’s a checklist of possible sources of the problem:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
[4] You forgot to include the path to the jdk1.5.0\bin directory in your PATH, or maybe you did not specify the path correctly. This will result in your operating system not being able to find the javac compiler that is in that directory.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
[5] You made an error typing in the program code. Remember &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java&lt;/a&gt; is case-sensitive, so OurfirstProgram is not the same as OurFirstProgram, and of course, there must be no spaces in the class name. If the compiler discovers an error, it will usually identify the line number in the code where the error was found. In general, watch out for confusing zero, 0, with a small letter o,or the digit one, 1, with the small letter l. All characters such as periods, commas, and semicolons in the code are essential and must be in the right place. Parentheses, (), curly braces, {}, and square brackets, [], always come in matching pairs and are not interchangeable.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
[6] The source file name must match the class name exactly. The slightest difference will result in an&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
error. It must have the extension .java. Once you have compiled the program successfully, you can execute it with the command:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
java –ea OurFirstProgram&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The -ea option is not strictly necessary since this program does not use assertions, but if you get used to putting it in, you won’t forget it when it is necessary. If you need the -classpath option specified:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
java –ea –classpath . OurFirstProgram&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Assuming the source file compiled correctly, and the jdk1.5.0\bin directory is defined in your path,
the most common reason for the program failing to execute is a typographical error in the class name,
OurFirstProgram. The second most common reason is writing the file name, OurFirstProgram.class,
in the command, whereas it should be just the class name, OurFirstProgram. &lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/5506461089068586976/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2013/07/java-applications.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/5506461089068586976'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/5506461089068586976'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2013/07/java-applications.html' title='Java Applications'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-6780953374460668544</id><published>2012-01-08T19:47:00.002+05:30</published><updated>2013-09-28T12:06:54.588+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="classes"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="jdk"/><title type='text'>Java’s Class Library</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;text-align: justify;&quot;&gt;
A library in Java is a collection of classes - usually providing related facilities - that you can use in your programs. The Java class library provides you with a whole range of goodies, some of which are essential for your programs to work at all, and some of which make writing your Java programs easier. To say that the standard class library covers a lot of ground would be something of an understatement, so I won’t be going into it in detail here; however, you will be looking into how to apply many of the facilities it provides throughout the &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;book of Java&lt;/a&gt;.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Since the &lt;a href=&quot;http://www.bookofjava.blogspot.com/2012/01/javas-class-library.html&quot;&gt;class library&lt;/a&gt; is a set of classes, it is stored in sets of files where each file contains a class definition. The classes are grouped together into related sets that are called packages, and each package is stored in a separate directory. A class in a package can access any of the other classes in the package. A class in another package may or may not be accessible.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The package name is based on the path to the directory in which the classes belonging to the package are stored. Classes in the package java.lang for example are stored in the directory path java\lang (or java/lang under Unix). This path is relative to a particular directory that is automatically known by the Java run-time environment that executes your code. You can also create your own packages that will contain classes of your own that you want to reuse in different contexts, and that are related in some way.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The JDK includes a growing number of standard packages - well over 100 the last time I counted. Some of the packages you will meet most frequently are:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
[1] java.lang :-&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
These classes support the basic language features and the handling of arrays and strings. Classes in this package are always available directly in your programs by default because this package is always automatically loaded with your program.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
[2] java.io :-&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Classes for data input and output operations.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
[3] java.util :-&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This package contains utility classes of various kinds, including classes for managing data within collections or groups of data items.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
[4] javax.swing :-&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
These classes provide easy-to-use and flexible components for building graphical user interfaces (GUIs). The components in this package are referred to as Swing components.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
[5] java.awt :-&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Classes in this package provide the original GUI components (JDK 1.1) as well as some basic support necessary for Swing components. java.awt.geom These classes define two-dimensional geometric shapes.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
[6] java.awt.event :-&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The classes in this package are used in the implementation of windowed applications to handle events in your program. Events are things like moving the mouse, pressing the left mouse button, or clicking on a menu item.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
As noted previously, you can use any of the classes from the java.lang package in your programs by default. To use classes from the other packages, you typically use import statements to identify the names of the classes that you need from each package. This allows you to reference the classes by the simple class name. Without an import statement you would need to specify the fully qualified name of each class from a package each time you refer to it. As we will see in a moment, the fully qualified name for a class includes the package name as well as the basic class name. Using fully qualified class names would make your program code rather cumbersome, and certainly less readable. It would also make them a lot more tedious to type in.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
You can use an import statement to import the name of a single class from a package into your program, or all the class names. The two import statements at the beginning of the code for the applet you saw earlier in this post are examples of importing a single class name. The first was:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
import javax.swing.JApplet;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This statement imports the JApplet class name that is defined in the javax.swing package. Formally, the name of the JApplet class is not really JApplet - it is the fully qualified name javax.swing.JApplet. You can use the unqualified name only when you import the class or the complete package containing it into your program. You can still reference a class from a package even if you don’t import it though - you just need to use the full class name, javax.swing.JApplet. You could try this out with the applet you saw earlier if you like. Just delete the two import statements from the file and use the full class names in the program. Then recompile it. It should work the same as before. Thus, the fully qualified name for a class is the name of the package in which it is defined, followed by a period, followed by the name given to the class in its definition. You could import the names of all the classes in the javax.swing package with the statement:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
import javax.swing.*;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The asterisk specifies that all the class names are to be imported. Importing just the class names that your source code uses makes compilation more efficient, but when you are using a lot of classes from a package you may find it more convenient to import all the names. This saves typing reams of import statements for one thing. We will do this with examples of Java code in the book to keep the number of lines to a minimum. However, there are risks associated with importing all the names in a package. There may be classes with names that are identical to names you have given to your own classes, which would obviously create some confusion when you compile your code.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
As I indicated earlier, the standard classes do not appear as files or directories on your hard disk. They are packaged up in a single compressed file, rt.jar, that is stored in the jre/lib directory. This directory is created when you install the JDK on your computer. A .jar file is a Java archive - a compressed archive of Java classes. The standard classes that your executable program requires are loaded automatically from rt.jar, so you don’t have to be concerned with it directly at all.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/6780953374460668544/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2012/01/javas-class-library.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/6780953374460668544'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/6780953374460668544'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2012/01/javas-class-library.html' title='Java’s Class Library'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-4297104867364569305</id><published>2012-01-08T19:36:00.000+05:30</published><updated>2013-09-28T12:07:15.816+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="jdk"/><category scheme="http://www.blogger.com/atom/ns#" term="programs"/><title type='text'>Java Program Structure</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;text-align: justify;&quot;&gt;
Let’s summarize how a &lt;a href=&quot;http://www.bookofjava.blogspot.com/2012/01/java-program-structure.html&quot;&gt;Java program&lt;/a&gt; is structured:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
[1] A Java program always consists of one or more classes.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
[2] You typically put the program code for each class in a separate file, and you must give each file the same name as that of the class that is defined within it.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
[3] A &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java&lt;/a&gt; source file name must have the extension .java. Thus your file containing the class Hat will be called Hat.java and your file containing the class BaseballPlayer must have the file name BaseballPlayer.java.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This program clearly majors on apparel, with four of the five classes representing clothing. Each source file contains a class definition, and all of the files that go to make up the program are stored in the same directory. The source files for your program contain all the code that you wrote, but this is not everything that is ultimately included in the program. There is also code from the Java standard class library, so let’s take a peek at what that can do.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/4297104867364569305/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2012/01/java-program-structure.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/4297104867364569305'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/4297104867364569305'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2012/01/java-program-structure.html' title='Java Program Structure'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-4681729904400633168</id><published>2012-01-08T19:29:00.000+05:30</published><updated>2013-09-28T12:07:32.596+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="object"/><category scheme="http://www.blogger.com/atom/ns#" term="programs"/><title type='text'>Advantages of Using Objects</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;text-align: justify;&quot;&gt;
As I said at the outset, object-oriented programs are written using objects that are specific to the problem being solved. Your pinball machine simulator may well define and use objects of type Table, Ball, Flipper, and Bumper. This has tremendous advantages, not only in terms of easing the development process and making the program code easier to understand, but also in any future expansion of such a program. &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java&lt;/a&gt; provides a whole range of standard classes to help you in the development of your program, and you can develop your own generic classes to provide a basis for developing programs that are of particular interest to you.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Because an &lt;a href=&quot;http://www.bookofjava.blogspot.com/2012/01/advantages-of-using-objects.html&quot;&gt;object&lt;/a&gt; includes the methods that can operate on it as well as the data that defines it, programming using objects is much less prone to error. Your object-oriented Java programs should be more robust than the equivalent in a procedural programming language. Object-oriented programs take a little longer to design than programs that do not use objects since you must take care in the design of the classes that you will need, but the time required to write and test the code is sometimes substantially less than that for procedural programs. Object-oriented programs are also much easier to maintain and extend.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/4681729904400633168/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2012/01/advantages-of-using-objects.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/4681729904400633168'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/4681729904400633168'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2012/01/advantages-of-using-objects.html' title='Advantages of Using Objects'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-1037968288354203506</id><published>2012-01-08T19:26:00.000+05:30</published><updated>2013-09-28T12:07:52.764+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="classes"/><category scheme="http://www.blogger.com/atom/ns#" term="subclasses"/><title type='text'>Classes and Subclasses</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;text-align: justify;&quot;&gt;
Many sets of objects that you might define in a class can be subdivided into more specialized subsets that can also be represented by classes, and &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java&lt;/a&gt; provides you with the capability to define one class as a more specialized version of another. This reflects the nature of reality. There are always lots of ways of dividing a cake - or a forest. Conifer, for example, could be a subclass of the class Tree. The Conifer class would have all the instance variables and methods of the Tree class, plus some additional instance variables and/or methods that make it a Conifer in particular.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
You refer to the Conifer &lt;a href=&quot;http://www.bookofjava.blogspot.com/2012/01/classes-and-subclasses.html&quot;&gt;class as a subclass&lt;/a&gt; of the class Tree, and the class Tree as a superclass of the class Conifer. When you define a class such as Conifer using another class such as Tree as a starting point, the class Conifer is said to be derived from the class Tree, and the class Conifer inherits all the attributes of the class Tree.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/1037968288354203506/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2012/01/classes-and-subclasses.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/1037968288354203506'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/1037968288354203506'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2012/01/classes-and-subclasses.html' title='Classes and Subclasses'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-2874157133230730166</id><published>2012-01-08T19:24:00.000+05:30</published><updated>2013-09-28T12:08:07.149+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="classes"/><category scheme="http://www.blogger.com/atom/ns#" term="datatype"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="jdk"/><title type='text'>Classes and Data Types</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;text-align: justify;&quot;&gt;
Programming is concerned with specifying how data of various kinds is to be processed, massaged, manipulated, or transformed. Since classes define the types of objects that a program will work with, you can consider defining a class to be the same as defining a &lt;a href=&quot;http://www.bookofjava.blogspot.com/2012/01/classes-and-data-types.html&quot;&gt;data type&lt;/a&gt;. Thus, Hat is a type of data, as is Tree, and any other class you care to define. Java also contains a library of standard classes that provide you with a whole range of programming tools and facilities. For the most part then, your Java program will process, massage, manipulate, or transform class objects.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
There are some basic types of data in Java that are not classes, and these are called primitive types. I will go into these in detail in the next chapter, but they are essentially data types for numeric values such as 99 or 3.75, for single characters such as A or ?, and for logical values that can be true or false. Java also has classes that correspond to each of the primitive data types for reasons that you will see later on, so there is an Integer class that defines objects that encapsulate integers, for example. Every entity in your &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java program&lt;/a&gt; that is not of a primitive data type will be an object of a class - either a class that you define yourself, a class supplied as part of the Java environment, or a class that you obtain from somewhere else, such as from a specialized support package.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/2874157133230730166/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2012/01/classes-and-data-types.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/2874157133230730166'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/2874157133230730166'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2012/01/classes-and-data-types.html' title='Classes and Data Types'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-1492598025033542297</id><published>2012-01-08T19:21:00.000+05:30</published><updated>2013-09-28T12:08:21.915+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="encapsulation"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java application"/><category scheme="http://www.blogger.com/atom/ns#" term="jdk"/><title type='text'>Encapsulation</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;text-align: justify;&quot;&gt;
At this point we can introduce another bit of jargon you can use to impress or bore your friends - encapsulation. &lt;a href=&quot;http://www.bookofjava.blogspot.com/2012/01/encapsulation.html&quot;&gt;Encapsulation&lt;/a&gt; refers to the hiding of items of data and methods within an object. This is achieved by specifying them as private in the definition of the class. In the CowboyHat class, the instance variables owner, type, size, and hatOn were encapsulated. They were accessible only through the methods defined for the class. Therefore, the only way to alter the values they contain is to call a method that does that. Being able to encapsulate members of a class in this way is important for the security and integrity of class objects. You may have a class with data members that can take on only particular values. By hiding the data members and forcing the use of a method to set or change the values, you can ensure that only legal values are set.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
I mentioned earlier another major advantage of encapsulation - the ability to hide the implementation of a class. By allowing only limited access to the members of a class, you have the freedom to change the internals of the class without necessitating changes to &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java programs&lt;/a&gt; that use the class. As long as the external characteristics of the methods that can be called from outside the class remain unchanged, the internal code can be changed in any way that you, the programmer, want.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
A particular object, an instance of CowboyHat, incorporates, or encapsulates, the owner, the size of the object, and the status of the hat in the instance variable hatOn. Only the constructor, and the putHatOn(), takeHatOff(), changeOwner(), and getSize() methods can be accessed externally.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/1492598025033542297/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2012/01/encapsulation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/1492598025033542297'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/1492598025033542297'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2012/01/encapsulation.html' title='Encapsulation'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-4016101233232066167</id><published>2012-01-08T19:18:00.000+05:30</published><updated>2013-09-28T12:08:42.206+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="jdk"/><category scheme="http://www.blogger.com/atom/ns#" term="programs"/><title type='text'>Java Program Statements</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;text-align: justify;&quot;&gt;
As you saw in the CowboyHat class example, the code for each method in the class appears between braces, and it consists of program statements. A semicolon terminates each program statement. A statement in &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java&lt;/a&gt; can spread over several lines if necessary, since the end of each statement is determined by the semicolon, not by the end of a line. Here is a Java program statement:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
hatOn = false;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
If you wanted to, you could also write this as:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
hatOn =
false;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
You can generally include spaces and tabs, and spread your statements over multiple lines to enhance readability if it is a particularly long &lt;a href=&quot;http://www.bookofjava.blogspot.com/2012/01/java-program-statements.html&quot;&gt;statement&lt;/a&gt;, but sensible constraints apply. You can’t put a space in the middle of a name for instance. If you write hat On, for example, the compiler will read this as two words.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/4016101233232066167/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2012/01/java-program-statements.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/4016101233232066167'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/4016101233232066167'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2012/01/java-program-statements.html' title='Java Program Statements'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4985359605833593940.post-2793230313018518229</id><published>2012-01-08T19:16:00.000+05:30</published><updated>2013-09-28T12:12:50.609+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="classes"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="jdk"/><category scheme="http://www.blogger.com/atom/ns#" term="object"/><title type='text'>Operating on Objects</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;text-align: justify;&quot;&gt;
A class object is not just a collection of various items of data. In addition to the parameters that characterize an object, a class specifies what you can do with an &lt;a href=&quot;http://www.bookofjava.blogspot.com/2012/01/operating-on-objects.html&quot;&gt;object of the class&lt;/a&gt; - that is, it defines the operations that are possible on objects of the class. Clearly, for objects to be of any use in a program, you need to decide what you can do with them. The operations that you specify for objects of a given type will depend on what sort of objects you are talking about, the attributes they contain, and how you intend to use them.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
For the CowboyHat class, you may want to have operations that you could refer to as putHatOn and takeHatOff, which would have meanings that are fairly obvious from their names, and do make sense for CowboyHat objects. These operations on a particular CowboyHat object would set the value of hatOn for the object. To determine whether your CowboyHat was on or off, you would just need to look at this value. Conceivably, you might also have an operation changeOwner by which you could set the instance variable recording the current owner’s name to a new value.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Of course, for each type of object you can have any operation that makes sense for you. If you want to have a shootHoleIn operation for Hat objects, that’s no problem. You just have to define what that operation does to an object. You are probably wondering at this point how an operation for a class is defined. As you’ll see in detail a bit later, it boils down to a self-contained block of program code called a method that is identified by the name you give to it. You can pass data items - which can be integers, floating-point numbers, character strings, or class objects - to a method, and these will be processed by the code in the method.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
A method may also return a data item as a result. Performing an operation on an object amounts to executing the method that defines that operation for the object. Just so you’ll recognize one when you see it, let’s take a look at an example of a complete class definition. The code for the class CowboyHat we have been talking. This code would be saved in a file with the name CowboyHat.java. The name of a file that contains the definition of a class is always the same as the class name, and the extension will be .java to identify that the file contains Java source code. The code for the class definition appears between the braces that follow the identification for the class.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The code for each of the methods in the class also appears between braces. The class has three instance variables, owner, size, and hatOn, and this last variable is always initialized as false. Each object that is created according to this class specification will have its own independent copy of each of these variables in &lt;a href=&quot;http://www.bookofjava.blogspot.com/&quot;&gt;Java program&lt;/a&gt;, so each object will have its own unique values for the owner, the hat size, and whether the hat is on or off. I omitted the type parameter in this version of the class to make the code a little bit shorter. The keyword private, which has been applied to each instance variable, ensures that only code within the methods of the class can access or change the values of these directly.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Methods of a class can also be specified as private. Being able to prevent access to some members of a class from outside is an important facility. It protects the internals of the class from being changed or used incorrectly. Someone using your class in another program can get access only to the bits to which you want them to have access. This means that you can change how the class works internally without affecting other programs that may use it. You can change any of the things inside the class that you have designated as private, and you can even change the code inside any of the public methods, as long as the method name and the number and types of values passed to it or returned from it remain the same.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Our CowboyHat class also has five methods, so you can do five different things with a CowboyHat object. One of these is a special method called a constructor, which creates a CowboyHat object - this is the method with the name, CowboyHat, that is the same as the class name. The items between the parentheses that follow the name of the constructor specify data that is to be passed to the method when it is executed - that is, when a CowboyHat object is created.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;p&gt; Copyright © 2011-2012 &lt;a href = &quot;http://www.blogger.com/profile/16361323882951392233&quot;&gt; Hardik &lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bookofjava.blogspot.com/feeds/2793230313018518229/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bookofjava.blogspot.com/2012/01/operating-on-objects.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/2793230313018518229'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4985359605833593940/posts/default/2793230313018518229'/><link rel='alternate' type='text/html' href='http://bookofjava.blogspot.com/2012/01/operating-on-objects.html' title='Operating on Objects'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16361323882951392233</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><georss:featurename>Vejalpur Gam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.0061749 72.519003800000064</georss:point><georss:box>22.9915589 72.498833800000071 23.0207909 72.539173800000057</georss:box></entry></feed>