<?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-8047285913921730738</id><updated>2024-11-01T01:36:37.186-07:00</updated><category term="news"/><category term="java"/><category term="operator"/><category term="sports"/><category term="literals"/><category term="movie"/><category term="Arithmetic Operators"/><category term="Boolean Literals"/><category term="Casting"/><category term="Character Literals"/><category term="Class Libraries"/><category term="Code blocks"/><category term="Comments"/><category term="Compiling The Java Program"/><category term="Conversion"/><category term="Floating-Point Literals"/><category term="Identifiers"/><category term="Integer Literals"/><category term="Java Data Types"/><category term="Java Introduction"/><category term="Keywords"/><category term="Lifetime"/><category term="Multidimensional Arrays"/><category term="Null Literals"/><category term="Objects"/><category term="One-Dimensional Arrays"/><category term="Scope"/><category term="Separators"/><category term="Variables"/><category term="Whitespace"/><category term="array"/><category term="for Loop"/><category term="hot topics"/><category term="if statement"/><category term="indian budget"/><category term="pointers"/><category term="results"/><category term="string"/><category term="technology"/><title type='text'>Java Programming</title><subtitle type='html'>Java is a programming language created by James Gosling from Sun Microsystems in 1991. The first public available version of Java (Java 1.0) was released 1995. Over time several version of Java were released which enhanced the language and its libraries. The Java platform allows that code is written in other languages then the Java programming language and still runs on the Java virtual machine.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</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>34</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-8661023662921219845</id><published>2012-01-09T05:15:00.000-08:00</published><updated>2012-01-09T05:16:47.660-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="operator"/><title type='text'>Combine An Arithmetic Operation With An Assignment Operator</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
Java provides special operators that can be used to combine an arithmetic operation&lt;br /&gt;
with an assignment. As you probably know, statements like the following are quite&lt;br /&gt;
common in programming:&lt;br /&gt;
a = a + 4;&lt;br /&gt;
In Java, you can rewrite this statement as shown here:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
a += 4;&lt;br /&gt;
This version uses the += assignment operator. Both statements perform the same&lt;br /&gt;
action: they increase the value of a by 4.&lt;br /&gt;
Here is another example,&lt;br /&gt;
a = a % 2;&lt;br /&gt;
which can be expressed as&lt;br /&gt;
a %= 2;&lt;br /&gt;
In this case, the %= obtains the remainder of a/2 and puts that result back into a.&lt;br /&gt;
There are assignment operators for all of the arithmetic, binary operators. Thus,&lt;br /&gt;
any statement of the form&lt;br /&gt;
var = var op expression;&lt;br /&gt;
can be rewritten as&lt;br /&gt;
var op= expression;&lt;br /&gt;
The assignment operators provide two benefits. First, they save you a bit of typing,&lt;br /&gt;
because they are “shorthand” for their equivalent long forms. Second, they are&lt;br /&gt;
implemented more efficiently by the Java run-time system than are their equivalent&lt;br /&gt;
long forms. For these reasons, you will often see the assignment operators used in&lt;br /&gt;
professionally written Java programs.&lt;br /&gt;
Here is a sample program that shows several op= operator assignments in action:&lt;br /&gt;
// Demonstrate several assignment operators.&lt;br /&gt;
class OpEquals {&lt;br /&gt;
public static void main(String args[]) {&lt;br /&gt;
int a = 1;&lt;br /&gt;
int b = 2;&lt;br /&gt;
int c = 3;&lt;br /&gt;
a += 5;&lt;br /&gt;
b *= 4;&lt;br /&gt;
&lt;br /&gt;
c += a * b;&lt;br /&gt;
c %= 6;&lt;br /&gt;
System.out.println(&quot;a = &quot; + a);&lt;br /&gt;
System.out.println(&quot;b = &quot; + b);&lt;br /&gt;
System.out.println(&quot;c = &quot; + c);&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
The output of this program is shown here:&lt;br /&gt;
a = 6&lt;br /&gt;
b = 8&lt;br /&gt;
c = 3&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/8661023662921219845/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/combine-arithmetic-operation-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/8661023662921219845'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/8661023662921219845'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/combine-arithmetic-operation-with.html' title='Combine An Arithmetic Operation With An Assignment Operator'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-1565419746889000908</id><published>2012-01-09T04:16:00.000-08:00</published><updated>2012-01-09T04:16:10.176-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="operator"/><title type='text'>Modulus Operator In Java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
The modulus operator, %, returns the remainder of a division operation. It can be&lt;br /&gt;
applied to floating-point types as well as integer types. (This differs from C/C++, in&lt;br /&gt;
which the % can only be applied to integer types.)&lt;br /&gt;
&lt;br /&gt;
The following example program&amp;nbsp;demonstrates the %:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;// Demonstrate the % operator.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;class Modulus {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;public static void main(String args[]) {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;int x = 42;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;double y = 42.25;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;System.out.println(&quot;x mod 10 = &quot; + x % 10);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;System.out.println(&quot;y mod 10 = &quot; + y % 10);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;When you run this program you will get the following output:&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;x mod 10 = 2&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;y mod 10 = 2.25&lt;/i&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/1565419746889000908/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/modulus-operator-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/1565419746889000908'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/1565419746889000908'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/modulus-operator-in-java.html' title='Modulus Operator In Java'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-5581108655853988826</id><published>2012-01-09T04:11:00.000-08:00</published><updated>2012-01-09T04:11:10.940-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Arithmetic Operators"/><title type='text'>Arithmetic Operators in Java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
Arithmetic operators are used in mathematical expressions in the same way that they&lt;br /&gt;
are used in algebra.&lt;br /&gt;
&amp;nbsp;The following table lists the arithmetic operators:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Operator&lt;/u&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;u&gt;Result&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
+ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Addition&lt;br /&gt;
– &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Subtraction (also unary minus)&lt;br /&gt;
* &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Multiplication&lt;br /&gt;
/ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Division&lt;br /&gt;
% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Modulus&lt;br /&gt;
++ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Increment&lt;br /&gt;
+= &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Addition assignment&lt;br /&gt;
–= &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Subtraction assignment&lt;br /&gt;
*= &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Multiplication assignment&lt;br /&gt;
/= &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Division assignment&lt;br /&gt;
%= &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Modulus assignment&lt;br /&gt;
– – &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Decrement&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;u&gt;Arithmetic Operators With Example&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The basic arithmetic operations—addition, subtraction, multiplication, and division—&lt;br /&gt;
all behave as you would expect for all numeric types. The minus operator also has&lt;br /&gt;
a unary form which negates its single operand. Remember that when the division&lt;br /&gt;
&lt;br /&gt;
operator is applied to an integer type, there will be no fractional component attached to&lt;br /&gt;
the result.&lt;br /&gt;
The following simple example program demonstrates the arithmetic operators. It&lt;br /&gt;
also illustrates the difference between floating-point division and integer division.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;// Demonstrate the basic arithmetic operators.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;class BasicMath {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;public static void main(String args[]) {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;// arithmetic using integers&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;System.out.println(&quot;Integer Arithmetic&quot;);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;int a = 1 + 1;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;int b = a * 3;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;int c = b / 4;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;int d = c - a;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;int e = -d;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;System.out.println(&quot;a = &quot; + a);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;System.out.println(&quot;b = &quot; + b);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;System.out.println(&quot;c = &quot; + c);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;System.out.println(&quot;d = &quot; + d);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;System.out.println(&quot;e = &quot; + e);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;// arithmetic using doubles&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;System.out.println(&quot;\nFloating Point Arithmetic&quot;);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;double da = 1 + 1;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;double db = da * 3;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;double dc = db / 4;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;double dd = dc - a;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;double de = -dd;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;System.out.println(&quot;da = &quot; + da);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;System.out.println(&quot;db = &quot; + db);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;System.out.println(&quot;dc = &quot; + dc);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;System.out.println(&quot;dd = &quot; + dd);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;System.out.println(&quot;de = &quot; + de);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;When you run this program, you will see the following output:&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;Integer Arithmetic&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;a = 2&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;b = 6&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;c = 1&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;d = -1&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;e = 1&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;Floating Point Arithmetic&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;da = 2.0&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;db = 6.0&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;dc = 1.5&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;dd = -0.5&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;de = 0.5&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/5581108655853988826/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/arithmetic-operators-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/5581108655853988826'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/5581108655853988826'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/arithmetic-operators-in-java.html' title='Arithmetic Operators in Java'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-2994419257203732616</id><published>2012-01-08T03:16:00.000-08:00</published><updated>2012-01-08T03:16:42.888-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="operator"/><title type='text'>Operator  in Java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
Java provides a rich operator environment. Most of its operators can be divided&lt;br /&gt;
into the following four groups:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;&lt;i&gt;&amp;nbsp;arithmetic&lt;/i&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;&amp;nbsp;bitwise&lt;/i&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;relational&lt;/i&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;&amp;nbsp;logical.&lt;/i&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;&amp;nbsp;Java also&amp;nbsp;defines some additional operators that handle certain special situations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;If you are familiar with C/C++/C#, then you will be pleased to know that most operators&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;in Java work just like they do in those languages. However, there are some subtle differences,&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;so a careful reading is advised&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/2994419257203732616/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/operator-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/2994419257203732616'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/2994419257203732616'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/operator-in-java.html' title='Operator  in Java'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-9022411804662068157</id><published>2012-01-08T03:09:00.000-08:00</published><updated>2012-01-08T03:09:44.030-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="pointers"/><title type='text'>Java cannot allow pointers</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
If you are an experienced C/C++ programmer, then you know that these languages&lt;br /&gt;
provide support for pointers.&amp;nbsp;The reason for this is simple: Java does not support or allow pointers. (Or&lt;br /&gt;
more properly, Java does not support pointers that can be accessed and/or modified&lt;br /&gt;
by the programmer.) Java cannot allow pointers, because doing so would allow Java&lt;br /&gt;
applets to breach the firewall between the Java execution environment and the host&lt;br /&gt;
computer. (Remember, a pointer can be given any address in memory—even addresses&lt;br /&gt;
that might be outside the Java run-time system.) Since C/C++ make extensive use of&lt;br /&gt;
pointers, you might be thinking that their loss is a significant disadvantage to Java.&lt;br /&gt;
However, this is not true. Java is designed in such a way that as long as you stay within&lt;br /&gt;
the confines of the execution environment, you will never need to use a pointer, nor would&lt;br /&gt;
there be any benefit in using one. For tips on converting C/C++ code to Java&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/9022411804662068157/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/java-cannot-allow-pointers.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/9022411804662068157'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/9022411804662068157'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/java-cannot-allow-pointers.html' title='Java cannot allow pointers'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</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>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-5567839348704909862</id><published>2012-01-07T20:04:00.000-08:00</published><updated>2012-01-07T20:04:18.579-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="string"/><title type='text'>Strings Introduction</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
As you may have noticed, in the preceding discussion of data types and arrays there&lt;br /&gt;
has been no mention of strings or a string data type. This is not because Java does not&lt;br /&gt;
support such a type—it does. It is just that Java’s string type, called String, is not a&lt;br /&gt;
simple type. Nor is it simply an array of characters (as are strings in C/C++). Rather,&lt;br /&gt;
String defines an object, and a full description of it requires an understanding of several&lt;br /&gt;
object-related features. After objects are&amp;nbsp;described. However, so that you can use simple strings in example programs, the&amp;nbsp;following brief introduction is in order.&lt;br /&gt;
The String type is used to declare string variables. You can also declare arrays of&lt;br /&gt;
strings. A quoted string constant can be assigned to a &lt;b&gt;String &lt;/b&gt;variable. A variable&lt;br /&gt;
&lt;br /&gt;
of type String can be assigned to another variable of type String. You can use an object of&lt;br /&gt;
type String as an argument to println( ). For example, consider the following fragment:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;String str = &quot;this is a test&quot;;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;System.out.println(str);&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Here, str is an object of type String. It is assigned the string “this is a test”. This string&lt;br /&gt;
is displayed by the println( ) statement.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/5567839348704909862/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/strings-introduction.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/5567839348704909862'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/5567839348704909862'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/strings-introduction.html' title='Strings Introduction'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-7323611879434113867</id><published>2012-01-07T06:46:00.000-08:00</published><updated>2012-01-07T06:46:50.343-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="array"/><category scheme="http://www.blogger.com/atom/ns#" term="Multidimensional Arrays"/><category scheme="http://www.blogger.com/atom/ns#" term="One-Dimensional Arrays"/><title type='text'>Arrays in Java and Different Types of Array</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;&lt;u&gt;Arrays in Java and Different Types of Array&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
An array is a group of like-typed variables that are referred to by a common name. Arrays&lt;br /&gt;
of any type can be created and may have one or more dimensions. A specific element&lt;br /&gt;
in an array is accessed by its index. Arrays offer a convenient means of grouping&lt;br /&gt;
related information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;If you are familiar with&lt;b&gt; C/C++&lt;/b&gt;, be careful.&lt;b&gt; Arrays in Java work differently than they do&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;in those languages....&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;One-Dimensional Arrays&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;Multidimensional Arrays&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;color: #cc0000; font-size: x-large;&quot;&gt;&lt;u&gt;One-Dimensional Arrays&lt;/u&gt;&lt;/b&gt; &lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;A one-dimensional array is, essentially, a list of like-typed variables. To create an array,&lt;/div&gt;&lt;div&gt;you first must create an array variable of the desired type. The general form of a onedimensional&lt;/div&gt;&lt;div&gt;array declaration is&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;b&gt;&lt;i&gt; &amp;nbsp;type var-name[ ];&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Here, type declares the base type of the array. The base type determines the data type&lt;/div&gt;&lt;div&gt;of each element that comprises the array. Thus, the base type for the array determines&lt;/div&gt;&lt;div&gt;what type of data the array will hold. For example, the following declares an array&lt;/div&gt;&lt;div&gt;named month_days with the type “array of int”:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;b&gt; &lt;i&gt;&amp;nbsp;int month_days[];&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Although this declaration establishes the fact that month_days is an array variable,&lt;/div&gt;&lt;div&gt;no array actually exists. In fact, the value of month_days is set to null, which represents&lt;/div&gt;&lt;div&gt;an array with no value. To link month_days with an actual, physical array of integers,&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;you must allocate one using new and assign it to month_days. new is a special operator&lt;/div&gt;&lt;div&gt;that allocates memory.&lt;/div&gt;&lt;div&gt;&lt;i&gt;new &lt;/i&gt;is used to allocate memory for arrays. The general form of new as it applies to one-dimensional&lt;/div&gt;&lt;div&gt;arrays appears as follows:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; array-var = new type[size];&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Here, type specifies the type of data being allocated, size specifies the number of elements&lt;/div&gt;&lt;div&gt;in the array, and array-var is the array variable that is linked to the array. That is, to use&lt;/div&gt;&lt;div&gt;new to allocate an array, you must specify the type and number of elements to allocate.&lt;/div&gt;&lt;div&gt;The elements in the array allocated by new will automatically be initialized to zero.&lt;/div&gt;&lt;div&gt;This example allocates a 12-element array of integers and links them to month_days.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;b&gt;&lt;i&gt; &amp;nbsp;month_days = new int[12];&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;After this statement executes, &lt;i&gt;month_days &lt;/i&gt;will refer to an array of 12 integers. Further,&lt;/div&gt;&lt;div&gt;all elements in the array will be initialized to zero.&lt;/div&gt;&lt;div&gt;Let’s review: Obtaining an array is a two-step process. First, you must declare a&lt;/div&gt;&lt;div&gt;variable of the desired array type. Second, you must allocate the memory that will hold&lt;/div&gt;&lt;div&gt;the array, using new, and assign it to the array variable. Thus, in Java all arrays are&lt;/div&gt;&lt;div&gt;dynamically allocated. If the concept of dynamic allocation is unfamiliar to you, don’t&lt;/div&gt;&lt;div&gt;worry. It will be described at length later in this book.&lt;/div&gt;&lt;div&gt;Once you have allocated an array, you can access a specific element in the array by&lt;/div&gt;&lt;div&gt;specifying its index within square brackets. All array indexes start at zero.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&amp;nbsp;For example,&lt;/div&gt;&lt;div&gt;this statement assigns the value 28 to the second element of month_days.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;month_days[1] = 28;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The next line displays the value stored at index 3.&lt;/div&gt;&lt;div&gt;System.out.println(month_days[3]);&lt;/div&gt;&lt;div&gt;Putting together all the pieces, here is a program that creates an array of the&lt;/div&gt;&lt;div&gt;number of days in each month.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;i&gt;// Demonstrate a one-dimensional array.&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;class Array {&lt;/i&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;i&gt;public static void main(String args[]) {&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;int month_days[];&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;month_days = new int[12];&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;month_days[0] = 31;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;month_days[1] = 28;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;month_days[2] = 31;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;month_days[3] = 30;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;month_days[4] = 31;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;month_days[5] = 30;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;month_days[6] = 31;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;month_days[7] = 31;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;month_days[8] = 30;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;month_days[9] = 31;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;month_days[10] = 30;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;month_days[11] = 31;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;System.out.println(&quot;April has &quot; + month_days[3] + &quot; days.&quot;);&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/div&gt;&lt;div&gt;When you run this program, it prints the number of days in April. As mentioned, Java&lt;/div&gt;&lt;div&gt;array indexes start with zero, so the number of days in April is month_days[3] or 30.&lt;/div&gt;&lt;div&gt;It is possible to combine the declaration of the array variable with the allocation of&lt;/div&gt;&lt;div&gt;the array itself, as shown here:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;int month_days[] = new int[12];&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;This is the way that you will normally see it done in professionally written Java&lt;/div&gt;&lt;div&gt;programs.&lt;/div&gt;&lt;div&gt;Arrays can be initialized when they are declared. The process is much the same as&lt;/div&gt;&lt;div&gt;that used to initialize the simple types. An array initializer is a list of comma-separated&lt;/div&gt;&lt;div&gt;expressions surrounded by curly braces. The commas separate the values of the array&lt;/div&gt;&lt;div&gt;elements. The array will automatically be created large enough to hold the number of&lt;/div&gt;&lt;div&gt;elements you specify in the array initializer. There is no need to use new. For example,&lt;/div&gt;&lt;div&gt;to store the number of days in each month, the following code creates an initialized&lt;/div&gt;&lt;div&gt;array of integers:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;i&gt;// An improved version of the previous program.&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;class AutoArray {&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;public static void main(String args[]) {&lt;/i&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;i&gt;int month_days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31,&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;30, 31 };&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;System.out.println(&quot;April has &quot; + month_days[3] + &quot; days.&quot;);&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;When you run this program, you see the same output as that generated by the&lt;/div&gt;&lt;div&gt;previous version.&lt;/div&gt;&lt;div&gt;Java strictly checks to make sure you do not accidentally try to store or reference&lt;/div&gt;&lt;div&gt;values outside of the range of the array. The Java run-time system will check to be sure&lt;/div&gt;&lt;div&gt;that all array indexes are in the correct range. (In this regard, Java is fundamentally&lt;/div&gt;&lt;div&gt;different from C/C++, which provide no run-time boundary checks.) For example, the&lt;/div&gt;&lt;div&gt;run-time system will check the value of each index into month_days to make sure that&lt;/div&gt;&lt;div&gt;it is between 0 and 11 inclusive. If you try to access elements outside the range of the&lt;/div&gt;&lt;div&gt;array (negative numbers or numbers greater than the length of the array), you will&lt;/div&gt;&lt;div&gt;cause a run-time error.&lt;/div&gt;&lt;div&gt;Here is one more example that uses a one-dimensional array. It finds the average of&lt;/div&gt;&lt;div&gt;a set of numbers.&lt;/div&gt;&lt;div&gt;&lt;i&gt;// Average an array of values.&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;class Average {&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;public static void main(String args[]) {&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;double nums[] = {10.1, 11.2, 12.3, 13.4, 14.5};&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;double result = 0;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;int i;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;for(i=0; i&amp;lt;5; i++)&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;result = result + nums[i];&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;System.out.println(&quot;Average is &quot; + result / 5);&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;color: #cc0000;&quot;&gt;&lt;u&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Multidimensional Arrays&lt;/span&gt;&lt;/u&gt;&lt;/b&gt; &lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;In Java, multidimensional arrays are actually arrays of arrays. These, as you might&lt;/div&gt;&lt;div&gt;expect, look and act like regular multidimensional arrays. However, as you will see,&lt;/div&gt;&lt;div&gt;&lt;div&gt;there are a couple of subtle differences. To declare a multidimensional array variable,&lt;/div&gt;&lt;div&gt;specify each additional index using another set of square brackets. For example, the&lt;/div&gt;&lt;div&gt;following declares a two-dimensional array variable called twoD.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int twoD[][] = new int[4][5];&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;This allocates a 4 by 5 array and assigns it to twoD. Internally this matrix is implemented&lt;/div&gt;&lt;div&gt;as an array of arrays of int.&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_nxypLh9ya8mp7ejW_NR6ysEtg9AhTrTSFEmya7CQCuX0PkK8nWK8Nhh1txICK1_XSmwydXXgJESRv7_0Ml5wAgCrRUIcMs2ZrtUDAV-gob9fDqPoflzWfoOd6xEY-mJwl96axtOAoWY/s1600/1.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;192&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_nxypLh9ya8mp7ejW_NR6ysEtg9AhTrTSFEmya7CQCuX0PkK8nWK8Nhh1txICK1_XSmwydXXgJESRv7_0Ml5wAgCrRUIcMs2ZrtUDAV-gob9fDqPoflzWfoOd6xEY-mJwl96axtOAoWY/s320/1.JPG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;The following program numbers each element in the array from left to right, top to&lt;/div&gt;&lt;div&gt;bottom, and then displays these values:&lt;/div&gt;&lt;div&gt;&lt;i&gt;// Demonstrate a two-dimensional array.&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;class TwoDArray {&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;public static void main(String args[]) {&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;int twoD[][]= new int[4][5];&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;int i, j, k = 0;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;for(i=0; i&amp;lt;4; i++)&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;for(j=0; j&amp;lt;5; j++) {&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;twoD[i][j] = k;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;k++;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;for(i=0; i&amp;lt;4; i++) {&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;for(j=0; j&amp;lt;5; j++)&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;System.out.print(twoD[i][j] + &quot; &quot;);&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;System.out.println();&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;u&gt;This program generates the following output:&lt;/u&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;0 1 2 3 4&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;5 6 7 8 9&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;10 11 12 13 14&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;15 16 17 18 19&lt;/i&gt;&lt;/div&gt;&lt;div&gt;When you allocate memory for a multidimensional array, you need only specify the&lt;/div&gt;&lt;div&gt;memory for the first (leftmost) dimension. You can allocate the remaining dimensions&lt;/div&gt;&lt;div&gt;separately. For example, this following code allocates memory for the first dimension of&lt;/div&gt;&lt;div&gt;twoD when it is declared. It allocates the second dimension manually.&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;int twoD[][] = new int[4][];&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;twoD[0] = new int[5];&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;twoD[1] = new int[5];&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;twoD[2] = new int[5];&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;twoD[3] = new int[5];&lt;/i&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;While there is no advantage to individually allocating the second dimension arrays&lt;/div&gt;&lt;div&gt;in this situation, there may be in others. For example, when you allocate dimensions&lt;/div&gt;&lt;div&gt;manually, you do not need to allocate the same number of elements for each dimension.&lt;/div&gt;&lt;div&gt;As stated earlier, since multidimensional arrays are actually arrays of arrays, the length&lt;/div&gt;&lt;div&gt;of each array is under your control. For example, the following program creates a twodimensional&lt;/div&gt;&lt;div&gt;array in which the sizes of the second dimension are unequal.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;// Manually allocate differing size second dimensions.&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;class TwoDAgain {&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;public static void main(String args[]) {&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;int twoD[][] = new int[4][];&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;twoD[0] = new int[1];&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;twoD[1] = new int[2];&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;twoD[2] = new int[3];&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;twoD[3] = new int[4];&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;int i, j, k = 0;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;for(i=0; i&amp;lt;4; i++)&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;for(j=0; j&amp;lt;i+1; j++) {&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;twoD[i][j] = k;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;k++;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;for(i=0; i&amp;lt;4; i++) {&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;for(j=0; j&amp;lt;i+1; j++)&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;System.out.print(twoD[i][j] + &quot; &quot;);&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;System.out.println();&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;u&gt;This program generates the following output:&lt;/u&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;0&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;1 2&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;3 4 5&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;6 7 8 9&lt;/i&gt;&lt;/div&gt;&lt;div&gt;The array created by this program looks like this:&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8V32cgpKI-qARX8CvG-SeryFY3pmPVwTMa0I6bWUYXMTazKrKZONIii6RTA0IfVV_aeJBO-16etMYmLGO08t0axrJu6vocH28T3GwfQopOjlRCnjOpT2093AYdPMn_R30Kx0qq2fUTC8/s1600/2.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8V32cgpKI-qARX8CvG-SeryFY3pmPVwTMa0I6bWUYXMTazKrKZONIii6RTA0IfVV_aeJBO-16etMYmLGO08t0axrJu6vocH28T3GwfQopOjlRCnjOpT2093AYdPMn_R30Kx0qq2fUTC8/s1600/2.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;The use of uneven (or, irregular) multidimensional arrays is not recommended&lt;/div&gt;&lt;div&gt;for most applications, because it runs contrary to what people expect to find when&lt;/div&gt;&lt;div&gt;a multidimensional array is encountered. However, it can be used effectively in some&lt;/div&gt;&lt;div&gt;situations. For example, if you need a very large two-dimensional array that is sparsely&lt;/div&gt;&lt;div&gt;populated (that is, one in which not all of the elements will be used), then an irregular&lt;/div&gt;&lt;div&gt;array might be a perfect solution.&lt;/div&gt;&lt;div&gt;It is possible to initialize multidimensional arrays. To do so, simply enclose each&lt;/div&gt;&lt;div&gt;dimension’s initializer within its own set of curly braces. The following program creates&lt;/div&gt;&lt;div&gt;a matrix where each element contains the product of the row and column indexes. Also&lt;/div&gt;&lt;div&gt;notice that you can use expressions as well as literal values inside of array initializers.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;// Initialize a two-dimensional array.&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;class Matrix {&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;public static void main(String args[]) {&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;double m[][] = {&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;{ 0*0, 1*0, 2*0, 3*0 },&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;{ 0*1, 1*1, 2*1, 3*1 },&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;{ 0*2, 1*2, 2*2, 3*2 },&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;{ 0*3, 1*3, 2*3, 3*3 }&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;};&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;int i, j;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;for(i=0; i&amp;lt;4; i++) {&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;for(j=0; j&amp;lt;4; j++)&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;System.out.print(m[i][j] + &quot; &quot;);&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;System.out.println();&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;i&gt;&lt;u&gt;When you run this program, you will get the following output:&lt;/u&gt;&lt;/i&gt;&lt;/div&gt;&lt;div style=&quot;font-style: italic;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-style: italic;&quot;&gt;0.0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.0&lt;/div&gt;&lt;div style=&quot;font-style: italic;&quot;&gt;0.0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1.0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2.0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3.0&lt;/div&gt;&lt;div style=&quot;font-style: italic;&quot;&gt;0.0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2.0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4.0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6.0&lt;/div&gt;&lt;div style=&quot;font-style: italic;&quot;&gt;0.0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3.0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6.0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9.0&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-style: italic;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;As you can see, each row in the array is initialized as specified in the initialization lists.&lt;/div&gt;&lt;div&gt;Let’s look at one more example that uses a multidimensional array. The following&lt;/div&gt;&lt;div&gt;program creates a 3 by 4 by 5, three-dimensional array. It then loads each element with&lt;/div&gt;&lt;div&gt;the product of its indexes. Finally, it displays these products.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;// Demonstrate a three-dimensional array.&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;class threeDMatrix {&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;public static void main(String args[]) {&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;int threeD[][][] = new int[3][4][5];&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;int i, j, k;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;for(i=0; i&amp;lt;3; i++)&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;for(j=0; j&amp;lt;4; j++)&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;for(k=0; k&amp;lt;5; k++)&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;threeD[i][j][k] = i * j * k;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;for(i=0; i&amp;lt;3; i++) {&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;for(j=0; j&amp;lt;4; j++) {&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;for(k=0; k&amp;lt;5; k++)&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;System.out.print(threeD[i][j][k] + &quot; &quot;);&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;System.out.println();&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;System.out.println();&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;u&gt;This program generates the following output:&lt;/u&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;0 0 0 0 0&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;0 0 0 0 0&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;0 0 0 0 0&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;0 0 0 0 0&lt;/i&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;font-style: italic;&quot;&gt;0 0 0 0 0&lt;/div&gt;&lt;div style=&quot;font-style: italic;&quot;&gt;0 1 2 3 4&lt;/div&gt;&lt;div style=&quot;font-style: italic;&quot;&gt;0 2 4 6 8&lt;/div&gt;&lt;div style=&quot;font-style: italic;&quot;&gt;0 3 6 9 12&lt;/div&gt;&lt;div style=&quot;font-style: italic;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-style: italic;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-style: italic;&quot;&gt;0 0 0 0 0&lt;/div&gt;&lt;div style=&quot;font-style: italic;&quot;&gt;0 2 4 6 8&lt;/div&gt;&lt;div style=&quot;font-style: italic;&quot;&gt;0 4 8 12 16&lt;/div&gt;&lt;div style=&quot;font-style: italic;&quot;&gt;0 6 12 18 24&lt;/div&gt;&lt;div style=&quot;font-style: italic;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-style: italic;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;u&gt;Alternative Array Declaration Syntax&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-style: italic;&quot;&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;There is a second form that may be used to declare an array:&lt;/div&gt;&lt;div&gt;type[ ] var-name;&lt;/div&gt;&lt;div&gt;Here, the square brackets follow the type specifier, and not the name of the array&lt;/div&gt;&lt;div&gt;variable. For example, the following two declarations are equivalent:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;int al[] = new int[3];&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;int[] a2 = new int[3];&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The following declarations are also equivalent:&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;char twod1[][] = new char[3][4];&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;char[][] twod2 = new char[3][4];&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;This alternative declaration form is included as a convenience, and is also useful when&lt;/div&gt;&lt;div&gt;specifying an array as a return type for a method.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/7323611879434113867/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/arrays-in-java-and-different-types-of.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/7323611879434113867'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/7323611879434113867'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/arrays-in-java-and-different-types-of.html' title='Arrays in Java and Different Types of Array'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</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><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_nxypLh9ya8mp7ejW_NR6ysEtg9AhTrTSFEmya7CQCuX0PkK8nWK8Nhh1txICK1_XSmwydXXgJESRv7_0Ml5wAgCrRUIcMs2ZrtUDAV-gob9fDqPoflzWfoOd6xEY-mJwl96axtOAoWY/s72-c/1.JPG" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-1035496734132014603</id><published>2012-01-05T06:46:00.000-08:00</published><updated>2012-01-05T06:46:26.912-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Casting"/><category scheme="http://www.blogger.com/atom/ns#" term="Conversion"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><title type='text'>Java Type Conversion and Casting</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
If you have previous programming experience, then you already know that it is fairly&lt;br /&gt;
common to assign a value of one type to a variable of another type. If the two types are&lt;br /&gt;
compatible, then Java will perform the conversion automatically. For example, it is always&lt;br /&gt;
possible to assign an &lt;b&gt;int &lt;/b&gt;value to a &lt;b&gt;long &lt;/b&gt;variable. However, not all types are compatible,&lt;br /&gt;
and thus, not all type conversions are implicitly allowed. For instance, there is no&lt;br /&gt;
conversion defined from &lt;b&gt;double &lt;/b&gt;to &lt;b&gt;byte&lt;/b&gt;. Fortunately, it is still possible to obtain a&lt;br /&gt;
conversion between incompatible types. To do so, you must use a cast, which performs&lt;br /&gt;
an explicit conversion between incompatible types. Let&#39;s look at both automatic type&lt;br /&gt;
conversions and casting.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;u&gt;Java&#39;s Automatic Conversions&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
When one type of data is assigned to another type of variable, an &lt;b&gt;automatic type&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;conversion will take place if the following two conditions are met:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;• The two types are compatible.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;• The destination type is larger than the source type.&lt;br /&gt;
&lt;br /&gt;
When these two conditions are met, a widening conversion takes place. For example, the&lt;br /&gt;
&lt;b&gt;int &lt;/b&gt;type is always large enough to hold all valid &lt;b&gt;byte &lt;/b&gt;values, so no explicit cast statement&lt;br /&gt;
is required.&lt;br /&gt;
For widening conversions, the numeric types, including integer and floating-point types,&lt;br /&gt;
are compatible with each other. However, the numeric types are not compatible with &lt;b&gt;char&lt;/b&gt;&lt;br /&gt;
or &lt;b&gt;boolean&lt;/b&gt;. Also, &lt;b&gt;char &lt;/b&gt;and &lt;b&gt;boolean &lt;/b&gt;are not compatible with each other.&lt;br /&gt;
&lt;br /&gt;
As mentioned earlier, Java also performs an automatic type conversion when storing a&lt;br /&gt;
literal integer constant into variables of type &lt;b&gt;byte&lt;/b&gt;, &lt;b&gt;short&lt;/b&gt;, or &lt;b&gt;long.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;u&gt;Casting Incompatible Types&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Although the automatic type conversions are helpful, they will not fulfill all needs. For&lt;br /&gt;
example, what if you want to assign an &lt;b&gt;int &lt;/b&gt;value to a &lt;b&gt;byte &lt;/b&gt;variable? This conversion will&lt;br /&gt;
not be performed automatically, because a &lt;b&gt;byte &lt;/b&gt;is smaller than an &lt;b&gt;int&lt;/b&gt;. This kind of&lt;br /&gt;
conversion is sometimes called a narrowing conversion, since you are explicitly making&lt;br /&gt;
the value narrower so that it will fit into the target type.&lt;br /&gt;
To create a conversion between two incompatible types, you must use a cast. A cast is&lt;br /&gt;
simply an explicit type conversion. It has this general form:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;(target-type) value&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Here, target-type specifies the desired type to convert the specified value to. For&lt;br /&gt;
example, the following fragment casts an &lt;b&gt;int &lt;/b&gt;to a &lt;b&gt;byte&lt;/b&gt;. If the integer&#39;s value is larger than&lt;br /&gt;
the range of a &lt;b&gt;byte&lt;/b&gt;, it will be reduced modulo (the remainder of an integer division by&lt;br /&gt;
the) &lt;b&gt;byte&#39;s &lt;/b&gt;range.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;int a;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;byte b;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;// ...&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;b = (byte) a;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
A different type of conversion will occur when a floating-point value is assigned to an&lt;br /&gt;
integer type: truncation. As you know, integers do not have fractional components. Thus,&lt;br /&gt;
when a floating-point value is assigned to an integer type, the fractional component is&lt;br /&gt;
lost. For example, if the value 1.23 is assigned to an integer, the resulting value will&lt;br /&gt;
simply be 1. The 0.23 will have been truncated. Of course, if the size of the whole&lt;br /&gt;
number component is too large to fit into the target integer type, then that value will be&lt;br /&gt;
reduced modulo the target type&#39;s range.&lt;br /&gt;
&lt;br /&gt;
The following program demonstrates some type conversions that require casts:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;// Demonstrate casts.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; class Conversion {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public static void main(String args[]) {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; byte b;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int i = 257;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;double d = 323.142;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.out.println(&quot;\\nConversion of int to byte.&quot;);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b = (byte) i;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.out.println(&quot;i and b &quot; + i + &quot; &quot; + b);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.out.println(&quot;\\nConversion of double to int.&quot;);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;i = (int) d;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;d and i &quot; + d + &quot; &quot; + i);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;\\nConversion of double to byte.&quot;);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; b = (byte) d;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.out.println(&quot;d and b &quot; + d + &quot; &quot; + b);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;This program generates the following output:&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Conversion of int to byte.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; i and b 257 1&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Conversion of double to int.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;d and i 323.142 323&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Conversion of double to byte.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; d and b 323.142 67&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Let&#39;s look at each conversion. When the value 257 is cast into a &lt;b&gt;byte &lt;/b&gt;variable, the result is&lt;br /&gt;
the remainder of the division of 257 by 256 (the range of a &lt;b&gt;byte&lt;/b&gt;), which is 1 in this case.&lt;br /&gt;
When the &lt;b&gt;d &lt;/b&gt;is converted to an &lt;b&gt;int&lt;/b&gt;, its fractional component is lost. When &lt;b&gt;d &lt;/b&gt;is converted to&lt;br /&gt;
a &lt;b&gt;byte&lt;/b&gt;, its fractional component is lost, and the value is reduced modulo 256, which in this&lt;br /&gt;
case is 67.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/1035496734132014603/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/java-type-conversion-and-casting.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/1035496734132014603'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/1035496734132014603'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/java-type-conversion-and-casting.html' title='Java Type Conversion and Casting'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-3285289961668005288</id><published>2012-01-04T10:09:00.000-08:00</published><updated>2012-01-04T10:09:58.222-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="Lifetime"/><category scheme="http://www.blogger.com/atom/ns#" term="Scope"/><category scheme="http://www.blogger.com/atom/ns#" term="Variables"/><title type='text'>Variables In Java And Declaration</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
The variable is the basic unit of storage in a Java program. A variable is defined by the&lt;br /&gt;
combination of an identifier, a type, and an optional initializer. In addition, all variables&lt;br /&gt;
have a scope, which defines their visibility, and a lifetime.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;u&gt;Declaring a Variable&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
In Java, all variables must be declared before they can be used. The basic form of a&lt;br /&gt;
&lt;br /&gt;
variable declaration is shown here:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;type identifier [ = value][, identifier [= value] ...] ;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The type is one of Java&#39;s atomic types, or the name of a class or interface.&amp;nbsp;The identifier is the name of the&lt;br /&gt;
variable. You can initialize the variable by specifying an equal sign and a value. Keep in&lt;br /&gt;
mind that the initialization expression must result in a value of the same (or compatible)&lt;br /&gt;
type as that specified for the variable. To declare more than one variable of the specified&lt;br /&gt;
type, use a comma-separated list.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here are several examples of variable declarations of various types. Note that some&lt;br /&gt;
include an initialization.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;int a, b, c; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// declares three ints, a, b, and c.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;int d = 3, e, f = 5; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // declares three more ints, initializing&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // d and f.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;byte z = 22; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// initializes z.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;double pi = 3.14159; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// declares an approximation of pi.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;char x = &#39;x&#39;; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // the variable x has the value &#39;x&#39;.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The identifiers that you choose have nothing intrinsic in their names that indicates their&lt;br /&gt;
type. Many readers will remember when FORTRAN predefined all identifiers from &lt;b&gt;I&lt;/b&gt;&lt;br /&gt;
through &lt;b&gt;N &lt;/b&gt;to be of type &lt;b&gt;INTEGER &lt;/b&gt;while all other identifiers were &lt;b&gt;REAL&lt;/b&gt;. Java allows any&lt;br /&gt;
properly formed identifier to have any declared type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;u&gt;Dynamic Initialization&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Although the preceding examples have used only constants as initializers, Java allows&lt;br /&gt;
variables to be initialized dynamically, using any expression valid at the time the variable&lt;br /&gt;
is declared.&lt;br /&gt;
For example, here is a short program that computes the length of the hypotenuse of a&lt;br /&gt;
right triangle given the lengths of its two opposing sides:&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;// Demonstrate dynamic initialization.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;class DynInit {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public static void main(String args[]) {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; double a = 3.0, b = 4.0;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// c is dynamically initialized&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; double c = Math.sqrt(a * a + b * b);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;Hypotenuse is &quot; + c);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here, three local variables—a, b,and c—are declared. The first two, a and b, are&lt;br /&gt;
initialized by constants. However, c is initialized dynamically to the length of the&lt;br /&gt;
hypotenuse (using the Pythagorean theorem). The program uses another of Java&#39;s builtin&lt;br /&gt;
methods, sqrt( ), which is a member of the Math class, to compute the square root of&lt;br /&gt;
its argument. The key point here is that the initialization expression may use any element&lt;br /&gt;
valid at the time of the initialization, including calls to methods, other variables, or literals.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;u&gt;Variables&amp;nbsp;&amp;nbsp;Scope and Lifetime&amp;nbsp;&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
So far, all of the variables used have been declared at the start of the main( ) method.&lt;br /&gt;
&lt;br /&gt;
However, Java allows variables to be declared within any block. A&amp;nbsp;block is begun with an opening curly brace and ended by a closing curly brace. A&amp;nbsp;block defines a scope. Thus, each time you start a new block, you are creating a new&amp;nbsp;scope. As you probably know from your previous programming experience, a scope&lt;br /&gt;
determines what objects are visible to other parts of your program. It also determines the&lt;br /&gt;
lifetime of those objects.&amp;nbsp;Most other computer languages define two general categories of scopes: global and&lt;br /&gt;
local. However, these traditional scopes do not fit well with Java&#39;s strict, object-oriented&amp;nbsp;model. While it is possible to create what amounts to being a global scope, it is by far the&amp;nbsp;exception, not the rule. In Java, the two major scopes are those defined by a class and&amp;nbsp;those defined by a method. Even this distinction is somewhat artificial. However, since&amp;nbsp;the class scope has several unique properties and attributes that do not apply to the&amp;nbsp;scope defined by a method, this distinction makes some sense. Because of the&lt;br /&gt;
differences,&amp;nbsp;&amp;nbsp;when classes are described. For now, we will only examine the scopes&lt;br /&gt;
defined by or within a method.&amp;nbsp;The scope defined by a method begins with its opening curly brace. However, if that&amp;nbsp;method has parameters, they too are included within the method&#39;s scope. They work the same as any other method variable.&amp;nbsp;As a general rule, variables declared inside a scope are not visible (that is, accessible) to&amp;nbsp;code that is defined outside that scope. Thus, when you declare a variable within a&amp;nbsp;scope, you are localizing that variable and protecting it from unauthorized access and/or&amp;nbsp;modification. Indeed, the scope rules provide the foundation for encapsulation.&amp;nbsp;Scopes can be nested. For example, each time you create a block of code, you are&amp;nbsp;creating a new, nested scope. When this occurs, the outer scope encloses the inner&lt;br /&gt;
scope. This means that objects declared in the outer scope will be visible to code within&lt;br /&gt;
the inner scope. However, the reverse is not true. Objects declared within the inner scope&lt;br /&gt;
will not be visible outside it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To understand the effect of nested scopes, consider the following program:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;// Demonstrate block scope.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;class Scope {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; public static void main(String args[]) {&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;int x; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // known to all code within main&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;x = 10;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(x == 10) { &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// start new scope&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int y = 20; // known only to this block&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // x and y both known here.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;x and y: &quot; + x + &quot; &quot; + y);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; x = y * 2;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // y = 100; // Error! y not known here&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // x is still known here.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;x is &quot; + x);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
As the comments indicate, the variable x is declared at the start of main( )&#39;s scope and is&lt;br /&gt;
accessible to all subsequent code within main( ). Within the if block, y is declared. Since&lt;br /&gt;
a block defines a scope, y is only visible to other code within its block. This is why outside&lt;br /&gt;
of its block, the line y = 100; is commented out. If you remove the leading comment&lt;br /&gt;
symbol, a compile-time error will occur, because y is not visible outside of its block.&lt;br /&gt;
Within the if block, x can be used because code within a block (that is, a nested scope)&lt;br /&gt;
has access to variables declared by an enclosing scope.&lt;br /&gt;
Within a block, variables can be declared at any point, but are valid only after they are&lt;br /&gt;
declared. Thus, if you define a variable at the start of a method, it is available to all of the&lt;br /&gt;
code within that method. Conversely, if you declare a variable at the end of a block, it is&lt;br /&gt;
effectively useless, because no code will have access to it. For example, this fragment is&lt;br /&gt;
invalid because count cannot be used prior to its declaration:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;// This fragment is wrong!&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;count = 100; // oops! cannot use count before it is declared!&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;int count;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is another important point to remember: variables are created when their scope is&lt;br /&gt;
entered, and destroyed when their scope is left. This means that a variable will not hold&lt;br /&gt;
its value once it has gone out of scope. Therefore, variables declared within a method will&lt;br /&gt;
not hold their values between calls to that method. Also, a variable declared within a&lt;br /&gt;
block will lose its value when the block is left. Thus, the lifetime of a variable is confined&lt;br /&gt;
to its scope.&lt;br /&gt;
If a variable declaration includes an initializer, then that variable will be reinitialized each&lt;br /&gt;
time the block in which it is declared is entered. For example, consider this program:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;i&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Demonstrate lifetime of a variable.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;class LifeTime {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; public static void main(String args[]) {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int x;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(x = 0; x &amp;lt; 3; x++) {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int y = -1; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// y is initialized each time block is entered&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;y is: &quot; + y); // this always prints -1&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;y = 100;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&quot;y is now: &quot; + y);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;The output generated by this program is shown here:&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;y is: -1&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;y is now: 100&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;y is: -1&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;y is now: 100&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;y is: -1&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;y is now: 100&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As you can see, y is always reinitialized to –1 each time the inner for loop is entered.&lt;br /&gt;
Even though it is subsequently assigned the value 100, this value is lost.&lt;br /&gt;
One last point: Although blocks can be nested, you cannot declare a variable to have the&lt;br /&gt;
same name as one in an outer scope. In this regard, Java differs from C and C++. Here&lt;br /&gt;
is an example that tries to declare two separate variables with the same name. In Java,&lt;br /&gt;
this is illegal. In C/C++, it would be legal and the two bars would be separate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // This program will not compile&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;class ScopeErr {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public static void main(String args[]) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int bar = 1;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; { // creates a new scope&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int bar = 2; // Compile-time error – bar already defined!&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/3285289961668005288/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/variables-in-java-and-declaration.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/3285289961668005288'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/3285289961668005288'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/variables-in-java-and-declaration.html' title='Variables In Java And Declaration'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</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>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-109578069809944484</id><published>2012-01-02T08:53:00.001-08:00</published><updated>2012-01-02T08:53:49.572-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Boolean Literals"/><category scheme="http://www.blogger.com/atom/ns#" term="Character Literals"/><category scheme="http://www.blogger.com/atom/ns#" term="Floating-Point Literals"/><category scheme="http://www.blogger.com/atom/ns#" term="Integer Literals"/><category scheme="http://www.blogger.com/atom/ns#" term="literals"/><category scheme="http://www.blogger.com/atom/ns#" term="Null Literals"/><title type='text'>Closer In Java, Its Look Like Literals</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;div&gt;&lt;b style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: -webkit-auto;&quot;&gt;By literal we mean any number, text, or other information that represents a value. This means what you type is what you get. We will use literals in addition to variables in Java statement.&lt;/b&gt; &lt;/div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;&lt;i&gt;Integer Literals&lt;/i&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;Floating-Point Literals&lt;/i&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;Boolean Literals&lt;/i&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;Character Literals&lt;/i&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;u&gt;Integer Literals&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;Integers are probably the most commonly used type in the typical program. Any whole&lt;/div&gt;&lt;div&gt;number value is an integer literal. Examples are 1, 2, 3, and 42. These are all decimal&lt;/div&gt;&lt;div&gt;values, meaning they are describing a base 10 number. There are two other bases which&lt;/div&gt;&lt;div&gt;can be used in integer literals, octal (base eight) and hexadecimal (base 16). Octal&lt;/div&gt;&lt;div&gt;values are denoted in Java by a leading zero. Normal decimal numbers cannot have a&lt;/div&gt;&lt;div&gt;leading zero. Thus, the seemingly valid value 09 will produce an error from the compiler,&lt;/div&gt;&lt;div&gt;since 9 is outside of octal&#39;s 0 to 7 range. A more common base for numbers used by&lt;/div&gt;&lt;div&gt;programmers is hexadecimal, which matches cleanly with modulo 8 word sizes, such as&lt;/div&gt;&lt;div&gt;8, 16, 32, and 64 bits. You signify a hexadecimal constant with a leading zero-x, (&lt;b&gt;0x&lt;/b&gt; or&lt;/div&gt;&lt;div&gt;&lt;b&gt;0X&lt;/b&gt;). The range of a hexadecimal digit is 0 to 15, so A through F (or a through f ) are&lt;/div&gt;&lt;div&gt;substituted for 10 through 15.&lt;/div&gt;&lt;div&gt;Integer literals create an &lt;b&gt;int &lt;/b&gt;value, which in Java is a 32-bit integer value. Since Java is&lt;/div&gt;&lt;div&gt;strongly typed, you might be wondering how it is possible to assign an integer literal to&lt;/div&gt;&lt;div&gt;one of Java&#39;s other integer types, such as &lt;b&gt;byte &lt;/b&gt;or &lt;b&gt;long&lt;/b&gt;, without causing a type mismatch&lt;/div&gt;&lt;div&gt;error. Fortunately, such situations are easily handled. When a literal value is assigned to&lt;/div&gt;&lt;div&gt;a &lt;b&gt;byte &lt;/b&gt;or &lt;b&gt;short &lt;/b&gt;variable, no error is generated if the literal value is within the range of the&lt;/div&gt;&lt;div&gt;target type. Also, an integer literal can always be assigned to a &lt;b&gt;long &lt;/b&gt;variable. However,&lt;/div&gt;&lt;div&gt;to specify a &lt;b&gt;long &lt;/b&gt;literal, you will need to explicitly tell the compiler that the literal value is&lt;/div&gt;&lt;div&gt;of type &lt;b&gt;long&lt;/b&gt;. You do this by appending an upper- or lowercase L to the literal. For&lt;/div&gt;&lt;div&gt;example, 0x7ffffffffffffffL or 9223372036854775807L is the largest &lt;b&gt;long&lt;/b&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div align=&quot;left&quot; style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px;&quot;&gt;&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td width=&quot;20%&quot;&gt;659L&lt;/td&gt;&lt;td width=&quot;80%&quot;&gt;&amp;nbsp;Decimal integer literal of type long integer&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;20%&quot;&gt;&amp;nbsp;0x4a&lt;/td&gt;&lt;td width=&quot;80%&quot;&gt;&amp;nbsp;Hexadecimal integer literal of type integer&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;20%&quot;&gt;&amp;nbsp;057L&lt;/td&gt;&lt;td width=&quot;80%&quot;&gt;&amp;nbsp;Octal integer literal of type long integer&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: -webkit-auto;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 24px; text-align: -webkit-auto;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;u&gt;Character Literals&lt;/u&gt;&lt;/span&gt;&lt;/b&gt; &lt;/div&gt;&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 24px; text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;Characters in Java are indices into the Unicode character set. They are 16-bit values that&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;can be converted into integers and manipulated with the integer operators, such as the&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;addition and subtraction operators. A literal character is represented inside a pair of&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;single quotes. All of the visible ASCII characters can be directly entered inside the&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;quotes, such as &#39;a&#39;, &#39;z&#39;, and &#39;@&#39;. For characters that are impossible to enter directly, there&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;are several escape sequences, which allow you to enter the character you need, such as&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;&#39;\\&#39;&#39; for the single-quote character itself, and &#39;\\n&#39; for the newline character. There is also a&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;mechanism for directly entering the value of a character in octal or hexadecimal. For octal&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;notation use the backslash followed by the three-digit number. For example, &#39;\\141&#39; is the&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;letter &#39;a&#39;. For hexadecimal, you enter a backslash-u (\\u), then exactly four hexadecimal&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;digits. For example, &#39;\\u0061&#39; is the ISO-Latin-1 &#39;a&#39; because the top byte is zero. &#39;\\ua432&#39;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;is a Japanese Katakana character.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;&lt;b&gt;&lt;u&gt;Character Escape Sequences&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;&lt;b&gt;Escape&amp;nbsp;Sequence &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Description&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;\ddd &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;O ctal character (ddd)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;\uxxxx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Hexadecimal UNICODE character (xxxx)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;\&#39; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Single quote&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;\&quot; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Double quote&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;\\ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Backslash&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;\r &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;Carriage return&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;\n &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;New line (also known as line feed)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;\f &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;Form feed&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;\t &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;Tab&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;\b &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;Backspace&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 24px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 24px; text-align: -webkit-auto;&quot;&gt;Lets see the table below in which the character literals use Unicode escape sequence to represent printable and nonprintable characters both.&lt;/div&gt;&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 24px; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;left&quot; style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px;&quot;&gt;&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td width=&quot;37%&quot;&gt;&amp;nbsp;&#39;u0041&#39;&lt;/td&gt;&lt;td width=&quot;63%&quot;&gt;&amp;nbsp;Capital letter A&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;37%&quot;&gt;&amp;nbsp;&#39;\u0030&#39;&lt;/td&gt;&lt;td width=&quot;63%&quot;&gt;&amp;nbsp;Digit 0&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;37%&quot;&gt;&amp;nbsp;&#39;\u0022&#39;&lt;/td&gt;&lt;td width=&quot;63%&quot;&gt;&amp;nbsp;Double quote &quot;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;37%&quot;&gt;&amp;nbsp;&#39;\u003b&#39;&lt;/td&gt;&lt;td width=&quot;63%&quot;&gt;&amp;nbsp;Punctuation ;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;37%&quot;&gt;&amp;nbsp;&#39;\u0020&#39;&lt;/td&gt;&lt;td width=&quot;63%&quot;&gt;&amp;nbsp;Space&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;37%&quot;&gt;&amp;nbsp;&#39;\u0009&#39;&lt;/td&gt;&lt;td width=&quot;63%&quot;&gt;&amp;nbsp;Horizontal Tab&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div align=&quot;left&quot; style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #cc0000; font-family: Arial, Helvetica, sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&lt;b&gt;&lt;u&gt;Floating-Point Literals&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot; style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #cc0000; font-family: Arial, Helvetica, sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot; style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div align=&quot;left&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Floating-point numbers represent decimal values with a fractional component. They can&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;be expressed in either standard or scientific notation. Standard notation consists of a&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;whole number component followed by a decimal point followed by a fractional&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;component. For example, 2.0, 3.14159, and 0.6667 represent valid standard-notation&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;floating-point numbers. Scientific notation uses a standard-notation, floating-point number&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;plus a suffix that specifies a power of 10 by which the number is to be multiplied. The&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;exponent is indicated by an E or e followed by a decimal number, which can be positive&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;or negative. Examples include 6.022E23, 314159E–05, and 2e+100.&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Floating-point literals in Java default to &lt;b&gt;double &lt;/b&gt;precision. To specify a &lt;b&gt;float &lt;/b&gt;literal, you&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;must append an F or f to the constant. You can also explicitly specify a &lt;b&gt;double &lt;/b&gt;literal by&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;appending a D or d. Doing so is, of course, redundant. The default &lt;b&gt;double &lt;/b&gt;type&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;consumes 64 bits of storage, while the less-accurate &lt;b&gt;float &lt;/b&gt;type requires only 32 bits.&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot; style=&quot;line-height: 24px;&quot;&gt;&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&amp;nbsp;The default type when you write a floating-point literal is double.&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;table border=&quot;1&quot; cellspacing=&quot;0&quot; style=&quot;color: black; font-size: 13px; line-height: 24px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td width=&quot;41&quot;&gt;&lt;div align=&quot;center&quot;&gt;Type&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&lt;div align=&quot;center&quot;&gt;Size&lt;/div&gt;&lt;/td&gt;&lt;td width=&quot;93&quot;&gt;&lt;div align=&quot;center&quot;&gt;Range&lt;/div&gt;&lt;/td&gt;&lt;td width=&quot;97&quot;&gt;&lt;div align=&quot;center&quot;&gt;Precision&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div align=&quot;center&quot;&gt;name&lt;/div&gt;&lt;/td&gt;&lt;td width=&quot;37&quot;&gt;&lt;div align=&quot;center&quot;&gt;bytes&lt;/div&gt;&lt;/td&gt;&lt;td width=&quot;38&quot;&gt;&lt;div align=&quot;center&quot;&gt;bits&lt;/div&gt;&lt;/td&gt;&lt;td&gt;&lt;div align=&quot;center&quot;&gt;approximate&lt;/div&gt;&lt;/td&gt;&lt;td&gt;in decimal digits&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div align=&quot;center&quot;&gt;float&lt;/div&gt;&lt;/td&gt;&lt;td&gt;&lt;div align=&quot;center&quot;&gt;4&lt;/div&gt;&lt;/td&gt;&lt;td&gt;&lt;div align=&quot;center&quot;&gt;32&lt;/div&gt;&lt;/td&gt;&lt;td&gt;&lt;div align=&quot;center&quot;&gt;+/- 3.4 * 10&lt;sup&gt;38&lt;/sup&gt;&lt;/div&gt;&lt;/td&gt;&lt;td&gt;&lt;div align=&quot;center&quot;&gt;6-7&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div align=&quot;center&quot;&gt;double&lt;/div&gt;&lt;/td&gt;&lt;td&gt;&lt;div align=&quot;center&quot;&gt;8&lt;/div&gt;&lt;/td&gt;&lt;td&gt;&lt;div align=&quot;center&quot;&gt;64&lt;/div&gt;&lt;/td&gt;&lt;td&gt;&lt;div align=&quot;center&quot;&gt;+/- 1.8 * 10&lt;sup&gt;308&lt;/sup&gt;&lt;/div&gt;&lt;/td&gt;&lt;td&gt;&lt;div align=&quot;center&quot;&gt;15&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div align=&quot;left&quot;&gt;&lt;div style=&quot;line-height: 24px; text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;The following floating-point literals represent double-precision floating-point and floating-point values.&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot; style=&quot;font-size: 13px; line-height: 24px;&quot;&gt;&lt;table border=&quot;1&quot; cellpadding=&quot;1&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td width=&quot;37%&quot;&gt;&amp;nbsp;6.5E+32 (or 6.5E32)&lt;/td&gt;&lt;td width=&quot;63%&quot;&gt;&amp;nbsp;Double-precision floating-point literal&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;37%&quot;&gt;&amp;nbsp;7D&lt;/td&gt;&lt;td width=&quot;63%&quot;&gt;&amp;nbsp;Double-precision floating-point literal&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;37%&quot;&gt;&amp;nbsp;.01f&lt;/td&gt;&lt;td width=&quot;63%&quot;&gt;&amp;nbsp;Floating-point literal&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div align=&quot;left&quot;&gt;&lt;div align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;u&gt;Boolean Literals&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;Boolean literals are simple. There are only two logical values that a boolean value can&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;have, true and false. The values of true and false do not convert into any numerical&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;representation. The true literal in Java does not equal 1, nor does the false literal equal&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;0. In Java, they can only be assigned to variables declared as boolean, or used in&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;expressions with Boolean operators.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 24px; text-align: -webkit-auto;&quot;&gt;We have to use the values true and false to represent a Boolean value. Like&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue; font-size: 13px; line-height: 24px; text-align: -webkit-auto;&quot;&gt;boolean chosen = true;&lt;/span&gt; &lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: blue; font-size: 13px; line-height: 24px; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b style=&quot;line-height: 24px; text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;u&gt;String Literals&lt;/u&gt;&lt;/span&gt;&lt;/b&gt; &lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot; style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;left&quot;&gt;&lt;div style=&quot;font-size: 13px; line-height: 24px; text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;The string of characters is represented as String literals in Java. In Java a string is not a basic data type, rather it is an object. These strings are not stored in arrays as in C language. There are few methods provided in Java to combine strings, modify strings and to know whether to strings have the same value.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;We represent string literals as&lt;span style=&quot;color: blue;&quot;&gt;String myString = &quot;How are you?&quot;;&lt;br /&gt;
The above example shows how to represent a string. It consists of&amp;nbsp;&lt;/span&gt;a series of characters inside double quotation marks.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-size: 13px; line-height: 24px; text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Lets see some more&amp;nbsp;examples of string literals:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&quot;&quot;&amp;nbsp;&amp;nbsp;&amp;nbsp; // the empty string&lt;br /&gt;
&quot;\&quot;&quot;&amp;nbsp;&amp;nbsp; // a string containing &quot;&lt;br /&gt;
&quot;This is a string&quot;&amp;nbsp;&amp;nbsp; // a string containing 16 characters&lt;br /&gt;
&quot;This is a &quot; +&amp;nbsp;&amp;nbsp; // actually a string-valued constant expression,&lt;br /&gt;
&quot;two-line string&quot;&amp;nbsp;&amp;nbsp; //  formed from two string literals&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-size: 13px; line-height: 24px; text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Strings can include the character escape codes as well, as shown here:&lt;span style=&quot;color: blue;&quot;&gt;String example = &quot;Your Name, \&quot;Sumit\&quot;&quot;;&lt;br /&gt;
System.out.println(&quot;Thankingyou,\nRichards\n&quot;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-size: 13px; line-height: 24px; text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 24px; text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;u&gt;Null Literals&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 24px; text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;The final literal that we can use in Java programming is a Null literal. We specify the Null literal in the source code as &#39;null&#39;. To reduce the number of references to an object, use null literal. The type of the null literal is always null. We typically assign null literals to object reference variables. For instance&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: blue; font-size: 13px;&quot;&gt;s = null;&lt;/span&gt;&lt;span style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
An this example an object is referenced by s. We reduce the number of references to an object by assigning null to s. Now, as in this example the object is no longer referenced so it will be available for the garbage collection i.e. the compiler will destroy it and the free memory will be allocated to the other object. Well, we will later learn about garbage collection.&lt;/span&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/b&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;The final literal that we can use in Java programming is a Null literal. We specify the Null literal in the source code as &#39;null&#39;. To reduce the number of references to an object, use null literal. The type of the null literal is always null. We typically assign null literals to object reference variables. For instance&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: blue; font-size: 13px;&quot;&gt;s = null;&lt;/span&gt;&lt;span style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 24px; text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 13px;&quot;&gt;An this example an object is referenced by s. We reduce the number of references to an object by assigning null to s. Now, as in this example the object is no longer referenced so it will be available for the garbage collection i.e. the compiler will destroy it and the free memory will be allocated to the other object. Well, we will later learn about garbage collection.&lt;/span&gt; &lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/109578069809944484/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/closer-in-java-its-look-like-literals.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/109578069809944484'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/109578069809944484'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/closer-in-java-its-look-like-literals.html' title='Closer In Java, Its Look Like Literals'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-8554816227211121437</id><published>2012-01-01T19:32:00.000-08:00</published><updated>2012-01-02T08:13:37.273-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="Java Data Types"/><title type='text'>Data Types Comes Under Java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Overview&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
three of Java&#39;s most fundamental elements: data types, variables,&amp;nbsp;and arrays. As with all modern programming languages, Java supports several types of&amp;nbsp;data. You may use these types to declare variables and to create arrays. As you will see,&amp;nbsp;Java&#39;s approach to these items is clean, efficient, and cohesive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Note&lt;/b&gt;&lt;br /&gt;
If you come from a C or C++ background, keep in mind that Java is more strictly&lt;br /&gt;
typed than either language. For example, in C/C++ you can assign a floating-point&lt;br /&gt;
value to an integer. In Java, you cannot. Also, in C there is not necessarily strong&lt;br /&gt;
type-checking between a parameter and an argument. In Java, there is. You might&lt;br /&gt;
find Java&#39;s strong type-checking a bit tedious at first. But remember, in the long run&lt;br /&gt;
it will help reduce the possibility of errors in your code.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Java Simple Types&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Java defines eight simple (or elemental) types of data: byte, short, int, long, char, float,&lt;br /&gt;
double, and boolean. These can be put in four groups:&lt;br /&gt;
• Integers This group includes byte, short, int, and long, which are for whole-valued&lt;br /&gt;
signed numbers.&lt;br /&gt;
• Floating-point numbers This group includes float and double, which represent&lt;br /&gt;
numbers with fractional precision.&lt;br /&gt;
• Characters This group includes char, which represents symbols in a character set, like&lt;br /&gt;
letters and numbers.&lt;br /&gt;
• Boolean This group includes boolean, which is a special type for representing&lt;br /&gt;
true/false values.&lt;br /&gt;
&lt;br /&gt;
You can use these types as-is, or to construct arrays or your own class types. Thus, they&lt;br /&gt;
form the basis for all other types of data that you can create.&lt;br /&gt;
&lt;br /&gt;
The simple types represent single values—not complex objects. Although Java is&lt;br /&gt;
otherwise completely object-oriented, the simple types are not. They are analogous to the&lt;br /&gt;
simple types found in most other non–object-oriented languages. The reason for this is&lt;br /&gt;
efficiency. Making the simple types into objects would have degraded performance too&lt;br /&gt;
much.&lt;br /&gt;
The simple types are defined to have an explicit range and mathematical behavior.&lt;br /&gt;
Languages such as C and C++ allow the size of an integer to vary based upon the&lt;br /&gt;
dictates of the execution environment. However, Java is different. Because of Java&#39;s&lt;br /&gt;
portability requirement, all data types have a strictly defined range. For example, an int is&lt;br /&gt;
always 32 bits, regardless of the particular platform. This allows programs to be written&lt;br /&gt;
that are guaranteed to run without porting on any machine architecture. While strictly&lt;br /&gt;
specifying the size of an integer may cause a small loss of performance in some&lt;br /&gt;
environments, it is necessary in order to achieve portability.&lt;br /&gt;
Let&#39;s look at each type of data in turn.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Integers&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
Java defines four integer types: byte, short, int, and long. All of these are signed,&lt;br /&gt;
positive and negative values. Java does not support unsigned, positive-only integers.&lt;br /&gt;
Many other computer languages, including C/C++, support both signed and unsigned&lt;br /&gt;
integers. However, Java&#39;s designers felt that unsigned integers were unnecessary.&lt;br /&gt;
Specifically, they felt that the concept of unsigned was used mostly to specify the&lt;br /&gt;
behavior of the high-order bit, which defined the sign of an int when expressed as a&lt;br /&gt;
number. Java manages the meaning of the high-order bit&lt;br /&gt;
differently, by adding a special &quot;unsigned right shift&quot; operator. Thus, the need for an&lt;br /&gt;
unsigned integer type was eliminated.&lt;br /&gt;
The width of an integer type should not be thought of as the amount of storage it&lt;br /&gt;
consumes, but rather as the behavior it defines for variables and expressions of that type.&lt;br /&gt;
The Java run-time environment is free to use whatever size it wants, as long as the types&lt;br /&gt;
behave as you declared them. In fact, at least one implementation stores bytes and&lt;br /&gt;
shorts as 32-bit (rather than 8- and 16-bit) values to improve performance, because that&lt;br /&gt;
is the word size of most computers currently in use.&lt;br /&gt;
The width and ranges of these integer types vary widely, as shown in this table:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;Name &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Width &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Range &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
long &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;–9,223,372,036,854,775,808 to&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9 ,223,372,036,854,775,807&lt;br /&gt;
int &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;32 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;–2,147,483,648 to 2,147,483,647&lt;br /&gt;
&lt;br /&gt;
short &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;16 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;nbsp;32,768 to 32,767&lt;br /&gt;
&lt;br /&gt;
byte &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; – 128 to 127&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&amp;nbsp;look at each type of integer.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;byte&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
The smallest integer type is byte. This is a signed 8-bit type that has a range from –128&lt;br /&gt;
to 127. Variables of type byte are especially useful when you&#39;re working with a stream of&lt;br /&gt;
data from a network or file. They are also useful when you&#39;re working with raw binary&lt;br /&gt;
data that may not be directly compatible with Java&#39;s other built-in types.&lt;br /&gt;
Byte variables are declared by use of the byte keyword. For example, the following&lt;br /&gt;
declares two byte variables called b and c:&lt;br /&gt;
&lt;br /&gt;
byte b, c;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;short&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
short is a signed 16-bit type. It has a range from –32,768 to 32,767. It is probably the&lt;br /&gt;
least-used Java type, since it is defined as having its high byte first (called big-endian&lt;br /&gt;
format). This type is mostly applicable to 16-bit computers, which are becoming&lt;br /&gt;
increasingly scarce.&lt;br /&gt;
Here are some examples of short variable declarations:&lt;br /&gt;
short s;&lt;br /&gt;
short t;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Note&lt;/b&gt;&lt;br /&gt;
&quot;Endianness&quot; describes how multibyte data types, such as short, int, and&lt;br /&gt;
long, are stored in memory. If it takes 2 bytes to represent a short, then&lt;br /&gt;
which one comes first, the most significant or the least significant? To say that&lt;br /&gt;
a machine is big-endian, means that the most significant byte is first, followed&lt;br /&gt;
by the least significant one. Machines such as the SPARC and PowerPC are&lt;br /&gt;
big-endian, while the Intel x86 series is little-endian.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;int&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
The most commonly used integer type is int. It is a signed 32-bit type that has a range&lt;br /&gt;
from –2,147,483,648 to 2,147,483,647. In addition to other uses, variables of type int are&lt;br /&gt;
commonly employed to control loops and to index arrays. Any time you have an integer&lt;br /&gt;
expression involving bytes, shorts, ints, and literal numbers, the entire expression is&lt;br /&gt;
promoted to int before the calculation is done.&lt;br /&gt;
The int type is the most versatile and efficient type, and it should be used most of the&lt;br /&gt;
time when you want to create a number for counting or indexing arrays or doing integer&lt;br /&gt;
math. It may seem that using short or byte will save space, but there is no guarantee&lt;br /&gt;
that Java won&#39;t promote those types to int internally anyway. Remember, type&lt;br /&gt;
determines behavior, not size. (The only exception is arrays, where byte is guaranteed to&lt;br /&gt;
use only one byte per array element, short will use two bytes, and int will use four.)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;long&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
long is a signed 64-bit type and is useful for those occasions where an int type is not&lt;br /&gt;
large enough to hold the desired value. The range of a long is quite large. This makes it&lt;br /&gt;
useful when big, whole numbers are needed. For example, here is a program that&lt;br /&gt;
computes the number of miles that light will travel in a specified number of days.&lt;br /&gt;
// Compute distance light travels using long variables.&lt;br /&gt;
class Light {&lt;br /&gt;
public static void main(String args[]) {&lt;br /&gt;
int lightspeed;&lt;br /&gt;
long days;&lt;br /&gt;
long seconds;&lt;br /&gt;
long distance;&lt;br /&gt;
// approximate speed of light in miles per second&lt;br /&gt;
lightspeed = 186000;&lt;br /&gt;
days = 1000; // specify number of days here&lt;br /&gt;
seconds = days * 24 * 60 * 60; // convert to seconds&lt;br /&gt;
distance = lightspeed * seconds; // compute distance&lt;br /&gt;
System.out.print(&quot;In &quot; + days);&lt;br /&gt;
System.out.print(&quot; days light will travel about &quot;);&lt;br /&gt;
System.out.println(distance + &quot; miles.&quot;);&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;This program output:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
In 1000 days light will travel about 16070400000000 miles.&lt;br /&gt;
&lt;br /&gt;
Clearly, the result could not have been held in an int variable.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Floating-Point Types&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
Floating-point numbers, also known as real numbers, are used when evaluating&lt;br /&gt;
expressions that require fractional precision. For example, calculations such as square&lt;br /&gt;
root, or transcendentals such as sine and cosine, result in a value whose precision&lt;br /&gt;
requires a floating-point type. Java implements the standard (IEEE–754) set of floatingpoint&lt;br /&gt;
types and operators. There are two kinds of floating-point types, float and double,&lt;br /&gt;
which represent single- and double-precision numbers, respectively. Their width and&lt;br /&gt;
ranges are shown here:&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;Name &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Width in&amp;nbsp;Bits &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Range&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;double&lt;/b&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;64 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1.7e–308 to 1.7e+308&lt;br /&gt;
&lt;b&gt;float &amp;nbsp; &lt;/b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;32 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3.4e–038 to 3.4e+038&lt;br /&gt;
&lt;br /&gt;
Each of these floating-point types is examined next.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;float.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
The type &lt;b&gt;float &lt;/b&gt;specifies a single-precision value that uses 32 bits of storage. Single&lt;br /&gt;
precision is faster on some processors and takes half as much space as double&lt;br /&gt;
precision, but will become imprecise when the values are either very large or very small.&lt;br /&gt;
Variables of type &lt;b&gt;float &lt;/b&gt;are useful when you need a fractional component, but don&#39;t&lt;br /&gt;
require a large degree of precision. For example, &lt;b&gt;float &lt;/b&gt;can be useful when representing&lt;br /&gt;
dollars and cents.&lt;br /&gt;
Here are some example &lt;b&gt;float &lt;/b&gt;variable declarations:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;float hightemp, lowtemp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;b&gt;double&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
Double precision, as denoted by the &lt;b&gt;double &lt;/b&gt;keyword, uses 64 bits to store a value.&lt;br /&gt;
Double precision is actually faster than single precision on some modern processors that&lt;br /&gt;
have been optimized for high-speed mathematical calculations. All transcendental math&lt;br /&gt;
functions, such as &lt;b&gt;sin( ), cos( ), and sqrt( ),&lt;/b&gt; return &lt;b&gt;double &lt;/b&gt;values. When you need to&lt;br /&gt;
maintain accuracy over many iterative calculations, or are manipulating large-valued&lt;br /&gt;
numbers, &lt;b&gt;double &lt;/b&gt;is the best choice.&lt;br /&gt;
Here is a short program that uses double variables to compute the area of a circle:&lt;br /&gt;
// Compute the area of a circle.&lt;br /&gt;
class Area {&lt;br /&gt;
public static void main(String args[]) {&lt;br /&gt;
double pi, r, a;&lt;br /&gt;
r = 10.8; // radius of circle&lt;br /&gt;
pi = 3.1416; // pi, approximately&lt;br /&gt;
a = pi * r * r; // compute area&lt;br /&gt;
- 40 -&lt;br /&gt;
System.out.println(&quot;Area of circle is &quot; + a);&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Characters&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
In Java, the data type used to store characters is &lt;b&gt;char&lt;/b&gt;. However, C/C++ programmers&lt;br /&gt;
beware: &lt;b&gt;char &lt;/b&gt;in Java is not the same as &lt;b&gt;char &lt;/b&gt;in C or C++. In C/C++, &lt;b&gt;char &lt;/b&gt;is an integer&lt;br /&gt;
type that is 8 bits wide. This is not the case in Java. Instead, Java uses Unicode to&lt;br /&gt;
represent characters. Unicode defines a fully international character set that can&lt;br /&gt;
represent all of the characters found in all human languages. It is a unification of dozens&lt;br /&gt;
of character sets, such as Latin, Greek, Arabic, Cyrillic, Hebrew, Katakana, Hangul, and&lt;br /&gt;
many more. For this purpose, it requires 16 bits. Thus, in Java &lt;b&gt;char &lt;/b&gt;is a 16-bit type. The&lt;br /&gt;
range of a &lt;b&gt;char &lt;/b&gt;is 0 to 65,536. There are no negative &lt;b&gt;chars&lt;/b&gt;. The standard set of&lt;br /&gt;
characters known as ASCII still ranges from 0 to 127 as always, and the extended 8-bit&lt;br /&gt;
character set, ISO-Latin-1, ranges from 0 to 255. Since Java is designed to allow applets&lt;br /&gt;
to be written for worldwide use, it makes sense that it would use Unicode to represent&lt;br /&gt;
characters. Of course, the use of Unicode is somewhat inefficient for languages such as&lt;br /&gt;
English, German, Spanish, or French, whose characters can easily be contained within 8&lt;br /&gt;
bits. But such is the price that must be paid for global portability.&lt;br /&gt;
Note More information about Unicode can be found at http://www.unicode.org.&lt;br /&gt;
Here is a program that demonstrates &lt;b&gt;char &lt;/b&gt;variables:&lt;br /&gt;
// Demonstrate char data type.&lt;br /&gt;
class CharDemo {&lt;br /&gt;
public static void main(String args[]) {&lt;br /&gt;
char ch1, ch2;&lt;br /&gt;
ch1 = 88; // code for X&lt;br /&gt;
ch2 = &#39;Y&#39;;&lt;br /&gt;
System.out.print(&quot;ch1 and ch2: &quot;);&lt;br /&gt;
System.out.println(ch1 + &quot; &quot; + ch2);&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
This program output:&lt;br /&gt;
&lt;br /&gt;
ch1 and ch2: X Y&lt;br /&gt;
&lt;br /&gt;
Notice that &lt;b&gt;ch1 &lt;/b&gt;is assigned the value 88, which is the ASCII (and Unicode) value that&lt;br /&gt;
corresponds to the letter X. As mentioned, the ASCII character set occupies the first 127&lt;br /&gt;
values in the Unicode character set. For this reason, all the &quot;old tricks&quot; that you have&lt;br /&gt;
used with characters in the past will work in Java, too.&lt;br /&gt;
Even though &lt;b&gt;char&lt;/b&gt;s are not integers, in many cases you can operate on them as if they&lt;br /&gt;
were integers. This allows you to add two characters together, or to increment the value&lt;br /&gt;
of a character variable. For example, consider the following program:&lt;br /&gt;
// char variables behave like integers.&lt;br /&gt;
class CharDemo2 {&lt;br /&gt;
public static void main(String args[]) {&lt;br /&gt;
char ch1;&lt;br /&gt;
ch1 = &#39;X&#39;;&lt;br /&gt;
System.out.println(&quot;ch1 contains &quot; + ch1);&lt;br /&gt;
ch1++; // increment ch1&lt;br /&gt;
System.out.println(&quot;ch1 is now &quot; + ch1);&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
The output &amp;nbsp;program is shown here:&lt;br /&gt;
&lt;br /&gt;
ch1 contains X&lt;br /&gt;
ch1 is now Y&lt;br /&gt;
&lt;br /&gt;
In the program, &lt;b&gt;ch1 &lt;/b&gt;is first given the value X. Next, &lt;b&gt;ch1 &lt;/b&gt;is incremented. This results in &lt;b&gt;ch1&lt;/b&gt;&lt;br /&gt;
containing Y, the next character in the ASCII (and Unicode) sequence.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Booleans:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
Java has a simple type, called &lt;b&gt;boolean&lt;/b&gt;, for logical values. It can have only one of two&lt;br /&gt;
possible values, &lt;b&gt;true &lt;/b&gt;or &lt;b&gt;false&lt;/b&gt;. This is the type returned by all relational operators, such&lt;br /&gt;
as &lt;b&gt;a &amp;lt; b. &lt;/b&gt;boolean is also the type required by the conditional expressions that govern the&lt;br /&gt;
control statements such as &lt;b&gt;if &lt;/b&gt;and &lt;b&gt;for&lt;/b&gt;.&lt;br /&gt;
Here is a program that demonstrates the boolean type:&lt;br /&gt;
// Demonstrate boolean values.&lt;br /&gt;
class BoolTest {&lt;br /&gt;
public static void main(String args[]) {&lt;br /&gt;
boolean b;&lt;br /&gt;
b = false;&lt;br /&gt;
System.out.println(&quot;b is &quot; + b);&lt;br /&gt;
b = true;&lt;br /&gt;
System.out.println(&quot;b is &quot; + b);&lt;br /&gt;
// a boolean value can control the if statement&lt;br /&gt;
if(b) System.out.println(&quot;This is executed.&quot;);&lt;br /&gt;
b = false;&lt;br /&gt;
if(b) System.out.println(&quot;This is not executed.&quot;);&lt;br /&gt;
// outcome of a relational operator is a boolean value&lt;br /&gt;
System.out.println(&quot;10 &amp;gt; 9 is &quot; + (10 &amp;gt; 9));&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
The output shown here:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;b is false&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;b is true&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;This is executed.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;10 &amp;gt; 9 is true&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
There are three interesting things to notice about this program. First, as you can see,&lt;br /&gt;
when a &lt;b&gt;boolean &lt;/b&gt;value is output by &lt;b&gt;println( )&lt;/b&gt;, &quot;true&quot; or &quot;false&quot; is displayed. Second, the&lt;br /&gt;
value of a &lt;b&gt;boolean &lt;/b&gt;variable is sufficient, by itself, to control the &lt;b&gt;if &lt;/b&gt;statement. There is no&lt;br /&gt;
need to write an &lt;b&gt;if &lt;/b&gt;statement like this:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;if(b == true) ...&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
Third, the outcome of a relational operator, such as &amp;lt;, is a &lt;b&gt;boolean &lt;/b&gt;value. This is why the&lt;br /&gt;
expression &lt;b&gt;10 &amp;gt; 9&lt;/b&gt; displays the value &quot;true.&quot; Further, the extra set of parentheses around &lt;b&gt;10&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;gt; 9&lt;/b&gt; is necessary because the &lt;b&gt;+ &lt;/b&gt;operator has a higher precedence than the&lt;b&gt; &amp;gt;.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/8554816227211121437/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/data-types-comes-under-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/8554816227211121437'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/8554816227211121437'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2012/01/data-types-comes-under-java.html' title='Data Types Comes Under Java'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-9217466359917954632</id><published>2011-12-31T04:38:00.000-08:00</published><updated>2011-12-31T04:38:07.197-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Class Libraries"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><title type='text'>Class Libraries in Java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;b&gt;println( ) and print( )&lt;/b&gt;. As mentioned, these methods are members of the &lt;b&gt;System class&lt;/b&gt;,&lt;br /&gt;
which is a class predefined by Java that is automatically included in your programs. In the&lt;br /&gt;
larger view, the Java environment relies on several built-in class libraries that contain many&lt;br /&gt;
built-in methods that provide support for such things as I/O, string handling, networking,&lt;br /&gt;
and graphics. The standard classes also provide support for windowed output. Thus, Java&lt;br /&gt;
as a totality is a combination of the Java language itself, plus its standard classes. As you&lt;br /&gt;
will see, the class libraries provide much of the functionality that comes with Java. Indeed,&lt;br /&gt;
part of becoming a Java programmer is learning to use the standard Java classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/9217466359917954632/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2011/12/class-libraries-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/9217466359917954632'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/9217466359917954632'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2011/12/class-libraries-in-java.html' title='Class Libraries in Java'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-4087042145091670039</id><published>2011-12-30T10:35:00.000-08:00</published><updated>2011-12-30T10:35:11.016-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Comments"/><category scheme="http://www.blogger.com/atom/ns#" term="Identifiers"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="Keywords"/><category scheme="http://www.blogger.com/atom/ns#" term="literals"/><category scheme="http://www.blogger.com/atom/ns#" term="Separators"/><category scheme="http://www.blogger.com/atom/ns#" term="Whitespace"/><title type='text'>Lexical Issues ( atomic elements of Java )</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
Now that you have seen several short Java programs, it is time to more formally describe&lt;br /&gt;
the atomic elements of Java. Java programs are a collection of&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;whitespace&amp;nbsp;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;b&gt;identifiers&lt;/b&gt; &lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;b&gt;&lt;b&gt;comments&lt;/b&gt; &lt;/b&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;b&gt;&lt;b&gt;&lt;b&gt;literals&lt;/b&gt; &lt;/b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;b&gt;&lt;b&gt;&lt;b&gt;&lt;b&gt;operators&lt;/b&gt; &lt;/b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;b&gt;&lt;b&gt;&lt;b&gt;&lt;b&gt;&lt;b&gt;separators&lt;/b&gt; &lt;/b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;b&gt;&lt;b&gt;&lt;b&gt;&lt;b&gt;&lt;b&gt;&lt;b&gt;keywords&lt;/b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;u&gt;Whitespace&amp;nbsp;&lt;/u&gt;&lt;/span&gt;&lt;/b&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;Java is a free-form language. This means that you do not need to follow any special&lt;/div&gt;&lt;div&gt;indentation rules. For example, the Example program could have been written all on one&lt;/div&gt;&lt;div&gt;line or in any other strange way you felt like typing it, as long as there was at least one&lt;/div&gt;&lt;div&gt;whitespace character between each token that was not already delineated by an operator&lt;/div&gt;&lt;div&gt;or separator. In Java, whitespace is a space, tab, or newline.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;Identifiers&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/b&gt; &lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;Identifiers are used for class names, method names, and variable names. An identifier&lt;/div&gt;&lt;div&gt;may be any descriptive sequence of uppercase and lowercase letters, numbers, or the&lt;/div&gt;&lt;div&gt;underscore and dollar-sign characters. They must not begin with a number, lest they be&lt;/div&gt;&lt;div&gt;confused with a numeric literal. Again, Java is case-sensitive, so &lt;b&gt;VALUE &lt;/b&gt;is a different&lt;/div&gt;&lt;div&gt;identifier than &lt;b&gt;Value&lt;/b&gt;.&lt;/div&gt;&lt;div&gt;Some examples of valid identifiers are:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;HighTemp &amp;nbsp; &amp;nbsp;&amp;nbsp;temp &amp;nbsp; &amp;nbsp;h8 &amp;nbsp; &amp;nbsp; &amp;nbsp;$low &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;this_is_ok&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;Invalid variable names include:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;2temp &amp;nbsp; &amp;nbsp; &amp;nbsp;low-temp &amp;nbsp; &amp;nbsp;Yes/ok&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;Comments&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;As mentioned, there are three types of comments defined by Java. You have already&lt;/div&gt;&lt;div&gt;seen two:&amp;nbsp;&lt;/div&gt;&lt;div&gt;1) single-line( // )&amp;nbsp;&lt;/div&gt;&lt;div&gt;2) multiline. &amp;nbsp;//&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The third type is called a documentation comment.&lt;/div&gt;&lt;div&gt;This type of comment is used to produce an HTML file that documents your program. The&lt;/div&gt;&lt;div&gt;documentation comment begins with a&amp;nbsp;&lt;/div&gt;&lt;div&gt;/* and ends with a */.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;literals&lt;/span&gt;&lt;/u&gt;&lt;/b&gt; &lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;A constant value in Java is created by using a literal representation of it. For example,&lt;/div&gt;&lt;div&gt;here are some literals:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #4c1130;&quot;&gt;100 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;literal specifies an integer&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #4c1130;&quot;&gt;98.6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;literal specifies&amp;nbsp;a floating-point value&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #4c1130;&quot;&gt;&#39;X&#39; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;literal specifies&amp;nbsp;is a character constant&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #4c1130;&quot;&gt;&quot;This is a test&quot; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;literal specifies&amp;nbsp; is a string&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&amp;nbsp;A literal can be used anywhere a value of&lt;/div&gt;&lt;div&gt;its type is allowed.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;Separators&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;In Java, there are a few characters that are used as separators. The most commonly&lt;/div&gt;&lt;div&gt;used separator in Java is the semicolon. As you have seen, it is used to terminate&lt;/div&gt;&lt;div&gt;statements. The separators are shown in the following table:&lt;/div&gt;&lt;div&gt;Symbol &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Name &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Purpose&lt;/div&gt;&lt;div&gt;( ) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Parentheses &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Used to contain lists of parameters in method&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; definition and invocation. Also used for defining&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; precedence in expressions, containing expressions in&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; control statements, and surrounding cast types.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;{ } &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Braces &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Used to contain the values of automatically initialized&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;arrays. Also used to define a block of code, for&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;classes, methods, and local scopes.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;[ ] &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Brackets &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Used to declare array types. Also used when&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dereferencing array values.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Semicolon &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Terminates statements.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Comma &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Separates consecutive identifiers in a variable&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;declaration. Also used to chain statements together&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; inside a for statement.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Period &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Used to separate package names from subpackages&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;and classes. Also used to separate a variable or&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;method from a reference variable.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;u&gt;Keywords in Java&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;br /&gt;
&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;There are 48 reserved keywords currently defined in the Java language.&lt;/div&gt;&lt;div&gt;These keywords, combined with the syntax of the operators and separators, form the&lt;/div&gt;&lt;div&gt;definition of the Java language. These keywords cannot be used as names for a variable,&lt;/div&gt;&lt;div&gt;class, or method&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;abstract &amp;nbsp;&amp;nbsp;const &amp;nbsp;&amp;nbsp;Finally &amp;nbsp;&amp;nbsp;int &amp;nbsp;&amp;nbsp;Public &amp;nbsp;&amp;nbsp;this &amp;nbsp;&amp;nbsp;boolean &amp;nbsp;&amp;nbsp;continue &amp;nbsp;&amp;nbsp;Float &amp;nbsp;&amp;nbsp;interface &amp;nbsp;&amp;nbsp;Return &amp;nbsp;&amp;nbsp;throw&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;break &amp;nbsp;&amp;nbsp;default &amp;nbsp; &amp;nbsp;For &amp;nbsp; &amp;nbsp; &amp;nbsp;long &amp;nbsp;&amp;nbsp;Short &amp;nbsp; &amp;nbsp;throws &amp;nbsp; &amp;nbsp;byte &amp;nbsp; &amp;nbsp; &amp;nbsp;do &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Goto &amp;nbsp; &amp;nbsp;native &amp;nbsp; &amp;nbsp; &amp;nbsp;Static &amp;nbsp;&amp;nbsp;transient&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;case &amp;nbsp; &amp;nbsp;&amp;nbsp;double &amp;nbsp; &amp;nbsp;&amp;nbsp;If &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;new &amp;nbsp;&amp;nbsp;Strictfp &amp;nbsp; try &amp;nbsp; &amp;nbsp; &amp;nbsp;catch &amp;nbsp; &amp;nbsp;&amp;nbsp;else &amp;nbsp; &amp;nbsp;&amp;nbsp;Implements &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;package &amp;nbsp; &amp;nbsp;&amp;nbsp;Super&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;void &amp;nbsp; &amp;nbsp; &amp;nbsp;char &amp;nbsp; &amp;nbsp;&amp;nbsp;extends &amp;nbsp; &amp;nbsp;Import &amp;nbsp;&amp;nbsp;private &amp;nbsp; &amp;nbsp;Switch &amp;nbsp; &amp;nbsp;volatile &amp;nbsp;&amp;nbsp;class &amp;nbsp; &amp;nbsp;&amp;nbsp;final &amp;nbsp; &amp;nbsp;Instanceof &amp;nbsp;&amp;nbsp;protected&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Synchronized &amp;nbsp; &amp;nbsp;while&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The keywords const and goto are reserved but not used.&lt;/div&gt;&lt;div&gt;&lt;div&gt;In addition to the keywords, Java reserves the following:&lt;b&gt; true, false, and null&lt;/b&gt;. These are&lt;/div&gt;&lt;div&gt;values defined by Java. You may not use these words for the names of variables, classes,&lt;/div&gt;&lt;div&gt;and so on.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/4087042145091670039/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2011/12/lexical-issues-atomic-elements-of-java.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/4087042145091670039'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/4087042145091670039'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2011/12/lexical-issues-atomic-elements-of-java.html' title='Lexical Issues ( atomic elements of Java )'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</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>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-4529588984330523890</id><published>2011-12-30T09:36:00.000-08:00</published><updated>2011-12-30T09:36:44.395-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Code blocks"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><title type='text'>Using Blocks of Code ( Code blocks )</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Java allows two or more statements to be grouped into &lt;i style=&quot;color: #cc0000;&quot;&gt;blocks of code &lt;/i&gt;also called &lt;span style=&quot;color: #cc0000; font-style: italic;&quot;&gt;code blocks&lt;/span&gt;.This is done by enclosing the statement between opening and closing curly braces.A block of statement should be a logical statement. It works a particular task. For example, a block can be a target for Java&#39;s &lt;b&gt;if&lt;/b&gt;&amp;nbsp;and &lt;b&gt;for&lt;/b&gt;&amp;nbsp;statement&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;if ( x &amp;lt; y ) { &amp;nbsp;// Block begins&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;x = y;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;y = 0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;} &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//Blocks end&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
Here, if value of &lt;b&gt;x&lt;/b&gt;&amp;nbsp;is less than &lt;b&gt;y&lt;/b&gt;&amp;nbsp;then we&amp;nbsp;enters&amp;nbsp;the code block for execution. What ever we given in the code block it will execute&lt;br /&gt;
Lets look at another example. The following program uses a block of code as the target of a &lt;b&gt;for &lt;/b&gt;loop&lt;br /&gt;
&lt;br /&gt;
class BlockTest {&lt;br /&gt;
public static void main ( String args [ ] ) &amp;nbsp;{&lt;br /&gt;
&lt;br /&gt;
int x, y;&lt;br /&gt;
y = 20;&lt;br /&gt;
&lt;br /&gt;
for ( x = 0; x &amp;lt; 10; x++) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp;System.out.println ( &quot; This is X= &quot; +x);&lt;br /&gt;
&amp;nbsp; &amp;nbsp;System.out.println ( &quot; This is Y= &quot; +y);&lt;br /&gt;
&amp;nbsp; &amp;nbsp;y = y - 2;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp;}&lt;br /&gt;
}&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/4529588984330523890/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2011/12/using-blocks-of-code-code-blocks.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/4529588984330523890'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/4529588984330523890'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2011/12/using-blocks-of-code-code-blocks.html' title='Using Blocks of Code ( Code blocks )'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-4928791212171459258</id><published>2011-12-29T10:11:00.000-08:00</published><updated>2011-12-29T10:11:41.060-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="for Loop"/><title type='text'>The for Loop with Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: -webkit-auto;&quot;&gt;The for loop is the type of&amp;nbsp; looping construct. It also works as while loop construct but it provide the initialization, condition and the increment&amp;nbsp; is same written in the for construct. All the statements which has to be executed written in the for block &lt;/div&gt;&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: -webkit-auto;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: -webkit-auto;&quot;&gt;&lt;b&gt;The Syntax for the For Loop:&lt;/b&gt;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;for( initialization; termination; increment)&lt;br /&gt;
&amp;nbsp; {&lt;br /&gt;
&amp;nbsp; statements;&lt;br /&gt;
&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: -webkit-auto;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: -webkit-auto;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; text-align: -webkit-auto;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;public class &amp;nbsp;ForLoop {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; public static void main(String[] args) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; for(int i = 1;i &amp;lt;= 5;i++) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; System.out.print(i);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/4928791212171459258/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2011/12/for-loop-with-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/4928791212171459258'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/4928791212171459258'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2011/12/for-loop-with-example.html' title='The for Loop with Example'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-536871808819492457</id><published>2011-12-29T09:57:00.000-08:00</published><updated>2011-12-29T09:57:32.878-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="if statement"/><title type='text'>if Control Statements with example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;b&gt;The if Statement&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 17px; text-align: justify;&quot;&gt;The&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;exd_c&quot; style=&quot;background-color: white; font-family: &#39;Lucida Console&#39;, Monaco, monospace; font-size: 14px; line-height: 17px; text-align: justify;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 17px; text-align: justify;&quot;&gt;&amp;nbsp;statement encloses some code which is executed only if a condition is true. The general syntax of the&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;exd_c&quot; style=&quot;background-color: white; font-family: &#39;Lucida Console&#39;, Monaco, monospace; font-size: 14px; line-height: 17px; text-align: justify;&quot;&gt;if&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 17px; text-align: justify;&quot;&gt;statement is:&lt;/span&gt; &lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 17px; text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;exd_code_body&quot; style=&quot;background-color: white; color: #31331f; font-family: &#39;Lucida Console&#39;, Monaco, monospace; font-size: 12px; line-height: 17px; overflow-x: auto; overflow-y: auto; padding-bottom: 0.5em !important; padding-left: 0.5em !important; padding-right: 0.5em !important; padding-top: 0.5em !important; text-align: justify;&quot;&gt;if (&lt;span class=&quot;exd_v&quot; style=&quot;color: blue; font-style: italic;&quot;&gt;condition&lt;/span&gt;) {
    &lt;span class=&quot;exd_v&quot; style=&quot;color: blue; font-style: italic;&quot;&gt;body-code&lt;/span&gt;
}&lt;/pre&gt;&lt;pre class=&quot;exd_code_body&quot; style=&quot;background-color: white; color: #31331f; font-family: &#39;Lucida Console&#39;, Monaco, monospace; font-size: 12px; line-height: 17px; overflow-x: auto; overflow-y: auto; padding-bottom: 0.5em !important; padding-left: 0.5em !important; padding-right: 0.5em !important; padding-top: 0.5em !important; text-align: justify;&quot;&gt;&lt;/pre&gt;&lt;pre class=&quot;exd_code_body&quot; style=&quot;background-color: white; font-family: &#39;Lucida Console&#39;, Monaco, monospace; font-size: 12px; line-height: 17px; overflow-x: auto; overflow-y: auto; padding-bottom: 0.5em !important; padding-left: 0.5em !important; padding-right: 0.5em !important; padding-top: 0.5em !important; text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; white-space: normal;&quot;&gt;The&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;exd_c&quot; style=&quot;font-size: 14px; white-space: normal;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; white-space: normal;&quot;&gt;&amp;nbsp;statement has two parts. The&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;exd_v&quot; style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-style: italic; white-space: normal;&quot;&gt;condition&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; white-space: normal;&quot;&gt;&amp;nbsp;is a boolean expression which resolves to either true or false. The&lt;/span&gt;&lt;span class=&quot;exd_v&quot; style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-style: italic; white-space: normal;&quot;&gt;body-code&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; white-space: normal;&quot;&gt;&amp;nbsp;is code that will be executed only if the condition is true. Here is an example of the&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;exd_c&quot; style=&quot;font-size: 14px; white-space: normal;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; white-space: normal;&quot;&gt;&amp;nbsp;statement.&lt;/span&gt;&lt;/pre&gt;&lt;pre class=&quot;exd_code_body&quot; style=&quot;background-color: white; font-family: &#39;Lucida Console&#39;, Monaco, monospace; font-size: 12px; line-height: 17px; overflow-x: auto; overflow-y: auto; padding-bottom: 0.5em !important; padding-left: 0.5em !important; padding-right: 0.5em !important; padding-top: 0.5em !important; text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;u&gt;Example&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;/pre&gt;&lt;pre class=&quot;exd_code_body&quot; style=&quot;background-color: white; overflow-x: auto; overflow-y: auto; padding-bottom: 0.5em !important; padding-left: 0.5em !important; padding-right: 0.5em !important; padding-top: 0.5em !important; text-align: justify;&quot;&gt;&lt;pre class=&quot;exd_code_body&quot; style=&quot;color: #31331f; font-family: &#39;Lucida Console&#39;, Monaco, monospace; font-size: 12px; line-height: 17px; overflow-x: auto; overflow-y: auto; padding-bottom: 0.5em !important; padding-left: 0.5em !important; padding-right: 0.5em !important; padding-top: 0.5em !important;&quot;&gt;// Returns 0 if s is null
public int getLength(String s) {
    if (s == null) {
        // This line of code is execute only if s is null
        return 0;
    }
    return s.length();
}&lt;/pre&gt;&lt;pre class=&quot;exd_code_body&quot; style=&quot;color: #31331f; font-family: &#39;Lucida Console&#39;, Monaco, monospace; font-size: 12px; line-height: 17px; overflow-x: auto; overflow-y: auto; padding-bottom: 0.5em !important; padding-left: 0.5em !important; padding-right: 0.5em !important; padding-top: 0.5em !important;&quot;&gt;&lt;/pre&gt;&lt;pre class=&quot;exd_code_body&quot; style=&quot;overflow-x: auto; overflow-y: auto; padding-bottom: 0.5em !important; padding-left: 0.5em !important; padding-right: 0.5em !important; padding-top: 0.5em !important;&quot;&gt;&lt;span style=&quot;color: #31331f; font-family: &#39;Lucida Console&#39;, Monaco, monospace; font-size: 12px; line-height: 17px;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 17px; white-space: normal;&quot;&gt;The&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;exd_c&quot; style=&quot;font-family: &#39;Lucida Console&#39;, Monaco, monospace; font-size: 14px; line-height: 17px; white-space: normal;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 17px; white-space: normal;&quot;&gt;&amp;nbsp;statement also has an optional&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;exd_c&quot; style=&quot;font-family: &#39;Lucida Console&#39;, Monaco, monospace; font-size: 14px; line-height: 17px; white-space: normal;&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 17px; white-space: normal;&quot;&gt;&amp;nbsp;part which encloses some code that is executed only if the&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;exd_v&quot; style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-style: italic; line-height: 17px; white-space: normal;&quot;&gt;condition&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 17px; white-space: normal;&quot;&gt;&amp;nbsp;is false. Here is the general syntax of the&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;exd_c&quot; style=&quot;font-family: &#39;Lucida Console&#39;, Monaco, monospace; font-size: 14px; line-height: 17px; white-space: normal;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 17px; white-space: normal;&quot;&gt;&amp;nbsp;statement with the optional&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;exd_c&quot; style=&quot;font-family: &#39;Lucida Console&#39;, Monaco, monospace; font-size: 14px; line-height: 17px; white-space: normal;&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 17px; white-space: normal;&quot;&gt;&amp;nbsp;part:&lt;/span&gt;&lt;span style=&quot;color: #31331f; font-family: &#39;Lucida Console&#39;, Monaco, monospace;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 17px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre class=&quot;exd_code_body&quot; style=&quot;overflow-x: auto; overflow-y: auto; padding-bottom: 0.5em !important; padding-left: 0.5em !important; padding-right: 0.5em !important; padding-top: 0.5em !important; text-align: justify;&quot;&gt;&lt;b style=&quot;color: black; font-family: &#39;Times New Roman&#39;; font-size: medium; line-height: normal; text-align: left; white-space: normal;&quot;&gt;
&lt;/b&gt;&lt;/pre&gt;&lt;pre class=&quot;exd_code_body&quot; style=&quot;overflow-x: auto; overflow-y: auto; padding-bottom: 0.5em !important; padding-left: 0.5em !important; padding-right: 0.5em !important; padding-top: 0.5em !important; text-align: justify;&quot;&gt;&lt;b style=&quot;color: black; font-family: &#39;Times New Roman&#39;; font-size: medium; line-height: normal; text-align: left; white-space: normal;&quot;&gt;The if Statement with else&lt;/b&gt;&lt;/pre&gt;&lt;pre class=&quot;exd_code_body&quot; style=&quot;overflow-x: auto; overflow-y: auto; padding-bottom: 0.5em !important; padding-left: 0.5em !important; padding-right: 0.5em !important; padding-top: 0.5em !important;&quot;&gt;&lt;span style=&quot;color: #31331f; font-family: &#39;Lucida Console&#39;, Monaco, monospace;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 17px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;pre class=&quot;exd_code_body&quot; style=&quot;color: #31331f; font-family: &#39;Lucida Console&#39;, Monaco, monospace; font-size: 12px; line-height: 17px; overflow-x: auto; overflow-y: auto; padding-bottom: 0.5em !important; padding-left: 0.5em !important; padding-right: 0.5em !important; padding-top: 0.5em !important;&quot;&gt;if (&lt;span class=&quot;exd_v&quot; style=&quot;color: blue; font-style: italic;&quot;&gt;condition&lt;/span&gt;) {
    &lt;span class=&quot;exd_v&quot; style=&quot;color: blue; font-style: italic;&quot;&gt;body-code&lt;/span&gt;
} else {
    &lt;span class=&quot;exd_v&quot; style=&quot;color: blue; font-style: italic;&quot;&gt;else-code&lt;/span&gt;
}&lt;/pre&gt;&lt;/pre&gt;&lt;pre class=&quot;exd_code_body&quot; style=&quot;color: #31331f; font-family: &#39;Lucida Console&#39;, Monaco, monospace; font-size: 12px; line-height: 17px; overflow-x: auto; overflow-y: auto; padding-bottom: 0.5em !important; padding-left: 0.5em !important; padding-right: 0.5em !important; padding-top: 0.5em !important;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; white-space: normal;&quot;&gt;The&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;exd_v&quot; style=&quot;color: blue; font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-style: italic; white-space: normal;&quot;&gt;else-code&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; white-space: normal;&quot;&gt;&amp;nbsp;is executed only if&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;exd_v&quot; style=&quot;color: blue; font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-style: italic; white-space: normal;&quot;&gt;condition&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; white-space: normal;&quot;&gt;&amp;nbsp;resolves to false. Here is an example of the&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;exd_c&quot; style=&quot;font-size: 14px; white-space: normal;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; white-space: normal;&quot;&gt;&amp;nbsp;statement with the optional&lt;/span&gt;&lt;span class=&quot;exd_c&quot; style=&quot;font-size: 14px; white-space: normal;&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; white-space: normal;&quot;&gt;&amp;nbsp;part&lt;/span&gt;
&lt;/pre&gt;&lt;span style=&quot;color: #31331f; font-family: &#39;Lucida Console&#39;, Monaco, monospace; font-size: 12px; line-height: 17px;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;pre class=&quot;exd_code_body&quot; style=&quot;background-color: white; font-family: &#39;Lucida Console&#39;, Monaco, monospace; font-size: 12px; line-height: 17px; overflow-x: auto; overflow-y: auto; padding-bottom: 0.5em !important; padding-left: 0.5em !important; padding-right: 0.5em !important; padding-top: 0.5em !important; text-align: justify;&quot;&gt;&lt;pre class=&quot;exd_code_body&quot; style=&quot;font-family: &#39;Lucida Console&#39;, Monaco, monospace; overflow-x: auto; overflow-y: auto; padding-bottom: 0.5em !important; padding-left: 0.5em !important; padding-right: 0.5em !important; padding-top: 0.5em !important;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;u&gt;Example&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;/pre&gt;&lt;pre class=&quot;exd_code_body&quot; style=&quot;color: #31331f; font-family: &#39;Lucida Console&#39;, Monaco, monospace; overflow-x: auto; overflow-y: auto; padding-bottom: 0.5em !important; padding-left: 0.5em !important; padding-right: 0.5em !important; padding-top: 0.5em !important;&quot;&gt;// Generates a random number and prints whether it is even or odd
if ((int)(Math.random()*100)%2 == 0) {
    System.out.println(&quot;The number is even&quot;);
} else {
    System.out.println(&quot;The number is odd&quot;);
}&lt;/pre&gt;&lt;/pre&gt;&lt;pre class=&quot;exd_code_body&quot; style=&quot;background-color: white; font-family: &#39;Lucida Console&#39;, Monaco, monospace; font-size: 12px; line-height: 17px; overflow-x: auto; overflow-y: auto; padding-bottom: 0.5em !important; padding-left: 0.5em !important; padding-right: 0.5em !important; padding-top: 0.5em !important; text-align: justify;&quot;&gt;&lt;span style=&quot;color: #31331f; font-family: Arial, Helvetica, sans-serif; font-size: 14px; white-space: normal;&quot;&gt;The&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;exd_v&quot; style=&quot;color: blue; font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-style: italic; white-space: normal;&quot;&gt;else-code&lt;/span&gt;&lt;span style=&quot;color: #31331f; font-family: Arial, Helvetica, sans-serif; font-size: 14px; white-space: normal;&quot;&gt;&amp;nbsp;part can also be another&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;exd_c&quot; style=&quot;color: #31331f; font-size: 14px; white-space: normal;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #31331f; font-family: Arial, Helvetica, sans-serif; font-size: 14px; white-space: normal;&quot;&gt;&amp;nbsp;statement. An&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;exd_c&quot; style=&quot;color: #31331f; font-size: 14px; white-space: normal;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #31331f; font-family: Arial, Helvetica, sans-serif; font-size: 14px; white-space: normal;&quot;&gt;&amp;nbsp;statement written this way sets up a sequence of&lt;/span&gt;&lt;span class=&quot;exd_c&quot; style=&quot;color: #31331f; font-size: 14px; white-space: normal;&quot;&gt;condition&lt;/span&gt;&lt;span style=&quot;color: #31331f; font-family: Arial, Helvetica, sans-serif; font-size: 14px; white-space: normal;&quot;&gt;&#39;s, each tested one after the other in top-down order. If one of the conditions is found to be true, the&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;exd_v&quot; style=&quot;color: blue; font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-style: italic; white-space: normal;&quot;&gt;body-code&lt;/span&gt;&lt;span style=&quot;color: #31331f; font-family: Arial, Helvetica, sans-serif; font-size: 14px; white-space: normal;&quot;&gt;&amp;nbsp;for that&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;exd_c&quot; style=&quot;color: #31331f; font-size: 14px; white-space: normal;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #31331f; font-family: Arial, Helvetica, sans-serif; font-size: 14px; white-space: normal;&quot;&gt;&amp;nbsp;statement is executed. Once executed, no other conditions are tested and execution continues after the sequence. Here is an example of a sequence of&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;exd_c&quot; style=&quot;color: #31331f; font-size: 14px; white-space: normal;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #31331f; font-family: Arial, Helvetica, sans-serif; font-size: 14px; white-space: normal;&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;exd_c&quot; style=&quot;color: #31331f; font-size: 14px; white-space: normal;&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #31331f; font-family: Arial, Helvetica, sans-serif; font-size: 14px; white-space: normal;&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;exd_c&quot; style=&quot;color: #31331f; font-size: 14px; white-space: normal;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #31331f; font-family: Arial, Helvetica, sans-serif; font-size: 14px; white-space: normal;&quot;&gt;&amp;nbsp;statements&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/536871808819492457/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2011/12/if-control-statements-with-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/536871808819492457'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/536871808819492457'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2011/12/if-control-statements-with-example.html' title='if Control Statements with example'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-4533800265887015299</id><published>2011-12-28T10:47:00.000-08:00</published><updated>2011-12-29T08:58:50.020-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Compiling The Java Program"/><title type='text'>Compiling The Java Program With environment variables</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 15px; line-height: 19px;&quot;&gt;In WINDOWS 2000 you do not use AUTOEXEC.BAT file. Instead you create environment variables. On your computer desktop right click the My Computer icon and select Properties.&lt;/span&gt; &lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcPzECeWZLH5ioq61eB0pt7nCo-jgxmxCnlzNp3QHE24r1m0HsY0DsRJxXOENw9YC1UXHHbkU9dNMGaV_81qk2Km4g8LYSP_cciB7ED5_omCz2JpRtDtXFsk1g4RbueFbImbCF7IkBAC0/s1600/env_variables1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcPzECeWZLH5ioq61eB0pt7nCo-jgxmxCnlzNp3QHE24r1m0HsY0DsRJxXOENw9YC1UXHHbkU9dNMGaV_81qk2Km4g8LYSP_cciB7ED5_omCz2JpRtDtXFsk1g4RbueFbImbCF7IkBAC0/s1600/env_variables1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 15px; line-height: 19px; text-align: left;&quot;&gt;&lt;b&gt;On the System Properties window select Advance tab.&lt;/b&gt;&lt;/span&gt; &lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhla4xP7pfAKG2TIkEQ68KJZr_y3QcQcH0zdRUccniHfilgPXPaLmnQNeuMkCPIVKSxe4gYGuwYY4X7MNqbYNv8u-o1KH_DcNWnaZtYY5n0y_6h1h1CPMxtTQRnfSgKixQeLEvWk9mAnwc/s1600/env_variables2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhla4xP7pfAKG2TIkEQ68KJZr_y3QcQcH0zdRUccniHfilgPXPaLmnQNeuMkCPIVKSxe4gYGuwYY4X7MNqbYNv8u-o1KH_DcNWnaZtYY5n0y_6h1h1CPMxtTQRnfSgKixQeLEvWk9mAnwc/s1600/env_variables2.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; font-size: 15px; line-height: 19px; text-align: left;&quot;&gt;On Windows 7 select Start, right click Computer. Click Advance System setting on System properties window select Advance tab, Click Environment Variables button&lt;/div&gt;&lt;div style=&quot;background-color: white; font-size: 15px; line-height: 19px; text-align: left;&quot;&gt;On Windows XP, to get to the same System Properties window, select&amp;nbsp;&lt;b&gt;Start&lt;/b&gt;, Select&amp;nbsp;&lt;b&gt;Control panel&lt;/b&gt;,&lt;/div&gt;&lt;div style=&quot;background-color: white; font-size: 15px; line-height: 19px; text-align: left;&quot;&gt;In the opened Control panel select&amp;nbsp;&lt;b&gt;Performance and Maintenance&lt;/b&gt;&amp;nbsp;(it is ar the bottom),&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhysHLophPmAFT2uV57OvxhfvLo-F8HGWlgZcI0LJf4cekHmVciemNzAUGOqarUNXps2ux61OKZVcE7WxtyTXLtbj1Ls7Zy3WQOWQdbDPX6GkatmUpQdZ8GNi3PU85KnGBU_Bo4xU7f_7s/s1600/env_variables3.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhysHLophPmAFT2uV57OvxhfvLo-F8HGWlgZcI0LJf4cekHmVciemNzAUGOqarUNXps2ux61OKZVcE7WxtyTXLtbj1Ls7Zy3WQOWQdbDPX6GkatmUpQdZ8GNi3PU85KnGBU_Bo4xU7f_7s/s1600/env_variables3.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 15px; line-height: 19px; text-align: left;&quot;&gt;Select&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: white; font-size: 15px; line-height: 19px; text-align: left;&quot;&gt;System, Advance tab.&lt;/b&gt; &lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5InaknuvZ7TiYxBeRqBhGaF0pr34zRauvbxOLNYPie98mNtE0dJ-zJZ0pSa64Vwvd-IvvqIYEXvASaRfFev6-nKq2xqRgkSVTbrIa0i-YOqrtmpDxcV_a-o4b0K-GnWaDpdSJYWTIaiY/s1600/env_variables4.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5InaknuvZ7TiYxBeRqBhGaF0pr34zRauvbxOLNYPie98mNtE0dJ-zJZ0pSa64Vwvd-IvvqIYEXvASaRfFev6-nKq2xqRgkSVTbrIa0i-YOqrtmpDxcV_a-o4b0K-GnWaDpdSJYWTIaiY/s1600/env_variables4.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjypdfW48IWLdiuew8Uon432CH_b9pq_shzOKVVjJ6wQCbpDIcK9ioC7G_ezn4cBk4sImZRMhYh2psBiLwESLg76bmXxlsg_XlEaJDQ0ljBtkrsLEPqN_GTw72natmwaaUXI_SrH7ri2Jg/s1600/env_variables5.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjypdfW48IWLdiuew8Uon432CH_b9pq_shzOKVVjJ6wQCbpDIcK9ioC7G_ezn4cBk4sImZRMhYh2psBiLwESLg76bmXxlsg_XlEaJDQ0ljBtkrsLEPqN_GTw72natmwaaUXI_SrH7ri2Jg/s1600/env_variables5.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 15px; line-height: 19px; text-align: left;&quot;&gt;Click the Environmental Variables button. Environment Variables window displays.&lt;/span&gt; &lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimhlYIl24lFDy1A1ptSws8AivY-zeXTxt21KbnSsRSkGV9b-_nrerMGHLZzsTEGqQqprOFA7_YFarV9J-td-O2w3M3I0Bahc2J2BCGDaRKvbzlnRvuoroBQi8qPgzOUp0lS6R3JWv8Q6A/s1600/env_variables6.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimhlYIl24lFDy1A1ptSws8AivY-zeXTxt21KbnSsRSkGV9b-_nrerMGHLZzsTEGqQqprOFA7_YFarV9J-td-O2w3M3I0Bahc2J2BCGDaRKvbzlnRvuoroBQi8qPgzOUp0lS6R3JWv8Q6A/s1600/env_variables6.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 15px; line-height: 19px; text-align: left;&quot;&gt;Click New button in System variables frame at the bottom of the Environment Variables Window. For Java SDK enter Path environment variable and.&lt;/span&gt; &lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJOGsip9xQEcdabIXc4GR6N-SMcGwLa2bi2o1a8beSa6VF9HNSbH0T5l3UG2hUm2UKxV_PpzZdRJRlCcgs9M50tm7of496trI55FdXFLMxB01UabfQzPyHMttcKJAPrFhY7joCePmg_WA/s1600/env_variables7.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJOGsip9xQEcdabIXc4GR6N-SMcGwLa2bi2o1a8beSa6VF9HNSbH0T5l3UG2hUm2UKxV_PpzZdRJRlCcgs9M50tm7of496trI55FdXFLMxB01UabfQzPyHMttcKJAPrFhY7joCePmg_WA/s1600/env_variables7.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; font-size: 15px; line-height: 19px; text-align: left;&quot;&gt;enter path to JAVA bin folder on your PC. On mine it is C:\j2sdk1.4.0\bin. Type semicolon at the end. If you installed tomcat after java type path to tomcat bin folder on your PC. On mine it is C:\j2sdk1.4.0\bin;C:\jakarta-tomcat-4.1.29\bin;. Do not forget to type semicolon. Click OK button. Click OK button on Environment Variables window. Click OK button on Properties window.&lt;/div&gt;&lt;div style=&quot;background-color: white; font-size: 15px; line-height: 19px; text-align: left;&quot;&gt;To execute Java program create CLASSPATH environment variable.&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_8jw7y7bqawrxNWtYK2lbiPRuQreNoNL0Eu2JJmxXF6ku83Gxmg7XQG6QWIMWpcu9ipVk0ChqQQpubpCFsCwuYEXmrS7YXcdWcdGEhTjQMdM5PJnUY5TUqnhy3VEy6VrTFZ-1VHQc58Q/s1600/env_variables8.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_8jw7y7bqawrxNWtYK2lbiPRuQreNoNL0Eu2JJmxXF6ku83Gxmg7XQG6QWIMWpcu9ipVk0ChqQQpubpCFsCwuYEXmrS7YXcdWcdGEhTjQMdM5PJnUY5TUqnhy3VEy6VrTFZ-1VHQc58Q/s1600/env_variables8.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTExk4Tht6mJlCmOz2KfvbzCGSgKJ12Dfohyt_Qt7panGhS6UTwuw2jEzqVBQCsr9z_S9okUGJWfIKhL1vBdAezF7X0wYbjr2imv99qLt70YLjkYzc4ScdUWspWlspu04LSKKz0jeUmsQ/s1600/env_variables9.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTExk4Tht6mJlCmOz2KfvbzCGSgKJ12Dfohyt_Qt7panGhS6UTwuw2jEzqVBQCsr9z_S9okUGJWfIKhL1vBdAezF7X0wYbjr2imv99qLt70YLjkYzc4ScdUWspWlspu04LSKKz0jeUmsQ/s1600/env_variables9.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 15px; line-height: 19px; text-align: left;&quot;&gt;For Tomcat enter CATALINA_HOME environment variable name and path to the folder where your tomcat installed. On mine it is C:\jakarta-tomcat-4.1.29&lt;/span&gt; &lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEnqKDfNTvtism0hjq0gqxIv8aj5fL3Gn34Lcltfh6CrqcSlhr7WcZYoMKJKuNy6cD8RtCFerR7N2GwlZmIqYrH7hbM7T-LeD3JzVVoo2WBchrGofk0eEcP-IVLe4gpw92KEyw9hCkB50/s1600/env_variables10.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEnqKDfNTvtism0hjq0gqxIv8aj5fL3Gn34Lcltfh6CrqcSlhr7WcZYoMKJKuNy6cD8RtCFerR7N2GwlZmIqYrH7hbM7T-LeD3JzVVoo2WBchrGofk0eEcP-IVLe4gpw92KEyw9hCkB50/s1600/env_variables10.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 15px; line-height: 19px; text-align: left;&quot;&gt;To run Tomcat you need to create JAVA_HOME environment variable. To check your configuration for Tomcat go to C:\jakarta-tomcat-4.1.29\bin directory, type startup and press enter.&lt;/span&gt; &lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_vtkyEXN1OF4q2BL3hSfuyLsj3KPVYM6WZ4-Grk1MTbo3f21g_YV66BH_u537-eZ2mSLRF9tjPpmBjSJfuDjEEWI81iCibY5WyT7IivK_ZYsHXaEZgUzKOJJlcuMAhNct3_4PwOF7hB8/s1600/env_variables11.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_vtkyEXN1OF4q2BL3hSfuyLsj3KPVYM6WZ4-Grk1MTbo3f21g_YV66BH_u537-eZ2mSLRF9tjPpmBjSJfuDjEEWI81iCibY5WyT7IivK_ZYsHXaEZgUzKOJJlcuMAhNct3_4PwOF7hB8/s1600/env_variables11.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 15px; line-height: 19px; text-align: left;&quot;&gt;Tomcat starts in separate command prompt window.&lt;/span&gt; &lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCLKKC7ls3RaXk7PmeIpVAdYXVxxABNwqTHs3lVvm9HIUIDuRnzx6eiL2ON6Cd2mSZ09STu1R4dDr_8wiBXp96-GIcveTkPSxHb2IHK7lPt9xHsng-qIv0UPTdBqaca_XroAwHIwRIWbo/s1600/env_variables12.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCLKKC7ls3RaXk7PmeIpVAdYXVxxABNwqTHs3lVvm9HIUIDuRnzx6eiL2ON6Cd2mSZ09STu1R4dDr_8wiBXp96-GIcveTkPSxHb2IHK7lPt9xHsng-qIv0UPTdBqaca_XroAwHIwRIWbo/s1600/env_variables12.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; font-size: 15px; line-height: 19px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; font-size: 15px; line-height: 19px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; font-size: 15px; line-height: 19px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; font-size: 15px; line-height: 19px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; font-size: 15px; line-height: 19px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; font-size: 15px; line-height: 19px;&quot;&gt;If Tomcat does not start, probably you have not enough memory set in command prompt. Go to command prompt menu on your desktop and right click it&lt;/span&gt; &lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhW-leywpD5Z4C2RVuEwoGiH7omSqcuu0mNb0UB8UPivrho41HUiv5Ym3l3UBdEi_ALbrlmMhUbzGYGpWpVMdBpulxSTv2U5V9KhSMb_4MWoWIzmPpmJw3SgvfiMATjCCUxiuCtbve0mc/s1600/env_variables13.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhW-leywpD5Z4C2RVuEwoGiH7omSqcuu0mNb0UB8UPivrho41HUiv5Ym3l3UBdEi_ALbrlmMhUbzGYGpWpVMdBpulxSTv2U5V9KhSMb_4MWoWIzmPpmJw3SgvfiMATjCCUxiuCtbve0mc/s1600/env_variables13.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 15px; line-height: 19px; text-align: left;&quot;&gt;From drop down menu select properties. Select memory tab. Increase convention memory and click OK to save changes.&lt;/span&gt; &lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhh65O1SGziDMi7SQRjG6HOgaMe6cgf1nmzwCQFXjMP6NjJw3UnwrD0JKBydoUzFPgTC96Igsptw9SNtEWVEyoLVvU6T4wcHsyiaxv5HDEd3aVtYHneXMMx2Zty7OwcQOL2cAa7fBISUhk/s1600/env_variables14.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhh65O1SGziDMi7SQRjG6HOgaMe6cgf1nmzwCQFXjMP6NjJw3UnwrD0JKBydoUzFPgTC96Igsptw9SNtEWVEyoLVvU6T4wcHsyiaxv5HDEd3aVtYHneXMMx2Zty7OwcQOL2cAa7fBISUhk/s1600/env_variables14.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; font-size: 15px; line-height: 19px; text-align: left;&quot;&gt;Close command prompt if you had it open. Open again and try to start Tomcat.&lt;/div&gt;&lt;div style=&quot;background-color: white; font-size: 15px; line-height: 19px; text-align: left;&quot;&gt;Now it should be started. To make sure that Tomcat is running properly, open Internet Explored and type URL address:&lt;/div&gt;&lt;div style=&quot;background-color: white; font-size: 15px; line-height: 19px; text-align: left;&quot;&gt;http://localhost:8080&lt;/div&gt;&lt;div style=&quot;background-color: white; font-size: 15px; line-height: 19px; text-align: left;&quot;&gt;Tomcat home page displays.&lt;/div&gt;&lt;div style=&quot;background-color: white; font-size: 15px; line-height: 19px; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/4533800265887015299/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2011/12/compiling-java-program-with-environment.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/4533800265887015299'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/4533800265887015299'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2011/12/compiling-java-program-with-environment.html' title='Compiling The Java Program With environment variables'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</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><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcPzECeWZLH5ioq61eB0pt7nCo-jgxmxCnlzNp3QHE24r1m0HsY0DsRJxXOENw9YC1UXHHbkU9dNMGaV_81qk2Km4g8LYSP_cciB7ED5_omCz2JpRtDtXFsk1g4RbueFbImbCF7IkBAC0/s72-c/env_variables1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-6600678368149347702</id><published>2011-12-28T10:26:00.000-08:00</published><updated>2011-12-29T08:58:50.046-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Objects"/><title type='text'>Java Objects with Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;&lt;div align=&quot;center&quot; style=&quot;text-align: -webkit-auto;&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: crimson; font-family: &amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;u&gt;Objects&lt;/u&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;a href=&quot;&quot; name=&quot;obj&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: crimson; font-family: &amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Object-oriented programming focuses on constructs called “&lt;b&gt;objects&lt;/b&gt;.” An object consists of data and functions known as&amp;nbsp;&lt;i&gt;&lt;b&gt;methods&lt;/b&gt;&lt;/i&gt;&amp;nbsp;which use or change the data. (Methods are similar to procedures or functions in other languages.)&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;Objects of the same kind are said to have the same type or be in the same class. A&amp;nbsp;&lt;i&gt;class&lt;/i&gt;&amp;nbsp;defines what data can be in an object, and what operations are performed by the methods. One or more objects can be created or “instantiated” from a class.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;The structure of a Java program consists of various objects exchanging messages. The keyword&amp;nbsp;&lt;b&gt;class&lt;/b&gt;&amp;nbsp;defines a blueprint for objects with similar properties.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&lt;b&gt;In our first example we define the class&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Courier; font-size: 13.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;Particle&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;b&gt;.&amp;nbsp;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; margin-left: 12.2pt; margin-right: 0in; margin-top: 0in;&quot;&gt;&lt;span style=&quot;color: red; font-family: Courier; font-size: 13.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; margin-left: 12.2pt; margin-right: 0in; margin-top: 0in;&quot;&gt;&lt;span style=&quot;color: red; font-family: Courier; font-size: 13.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;public class Particle&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; margin-left: 12.2pt; margin-right: 0in; margin-top: 0in;&quot;&gt;&lt;span style=&quot;color: red; font-family: Courier; font-size: 13.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; margin-left: 12.2pt; margin-right: 0in; margin-top: 0in;&quot;&gt;&lt;span style=&quot;color: red; font-family: Courier; font-size: 13.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp; double x, y, vx, vy, mass;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; margin-left: 12.2pt; margin-right: 0in; margin-top: 0in;&quot;&gt;&lt;span style=&quot;color: red; font-family: Courier; font-size: 13.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; margin-left: 12.2pt; margin-right: 0in; margin-top: 0in;&quot;&gt;&lt;span style=&quot;color: red; font-family: Courier; font-size: 13.0pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;This class does not do anything (because it has no methods), but it can be used to describe a particle by its position, velocity, and mass. For simplicity, we will consider only two dimensions.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Georgia&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/6600678368149347702/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2011/12/java-objects-with-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/6600678368149347702'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/6600678368149347702'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2011/12/java-objects-with-example.html' title='Java Objects with Example'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-1034908600257288195</id><published>2011-12-28T09:47:00.000-08:00</published><updated>2011-12-29T08:58:50.068-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java Introduction"/><title type='text'>What is Java?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;A&lt;b&gt; high-level programming language&lt;/b&gt; developed by Sun Microsystems. Java was originally called OAK, and was designed for handheld devices and set-top boxes. Oak was unsuccessful so in 1995 Sun changed the name to Java and modified the language to take advantage of the burgeoning World Wide Web.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Java is an object-oriented language&lt;/b&gt; similar to C++, but simplified to eliminate language features that cause common programming errors. Java source code files (files with a .java extension) are compiled into a format called bytecode (files with a .class extension), which can then be executed by a Java interpreter. Compiled Java code can run on most computers because Java interpreters and runtime environments, known as Java Virtual Machines (VMs), exist for most operating systems, including UNIX, the Macintosh OS, and Windows. Bytecode can also be converted directly into machine language instructions by a just-in-time compiler (JIT).&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Java is a general purpose programming language with a number of features that make the language well suited for use on the World Wide Web. &lt;b&gt;Small Java applications are called Java applets&lt;/b&gt; and can be downloaded from a Web server and run on your computer by a Java-compatible Web browser, such as Netscape Navigator or Microsoft Internet Explorer.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/1034908600257288195/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2011/12/what-is-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/1034908600257288195'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/1034908600257288195'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2011/12/what-is-java.html' title='What is Java?'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-3153428271140223873</id><published>2010-06-02T11:00:00.000-07:00</published><updated>2011-12-29T08:55:35.276-08:00</updated><title type='text'>mp pet 2010, mp pet vyapam, mp pet result 2010 online</title><content type='html'>mp pet 2010, mp pet vyapam, mp pet result 2010 online&lt;br /&gt;&lt;br /&gt;Madhya Pradesh Professional Examination Board is likely to publish mp pet result 2010 online at vyapam official website of www.vyapam.nic.in.&lt;br /&gt;&lt;br /&gt;Students are currently eagerly searching for mppetresult 2010, pet result, mppetresult2010, mppet. Currently vyapam official website of www.vyapam.nic.in is not working properly because of heavey traffic load.&lt;br /&gt;&lt;br /&gt;Once mp pet result 2010 is pubilshed online then students can check pet result 2010 of MPPET online. We closely checking that website and we will update here when site get tun properly. Students of General Nursing Training can check result for GNTST 2010 or the General Nursing Training Selection Test online.&lt;br /&gt;&lt;br /&gt;Tags: mp pet 2010, mp pet vyapam, mp pet 2010 result, vyapam, mp pet result 2010, pet result, pet result 2010, mp pet result, mppet result 2010, mp pet result 2010, mp pet vyapam, mppetresult 2010, mppetresult2010, mppet</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/3153428271140223873/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2010/06/mp-pet-2010-mp-pet-vyapam-mp-pet-result.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/3153428271140223873'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/3153428271140223873'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2010/06/mp-pet-2010-mp-pet-vyapam-mp-pet-result.html' title='mp pet 2010, mp pet vyapam, mp pet result 2010 online'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-3737237741914563829</id><published>2010-06-02T10:51:00.000-07:00</published><updated>2011-12-29T08:55:35.299-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="news"/><category scheme="http://www.blogger.com/atom/ns#" term="sports"/><title type='text'>French Open Results Suddenly Unpredictable</title><content type='html'>The French Open results had been fairly conventional most of the way. But with the most recent French Open results, no one now knows what to expect. Neither Roger Federer or Serena Williams&lt;br /&gt; will even be around for the semifinals, leaving a few newcomers in the mix. With only Rafael Nadal left among the big names, it might be the worst case outcome for tennis and NBC. There are no Federer-Nadal or Williams sister finals to hype for the weekend, and some may have never heard of many remaining players. But the French Open results guarantee new blood at the end, and could still have a power matchup or two.&lt;br /&gt;&lt;br /&gt;At the least, things have gotten exciting after a conventional first week plus The only notable upset beforehand was Venus Williams getting knocked out last weekend. Otherwise, it looked like the French Open results would be predictable, at least until the championship.&lt;br /&gt;&lt;br /&gt;Fans expected a new Federer-Nadal showdown on Sunday morning, and another Serena Williams title on Saturday. Both scenarios are no more, thanks to Robin Soderling and Samantha Stosur. However, these two giant killers could provide intrigue at the end, assuming they don&#39;t fall off in the semis.&lt;br /&gt;&lt;br /&gt;The French Open results in the last two days did not give Soderling or Stosur a title. In fact, if Soderling loses in the semifinals, he will have done worse in this year&#39;s tournament than last year&#39;s. To make the finals for the second year in a row, Soderling still has to beat Tomas Berdych, who reached his first Grand Slam semifinal yesterday.&lt;br /&gt;&lt;br /&gt;With no Federer-Nadal match to hype, the new highly anticipated final would be Nadal vs Soderling. The French Open results last year had Soderling end Nadal&#39;s long reign at Roland Garros. After beating Federer to go with it, a rematch is already being projected. But first, Nadal has to beat Nicolas Almagro - who he leads by two sets after two tiebreakers - and then either Novak Djokovic or Jurgen Melzer.For the women, the French Open results are harder to put up with. With both Williams sisters gone, the rest of the field will make headlines at the end for once. No matter what, there will be a new champion, as no one left has ever won a Grand Slam.</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/3737237741914563829/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2010/06/french-open-results-suddenly.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/3737237741914563829'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/3737237741914563829'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2010/06/french-open-results-suddenly.html' title='French Open Results Suddenly Unpredictable'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-8296670124775048711</id><published>2010-03-07T09:06:00.000-08:00</published><updated>2011-12-29T08:55:35.325-08:00</updated><title type='text'>Varudu Songs Free Download</title><content type='html'>&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;http://1.bp.blogspot.com/_bRz8H3W0bYE/S5Pe3j1tWvI/AAAAAAAAAD8/4V5_ZHUiDXE/s1600-h/Varudu-Songs-Free-Download-.jpg&quot;&gt;&lt;img style=&quot;float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 244px; height: 244px;&quot; src=&quot;http://1.bp.blogspot.com/_bRz8H3W0bYE/S5Pe3j1tWvI/AAAAAAAAAD8/4V5_ZHUiDXE/s320/Varudu-Songs-Free-Download-.jpg&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5445941420515744498&quot; /&gt;&lt;/a&gt;&lt;br /&gt;Varudu Songs Free Download, Allu Arjun’s Arya 2 released on yesterday but Arya 2 not got the good response from the audience like as Arya Movie. Allu Arjun’s new film ‘Varudu’ has almost completed its shooting. No sooner releasing Arya 2, Varudu is gearing up for a release. Recently it has completed shooting except some action scenes and two songs&lt;br /&gt;&lt;br /&gt;Allu Arjun’s Varudu is directed by Gunasekhar is getting ready to release in the Summer 2010. The special attraction in the movie is Tamil actor Arya, He’s doing a negative role. This is Arya’s first time ever negative role in a movie. Other than Arya, The comedy king of Tollywood Brahmanandam, Suhasini Mani Ratnam, Ashish Vidyarthi and Sayaji Shinde playing supporting roles. Themovie has been produced by D.V.V. Danaiya.&lt;br /&gt;&lt;br /&gt;Varudu is a drama based movie in which Allu Arjun’s performance and Tamil hero Arya’s role in negative shade will be highlight for this movie.&lt;br /&gt;&lt;br /&gt;In this movie director introducing a new heroine through this flick. For about a 100 families have acted in this movie.</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/8296670124775048711/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2010/03/varudu-songs-free-download.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/8296670124775048711'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/8296670124775048711'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2010/03/varudu-songs-free-download.html' title='Varudu Songs Free Download'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</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><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_bRz8H3W0bYE/S5Pe3j1tWvI/AAAAAAAAAD8/4V5_ZHUiDXE/s72-c/Varudu-Songs-Free-Download-.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-4689928528656038594</id><published>2010-02-28T00:56:00.000-08:00</published><updated>2011-12-29T08:55:35.346-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="technology"/><title type='text'>How WiMAX Works</title><content type='html'>Think about how you access the Internet today. There are basically three different options: &lt;br /&gt;Broadband access - In your home, you have either a DSL or cable modem. At the office, your company may be using a T1 or a T3 line. &lt;br /&gt;&lt;br /&gt;WiFi access - In your home, you may have set up a WiFi router that lets you surf the Web while you lounge with your laptop. On the road, you can find WiFi hot spots in restaurants, hotels, coffee shops and libraries. &lt;br /&gt;&lt;br /&gt;Dial-up access - If you are still using dial-up, chances are that either broadband access is not available, or you think that broadband access is too expensive. &lt;br /&gt;&lt;br /&gt;The main problems with broadband access are that it is pretty expensive and it doesn&#39;t reach all areas. The main problem with WiFi access is that hot spots are very small, so coverage is sparse.&lt;br /&gt;&lt;br /&gt;What if there were a new technology that solved all of these problems? This new technology would provide: &lt;br /&gt;The high speed of broadband service &lt;br /&gt;Wireless rather than wired access, so it would be a lot less expensive than cable or DSL and much easier to extend to suburban and rural areas &lt;br /&gt;Broad coverage like the cell phone network instead of small WiFi hotspots &lt;br /&gt;&lt;br /&gt;This system is actually coming into being right now, and it is called WiMAX. WiMAX is short for Worldwide Interoperability for Microwave Access, and it also goes by the IEEE name 802.16. &lt;br /&gt;&lt;br /&gt;WiMAX has the potential to do to broadband Internet access what cell phones have done to phone access. In the same way that many people have given up their &quot;land lines&quot; in favor of cell phones, WiMAX could replace cable and DSL services, providing universal Internet access just about anywhere you go. WiMAX will also be as painless as WiFi -- turning your computer on will automatically connect you to the closest available WiMAX antenna. &lt;br /&gt;&lt;br /&gt;In this article, we&#39;ll find out how WiMAX works, what engineers are doing to make it better and what it could mean for the future of wireless Internet. &lt;br /&gt;&lt;br /&gt;Next Page</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/4689928528656038594/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2010/02/how-wimax-works.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/4689928528656038594'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/4689928528656038594'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2010/02/how-wimax-works.html' title='How WiMAX Works'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-3710691352044656806</id><published>2010-02-28T00:51:00.000-08:00</published><updated>2011-12-29T08:55:35.364-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="movie"/><category scheme="http://www.blogger.com/atom/ns#" term="news"/><title type='text'>India&amp;#39;s &amp;#39;biggest song&amp;#39; readies for launch</title><content type='html'>MUMBAI: For the first time ever, over 450 artistes have lent their voices for a single song - the Marathi Abhimaan Geet - which will be launched in Thane on Marathi Bhasha Diwas - February 27.&lt;br /&gt;&lt;br /&gt;The song, penned by noted Marathi poet Suresh Bhat, has been set to tune by well known composer Kaushal Inamdar. Labhale amhas bhagya bolato Marathi has been sung by 112 established singers and a chorus of 356 upcoming singers. It was recorded in Mumbai, Chennai and Thane with 12 sound engineers and 65 musicians.&lt;br /&gt;&lt;br /&gt;The well-known singers include Ashwini Bhide Deshpande, Suresh Wadkar, Arti Anklikar, Avadhoot Gupte, Mahalakshmi Iyer and more. Inamdar invited Shankar Mahadevan too, and so enamoured was he that he asked Inamdar to invite Hariharan as well.&lt;br /&gt;&lt;br /&gt;Inamdar&#39;s mission to put Marathi on the global map has apparently just begun. Irked by the fact that radio stations in Mumbai resist airing Marathi songs while other language songs are played, the composer got together donations of Rs 500 each from over 1400 enthusiasts like himself and put the album together. His ambitious plans now include starting a FM radio station that will play Marathi at all hours.&lt;br /&gt;&lt;br /&gt;Interestingly, Inamdar also refused Uddhav Thackeray’s offer of Rs 11 lakh, for it would then become a Sena song. For the inaugural event at Thane&#39;s Dadoji Konddev stadium on Saturday, Inamdar has lined up an illustrious assemblage of 21 noted Maharashtrians who will do the honours collectively. These will include filmmaker Sai Paranjape, photographer Gautam Rajadhyaksha, restaurateur Vithal Kamat, veteran theatre personality Prabhakar Panshikar, Planning Commission member Dr Narendra Jadhav, among others.&lt;br /&gt;&lt;br /&gt;The album contains two more songs by Kusumagraj and Ashok Bagwe, is priced Rs 300, and took a good 15 months to complete. After Marathi Abhimaan Geet releases, Inamdar has two more ambitious projects. For May 1, 2011, when Maharashtra State completes 51 years, he wants to perform Marathi fusion songs with an overseas philharmonic orchestra.&lt;br /&gt;&lt;br /&gt;Adds a delighted Inamdar, &quot;Interestingly, many radio stations from Mumbai have called me in the past two days wanting to know more about the project, and expressing their wish to include Marathi music in their programming.&quot; Now that would be the icing on the cake for Inamdar&#39;s mission.</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/3710691352044656806/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2010/02/india-song-readies-for-launch.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/3710691352044656806'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/3710691352044656806'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2010/02/india-song-readies-for-launch.html' title='India&amp;#39;s &amp;#39;biggest song&amp;#39; readies for launch'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8047285913921730738.post-4398687553473129774</id><published>2010-02-28T00:50:00.000-08:00</published><updated>2011-12-29T08:55:35.391-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="news"/><title type='text'>Major earthquake strikes Chile; Hawaii escapes without tsunami damage</title><content type='html'>SANTIAGO, CHILE -- One of the most powerful earthquakes on record jolted central Chile on Saturday, smashing homes and bridges and unleashing tsunami waves that coursed across the Pacific, prompting alerts in Hawaii and dozens of countries. More than 300 people have died in the coastal South American nation. &lt;br /&gt;&lt;br /&gt;Waves generated by the 8.8-magnitude quake started to smack Hawaiian beaches about noon local time, but they were smaller than the six-foot monsters scientists had feared. The water surged more than three feet in Kahului Bay in Maui before the tsunami warning was canceled in the early afternoon, officials said. &lt;br /&gt;&lt;br /&gt;Hawaiian residents had awakened at dawn to the blast of emergency sirens. Police closed roads and roped off coastal areas, and thousands of people were evacuated. But there were no reports of flooding or damage, and by Saturday evening, the Pacific Tsunami Warning Center had lifted its warning for the entire Pacific except for Russia and Japan. &lt;br /&gt;&lt;br /&gt;Japan issued its first &quot;major&quot; tsunami warning in 17 years, predicting Sunday morning that nine-foot-high waves could strike its northern Pacific coast and ordering about 400,000 residents to evacuate. But by late afternoon, hours after the high water was expected, dangerously high waves had not shown up. &lt;br /&gt;&lt;br /&gt;The predawn quake that hit Chile was far stronger than the temblor that rocked Haiti last month. But far fewer people died in Chile because the quake was farther from big cities and occurred deeper underground -- nearly 22 miles beneath the surface. The epicenter was 200 miles southwest of the Chilean capital, Santiago, while the Haitian quake was centered just a few miles outside its capital, Port-au-Prince. &lt;br /&gt;&lt;br /&gt;In addition, better building materials were used in Chile, one of the most developed Latin American countries. In poverty-stricken Haiti, more than 200,000 people perished as flimsy homes of cheap concrete disintegrated. &lt;br /&gt;&lt;br /&gt;&quot;The people in Chile have lots of experience with earthquakes. They&#39;ve done an excellent job of preparing,&quot; said Paul Caruso, a geophysicist with the U.S. Geological Survey. &lt;br /&gt;&lt;br /&gt;Still, the disaster wreaked havoc. Highway overpasses, buildings and bridges collapsed into mounds of twisted metal and chunks of concrete. Roads in Santiago were webbed with cracks and studded with holes big enough to swallow a motorcycle. In Concepcion, the country&#39;s second-biggest city, 70 miles from the epicenter, firefighters struggled to rescue dozens of people from a 14-story building that pancaked. &lt;br /&gt;&lt;br /&gt;Incoming President Sebastian Piñera, who is set to take office March 11, said the quake had dealt &quot;a very serious blow to the infrastructure of our country&quot; and asked key disaster-relief officials to delay their planned departures. Dozens of aftershocks rattled the country, further imperiling fragile buildings. &lt;br /&gt;&lt;br /&gt;About 600 travelers at the Santiago airport escaped when massive sections of the roof caved in, glass shattered and water poured through the terminal. Huddled under counters and inside gift stores, the travelers watched the newly renovated airport crumble around them. &quot;Although the runways were cleared for takeoffs and landings, the airport was closed because of the internal damage. &lt;br /&gt;&lt;br /&gt;Hundreds of prisoners in the city of Chillan, about 230 miles south of Santiago, escaped when a retaining wall collapsed. Rioting prisoners clashed with prison guards, leaving three inmates dead. &lt;br /&gt;&lt;br /&gt;Earthquake survivors told of being flung around buildings in the dark as the temblor struck at 3:34 a.m.</content><link rel='replies' type='application/atom+xml' href='http://highlevelprogramming.blogspot.com/feeds/4398687553473129774/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://highlevelprogramming.blogspot.com/2010/02/major-earthquake-strikes-chile-hawaii.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/4398687553473129774'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8047285913921730738/posts/default/4398687553473129774'/><link rel='alternate' type='text/html' href='http://highlevelprogramming.blogspot.com/2010/02/major-earthquake-strikes-chile-hawaii.html' title='Major earthquake strikes Chile; Hawaii escapes without tsunami damage'/><author><name>Life</name><uri>http://www.blogger.com/profile/11684582336499560918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>