<?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-4430265161967407772</id><updated>2024-08-30T23:57:05.176+05:30</updated><title type='text'>Learn Java Quickly</title><subtitle type='html'>Java is an object oriented programming language, originally developed by James Gosling at Sun Microsystems (which has since merged into Oracle Corporation) and released in 1995 as a core component of Sun Microsystems&#39; Java platform. Object-oriented programming is at the core of Java. Object Oriented Programming or OOP is the technique to create programs based on the real world. All java programs are object oriented</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://quicklearnjava.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4430265161967407772/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://quicklearnjava.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Unknown</name><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>7</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4430265161967407772.post-8248074140518772471</id><published>2012-02-16T09:37:00.000+05:30</published><updated>2012-03-20T09:26:21.808+05:30</updated><title type='text'>Multithreading</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
A multithreaded program contains two or more parts that can run
concurrently. Each part of such a program is called a &lt;i&gt;thread, &lt;/i&gt;and each thread
defines a separate path of execution. Thus, multithreading is a
specialized form of multitasking. Multithreading enables you to write very
efficient programs that make maximum use of the CPU, because idle time can be
kept to a minimum. This is especially important for the interactive, networked
environment in which Java operates, because idle time is common. &lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify; text-indent: 0.5in;&quot;&gt;
The value of a multithreaded environment is best understood in
contrast to its counterpart. Single-threaded systems use an approach called an &lt;i&gt;event loop &lt;/i&gt;with &lt;i&gt;&lt;b&gt;polling&lt;/b&gt;. &lt;/i&gt;In this model,
a single thread of control runs in an infinite loop, polling a single event
queue to decide what to do next. Once this polling mechanism returns with, say,
a signal that a network file is ready to be read, then the event loop
dispatches control to the appropriate event handler. Until this event handler
returns, nothing else can happen in the system. This wastes CPU time. It can
also result in one part of a program dominating the system and preventing any other
events from being processed. In general, in a singled-threaded environment,
when a&lt;/div&gt;

&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
thread &lt;i&gt;blocks &lt;/i&gt;(that is, suspends execution) because it is waiting for some
resource, the entire program stops running.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify; text-indent: 0.5in;&quot;&gt;
The benefit of Java’s multithreading is that the main
loop/polling mechanism is eliminated. One thread can pause without stopping
other parts of your program. &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify; text-indent: 0.5in;&quot;&gt;
&amp;nbsp;For example, the idle time
created when a thread reads data from a network or waits for user input can be
utilized elsewhere. Multithreading allows animation loops to sleep for a second
between each frame without causing the whole system to pause. When a thread
blocks in a Java program, only the single thread that is blocked pauses. All
other threads continue to run.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
Threads exist in several states. &lt;/div&gt;
&lt;ul style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: left;&quot;&gt;
&lt;li&gt;&amp;nbsp;A thread can be&lt;b&gt; &lt;/b&gt;&lt;i&gt;&lt;b&gt;running&lt;/b&gt;. &lt;/i&gt;It can be &lt;i&gt;ready to run &lt;/i&gt;as soon as it
gets CPU time.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: left;&quot;&gt;
&lt;li&gt;&amp;nbsp;A running thread can be &lt;i&gt;&lt;b&gt;suspended&lt;/b&gt;, &lt;/i&gt;which
temporarily suspends its activity. A suspended thread can then be &lt;i&gt;resumed, &lt;/i&gt;allowing it to
pick up where it left off. &lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: left;&quot;&gt;
&lt;li&gt;A thread can be &lt;i&gt;&lt;b&gt;blocked&lt;/b&gt; &lt;/i&gt;when waiting
for a resource. At any time, a thread can be terminated, which halts its
execution immediately. Once terminated, a thread cannot be resumed.

&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;Thread Priorities&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Every thread has a &lt;i&gt;priority. &lt;/i&gt;By default, a
thread inherits the priority of its parent thread, that is, the thread that
started it. You can increase or decrease the priority of any thread with the setPriority
method.
You can set the priority to any value between &lt;b&gt;MIN_PRIORITY&lt;/b&gt; (defined as 1
in the Thread
class)
and &lt;b&gt;MAX_PRIORITY&lt;/b&gt;
(defined
as 10). &lt;b&gt;NORM_PRIORITY&lt;/b&gt;
is
defined as 5.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
Whenever the thread-scheduler has a chance to pick a new
thread, it prefers threads with higher priority.&lt;br /&gt;
&lt;div style=&quot;margin-left: 40px;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Cambria;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;In cases where two threads with the same priority are competing
for CPU cycles, the situation is a bit complicated. For operating systems such as
Windows, threads of equal priority are time-sliced automatically in round-robin
fashion. For other types of operating systems, threads of equal priority must
voluntarily yield control to their peers. If they don’t, the other threads will
not run.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;Synchronization&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&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; When
two or more threads need access to a shared resource, they need some way to
ensure that the resource will be used by only one thread at a time. The process
by which this is achieved is called &lt;i&gt;&lt;b&gt;synchronization&lt;/b&gt;. &lt;/i&gt;In most
practical multithreaded applications, two or more threads need to share access
to the same objects. Because multithreading introduces an asynchronous behavior
to your programs, there must be a way for you to enforce synchronicity when you
need it.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; For example, if you want two threads to communicate and share a
complicated data structure, such as a linked list, you need some way to ensure
that they don’t conflict with each other. That is, you must prevent one thread from
writing data while another thread is in the middle of reading it.&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&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; For this
purpose, Java implements a model of interprocess synchronization: the &lt;b&gt;&lt;i&gt;monitor&lt;/i&gt;&lt;/b&gt; (also called a
&lt;b&gt;&lt;i&gt;semaphore&lt;/i&gt;&lt;/b&gt;). A &lt;i&gt;monitor &lt;/i&gt;is an object
that is used as a mutually exclusive lock, or &lt;i&gt;&lt;b&gt;mutex&lt;/b&gt;. &lt;/i&gt;Only one thread
can &lt;i&gt;own
&lt;/i&gt;a&lt;i&gt; &lt;/i&gt;monitor at a
given time. When a thread acquires a lock, it is said to have &lt;i&gt;entered &lt;/i&gt;the monitor.&lt;i&gt; &lt;/i&gt;All other
threads attempting to enter the locked monitor will be suspended until the
first&lt;i&gt;
&lt;/i&gt;thread
&lt;i&gt;exits
&lt;/i&gt;the
monitor. These other threads are said to be &lt;i&gt;waiting &lt;/i&gt;for the
monitor. A thread&lt;i&gt; &lt;/i&gt;that owns a monitor can reenter the same monitor if it so
desires.&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://quicklearnjava.blogspot.com/feeds/8248074140518772471/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://quicklearnjava.blogspot.com/2012/02/multithreading.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4430265161967407772/posts/default/8248074140518772471'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4430265161967407772/posts/default/8248074140518772471'/><link rel='alternate' type='text/html' href='http://quicklearnjava.blogspot.com/2012/02/multithreading.html' title='Multithreading'/><author><name>Unknown</name><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-4430265161967407772.post-1680709924142577033</id><published>2012-01-30T11:51:00.000+05:30</published><updated>2012-03-20T09:28:03.838+05:30</updated><title type='text'>Exception Handling in Java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
A Java exception is an object that describes an exceptional condition that has occurred in a piece of code.&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: 14pt;&quot;&gt;Categories of exceptions:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify; text-indent: 0.5in;&quot;&gt;
&lt;b&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;Checked
exceptions:&lt;/i&gt;&lt;/b&gt; A checked
exception is an exception that is typically a user error or a problem that
cannot be foreseen by the programmer. For example, if a file is to be opened,
but the file cannot be found, an exception occurs. These exceptions cannot
simply be ignored at the time of compilation.&lt;/div&gt;


&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify; text-indent: 0.5in;&quot;&gt;
&lt;b&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;Runtime
exceptions&lt;/i&gt;&lt;/b&gt;: A runtime exception is an
exception that occurs that probably could have been avoided by the programmer.
As opposed to checked exceptions, runtime exceptions are ignored at the time of
compliation.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify; text-indent: 0.5in;&quot;&gt;
&lt;b&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;Errors:&lt;/i&gt;&lt;/b&gt; These are not exceptions at all, but problems that
arise beyond the control of the user or the programmer. Errors are typically
ignored in your code because you can rarely do anything about an error. For
example, if a stack overflow occurs, an error will arise. They are also ignored
at the time of compilation.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
When an exceptional condition arises, an object representing that exception is
created and &lt;i&gt;thrown &lt;/i&gt;in the method that caused the error. That method may
choose to handle the exception itself, or pass it on. Either way, at some
point, the exception is &lt;i&gt;caught &lt;/i&gt;and processed. Exceptions can be
generated by the Java run-time system, or they can be manually generated by
your code. Exceptions thrown by Java relate to fundamental errors that violate
the rules of the Java language or the constraints of the Java execution
environment. Manually generated exceptions are typically used to report some
error condition to the caller of a method. Java exception handling is managed
via five keywords: &lt;b&gt;try&lt;/b&gt;, &lt;b&gt;catch&lt;/b&gt;, &lt;b&gt;throw&lt;/b&gt;, &lt;b&gt;throws&lt;/b&gt;, and &lt;b&gt;finally&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&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;
Briefly, here is how they work. Program statements that you want to
monitor for exceptions are contained within a &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;try &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;block.
If an exception occurs within the &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;try &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;block,
it is thrown. Your code can catch this exception (using &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;catch&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;)
and handle it in some rational manner. System-generated exceptions are
automatically thrown by the Java run-time system.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&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;To manually throw an exception,
use the keyword &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;throw&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;. Any exception that is thrown
out of a method must be specified as such by a &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;throws
&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;clause. Any code that absolutely must be executed after a &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;try &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;block
completes is put in a &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;finally &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;block.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;This is the general form of an exception-handling block:&lt;/span&gt;&lt;/div&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: medium none; font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 237.9pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 237.9pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 275.9pt;&quot; valign=&quot;top&quot; width=&quot;368&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;try&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;//
  block of code to monitor for errors&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;catch
  (&lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: black;&quot;&gt;ExceptionType1 exObj&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: black;&quot;&gt;) &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;//
  exception handler for &lt;i&gt;ExceptionType1&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;catch
  (&lt;i&gt;ExceptionType2 exObj&lt;/i&gt;) &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;//
  exception handler for &lt;i&gt;ExceptionType2&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;//
  ...&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;finally
  &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;//
  block of code to be executed after try block ends&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;Here, &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: black;&quot;&gt;ExceptionType
&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: black;&quot;&gt;is the type of exception that has occurred&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;span style=&quot;color: black; font-size: 14pt;&quot;&gt;Exception Types:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR3nLqJ4917o2jSQcLiG-siljNSlSIz5m_yjgiElNHJs-MgDZot_e5KWuRiacxV1fm4mV6vyQXS2shstuKKAFAtHQFcEmugX8nSI91kSvC1F6TFqtUCuIVpcM2zqzFeTrk4tb83_lBwsNF/s1600/exceptions.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;197&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR3nLqJ4917o2jSQcLiG-siljNSlSIz5m_yjgiElNHJs-MgDZot_e5KWuRiacxV1fm4mV6vyQXS2shstuKKAFAtHQFcEmugX8nSI91kSvC1F6TFqtUCuIVpcM2zqzFeTrk4tb83_lBwsNF/s320/exceptions.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; All exception
types are subclasses of the built-in class &lt;b&gt;Throwable&lt;/b&gt;. Thus, &lt;b&gt;Throwable &lt;/b&gt;is at the top
of the exception class hierarchy. Immediately below &lt;b&gt;Throwable &lt;/b&gt;are two
subclasses that partition exceptions into two distinct branches. One branch is
headed by &lt;b&gt;Exception&lt;/b&gt;. This class is
used for exceptional conditions that user programs should catch. This is also
the class that you will subclass to create your own custom exception types.
There is an important subclass of &lt;b&gt;Exception&lt;/b&gt;, called &lt;b&gt;RuntimeException&lt;/b&gt;. Exceptions of
this type are automatically defined for the programs that you write and include
things such as division by zero and invalid array indexing.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&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; The
other branch is topped by &lt;b&gt;Error&lt;/b&gt;, which defines exceptions that
are not expected to be caught under normal circumstances by your program.
Exceptions of type &lt;b&gt;Error &lt;/b&gt;are used by the Java run-time system to indicate errors having
to do with the run-time environment, itself. Stack overflow is an example of
such an error. This chapter will not be dealing with exceptions of type &lt;b&gt;Error&lt;/b&gt;, because these
are typically created in response to catastrophic failures that cannot usually
be handled by your program.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;try/catch
Statement &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The &lt;span class=&quot;exdc&quot;&gt;try&lt;/span&gt;/&lt;span class=&quot;exdc&quot;&gt;catch&lt;/span&gt; statement encloses some
code and is used to handle errors and exceptions that might occur in that code.
Here is the general syntax of the &lt;span class=&quot;exdc&quot;&gt;try&lt;/span&gt;/&lt;span class=&quot;exdc&quot;&gt;catch&lt;/span&gt;
statement: &lt;/div&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: medium none; font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 111.1pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 111.1pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 239.85pt;&quot; valign=&quot;top&quot; width=&quot;320&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;
try&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
  body-code&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
} &lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
catch
  (exception-classname variable-name)&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;{&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
  handler-code&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
}&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&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;
The &lt;span class=&quot;exdc&quot;&gt;try&lt;/span&gt;/&lt;span class=&quot;exdc&quot;&gt;catch&lt;/span&gt; statement has
four parts. The &lt;span class=&quot;exdv&quot;&gt;body-code&lt;/span&gt; contains code that might
throw the exception that we want to handle. The &lt;span class=&quot;exdv&quot;&gt;exception-classname&lt;/span&gt;
is the class name of the exception we want to handle. The &lt;span class=&quot;exdv&quot;&gt;variable-name&lt;/span&gt;
specifies a name for a variable that will hold the exception object if the
exception occurs. Finally, the &lt;span class=&quot;exdv&quot;&gt;handler-code&lt;/span&gt; contains
the code to execute if the exception occurs. After the handler-code executes,
execution of the thread continues after the &lt;span class=&quot;exdc&quot;&gt;try&lt;/span&gt;/&lt;span class=&quot;exdc&quot;&gt;catch&lt;/span&gt; statement. Here is an example of code that tries to
create a file in a non-existent directory which results in an &lt;span class=&quot;exdc&quot;&gt;IOException&lt;/span&gt;.
&lt;/div&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: medium none; font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 170.25pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 170.25pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 393.2pt;&quot; valign=&quot;top&quot; width=&quot;524&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;
String filename
  = &quot;/nosuchdir/myfilename&quot;;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
try&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;{&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
  // Create the file&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
  new File(filename).createNewFile();&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
} &lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
catch
  (IOException e)&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;{&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
  // Print out the exception that occurred&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
  System.out.println(&quot;Unable to create &quot;+filename+&quot;: &quot;+e.getMessage());&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
// Execution
  continues here after the IOException handler is executed&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
Here&#39;s
the output: &lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
Unable
to create /nosuchdir/myfilename: The system cannot find the path specified.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&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; &lt;span style=&quot;color: black;&quot;&gt;Although the default exception handler provided by the Java
run-time system is useful for debugging, you will usually want to handle an
exception yourself. Doing so provides two benefits. First, it allows you to fix
the error. Second, it prevents the program from automatically terminating. Most
users would be confused (to say the least) if your program stopped running and
printed a stack trace whenever an error occurred! It is quite easy to prevent
this. &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&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;
To guard against and handle a run-time error, simply enclose the code
that you want to monitor inside a &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;try &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;block.
Immediately following the &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;try &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;block,
include a &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;catch &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;clause that specifies the exception type that you
wish to catch.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&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;To illustrate how easily this can
be done, the following program includes a &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;try &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;block
and a &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;catch &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;clause that processes the &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;ArithmeticException
&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;generated by the division-by-zero error:&lt;/span&gt;&lt;/div&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: medium none; font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 251.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 251.5pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 248.85pt;&quot; valign=&quot;top&quot; width=&quot;332&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;class
  Exc2&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;public
  static void main(String args[]) &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;int
  d, a;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;try&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;{
  // monitor a block of code.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;d =
  0;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;a =
  42 / d;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;System.out.println(&quot;This
  will not be printed.&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;} &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;catch
  (ArithmeticException e) &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;{
  // catch divide-by-zero error&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;System.out.println(&quot;Division
  by zero.&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;System.out.println(&quot;After
  catch statement.&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;This program generates the following output:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;Division by zero.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;After catch statement.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Notice
that the call to &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;println( ) &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;inside the &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;try &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;block
is never executed. Once an exception is thrown, program control transfers out
of the &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;try &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;block into the &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;catch &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;block.
Put differently, &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;catch &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;is not “called,” so execution
never “returns” to the &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;try &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;block from a &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;catch&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;.
Thus, the line “This will not be printed.” is not displayed. Once the &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;catch
&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;statement has executed, program control continues with the next
line in the program following the entire &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;try&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;/&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;catch&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt; mechanism.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;try &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;and
its &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;catch &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;statement form a unit. The scope of the &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;catch
&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;clause is restricted to those statements specified by the immediately
preceding &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;try &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;statement. A &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;catch &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;statement
cannot catch an exception thrown by another &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;try &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;statement
(except in the case of nested &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;try&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt; statements,
described shortly). The statements that are protected by &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;try &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;must
be surrounded by curly braces. (That is, they must be within a block.) You
cannot use &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;try &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;on a single statement.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The
goal of most well-constructed &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;catch &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;clauses
should be to resolve the exceptional condition and then continue on as if the
error had never happened. For example, in the next program each iteration of
the &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;for &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;loop obtains two random integers. Those two
integers are divided by each other, and the result is used to divide the value
12345. The final result is put into &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;a&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;.
If either division operation causes a divide-by-zero error, it is caught, the
value of &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;a &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;is set to zero, and the program continues.&lt;/span&gt;&lt;/div&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: medium none; font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 44.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 44.5pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 248.85pt;&quot; valign=&quot;top&quot; width=&quot;332&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;//
  Handle an exception and move on.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;import
  java.util.Random;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;class
  HandleError &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;public
  static void main(String args[])&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;int
  a=0, b=0, c=0;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;Random
  r = new Random();&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;for(int
  i=0; i&amp;lt;32000; i++)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;try&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;b
  = r.nextInt();&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;c
  = r.nextInt();&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;a
  = 12345 / (b/c);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;}
  &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;catch
  (ArithmeticException e)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;System.out.println(&quot;Division
  by zero.&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;a
  = 0; // set a to zero and continue&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;System.out.println(&quot;a:
  &quot; + a);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: black; font-size: 14pt;&quot;&gt;Multiple catch Clauses&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none; text-indent: .5in;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;In some cases, more than one exception could be
raised by a single piece of code. To handle this type of situation, you can
specify two or more &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;catch &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;clauses, each catching a
different type of exception. When an exception is thrown, each &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;catch
&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;statement is inspected in order, and the first one whose type
matches that of the exception is executed. After one &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;catch&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt; statement
executes, the others are bypassed, and execution continues after the &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;try&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;/&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;catch&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt; block.
The following example traps two different exception types:&lt;/span&gt;&lt;/div&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 480;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 17.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 17.5pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 239.85pt;&quot; valign=&quot;top&quot; width=&quot;320&quot;&gt;&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;// Demonstrate multiple catch statements.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;class MultiCatch &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;public static void main(String args[])&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;Try&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;int a = args.length;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;System.out.println(&quot;a = &quot; + a);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;int b = 42 / a;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;int c[] = { 1 };&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;c[42] = 99;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;} &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;catch(ArithmeticException e) &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;System.out.println(&quot;Divide by 0: &quot; + e);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;} &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;catch(ArrayIndexOutOfBoundsException e)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;System.out.println(&quot;Array index oob: &quot; + e);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;System.out.println(&quot;After try/catch
  blocks.&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: #231f20;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;This program will cause a division-by-zero
exception if it is started with no commandline arguments, since &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;a &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;will
equal zero. It will survive the division if you provide a command-line
argument, setting &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;a &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;to something larger than zero.
&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; But
it will cause an &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;ArrayIndexOutOfBoundsException&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;,
since the &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;int &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;array &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;c &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;has
a length of 1, yet the program attempts to assign a value to &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;c[42]&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;Here is the output generated by running it both
ways:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none; text-indent: .5in;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;C:\&amp;gt;java MultiCatch&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in; mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;a = 0&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in; mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;Divide by 0: java.lang.ArithmeticException: / by zero&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in; mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;After try/catch blocks.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in; mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;C:\&amp;gt;java MultiCatch TestArg&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in; mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;a = 1&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in; mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;Array index oob:
java.lang.ArrayIndexOutOfBoundsException:42&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in; mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;After try/catch blocks.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in; mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;When you use multiple &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;catch
&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;statements, it is important to remember that exception subclasses
must come before any of their superclasses. This is because a &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;catch
&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;statement that uses a superclass will catch exceptions of that
type plus any of its subclasses. Thus, a subclass would never be reached if it
came after its superclass. Further, in Java, unreachable code is an error. &lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://quicklearnjava.blogspot.com/feeds/1680709924142577033/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://quicklearnjava.blogspot.com/2012/01/exception-handling-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4430265161967407772/posts/default/1680709924142577033'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4430265161967407772/posts/default/1680709924142577033'/><link rel='alternate' type='text/html' href='http://quicklearnjava.blogspot.com/2012/01/exception-handling-in-java.html' title='Exception Handling in Java'/><author><name>Unknown</name><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/AVvXsEgR3nLqJ4917o2jSQcLiG-siljNSlSIz5m_yjgiElNHJs-MgDZot_e5KWuRiacxV1fm4mV6vyQXS2shstuKKAFAtHQFcEmugX8nSI91kSvC1F6TFqtUCuIVpcM2zqzFeTrk4tb83_lBwsNF/s72-c/exceptions.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4430265161967407772.post-7831666270260128907</id><published>2012-01-16T14:30:00.000+05:30</published><updated>2012-03-20T09:28:20.069+05:30</updated><title type='text'>Inheritance</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;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
Inheritance
is one of the most important feature of Object Oriented Programming.
Inheritance means to take something that is already made. It is the concept
that is used for reusability purpose. Inheritance is the mechanism through
which we can derive classes from other classes. The derived class is called as
child class or the subclass or&amp;nbsp; we can say the extended class and the
class from which we are deriving the subclass is called the base class or the
parent class. The concept of inheritance is used to make the things from
general to more specific The following kinds of inheritance are there in java.&lt;/div&gt;
&lt;ul style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot; type=&quot;disc&quot;&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in; text-align: justify;&quot;&gt;&amp;nbsp; &lt;b&gt;Simple Inheritance&lt;/b&gt; &lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in; text-align: justify;&quot;&gt;&lt;b&gt;&amp;nbsp; Multilevel Inheritance&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;a href=&quot;http://www.freelancer.com/affiliates/jobinbennett/&quot;&gt;&lt;img src=&quot;http://www.freelancer.com/img/affiliates/contest-banner-336x280.gif&quot; width=336 height=280 alt=&quot;Freelance Jobs&quot; border=0&gt;&lt;/a&gt;

&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;To inherit a class, you simply incorporate the definition of one
class into another by using the &lt;b&gt;extends &lt;/b&gt;keyword. To see how, let’s begin
with a short example. The following program creates a superclass called &lt;b&gt;A &lt;/b&gt;and
a subclass called &lt;b&gt;B&lt;/b&gt;. Notice how the keyword &lt;b&gt;extends &lt;/b&gt;is used to
create a subclass of &lt;b&gt;A&lt;/b&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 480;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 305.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 305.5pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 257.9pt;&quot; valign=&quot;top&quot; width=&quot;344&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;//
  A simple example of inheritance.&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;//
  Create a superclass.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;class
  A&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;int
  i, j;&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;void
  showij()&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;System.out.println(&quot;i
  and j: &quot; + i + &quot; &quot; + j);&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;//
  Create a subclass by extending class A.&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;class
  B extends A&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;int
  k;&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;void
  showk()&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;System.out.println(&quot;k:
  &quot; + k);&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;void
  sum()&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;System.out.println(&quot;i+j+k:
  &quot; + (i+j+k));&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;class
  SimpleInheritance&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;public
  static void main(String args[] )&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;A
  superOb = new A();&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;B
  subOb = new B();&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;//
  The superclass may be used by itself.&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;superOb.i
  = 10;&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;superOb.j
  = 20;&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;System.out.println(&quot;Contents
  of superOb: &quot;);&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;superOb.showij();&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;System.out.println();&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;/*
  The subclass has access to all public members of&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;its
  superclass. */&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;subOb.i
  = 7;&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;subOb.j
  = 8;&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;subOb.k
  = 9;&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;System.out.println(&quot;Contents
  of subOb: &quot;);&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;subOb.showij();&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;subOb.showk();&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;System.out.println();&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;System.out.println(&quot;Sum
  of i, j and k in subOb:&quot;);&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;subOb.sum();&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;The
  output from this program is shown here:&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;Contents
  of superOb:&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;i
  and j: 10 20&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;Contents
  of subOb:&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;i
  and j: 7 8&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;k:
  9&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;Sum
  of i, j and k in subOb:&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;color: black; font-family: Arial;&quot;&gt;i+j+k:
  24&lt;/span&gt;

&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
As
you can see, the subclass &lt;b&gt;B &lt;/b&gt;includes all of the members of its
superclass, &lt;b&gt;A&lt;/b&gt;. This is why &lt;b&gt;subOb &lt;/b&gt;can access &lt;b&gt;i &lt;/b&gt;and &lt;b&gt;j &lt;/b&gt;and
call &lt;b&gt;showij( )&lt;/b&gt;. Also, inside &lt;b&gt;sum( )&lt;/b&gt;, &lt;b&gt;i &lt;/b&gt;and &lt;b&gt;j &lt;/b&gt;can be
referred to directly, as if they were part of &lt;b&gt;B&lt;/b&gt;. Even though &lt;b&gt;A &lt;/b&gt;is
a superclass for &lt;b&gt;B&lt;/b&gt;, it is also a completely independent, stand-alone
class. Being a superclass for a subclass does not mean that the superclass
cannot be used by itself. Further, a subclass can be a superclass for another
subclass.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
The
general form of a &lt;b&gt;class &lt;/b&gt;declaration that inherits a superclass is shown
here:&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
class
&lt;i&gt;subclass-name &lt;/i&gt;extends &lt;i&gt;superclass-name &lt;/i&gt;{&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
//
body of class&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
}&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;br /&gt;
You
can only specify one superclass for any subclass that you create. Java does not
support the inheritance of multiple superclasses into a single subclass. You can,
as stated, create a hierarchy of inheritance in which a subclass becomes a
superclass of another subclass. However, no class can be a superclass of itself.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;Member
Access and Inheritance&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&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; Although
a subclass includes all of the members of its superclass, it cannot access
those members of the superclass that have been declared as &lt;b&gt;private&lt;/b&gt;. For example,
consider the following simple class hierarchy:&lt;/div&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 480;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 486.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 486.5pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 239.85pt;&quot; valign=&quot;top&quot; width=&quot;320&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
/* In a class hierarchy, private members remain&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
private to their class.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
This program contains an error and will not&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
compile.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
*/&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
// Create a superclass.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
class A&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&amp;nbsp;{&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
int i; // public by default&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
private int j; // private to A&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
void setij(int x, int y) &lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
{&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
i = x;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
j = y;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
}&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
}&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
// A&#39;s j is not accessible here.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
class B extends A&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&amp;nbsp;{&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
int total;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
void sum()&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&amp;nbsp;{&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
total = i + j; // ERROR, j is not accessible here&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
}&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
}&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
class Access &lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
{&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
public static void main(String args[])&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&amp;nbsp;{&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
B subOb = new B();&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
subOb.setij(10, 12);&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
subOb.sum();&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
System.out.println(&quot;Total is &quot; + subOb.total);&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
}&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
}&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
This program will not compile because the reference to &lt;b&gt;j &lt;/b&gt;inside the &lt;b&gt;sum( ) &lt;/b&gt;method of &lt;b&gt;B &lt;/b&gt;causes an
access violation. Since &lt;b&gt;j &lt;/b&gt;is declared as &lt;b&gt;private&lt;/b&gt;, it is only accessible by other
members&lt;b&gt;
&lt;/b&gt;of
its own class. Subclasses have no access to it.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: 16pt;&quot;&gt;Using the Keyword &lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;super&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;
&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;Accessing
Superclass Members&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; text-align: justify;&quot;&gt;
&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&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;
&lt;/i&gt;&lt;/b&gt;If your method
overrides one of its superclass&#39;s methods, you can invoke the overridden method
through the use of the keyword &lt;code&gt;super&lt;/code&gt;. You can also use &lt;code&gt;super&lt;/code&gt; to refer to a hidden field.&amp;nbsp; More Elaborately we can say it is used to
access members of a class inherited by the class in which it appears. Allows a
subclass to access overridden methods and hidden members of its superclass. The
&lt;code&gt;super&lt;/code&gt;
keyword is also used to forward a call from a constructor to a constructor in
the superclass. &lt;/div&gt;
Consider this class, &lt;code&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;Superclass&lt;/span&gt;&lt;/code&gt;:&lt;br /&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoNormalTable&quot; style=&quot;border-collapse: collapse; border: medium none; width: 320px;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 314.3pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 314.3pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 239.85pt;&quot; valign=&quot;top&quot; width=&quot;320&quot;&gt;public class Superclass &lt;br /&gt;
{&lt;br /&gt;
public void printMethod() &lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;System.out.println(&quot;Printed in Superclass.&quot;);&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
Here is a subclass, called &lt;code&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;Subclass&lt;/span&gt;&lt;/code&gt;,
  that overrides &lt;code&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;printMethod()&lt;/span&gt;&lt;/code&gt;:&lt;br /&gt;
public class Subclass extends Superclass &lt;br /&gt;
{&lt;br /&gt;
// overrides printMethod in Superclass&lt;br /&gt;
public void printMethod() &lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;super.printMethod();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(&quot;Printed in Subclass&quot;);&lt;br /&gt;
}&lt;br /&gt;
public static void main(String[] args)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Subclass s = new Subclass();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; s.printMethod();&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
}&lt;br /&gt;
}&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&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; Within &lt;code&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;Subclass&lt;/span&gt;&lt;/code&gt;,
the simple name &lt;code&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;printMethod()&lt;/span&gt;&lt;/code&gt;
refers to the one declared in &lt;code&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;Subclass&lt;/span&gt;&lt;/code&gt;,which overrides the one in &lt;code&gt;Superclass&lt;/code&gt;. So, to refer to &lt;code&gt;printMethod()&lt;/code&gt; inherited from &lt;code&gt;Superclass&lt;/code&gt;, &lt;code&gt;Subclass&lt;/code&gt; must use a qualified name, using &lt;code&gt;super&lt;/code&gt; as shown. Compiling and executing &lt;code&gt;Subclass&lt;/code&gt; prints the following:&lt;br /&gt;
&lt;pre style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;Printed in Superclass.&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;Printed in Subclass&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://quicklearnjava.blogspot.com/feeds/7831666270260128907/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://quicklearnjava.blogspot.com/2012/01/inheritance.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4430265161967407772/posts/default/7831666270260128907'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4430265161967407772/posts/default/7831666270260128907'/><link rel='alternate' type='text/html' href='http://quicklearnjava.blogspot.com/2012/01/inheritance.html' title='Inheritance'/><author><name>Unknown</name><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-4430265161967407772.post-5728440915093300023</id><published>2012-01-16T14:18:00.000+05:30</published><updated>2012-02-16T10:29:28.521+05:30</updated><title type='text'>Classes</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;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
Classes are the fundamental building blocks of a
Java program. The most important thing to understand about a class is that it
defines a new data type. Once defined, this new type can be used to create
objects of that type. Thus, a class is a &lt;i&gt;&lt;b&gt;template&lt;/b&gt; &lt;/i&gt;for an object, and an
object is an &lt;i&gt;instance &lt;/i&gt;of a class. Because an object is an instance of a
class, you will often see the two words &lt;i&gt;object &lt;/i&gt;and &lt;i&gt;instance &lt;/i&gt;used
interchangeably.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
A class is declared by use of the &lt;b&gt;&lt;i&gt;class&lt;/i&gt;&lt;/b&gt; keyword. The
classes that have been used up to this point are actually very limited examples
of its complete form. Classes can (and usually do) get much more complex. A
simplified general form of a class definition is shown here:&lt;/div&gt;
&lt;!--[if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:WordDocument&gt;
  &lt;w:View&gt;Normal&lt;/w:View&gt;
  &lt;w:Zoom&gt;0&lt;/w:Zoom&gt;
  &lt;w:PunctuationKerning/&gt;
  &lt;w:ValidateAgainstSchemas/&gt;
  &lt;w:SaveIfXMLInvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;
  &lt;w:IgnoreMixedContent&gt;false&lt;/w:IgnoreMixedContent&gt;
  &lt;w:AlwaysShowPlaceholderText&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;
  &lt;w:Compatibility&gt;
   &lt;w:BreakWrappedTables/&gt;
   &lt;w:SnapToGridInCell/&gt;
   &lt;w:WrapTextWithPunct/&gt;
   &lt;w:UseAsianBreakRules/&gt;
   &lt;w:DontGrowAutofit/&gt;
  &lt;/w:Compatibility&gt;
  &lt;w:BrowserLevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;
 &lt;/w:WordDocument&gt;
&lt;/xml&gt;&lt;![endif][if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:LatentStyles DefLockedState=&quot;false&quot; LatentStyleCount=&quot;156&quot;&gt;
 &lt;/w:LatentStyles&gt;
&lt;/xml&gt;&lt;![endif][if gte mso 10]&gt;
&lt;style&gt;
 /* Style Definitions */
 table.MsoNormalTable
 {mso-style-name:&quot;Table Normal&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 mso-style-noshow:yes;
 mso-style-parent:&quot;&quot;;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
table.MsoTableGrid
 {mso-style-name:&quot;Table Grid&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 border:solid windowtext 1.0pt;
 mso-border-alt:solid windowtext .5pt;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-border-insideh:.5pt solid windowtext;
 mso-border-insidev:.5pt solid windowtext;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
&lt;/style&gt;
&lt;![endif]--&gt;

&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 480;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 237.9pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 237.9pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 203.75pt;&quot; valign=&quot;top&quot; width=&quot;272&quot;&gt;
  &lt;span style=&quot;font-family: Arial;&quot;&gt;class classname&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;type instance-variable1;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;type instance-variable2;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;….&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;type instance-variableN;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;type methodname1(parameter-list) {&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;// body of method&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;type methodname2(parameter-list) {&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;// body of method&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;// ...&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;type methodnameN(parameter-list) {&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;// body of method&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;

  &lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
The data, or variables, defined within a class are
called instance variables. The code is&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
contained within methods. Collectively, the methods
and variables defined within a class are called members of the class. In most
classes, the instance variables are acted upon and accessed by the methods
defined for that class. Thus, as a general rule, it is the methods that
determine how a class’ data can be used.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
Example: a simple class named cricket&lt;/div&gt;
&lt;!--[if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:WordDocument&gt;
  &lt;w:View&gt;Normal&lt;/w:View&gt;
  &lt;w:Zoom&gt;0&lt;/w:Zoom&gt;
  &lt;w:PunctuationKerning/&gt;
  &lt;w:ValidateAgainstSchemas/&gt;
  &lt;w:SaveIfXMLInvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;
  &lt;w:IgnoreMixedContent&gt;false&lt;/w:IgnoreMixedContent&gt;
  &lt;w:AlwaysShowPlaceholderText&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;
  &lt;w:Compatibility&gt;
   &lt;w:BreakWrappedTables/&gt;
   &lt;w:SnapToGridInCell/&gt;
   &lt;w:WrapTextWithPunct/&gt;
   &lt;w:UseAsianBreakRules/&gt;
   &lt;w:DontGrowAutofit/&gt;
  &lt;/w:Compatibility&gt;
  &lt;w:BrowserLevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;
 &lt;/w:WordDocument&gt;
&lt;/xml&gt;&lt;![endif][if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:LatentStyles DefLockedState=&quot;false&quot; LatentStyleCount=&quot;156&quot;&gt;
 &lt;/w:LatentStyles&gt;
&lt;/xml&gt;&lt;![endif][if gte mso 10]&gt;
&lt;style&gt;
 /* Style Definitions */
 table.MsoNormalTable
 {mso-style-name:&quot;Table Normal&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 mso-style-noshow:yes;
 mso-style-parent:&quot;&quot;;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
table.MsoTableGrid
 {mso-style-name:&quot;Table Grid&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 border:solid windowtext 1.0pt;
 mso-border-alt:solid windowtext .5pt;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-border-insideh:.5pt solid windowtext;
 mso-border-insidev:.5pt solid windowtext;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
&lt;/style&gt;
&lt;![endif]--&gt;

&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 480;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 83.9pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 83.9pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 86.5pt;&quot; valign=&quot;top&quot; width=&quot;115&quot;&gt;
  &lt;span style=&quot;font-family: Arial;&quot;&gt;class Cricket&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;int overs;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;Int wickets ;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;int runs;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;

  &lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
As stated, a class defines a new type of data. In
this case, the new data type is called Cricket. You will use this name to
declare objects of type Cricket. It is important to remember that a class
declaration only creates a template; it does not create an actual object. Thus,
the preceding code does not cause any objects of type Cricket to come into
existence.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
To actually create a Cricket object, you will use a
statement like the following:&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Cricket mycricket = new Cricket
(); // create a Cricket object called mycricket.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;Declaring Objects&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&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; As just
explained, when you create a class, you are creating a new data type. You can
use this type to declare objects of that type. However, obtaining objects of a
class is a two-step process. &lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; First, you must
declare a variable of the class type. This variable does not define an object. Instead,
it is simply a variable that can &lt;i&gt;refer &lt;/i&gt;to an object. &lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Second, you must
acquire an actual, physical copy of the object and assign it to that variable.
You can do this using the &lt;b&gt;new &lt;/b&gt;operator. The &lt;b&gt;new &lt;/b&gt;operator
dynamically allocates (that is, allocates at run time) memory for an object and
returns a reference to it. This reference is, more or less, the address in
memory of the object allocated by &lt;b&gt;new&lt;/b&gt;. This reference is then stored in
the variable. Thus, in Java, all class objects must be dynamically allocated.
Let’s look at the details of this procedure.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
The following line is used to declare an object of type &lt;b&gt;Box&lt;/b&gt;:&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in; mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
Box mybox = new Box();&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
This statement combines the two steps just described. It can be
rewritten like this to show each step more clearly:&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in; mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
Box mybox; // declare reference to object&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in; mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
mybox = new Box(); // allocate a Box object&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-layout-grid-align: none; text-align: justify; text-autospace: none;&quot;&gt;
The first line declares &lt;b&gt;mybox &lt;/b&gt;as a reference
to an object of type &lt;b&gt;Box&lt;/b&gt;. After this line executes, &lt;b&gt;mybox &lt;/b&gt;contains the
value &lt;b&gt;null&lt;/b&gt;, which
indicates that it does not yet point to an actual object. Any attempt to use &lt;b&gt;mybox &lt;/b&gt;at this point
will result in a compile-time error. The next line allocates an actual object
and assigns a reference to it to &lt;b&gt;mybox&lt;/b&gt;. After the second line executes, you
can use &lt;b&gt;mybox
&lt;/b&gt;as
if it were a &lt;b&gt;Box &lt;/b&gt;object. But in reality, &lt;b&gt;mybox &lt;/b&gt;simply holds
the memory address of the actual &lt;b&gt;Box &lt;/b&gt;object.&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://quicklearnjava.blogspot.com/feeds/5728440915093300023/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://quicklearnjava.blogspot.com/2012/01/classes.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4430265161967407772/posts/default/5728440915093300023'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4430265161967407772/posts/default/5728440915093300023'/><link rel='alternate' type='text/html' href='http://quicklearnjava.blogspot.com/2012/01/classes.html' title='Classes'/><author><name>Unknown</name><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-4430265161967407772.post-714712330756328906</id><published>2011-12-10T14:49:00.001+05:30</published><updated>2012-02-16T10:33:02.929+05:30</updated><title type='text'>Control Statements in java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
The control statement are used to controll the flow of execution of the program
. &lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
This execution order
depends on the supplied data values and the conditional logic. &lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
Java contains the
following types of control statements. . &lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;1-
Selection Statements&lt;/span&gt;&lt;/b&gt;&lt;b&gt;: &lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&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;
Selection statements allow your program to choose different paths of&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&amp;nbsp;execution based upon
the outcome of an expression or the state of a variable Java &lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
supports two selection
statements, &quot;if and switch&quot;.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; a: If
Statement:&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
It can be used to route program execution through two different paths.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
This is a control statement to execute a single statement or a block of code,&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;when the given condition is true and if it is false then it skips
if block and rest code of program is executed .&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&amp;nbsp; Syntax:&lt;/div&gt;
&lt;!--[if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:WordDocument&gt;
  &lt;w:View&gt;Normal&lt;/w:View&gt;
  &lt;w:Zoom&gt;0&lt;/w:Zoom&gt;
  &lt;w:PunctuationKerning/&gt;
  &lt;w:ValidateAgainstSchemas/&gt;
  &lt;w:SaveIfXMLInvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;
  &lt;w:IgnoreMixedContent&gt;false&lt;/w:IgnoreMixedContent&gt;
  &lt;w:AlwaysShowPlaceholderText&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;
  &lt;w:Compatibility&gt;
   &lt;w:BreakWrappedTables/&gt;
   &lt;w:SnapToGridInCell/&gt;
   &lt;w:WrapTextWithPunct/&gt;
   &lt;w:UseAsianBreakRules/&gt;
   &lt;w:DontGrowAutofit/&gt;
  &lt;/w:Compatibility&gt;
  &lt;w:BrowserLevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;
 &lt;/w:WordDocument&gt;
&lt;/xml&gt;&lt;![endif][if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:LatentStyles DefLockedState=&quot;false&quot; LatentStyleCount=&quot;156&quot;&gt;
 &lt;/w:LatentStyles&gt;
&lt;/xml&gt;&lt;![endif][if gte mso 10]&gt;
&lt;style&gt;
 /* Style Definitions */
 table.MsoNormalTable
 {mso-style-name:&quot;Table Normal&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 mso-style-noshow:yes;
 mso-style-parent:&quot;&quot;;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
table.MsoTableGrid
 {mso-style-name:&quot;Table Grid&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 border:solid windowtext 1.0pt;
 mso-border-alt:solid windowtext .5pt;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-border-insideh:.5pt solid windowtext;
 mso-border-insidev:.5pt solid windowtext;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
&lt;/style&gt;
&lt;![endif]--&gt;

&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 480;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 111.1pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 111.1pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 113.55pt;&quot; valign=&quot;top&quot; width=&quot;151&quot;&gt;
  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;if(condition)&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;lt;statement1&amp;gt;;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp; else&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp; &amp;lt;statement2&amp;gt;;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;

  &lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&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;
If the condition is true, then statement1 is executed. Otherwise, statement2
(if it exists) is executed.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
Example:&lt;/div&gt;
&lt;!--[if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:WordDocument&gt;
  &lt;w:View&gt;Normal&lt;/w:View&gt;
  &lt;w:Zoom&gt;0&lt;/w:Zoom&gt;
  &lt;w:PunctuationKerning/&gt;
  &lt;w:ValidateAgainstSchemas/&gt;
  &lt;w:SaveIfXMLInvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;
  &lt;w:IgnoreMixedContent&gt;false&lt;/w:IgnoreMixedContent&gt;
  &lt;w:AlwaysShowPlaceholderText&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;
  &lt;w:Compatibility&gt;
   &lt;w:BreakWrappedTables/&gt;
   &lt;w:SnapToGridInCell/&gt;
   &lt;w:WrapTextWithPunct/&gt;
   &lt;w:UseAsianBreakRules/&gt;
   &lt;w:DontGrowAutofit/&gt;
  &lt;/w:Compatibility&gt;
  &lt;w:BrowserLevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;
 &lt;/w:WordDocument&gt;
&lt;/xml&gt;&lt;![endif][if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:LatentStyles DefLockedState=&quot;false&quot; LatentStyleCount=&quot;156&quot;&gt;
 &lt;/w:LatentStyles&gt;
&lt;/xml&gt;&lt;![endif][if gte mso 10]&gt;
&lt;style&gt;
 /* Style Definitions */
 table.MsoNormalTable
 {mso-style-name:&quot;Table Normal&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 mso-style-noshow:yes;
 mso-style-parent:&quot;&quot;;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
table.MsoTableGrid
 {mso-style-name:&quot;Table Grid&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 border:solid windowtext 1.0pt;
 mso-border-alt:solid windowtext .5pt;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-border-insideh:.5pt solid windowtext;
 mso-border-insidev:.5pt solid windowtext;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
&lt;/style&gt;
&lt;![endif]--&gt;

&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 480;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 154.75pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 154.75pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 366.15pt;&quot; valign=&quot;top&quot; width=&quot;488&quot;&gt;
  &lt;span style=&quot;font-family: Arial;&quot;&gt;if(a&amp;gt;b)&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp; System.out.println(&quot;a is
  greater than b&quot;);// prints a is greater than b&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp; else&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp; System.out.println(&quot;b is
  greater than a&quot;);//prints b is greater than a&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp; } &lt;/span&gt;&lt;br /&gt;

  &lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp;
if-else-if Ladder&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
When there are more than
two conditions then a common programming construct that is based upon a
sequence of nested ifs called if-else-if ladder is used. It looks like this:&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&amp;nbsp; &lt;!--[if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:WordDocument&gt;
  &lt;w:View&gt;Normal&lt;/w:View&gt;
  &lt;w:Zoom&gt;0&lt;/w:Zoom&gt;
  &lt;w:PunctuationKerning/&gt;
  &lt;w:ValidateAgainstSchemas/&gt;
  &lt;w:SaveIfXMLInvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;
  &lt;w:IgnoreMixedContent&gt;false&lt;/w:IgnoreMixedContent&gt;
  &lt;w:AlwaysShowPlaceholderText&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;
  &lt;w:Compatibility&gt;
   &lt;w:BreakWrappedTables/&gt;
   &lt;w:SnapToGridInCell/&gt;
   &lt;w:WrapTextWithPunct/&gt;
   &lt;w:UseAsianBreakRules/&gt;
   &lt;w:DontGrowAutofit/&gt;
  &lt;/w:Compatibility&gt;
  &lt;w:BrowserLevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;
 &lt;/w:WordDocument&gt;
&lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:LatentStyles DefLockedState=&quot;false&quot; LatentStyleCount=&quot;156&quot;&gt;
 &lt;/w:LatentStyles&gt;
&lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 10]&gt;
&lt;style&gt;
 /* Style Definitions */
 table.MsoNormalTable
 {mso-style-name:&quot;Table Normal&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 mso-style-noshow:yes;
 mso-style-parent:&quot;&quot;;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
table.MsoTableGrid
 {mso-style-name:&quot;Table Grid&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 border:solid windowtext 1.0pt;
 mso-border-alt:solid windowtext .5pt;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-border-insideh:.5pt solid windowtext;
 mso-border-insidev:.5pt solid windowtext;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
&lt;/style&gt;
&lt;![endif]--&gt;

&lt;br /&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 480;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 124.7pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 124.7pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 113.55pt;&quot; valign=&quot;top&quot; width=&quot;151&quot;&gt;
  &lt;span style=&quot;font-family: Arial;&quot;&gt;if(condition)&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
  &amp;lt;statement&amp;gt;;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp; else if(condition)&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
  &amp;lt;statement&amp;gt;;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp; else if(condition)&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
  &amp;lt;statement&amp;gt;;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;...&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;lt;statement&amp;gt;;&lt;/span&gt;&lt;br /&gt;

  &lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp;b.Switch
statement:&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
Switch statement provides a better alternative than a large series of
if-else-if statements.This is an easier implementation to the if-else
statements. The keyword &quot;switch&quot; is followed by an expression that
should evaluates to byte, short, char or int primitive data types ,only.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
General Syntax:&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&amp;nbsp;&amp;nbsp; &lt;!--[if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:WordDocument&gt;
  &lt;w:View&gt;Normal&lt;/w:View&gt;
  &lt;w:Zoom&gt;0&lt;/w:Zoom&gt;
  &lt;w:PunctuationKerning/&gt;
  &lt;w:ValidateAgainstSchemas/&gt;
  &lt;w:SaveIfXMLInvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;
  &lt;w:IgnoreMixedContent&gt;false&lt;/w:IgnoreMixedContent&gt;
  &lt;w:AlwaysShowPlaceholderText&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;
  &lt;w:Compatibility&gt;
   &lt;w:BreakWrappedTables/&gt;
   &lt;w:SnapToGridInCell/&gt;
   &lt;w:WrapTextWithPunct/&gt;
   &lt;w:UseAsianBreakRules/&gt;
   &lt;w:DontGrowAutofit/&gt;
  &lt;/w:Compatibility&gt;
  &lt;w:BrowserLevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;
 &lt;/w:WordDocument&gt;
&lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:LatentStyles DefLockedState=&quot;false&quot; LatentStyleCount=&quot;156&quot;&gt;
 &lt;/w:LatentStyles&gt;
&lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 10]&gt;
&lt;style&gt;
 /* Style Definitions */
 table.MsoNormalTable
 {mso-style-name:&quot;Table Normal&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 mso-style-noshow:yes;
 mso-style-parent:&quot;&quot;;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
table.MsoTableGrid
 {mso-style-name:&quot;Table Grid&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 border:solid windowtext 1.0pt;
 mso-border-alt:solid windowtext .5pt;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-border-insideh:.5pt solid windowtext;
 mso-border-insidev:.5pt solid windowtext;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
&lt;/style&gt;
&lt;![endif]--&gt;

&lt;br /&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 480;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 17.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 17.5pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 140.6pt;&quot; valign=&quot;top&quot; width=&quot;187&quot;&gt;
  &lt;span style=&quot;font-family: Arial;&quot;&gt;switch (x) {&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; case value0: &lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; doSomething0();&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp; case value1: &lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; doSomething1();&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp; case value2: &lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; doSomething2();&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;case value3: &lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; doSomething3();&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp; case value4: &lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; doSomething4();&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ....&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ....&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp; case valueN: &lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;doSomethingN();&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp; default: &lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; doSomethingElse();&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;

  &lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
The switch statement works
like this: The value of the expression is compared with each of the literal
values in the case statements. If a match is found, the code sequence following
that case statement is executed. If none of the constants matches the value of
the expression, then the default statement is executed. However, the default
statement is optional. If no case matches and no default is present, then no
further action is taken. The break statement is used inside the switch to
terminate a statement sequence. When a break statement is encountered,
execution branches to the first line of code that follows the entire switch
statement. This has the effect of “jumping out” of the switch.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;2-
Looping Statements:&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
Looping statements or Iteration statements enable program execution to repeat
one or more statements (that is,iteration statements form loops).&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;b&gt;&lt;i&gt;a: for loop:&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;!--[if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:WordDocument&gt;
  &lt;w:View&gt;Normal&lt;/w:View&gt;
  &lt;w:Zoom&gt;0&lt;/w:Zoom&gt;
  &lt;w:PunctuationKerning/&gt;
  &lt;w:ValidateAgainstSchemas/&gt;
  &lt;w:SaveIfXMLInvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;
  &lt;w:IgnoreMixedContent&gt;false&lt;/w:IgnoreMixedContent&gt;
  &lt;w:AlwaysShowPlaceholderText&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;
  &lt;w:Compatibility&gt;
   &lt;w:BreakWrappedTables/&gt;
   &lt;w:SnapToGridInCell/&gt;
   &lt;w:WrapTextWithPunct/&gt;
   &lt;w:UseAsianBreakRules/&gt;
   &lt;w:DontGrowAutofit/&gt;
  &lt;/w:Compatibility&gt;
  &lt;w:BrowserLevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;
 &lt;/w:WordDocument&gt;
&lt;/xml&gt;&lt;![endif][if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:LatentStyles DefLockedState=&quot;false&quot; LatentStyleCount=&quot;156&quot;&gt;
 &lt;/w:LatentStyles&gt;
&lt;/xml&gt;&lt;![endif][if gte mso 10]&gt;
&lt;style&gt;
 /* Style Definitions */
 table.MsoNormalTable
 {mso-style-name:&quot;Table Normal&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 mso-style-noshow:yes;
 mso-style-parent:&quot;&quot;;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
table.MsoTableGrid
 {mso-style-name:&quot;Table Grid&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 border:solid windowtext 1.0pt;
 mso-border-alt:solid windowtext .5pt;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-border-insideh:.5pt solid windowtext;
 mso-border-insidev:.5pt solid windowtext;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
&lt;/style&gt;
&lt;![endif]--&gt;

&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 480;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 56.8pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 56.8pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 203.75pt;&quot; valign=&quot;top&quot; width=&quot;272&quot;&gt;
  &lt;span style=&quot;color: #1d1d1e; font-family: Arial;&quot;&gt;for(&lt;i&gt;initialization&lt;/i&gt;; &lt;i&gt;condition&lt;/i&gt;;
  &lt;i&gt;iteration&lt;/i&gt;) &lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #1d1d1e; font-family: Arial;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #1d1d1e; font-family: Arial;&quot;&gt;// body&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #1d1d1e; font-family: Arial;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;The &lt;b&gt;for &lt;/b&gt;loop
operates as follows. When the loop first starts, the &lt;i&gt;initialization &lt;/i&gt;portion
of the loop is executed. Generally, this is an expression that sets the value
of the &lt;i&gt;loop control variable, &lt;/i&gt;which acts as a counter that controls the
loop. It is important to understand that the initialization expression is only
executed once. Next, &lt;i&gt;condition &lt;/i&gt;is evaluated. This must be a Boolean
expression. It usually tests the loop control variable against a target value.
If this expression is true, then the body of the loop is executed. If it is
false, the loop terminates. Next, the &lt;i&gt;iteration &lt;/i&gt;portion of the loop is
executed. This is usually an expression that increments or decrements the loop
control variable. The loop then iterates, first evaluating the conditional
expression, then executing the body of the loop, and then executing the
iteration expression with each pass. This process repeats until the controlling
expression is false.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;b&gt;&lt;i&gt;&lt;span style=&quot;color: #1d1d1e;&quot;&gt;b:
do-while&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;!--[if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:WordDocument&gt;
  &lt;w:View&gt;Normal&lt;/w:View&gt;
  &lt;w:Zoom&gt;0&lt;/w:Zoom&gt;
  &lt;w:PunctuationKerning/&gt;
  &lt;w:ValidateAgainstSchemas/&gt;
  &lt;w:SaveIfXMLInvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;
  &lt;w:IgnoreMixedContent&gt;false&lt;/w:IgnoreMixedContent&gt;
  &lt;w:AlwaysShowPlaceholderText&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;
  &lt;w:Compatibility&gt;
   &lt;w:BreakWrappedTables/&gt;
   &lt;w:SnapToGridInCell/&gt;
   &lt;w:WrapTextWithPunct/&gt;
   &lt;w:UseAsianBreakRules/&gt;
   &lt;w:DontGrowAutofit/&gt;
  &lt;/w:Compatibility&gt;
  &lt;w:BrowserLevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;
 &lt;/w:WordDocument&gt;
&lt;/xml&gt;&lt;![endif][if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:LatentStyles DefLockedState=&quot;false&quot; LatentStyleCount=&quot;156&quot;&gt;
 &lt;/w:LatentStyles&gt;
&lt;/xml&gt;&lt;![endif][if gte mso 10]&gt;
&lt;style&gt;
 /* Style Definitions */
 table.MsoNormalTable
 {mso-style-name:&quot;Table Normal&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 mso-style-noshow:yes;
 mso-style-parent:&quot;&quot;;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
table.MsoTableGrid
 {mso-style-name:&quot;Table Grid&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 border:solid windowtext 1.0pt;
 mso-border-alt:solid windowtext .5pt;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-border-insideh:.5pt solid windowtext;
 mso-border-insidev:.5pt solid windowtext;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
&lt;/style&gt;
&lt;![endif]--&gt;

&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 480;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 70.35pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 70.35pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 104.55pt;&quot; valign=&quot;top&quot; width=&quot;139&quot;&gt;
  &lt;span style=&quot;color: #1d1d1e; font-family: Arial;&quot;&gt;&amp;nbsp;do&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #1d1d1e; font-family: Arial;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #1d1d1e; font-family: Arial;&quot;&gt;&amp;nbsp;// body of loop&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #1d1d1e; font-family: Arial;&quot;&gt;&amp;nbsp;}&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #1d1d1e; font-family: Arial;&quot;&gt;&amp;nbsp;while (&lt;i&gt;condition&lt;/i&gt;);&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;Each
iteration of the &lt;b&gt;do-while &lt;/b&gt;loop first executes the body of the loop and
then evaluates the conditional expression. If this expression is true, the loop
will repeat. Otherwise, the loop terminates. As with all of Java’s loops, &lt;i&gt;condition
&lt;/i&gt;must be a Boolean expression&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;b&gt;&lt;i&gt;&lt;span style=&quot;color: #1d1d1e;&quot;&gt;c:
while&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;The &lt;b&gt;while
&lt;/b&gt;loop is Java’s most fundamental looping statement. It repeats a statement
or block while its controlling expression is true. Here is its general form:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;!--[if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:WordDocument&gt;
  &lt;w:View&gt;Normal&lt;/w:View&gt;
  &lt;w:Zoom&gt;0&lt;/w:Zoom&gt;
  &lt;w:PunctuationKerning/&gt;
  &lt;w:ValidateAgainstSchemas/&gt;
  &lt;w:SaveIfXMLInvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;
  &lt;w:IgnoreMixedContent&gt;false&lt;/w:IgnoreMixedContent&gt;
  &lt;w:AlwaysShowPlaceholderText&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;
  &lt;w:Compatibility&gt;
   &lt;w:BreakWrappedTables/&gt;
   &lt;w:SnapToGridInCell/&gt;
   &lt;w:WrapTextWithPunct/&gt;
   &lt;w:UseAsianBreakRules/&gt;
   &lt;w:DontGrowAutofit/&gt;
  &lt;/w:Compatibility&gt;
  &lt;w:BrowserLevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;
 &lt;/w:WordDocument&gt;
&lt;/xml&gt;&lt;![endif][if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:LatentStyles DefLockedState=&quot;false&quot; LatentStyleCount=&quot;156&quot;&gt;
 &lt;/w:LatentStyles&gt;
&lt;/xml&gt;&lt;![endif][if gte mso 10]&gt;
&lt;style&gt;
 /* Style Definitions */
 table.MsoNormalTable
 {mso-style-name:&quot;Table Normal&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 mso-style-noshow:yes;
 mso-style-parent:&quot;&quot;;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
table.MsoTableGrid
 {mso-style-name:&quot;Table Grid&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 border:solid windowtext 1.0pt;
 mso-border-alt:solid windowtext .5pt;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-border-insideh:.5pt solid windowtext;
 mso-border-insidev:.5pt solid windowtext;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
&lt;/style&gt;
&lt;![endif]--&gt;

&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 480;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 56.8pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 56.8pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 104.55pt;&quot; valign=&quot;top&quot; width=&quot;139&quot;&gt;
  &lt;span style=&quot;color: #1d1d1e; font-family: Arial;&quot;&gt;while(&lt;i&gt;condition&lt;/i&gt;)&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #1d1d1e; font-family: Arial;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #1d1d1e; font-family: Arial;&quot;&gt;// body of loop&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #1d1d1e; font-family: Arial;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;The &lt;i&gt;condition
&lt;/i&gt;can be any Boolean expression. The body of the loop will be executed as
long as the conditional expression is true. When &lt;i&gt;condition &lt;/i&gt;becomes
false, control passes to the next line of code immediately following the loop.
The curly braces are unnecessary if only a single statement is being repeated.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;b&gt;3- Branching
Statements: &lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
Branching statements allow your program to execute in a nonlinear fashion. &lt;b&gt;&lt;i&gt;Break,
jump and goto&lt;/i&gt;&lt;/b&gt; are the branching statements used in java.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://quicklearnjava.blogspot.com/feeds/714712330756328906/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://quicklearnjava.blogspot.com/2011/12/control-statements-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4430265161967407772/posts/default/714712330756328906'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4430265161967407772/posts/default/714712330756328906'/><link rel='alternate' type='text/html' href='http://quicklearnjava.blogspot.com/2011/12/control-statements-in-java.html' title='Control Statements in java'/><author><name>Unknown</name><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-4430265161967407772.post-3415531476175718273</id><published>2011-12-07T21:58:00.001+05:30</published><updated>2012-02-16T10:35:52.952+05:30</updated><title type='text'>Datatypes And Arrays</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;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: 14pt;&quot;&gt;&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;Java is a &lt;b&gt;&lt;i&gt;strongly typed&lt;/i&gt;&lt;/b&gt;
language. All expressions and parameters are checked by the java compiler to
ensure that the types are compatible. &lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&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;
There are 8 simple datatypes defined by Java. They are &lt;b&gt;&lt;i&gt;byte,&lt;/i&gt;&lt;/b&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;color: #1d1d1e; font-size: 9pt;&quot;&gt; &lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;color: #1d1d1e;&quot;&gt;short, int, long, char, float, double
and boolean.&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;b&gt;Integers&lt;i&gt;: &lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&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;&lt;/i&gt;&lt;/b&gt;The
datatypes&lt;b&gt;&lt;i&gt; byte,&lt;/i&gt;&lt;/b&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;color: #1d1d1e; font-size: 9pt;&quot;&gt; &lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;color: #1d1d1e;&quot;&gt;short, int and long &lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;color: #1d1d1e;&quot;&gt;is grouped&amp;nbsp; under integers.&lt;/span&gt;&lt;span style=&quot;color: #1d1d1e; font-size: 9pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #1d1d1e;&quot;&gt;All of these datatypes are signed,
positive and negative values.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoNormalTable&quot; style=&quot;border-collapse: collapse; font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; margin-left: 29.6pt;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 13.25pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;&quot;&gt;
  &lt;td style=&quot;border: solid black 1.0pt; height: 13.25pt; padding: 0in 5.4pt 0in 5.4pt; width: 104.7pt;&quot; valign=&quot;top&quot; width=&quot;140&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;Name&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-color: -moz-use-text-color; border-left: none; border: solid windowtext 1.0pt; height: 13.25pt; padding: 0in 5.4pt 0in 5.4pt; width: 92.4pt;&quot; valign=&quot;top&quot; width=&quot;123&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;Width&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-color: -moz-use-text-color; border-left: none; border: solid windowtext 1.0pt; height: 13.25pt; padding: 0in 5.4pt 0in 5.4pt; width: 212.55pt;&quot; valign=&quot;top&quot; width=&quot;283&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;Range&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr style=&quot;height: 26.45pt; mso-yfti-irow: 1;&quot;&gt;
  &lt;td style=&quot;border-color: -moz-use-text-color black black; border-top: none; border: solid windowtext 1.0pt; height: 26.45pt; padding: 0in 5.4pt 0in 5.4pt; width: 104.7pt;&quot; valign=&quot;top&quot; width=&quot;140&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #1d1d1e;&quot;&gt;long&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-color: -moz-use-text-color black black -moz-use-text-color; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 26.45pt; padding: 0in 5.4pt 0in 5.4pt; width: 92.4pt;&quot; valign=&quot;top&quot; width=&quot;123&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;64&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-color: -moz-use-text-color black black -moz-use-text-color; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 26.45pt; padding: 0in 5.4pt 0in 5.4pt; width: 212.55pt;&quot; valign=&quot;top&quot; width=&quot;283&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;-9,223,372,036,854,775,808
  to 9,223,372,036,854,775,807&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr style=&quot;height: 27.2pt; mso-yfti-irow: 2;&quot;&gt;
  &lt;td style=&quot;border-color: -moz-use-text-color black black; border-top: none; border: solid windowtext 1.0pt; height: 27.2pt; padding: 0in 5.4pt 0in 5.4pt; width: 104.7pt;&quot; valign=&quot;top&quot; width=&quot;140&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #1d1d1e;&quot;&gt;int&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-color: -moz-use-text-color black black -moz-use-text-color; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 27.2pt; padding: 0in 5.4pt 0in 5.4pt; width: 92.4pt;&quot; valign=&quot;top&quot; width=&quot;123&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;32&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-color: -moz-use-text-color black black -moz-use-text-color; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 27.2pt; padding: 0in 5.4pt 0in 5.4pt; width: 212.55pt;&quot; valign=&quot;top&quot; width=&quot;283&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;-2,147,483,648
  &amp;nbsp;to &amp;nbsp;2,147,483,647&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr style=&quot;height: 22.9pt; mso-yfti-irow: 3;&quot;&gt;
  &lt;td style=&quot;border-color: -moz-use-text-color black black; border-top: none; border: solid windowtext 1.0pt; height: 22.9pt; padding: 0in 5.4pt 0in 5.4pt; width: 104.7pt;&quot; valign=&quot;top&quot; width=&quot;140&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #1d1d1e;&quot;&gt;short&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-color: -moz-use-text-color black black -moz-use-text-color; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 22.9pt; padding: 0in 5.4pt 0in 5.4pt; width: 92.4pt;&quot; valign=&quot;top&quot; width=&quot;123&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;16&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-color: -moz-use-text-color black black -moz-use-text-color; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 22.9pt; padding: 0in 5.4pt 0in 5.4pt; width: 212.55pt;&quot; valign=&quot;top&quot; width=&quot;283&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;-32,768
  &amp;nbsp;to &amp;nbsp;32,767&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr style=&quot;height: 13.95pt; mso-yfti-irow: 4; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border-color: -moz-use-text-color black black; border-top: none; border: solid windowtext 1.0pt; height: 13.95pt; padding: 0in 5.4pt 0in 5.4pt; width: 104.7pt;&quot; valign=&quot;top&quot; width=&quot;140&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #1d1d1e;&quot;&gt;byte&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-color: -moz-use-text-color black black -moz-use-text-color; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.95pt; padding: 0in 5.4pt 0in 5.4pt; width: 92.4pt;&quot; valign=&quot;top&quot; width=&quot;123&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;8&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-color: -moz-use-text-color black black -moz-use-text-color; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.95pt; padding: 0in 5.4pt 0in 5.4pt; width: 212.55pt;&quot; valign=&quot;top&quot; width=&quot;283&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;-128
  &amp;nbsp;to &amp;nbsp;127&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #1d1d1e;&quot;&gt;Floating
point types:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #1d1d1e;&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;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #1d1d1e;&quot;&gt;When
evaluating expressions that require fractional precision then floating-point
numbers are used. There are two types of floating-point types, &lt;b&gt;float &lt;/b&gt;and
&lt;b&gt;double&lt;/b&gt;, which represent single- and double-precision numbers,
respectively. Their&lt;b&gt; &lt;/b&gt;width and ranges are shown here:&lt;/span&gt;&lt;/div&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoNormalTable&quot; style=&quot;border-collapse: collapse; font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; margin-left: 27pt; width: 554px;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 21.9pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;&quot;&gt;
  &lt;td style=&quot;border: solid black 1.0pt; height: 21.9pt; padding: 0in 5.4pt 0in 5.4pt; width: 138.55pt;&quot; valign=&quot;top&quot; width=&quot;185&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;Name&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-color: -moz-use-text-color; border-left: none; border: solid windowtext 1.0pt; height: 21.9pt; padding: 0in 5.4pt 0in 5.4pt; width: 138.55pt;&quot; valign=&quot;top&quot; width=&quot;185&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;Width in
  Bits&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-color: -moz-use-text-color; border-left: none; border: solid windowtext 1.0pt; height: 21.9pt; padding: 0in 5.4pt 0in 5.4pt; width: 138.55pt;&quot; valign=&quot;top&quot; width=&quot;185&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;Approximate
  Range&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr style=&quot;height: 20.75pt; mso-yfti-irow: 1;&quot;&gt;
  &lt;td style=&quot;border-color: -moz-use-text-color black black; border-top: none; border: solid windowtext 1.0pt; height: 20.75pt; padding: 0in 5.4pt 0in 5.4pt; width: 138.55pt;&quot; valign=&quot;top&quot; width=&quot;185&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #1d1d1e;&quot;&gt;double&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-color: -moz-use-text-color black black -moz-use-text-color; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 20.75pt; padding: 0in 5.4pt 0in 5.4pt; width: 138.55pt;&quot; valign=&quot;top&quot; width=&quot;185&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;64&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-color: -moz-use-text-color black black -moz-use-text-color; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 20.75pt; padding: 0in 5.4pt 0in 5.4pt; width: 138.55pt;&quot; valign=&quot;top&quot; width=&quot;185&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;4.9e–324
  to 1.8e+308&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr style=&quot;height: 21.9pt; mso-yfti-irow: 2; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border-color: -moz-use-text-color black black; border-top: none; border: solid windowtext 1.0pt; height: 21.9pt; padding: 0in 5.4pt 0in 5.4pt; width: 138.55pt;&quot; valign=&quot;top&quot; width=&quot;185&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #1d1d1e;&quot;&gt;float&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-color: -moz-use-text-color black black -moz-use-text-color; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 21.9pt; padding: 0in 5.4pt 0in 5.4pt; width: 138.55pt;&quot; valign=&quot;top&quot; width=&quot;185&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;32&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-color: -moz-use-text-color black black -moz-use-text-color; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 21.9pt; padding: 0in 5.4pt 0in 5.4pt; width: 138.55pt;&quot; valign=&quot;top&quot; width=&quot;185&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&quot;&gt;1.4e-045
  to 3.4e+038&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #1d1d1e;&quot;&gt;Characters:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;span style=&quot;color: #1d1d1e;&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;
&lt;b&gt;&lt;i&gt;char&lt;/i&gt;&lt;/b&gt; is the datatype used to store characters in java. In Java &lt;b&gt;char
&lt;/b&gt;is a 16-bit type. The range of a &lt;b&gt;char &lt;/b&gt;is 0 to 65,536. There are no
negative &lt;b&gt;char&lt;/b&gt;s. The standard set of characters known as ASCII still
ranges from 0 to 127 as always, and the extended 8-bit character set,
ISO-Latin-1, ranges from 0 to 255. Since Java is designed to allow applets to
be written for worldwide use, it makes sense that it would use Unicode to
represent characters.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;b&gt;Booleans:&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&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;
The simple datatype used for logical values is&lt;b&gt; &lt;i&gt;boolean. &lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;color: #1d1d1e;&quot;&gt;It can have only one of two possible values, &lt;b&gt;true &lt;/b&gt;or
&lt;b&gt;false.&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt; &lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;color: #1d1d1e;&quot;&gt;This is the type
returned by all relational operators, such as &lt;b&gt;a &amp;lt; b&lt;/b&gt;. &lt;b&gt;boolean &lt;/b&gt;is
also the type &lt;i&gt;required &lt;/i&gt;by the conditional expressions that govern the
control statements such as &lt;b&gt;if &lt;/b&gt;and &lt;b&gt;for.&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;Arrays:
&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&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;
An &lt;i&gt;array &lt;/i&gt;is a group of like-typed variables that are referred to by a
common name. Arrays of any type can be created and may have one or more
dimensions. A specific element in an array is accessed by its index. Arrays
offer a convenient means of grouping related information.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
One-Dimensional Arrays&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A
&lt;i&gt;one-dimensional array &lt;/i&gt;is, essentially, a list of like-typed variables.
To create an array, you first must create an array variable of the desired
type. The general form of a one-dimensional array declaration is&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;i&gt;type var-name&lt;/i&gt;[ ];&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
Here, &lt;i&gt;type &lt;/i&gt;declares
the base type of the array. The base type determines the data type of each
element that comprises the array. Thus, the base type for the array determines
what type of data the array will hold. &lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
For example, the following declares an array named month_days with the type
“array of int”:&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
int month_days[];&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
Although this declaration
establishes the fact that month_days is an array variable, no array actually
exists. In fact, the value of month_days is set to null, which represents an
array with no value. To link month_days with an actual, physical array of
integers, you must allocate one using new and assign it to month_days. new is a
special operator that allocates memory.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&amp;nbsp; The general form of
new as it applies to one-dimensional arrays appears&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
as follows:&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;i&gt;array-var &lt;/i&gt;= new &lt;i&gt;type&lt;/i&gt;[&lt;i&gt;size&lt;/i&gt;];&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
Here, &lt;i&gt;type &lt;/i&gt;specifies
the type of data being allocated, &lt;i&gt;size &lt;/i&gt;specifies the number of elements
in&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
the array, and &lt;i&gt;array-var
&lt;/i&gt;is the array variable that is linked to the array. That is, to use new to&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
allocate an array, you
must specify the type and number of elements to allocate. The elements in the
array allocated by new will automatically be initialized to zero. This example
allocates a 12-element array of integers and links them to month_days.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
month_days = new int[12];&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
After this statement
executes, month_days will refer to an array of 12 integers. Further, all
elements in the array will be initialized to zero.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
Let’s review: &lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&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;
Obtaining an array is a two-step process. First, you must declare a variable of
the desired array type. Second, you must allocate the memory that will hold the
array, using new, and assign it to the array variable. Thus, in Java all arrays
are dynamically allocated. &lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
Once you have allocated an array, you can access a specific element in the
array by specifying its index within square brackets. All array indexes start
at zero. &lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
For example, this
statement assigns the value 28 to the second element of month_days.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
month_days[1] = 28;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
The next line displays the
value stored at index 3.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
System.out.println(month_days[3]);&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
Putting together all the
pieces, here is a program that creates an array of the number&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
of days in each month.&lt;/div&gt;
&lt;!--[if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:WordDocument&gt;
  &lt;w:View&gt;Normal&lt;/w:View&gt;
  &lt;w:Zoom&gt;0&lt;/w:Zoom&gt;
  &lt;w:PunctuationKerning/&gt;
  &lt;w:ValidateAgainstSchemas/&gt;
  &lt;w:SaveIfXMLInvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;
  &lt;w:IgnoreMixedContent&gt;false&lt;/w:IgnoreMixedContent&gt;
  &lt;w:AlwaysShowPlaceholderText&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;
  &lt;w:Compatibility&gt;
   &lt;w:BreakWrappedTables/&gt;
   &lt;w:SnapToGridInCell/&gt;
   &lt;w:WrapTextWithPunct/&gt;
   &lt;w:UseAsianBreakRules/&gt;
   &lt;w:DontGrowAutofit/&gt;
  &lt;/w:Compatibility&gt;
  &lt;w:BrowserLevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;
 &lt;/w:WordDocument&gt;
&lt;/xml&gt;&lt;![endif][if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:LatentStyles DefLockedState=&quot;false&quot; LatentStyleCount=&quot;156&quot;&gt;
 &lt;/w:LatentStyles&gt;
&lt;/xml&gt;&lt;![endif][if gte mso 10]&gt;
&lt;style&gt;
 /* Style Definitions */
 table.MsoNormalTable
 {mso-style-name:&quot;Table Normal&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 mso-style-noshow:yes;
 mso-style-parent:&quot;&quot;;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
table.MsoTableGrid
 {mso-style-name:&quot;Table Grid&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 border:solid windowtext 1.0pt;
 mso-border-alt:solid windowtext .5pt;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-border-insideh:.5pt solid windowtext;
 mso-border-insidev:.5pt solid windowtext;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
&lt;/style&gt;
&lt;![endif]--&gt;

&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 480;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 305.95pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 305.95pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 321.0pt;&quot; valign=&quot;top&quot; width=&quot;428&quot;&gt;
  &lt;span style=&quot;font-family: Arial;&quot;&gt;// Demonstrate a one-dimensional array.&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;class Array &lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;public static void main(String args[]) &lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;int month_days[];&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;month_days = new int[12];&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;month_days[0] = 31;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;month_days[1] = 28;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;month_days[2] = 31;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;month_days[3] = 30;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;month_days[4] = 31;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;month_days[5] = 30;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;month_days[6] = 31;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;month_days[7] = 31;&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;month_days[8] = 30;&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;month_days[9] = 31;&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;month_days[10] = 30;&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;month_days[11] = 31;&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;System.out.println(&quot;April
  has &quot; + month_days[3] + &quot; days.&quot;);&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
When you run this program,
it prints the number of days in April. As mentioned, Java array indexes start
with zero, so the number of days in April is month_days[3] or 30. It is
possible to combine the declaration of the array variable with the allocation
of the array itself, as shown here:&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
int month_days[] = new
int[12];&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
This is the way that you
will normally see it done in professionally written Java programs. Arrays can
be initialized when they are declared. The process is much the same as that
used to initialize the simple types. An &lt;i&gt;array initializer &lt;/i&gt;is a list of
comma-separated expressions surrounded by curly braces. The commas separate the
values of the array elements. The array will automatically be created large
enough to hold the number of elements you specify in the array initializer.
There is no need to use new. &lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
For example, to store the number of days in each month, the following code
creates an initialized array of integers:&lt;/div&gt;
&lt;!--[if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:WordDocument&gt;
  &lt;w:View&gt;Normal&lt;/w:View&gt;
  &lt;w:Zoom&gt;0&lt;/w:Zoom&gt;
  &lt;w:PunctuationKerning/&gt;
  &lt;w:ValidateAgainstSchemas/&gt;
  &lt;w:SaveIfXMLInvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;
  &lt;w:IgnoreMixedContent&gt;false&lt;/w:IgnoreMixedContent&gt;
  &lt;w:AlwaysShowPlaceholderText&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;
  &lt;w:Compatibility&gt;
   &lt;w:BreakWrappedTables/&gt;
   &lt;w:SnapToGridInCell/&gt;
   &lt;w:WrapTextWithPunct/&gt;
   &lt;w:UseAsianBreakRules/&gt;
   &lt;w:DontGrowAutofit/&gt;
  &lt;/w:Compatibility&gt;
  &lt;w:BrowserLevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;
 &lt;/w:WordDocument&gt;
&lt;/xml&gt;&lt;![endif][if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:LatentStyles DefLockedState=&quot;false&quot; LatentStyleCount=&quot;156&quot;&gt;
 &lt;/w:LatentStyles&gt;
&lt;/xml&gt;&lt;![endif][if gte mso 10]&gt;
&lt;style&gt;
 /* Style Definitions */
 table.MsoNormalTable
 {mso-style-name:&quot;Table Normal&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 mso-style-noshow:yes;
 mso-style-parent:&quot;&quot;;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
table.MsoTableGrid
 {mso-style-name:&quot;Table Grid&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 border:solid windowtext 1.0pt;
 mso-border-alt:solid windowtext .5pt;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-border-insideh:.5pt solid windowtext;
 mso-border-insidev:.5pt solid windowtext;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
&lt;/style&gt;
&lt;![endif]--&gt;

&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 480;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 139.05pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 139.05pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 330.0pt;&quot; valign=&quot;top&quot; width=&quot;440&quot;&gt;
  &lt;span style=&quot;font-family: Arial;&quot;&gt;// An improved version of the previous
  program.&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;class AutoArray&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;public static void main(String args[]) &lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;int month_days[] = { 31, 28, 31, 30, 31,
  30, 31, 31, 30, 31,&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;30, 31 };&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;System.out.println(&quot;April has &quot;
  + month_days[3] + &quot; days.&quot;);&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;

  &lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
When you run this program,
you see the same output as that generated by the previous version. Java
strictly checks to make sure you do not accidentally try to store or reference
values outside of the range of the array. The Java run-time system will check
to be sure that all array indexes are in the correct range. For example, the
run-time system will check the value of each index into month_days to make sure
that it is between 0 and 11 inclusive. If you try to access elements outside
the range of the array (negative numbers or numbers greater than the length of
the array), you will cause a run-time error.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
Here is one more example
that uses a one-dimensional array. It finds the average of a set&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
of numbers.&lt;/div&gt;
&lt;!--[if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:WordDocument&gt;
  &lt;w:View&gt;Normal&lt;/w:View&gt;
  &lt;w:Zoom&gt;0&lt;/w:Zoom&gt;
  &lt;w:PunctuationKerning/&gt;
  &lt;w:ValidateAgainstSchemas/&gt;
  &lt;w:SaveIfXMLInvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;
  &lt;w:IgnoreMixedContent&gt;false&lt;/w:IgnoreMixedContent&gt;
  &lt;w:AlwaysShowPlaceholderText&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;
  &lt;w:Compatibility&gt;
   &lt;w:BreakWrappedTables/&gt;
   &lt;w:SnapToGridInCell/&gt;
   &lt;w:WrapTextWithPunct/&gt;
   &lt;w:UseAsianBreakRules/&gt;
   &lt;w:DontGrowAutofit/&gt;
  &lt;/w:Compatibility&gt;
  &lt;w:BrowserLevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;
 &lt;/w:WordDocument&gt;
&lt;/xml&gt;&lt;![endif][if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:LatentStyles DefLockedState=&quot;false&quot; LatentStyleCount=&quot;156&quot;&gt;
 &lt;/w:LatentStyles&gt;
&lt;/xml&gt;&lt;![endif][if gte mso 10]&gt;
&lt;style&gt;
 /* Style Definitions */
 table.MsoNormalTable
 {mso-style-name:&quot;Table Normal&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 mso-style-noshow:yes;
 mso-style-parent:&quot;&quot;;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
table.MsoTableGrid
 {mso-style-name:&quot;Table Grid&quot;;
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 border:solid windowtext 1.0pt;
 mso-border-alt:solid windowtext .5pt;
 mso-padding-alt:0in 5.4pt 0in 5.4pt;
 mso-border-insideh:.5pt solid windowtext;
 mso-border-insidev:.5pt solid windowtext;
 mso-para-margin:0in;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:&quot;Times New Roman&quot;;
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
&lt;/style&gt;
&lt;![endif]--&gt;

&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 480;&quot;&gt;
 &lt;tbody&gt;
&lt;tr style=&quot;height: 183.45pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; height: 183.45pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 275.9pt;&quot; valign=&quot;top&quot; width=&quot;368&quot;&gt;
  &lt;span style=&quot;font-family: Arial;&quot;&gt;// Average an array of values.&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;class Average&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;public static void main(String args[])&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;double nums[] = {10.1, 11.2, 12.3, 13.4,
  14.5};&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;double result = 0;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;font-family: Arial;&quot;&gt;int i;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;for(i=0; i&amp;lt;5; i++)&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;result = result + nums[i];&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;System.out.println(&quot;Average
  is &quot; + result / 5);&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;span style=&quot;color: #231f20; font-family: Arial;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;br /&gt;

  &lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://quicklearnjava.blogspot.com/feeds/3415531476175718273/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://quicklearnjava.blogspot.com/2011/12/datatypes.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4430265161967407772/posts/default/3415531476175718273'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4430265161967407772/posts/default/3415531476175718273'/><link rel='alternate' type='text/html' href='http://quicklearnjava.blogspot.com/2011/12/datatypes.html' title='Datatypes And Arrays'/><author><name>Unknown</name><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-4430265161967407772.post-7871095021702359928</id><published>2011-12-06T20:43:00.001+05:30</published><updated>2012-02-16T09:53:26.523+05:30</updated><title type='text'>OOP concepts</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;m:smallfrac m:val=&quot;off&quot;&gt;
   &lt;m:dispdef&gt;
   &lt;m:lmargin m:val=&quot;0&quot;&gt;
   &lt;m:rmargin m:val=&quot;0&quot;&gt;
   &lt;m:defjc m:val=&quot;centerGroup&quot;&gt;
   &lt;m:wrapindent m:val=&quot;1440&quot;&gt;
   &lt;m:intlim m:val=&quot;subSup&quot;&gt;
   &lt;m:narylim m:val=&quot;undOvr&quot;&gt;
  &lt;/m:narylim&gt;&lt;/m:intlim&gt;
&lt;/m:wrapindent&gt;

&lt;/m:defjc&gt;&lt;/m:rmargin&gt;&lt;/m:lmargin&gt;&lt;/m:dispdef&gt;&lt;/m:smallfrac&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: 12pt; line-height: 115%;&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; Java&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt; line-height: 115%;&quot;&gt; is an &lt;b&gt;object oriented&lt;/b&gt; &lt;b&gt;programming&lt;/b&gt;
language. &lt;span style=&quot;color: #1d1d1e;&quot;&gt;Object-oriented programming is at the
core of Java. &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 12pt; line-height: 115%;&quot;&gt;Object
Oriented Programming or &lt;b&gt;OOP&lt;/b&gt; is the
technique to create programs based on the real world. All java programs are
object oriented.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: 12pt; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; To understand the functionality of OOP
in Java, we first need to understand several fundamentals related to objects.
These include class, method, inheritance, encapsulation, abstraction and polymorphism.&lt;/span&gt;&lt;/div&gt;
&lt;ul style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: left;&quot;&gt;
&lt;li&gt;&lt;b&gt;&lt;span style=&quot;font-size: 14pt; line-height: 115%;&quot;&gt;Classes and Objects:&lt;/span&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; line-height: normal; margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: 12pt;&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; A class is a blueprint for an
object, and that nearly everything in java is an object. All java code is
defined in a class. A class describes how to make an object of that class type.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt; Class&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt; is the central point of
OOP and that contains data and codes with behavior. The class definition
describes all the properties, behavior, and identity of objects present within
that class. In Java everything happens within class and it describes a set of
objects with common behavior.&lt;/span&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; line-height: normal; margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: 12pt;&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; Objects are the basic unit with
identity and behavior, and object can take care of itself; you don’t have to
know or care &lt;i&gt;how &lt;/i&gt;the object does it. An object &lt;b&gt;knows &lt;/b&gt;things and &lt;b&gt;does
&lt;/b&gt;things. Things an object knows about itself are called &lt;b&gt;instance
variables&lt;/b&gt;. They represent the &lt;i&gt;state&lt;/i&gt; of an object Things an object
does are called &lt;b&gt;methods&lt;/b&gt;. They represent the &lt;i&gt;behavior &lt;/i&gt;of an
object.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; line-height: normal; margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;ul style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: left;&quot;&gt;
&lt;li&gt;&lt;b&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;Abstraction:&lt;/span&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: 12pt;&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; An &lt;b&gt;abstraction&lt;/b&gt; is an &lt;span style=&quot;color: #1d1d1e;&quot;&gt;essential element of
object-oriented programming. &lt;/span&gt;An abstraction is the &lt;/span&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;way of converting real
world objects in terms of class. The process of abstraction in Java is used to
hide certain details and only show the essential features of the object. In
other words, it deals with the outside view of an object (interface). For example
creating a class Vehicle and injecting properties into it. &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: 12pt;&quot;&gt;Example:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; line-height: normal;&quot;&gt;
&lt;span style=&quot;font-size: 12pt;&quot;&gt;public
class Vehicle {&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; line-height: normal;&quot;&gt;
&lt;span style=&quot;font-size: 12pt;&quot;&gt;public
String colour;&lt;br /&gt;
public String model;&lt;br /&gt;
}&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; line-height: normal; margin: 0in 0in 0.0001pt 0.25in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;ul style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: left;&quot;&gt;
&lt;li&gt;&lt;b&gt;&lt;span style=&quot;font-size: 14pt; line-height: 115%;&quot;&gt;Encapsulation:&lt;/span&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; line-height: normal; margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #1d1d1e; font-size: 12pt;&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; Encapsulation&lt;/span&gt;&lt;/b&gt;&lt;i&gt;&lt;span style=&quot;color: #1d1d1e; font-size: 12pt;&quot;&gt; &lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #1d1d1e; font-size: 12pt;&quot;&gt;is the mechanism that binds together code and
the data it manipulates, and keeps both safe from outside interference and
misuse.&lt;/span&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt; This
is an important programming concept that assists in separating an object&#39;s
state from its behavior. This helps in hiding an object&#39;s data describing its
state from any further modification by external component. In Java there are
four different terms used for hiding data constructs and these are public,
private, protected and package.&lt;/span&gt;&lt;span style=&quot;color: #1d1d1e; font-size: 9pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #1d1d1e; font-size: 12pt;&quot;&gt;One way to think about encapsulation is as a protective wrapper
that prevents the code and data from being arbitrarily accessed by other code
defined outside the wrapper.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; line-height: normal; margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;ul style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: left;&quot;&gt;
&lt;li&gt;&lt;b&gt;&lt;span style=&quot;font-size: 14pt; line-height: 115%;&quot;&gt;Inheritance:&lt;/span&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #1d1d1e; font-size: 12pt; line-height: 115%;&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; The process
by which one object acquires the properties of another object is known as &lt;b&gt;inheritance&lt;/b&gt;.&lt;/span&gt;&lt;span style=&quot;font-size: 12pt; line-height: 115%;&quot;&gt; Inheritance
is the property which allows a Child class to inherit some properties from its
parent class. In Java this is achieved by using &lt;b&gt;&lt;i&gt;extends&lt;/i&gt;&lt;/b&gt; keyword. Only
properties with access modifier public and protected can be accessed in child
class. Though objects are distinguished from each other by some additional
features but there are objects that share certain things common. In object
oriented programming classes can inherit some common behavior and state from
others. Inheritance in OOP allows to define a general class and later to
organize some other classes simply adding some details with the old class
definition. This saves work as the special class inherits all the properties of
the old general class and as a programmer you only require the new features.
This helps in a better data analysis, accurate coding and reduces development
time.&amp;nbsp;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 12pt; line-height: 115%;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;ul style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; text-align: left;&quot;&gt;
&lt;li&gt;&lt;b&gt;&lt;span style=&quot;font-size: 14pt; line-height: 115%;&quot;&gt;Polymorphism:&lt;/span&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; line-height: normal; text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #1d1d1e; font-size: 12pt;&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; Polymorphism&lt;/span&gt;&lt;/b&gt;&lt;i&gt;&lt;span style=&quot;color: #1d1d1e; font-size: 12pt;&quot;&gt; &lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #1d1d1e; font-size: 12pt;&quot;&gt;(many forms) is a feature that allows one interface
to be used for a general class of actions. &lt;/span&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;It
describes the ability of the object in belonging to different types with specific
behavior of each type. So by using this, one object can be treated like another
and in this way it can create and define multiple level of interface. Here the
programmers need not have to know the exact type of object in advance and this
is being implemented at runtime.&lt;b&gt; Polymorphism&lt;/b&gt; gives us the ultimate
flexibility in extensibility. The ability to define more than one function with
the same name is called Polymorphism. In java, there are two type of
polymorphism: compile time polymorphism (overloading) and runtime polymorphism
(overriding).&lt;br /&gt;
&lt;br /&gt;
When you override methods, &lt;b&gt;JVM&lt;/b&gt; determines the proper methods to call at the
program’s run time, not at the compile time. Overriding occurs when a class
method has the same name and signature as a method in parent class. &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif; line-height: normal; text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: 12pt;&quot;&gt;Overloading
occurs when several methods have same names with &lt;/span&gt;&lt;/div&gt;
&lt;ul style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot; type=&quot;disc&quot;&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;Overloading
     is determined at the compile time.&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;Different
     method signature and different number or type of parameters. &lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;line-height: normal; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;Same
     method signature but different number of parameters.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: 12pt;&quot;&gt;Same method signature and
same number of parameters but of different type.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://quicklearnjava.blogspot.com/feeds/7871095021702359928/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://quicklearnjava.blogspot.com/2011/12/object-oriented-programming-concepts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4430265161967407772/posts/default/7871095021702359928'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4430265161967407772/posts/default/7871095021702359928'/><link rel='alternate' type='text/html' href='http://quicklearnjava.blogspot.com/2011/12/object-oriented-programming-concepts.html' title='OOP concepts'/><author><name>Unknown</name><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>