<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-9218169636891156375</id><updated>2012-02-15T22:31:18.364-08:00</updated><title type='text'>CORE JAVA</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>27</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-1626270745204272358</id><published>2008-06-11T10:42:00.000-07:00</published><updated>2008-06-11T10:43:44.546-07:00</updated><title type='text'></title><content type='html'>&lt;p&gt;&lt;b&gt;&lt;u&gt;To Install Java&lt;/u&gt;&lt;/b&gt; &lt;/p&gt;&lt;p&gt;These instructions are to help you download and install Java on your personal computer. You must install Java before installing Eclipse, and you will need both.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Downloading and Installing Java On Windows:&lt;/b&gt; &lt;/p&gt;&lt;p&gt;&lt;b&gt;Prevent Errors like --&gt; &lt;/b&gt;&lt;span style="color:#ff0000;"&gt;&lt;b&gt;'javac' is not recognized as an internal or external command&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;                 1. Go to &lt;b&gt;http://java.sun.com&lt;/b&gt; and download the latest Version of Jave SDK or any Jace SDK as per your         requirement and install on your system.&lt;br /&gt;&lt;br /&gt;2. Accept all of the defaults and suggestions, but make sure that the location where Java will be installed is at the top level of your C: drive. Click on "Finish." You should have a directory (folder) named C:\j2sdk1.5.0_04, with subfolders C:\j2sdk1.5.0_04\bin and C:\j2sdk1.5.0_04\lib&lt;br /&gt;&lt;br /&gt;                 4. Modify your system variable called "&lt;b&gt;PATH&lt;/b&gt;" (so that programs can find where Java is located).&lt;br /&gt;To do this for Windows 2000 or XP, either right-click on the My Computer icon or select "System" on the control panel. When the window titled &lt;u&gt; "System Properties"&lt;/u&gt; appears, choose the tab at the top named &lt;u&gt; "Advanced."&lt;/u&gt; Then, click on         "&lt;u&gt;Environment Variables.&lt;/u&gt;" In the bottom window that shows system variables, select         "&lt;u&gt;Path&lt;/u&gt;" and then click on "&lt;u&gt;Edit...&lt;/u&gt;" Add C:\j2sdk1.5.0_04\bin as the first item in the list. Note that all items are separated by a         semicolon, with no spaces around the semicolon. You should end up with a path variable that looks something like&lt;br /&gt;        C:\j2sdk1.5.0_04\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\system32\Wbem&lt;br /&gt;&lt;br /&gt;                 For Windows 98 or ME, open the file AUTOEXEC.BAT in Notepad. You should find a line in this file that begins&lt;br /&gt;        SET PATH=...&lt;br /&gt;        Modify this line to add C:\j2sdk1.5.0_04\bin; immediately after the equals sign.&lt;br /&gt;&lt;br /&gt;                 5. Modify or create a system variable called "&lt;b&gt;CLASSPATH,&lt;/b&gt;" as follows. In the lower         "&lt;u&gt;System Variables&lt;/u&gt;" pane choose "New..." and type in Variable Name         "&lt;u&gt;CLASSPATH&lt;/u&gt;" and value (note that it begins with dot semicolon)&lt;br /&gt;        .;C:\j2sdk1.5.0_04\lib&lt;br /&gt;&lt;br /&gt;6. To test Java to see if everything is installed properly, open a command window (a DOS window) and type the command "javac" The result should be information about the Usage of javac and its options. If you get a result that "'javac' is not recognized as an internal or external command, operable program or batch file" then there is a problem and Java will not work correctly. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-1626270745204272358?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/1626270745204272358/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=1626270745204272358' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/1626270745204272358'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/1626270745204272358'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/to-install-java-these-instructions-are.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-8327855079523868175</id><published>2008-06-11T10:40:00.000-07:00</published><updated>2008-06-11T10:41:17.686-07:00</updated><title type='text'></title><content type='html'>&lt;u style="font-weight: bold;"&gt;Java Hello World Program:&lt;br /&gt;&lt;br /&gt;&lt;/u&gt;Our first application will be extremely simple - the obligatory &lt;u&gt;"Hello World".&lt;/u&gt; The following is the Hello World Application as written in Java. Type it into a text file or copy it out of your web browser, and save it as a file named &lt;i&gt;HelloWorld.java&lt;/i&gt;. This program demonstrates the text output function of the Java programming language by displaying the message "Hello world!". Java compilers expect the filename to match the class name.&lt;br /&gt;&lt;br /&gt;A java program is defined by a public class that takes the form:         &lt;pre&gt;&lt;span style="color:#000080;"&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;public class &lt;/span&gt;&lt;b style="color: rgb(0, 0, 0);"&gt;program-name&lt;/b&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;            &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;                &lt;/span&gt;&lt;b style="color: rgb(0, 0, 0);"&gt;optional variable declarations and methods&lt;/b&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;                &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;                public static void main(String[] args) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;                   &lt;/span&gt;&lt;b style="color: rgb(0, 0, 0);"&gt;statements&lt;/b&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;                }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;                &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;                &lt;/span&gt;&lt;b style="color: rgb(0, 0, 0);"&gt;optional variable declarations and methods&lt;/b&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;          &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;            }&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;u&gt;Source Code&lt;/u&gt;                  &lt;p&gt;In your favorite editor, create a file called HelloWorld.java with the following contents:&lt;/p&gt;         &lt;p style="color: rgb(0, 0, 0);"&gt;/** &lt;i&gt;Comment&lt;/i&gt;&lt;br /&gt;         * Displays "Hello World!" to the standard output.&lt;br /&gt;         */&lt;/p&gt; &lt;span style="color: rgb(0, 0, 0);" &gt;                 &lt;/span&gt;&lt;p&gt;&lt;code style="color: rgb(0, 0, 0);"&gt;class HelloWorld {&lt;br /&gt;&lt;br /&gt;          public static void main (String args[]) {&lt;br /&gt;&lt;br /&gt;            System.out.println("Hello World!");           //Displays the enclosed String on the Screen Console&lt;br /&gt;&lt;br /&gt;          }&lt;br /&gt;         &lt;br /&gt;        }&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;                 To compile Java code, we need to use the 'javac' tool. From a command line, the command to &lt;u&gt;compile&lt;/u&gt; this program is:&lt;br /&gt;&lt;br /&gt;                 javac HelloWorld.java&lt;br /&gt;&lt;br /&gt;For this to work, the javac must be in your shell's path or you must explicitly specify the path to the program (such as c:\j2se\bin\javac HelloWork.java). If the compilation is successful, javac will quietly end and return you to a command prompt. If you look in the directory, there will now be a HelloWorld.class file. This file is the compiled version of your program. Once your program is in this form, its ready to run. Check to see that a class file has been created. If not, or you receive an error message, check for typographical errors in your source code.&lt;/p&gt;         &lt;p&gt;You're ready to run your first Java application. To&lt;u&gt; run the program&lt;/u&gt;, you just run it with the java command:&lt;br /&gt;&lt;br /&gt;                 java HelloWorld&lt;br /&gt;&lt;br /&gt;        &lt;u&gt;Sample Run&lt;/u&gt;&lt;br /&gt;&lt;br /&gt;                 Hello world!&lt;/p&gt;         &lt;p&gt;The source file above should be saved as myfirstjavaprog.java, using any standard text editor capable of saving         as ASCII (eg - Notepad, Vi). As an alternative, you can download the source for this tutorial.&lt;br /&gt;&lt;br /&gt;                 &lt;code&gt;HelloWorld.java&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;                 &lt;b&gt;&lt;span style="color:#ff0000;"&gt;Note: &lt;/span&gt;&lt;/b&gt;It is important to note that you use the full name with extension when compiling (javac         HelloWorld.java) but only the class name when running (java HelloWorld).&lt;br /&gt;&lt;br /&gt;                 &lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-8327855079523868175?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/8327855079523868175/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=8327855079523868175' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/8327855079523868175'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/8327855079523868175'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/java-hello-world-program-our-first.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-3977487482120616052</id><published>2008-06-11T10:38:00.000-07:00</published><updated>2008-06-11T10:39:05.831-07:00</updated><title type='text'></title><content type='html'>&lt;u style="font-weight: bold;"&gt;Java Comments:&lt;br /&gt;&lt;/u&gt;&lt;p&gt;The Java programming language supports three kinds of comments:&lt;br /&gt;&lt;br /&gt;        /* text */&lt;br /&gt;        The compiler ignores everything from /* to */. &lt;/p&gt;         &lt;p&gt;/** documentation */&lt;br /&gt;        This indicates a documentation comment (doc comment, for short). The         compiler ignores this kind of comment, just like it ignores comments         that use /* and */. The JDK javadoc tool uses doc comments when         preparing automatically generated documentation. &lt;/p&gt;         &lt;p&gt;// text&lt;br /&gt;  &lt;br /&gt;        The compiler ignores everything from // to the end of the line. &lt;/p&gt;         &lt;p&gt;&lt;u&gt;Example&lt;/u&gt;&lt;/p&gt;         &lt;p&gt;&lt;u&gt;Java denotes comments in three ways:&lt;br /&gt;        &lt;/u&gt;&lt;br /&gt;        1. Double slashes in front of a single line comment:&lt;br /&gt;&lt;br /&gt;                 int i=5; // Set the integer to 5&lt;br /&gt;&lt;br /&gt;                 2. Matching slash-asterisk (/*) and asterisk-slash (*/) to bracket         multi-line comments:&lt;br /&gt;&lt;br /&gt;        /*&lt;br /&gt;        Set the integer to 5&lt;br /&gt;        */&lt;br /&gt;        int i=5;&lt;br /&gt;&lt;br /&gt;                 3. Matching slash-double asterisk (/**) &amp;amp; asterisk-slash(*/) for Javadoc automatic hypertext documentation, as in&lt;br /&gt;&lt;br /&gt;                 /**&lt;br /&gt;        This applet tests graphics.&lt;br /&gt;        */&lt;br /&gt;        public class testApplet extends applet{...&lt;br /&gt;&lt;br /&gt;                 or&lt;br /&gt;&lt;br /&gt;                 /**&lt;br /&gt;        * Asterisks inside the comment are ignored by javadoc so they&lt;br /&gt;        * can be used to make nice line markers.&lt;br /&gt;        **/&lt;br /&gt;&lt;br /&gt;        The SDK tool javadoc uses the latter /** ..*/ comment style when it    produces hypertext pages to describe a class.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-3977487482120616052?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/3977487482120616052/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=3977487482120616052' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/3977487482120616052'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/3977487482120616052'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/java-comments-java-programming-language.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-2923801842067174093</id><published>2008-06-11T10:36:00.000-07:00</published><updated>2008-06-11T10:42:03.344-07:00</updated><title type='text'></title><content type='html'>&lt;u style="font-weight: bold;"&gt;Java Data and Variables:&lt;br /&gt;&lt;/u&gt;&lt;br /&gt;There are 8 &lt;em&gt;primitive data types&lt;/em&gt;. he 8 primitive data types are numeric types. The names of the eight primitive data types are:&lt;br /&gt;&lt;br /&gt;       &lt;table style="color: rgb(255, 239, 234);" align="center" border="1" cellpadding="10"&gt;           &lt;tbody&gt;&lt;tr&gt;               &lt;td style="color: rgb(51, 51, 255);" align="center"&gt;&lt;b&gt;&lt;span style="font-size:85%;"&gt;byte&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;               &lt;td style="color: rgb(51, 51, 255);" align="center"&gt;&lt;b&gt;&lt;span style="font-size:85%;"&gt;short&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;               &lt;td style="color: rgb(51, 51, 255);" align="center"&gt;&lt;b&gt;&lt;span style="font-size:85%;"&gt;int&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;               &lt;td style="color: rgb(51, 51, 255);" align="center"&gt;&lt;b&gt;&lt;span style="font-size:85%;"&gt;long&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;               &lt;td style="color: rgb(51, 51, 255);" align="center"&gt;&lt;b&gt;&lt;span style="font-size:85%;"&gt;float&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;               &lt;td style="color: rgb(51, 51, 255);" align="center"&gt;&lt;b&gt;&lt;span style="font-size:85%;"&gt;double&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;               &lt;td style="color: rgb(51, 51, 255);" align="center"&gt;&lt;b&gt;&lt;span style="font-size:85%;"&gt;char&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;               &lt;td style="color: rgb(51, 51, 255);" align="center"&gt;&lt;b&gt;&lt;span style="font-size:85%;"&gt;boolean&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;             &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;         &lt;p&gt;There are both&lt;b&gt; &lt;/b&gt;&lt;em&gt;&lt;b&gt;integer&lt;/b&gt;&lt;/em&gt;&lt;b&gt; &lt;/b&gt;and &lt;b&gt;&lt;em&gt;floating         point&lt;/em&gt; &lt;/b&gt;primitive types. Integer types have no fractional part;         floating point types have a fractional part. On paper, integers have no         decimal point, and floating point types do. But in main memory, there         are no decimal points: even floating point values are represented with         bit patterns. There is a fundamental difference between the method used         to represent integers and the method used to represent floating point         numbers.&lt;b&gt; &lt;/b&gt;&lt;br /&gt;&lt;/p&gt;        &lt;table class="table1" height="114"&gt;     &lt;tbody&gt;&lt;tr align="left"&gt;&lt;th colspan="3" height="7"&gt;&lt;span style="font-size:85%;"&gt;Integer                 Primitive Data Types&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;             &lt;tr&gt;&lt;td bg="" style="color: rgb(51, 51, 255);" height="8"&gt;&lt;b&gt;&lt;span style="font-size:85%;"&gt;Type&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;               &lt;td bg="" style="color: rgb(51, 51, 255);" height="8"&gt;&lt;b&gt;&lt;span style="font-size:85%;"&gt;Size&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;               &lt;td bg="" style="color: rgb(51, 51, 255);" height="8"&gt;&lt;b&gt;&lt;span style="font-size:85%;"&gt;Range&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;             &lt;tr&gt;&lt;td height="8"&gt;&lt;span style="font-size:85%;"&gt;&lt;i&gt;byte&lt;/i&gt;&lt;/span&gt;&lt;/td&gt;               &lt;td height="8"&gt;&lt;span style="font-size:85%;"&gt;8 bits&lt;/span&gt;&lt;/td&gt;               &lt;td height="8"&gt;&lt;span style="font-size:85%;"&gt;-128 to +127&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;             &lt;tr&gt;&lt;td height="8"&gt;&lt;span style="font-size:85%;"&gt;&lt;i&gt;short&lt;/i&gt;&lt;/span&gt;&lt;/td&gt;               &lt;td height="8"&gt;&lt;span style="font-size:85%;"&gt;16 bits&lt;/span&gt;&lt;/td&gt;               &lt;td height="8"&gt;&lt;span style="font-size:85%;"&gt;-32,768 to +32,767&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;             &lt;tr&gt;&lt;td height="8"&gt;&lt;span style="font-size:85%;"&gt;&lt;i&gt;int&lt;/i&gt;&lt;/span&gt;&lt;/td&gt;               &lt;td height="8"&gt;&lt;span style="font-size:85%;"&gt;32 bits&lt;/span&gt;&lt;/td&gt;               &lt;td height="8"&gt;&lt;span style="font-size:85%;"&gt;(about)-2 billion to +2 billion&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;             &lt;tr&gt;&lt;td height="1"&gt;&lt;span style="font-size:85%;"&gt;&lt;i&gt;long&lt;/i&gt;&lt;/span&gt;&lt;/td&gt;               &lt;td height="1"&gt;&lt;span style="font-size:85%;"&gt;64 bits&lt;/span&gt;&lt;/td&gt;               &lt;td height="1"&gt;&lt;span style="font-size:85%;"&gt;(about)-10E18 to +10E18&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;        &lt;table class="table1" height="1"&gt;     &lt;tbody&gt;&lt;tr&gt;&lt;th colspan="3" height="1"&gt;&lt;span style="font-size:85%;"&gt;Floating Point Primitive Data Types&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;             &lt;tr&gt;&lt;td bg="" style="color: rgb(51, 51, 255);" height="1"&gt;&lt;b&gt;&lt;span style="font-size:85%;"&gt;Type&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;               &lt;td bg="" style="color: rgb(51, 51, 255);" height="1"&gt;&lt;b&gt;&lt;span style="font-size:85%;"&gt;Size&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;               &lt;td bg="" style="color: rgb(51, 51, 255);" height="1"&gt;&lt;b&gt;&lt;span style="font-size:85%;"&gt;Range&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;             &lt;tr&gt;&lt;td height="1"&gt;&lt;span style="font-size:85%;"&gt;float&lt;/span&gt;&lt;/td&gt;               &lt;td height="1"&gt;&lt;span style="font-size:85%;"&gt;32 bits&lt;/span&gt;&lt;/td&gt;               &lt;td height="1"&gt;&lt;span style="font-size:85%;"&gt;-3.4E+38 to +3.4E+38&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;             &lt;tr&gt;&lt;td height="1"&gt;&lt;span style="font-size:85%;"&gt;double&lt;/span&gt;&lt;/td&gt;               &lt;td height="1"&gt;&lt;span style="font-size:85%;"&gt;64 bits&lt;/span&gt;&lt;/td&gt;               &lt;td height="1"&gt;&lt;span style="font-size:85%;"&gt;-1.7E+308 to 1.7E+308&lt;/span&gt;&lt;/td&gt;             &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;             &lt;p align="left"&gt;         &lt;i&gt;&lt;u&gt;Examples&lt;/u&gt;&lt;/i&gt;&lt;/p&gt;         &lt;p&gt;int yr = 2006;&lt;br /&gt;       double rats = 8912 ;&lt;/p&gt;         &lt;p&gt;         For each primitive         type, there is a corresponding &lt;em&gt;wrapper class&lt;/em&gt;. A wrapper class         can be used to convert a primitive data value into an object, and some         type of objects into primitive data. The table shows primitive types and         their wrapper classes:&lt;/p&gt;        &lt;table class="table1" height="1"&gt;             &lt;tbody&gt;&lt;tr&gt;               &lt;td bg="" style="color: rgb(240, 240, 255);" align="center"&gt;&lt;b&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;primitive type&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;               &lt;td bg="" style="color: rgb(240, 240, 255);" align="center"&gt;&lt;b&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Wrapper type&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;             &lt;/tr&gt;             &lt;tr&gt;               &lt;td&gt;byte&lt;/td&gt;               &lt;td&gt;Byte&lt;/td&gt;             &lt;/tr&gt;             &lt;tr&gt;               &lt;td&gt;short&lt;/td&gt;               &lt;td&gt;Short&lt;/td&gt;             &lt;/tr&gt;             &lt;tr&gt;               &lt;td&gt;int&lt;/td&gt;               &lt;td&gt;Int&lt;/td&gt;             &lt;/tr&gt;             &lt;tr&gt;               &lt;td&gt;long&lt;/td&gt;               &lt;td&gt;Long&lt;/td&gt;             &lt;/tr&gt;             &lt;tr&gt;               &lt;td&gt;float&lt;/td&gt;               &lt;td&gt;Float&lt;/td&gt;             &lt;/tr&gt;             &lt;tr&gt;               &lt;td&gt;double&lt;/td&gt;               &lt;td&gt;Double&lt;/td&gt;             &lt;/tr&gt;             &lt;tr&gt;               &lt;td&gt;char&lt;/td&gt;               &lt;td&gt;Character&lt;/td&gt;             &lt;/tr&gt;             &lt;tr&gt;               &lt;td&gt;boolean&lt;/td&gt;               &lt;td&gt;Boolean&lt;/td&gt;             &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;             &lt;p&gt; Variables only exist within the structure in which they are         defined. For example, if a variable is created within a method, it         cannot be accessed outside the method. In addition, a different method         can create a variable of the same name which will not conflict with the         other variable. A java variable can be thought of as a little box made         up of one or more bytes that can hold a value of a particular data type:&lt;/p&gt;         &lt;p&gt;&lt;b&gt;Syntax: &lt;/b&gt;variabletype variablename = data;&lt;/p&gt;         &lt;p&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;u&gt;Source Code &lt;/u&gt;&lt;i&gt;( demonstrating         declaration of a variable )&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;         &lt;p&gt;class example&lt;br /&gt;       {&lt;br /&gt;         public static void main ( String[] args )&lt;br /&gt;         {&lt;br /&gt;           long x = 123;    &lt;span class="blue"&gt;//a         declaration of a variable named x with a datatype of long&lt;/span&gt;&lt;br /&gt;     &lt;br /&gt;           System.out.println("The variable x has: " +         x );&lt;br /&gt;         }&lt;br /&gt;       }&lt;/p&gt;         &lt;p&gt;&lt;u&gt;Source Code&lt;/u&gt;&lt;/p&gt;         &lt;p&gt;&lt;span style="font-family:Verdana;"&gt;public class MaxDemo {&lt;br /&gt;            public static void main(String args[]) {&lt;br /&gt;            //integers&lt;br /&gt;                 byte largestByte         = Byte.MAX_VALUE;&lt;br /&gt;                 short         largestShort = Short.MAX_VALUE;&lt;br /&gt;                 int         largestInteger = Integer.MAX_VALUE;&lt;br /&gt;                 long largestLong         = Long.MAX_VALUE;&lt;br /&gt;     &lt;br /&gt;                //real numbers&lt;br /&gt;                float largestFloat =         Float.MAX_VALUE;&lt;br /&gt;                double largestDouble =         Double.MAX_VALUE;&lt;br /&gt;      &lt;br /&gt;                //other primitive types&lt;br /&gt;               char aChar = 'S';&lt;br /&gt;               boolean aBoolean = true;&lt;br /&gt;     &lt;br /&gt;               //Display them all.&lt;br /&gt;                       System.out.println("largest byte value is " + largestByte +         ".");&lt;br /&gt;                       System.out.println("largest short value is " + largestShort +         ".");&lt;br /&gt;                       System.out.println("largest integer value is " +         largestInteger + ".");&lt;br /&gt;                       System.out.println("largest long value is " + largestLong +         ".");&lt;br /&gt;                       System.out.println("largest float value is " + largestFloat +         ".");&lt;br /&gt;                       System.out.println("largest double value is " + largestDouble         + ".");&lt;br /&gt;          }&lt;br /&gt;       }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;                &lt;u&gt;Sample Run&lt;/u&gt;&lt;/p&gt;         &lt;p&gt;The largest byte value is 127.&lt;br /&gt;       The largest short value is 32767.&lt;br /&gt;       The largest integer value is 2147483647.&lt;br /&gt;       The largest long value is 9223372036854775807.&lt;br /&gt;       The largest float value is 3.4028235E38.&lt;br /&gt;       The largest double value is 1.7976931348623157E308.&lt;br /&gt;&lt;/p&gt;                    &lt;span&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-2923801842067174093?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/2923801842067174093/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=2923801842067174093' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/2923801842067174093'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/2923801842067174093'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/java-data-and-variables-there-are-8.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-3417167925270464276</id><published>2008-06-11T10:35:00.000-07:00</published><updated>2008-06-11T10:36:54.824-07:00</updated><title type='text'></title><content type='html'>&lt;u style="font-weight: bold;"&gt;Java Command Line Arguments:&lt;br /&gt;&lt;/u&gt;&lt;br /&gt;This class demonstrates how command line arguments are passed in Java. Arguments are passed as a String array to the main method of a class. The first element (element 0) is the first argument passed not the name of the class.&lt;br /&gt;&lt;p&gt;&lt;u&gt;Source Code&lt;/u&gt;&lt;/p&gt; &lt;p&gt;An example that prints in the command line arguments passed into the class when executed. &lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana;"&gt;public class ReadArgs&lt;br /&gt;       {&lt;br /&gt;              public static final void         main(String args[])&lt;br /&gt;              {&lt;br /&gt;                               for (int i=0;i&lt;args.length;++i)&gt;&lt;/args.length;++i)&gt;&lt;/span&gt;&lt;/p&gt;         &lt;p align="left"&gt;&lt;u&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;  Sample Run&lt;/span&gt;&lt;/u&gt;&lt;/p&gt;         With the following command line, the output shown is produced.&lt;br /&gt;&lt;br /&gt;       java ReadArgs zero one two three&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Output:&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;                The following command line arguments were passed:&lt;br /&gt;       arg[0]: zero&lt;br /&gt;       arg[1]: one&lt;br /&gt;       arg[2]: two&lt;br /&gt;       arg[3]: three&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-3417167925270464276?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/3417167925270464276/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=3417167925270464276' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/3417167925270464276'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/3417167925270464276'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/java-command-line-arguments-this-class.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-3553144301919836961</id><published>2008-06-11T10:34:00.000-07:00</published><updated>2008-06-11T10:35:42.897-07:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold;"&gt;Java Arithmetic Operators:&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;The Java programming language has includes five simple arithmetic operators like are &lt;b&gt;+ (addition), - (subtraction), * (multiplication), / (division)&lt;/b&gt;, and &lt;b&gt;% (modulo).&lt;/b&gt; The following table summarizes the binary arithmetic operators in the Java programming language.&lt;br /&gt;&lt;br /&gt;The relation operators in Java are: &lt;tt&gt;==&lt;/tt&gt;, &lt;tt&gt;!=&lt;/tt&gt;,         &lt;tt&gt;&lt;&lt;/tt&gt;, &lt;tt&gt;&gt;&lt;/tt&gt;, &lt;tt&gt;&lt;=&lt;/tt&gt;, and &lt;tt&gt;&gt;=&lt;/tt&gt;. The         meanings of these operators are:        &lt;table class="table1" height="114" width="100%"&gt;             &lt;tbody&gt;&lt;tr&gt;             &lt;td height="15" width="41%"&gt;&lt;b&gt;Use&lt;/b&gt;&lt;/td&gt;             &lt;td height="15" width="100%"&gt;&lt;b&gt;Returns true if&lt;/b&gt;&lt;/td&gt;             &lt;/tr&gt;             &lt;tr&gt;             &lt;td height="15" width="41%"&gt;op1 &lt;b&gt;&lt;span style="color:#ff0000;"&gt;+&lt;/span&gt;&lt;/b&gt;               op2&lt;/td&gt;             &lt;td height="15" width="100%"&gt;op1 added to op2&lt;/td&gt;             &lt;/tr&gt;             &lt;tr&gt;             &lt;td height="15" width="41%"&gt;op1&lt;span style="color:#ff0000;"&gt; &lt;b&gt;-&lt;/b&gt; &lt;/span&gt;op2 &lt;/td&gt;             &lt;td height="15" width="100%"&gt;op2 subtracted from op1&lt;/td&gt;             &lt;/tr&gt;             &lt;tr&gt;             &lt;td height="15" width="41%"&gt;op1 &lt;b&gt;&lt;span style="color:#ff0000;"&gt;* &lt;/span&gt;&lt;/b&gt;op2 &lt;/td&gt;             &lt;td height="15" width="100%"&gt;op1 multiplied with op2&lt;/td&gt;             &lt;/tr&gt;             &lt;tr&gt;             &lt;td height="15" width="41%"&gt;op1 &lt;b&gt;&lt;span style="color:#ff0000;"&gt;/&lt;/span&gt;&lt;/b&gt;               op2 &lt;/td&gt;             &lt;td height="15" width="100%"&gt;op1 divided by op2&lt;/td&gt;             &lt;/tr&gt;             &lt;tr&gt;             &lt;td height="13" width="41%"&gt;op1&lt;b&gt; &lt;span style="color:#ff0000;"&gt;%&lt;/span&gt; &lt;/b&gt;op2 &lt;/td&gt;             &lt;td height="13" width="100%"&gt;Computes the remainder of dividing op1               by op2&lt;/td&gt;             &lt;/tr&gt;    &lt;/tbody&gt;&lt;/table&gt;             &lt;p align="left"&gt;The following java program, ArithmeticProg , defines two         integers and two double-precision floating-point numbers and uses the         five arithmetic operators to perform different arithmetic operations.         This program also uses + to concatenate strings. The arithmetic         operations are shown in boldface.         &lt;/p&gt;&lt;pre&gt;public class ArithmeticProg {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;&lt;br /&gt; //a few numbers&lt;br /&gt; int i = 10;&lt;br /&gt; int j = 20;&lt;br /&gt; double x = 10.5;&lt;br /&gt; double y = 20.5;&lt;br /&gt;&lt;br /&gt; //adding numbers&lt;br /&gt; System.out.println("Adding");&lt;br /&gt; System.out.println(" i + j = " + (i + j));&lt;br /&gt; System.out.println(" x + y = " + (x + y));&lt;br /&gt;&lt;br /&gt; //subtracting numbers&lt;br /&gt; System.out.println("Subtracting");&lt;br /&gt; System.out.println(" i - j = " + (i - j));&lt;br /&gt; System.out.println(" x - y = " + (x - y));&lt;br /&gt;&lt;br /&gt; //multiplying numbers&lt;br /&gt; System.out.println("Multiplying");&lt;br /&gt; System.out.println(" i * j = " + (i * j));&lt;br /&gt; System.out.println(" x * y = " + (x * y));&lt;br /&gt;&lt;br /&gt; //dividing numbers&lt;br /&gt; System.out.println("Dividing");&lt;br /&gt; System.out.println(" i / j = " + (i / j));&lt;br /&gt; System.out.println(" x / y = " + (x / y));&lt;br /&gt;&lt;br /&gt; //computing the remainder resulting&lt;br /&gt; //from dividing numbers&lt;br /&gt; System.out.println("Modulus");&lt;br /&gt; System.out.println(" i % j = " + (i % j));&lt;br /&gt; System.out.println(" x % y = " + (x % y));&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-3553144301919836961?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/3553144301919836961/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=3553144301919836961' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/3553144301919836961'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/3553144301919836961'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/java-arithmetic-operators-java.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-8598609697019374036</id><published>2008-06-11T10:33:00.000-07:00</published><updated>2008-06-11T10:34:35.811-07:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold;"&gt;Java Assignment Operators:&lt;br /&gt;&lt;/span&gt;&lt;p&gt;It's very common to see statement like the following, where you're adding something to a variable. Java Variables are assigned, or given, values using one of the assignment operators. The variable are always on the left-hand side of the assignment operator and the value to be assigned is always on the right-hand side of the assignment operator. The assignment operator is evaluated from &lt;b&gt;right to left&lt;/b&gt;, so a = b = c = 0; would assign 0 to c, then c to b then b to a.&lt;br /&gt;&lt;br /&gt;                 i = i + 2;&lt;/p&gt;         &lt;p&gt;Here we say that we are assigning i's value to the new value which is i+2.&lt;br /&gt;&lt;br /&gt;A shortcut way to write assignments like this is to use the += operator. It's one operator symbol so don't put blanks between the + and =.&lt;br /&gt;        i += 2; // Same as "i = i + 2"&lt;/p&gt;&lt;p&gt;&lt;u&gt;Here are some examples of assignments:&lt;/u&gt;&lt;/p&gt;&lt;p&gt;                 //assign 1 to&lt;br /&gt;        //variable a&lt;br /&gt;        int a = 1;&lt;br /&gt;&lt;br /&gt;                 //assign the result&lt;br /&gt;        //of 2 + 2 to b&lt;br /&gt;        int b = 2 + 2;         &lt;/p&gt;&lt;p&gt;//assign the literal&lt;br /&gt;        //"Hello" to str&lt;br /&gt;        String str = new String("Hello");&lt;br /&gt;       &lt;br /&gt;        //assign b to a, then assign a&lt;br /&gt;        //to d; results in d, a, and b being equal&lt;br /&gt;        int d = a = b;&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-8598609697019374036?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/8598609697019374036/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=8598609697019374036' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/8598609697019374036'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/8598609697019374036'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/java-assignment-operators-its-very.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-5382408551183436373</id><published>2008-06-11T10:32:00.000-07:00</published><updated>2008-06-11T10:33:20.475-07:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold;"&gt;Java Increment and Decrement Operators:&lt;br /&gt;&lt;/span&gt;&lt;p&gt;There are 2 Increment or decrement operators -&gt;  ++ and --. These two operators are unique in that they can be written both    before the operand they are applied to, called prefix increment/decrement, or after, called postfix increment/decrement.     The meaning is different in each case.         &lt;/p&gt;&lt;p&gt;&lt;i&gt;Example&lt;/i&gt;&lt;/p&gt;         &lt;p&gt;x = 1;&lt;br /&gt;        y = ++x;&lt;br /&gt;        System.out.println(y);&lt;br /&gt;&lt;br /&gt;                 prints 2, but&lt;br /&gt;&lt;br /&gt;                 x = 1;&lt;br /&gt;        y = x++;&lt;br /&gt;        System.out.println(y);&lt;br /&gt;&lt;br /&gt;                 prints 1&lt;/p&gt;         &lt;p&gt;&lt;u&gt;Source Code&lt;/u&gt;&lt;/p&gt;         &lt;p&gt;&lt;code&gt;&lt;span style="font-family:Verdana;"&gt;//Count to ten&lt;br /&gt;&lt;br /&gt;                 class UptoTen  {&lt;br /&gt;&lt;br /&gt;                   public static void main (String args[]) {&lt;br /&gt;            int i;&lt;br /&gt;            for (i=1; i &lt;=10; i++) { &lt;br /&gt;              System.out.println(i);&lt;br /&gt;            }&lt;br /&gt;           }&lt;br /&gt;&lt;br /&gt;                 }&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;         When we write i++ we're using shorthand for i = i + 1. When we say i--  we're using shorthand for i = i - 1. Adding and subtracting one from a number  are such common operations that these special increment and decrement operators  have been added to the language. T         &lt;p&gt;There's another short hand for the general add and assign operation, &lt;code&gt;   +=&lt;/code&gt;. We would normally write this as &lt;code&gt;i += 15&lt;/code&gt;. Thus if    we wanted to count from 0 to 20 by two's we'd write:&lt;/p&gt;&lt;p&gt;&lt;u&gt;Source Code&lt;/u&gt;&lt;/p&gt;         &lt;p&gt;&lt;code&gt;&lt;span style="font-family:Verdana;"&gt;class CountToTwenty  {&lt;br /&gt;&lt;br /&gt;                   public static void main (String args[]) {&lt;br /&gt;            int i;&lt;br /&gt;            for (i=0; i &lt;=20; i += 2) {  //Note Increment    Operator by 2&lt;br /&gt;              System.out.println(i);&lt;br /&gt;            }&lt;br /&gt;          &lt;br /&gt;         } //main ends here&lt;br /&gt;&lt;br /&gt;                 }&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;         As you might guess there is a corresponding -= operator. If we wanted to  count down from twenty to zero by twos we could write: &lt;code&gt;-=&lt;/code&gt;         &lt;p&gt;&lt;code&gt;&lt;span style="font-family:Verdana;"&gt;class CountToZero  {&lt;br /&gt;       &lt;br /&gt;          public static void main (String args[]) {&lt;br /&gt;            int i;&lt;br /&gt;            for (i=20; i &gt;= 0; i -= 2) {  //Note Decrement    Operator by 2&lt;br /&gt;              System.out.println(i);&lt;br /&gt;            }&lt;br /&gt;           }&lt;br /&gt;&lt;br /&gt;        }&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;    &lt;span&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt; &lt;script type="text/javascript"&gt;&lt;!-- google_ad_client = "pub-8082275437470616"; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_type = "text"; google_ad_channel =""; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "000000"; google_color_text = "000000"; google_color_url = "000000"; //--&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-5382408551183436373?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/5382408551183436373/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=5382408551183436373' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/5382408551183436373'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/5382408551183436373'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/java-increment-and-decrement-operators.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-1278489230278783362</id><published>2008-06-11T10:28:00.000-07:00</published><updated>2008-06-11T10:29:12.208-07:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold;"&gt;Java Relational Operators:&lt;br /&gt;&lt;/span&gt;&lt;p&gt;A relational operator compares two values and determines the relationship between them. For example, != returns true if its two operands are unequal. Relational operators are used to test whether two values are equal, whether one value is greater than another, and so forth. The relation operators in Java are: &lt;tt&gt;==&lt;/tt&gt;, &lt;tt&gt;!=&lt;/tt&gt;, &lt;tt&gt;   &lt;&lt;/tt&gt;,         &lt;tt&gt;&gt;&lt;/tt&gt;, &lt;tt&gt;&lt;=&lt;/tt&gt;, and &lt;tt&gt;&gt;=&lt;/tt&gt;. The meanings of these operators are:&lt;/p&gt;        &lt;table class="table1" height="1" width="100%"&gt;             &lt;tbody&gt;&lt;tr&gt;             &lt;td height="15" width="35%"&gt;&lt;b&gt;Use&lt;/b&gt;&lt;/td&gt;             &lt;td height="15" width="100%"&gt;&lt;b&gt;Returns true if&lt;/b&gt;&lt;/td&gt;             &lt;/tr&gt;             &lt;tr&gt;             &lt;td height="15" width="35%"&gt;op1 &lt;b&gt;&lt;span style="color:#ff0000;"&gt;&gt;&lt;/span&gt;&lt;/b&gt;               op2&lt;/td&gt;             &lt;td height="15" width="100%"&gt;op1 is greater than op2&lt;/td&gt;             &lt;/tr&gt;             &lt;tr&gt;             &lt;td height="15" width="35%"&gt;op1&lt;span style="color:#ff0000;"&gt; &lt;b&gt;&gt;=&lt;/b&gt; &lt;/span&gt;    op2 &lt;/td&gt;             &lt;td height="15" width="100%"&gt;op1 is greater than or equal to op2&lt;/td&gt;             &lt;/tr&gt;             &lt;tr&gt;             &lt;td height="15" width="35%"&gt;op1 &lt;b&gt;&lt;span style="color:#ff0000;"&gt;&lt; &lt;/span&gt;&lt;/b&gt;    op2 &lt;/td&gt;             &lt;td height="15" width="100%"&gt;op1 is less than to op2&lt;/td&gt;             &lt;/tr&gt;             &lt;tr&gt;             &lt;td height="15" width="35%"&gt;op1 &lt;b&gt;&lt;span style="color:#ff0000;"&gt;&lt;=&lt;/span&gt;&lt;/b&gt;               op2 &lt;/td&gt;             &lt;td height="15" width="100%"&gt;op1 is less than or equal to op2&lt;/td&gt;             &lt;/tr&gt;             &lt;tr&gt;             &lt;td height="13" width="35%"&gt;op1&lt;b&gt; == &lt;/b&gt;op2 &lt;/td&gt;             &lt;td height="13" width="100%"&gt;op1 and op2 are equal&lt;/td&gt;             &lt;/tr&gt;             &lt;tr&gt;             &lt;td height="15" width="35%"&gt;op1&lt;span style="color:#ff0000;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="color:#ff0000;"&gt;    !=&lt;/span&gt;               &lt;/b&gt;op2 &lt;/td&gt;             &lt;td height="15" width="100%"&gt;op1 and op2 are not equal&lt;/td&gt;             &lt;/tr&gt;    &lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;Variables only exist within the structure in which they are defined. For example, if a variable is created within a method, it cannot be accessed outside the method. In addition, a different method can create a variable of the same name which will not conflict with the other variable. A java variable can be thought of&lt;br /&gt;&lt;br /&gt;The main use for the above relational operators are in CONDITIONAL phrases The following java program is an example, RelationalProg, that defines three integer numbers and uses the relational operators to compare them.  &lt;/p&gt;&lt;pre&gt;public class RelationalProg {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;&lt;br /&gt; //a few numbers&lt;br /&gt; int i = 37;&lt;br /&gt; int j = 42;&lt;br /&gt; int k = 42;&lt;br /&gt;&lt;br /&gt; //greater than&lt;br /&gt; System.out.println("Greater than...");&lt;br /&gt; System.out.println(" i &gt; j = " + (i &gt; j)); //false&lt;br /&gt; System.out.println(" j &gt; i = " + (j &gt; i)); //true&lt;br /&gt; System.out.println(" k &gt; j = " + (k &gt; j)); //false&lt;br /&gt; //(they are equal)&lt;br /&gt;&lt;br /&gt; //greater than or equal to&lt;br /&gt; System.out.println("Greater than or equal to...");&lt;br /&gt; System.out.println(" i &gt;= j = " + (i &gt;= j)); //false&lt;br /&gt; System.out.println(" j &gt;= i = " + (j &gt;= i)); //true&lt;br /&gt; System.out.println(" k &gt;= j = " + (k &gt;= j)); //true&lt;br /&gt;&lt;br /&gt; //less than&lt;br /&gt; System.out.println("Less than...");&lt;br /&gt; System.out.println(" i &lt; j = " + (i &lt; j)); //true&lt;br /&gt; System.out.println(" j &lt; i = " + (j &lt; i)); //false&lt;br /&gt; System.out.println(" k &lt; j = " + (k &lt; j)); //false&lt;br /&gt;&lt;br /&gt; //less than or equal to&lt;br /&gt; System.out.println("Less than or equal to...");&lt;br /&gt; System.out.println(" i &lt;= j = " + (i &lt;= j)); //true&lt;br /&gt; System.out.println(" j &lt;= i = " + (j &lt;= i)); //false&lt;br /&gt; System.out.println(" k &lt;= j = " + (k &lt;= j)); //true&lt;br /&gt;&lt;br /&gt; //equal to&lt;br /&gt; System.out.println("Equal to...");&lt;br /&gt; System.out.println(" i == j = " + (i == j)); //false&lt;br /&gt; System.out.println(" k == j = " + (k == j)); //true&lt;br /&gt;&lt;br /&gt; //not equal to&lt;br /&gt; System.out.println("Not equal to...");&lt;br /&gt; System.out.println(" i != j = " + (i != j)); //true&lt;br /&gt; System.out.println(" k != j = " + (k != j)); //false&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;    &lt;span&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-1278489230278783362?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/1278489230278783362/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=1278489230278783362' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/1278489230278783362'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/1278489230278783362'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/java-relational-operators-relational.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-2393092192043158515</id><published>2008-06-11T10:26:00.000-07:00</published><updated>2008-06-11T10:28:27.198-07:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold;"&gt;Java Boolean Operators:&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;The Boolean logical operators are : &lt;b&gt;| , &amp;amp; , ^ , ! , || , &amp;amp;&amp;amp; , == , != . &lt;/b&gt;Java supplies a primitive data type called Boolean, instances of which can take the value true or false only, and have the default value false. The major use of Boolean facilities is to implement the expressions which control if decisions and while loops.&lt;br /&gt;&lt;br /&gt; These operators act on Boolean operands according to this table&lt;br /&gt;&lt;pre&gt;&lt;span style="color:#ff0000;"&gt;&lt;b&gt;A         B             A|B       A&amp;amp;B      A^B      !A&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;b&gt;false     false         false     false    false    true&lt;br /&gt;true      false         true      false    true     false&lt;br /&gt;false     true          true      false    true     true&lt;br /&gt;true      true          true      true     false    false&lt;/b&gt;&lt;/pre&gt;         &lt;pre&gt;&lt;span style="color:#ff0000;"&gt;&lt;b&gt;|&lt;/b&gt;&lt;/span&gt; the OR operator&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;b&gt;&amp;amp;&lt;/b&gt;&lt;/span&gt; the AND operator&lt;br /&gt;&lt;b&gt;&lt;span style="color:#ff0000;"&gt;^&lt;/span&gt;&lt;/b&gt; the XOR operator&lt;br /&gt;&lt;b&gt;&lt;span style="color:#ff0000;"&gt;!&lt;/span&gt;&lt;/b&gt; the NOT operator&lt;br /&gt;&lt;b&gt;&lt;span style="color:#ff0000;"&gt;||&lt;/span&gt;&lt;/b&gt; the short-circuit OR operator&lt;br /&gt;&lt;b&gt;&lt;span style="color:#ff0000;"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;/b&gt; the short-circuit AND operator&lt;br /&gt;&lt;b&gt;&lt;span style="color:#ff0000;"&gt;==&lt;/span&gt;&lt;/b&gt; the EQUAL TO operator&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;!=&lt;/span&gt; the NOT EQUAL TO operator &lt;/pre&gt;         &lt;p align="left"&gt;&lt;span style="color:#000000;"&gt;&lt;u&gt;Example&lt;/u&gt;&lt;/span&gt;              &lt;!--StartFragment --&gt;         &lt;/p&gt;         &lt;pre style="color: rgb(0, 0, 0);"&gt;&lt;b&gt;class Bool1{&lt;br /&gt;  public static void main(String args[]){&lt;br /&gt;&lt;br /&gt;// these are boolean variables    &lt;br /&gt;     boolean A = true;&lt;br /&gt;     boolean B = false;&lt;br /&gt;&lt;br /&gt;     System.out.println("A|B = "+(A|B));&lt;br /&gt;     System.out.println("A&amp;amp;B = "+(A&amp;amp;B));&lt;br /&gt;     System.out.println("!A = "+(!A));&lt;br /&gt;     System.out.println("A^B = "+(A^B));&lt;br /&gt;     System.out.println("(A|B)&amp;amp;A = "+((A|B)&amp;amp;A));&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/b&gt;&lt;/pre&gt;    &lt;span style="color: rgb(0, 0, 0);"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-2393092192043158515?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/2393092192043158515/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=2393092192043158515' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/2393092192043158515'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/2393092192043158515'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/java-boolean-operators-boolean-logical.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-5828398299871917931</id><published>2008-06-11T10:24:00.000-07:00</published><updated>2008-06-11T10:26:36.250-07:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold;"&gt;Java Conditional Operators:&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Java has the conditional operator. It's a ternary operator -- that is, it has three operands -- and it comes in two pieces, ? and :, that have to be used together. It takes the form&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;span style="color: rgb(0, 0, 0);" &gt;&lt;b&gt;Boolean-expression&lt;/b&gt; ? &lt;b&gt;   expression-1&lt;/b&gt;         : &lt;b&gt;expression-2&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt; &lt;br /&gt;&lt;p&gt;The JVM tests the value of &lt;b style="color: rgb(0, 0, 0);"&gt;   Boolean-expression&lt;/b&gt;. If the value is &lt;tt&gt;true&lt;/tt&gt;, &lt;span style="color:#000080;"&gt;   it evaluates &lt;b&gt;expression-1&lt;/b&gt;; otherwise, it evaluates &lt;b&gt;   expression-2&lt;/b&gt;.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;         &lt;p&gt;&lt;span style="color:#000000;"&gt;&lt;u&gt;Example&lt;/u&gt;&lt;/span&gt;&lt;/p&gt;         &lt;p&gt;if (a &gt; b) {&lt;br /&gt;             max = a;&lt;br /&gt;        }&lt;br /&gt;        else {&lt;br /&gt;             max = b;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;                &lt;br /&gt;                 Setting a single variable to one of two states based on a single    condition is such a common use of if-else that a shortcut has been    devised for it, the conditional operator, ?:. Using the conditional    operator you can rewrite the above example in a single line like this:&lt;br /&gt;&lt;br /&gt;        max = (a &gt; b) ? a : b;&lt;br /&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-5828398299871917931?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/5828398299871917931/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=5828398299871917931' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/5828398299871917931'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/5828398299871917931'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/java-conditional-operators-java-has.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-848310253044750525</id><published>2008-06-11T10:22:00.000-07:00</published><updated>2008-06-11T10:24:29.542-07:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold;"&gt;Java If-else Statement:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style="text-align: left;"&gt;&lt;u&gt;&lt;i&gt;The if-else class of statements should have the following form:&lt;/i&gt;&lt;/u&gt;&lt;br /&gt;&lt;br /&gt;if (condition)&lt;br /&gt;{&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;         statements;&lt;br /&gt;        }&lt;br /&gt;       &lt;br /&gt;        if (condition)&lt;br /&gt; {&lt;br /&gt;        statements;&lt;br /&gt;        }&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;        statements;&lt;br /&gt;        }&lt;br /&gt;       &lt;br /&gt;        if (condition)&lt;br /&gt;{&lt;br /&gt;        statements;&lt;br /&gt;        }&lt;br /&gt; else if (condition)&lt;br /&gt;{&lt;br /&gt;        statements;&lt;br /&gt;        }&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;        statements;&lt;br /&gt;        }&lt;/div&gt;         &lt;p&gt;All programming languages have some form of an &lt;code&gt;if&lt;/code&gt;         statement that allows you to test conditions. All arrays have lengths and         we can access that length by referencing the variable &lt;code&gt;arrayname.length&lt;/code&gt;.          We test the length of the &lt;code&gt;args&lt;/code&gt; array as follows:&lt;/p&gt;&lt;p&gt;&lt;u&gt;Source Code&lt;/u&gt;&lt;/p&gt;         &lt;p&gt;&lt;code&gt;&lt;span style="font-family:Verdana;"&gt;// This is the Hello program in Java&lt;br /&gt;        class Hello {&lt;br /&gt;       &lt;br /&gt;            public static void main (String args[]) {&lt;br /&gt;           &lt;br /&gt;              /* Now let's say hello */&lt;br /&gt;              System.out.print("Hello ");&lt;br /&gt;              if (args.length &gt; 0) {&lt;br /&gt;                System.out.println(args[0]);&lt;br /&gt;              }&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;                 }&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;         Compile and run this program and toss different inputs at it. You should         note that there's no longer an ArrayIndexOutOfBoundsException if you         don't give it any command line arguments at all.         &lt;p&gt;What we did was wrap the &lt;code&gt;System.out.println(args[0])&lt;/code&gt;         statement in a conditional test, &lt;code&gt;if (args.length &gt; 0) { }&lt;/code&gt;.         The code inside the braces, &lt;code&gt;System.out.println(args[0])&lt;/code&gt;,         now gets executed if and only if the length of the args array is greater         than zero. In Java numerical greater than and lesser than tests are done         with the &gt; and &lt;&gt;= respectively.&lt;/p&gt;         &lt;p&gt;Testing for equality is a little trickier. We would expect to test if         two numbers were equal by using the = sign. However we've already used         the = sign to set the value of a variable. Therefore we need a new         symbol to test for equality. Java borrows C's double equals sign, ==, to         test for equality. Lets look at an example when there are more then 1         statement in a branch and how &lt;b&gt;braces&lt;/b&gt; are used indefinitely.&lt;/p&gt;         &lt;p&gt;&lt;u&gt;&lt;span style="color:#000000;"&gt;Source Code&lt;/span&gt;&lt;/u&gt;&lt;/p&gt;         &lt;pre&gt;import java.io.*;&lt;br /&gt;class NumberTest&lt;br /&gt;{&lt;br /&gt; public static void main (String[] args) throws IOException&lt;br /&gt; {&lt;br /&gt;  BufferedReader stdin = new BufferedReader ( new InputStreamReader( System.in ) );&lt;br /&gt;&lt;br /&gt;  String inS;&lt;br /&gt;  int num;&lt;br /&gt;&lt;br /&gt;  System.out.println("Enter an integer number");&lt;br /&gt;  inS = stdin.readLine();&lt;br /&gt;  num = Integer.parseInt( inS ); // convert inS to int using wrapper classes&lt;br /&gt;&lt;br /&gt;  if ( num &lt; 0 )  // true-branch&lt;br /&gt;  {&lt;br /&gt;       System.out.println("The number " + num + " is negative");&lt;br /&gt;     System.out.println("negative number are less than zero");&lt;br /&gt;  }&lt;br /&gt;  else   // false-branch&lt;br /&gt;  {&lt;br /&gt;     System.out.println("The number " + num + " is positive");&lt;br /&gt;     System.out.print ("positive numbers are greater ");&lt;br /&gt;     System.out.println("or equal to zero ");&lt;br /&gt;  }&lt;br /&gt;  System.out.println("End of program"); // always executed&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;       &lt;/pre&gt;         &lt;p&gt;All conditional statements in Java require boolean values, and that's         what the ==, &lt;, &gt;, &lt;=, and &gt;= operators all return. A         boolean is a value that is either true or false. Unlike in C booleans         are not the same as ints, and ints and booleans cannot be cast back and         forth. If you need to set a boolean variable in a Java program, you have         to use the constants &lt;code&gt;true&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt;. &lt;code&gt;false&lt;/code&gt;         is not 0 and &lt;code&gt;true&lt;/code&gt; is not non-zero as in C. Boolean values         are no more integers than are strings.&lt;/p&gt;         &lt;p&gt;&lt;a name="xtocid226309"&gt;Else&lt;/a&gt;&lt;/p&gt;         &lt;p&gt;&lt;i&gt;Lets look at some examples of if-else:&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;                 //Example 1&lt;br /&gt;        if(a == b) {&lt;br /&gt;        c++;&lt;br /&gt;        }&lt;br /&gt;        if(a != b) {&lt;br /&gt;        c--;&lt;br /&gt;        }&lt;br /&gt;       &lt;br /&gt;        //Example 2&lt;br /&gt;        if(a == b) {&lt;br /&gt;        c++;&lt;br /&gt;        }&lt;br /&gt;        else {&lt;br /&gt;        c--;&lt;br /&gt;        }&lt;br /&gt;       &lt;br /&gt;        We could add an else statement like so:&lt;/p&gt;         &lt;p&gt;&lt;u&gt;Source Code&lt;/u&gt;&lt;/p&gt;         &lt;p&gt;&lt;code&gt;&lt;span style="font-family:Verdana;"&gt;// This is the Hello program in Java&lt;br /&gt;        class Hello {&lt;br /&gt;&lt;br /&gt;                     public static void main (String args[]) {&lt;br /&gt;           &lt;br /&gt;              /* Now let's say hello */&lt;br /&gt;              System.out.print("Hello ");&lt;br /&gt;              if (args.length &gt; 0) {&lt;br /&gt;                System.out.println(args[0]);&lt;br /&gt;              }&lt;br /&gt;              else {&lt;br /&gt;                        System.out.println("whoever you are");&lt;br /&gt;              }&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;                 }&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;         &lt;p&gt;&lt;code&gt;&lt;u&gt;Source Code&lt;/u&gt;&lt;/code&gt;&lt;/p&gt;         &lt;p&gt;public class divisor&lt;br /&gt;        {&lt;br /&gt;        public static void main(String[] args)&lt;br /&gt;                 int a = 10;&lt;br /&gt;                 int b = 2;&lt;br /&gt;                 if ( a % b == 0 )&lt;br /&gt;                 {&lt;br /&gt;                               System.out.println(a + " is divisible by "+ b);&lt;br /&gt;                 }&lt;br /&gt;                 else&lt;br /&gt;                 {&lt;br /&gt;                               System.out.println(a + " is not divisible by " + b);&lt;br /&gt;                 }&lt;br /&gt;        }&lt;br /&gt;        &lt;/p&gt;         Now that Hello at least doesn't crash with an         ArrayIndexOutOfBoundsException we're still not done. java Hello works         and Java Hello Rusty works, but if we type java Hello Elliotte Rusty         Harold, Java still only prints Hello Elliotte. Let's fix that.         &lt;p&gt;We're not just limited to two cases though. We can combine an &lt;code&gt;else&lt;/code&gt;         and an &lt;code&gt;if&lt;/code&gt; to make an &lt;code&gt;else if&lt;/code&gt; and use this to         test a whole range of mutually exclusive possibilities. &lt;/p&gt;         &lt;p&gt;&lt;i&gt;Lets look at some examples of if-else-if:&lt;/i&gt;&lt;br /&gt;       &lt;br /&gt;        //Example 1&lt;br /&gt;        if(color == BLUE)) {&lt;br /&gt;        System.out.println("The color is blue.");&lt;br /&gt;        }&lt;br /&gt;        else if(color == GREEN) {&lt;br /&gt;        System.out.println("The color is green.");&lt;br /&gt;        }&lt;br /&gt;       &lt;br /&gt;        //Example 2&lt;br /&gt;        if(employee.isManager()) {&lt;br /&gt;        System.out.println("Is a Manager");&lt;br /&gt;        }&lt;br /&gt;        else if(employee.isVicePresident()) {&lt;br /&gt;        System.out.println("Is a Vice-President");&lt;br /&gt;        }&lt;br /&gt;        else {&lt;br /&gt;        System.out.println("Is a Worker");&lt;br /&gt;        }&lt;br /&gt;       &lt;br /&gt;        &lt;u&gt;Source Code&lt;/u&gt;&lt;/p&gt;         &lt;p&gt;&lt;code&gt;&lt;span style="font-family:Verdana;"&gt;// This is the Hello program in Java&lt;br /&gt;        class Hello {&lt;br /&gt;       &lt;br /&gt;            public static void main (String args[]) {&lt;br /&gt;           &lt;br /&gt;              /* Now let's say hello */&lt;br /&gt;              System.out.print("Hello ");&lt;br /&gt;              if (args.length == 0) {&lt;br /&gt;                        System.out.print("whoever you are");&lt;br /&gt;              }&lt;br /&gt;              else if (args.length == 1) {&lt;br /&gt;                System.out.println(args[0]);&lt;br /&gt;              }&lt;br /&gt;              else if (args.length == 2) {&lt;br /&gt;                System.out.print(args[0]);&lt;br /&gt;                System.out.print("         ");&lt;br /&gt;                System.out.print(args[1]);&lt;br /&gt;              }     &lt;br /&gt;              else if (args.length == 3) {&lt;br /&gt;                System.out.print(args[0]);&lt;br /&gt;                System.out.print("         ");&lt;br /&gt;                System.out.print(args[1]);&lt;br /&gt;                System.out.print("         ");&lt;br /&gt;                System.out.print(args[2]);&lt;br /&gt;              }     &lt;br /&gt;                System.out.println();&lt;br /&gt;          }&lt;br /&gt;        }&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-848310253044750525?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/848310253044750525/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=848310253044750525' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/848310253044750525'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/848310253044750525'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/java-if-else-statement-if-else-class-of.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-7162583535062642128</id><published>2008-06-11T10:21:00.001-07:00</published><updated>2008-06-11T10:32:06.568-07:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold;"&gt;Java Loops (while, do-while and for loops):&lt;br /&gt;&lt;/span&gt;&lt;p&gt;A loop is a section of code that is executed repeatedly until a stopping condition is met. A typical loop may look like:  &lt;span style="font-family:monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:monospace;"&gt;&lt;/span&gt;while there's more data {&lt;br /&gt;&lt;/p&gt;&lt;pre&gt;  Read a Line of Data&lt;br /&gt;Do Something with the Data&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;         &lt;p&gt;There are many different kinds of loops in Java including &lt;code&gt;while&lt;/code&gt;,         &lt;code&gt;for&lt;/code&gt;, and &lt;code&gt;do while&lt;/code&gt; loops. They differ primarily in the stopping conditions used.&lt;/p&gt;&lt;p&gt;&lt;code&gt;For&lt;/code&gt; loops typically iterate a fixed number of times and then exit. &lt;code&gt;While&lt;/code&gt; loops iterate continuously until a         particular condition is met. You usually do not know in advance how many times a &lt;code&gt;while&lt;/code&gt; loop will loop.&lt;/p&gt;         &lt;p&gt;In this case we want to write a loop that will print each of the command line arguments in succession, starting with the first one. We don't know in advance how many arguments there will be, but we can easily find this out before the loop starts using the &lt;code&gt;args.length&lt;/code&gt;.         Therefore we will write this with a &lt;code&gt;for&lt;/code&gt; loop. Here's the code:&lt;/p&gt;         &lt;p&gt;&lt;u&gt;Source Code&lt;/u&gt;         &lt;/p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style="font-family:Verdana;"&gt;// This is the Hello program in Java&lt;br /&gt;class Hello {&lt;br /&gt;&lt;br /&gt;  public static void main (String args[]) {&lt;br /&gt;&lt;br /&gt;    int i;&lt;br /&gt;&lt;br /&gt;    /* Now let's say hello */&lt;br /&gt;    System.out.print("Hello ");&lt;br /&gt;    for (i=0; i &lt; i =" i++)"&gt;&lt;/code&gt;&lt;/pre&gt;         We begin the code by declaring our variables. In this case we have         exactly one variable, the integer i. &lt;code&gt;i&lt;/code&gt;         &lt;p&gt;Then we begin the program by saying "Hello" just like         before.&lt;/p&gt;         &lt;p&gt;Next comes the &lt;code&gt;for&lt;/code&gt; loop. The loop begins by initializing         the counter variable &lt;code&gt;i&lt;/code&gt; to be zero. This happens exactly         once at the beginning of the loop. Programming tradition that dates back         to Fortran insists that loop indices be named &lt;code&gt;i&lt;/code&gt;, &lt;code&gt;j&lt;/code&gt;,         &lt;code&gt;k&lt;/code&gt;, &lt;code&gt;l&lt;/code&gt;, &lt;code&gt;m&lt;/code&gt; and &lt;code&gt;n&lt;/code&gt; in         that order.&lt;/p&gt;         &lt;p&gt;Next is the test condition. In this case we test that &lt;code&gt;i&lt;/code&gt;         is less than the number of arguments. When &lt;code&gt;i&lt;/code&gt; becomes equal         to the number of arguments, (&lt;code&gt;args.length&lt;/code&gt;) we exit the loop         and go to the first statement after the loop's closing brace. You might         think that we should test for &lt;code&gt;i&lt;/code&gt; being less than or equal to         the number of arguments; but remember that we began counting at zero,         not one.&lt;/p&gt;         &lt;p&gt;Finally we have the increment step, &lt;code&gt;i++ (i=i+1)&lt;/code&gt;. This is         executed at the end of each iteration of the loop. Without this we'd         continue to loop forever since &lt;code&gt;i&lt;/code&gt; would always be less than &lt;code&gt;args.length&lt;/code&gt;.&lt;/p&gt;    &lt;span&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt; &lt;script type="text/javascript"&gt;&lt;!-- google_ad_client = "pub-8082275437470616"; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_type = "text_image"; google_ad_channel =""; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "000000"; google_color_text = "000000"; google_color_url = "000000"; //--&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-7162583535062642128?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/7162583535062642128/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=7162583535062642128' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/7162583535062642128'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/7162583535062642128'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/java-loops-while-do-while-and-for-loops_11.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-5216658064975191503</id><published>2008-06-11T10:21:00.000-07:00</published><updated>2008-06-11T10:22:38.914-07:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold;"&gt;Java Loops (while, do-while and for loops):&lt;br /&gt;&lt;/span&gt;&lt;p&gt;A loop is a section of code that is executed repeatedly until a stopping condition is met. A typical loop may look like:  &lt;span style="font-family: monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: monospace;"&gt;&lt;/span&gt;while there's more data {&lt;br /&gt;&lt;/p&gt;&lt;pre&gt;  Read a Line of Data&lt;br /&gt; Do Something with the Data&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;         &lt;p&gt;There are many different kinds of loops in Java including &lt;code&gt;while&lt;/code&gt;,         &lt;code&gt;for&lt;/code&gt;, and &lt;code&gt;do while&lt;/code&gt; loops. They differ primarily in the stopping conditions used.&lt;/p&gt;&lt;p&gt;&lt;code&gt;For&lt;/code&gt; loops typically iterate a fixed number of times and then exit. &lt;code&gt;While&lt;/code&gt; loops iterate continuously until a         particular condition is met. You usually do not know in advance how many times a &lt;code&gt;while&lt;/code&gt; loop will loop.&lt;/p&gt;         &lt;p&gt;In this case we want to write a loop that will print each of the command line arguments in succession, starting with the first one. We don't know in advance how many arguments there will be, but we can easily find this out before the loop starts using the &lt;code&gt;args.length&lt;/code&gt;.         Therefore we will write this with a &lt;code&gt;for&lt;/code&gt; loop. Here's the code:&lt;/p&gt;         &lt;p&gt;&lt;u&gt;Source Code&lt;/u&gt;         &lt;/p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style="font-family:Verdana;"&gt;// This is the Hello program in Java&lt;br /&gt;class Hello {&lt;br /&gt;&lt;br /&gt;   public static void main (String args[]) {&lt;br /&gt;  &lt;br /&gt;     int i;&lt;br /&gt;  &lt;br /&gt;     /* Now let's say hello */&lt;br /&gt;     System.out.print("Hello ");&lt;br /&gt;     for (i=0; i &lt; args.length; i = i++) {&lt;br /&gt;       System.out.print(args[i]);&lt;br /&gt;       System.out.print(" ");&lt;br /&gt;     }&lt;br /&gt;     System.out.println();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;         We begin the code by declaring our variables. In this case we have         exactly one variable, the integer i. &lt;code&gt;i&lt;/code&gt;         &lt;p&gt;Then we begin the program by saying "Hello" just like         before.&lt;/p&gt;         &lt;p&gt;Next comes the &lt;code&gt;for&lt;/code&gt; loop. The loop begins by initializing         the counter variable &lt;code&gt;i&lt;/code&gt; to be zero. This happens exactly         once at the beginning of the loop. Programming tradition that dates back         to Fortran insists that loop indices be named &lt;code&gt;i&lt;/code&gt;, &lt;code&gt;j&lt;/code&gt;,         &lt;code&gt;k&lt;/code&gt;, &lt;code&gt;l&lt;/code&gt;, &lt;code&gt;m&lt;/code&gt; and &lt;code&gt;n&lt;/code&gt; in         that order.&lt;/p&gt;         &lt;p&gt;Next is the test condition. In this case we test that &lt;code&gt;i&lt;/code&gt;         is less than the number of arguments. When &lt;code&gt;i&lt;/code&gt; becomes equal         to the number of arguments, (&lt;code&gt;args.length&lt;/code&gt;) we exit the loop         and go to the first statement after the loop's closing brace. You might         think that we should test for &lt;code&gt;i&lt;/code&gt; being less than or equal to         the number of arguments; but remember that we began counting at zero,         not one.&lt;/p&gt;         &lt;p&gt;Finally we have the increment step, &lt;code&gt;i++ (i=i+1)&lt;/code&gt;. This is         executed at the end of each iteration of the loop. Without this we'd         continue to loop forever since &lt;code&gt;i&lt;/code&gt; would always be less than &lt;code&gt;args.length&lt;/code&gt;.&lt;/p&gt;    &lt;span&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt; &lt;script type="text/javascript"&gt;&lt;!-- google_ad_client = "pub-8082275437470616"; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_type = "text_image"; google_ad_channel =""; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "000000"; google_color_text = "000000"; google_color_url = "000000"; //--&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-5216658064975191503?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/5216658064975191503/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=5216658064975191503' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/5216658064975191503'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/5216658064975191503'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/java-loops-while-do-while-and-for-loops.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-2658512965866750571</id><published>2008-06-11T10:20:00.000-07:00</published><updated>2008-06-11T10:21:14.196-07:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold;"&gt;Java Variables and Arithmetic Expressions:&lt;br /&gt;&lt;/span&gt;&lt;p&gt;Java &lt;b&gt;Variables &lt;/b&gt;are used to store data. Variables have type, name, and value. Variable names begin with a character, such         as x, D, Y, z. Other examples are xy1, abc2, Count, N, sum, Sum, product etc. These are all variable names.&lt;br /&gt;&lt;br /&gt;Different variable types are int, char, double. A variable type tells you what kind of data can be stored in that variable.&lt;br /&gt;&lt;br /&gt;                 The &lt;b&gt;syntax&lt;/b&gt; of assignment statements is easy. Assignment statements look like this:&lt;br /&gt;&lt;br /&gt;                 variableName = expression ;&lt;br /&gt;&lt;br /&gt;                 &lt;i&gt;For example:&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;                 int x; // This means variable x can store numbers such as 2, 10, -5.&lt;br /&gt;&lt;br /&gt;                 char y; // This means variable y can store single characters 'a', 'A'.&lt;br /&gt;&lt;br /&gt;                 double z; // This means variable z can store real numbers such as&lt;br /&gt;        10.45, 3.13411.&lt;br /&gt;&lt;br /&gt;                 The above are declarations for variables x, y and z.&lt;/p&gt; &lt;p&gt;&lt;script type="text/javascript"&gt;&lt;!-- google_ad_client = "pub-8082275437470616"; google_ad_width = 468; google_ad_height = 15; google_ad_format = "468x15_0ads_al"; google_ad_channel =""; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "000000"; google_color_text = "000000"; google_color_url = "008000"; //--&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt; &lt;/script&gt;&lt;iframe name="google_ads_frame" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-8082275437470616&amp;amp;dt=928257658031&amp;amp;lmt=1176898445&amp;amp;prev_fmts=468x60_as%2C468x60_as&amp;amp;format=468x15_0ads_al&amp;amp;output=html&amp;amp;correlator=928257657906&amp;amp;url=http%3A%2F%2Fwww.freejavaguide.com%2Farithmetic_expressions.htm&amp;amp;color_bg=FFFFFF&amp;amp;color_text=000000&amp;amp;color_link=000000&amp;amp;color_url=008000&amp;amp;color_border=FFFFFF&amp;amp;ref=http%3A%2F%2Fwww.freejavaguide.com%2Fjava_loops.htm&amp;amp;frm=0&amp;amp;cc=100&amp;amp;ga_vid=3362568785401447400.928257658&amp;amp;ga_sid=928257658&amp;amp;ga_hid=1697722229&amp;amp;flash=9.0.115&amp;amp;u_h=864&amp;amp;u_w=1152&amp;amp;u_ah=836&amp;amp;u_aw=1152&amp;amp;u_cd=16&amp;amp;u_tz=330&amp;amp;u_his=17&amp;amp;u_java=true&amp;amp;u_nplug=10&amp;amp;u_nmime=41" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" frameborder="0" height="15" scrolling="no" width="468"&gt;&lt;/iframe&gt;&lt;/p&gt; &lt;p&gt;&lt;u&gt;Important points:&lt;/u&gt;&lt;br /&gt;&lt;br /&gt;                 1. Note that a variable has to be declared before being used.&lt;br /&gt;&lt;br /&gt;2. The values assigned to a variable correspond to its type. Statements below represent assignment of values to a variable.&lt;br /&gt;&lt;br /&gt;                 x = 100; // x is an integer variable.&lt;br /&gt;        y = 'A'; // y is a character variable.&lt;br /&gt;        abc = 10.45; // abc is of type double (real numbers).&lt;br /&gt;&lt;br /&gt;                 3. Both variable declaration and assignment of values can be done in same statement. For example,&lt;br /&gt;&lt;br /&gt;                 int x;&lt;br /&gt;        x = 100; is same as int x = 100;&lt;br /&gt;&lt;br /&gt;                 4. A variable is declared only once.&lt;br /&gt;&lt;br /&gt;                 int x; // Declaration for x.&lt;br /&gt;        x = 100; // Initialization.&lt;br /&gt;        x = x + 12; // Using x in an assignment statement.&lt;/p&gt;&lt;p&gt;Often in a program you want to give a variable, a constant value. This can be done:&lt;br /&gt;&lt;br /&gt;                 class ConstDemo&lt;br /&gt;        {&lt;br /&gt;        public static void main ( String[] arg )&lt;br /&gt;        {&lt;br /&gt;              final double PI = 3.14;&lt;br /&gt;              final double CONSTANT2 = 100;&lt;br /&gt;        . . . . . .&lt;br /&gt;        }&lt;br /&gt;        }&lt;/p&gt;         &lt;p&gt;The reserved word final tells the compiler that the value will not change. The names of constants follow the same rules as the names for variables. (Programmers sometimes use all capital letters for constants; but that is a matter of personal style, not part of the language.)&lt;/p&gt;                  &lt;p&gt;2. Arithmetic Expressions&lt;br /&gt;        --------------------------&lt;br /&gt;An assignment statement or expression changes the value that is held in a variable. Here is a program that uses an assignment statement:&lt;br /&gt;&lt;br /&gt;                 &lt;span style="font-family:Verdana;"&gt;class example&lt;br /&gt;        {&lt;br /&gt;                public static void main (         String[] args )&lt;br /&gt;        {&lt;br /&gt;                long x ; //a declaration         without an initial value&lt;br /&gt;&lt;br /&gt;                         x = 123; //&lt;span style="color: rgb(0, 0, 0);" &gt;an assignment statement&lt;/span&gt;&lt;br /&gt;                System.out.println("The variable x contains: " + x );&lt;br /&gt;        }&lt;br /&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;                 Java &lt;b&gt;Arithmetic expressions&lt;/b&gt; use arithmetic operators such as +, -, /, *, and %. The % operator is the remainder or modulo operator. Arithmetic expressions are used to assign arithmetic values to variables. An expression is a combination of literals, operators, variables, and parentheses used to calculate a value.&lt;br /&gt;&lt;br /&gt;                 The following code describes the use of different arithmetic expressions.&lt;br /&gt;&lt;br /&gt;                 int x, y, z; // Three integer variables declared at the same time.&lt;br /&gt;&lt;br /&gt;                 x = 10;&lt;br /&gt;        y = 12;&lt;br /&gt;        z = y / x; // z is assigned the value of y divided by x.&lt;br /&gt;        // Here z will have value 1.&lt;br /&gt;&lt;br /&gt;                 z = x + y; // z is assigned the value of x+y                                             // Here z will have value 22.&lt;br /&gt;&lt;br /&gt;                 z = y % x // z is assigned the value of remainder when y                 // is divided by x. Here z will have value 2.&lt;br /&gt;&lt;br /&gt;                 Java &lt;b&gt;Boolean expressions&lt;/b&gt; are expressions which are either true or false. The different boolean operators are &lt; (less than), &gt;         (greater than),&lt;br /&gt;        == (equal to), &gt;= (greater or equal to), &lt;= (less or equal), != (not equal to).&lt;br /&gt;&lt;br /&gt;                 Example:&lt;br /&gt;&lt;br /&gt;                 int x = 10;&lt;br /&gt;        int y = 4;&lt;br /&gt;        int z = 5;&lt;br /&gt;&lt;br /&gt;                 (x &lt; 10) // This expression checks if x is less than 10.&lt;br /&gt;&lt;br /&gt;                 (y &gt; 1) // This expression checks if y is greater than 1.&lt;br /&gt;&lt;br /&gt;                 ((x - y) == (z + 1)); // This expression checks&lt;br /&gt;        // if (x - y) equals (z + 1).&lt;br /&gt;&lt;br /&gt;A boolean expression can also be a combination of other boolean expressions. Two or more boolean expressions can be connected using &amp;amp;&amp;amp;&lt;br /&gt;        (logical AND) and || (logical OR) operators.&lt;br /&gt;&lt;br /&gt;The &amp;amp;&amp;amp; operator represents logical AND. The expression is true only if both boolean expressions are true. The || operator represents logical&lt;br /&gt;        OR. This expression would be true if any one of the associated expressions is true.&lt;br /&gt;&lt;br /&gt;                 &lt;i&gt;Example:&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;                 int x = 10; int y = 4; int z = 5;&lt;br /&gt;&lt;br /&gt;                 (x &lt;= 10) &amp;amp;&amp;amp; (y &gt; 1) // This expression checks if x is less&lt;br /&gt;        // than 10 AND y is greater than 1.&lt;br /&gt;        // This expression is TRUE.&lt;br /&gt;&lt;br /&gt;        (x*y == 41) || (z == 5) // This expression checks if x*y is equal&lt;br /&gt;        // to 40 OR if z is equal to 5.&lt;br /&gt;        // This expression is FALSE&lt;br /&gt;&lt;/p&gt;    &lt;span&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-2658512965866750571?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/2658512965866750571/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=2658512965866750571' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/2658512965866750571'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/2658512965866750571'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/java-variables-and-arithmetic.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-8459161734516370397</id><published>2008-06-11T10:15:00.000-07:00</published><updated>2008-06-11T10:16:54.257-07:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold;"&gt;Methods (Includes Recursive Methods):&lt;br /&gt;&lt;/span&gt;&lt;p&gt;A method is a group of instructions that is given a name and can be called up at any point in a program simply by quoting that name. Each &lt;dfn&gt;calculation part&lt;/dfn&gt; of a program is called a method. Methods are logically the same as C's functions, Pascal's procedures and functions, and Fortran's functions and subroutines.&lt;/p&gt;&lt;p&gt;When I wrote &lt;code&gt;System.out.println("Hello World!");&lt;/code&gt; in the first program we were using the &lt;code&gt;System.out.println()&lt;/code&gt;         method. The &lt;code&gt;System.out.println()&lt;/code&gt; method actually requires quite a lot of code, but it is all stored for us in the System         libraries. Thus rather than including that code every time we need to print, we just call the &lt;code&gt;System.out.println()&lt;/code&gt; method.&lt;br /&gt;&lt;br /&gt;You can write and call your own methods too. Methods begin with a declaration. This can include three to five parts. First is an optional access specifier which can be public, private or protected. A &lt;b&gt;public&lt;/b&gt; method can be called from pretty much anywhere. A&lt;b&gt; private&lt;/b&gt; method         can only be used within the class where it is defined. A &lt;b&gt;protected&lt;/b&gt; method can be used anywhere within the package in which it is defined.         Methods that aren't specifically declared public or private are protected by default. &lt;dfn&gt;access specifier. &lt;/dfn&gt;We then decide whether the method is or is not static. Static methods have only one instance per class rather than one instance per object. All objects of the same class share a single copy of a static method. By default methods are not static. We finally specify the &lt;dfn&gt;return type&lt;/dfn&gt;. &lt;/p&gt;         &lt;p&gt;Next is the name of the method.&lt;/p&gt;         &lt;p&gt;&lt;u&gt;Source Code&lt;/u&gt;         &lt;/p&gt;&lt;pre&gt;&lt;span style="font-family:Verdana;"&gt;&lt;code&gt;class FactorialTest {    //&lt;/code&gt;calculates the factorial of that number.&lt;code&gt;&lt;br /&gt;&lt;br /&gt; public static void main(String args[]) {&lt;br /&gt;&lt;br /&gt;   int n;&lt;br /&gt;   int i;&lt;br /&gt;   long result;&lt;br /&gt;&lt;br /&gt;   for (i=1; i &lt;=10; i++)  {&lt;br /&gt;     result = factorial(i);&lt;br /&gt;     System.out.println(result);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt; } // main ends here&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; static long factorial (int n) {&lt;br /&gt;&lt;br /&gt; int i;&lt;br /&gt; long result=1;&lt;br /&gt;&lt;br /&gt; for (i=1; i &lt;= n; i++) {&lt;br /&gt;  result *= i;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; return result;&lt;br /&gt;&lt;br /&gt;} // factorial ends here&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;/code&gt;&lt;/span&gt;&lt;/pre&gt;         &lt;h4&gt;&lt;a name="xtocid1903615"&gt;Recursive Methods&lt;/a&gt;&lt;/h4&gt;         Recursion is used when a problem can be reduced into one or several         problems of the same nature, but a smaller size. This process is usually         repeated until a boundary situation is reached, where the problem can be         directly solved. Java supports recursive methods, i.e. even if you're         already inside methodA() you can call methodA().          &lt;p&gt;&lt;i&gt;Example  (A Recursive Counterpart of the Above Factorial Method)&lt;/i&gt;&lt;/p&gt;         &lt;p&gt;n! is defined as n times n-1 times n-2 times n-3 ... times 2 times 1         where n is a positive integer. 0! is defined as 1. As you see n! = n         time (n-1)!. This lends itself to recursive calculation, as in the         following method:&lt;/p&gt;         &lt;p&gt;&lt;code&gt;&lt;span style="font-family:Verdana;"&gt;public static long factorial (int n) {&lt;br /&gt;&lt;br /&gt;          if (n &lt; 0) {&lt;br /&gt;            return -1;&lt;br /&gt;          }&lt;br /&gt;          else if (n == 0) {&lt;br /&gt;            return 1;&lt;br /&gt;          }&lt;br /&gt;          else {&lt;br /&gt;            return n*factorial(n-1);&lt;br /&gt;          }&lt;br /&gt;       &lt;br /&gt;        }&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;    &lt;span&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt; &lt;script type="text/javascript"&gt;&lt;!-- google_ad_client = "pub-8082275437470616"; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_type = "text_image"; google_ad_channel =""; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "000000"; google_color_text = "000000"; google_color_url = "000000"; //--&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-8459161734516370397?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/8459161734516370397/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=8459161734516370397' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/8459161734516370397'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/8459161734516370397'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/methods-includes-recursive-methods.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-5538938534583121546</id><published>2008-06-11T10:13:00.000-07:00</published><updated>2008-06-11T10:15:49.812-07:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold;"&gt;Arrays:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Arrays are generally effective means of storing groups of variables. An array is a group of variables that share the same name and are ordered sequentially from zero to one less than the number of variables in the array. The number of variables that can be stored in an array is called the array's &lt;dfn&gt;dimension&lt;/dfn&gt;. Each variable in the array is called an &lt;dfn&gt;element&lt;/dfn&gt; of the array.&lt;br /&gt;&lt;br /&gt;Creating Arrays&lt;br /&gt;&lt;p&gt;There are three steps to creating an array, declaring it, allocating it and initializing it.&lt;br /&gt;&lt;br /&gt;                 &lt;u&gt;Declaring Arrays&lt;/u&gt;&lt;br /&gt;&lt;br /&gt;Like other variables in Java, an array must have a specific type like byte, int, String or double. Only variables of the appropriate type can be stored in an array. You cannot have an array that will store both ints and Strings, for instance.&lt;br /&gt;&lt;br /&gt;                 Like all other variables in Java an array must be declared. When you declare an array variable you suffix the type with &lt;code&gt;[]&lt;/code&gt; to         indicate that this variable is an array. Here are some examples:&lt;/p&gt;         &lt;p&gt;&lt;code&gt;int[] k;&lt;br /&gt;        float[] yt;&lt;br /&gt;        String[] names;&lt;br /&gt;        &lt;/code&gt;&lt;/p&gt; In other words you declare an array like you'd declare any other variable except you append brackets to the end of the variable type. &lt;p&gt;&lt;u&gt;Allocating Arrays&lt;/u&gt;&lt;/p&gt; Declaring an array merely says what it is. It does not create the array. To actually create the array (or any other object) use the new operator. When we create an array we need to tell the compiler how many elements will be stored in it. Here's how we'd create the variables declared above: &lt;code&gt;new&lt;/code&gt;         &lt;p&gt;&lt;code&gt;k = new int[3];&lt;br /&gt;        yt = new float[7];&lt;br /&gt;        names = new String[50];&lt;br /&gt;        &lt;/code&gt;&lt;/p&gt; The numbers in the brackets specify the dimension of the array; i.e. how many slots it has to hold values. With the dimensions above k can hold three ints, yt can hold seven floats and names can hold fifty Strings.  &lt;p&gt;&lt;u&gt;Initializing Arrays&lt;/u&gt;&lt;/p&gt; Individual elements of the array are referenced by the array name and by an integer which represents their position in the array. The numbers we use to identify them are called subscripts or indexes into the array. Subscripts are consecutive integers beginning with 0. Thus the array k above has elements k[0], k[1], and k[2]. Since we started counting at zero there is no k[3], and trying to access it will generate an ArrayIndexOutOfBoundsException. &lt;dfn&gt;subscripts&lt;/dfn&gt; &lt;dfn&gt;indexes&lt;/dfn&gt;         &lt;code&gt;k&lt;/code&gt; &lt;code&gt;k[0]&lt;/code&gt; &lt;code&gt;k[1]&lt;/code&gt; &lt;code&gt;k[2]&lt;/code&gt; &lt;code&gt;k[3]&lt;/code&gt;         &lt;code&gt;ArrayIndexOutOfBoundsException&lt;/code&gt;         &lt;p&gt;You can use array elements wherever you'd use a similarly typed variable that wasn't part of an array.&lt;/p&gt;         &lt;p&gt;Here's how we'd store values in the arrays we've been working with:&lt;/p&gt;         &lt;p&gt;&lt;code&gt;k[0] = 2;&lt;br /&gt;        k[1] = 5;&lt;br /&gt;        k[2] = -2;&lt;br /&gt;        yt[6] = 7.5f;&lt;br /&gt;        names[4] = "Fred";&lt;/code&gt;&lt;/p&gt;         &lt;p&gt;This step is called initializing the array or, more precisely, initializing the elements of the array. Sometimes the phrase         "initializing the array" would be reserved for when we initialize all the elements of the array.&lt;/p&gt;         &lt;p&gt;For even medium sized arrays, it's unwieldy to specify each element individually. It is often helpful to use &lt;code&gt;for&lt;/code&gt; loops to         initialize the array. For instance here is a loop that fills an array with the squares of the numbers from 0 to 100.&lt;/p&gt;         &lt;p&gt;&lt;code&gt;float[] squares = new float[101];&lt;br /&gt;       &lt;br /&gt;        for (int i=0; i &lt;= 500; i++) {&lt;br /&gt;          squares[i] = i*2;&lt;br /&gt;        }&lt;/code&gt;&lt;/p&gt;         &lt;p&gt;&lt;u&gt;Shortcuts&lt;/u&gt;&lt;/p&gt;         &lt;p&gt;We can declare and allocate an array at the same time like this:&lt;/p&gt;         &lt;p&gt;&lt;code&gt;int[] k = new int[3];&lt;br /&gt;        float[] yt = new float[7];&lt;br /&gt;        String[] names = new String[50];&lt;br /&gt;        &lt;/code&gt;&lt;/p&gt; We can even declare, allocate, and initialize an array at the same time providing a list of the initial values inside brackets like so: &lt;p&gt;&lt;code&gt;int[] k = {1, 2, 3};&lt;br /&gt;        float[] yt = {0.0f, 1.2f, 3.4f, -9.87f, 65.4f, 0.0f, 567.9f};&lt;br /&gt;        &lt;/code&gt;&lt;/p&gt;         &lt;p&gt;&lt;a name="xtocid459715"&gt;Two Dimensional Arrays&lt;/a&gt;&lt;/p&gt;         &lt;p&gt;Declaring, Allocating and Initializing Two Dimensional Arrays&lt;/p&gt; Two dimensional arrays are declared, allocated and initialized much like one dimensional arrays. However we have to specify two dimensions rather than one, and we typically use two nested for loops to fill the array. &lt;code&gt;for&lt;/code&gt;         &lt;p&gt;The array examples above are filled with the sum of their row and column indices. Here's some code that would create and fill such an array:&lt;/p&gt;         &lt;p&gt;&lt;code&gt;&lt;span style="font-family:Verdana;"&gt;class FillArray {&lt;br /&gt;       &lt;br /&gt;          public static void main (String args[]) {&lt;br /&gt;         &lt;br /&gt;            int[][] M;&lt;br /&gt;            M = new int[4][5];&lt;br /&gt;         &lt;br /&gt;            for (int row=0; row &lt; 4; row++) {&lt;br /&gt;              for (int col=0; col &lt; 5; col++) {&lt;br /&gt;                M[row][col] = row+col;&lt;br /&gt;              }&lt;br /&gt;            }&lt;br /&gt;           &lt;br /&gt;          }&lt;br /&gt;         &lt;br /&gt;        }&lt;/span&gt;&lt;/code&gt;&lt;/p&gt; In two-dimensional arrays ArrayIndexOutOfBounds errors occur whenever you exceed the maximum column index or row index. Unlike two-dimensional C arrays, two-dimensional Java arrays are not just one-dimensional arrays indexed in a funny way. &lt;p&gt;&lt;a name="xtocid2801933"&gt;Multidimensional Arrays&lt;/a&gt;&lt;/p&gt; You don't have to stop with two dimensional arrays. Java lets you have arrays of three, four or more dimensions. However chances are pretty good that if you need more than three dimensions in an array, you're probably using the wrong data structure. Even three dimensional arrays are exceptionally rare outside of scientific and engineering applications. &lt;p&gt;The syntax for three dimensional arrays is a direct extension of that for two-dimensional arrays. Here's a program that declares, allocates and initializes a three-dimensional array:&lt;/p&gt;         &lt;p&gt;&lt;code&gt;&lt;span style="font-family:Verdana;"&gt;class Fill3DArray {&lt;br /&gt;       &lt;br /&gt;          public static void main (String args[]) {&lt;br /&gt;         &lt;br /&gt;            int[][][] M;&lt;br /&gt;            M = new int[4][5][3];&lt;br /&gt;         &lt;br /&gt;            for (int row=0; row &lt; 4; row++) {&lt;br /&gt;              for (int col=0; col &lt; 5; col++) {&lt;br /&gt;                for (int ver=0; ver &lt; 3;         ver++) {&lt;br /&gt;                  M[row][col][ver]         = row+col+ver;&lt;br /&gt;                }&lt;br /&gt;              }&lt;br /&gt;            }&lt;br /&gt;           &lt;br /&gt;          }&lt;br /&gt;         &lt;br /&gt;        }&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;         &lt;p&gt;&lt;u&gt;Declaring and initializing 1-dimensional arrays&lt;/u&gt;&lt;br /&gt;       &lt;br /&gt;        An array groups elements of the same type. It makes it easy to manipulate the information contained in them.&lt;br /&gt;       &lt;br /&gt;        &lt;span style="font-family:Verdana;"&gt;class Arrays1{&lt;br /&gt;       &lt;br /&gt;        public static void main(String args[]){&lt;br /&gt;       &lt;br /&gt;        // this declares an array named x with the type "array of int"         and of&lt;br /&gt;        // size 10, meaning 10 elements, x[0], x[1] , ... , x[9] ; the first         term&lt;br /&gt;        // is x[0] and the last term x[9] NOT x[10].&lt;br /&gt;        int x[] = new int[10];&lt;br /&gt;       &lt;br /&gt;        // print out the values of x[i] and they are all equal to 0.&lt;br /&gt;        for(int i=0; i&lt;=9; i++)&lt;br /&gt;        System.out.println("x["+i+"] = "+x[i]);&lt;br /&gt;       &lt;br /&gt;        // assign values to x[i]&lt;br /&gt;        for(int i=0; i&lt;=9; i++)&lt;br /&gt;        x[i] = i; // for example&lt;br /&gt;       &lt;br /&gt;        // print the assigned values of x[i] : 1,2,......,9&lt;br /&gt;        for(int i=0; i&lt;=9; i++)&lt;br /&gt;        System.out.println("x["+i+"] = "+x[i]);&lt;br /&gt;       &lt;br /&gt;        // this declares an array named st the type "array of String"&lt;br /&gt;        // and initializes it&lt;br /&gt;        String st[]={"first","second","third"};&lt;br /&gt;       &lt;br /&gt;        // print out st[i]&lt;br /&gt;        for(int i=0; i&lt;=2; i++)&lt;br /&gt;        System.out.println("st["+i+"] = "+st[i]);&lt;br /&gt;       &lt;br /&gt;        }&lt;br /&gt;        }&lt;/span&gt;&lt;br /&gt;       &lt;br /&gt;&lt;u&gt;Find the sum of the numbers 2.5, 4.5, 8.9, 5.0 and 8.9&lt;/u&gt;&lt;br /&gt;       &lt;br /&gt;        &lt;span style="font-family:Verdana;"&gt;class Arrays2{&lt;br /&gt;       &lt;br /&gt;        public static void main(String args[]){&lt;br /&gt;       &lt;br /&gt;        // this declares an array named fl with the type "array of int"         and&lt;br /&gt;        // initialize its elements&lt;br /&gt;       &lt;br /&gt;        float fl[] = {2.5f, 4.5f, 8.9f, 5.0f, 8.9f};&lt;br /&gt;       &lt;br /&gt;        // find the sum by adding all elements of the array fl&lt;br /&gt;        float sum = 0.0f;&lt;br /&gt;        for(int i=0; i&lt;= 4; i++)&lt;br /&gt;        sum = sum + fl[i];&lt;br /&gt;       &lt;br /&gt;        // displays the sum&lt;br /&gt;        System.out.println("sum = "+sum);&lt;br /&gt;        }&lt;br /&gt;        }&lt;/span&gt;&lt;br /&gt;       &lt;br /&gt;        Check that the sum displayed is 29.8.&lt;br /&gt;       &lt;br /&gt;&lt;u&gt;Declaring and initializing 2-dimensional arrays&lt;/u&gt;&lt;br /&gt;       &lt;br /&gt;        &lt;span style="font-family:Verdana;"&gt;class Arrays3{&lt;br /&gt;       &lt;br /&gt;        public static void main(String args[]){&lt;br /&gt;       &lt;br /&gt;        // this declares a 2-dimensional array named x[i][j] of size 4 (4         elements)&lt;br /&gt;        // its elements are x[0][0], x[0][1], x[1][0] and x[1][1].&lt;br /&gt;        // the first index i indicates the row and the second index indicates         the&lt;br /&gt;        // column if you think of this array as a matrix.&lt;br /&gt;       &lt;br /&gt;       &lt;br /&gt;        int x[][] = new int[2][2];&lt;br /&gt;       &lt;br /&gt;        // print out the values of x[i][j] and they are all equal to 0.0.&lt;br /&gt;        for(int i=0; i&lt;=1; i++)&lt;br /&gt;        for(int j=0; j&lt;=1; j++)&lt;br /&gt;        System.out.println("x["+i+","+j+"] = "+x[i][j]);&lt;br /&gt;       &lt;br /&gt;        // assign values to x[i]&lt;br /&gt;        for(int i=0; i&lt;=1; i++)&lt;br /&gt;        for(int j=0; j&lt;=1; j++)&lt;br /&gt;        x[i][j] = i+j; // for example&lt;br /&gt;       &lt;br /&gt;        // print the assigned values to x[i][j]&lt;br /&gt;        for(int i=0; i&lt;=1; i++)&lt;br /&gt;        for(int j=0; j&lt;=1; j++)&lt;br /&gt;        System.out.println("x["+i+","+j+"] = "+x[i][j]);&lt;br /&gt;       &lt;br /&gt;        // this declares a 2-dimensional array of type String&lt;br /&gt;        // and initializes it&lt;br /&gt;        String st[][]={{"row 0 column 0","row 0 column 1"},         // first row&lt;br /&gt;        {"row 1 column 0","row 1 column 1"}}; // second row&lt;br /&gt;       &lt;br /&gt;        // print out st[i]&lt;br /&gt;        for(int i=0; i&lt;=1; i++)&lt;br /&gt;        for(int j=0; j&lt;=1; j++)&lt;br /&gt;        System.out.println("st["+i+","+j+"] = "+st[i][j]);&lt;br /&gt;       &lt;br /&gt;        }&lt;br /&gt;        }&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-5538938534583121546?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/5538938534583121546/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=5538938534583121546' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/5538938534583121546'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/5538938534583121546'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/arrays-arrays-are-generally-effective.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-3631864252140482061</id><published>2008-06-11T10:08:00.000-07:00</published><updated>2008-06-11T10:13:20.867-07:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold;"&gt;Classes and Objects:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Following the principles of &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Object Oriented Programming(OOP), everything in Java is either a class, a part of a class, or describes how a class behaves. Objects are the physical instantiations of classes. They are living entities within a program that have independent lifecycles and that are created according to the class that describes them. Just as many buildings can be built from one blueprint, many objects can be instantiated from one class. Many objects of different classes can be created, used, and destroyed in the course of executing a program. Programming languages provide a number of simple data types like int, float and String. However very often the data you want to work with may not be simple ints, floats or Strings. Classes let programmers define their own more complicated data types.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;All the action in Java programs takes place inside class blocks, in this case the HelloWorld class. In Java almost everything of interest is either a class itself or belongs to a class. Methods are defined inside the classes they belong to. Even basic data primitives like integers often need to be incorporated into classes before you can do many useful things with them. The class is the fundamental unit of Java programs. For instance consider the following Java program:&lt;br /&gt;&lt;p&gt;&lt;br /&gt;         &lt;code&gt;&lt;span style="font-family:Verdana;"&gt;class HelloWorld {&lt;br /&gt;&lt;br /&gt;                   public static void main (String args[]) {&lt;br /&gt;&lt;br /&gt;                     System.out.println("Hello World");&lt;br /&gt;&lt;br /&gt;                   }&lt;br /&gt;       &lt;br /&gt;        }&lt;br /&gt;       &lt;br /&gt;        class GoodbyeWorld {&lt;br /&gt;       &lt;br /&gt;          public static void main (String args[]) {&lt;br /&gt;       &lt;br /&gt;            System.out.println("Goodbye Cruel World!");&lt;br /&gt;       &lt;br /&gt;          }&lt;br /&gt;       &lt;br /&gt;        }&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Save this code in a single file called hellogoodbye.java in your javahtml directory, and compile it with the command javac hellogoodbye.java. Then list the contents of the directory. You will see that the compiler has produced two separate class files, HelloWorld.class and GoodbyeWorld.class. &lt;kbd&gt;javac hellogoodbye.java&lt;/kbd&gt;         &lt;/p&gt;&lt;p&gt;The second class is a completely independent program. Type &lt;kbd&gt;java GoodbyeWorld&lt;/kbd&gt; and then type &lt;kbd&gt;java HelloWorld&lt;/kbd&gt;. These programs run and execute         independently of each other although they exist in the same source code file. &lt;/p&gt;         &lt;p&gt;&lt;u&gt;Class Syntax&lt;/u&gt;&lt;/p&gt;         &lt;p&gt;Use the following syntax to declare a class in Java:&lt;br /&gt;       &lt;br /&gt;        //Contents of SomeClassName.java&lt;br /&gt;        [ public ] [ ( abstract | final ) ] class SomeClassName [ extends         SomeParentClass ] [ implements SomeInterfaces ]&lt;br /&gt;        {&lt;br /&gt;                // variables and methods are         declared within the curly braces&lt;br /&gt;        }&lt;br /&gt;       &lt;br /&gt;        * A class can have public or default (no modifier) visibility.&lt;br /&gt;        * It can be either abstract, final or concrete (no modifier).&lt;br /&gt;        * It must have the class keyword, and class must be followed by a legal         identifier.&lt;br /&gt;        * It may optionally extend one parent class. By default, it will extend         java.lang.Object.&lt;br /&gt;        * It may optionally implement any number of comma-separated interfaces.&lt;br /&gt;        * The class's variables and methods are declared within a set of curly         braces '{}'.&lt;br /&gt;        * Each .java source file may contain only one public class. A source         file may contain any number of default visible classes.&lt;br /&gt;        * Finally, the source file name must match the public class name and it         must have a .java suffix.&lt;br /&gt;       &lt;br /&gt;        Here is an example of a Horse class. Horse is a subclass of Mammal, and         it implements the Hoofed interface.&lt;br /&gt;       &lt;br /&gt;        public class Horse extends Mammal implements Hoofed&lt;br /&gt;        {&lt;br /&gt;                 //Horse's variables and         methods go here&lt;br /&gt;        }&lt;/p&gt;         &lt;p&gt;Lets take one more example of Why use Classes and Objects. For         instance let's suppose your program needs to keep a database of web         sites. For each site you have a name, a URL, and a description. &lt;/p&gt;         &lt;pre&gt;&lt;code&gt;class website {&lt;br /&gt;&lt;br /&gt; String name;&lt;br /&gt; String url;&lt;br /&gt; String description;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;         These variables (name, url and description) are called the members of         the class. They tell you what a class is and what its properties are.         They are the nouns of the class. &lt;dfn&gt;members. &lt;/dfn&gt;A class defines         what an object is, but it is not itself an object. An object is a         specific &lt;dfn&gt;instance&lt;/dfn&gt; of a class. Thus when we create a new         object we say we are &lt;dfn&gt;instantiating&lt;/dfn&gt; the object. Each class         exists only once in a program, but there can be many thousands of         objects that are instances of that class.         &lt;p&gt;To instantiate an object in Java we use the &lt;code&gt;new&lt;/code&gt;         operator. Here's how we'd create a new web site:&lt;/p&gt;         &lt;pre&gt;&lt;code&gt;    website x = new website();&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;         Once we've got a website we want to know something about it. To get at         the member variables of the website we can use the . operator. Website         has three member variables, name, url and description, so x has three         member variables as well, x.name, x.url and x.description. We can use         these just like we'd use any other String variables. For instance:&lt;br /&gt; &lt;p&gt;&lt;code&gt;    website x = new website();  &lt;br /&gt;            x.name = "freehavaguide.com";&lt;br /&gt;            x.url = "http://www.freejavaguide.com";&lt;br /&gt;            x.description = "A Java Programming         Website";&lt;br /&gt;           &lt;br /&gt;            System.out.println(x.name + " at " + x.url         + " is " + x.description);&lt;/code&gt;&lt;/p&gt;         &lt;span style="font-size:85%;"&gt;         &lt;p&gt;&lt;br /&gt;&lt;/p&gt;         &lt;/span&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;p align="center"&gt;Class Declaration&lt;/p&gt;&lt;/b&gt;&lt;/div&gt;         &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;i&gt;A simple Java class declaration with constructor declaration:&lt;/i&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:100%;"&gt;class simple {&lt;br /&gt;// Constructor&lt;br /&gt; simple(){&lt;br /&gt; p = 1;&lt;br /&gt; q = 2;&lt;br /&gt; r = 3;&lt;br /&gt;}&lt;br /&gt;int p,q,r;&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:100%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;i&gt;In class declaration, you can declare methods of the class:&lt;/i&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:100%;"&gt;        &lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:100%;"&gt;class simple {&lt;br /&gt;// Constructor&lt;br /&gt; simple(){&lt;br /&gt;  p = 1;&lt;br /&gt;  q = 2;&lt;br /&gt;  r = 3;&lt;br /&gt; }&lt;br /&gt; int p,q,r;&lt;br /&gt; public int addNumbers(int var1, int var2, int var3)&lt;br /&gt; {&lt;br /&gt;   return var1 + var2 + var3;&lt;br /&gt; }&lt;br /&gt; public void displayMessage()&lt;br /&gt; {&lt;br /&gt;  System.out.println("Display Message");&lt;br /&gt; }&lt;br /&gt;}&lt;i&gt;&lt;br /&gt;&lt;br /&gt;To invoke the class, you can create the new instance of the class:&lt;/i&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:100%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;// To create a new instance class&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:100%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;Simple sim = &lt;b&gt;new &lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;Simple();&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:100%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;// To access the methods of the class&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:100%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;sim.addNumbers(5,1,2)&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:100%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;// To show the result of the addNumbers&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:100%;"&gt;        &lt;b&gt;         &lt;/b&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;System.out.println&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;("The         result is " + Integer.toString(addNumbers(5,1,2)));&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:100%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;i&gt;The complete listing of class declaration:&lt;/i&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:100%;"&gt;        &lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:100%;"&gt;class simple {&lt;br /&gt;// Constructor&lt;br /&gt; simple(){&lt;br /&gt;  p = 1;&lt;br /&gt;  q = 2;&lt;br /&gt;  r = 3;&lt;br /&gt; }&lt;br /&gt; int p,q,r;&lt;br /&gt; public int addNumbers(int var1, int var2, int var3)&lt;br /&gt; {&lt;br /&gt;  return var1 + var2 + var3;&lt;br /&gt; }&lt;br /&gt; public void displayMessage()&lt;br /&gt; {&lt;br /&gt;  System.out.println("Display Message");&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class example1{&lt;br /&gt; public static void main(String args[])&lt;br /&gt; {&lt;br /&gt;  // To create a new instance class&lt;br /&gt;  Simple sim = new Simple();&lt;br /&gt;  // To show the result of the addNumbers&lt;br /&gt;  System.out.println("The result is " + Integer.toString(addNumbers(5,1,2)));&lt;br /&gt;  // To display message&lt;br /&gt;  sim.displayMessage();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-3631864252140482061?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/3631864252140482061/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=3631864252140482061' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/3631864252140482061'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/3631864252140482061'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/classes-and-objects-following.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-461091471520606128</id><published>2008-06-11T10:06:00.000-07:00</published><updated>2008-06-11T10:08:20.890-07:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold;"&gt;Interfaces:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style="text-align: justify;"&gt;There is one thing in Java source code that is neither a class nor a member of a class. That's an interface. An interface defines methods that a class implements. In other words it declares what certain classes do. However an interface itself does nothing. All the action at least, happens inside classes. &lt;dfn&gt;A class may implement one or more interfaces. This means that the class subscribes to the promises made by those interfaces. Since an interface promises certain methods, a class implementing that interface will need to provide the methods specified by the interface. The methods of an interface are abstract -- they have no bodies. Generally, a class implementing an interface will not only match the method specifications of the interface, it will also provide bodies -- implementations -- for its methods.&lt;br /&gt;&lt;/dfn&gt;&lt;br /&gt;For example, a ScoreCounter class might meet the contract specified by the Counting interface:&lt;br /&gt;&lt;p&gt;interface Counting&lt;br /&gt;        {&lt;br /&gt;        abstract void increment();&lt;br /&gt;        abstract int getValue();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;So might a Stopwatch, although it might have a totally different internal representation. Both would have increment() and getValue() methods, but the bodies of these methods might look quite different. For example, a ScoreCounter for a basketball game might implement increment() so that it counts by 2 points each time, while a Stopwatch might call its own increment() method even if no one else does.&lt;br /&gt;&lt;br /&gt;                 A class that implements a particular interface must declare this explicitly:&lt;br /&gt;&lt;br /&gt;                 class ScoreCounter implements Counting {&lt;br /&gt;        ....&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;If a class implements an interface, an instance of that class can also be treated as though its type were that interface. For example, it can be labeled with a name whose declared type is that interface. For example, an instance of class ScoreCounter can be labeled with a name of type Counting. It will also answer true when asked whether it's an instanceof that interface type: if myScoreCounter is a ScoreCounter, then myScoreCounter instanceof Counting is true. Similarly, you can pass or return a ScoreCounter whenever a Counting is required by a method signature.&lt;br /&gt;&lt;br /&gt;The generality of interfaces and the inclusion of multiple implementations within a single (interface) type is an extremely powerful feature. For example, you can use a name of type Counting to label either an instance of ScoreCOunter or an instance of Stopwatch (and use its increment() and getValue() methods) without even knowing which one you've got.&lt;/p&gt;&lt;hr /&gt;    &lt;span&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-461091471520606128?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/461091471520606128/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=461091471520606128' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/461091471520606128'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/461091471520606128'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/interfaces-there-is-one-thing-in-java.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-9129144795674391957</id><published>2008-06-11T09:57:00.000-07:00</published><updated>2008-06-11T10:04:02.621-07:00</updated><title type='text'></title><content type='html'>&lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-weight: bold;"&gt;Catching Exceptions:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;          An exception is a point in the code where something out of the ordinary has happened and the regular flow of the program needs to be interrupted; an exception is not necessarily an error. A method which has run into such a case will throw an exception using the throw(ExceptionClass) method. When an exception is thrown it must be caught by a catch statement that should sit right after a try statement.&lt;/p&gt;// This is the Hello program in Java&lt;br /&gt;&lt;p&gt;&lt;code&gt;&lt;span style="font-family:Verdana;"&gt;         class Hello {&lt;br /&gt;&lt;br /&gt;         public static void main (String args[]) {&lt;br /&gt;     &lt;br /&gt;           /* Now let's say hello */&lt;br /&gt;           System.out.print("Hello ");&lt;br /&gt;           System.out.println(args[0]);&lt;br /&gt;       }&lt;br /&gt; &lt;br /&gt;     }&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;         If you run the program without giving it any command line arguments,         then the  runtime system generates an exception something like,         &lt;p&gt;&lt;tt&gt;Exception in thread "main"         java.lang.ArrayIndexOutOfBoundsException at Hello.main(C:\javahtml\Hello.java:7)&lt;/tt&gt;&lt;/p&gt;         &lt;p&gt;Since we didn't give Hello any command line arguments there wasn't         anything in &lt;code&gt;args[0]&lt;/code&gt;. Therefore Java kicked back this not         too friendly error message about an "ArrayIndexOutOfBoundsException."&lt;/p&gt;         &lt;p&gt;we can fix this problem by testing the length of the array before we         try to access its first element (using array.length). This works well in         this simple case, but this is far from the only such potential problem. &lt;/p&gt;         &lt;p&gt;&lt;b&gt;What is an Exception ?&lt;br /&gt;     &lt;/b&gt;&lt;br /&gt;     Let us see what happens when an exception occurs and is not handled         properly&lt;br /&gt; &lt;br /&gt;     When you compile and run the following program&lt;br /&gt; &lt;br /&gt;     public class Test{&lt;br /&gt;         public static void main(String str[]){&lt;br /&gt;         int y = 0;&lt;br /&gt;         int x = 1;&lt;br /&gt;         // a division by 0 occurs here.&lt;br /&gt;         int z = x/y;&lt;br /&gt;         System.out.println("after didvision");&lt;br /&gt;       }&lt;br /&gt;     }&lt;br /&gt; &lt;br /&gt;     The execution of the Test stops and this is caused by the &lt;u&gt;division by         zero&lt;/u&gt; at - x/y - an exception has been thrown but has not been         handled properly.&lt;br /&gt; &lt;br /&gt;     &lt;b&gt;How to handle an Exception ?&lt;br /&gt;     &lt;/b&gt;&lt;br /&gt;     To handle an Exception, enclose the code that is likely to throw an         exception in a &lt;u&gt;try block &lt;/u&gt;and follow it immediately by a catch         clause as follows&lt;br /&gt;&lt;br /&gt;              public class Test{&lt;br /&gt;         public static void main(String str[]){&lt;br /&gt;             int y = 0;&lt;br /&gt;             int x = 1;&lt;br /&gt;             // try block to         "SEE" if an exception occurs&lt;br /&gt;             try{&lt;br /&gt;               int z = x/y;&lt;br /&gt;                       System.out.println("after didvision");&lt;br /&gt;                // catch         clause below handles the&lt;br /&gt;               //         ArithmeticException generated by&lt;br /&gt;               // the division         by zero.&lt;br /&gt;            } catch (ArithmeticException ae)&lt;br /&gt;            {System.out.println(" attempt         to divide by 0");}&lt;br /&gt;            System.out.println(" after         catch ");&lt;br /&gt;        }&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;              The output of the above program is as follows&lt;br /&gt;&lt;br /&gt;              attempt to divide by 0&lt;br /&gt;     after catch&lt;br /&gt;&lt;br /&gt;              the statement - System.out.println("after didvision") - is NOT         executed, once an exception is thrown, the program control moves out of         the try block into the catch block.&lt;/p&gt;         &lt;p&gt;The goal of exception handling is to be able to define the regular         flow of the program in part of the code without worrying about all the         special cases. Then, in a separate block of code, you cover the         exceptional cases. This produces more legible code since you don't need         to interrupt the flow of the algorithm to check and respond to every         possible strange condition. The runtime environment is responsible for         moving from the regular program flow to the exception handlers when an         exceptional condition arises.&lt;/p&gt;         &lt;p&gt;In practice what you do is write blocks of code that may generate         exceptions inside try-catch blocks. You try the statements that generate         the exceptions. Within your try block you are free to act as if nothing         has or can go wrong. Then, within one or more catch blocks, you write         the program logic that deals with all the special cases.&lt;/p&gt;         &lt;p&gt;To start a section of code which might fail or not follow through you         start a try clause:&lt;/p&gt;         &lt;p&gt;&lt;small&gt;try&lt;br /&gt;     {&lt;br /&gt;       // Section of code which might fail&lt;br /&gt;     }&lt;/small&gt;&lt;/p&gt;         &lt;p&gt;The try statement is needed in case of an exception. If the read         fails in some way it will throw an exception of type java.io.IOException.         That exception must be caught in this method, or the method can declare         that it will continue throwing that message. Exception handling is a         very powerful tool, you can use it to catch and throw exceptions and         thus group all your error handling code very well and make it much more         readable in larger more complex applications. After the try section         there must exist one or more catch statements to catch some or all of         the exceptions that can happen within the try block. Exceptions that are         not caught will be passed up to the next level, such as the function         that called the one which threw the exception, and so on. .&lt;/p&gt;         &lt;p&gt;&lt;small&gt;try&lt;br /&gt;     {&lt;br /&gt;       // Section of code which might fail&lt;br /&gt;     }&lt;br /&gt;     catch (Exception1ThatCanHappen E)&lt;br /&gt;     {&lt;br /&gt;       // things to do if this exception was thrown..&lt;br /&gt;     }&lt;br /&gt;     catch (Exception2ThatCanHappen E)&lt;br /&gt;     {&lt;br /&gt;       // things to do if this exception was thrown..&lt;br /&gt;     }&lt;/small&gt;&lt;/p&gt;         &lt;p&gt;Here's an example of exception handling in Java using the Hello World         program above:&lt;/p&gt;         &lt;p&gt;&lt;u&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Source Code&lt;/span&gt;&lt;/u&gt;&lt;/p&gt;         &lt;p&gt;&lt;code&gt;&lt;span style="font-family:Verdana;"&gt;// This is the Hello program in Java&lt;br /&gt;     class ExceptionalHello {&lt;br /&gt; &lt;br /&gt;         public static void main (String args[]) {&lt;br /&gt;     &lt;br /&gt;           /* Now let's say hello */&lt;br /&gt;           try {&lt;br /&gt;                     System.out.println("Hello " + args[0]);&lt;br /&gt;           }&lt;br /&gt;           catch (Exception e) {&lt;br /&gt;                     System.out.println("Hello whoever you are");  &lt;br /&gt;           }&lt;br /&gt;       }&lt;br /&gt; &lt;br /&gt;     }&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;         &lt;p&gt;You may or may not print an error message. If you write an exception         handler and you don't expect it to be called, then by all means put a&lt;/p&gt;         &lt;p&gt;&lt;code&gt;System.out.println("Error: " + e);&lt;/code&gt;&lt;/p&gt;         &lt;p&gt;This has the folowing advantages over handling your errors         internally:&lt;/p&gt;         &lt;ul&gt;&lt;li&gt;You can react to an error in custom defined way. A read error does             not mean that the program should crash.           &lt;/li&gt;&lt;li&gt;You can write code with no worry about failure which will be             handled by the users of your class.           &lt;/li&gt;&lt;li&gt;You can group your error handling code much better.           &lt;/li&gt;&lt;li&gt;You can make your application more transactional focused with             nested try catch blocks:&lt;/li&gt;&lt;/ul&gt;         &lt;p&gt;&lt;u&gt;A simple Java code which demonstrates the exception handling in         Java&lt;/u&gt;         &lt;/p&gt;&lt;p&gt;&lt;i&gt;Refer to the java API document to see all exception types that can         be handled in Java.&lt;/i&gt;         &lt;/p&gt;&lt;p&gt;&lt;u&gt;Source Code&lt;/u&gt;         &lt;/p&gt;&lt;pre&gt;public class excep2&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;int i =0 ;&lt;br /&gt;//Declare an array of strings&lt;br /&gt;String Box [] = {"Book", "Pen", "Pencil"};&lt;br /&gt;while(i&lt;4)&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;!-- google_ad_client = "pub-8082275437470616"; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_type = "text"; google_ad_channel =""; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "000000"; google_color_text = "000000"; google_color_url = "000000"; //--&gt;&lt;/script&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-9129144795674391957?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/9129144795674391957/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=9129144795674391957' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/9129144795674391957'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/9129144795674391957'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/catching-exceptions-exception-is-point.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-6928094634312044106</id><published>2008-06-11T09:54:00.000-07:00</published><updated>2008-06-11T09:56:56.067-07:00</updated><title type='text'></title><content type='html'>&lt;div style="text-align: left; color: rgb(0, 0, 0);"&gt;&lt;b&gt;File I/O and Streams:&lt;/b&gt;&lt;/div&gt; &lt;p&gt;           You can write data to a file instead of the computer screen. You can write certain data to a file while still putting other data on the screen. Or you may need access to multiple files simultaneously. Or you may want to query the user for input rather than accepting it all on the command line. Or maybe you want to read data out of a file that's in a particular format. In Java all these methods take place as streams. &lt;kbd&gt;&lt;&lt;/kbd&gt;         &lt;kbd&gt;&gt;&lt;/kbd&gt; Using File I/O &lt;dfn&gt;streams.&lt;/dfn&gt; The &lt;code&gt;System.out.println()&lt;/code&gt; statement we've been using all along is an implementation of Streams.&lt;/p&gt;&lt;p&gt;&lt;u&gt;&lt;i&gt;A program that writes a string to a file&lt;/i&gt;&lt;/u&gt;&lt;/p&gt;         &lt;p&gt;In order to use the Java file classes, we must import the Java         input/output package (java.io) in the following manner&lt;br /&gt;&lt;br /&gt;                 import java.io.*;&lt;br /&gt;&lt;br /&gt;                 Inside the main method of our program, we must declare a         FileOutputStream object. In this case, we wish to write a string to the         file, and so we create a new PrintStream object that takes as its         constructor the existing FileOutputStream. Any data we send from         PrintStream will now be passed to the FileOutputStream, and ultimately         to disk. We then make a call to the println method, passing it a string,         and then close the connection.&lt;/p&gt;         &lt;p&gt;&lt;u&gt;Source Code&lt;/u&gt;&lt;/p&gt;         &lt;p&gt;&lt;span style="font-family:Verdana;"&gt;/*&lt;br /&gt;        * FileOutput&lt;br /&gt;        * Demonstration of FileOutputStream and PrintStream classes&lt;br /&gt;        */&lt;br /&gt;       &lt;br /&gt;        import java.io.*;&lt;br /&gt;       &lt;br /&gt;        class FileOutput&lt;br /&gt;        {&lt;br /&gt;       &lt;br /&gt;        public static void main(String args[])&lt;br /&gt;        {&lt;br /&gt;        FileOutputStream out; // declare a file output object&lt;br /&gt;        PrintStream p; // declare a print stream object&lt;br /&gt;       &lt;br /&gt;        try&lt;br /&gt;        {&lt;br /&gt;        // Create a new file output stream connected to "myfile.txt"&lt;br /&gt;        out = new FileOutputStream("myfile.txt");&lt;br /&gt;       &lt;br /&gt;        // Connect print stream to the output stream&lt;br /&gt;        p = new PrintStream( out );&lt;br /&gt;       &lt;br /&gt;        p.println ("This is written to a file myFile.txt");&lt;br /&gt;       &lt;br /&gt;        p.close();&lt;br /&gt;        }&lt;br /&gt;        catch (Exception e)&lt;br /&gt;        {&lt;br /&gt;        System.err.println ("Error writing to the file myFile.txt");&lt;br /&gt;        }&lt;br /&gt;        }&lt;br /&gt;        }&lt;/span&gt;&lt;/p&gt;         &lt;p&gt;&lt;a name="xtocid69323"&gt;Interactively communicating with the user&lt;/a&gt;&lt;/p&gt;         &lt;i&gt;Program asking  the user for their name and then prints a         personalized greeting.&lt;/i&gt;         &lt;p&gt;&lt;span style="color:#000000;"&gt;&lt;u&gt;Source Code&lt;/u&gt;&lt;/span&gt;&lt;/p&gt;         &lt;p&gt;&lt;code&gt;&lt;span style="font-family:Verdana;"&gt;import java.io.*;&lt;br /&gt;       &lt;br /&gt;        class PersonalHello {&lt;br /&gt;       &lt;br /&gt;          public static void main (String args[])&lt;br /&gt;            {&lt;br /&gt;           &lt;br /&gt;              byte name[] = new byte[100];&lt;br /&gt;              int nr_read = 0;&lt;br /&gt;       &lt;br /&gt;              System.out.println("Your name         Please?");&lt;br /&gt;              try {&lt;br /&gt;                nr_read = System.in.read(name);&lt;br /&gt;                System.out.print("Hello         ");&lt;br /&gt;                        System.out.write(name,0,nr_read);&lt;br /&gt;              }&lt;br /&gt;              catch (IOException e) {&lt;br /&gt;                System.out.print("I did         not get your name.");&lt;br /&gt;              }&lt;br /&gt;             &lt;br /&gt;            }&lt;br /&gt;           &lt;br /&gt;        }&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;         In code that does any significant input or output you'll want to begin         by importing all the various java.io classes. import.java.io.*; Most of         the reading and writing you do in Java will be done with bytes. Here         we've started with an array of bytes that will hold the user's name.         &lt;p&gt;First we print a query requesting the user's name. Then we read the         user's name using the &lt;code&gt;System.in.read()&lt;/code&gt; method. This method         takes a byte array as an argument, and places whatever the user types in         that byte array. Then, like before, we print "Hello." Finally         we print the user's name.&lt;/p&gt;         &lt;p&gt;The program doesn't actually see what the user types until he or she         types a carriage return. This gives the user the chance to backspace         over and delete any mistakes. Once the return key is pressed, everything         in the line is placed in the array.&lt;/p&gt;         &lt;p style="font-weight: bold;"&gt;&lt;a name="xtocid181431"&gt;Reading Numbers&lt;/a&gt;&lt;/p&gt;         Often strings aren't enough. A lot of times you'll want to ask the user         for a number as input. All user input comes in as strings so we need to         convert the string into a number.         &lt;p&gt;The &lt;code&gt;getNextInteger()&lt;/code&gt; method that will accept an integer         from the user. Here it is:&lt;/p&gt;         &lt;p&gt;&lt;code&gt;  static int getNextInteger() {&lt;br /&gt;         &lt;br /&gt;            String line;&lt;br /&gt;         &lt;br /&gt;            DataInputStream in = new DataInputStream(System.in);&lt;br /&gt;            try {&lt;br /&gt;              line = in.readLine();&lt;br /&gt;              int i = Integer.valueOf(line).intValue();&lt;br /&gt;              return i;&lt;br /&gt;            }&lt;br /&gt;            catch (Exception e) {&lt;br /&gt;              return -1;&lt;br /&gt;            }&lt;br /&gt;              &lt;br /&gt;          } // getNextInteger ends here&lt;/code&gt;&lt;/p&gt;         &lt;p style="font-weight: bold;"&gt;&lt;a name="xtocid181432"&gt;Reading Formatted Data&lt;/a&gt;&lt;/p&gt;         It's often the case that you want to read not just one number but         multiple numbers. Sometimes you may need to read text and numbers on the         same line. For this purpose Java provides the StreamTokenizer class.         &lt;p style="font-weight: bold;"&gt;&lt;a name="xtocid69324"&gt;Writing a text file&lt;/a&gt;&lt;/p&gt;         Sometimes you want to save your output in a  file. To do this we'll         need to learn how to write data to a file.          &lt;p&gt;&lt;u&gt;&lt;span style="color:#000000;"&gt;Source Code&lt;/span&gt;&lt;/u&gt;&lt;/p&gt;         &lt;p&gt;&lt;code&gt;&lt;span style="font-family:Verdana;"&gt;// Write the Fahrenheit to Celsius table         in a file&lt;br /&gt;       &lt;br /&gt;        import java.io.*;&lt;br /&gt;       &lt;br /&gt;        class FahrToCelsius  {&lt;br /&gt;       &lt;br /&gt;          public static void main (String args[]) {&lt;br /&gt;       &lt;br /&gt;            double fahr, celsius;&lt;br /&gt;            double lower, upper, step;&lt;br /&gt;       &lt;br /&gt;            lower = 0.0;    // lower limit of         temperature table&lt;br /&gt;            upper = 300.0;  // upper limit of temperature         table&lt;br /&gt;            step  = 20.0;   // step size&lt;br /&gt;       &lt;br /&gt;            fahr = lower;&lt;br /&gt;         &lt;br /&gt;            try {&lt;br /&gt;       &lt;br /&gt;              FileOutputStream fout =  new         FileOutputStream("test.out");&lt;br /&gt;       &lt;br /&gt;              // now to the FileOutputStream into a         PrintStream&lt;br /&gt;              PrintStream myOutput = new         PrintStream(fout);&lt;br /&gt;         &lt;br /&gt;              while (fahr &lt;= upper) {  // while         loop begins here&lt;br /&gt;                celsius = 5.0 * (fahr-32.0) /         9.0;&lt;br /&gt;                myOutput.println(fahr +         " " + celsius);&lt;br /&gt;                fahr = fahr + step;&lt;br /&gt;              } // while loop ends here&lt;br /&gt;         &lt;br /&gt;            }  // try ends here&lt;br /&gt;            catch (IOException e) {&lt;br /&gt;              System.out.println("Error: " +         e);&lt;br /&gt;              System.exit(1);&lt;br /&gt;            }&lt;br /&gt;         &lt;br /&gt;          } // main ends here&lt;br /&gt;       &lt;br /&gt;        }&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;         There are only three things necessary to write formatted output to a         file rather than to the standard output:         &lt;ol&gt;&lt;li&gt;Open a &lt;dfn&gt;FileOutputStream&lt;/dfn&gt; using a line like             &lt;p&gt;&lt;code&gt;FileOutputStream fout =  new             FileOutputStream("test.out");&lt;/code&gt;&lt;/p&gt;             This line initializes the FileOutputStream with the name of the file             you want to write into.           &lt;/li&gt;&lt;li&gt;Convert the FileOutputStream into a &lt;dfn&gt;PrintStream&lt;/dfn&gt; using a             statement like             &lt;p&gt;&lt;code&gt;PrintStream myOutput = new PrintStream(fout);&lt;/code&gt;&lt;/p&gt;             &lt;p&gt;The PrintStream is passed the FileOutputStream from step 1.           &lt;/p&gt;&lt;/li&gt;&lt;li&gt;Instead of using &lt;code&gt;System.out.println()&lt;/code&gt; use &lt;code&gt;myOutput.println()&lt;/code&gt;.             &lt;code&gt;System.out&lt;/code&gt; and &lt;code&gt;myOutput&lt;/code&gt; are just different             instances of the &lt;code&gt;PrintStream&lt;/code&gt; class. To print to a             different &lt;code&gt;PrintStream&lt;/code&gt; we keep the syntax the same but             change the name of the &lt;code&gt;PrintStream&lt;/code&gt;.&lt;/li&gt;&lt;/ol&gt;         &lt;p style="font-weight: bold;"&gt;&lt;a name="xtocid69325"&gt;Reading a text file:&lt;/a&gt;&lt;/p&gt;         Now that we know how to write a text file, let's try reading one. The         following code accepts a series of file names on the command line and         then prints those filenames to the standard output in the order they         were listed.         &lt;p&gt;&lt;code&gt;&lt;span style="font-family:Verdana;"&gt;// Imitate the Unix cat utility&lt;br /&gt;       &lt;br /&gt;        import java.io.*;&lt;br /&gt;       &lt;br /&gt;        class cat  {&lt;br /&gt;       &lt;br /&gt;          public static void main (String args[]) {&lt;br /&gt;         &lt;br /&gt;          String thisLine;&lt;br /&gt;       &lt;br /&gt;          //Loop across the arguments&lt;br /&gt;          for (int i=0; i &lt; args.length; i++) {&lt;br /&gt;        &lt;br /&gt;          //Open the file for reading&lt;br /&gt;          try {&lt;br /&gt;            FileInputStream fin =  new         FileInputStream(args[i]);&lt;br /&gt;       &lt;br /&gt;            // now turn the FileInputStream into a         DataInputStream&lt;br /&gt;            try {&lt;br /&gt;              DataInputStream myInput = new         DataInputStream(fin);&lt;br /&gt;         &lt;br /&gt;              try {&lt;br /&gt;                while ((thisLine =         myInput.readLine()) != null) {  // while loop begins here&lt;br /&gt;                          System.out.println(thisLine);&lt;br /&gt;                } // while loop ends here&lt;br /&gt;              }&lt;br /&gt;              catch (Exception e) {&lt;br /&gt;               System.out.println("Error:         " + e);&lt;br /&gt;              }&lt;br /&gt;            } // end try&lt;br /&gt;            catch (Exception e) {&lt;br /&gt;              System.out.println("Error: " +         e);&lt;br /&gt;            }&lt;br /&gt;         &lt;br /&gt;           } // end try&lt;br /&gt;           catch (Exception e) {&lt;br /&gt;            System.out.println("failed to open file " +         args[i]);&lt;br /&gt;            System.out.println("Error: " + e);&lt;br /&gt;          }&lt;br /&gt;          } // for end here&lt;br /&gt;         &lt;br /&gt;          } // main ends here&lt;br /&gt;       &lt;br /&gt;        }&lt;/span&gt;&lt;/code&gt;                   &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-6928094634312044106?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/6928094634312044106/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=6928094634312044106' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/6928094634312044106'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/6928094634312044106'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/file-io-and-streams-you-can-write-data.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-5377617428569654622</id><published>2008-06-11T09:52:00.000-07:00</published><updated>2008-06-11T10:05:58.345-07:00</updated><title type='text'></title><content type='html'>&lt;div style="text-align: left;"&gt;&lt;span style="font-weight: bold;"&gt;To make executable jar files in JDK1.3.1?:&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;u&gt;&lt;br /&gt;Instructions for creating an Executable .jar file:&lt;br /&gt;&lt;/u&gt;&lt;br /&gt;Make or modify the Manifest.MF to YourManifest.MF.&lt;br /&gt;&lt;p&gt;   1) YourClassNameWithMain is the class name (case sensitive) without         .class extension&lt;br /&gt;     2) No extra spaces following the YourClassName withMain.&lt;br /&gt; &lt;br /&gt;     Manifest-Version:1.0&lt;br /&gt;     Main-Class: YourClassNameWithMain&lt;br /&gt;     Created-by:1.2(Sun Microsystems Inc.)&lt;br /&gt;     On Command line : type the following&lt;br /&gt;     jar cvfm YourJarFileName.jar YourManifest.MF*&lt;br /&gt;&lt;br /&gt;     or&lt;br /&gt;&lt;br /&gt;     jar cvfm YourJarFileName.jar YourManifest.MF -C classes yourClassPath&lt;br /&gt;     Drag-drop the YourJarFileName.jar to your desktop double click it, it         runs&lt;br /&gt;     If your program only has System.out.println ("whatever");         statements, it will&lt;br /&gt;     display nothing. The same will happen when you run it useing java at         command line          &lt;/p&gt;&lt;p&gt;You need some windows code to see it run         &lt;/p&gt;&lt;p&gt;Instructions for creating a .jar file. jar utility comes with your         JDK1.2.2 It compresses your file similar to zip utility, and more Java.&lt;br /&gt;&lt;br /&gt;     You can use it on any machine installed JDK          &lt;/p&gt;&lt;p&gt;Create a folder name it anything&lt;br /&gt;     Make that folder your current directory&lt;br /&gt;     put all your files for turning in (do not put any extra) in that         directory.&lt;br /&gt;&lt;br /&gt;     Be sure to put your html file, if there is one&lt;br /&gt;     At your dos prompt, while you are in the directory that you created ,         type in:&lt;br /&gt;     jar cvf Prj02.jar*         &lt;/p&gt;&lt;p&gt;This will take ALL the files in the directory including         subdirectories and place them in a .jar file Prj02 that can be replaced         by any of your desired jar file name.         &lt;/p&gt;To test it, you can extract the contents of jar file by typing:&lt;br /&gt;     jar xvf Prj02.jar&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-5377617428569654622?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/5377617428569654622/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=5377617428569654622' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/5377617428569654622'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/5377617428569654622'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/instructions-for-creating-executable.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-2298515949100381226</id><published>2008-06-11T09:41:00.000-07:00</published><updated>2008-06-11T09:49:56.847-07:00</updated><title type='text'></title><content type='html'>&lt;h2&gt;&lt;span style="font-size:85%;"&gt;&lt;u&gt;&lt;span style="font-size:100%;"&gt;Core Java Programs&lt;br /&gt;&lt;/span&gt;&lt;/u&gt;&lt;/span&gt;&lt;/h2&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-size:85%;"&gt;Some Java programs which help lot of java beginners to understand the basic fundamentals in Java programming.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;&lt;br /&gt;//Find Maximum of 2 nos.&lt;/b&gt;&lt;/span&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;class Maxof2{&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;  public static void main(String args[]){&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;      //taking value as command line argument.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;      //Converting String format to Integer value&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;      int i = Integer.parseInt(args[0]);&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;      int j = Integer.parseInt(args[1]);&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;      if(i &gt; j)&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;          System.out.println(i+" is greater than "+j);&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;      else&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;          System.out.println(j+" is greater than "+i);&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;  }&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;hr align="left" width="100%"&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;//Find Minimum of 2 nos. using conditional operator&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;class Minof2{&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;      public static void         main(String args[]){&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;      //taking value as command line         argument.&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;      //Converting String         format to Integer value&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;      int i =         Integer.parseInt(args[0]);&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;      int j =         Integer.parseInt(args[1]);&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;      int result = (i&lt;j)?i:j;&gt;&lt;/j)?i:j;&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;      System.out.println(result+"         is a minimum value");&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;  }&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;hr align="left" width="100%"&gt;  &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;/* Write a program that will read a float type value from the   keyboard and print the following output.&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;   -&gt;Small Integer not less than the number.&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;   -&gt;Given Number.&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;   -&gt;Largest Integer not greater than the number.&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;*/&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;class ValueFormat{&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;  public static void main(String args[]){&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;      double i = 34.32;         //given number &lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;      System.out.println("Small         Integer not greater than the number : "+Math.ceil(i));&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;      System.out.println("Given         Number : "+i);&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;      System.out.println("Largest         Integer not greater than the number : "+Math.floor(i));&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;  }&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;hr align="left" width="100%"&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;/*Write a program to generate 5 Random nos. between 1         to 100, and it&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;  should not follow with decimal point.&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;*/&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;class RandomDemo{&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;      public static void         main(String args[]){&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;          for(int         i=1;i&lt;=5;i++){&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;              System.out.println((int)(Math.random()*100));&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;          }&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;    }&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;hr align="left" width="100%"&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;/* Write a program to display a greet message         according to&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;   Marks obtained by student.&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;*/&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;class SwitchDemo{&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;      public static void         main(String args[]){&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;          int         marks = Integer.parseInt(args[0]);                        //take         marks as command line argument.&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;         switch(marks/10){&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            case         10:&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            case         9:&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            case         8:&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;                             System.out.println("Excellent");&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;                             break;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            case         7:&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;                             System.out.println("Very Good");&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;                             break;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            case         6:&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;                             System.out.println("Good");&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;                             break;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            case         5:&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;                             System.out.println("Work Hard");&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;                             break;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            case         4:&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;                             System.out.println("Poor");&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;                             break;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            case         3:&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            case         2:&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            case         1:&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            case         0:&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;                             System.out.println("Very Poor");&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;                             break;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            default:&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;                             System.out.println("Invalid value Entered");&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;      }&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt; }&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;hr align="left" width="100%"&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;/*Write a program to find SUM AND PRODUCT of a given         Digit. */&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;class Sum_Product_ofDigit{&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;      public static void         main(String args[]){&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;                        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            int         num = Integer.parseInt(args[0]);                                 //taking         value as command line argument.&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            int         temp = num,result=0;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            //Logic         for sum of digit&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            while(temp&gt;0){&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;               result         = result + temp;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;               temp--;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            }&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            System.out.println("Sum         of Digit for "+num+" is : "+result);&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            //Logic         for product of digit&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            temp         = num;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            result         = 1;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            while(temp         &gt; 0){&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;                 result         = result * temp;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;                 temp--;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            }&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            System.out.println("Product         of Digit for "+num+" is : "+result);&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;   }&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;hr align="left" width="100%"&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;/*Write a program to Find Factorial of Given no. */&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;class Factorial{&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;      public static void         main(String args[]){&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;          int         num = Integer.parseInt(args[0]);                         //take         argument as command line&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;          int         result = 1;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;          while(num&gt;0){&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;                result         = result * num;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;                num--;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;          }&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;          System.out.println("Factorial         of Given no. is : "+result);&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;   }&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;hr align="left" width="100%"&gt;  &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;/*Write a program to Reverse a given no. */&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;class Reverse{&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;      public static void         main(String args[]){&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;          int         num = Integer.parseInt(args[0]);                       //take         argument as command line&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;          int         remainder, result=0;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;          while(num&gt;0){&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;              remainder         = num%10;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;              result         = result * 10 + remainder;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;              num         = num/10;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;         }&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;         System.out.println("Reverse         number is : "+result);&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;    }&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;hr align="left" width="100%"&gt;  &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;/*Write a program to find Fibonacci series of a given         no.&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;  Example :&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;        Input         - 8&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;        Output         - 1 1 2 3 5 8 13 21&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;*/&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;class Fibonacci{&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;      public static void         main(String args[]){&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;          int         num = Integer.parseInt(args[0]);                                //taking         no. as command line argument.&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;          System.out.println("*****Fibonacci         Series*****");&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;          int         f1, f2=0, f3=1;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;          for(int         i=1;i&lt;=num;i++){&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;             System.out.print("         "+f3+" ");&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;             f1 = f2;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;             f2 = f3;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;             f3 = f1 + f2;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;          }&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:85%;"&gt;        &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;   }&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;hr align="left" width="100%"&gt;  &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;/* Write a program to find sum of all integers greater than 100 and&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;   less than 200 that are divisible by 7 */&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;class SumOfDigit{&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;      public static void main(String args[]){&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;      int result=0;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;      for(int i=100;i&lt;=200;i++){&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;           if(i%7==0)&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;              result+=i;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;      }&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;      System.out.println("Output of Program is : "+result);&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;   }&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;}&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-2298515949100381226?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/2298515949100381226/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=2298515949100381226' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/2298515949100381226'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/2298515949100381226'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/core-java-programs-some-java-programs_5020.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-6845321679300158110</id><published>2008-06-11T09:39:00.000-07:00</published><updated>2008-06-11T09:49:39.693-07:00</updated><title type='text'></title><content type='html'>&lt;b&gt;/* Write a program to Concatenate  string using for Loop&lt;/b&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;b&gt;   Example:&lt;/b&gt; &lt;/p&gt;&lt;p&gt;&lt;b&gt;          Input - 5&lt;/b&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;          Output - 1 2 3 4 5 */&lt;/b&gt;&lt;/p&gt; &lt;p&gt;class Join{&lt;/p&gt; &lt;p&gt;      public static void main(String args[]){&lt;/p&gt; &lt;p&gt;      int num =         Integer.parseInt(args[0]);&lt;/p&gt; &lt;p&gt;      String result =         " ";&lt;/p&gt; &lt;p&gt;      for(int i=1;i&lt;=num;i++){&lt;/p&gt; &lt;p&gt;           result         = result + i + " ";&lt;/p&gt; &lt;p&gt;      }&lt;/p&gt; &lt;p&gt;      System.out.println(result);&lt;/p&gt; &lt;p&gt;  }&lt;/p&gt; &lt;p&gt;}&lt;/p&gt; &lt;hr align="left" width="100%"&gt;  &lt;p&gt;&lt;b&gt;/* Program to Display Multiplication Table */&lt;/b&gt;&lt;/p&gt; &lt;p&gt;class MultiplicationTable{&lt;/p&gt; &lt;p&gt;      public static void main(String args[]){&lt;/p&gt; &lt;p&gt;      int num =         Integer.parseInt(args[0]);&lt;/p&gt; &lt;p&gt;      System.out.println("*****MULTIPLICATION         TABLE*****");&lt;/p&gt; &lt;p&gt;      for(int i=1;i&lt;=num;i++){&lt;/p&gt; &lt;p&gt;         for(int         j=1;j&lt;=num;j++){&lt;/p&gt; &lt;p&gt;            System.out.print("         "+i*j+" ");&lt;/p&gt; &lt;p&gt;         }&lt;/p&gt; &lt;p&gt;         System.out.print("\n");&lt;/p&gt; &lt;p&gt;      }&lt;/p&gt; &lt;p&gt;  }&lt;/p&gt; &lt;p&gt;}&lt;/p&gt; &lt;hr align="left" width="100%"&gt;  &lt;p&gt;&lt;b&gt;/* Write a program to Swap the values */&lt;/b&gt;&lt;/p&gt; &lt;p&gt;class Swap{&lt;/p&gt; &lt;p&gt;      public static void         main(String args[]){&lt;/p&gt; &lt;p&gt;      int num1 =         Integer.parseInt(args[0]);&lt;/p&gt; &lt;p&gt;      int num2 =         Integer.parseInt(args[1]);&lt;/p&gt; &lt;p&gt;      System.out.println("\n***Before         Swapping***");&lt;/p&gt; &lt;p&gt;      System.out.println("Number         1 : "+num1);&lt;/p&gt; &lt;p&gt;      System.out.println("Number         2 : "+num2);&lt;/p&gt; &lt;p&gt;      //Swap logic&lt;/p&gt; &lt;p&gt;      num1 = num1 + num2;&lt;/p&gt; &lt;p&gt;      num2 = num1 - num2;&lt;/p&gt; &lt;p&gt;      num1 = num1 - num2;&lt;/p&gt; &lt;p&gt;      System.out.println("\n***After         Swapping***");&lt;/p&gt; &lt;p&gt;      System.out.println("Number         1 : "+num1);&lt;/p&gt; &lt;p&gt;      System.out.println("Number         2 : "+num2);&lt;/p&gt; &lt;p&gt;      }&lt;/p&gt; &lt;p&gt;}&lt;/p&gt; &lt;hr align="left" width="100%"&gt;  &lt;p&gt;&lt;b&gt;/* Write a program to convert given no. of days into months and days.&lt;/b&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;  (Assume that each month is of 30 days)&lt;/b&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;  Example :&lt;/b&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;           Input - 69&lt;/b&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;           Output - 69 days = 2 Month and 9 days */&lt;/b&gt;&lt;/p&gt; &lt;p&gt;class DayMonthDemo{&lt;/p&gt; &lt;p&gt;      public static void main(String args[]){&lt;/p&gt; &lt;p&gt;      int num = Integer.parseInt(args[0]);&lt;/p&gt; &lt;p&gt;      int days = num%30;&lt;/p&gt; &lt;p&gt;      int month = num/30;&lt;/p&gt; &lt;p&gt;      System.out.println(num+"        days = "+month+" Month and "+days+" days");&lt;/p&gt; &lt;p&gt;   }&lt;/p&gt; &lt;p&gt;}&lt;/p&gt; &lt;hr align="left" width="100%"&gt;  &lt;p&gt;/*Write a program to generate a Triangle.&lt;/p&gt; &lt;p&gt;  eg:&lt;/p&gt; &lt;p&gt;  1&lt;/p&gt; &lt;p&gt;  2 2&lt;/p&gt; &lt;p&gt;  3 3 3&lt;/p&gt; &lt;p&gt;  4 4 4 4 and so on as per user given number */&lt;/p&gt;         &lt;p&gt;class Triangle{&lt;/p&gt;         &lt;p&gt;      public static void         main(String args[]){&lt;/p&gt;         &lt;p&gt;          int         num = Integer.parseInt(args[0]);&lt;/p&gt;         &lt;p&gt;          for(int         i=1;i&lt;=num;i++){&lt;/p&gt;         &lt;p&gt;             for(int         j=1;j&lt;=i;j++){&lt;/p&gt;         &lt;p&gt;                System.out.print("         "+i+" ");&lt;/p&gt;         &lt;p&gt;             }&lt;/p&gt;         &lt;p&gt;             System.out.print("\n");&lt;/p&gt;         &lt;p&gt;           } &lt;/p&gt;         &lt;p&gt;    }&lt;/p&gt;         &lt;p&gt;}&lt;/p&gt;         &lt;b&gt;         &lt;hr align="left" width="100%"&gt;         &lt;/b&gt;                  &lt;p&gt;&lt;b&gt;/* Write a program to Display Invert Triangle.&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;   Example:&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;          Input         - 5&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;          Output         :&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;          5         5 5 5 5&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;          4         4 4 4&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;          3         3 3&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;          2         2&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;          1&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;*/&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;class InvertTriangle{&lt;/p&gt;         &lt;p&gt;      public static void         main(String args[]){&lt;/p&gt;         &lt;p&gt;           int         num = Integer.parseInt(args[0]);&lt;/p&gt;         &lt;p&gt;           while(num         &gt; 0){&lt;/p&gt;         &lt;p&gt;              for(int         j=1;j&lt;=num;j++){&lt;/p&gt;         &lt;p&gt;                          System.out.print(" "+num+" ");&lt;/p&gt;         &lt;p&gt;                }&lt;/p&gt;         &lt;p&gt;                System.out.print("\n");&lt;/p&gt;         &lt;p&gt;                num--;&lt;/p&gt;         &lt;p&gt;            }&lt;/p&gt;         &lt;p&gt;      }&lt;/p&gt;         &lt;p&gt;}&lt;/p&gt; &lt;hr align="left" width="100%"&gt;  &lt;p&gt;&lt;b&gt;/*Write a program to find whether given no. is Armstrong or not.&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;  Example :&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;           Input         - 153&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;           Output         - 1^3 + 5^3 + 3^3 = 153, so it is Armstrong no. */&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;class Armstrong{&lt;/p&gt;         &lt;p&gt;      public static void         main(String args[]){&lt;/p&gt;         &lt;p&gt;      int num =         Integer.parseInt(args[0]);&lt;/p&gt;         &lt;p&gt;      int n = num; //use         to check at last time&lt;/p&gt;         &lt;p&gt;      int         check=0,remainder;&lt;/p&gt;         &lt;p&gt;      while(num &gt; 0){&lt;/p&gt;         &lt;p&gt;           remainder         = num % 10;&lt;/p&gt;         &lt;p&gt;           check         = check + (int)Math.pow(remainder,3);&lt;/p&gt;         &lt;p&gt;           num         = num / 10;&lt;/p&gt;         &lt;p&gt;      }&lt;/p&gt;         &lt;p&gt;      if(check == n)&lt;/p&gt;         &lt;p&gt;            System.out.println(n+"         is an Armstrong Number");&lt;/p&gt;         &lt;p&gt;      else&lt;/p&gt;         &lt;p&gt;            System.out.println(n+"         is not a Armstrong Number");&lt;/p&gt;         &lt;p&gt;   }&lt;/p&gt;         &lt;p&gt;}&lt;/p&gt;         &lt;hr align="left" width="100%"&gt;                  &lt;p&gt;&lt;b&gt;/* Write a program to Find whether number is Prime or         Not. */&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;class PrimeNo{&lt;/p&gt;         &lt;p&gt;      public static void         main(String args[]){&lt;/p&gt;         &lt;p&gt;          int         num = Integer.parseInt(args[0]);&lt;/p&gt;         &lt;p&gt;         int         flag=0;&lt;/p&gt;         &lt;p&gt;         for(int         i=2;i&lt;num;i++){&gt;&lt;/num;i++){&gt;&lt;/p&gt;         &lt;p&gt;             if(num%i==0)&lt;/p&gt;         &lt;p&gt;              {&lt;/p&gt;         &lt;p&gt;                 System.out.println(num+"         is not a Prime Number");&lt;/p&gt;         &lt;p&gt;                 flag         = 1;&lt;/p&gt;         &lt;p&gt;                 break;&lt;/p&gt;         &lt;p&gt;              }&lt;/p&gt;         &lt;p&gt;         }&lt;/p&gt;         &lt;p&gt;         if(flag==0)&lt;/p&gt;         &lt;p&gt;             System.out.println(num+"         is a Prime Number");&lt;/p&gt;         &lt;p&gt;    }&lt;/p&gt;         &lt;p&gt;}&lt;/p&gt;         &lt;hr align="left" width="100%"&gt;                  &lt;p&gt;&lt;b&gt;/* Write a program to find whether no. is palindrome or not.&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;   Example :&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;           Input         - 12521 is a palindrome no.&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;           Input         - 12345 is not a palindrome no. */&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;class Palindrome{&lt;/p&gt;         &lt;p&gt;      public static void         main(String args[]){&lt;/p&gt;         &lt;p&gt;          int         num = Integer.parseInt(args[0]);&lt;/p&gt;         &lt;p&gt;          int         n = num; //used at last time check&lt;/p&gt;         &lt;p&gt;          int         reverse=0,remainder;&lt;/p&gt;         &lt;p&gt;          while(num         &gt; 0){&lt;/p&gt;         &lt;p&gt;                remainder         = num % 10;&lt;/p&gt;         &lt;p&gt;                reverse         = reverse * 10 + remainder;&lt;/p&gt;         &lt;p&gt;                num         = num / 10;&lt;/p&gt;         &lt;p&gt;           }&lt;/p&gt;         &lt;p&gt;          if(reverse         == n)&lt;/p&gt;         &lt;p&gt;              System.out.println(n+"         is a Palindrome Number");&lt;/p&gt;         &lt;p&gt;          else&lt;/p&gt;         &lt;p&gt;              System.out.println(n+"         is not a Palindrome Number");&lt;/p&gt;         &lt;p&gt;     }&lt;/p&gt;         &lt;p&gt;}&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-6845321679300158110?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/6845321679300158110/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=6845321679300158110' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/6845321679300158110'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/6845321679300158110'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/core-java-programs-some-java-programs_11.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-2209331220901991485</id><published>2008-06-11T09:37:00.000-07:00</published><updated>2008-06-11T09:49:25.475-07:00</updated><title type='text'></title><content type='html'>&lt;h2&gt;&lt;span style="font-size:100%;"&gt;&lt;b&gt;/* switch case demo&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;                            &lt;p&gt;&lt;b&gt;   Example :&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;           Input         - 124&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;           Output         - One Two Four */&lt;/b&gt;&lt;/p&gt;         &lt;p&gt; &lt;/p&gt;         &lt;p&gt;class SwitchCaseDemo{&lt;/p&gt;         &lt;p&gt;      public static void         main(String args[]){&lt;/p&gt;         &lt;p&gt;          try{&lt;/p&gt;         &lt;p&gt;          int         num = Integer.parseInt(args[0]);&lt;/p&gt;         &lt;p&gt;          int         n = num; //used at last time check&lt;/p&gt;         &lt;p&gt;          int         reverse=0,remainder;&lt;/p&gt;         &lt;p&gt;          while(num         &gt; 0){&lt;/p&gt;         &lt;p&gt;                remainder         = num % 10;&lt;/p&gt;         &lt;p&gt;                reverse         = reverse * 10 + remainder;&lt;/p&gt;         &lt;p&gt;                num         = num / 10;&lt;/p&gt;         &lt;p&gt;           }&lt;/p&gt;         &lt;p&gt;          String         result=""; //contains the actual output&lt;/p&gt;         &lt;p&gt;          while(reverse         &gt; 0){&lt;/p&gt;         &lt;p&gt;               remainder         = reverse % 10;&lt;/p&gt;         &lt;p&gt;               reverse         = reverse / 10;&lt;/p&gt;         &lt;p&gt;               switch(remainder){&lt;/p&gt;         &lt;p&gt;                            case 0 :&lt;/p&gt;         &lt;p&gt;                                     result = result + "Zero ";&lt;/p&gt;         &lt;p&gt;                                     break;&lt;/p&gt;         &lt;p&gt;                            case 1 :&lt;/p&gt;         &lt;p&gt;                                     result = result + "One ";&lt;/p&gt;         &lt;p&gt;                                     break;&lt;/p&gt;         &lt;p&gt;                            case 2 :&lt;/p&gt;         &lt;p&gt;                                     result = result + "Two ";&lt;/p&gt;         &lt;p&gt;                                     break;&lt;/p&gt;         &lt;p&gt;                            case 3 :&lt;/p&gt;         &lt;p&gt;                                     result = result + "Three ";&lt;/p&gt;         &lt;p&gt;                                     break;&lt;/p&gt;         &lt;p&gt;                            case 4 :&lt;/p&gt;         &lt;p&gt;                                     result = result + "Four ";&lt;/p&gt;         &lt;p&gt;                                     break;&lt;/p&gt;         &lt;p&gt;                            case 5 :&lt;/p&gt;         &lt;p&gt;                                     result = result + "Five ";&lt;/p&gt;         &lt;p&gt;                                     break;&lt;/p&gt;         &lt;p&gt;                            case 6 :&lt;/p&gt;         &lt;p&gt;                                     result = result + "Six ";&lt;/p&gt;         &lt;p&gt;                                     break;&lt;/p&gt;         &lt;p&gt;                            case 7 :&lt;/p&gt;         &lt;p&gt;                                     result = result + "Seven ";&lt;/p&gt;         &lt;p&gt;                                     break;&lt;/p&gt;         &lt;p&gt;                            case 8 :&lt;/p&gt;         &lt;p&gt;                                     result = result + "Eight ";&lt;/p&gt;         &lt;p&gt;                                     break;&lt;/p&gt;         &lt;p&gt;                            case 9 :&lt;/p&gt;         &lt;p&gt;                                     result = result + "Nine ";&lt;/p&gt;         &lt;p&gt;                                     break;&lt;/p&gt;         &lt;p&gt;                            default:&lt;/p&gt;         &lt;p&gt;                                     result="";&lt;/p&gt;         &lt;p&gt;                 }&lt;/p&gt;         &lt;p&gt;            }&lt;/p&gt;         &lt;p&gt;                System.out.println(result);&lt;/p&gt;         &lt;p&gt;        }catch(Exception         e){&lt;/p&gt;         &lt;p&gt;             System.out.println("Invalid         Number Format");&lt;/p&gt;         &lt;p&gt;         }&lt;/p&gt;         &lt;p&gt;     }&lt;/p&gt; &lt;p&gt;}&lt;/p&gt; &lt;hr align="left" width="100%"&gt;          &lt;p&gt;&lt;b&gt;/* Write a program to generate Harmonic Series.&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;   Example :&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;           Input         - 5&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;           Output         - 1 + 1/2 + 1/3 + 1/4 + 1/5 = 2.28 (Approximately) */&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;class HarmonicSeries{&lt;/p&gt;         &lt;p&gt;      public static void         main(String args[]){&lt;/p&gt;         &lt;p&gt;      int num =         Integer.parseInt(args[0]);&lt;/p&gt;         &lt;p&gt;      double result = 0.0;&lt;/p&gt;         &lt;p&gt;      while(num &gt; 0){&lt;/p&gt;         &lt;p&gt;            result         = result + (double) 1 / num;&lt;/p&gt;         &lt;p&gt;            num--;&lt;/p&gt;         &lt;p&gt;      }&lt;/p&gt;         &lt;p&gt;      System.out.println("Output         of Harmonic Series is "+result);&lt;/p&gt;         &lt;p&gt;  }&lt;/p&gt;         &lt;p&gt;}&lt;/p&gt;         &lt;hr align="left" width="100%"&gt;                  &lt;p&gt;&lt;b&gt;/*Write a program to find average of consecutive N         Odd no. and Even no. */&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;class EvenOdd_Avg{&lt;/p&gt;         &lt;p&gt;      public static void         main(String args[]){&lt;/p&gt;         &lt;p&gt;      int n =         Integer.parseInt(args[0]);&lt;/p&gt;         &lt;p&gt;      int cntEven=0,cntOdd=0,sumEven=0,sumOdd=0;&lt;/p&gt;         &lt;p&gt;      while(n &gt; 0){&lt;/p&gt;         &lt;p&gt;           if(n%2==0){&lt;/p&gt;         &lt;p&gt;               cntEven++;&lt;/p&gt;         &lt;p&gt;               sumEven         = sumEven + n;&lt;/p&gt;         &lt;p&gt;           }&lt;/p&gt;         &lt;p&gt;           else{&lt;/p&gt;         &lt;p&gt;               cntOdd++;&lt;/p&gt;         &lt;p&gt;               sumOdd         = sumOdd + n;&lt;/p&gt;         &lt;p&gt;           }&lt;/p&gt;         &lt;p&gt;           n--;&lt;/p&gt;         &lt;p&gt;      }&lt;/p&gt;         &lt;p&gt;      int evenAvg,oddAvg;&lt;/p&gt;         &lt;p&gt;      evenAvg = sumEven/cntEven;&lt;/p&gt;         &lt;p&gt;      oddAvg = sumOdd/cntOdd;&lt;/p&gt;         &lt;p&gt;      System.out.println("Average         of first N Even no is "+evenAvg);&lt;/p&gt;         &lt;p&gt;      System.out.println("Average         of first N Odd no is "+oddAvg);&lt;/p&gt;         &lt;p&gt; &lt;/p&gt;         &lt;p&gt;  }&lt;/p&gt; &lt;p&gt;}&lt;/p&gt; &lt;hr align="left" width="100%"&gt;          &lt;p&gt;&lt;b&gt;/* Display Triangle as follow : BREAK DEMO.&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;    1&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;    2 3&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;    4 5 6&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;    7 8 9 10 ... N */&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;class Output1{&lt;/p&gt;         &lt;p&gt;      public static void         main(String args[]){&lt;/p&gt;         &lt;p&gt;          int         c=0;&lt;/p&gt;         &lt;p&gt;          int         n = Integer.parseInt(args[0]);&lt;/p&gt;         &lt;p&gt;         loop1:         for(int i=1;i&lt;=n;i++){&lt;/p&gt;         &lt;p&gt;         loop2:         for(int j=1;j&lt;=i;j++){&lt;/p&gt;         &lt;p&gt;                               if(c!=n){&lt;/p&gt;         &lt;p&gt;                                    c++;&lt;/p&gt;         &lt;p&gt;                                    System.out.print(c+" ");&lt;/p&gt;         &lt;p&gt;                               }&lt;/p&gt;         &lt;p&gt;                               else&lt;/p&gt;         &lt;p&gt;                                   break loop1;&lt;/p&gt;         &lt;p&gt;                            }&lt;/p&gt;         &lt;p&gt;                            System.out.print("\n");&lt;/p&gt;         &lt;p&gt;                 }&lt;/p&gt;         &lt;p&gt;     }&lt;/p&gt; &lt;p&gt;}&lt;/p&gt; &lt;hr align="left" width="100%"&gt;&lt;b&gt;/* Display Triangle as follow&lt;/b&gt;         &lt;p&gt;&lt;b&gt;    0&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;    1 0&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;    1 0 1&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;    0 1 0 1 */&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;class Output2{&lt;/p&gt;         &lt;p&gt;      public static void         main(String args[]){&lt;/p&gt;         &lt;p&gt;           for(int         i=1;i&lt;=4;i++){&lt;/p&gt;         &lt;p&gt;              for(int         j=1;j&lt;=i;j++){&lt;/p&gt;         &lt;p&gt;                                    System.out.print(((i+j)%2)+" ");&lt;/p&gt;         &lt;p&gt;                            }&lt;/p&gt;         &lt;p&gt;                            System.out.print("\n");&lt;/p&gt;         &lt;p&gt;                 }&lt;/p&gt;         &lt;p&gt;     }&lt;/p&gt; &lt;p&gt;}&lt;b&gt;      &lt;/b&gt; &lt;/p&gt; &lt;hr align="left" width="100%"&gt;          &lt;p&gt;&lt;b&gt;/* Display Triangle as follow&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;    1&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;    2 4&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;    3 6 9&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;    4 8 12 16 ... N (indicates         no. of Rows) */&lt;/b&gt;&lt;/p&gt;         &lt;p&gt;class Output3{&lt;/p&gt;         &lt;p&gt;      public static void         main(String args[]){&lt;/p&gt;         &lt;p&gt;          int         n = Integer.parseInt(args[0]);&lt;/p&gt;         &lt;p&gt;                           for(int i=1;i&lt;=n;i++){&lt;/p&gt;         &lt;p&gt;                             for(int j=1;j&lt;=i;j++){&lt;/p&gt;         &lt;p&gt;                                System.out.print((i*j)+" ");&lt;/p&gt;         &lt;p&gt;                            }&lt;/p&gt;         &lt;p&gt;                            System.out.print("\n");&lt;/p&gt;         &lt;p&gt;                 }&lt;/p&gt;         &lt;p&gt;     }&lt;br /&gt;&lt;br /&gt;      }&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-2209331220901991485?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/2209331220901991485/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=2209331220901991485' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/2209331220901991485'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/2209331220901991485'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/core-java-programs-some-java-programs.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-4872173697739690455</id><published>2008-06-11T09:36:00.001-07:00</published><updated>2008-06-11T09:48:38.308-07:00</updated><title type='text'></title><content type='html'>&lt;p&gt;This program Demonstrates the proper use of Date functionality in common java programming scenarios&lt;br /&gt;&lt;/p&gt;         &lt;p&gt;&lt;b&gt;&lt;u&gt;Date and Time&lt;/u&gt;&lt;/b&gt;         &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;pre&gt;import java.text.DateFormat;&lt;br /&gt;import java.text.ParseException;&lt;br /&gt;import java.text.SimpleDateFormat;&lt;br /&gt;import java.util.Calendar;&lt;br /&gt;import java.util.Date;&lt;br /&gt;public class DateUtility {&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt;/* Add Day/Month/Year to a Date&lt;br /&gt;add() is used to add  values to a Calendar object.&lt;br /&gt;You specify which Calendar field is to be affected by the operation&lt;br /&gt;(Calendar.YEAR, Calendar.MONTH, Calendar.DATE).&lt;br /&gt;*/&lt;/span&gt;&lt;br /&gt;public static void addToDate(){&lt;br /&gt;System.out.println("In the ADD Operation");&lt;br /&gt;// String DATE_FORMAT = "yyyy-MM-dd";&lt;br /&gt;String DATE_FORMAT = "dd-MM-yyyy";  //Refer Java DOCS for formats&lt;br /&gt;java.text.SimpleDateFormat sdf =  new java.text.SimpleDateFormat(DATE_FORMAT);&lt;br /&gt;Calendar c1 = Calendar.getInstance();&lt;br /&gt;Date d1 = new Date();&lt;br /&gt;System.out.println("Todays date in Calendar Format : "+c1);&lt;br /&gt;System.out.println("c1.getTime() : "+c1.getTime());&lt;br /&gt;System.out.println("c1.get(Calendar.YEAR): " + c1.get(Calendar.YEAR));&lt;br /&gt;System.out.println("Todays date in Date Format : "+d1);&lt;br /&gt;c1.set(1999,0 ,20);   //(year,month,date)&lt;br /&gt;System.out.println("c1.set(1999,0 ,20) : "+c1.getTime());&lt;br /&gt;c1.add(Calendar.DATE,40);&lt;br /&gt;System.out.println("Date + 20 days is : " + sdf.format(c1.getTime()));&lt;br /&gt;System.out.println();&lt;br /&gt;System.out.println();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt;/*Substract Day/Month/Year to a Date&lt;br /&gt;roll() is used to substract values to a Calendar object.&lt;br /&gt;You specify which Calendar field is to be affected by the operation&lt;br /&gt;(Calendar.YEAR, Calendar.MONTH, Calendar.DATE).&lt;br /&gt;&lt;br /&gt;Note: To substract, simply use a negative argument.&lt;br /&gt; roll() does the same thing except you specify if you want to roll up (add 1)&lt;br /&gt; or roll down (substract 1) to the specified Calendar field. The operation only&lt;br /&gt; affects the specified field while add() adjusts other Calendar fields.&lt;br /&gt; See the following example, roll() makes january rolls to december in the same&lt;br /&gt; year while add() substract the YEAR field for the correct result&lt;br /&gt;&lt;br /&gt;*/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;public static void subToDate(){&lt;br /&gt;System.out.println("In the SUB Operation");&lt;br /&gt;String DATE_FORMAT = "dd-MM-yyyy";&lt;br /&gt;java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(DATE_FORMAT);&lt;br /&gt;Calendar c1 = Calendar.getInstance();&lt;br /&gt;c1.set(1999, 0 , 20);&lt;br /&gt;System.out.println("Date is : " + sdf.format(c1.getTime()));&lt;br /&gt;&lt;br /&gt;// roll down, substract 1 month&lt;br /&gt;c1.roll(Calendar.MONTH, false);&lt;br /&gt;System.out.println("Date roll down 1 month : " + sdf.format(c1.getTime()));&lt;br /&gt;&lt;br /&gt;c1.set(1999, 0 , 20);&lt;br /&gt;System.out.println("Date is : " + sdf.format(c1.getTime()));&lt;br /&gt;c1.add(Calendar.MONTH, -1);&lt;br /&gt;// substract 1 month&lt;br /&gt;System.out.println("Date minus 1 month : " + sdf.format(c1.getTime()));&lt;br /&gt;System.out.println();&lt;br /&gt;System.out.println();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void daysBetween2Dates(){&lt;br /&gt;Calendar c1 = Calendar.getInstance();  //new GregorianCalendar();&lt;br /&gt;Calendar c2 = Calendar.getInstance();  //new GregorianCalendar();&lt;br /&gt;   c1.set(1999, 0 , 20);&lt;br /&gt;   c2.set(1999, 0 , 22);&lt;br /&gt;   System.out.println("Days Between "+c1.getTime()+"\t"+ c2.getTime()+" is");&lt;br /&gt;   System.out.println((c2.getTime().getTime() - c1.getTime().getTime())/(24*3600*1000));&lt;br /&gt;   System.out.println();&lt;br /&gt;System.out.println();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void daysInMonth() {&lt;br /&gt;Calendar c1 = Calendar.getInstance();  //new GregorianCalendar();&lt;br /&gt;   c1.set(1999, 6 , 20);&lt;br /&gt;   int year = c1.get(Calendar.YEAR);&lt;br /&gt;   int month = c1.get(Calendar.MONTH);&lt;br /&gt;//     int days = c1.get(Calendar.DATE);&lt;br /&gt;int [] daysInMonths = {31,28,31,30,31,30,31,31,30,31,30,31};&lt;br /&gt;daysInMonths[1] += DateUtility.isLeapYear(year) ? 1 : 0;&lt;br /&gt;System.out.println("Days in "+month+"th month for year "+year+" is "+ daysInMonths[c1.get(Calendar.MONTH)]);&lt;br /&gt;   System.out.println();&lt;br /&gt;System.out.println();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void getDayofTheDate() {&lt;br /&gt;Date d1 = new Date();&lt;br /&gt;String day = null;&lt;br /&gt;   DateFormat f = new SimpleDateFormat("EEEE");&lt;br /&gt;   try {&lt;br /&gt;    day = f.format(d1);&lt;br /&gt;   }&lt;br /&gt;   catch(Exception e) {&lt;br /&gt;     e.printStackTrace();&lt;br /&gt;   }&lt;br /&gt;   System.out.println("The dat for "+d1+" is "+day);&lt;br /&gt;   System.out.println();&lt;br /&gt;System.out.println();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void validateAGivenDate() {&lt;br /&gt;String dt = "20011223";&lt;br /&gt;String invalidDt = "20031315";&lt;br /&gt;String dateformat = "yyyyMMdd";&lt;br /&gt;Date dt1=null , dt2=null;&lt;br /&gt;try {  &lt;br /&gt; SimpleDateFormat sdf = new SimpleDateFormat(dateformat); &lt;br /&gt; sdf.setLenient(false); &lt;br /&gt; dt1 = sdf.parse(dt);&lt;br /&gt; dt2 = sdf.parse(invalidDt);&lt;br /&gt; System.out.println("Date is ok = " + dt1 + "(" + dt + ")");  &lt;br /&gt;}&lt;br /&gt;catch (ParseException e) {  &lt;br /&gt; System.out.println(e.getMessage());&lt;br /&gt;}&lt;br /&gt;catch (IllegalArgumentException e) { &lt;br /&gt; System.out.println("Invalid date");  &lt;br /&gt;}&lt;br /&gt;   System.out.println();&lt;br /&gt;System.out.println();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void compare2Dates(){&lt;br /&gt;SimpleDateFormat fm = new SimpleDateFormat("dd-MM-yyyy");&lt;br /&gt;Calendar c1 = Calendar.getInstance();&lt;br /&gt;Calendar c2 = Calendar.getInstance();&lt;br /&gt;&lt;br /&gt;c1.set(2000, 02, 15);&lt;br /&gt;c2.set(2001, 02, 15);&lt;br /&gt;&lt;br /&gt;System.out.print(fm.format(c1.getTime())+" is ");&lt;br /&gt;if(c1.before(c2)){&lt;br /&gt; System.out.println("less than "+c2.getTime());&lt;br /&gt;}else if(c1.after(c2)){&lt;br /&gt; System.out.println("greater than "+c2.getTime());&lt;br /&gt;}else if(c1.equals(c2)){&lt;br /&gt; System.out.println("is equal to "+fm.format(c2.getTime()));&lt;br /&gt;}&lt;br /&gt;System.out.println();&lt;br /&gt;System.out.println();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static boolean isLeapYear(int year){&lt;br /&gt; if((year%100 != 0) || (year%400 == 0)){&lt;br /&gt;  return true;&lt;br /&gt; }&lt;br /&gt; return false;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void main(String args[]){&lt;br /&gt;addToDate();&lt;br /&gt;subToDate();&lt;br /&gt;daysBetween2Dates(); &lt;span style="color: rgb(136, 136, 136);"&gt;//The "right" way would be to compute the julian day number of both dates and then do the substraction.&lt;br /&gt;&lt;/span&gt;  daysInMonth();&lt;br /&gt;validateAGivenDate();&lt;br /&gt;compare2Dates();&lt;br /&gt;getDayofTheDate();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-4872173697739690455?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/4872173697739690455/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=4872173697739690455' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/4872173697739690455'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/4872173697739690455'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/java-date-utility-this-program.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9218169636891156375.post-621820940925659731</id><published>2008-06-11T09:35:00.000-07:00</published><updated>2008-06-11T09:51:19.550-07:00</updated><title type='text'></title><content type='html'>&lt;p&gt;This program Demonstrates the proper use of Number Formats in common java programming scenarios&lt;br /&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;&lt;u&gt;String Utility&lt;/u&gt;&lt;/b&gt;                         &lt;/p&gt;&lt;pre&gt;/*&lt;br /&gt;* NumberUtility.java&lt;br /&gt;*&lt;br /&gt;*  Source:  http://www.freejavaguide.com&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;import java.math.BigDecimal;&lt;br /&gt;import java.text.DecimalFormat;&lt;br /&gt;import java.text.DecimalFormatSymbols;&lt;br /&gt;import java.util.Locale;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;* Class provides common functions on number formats.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public class NumberUtility {&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * Method takes Object as parameter and returns decimal number.&lt;br /&gt;  * if argument is float or double and contains tailing zeros&lt;br /&gt;  * it removes them. If argument is float or double then no change in return type.&lt;br /&gt;  * Change the Format of the Number by changing the String Pattern&lt;br /&gt;  */&lt;br /&gt; public static String changeToDecimalFormat(Object number) {&lt;br /&gt;&lt;br /&gt;     BigDecimal bdNumber = new BigDecimal(number.toString());&lt;br /&gt;     bdNumber = bdNumber.stripTrailingZeros();           //Returns a BigDecimal with any trailing zero's removed&lt;br /&gt;     String pattern = "###,##0.0###########";  //To apply formatting when the number of digits in input equals the pattern&lt;br /&gt;     DecimalFormat newFormat = new DecimalFormat(pattern, new DecimalFormatSymbols(Locale.US));&lt;br /&gt;     return newFormat.format(bdNumber);&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; /* Method takes Object as parameter and removes commas from the parameter */&lt;br /&gt; public static double removeCommasFromNumber(Object number) {&lt;br /&gt;     try {&lt;br /&gt;         StringBuffer inputNo = new StringBuffer(number.toString());&lt;br /&gt;         if (inputNo.length() &gt; 0) {&lt;br /&gt;             while (inputNo.indexOf(",") != -1) {&lt;br /&gt;                 inputNo.deleteCharAt(inputNo.indexOf(","));&lt;br /&gt;             }&lt;br /&gt;         } else {&lt;br /&gt;             return 0.0;&lt;br /&gt;         }&lt;br /&gt;         return Double.parseDouble(inputNo.toString());&lt;br /&gt;&lt;br /&gt;     } catch (NumberFormatException e) {&lt;br /&gt;         return 0.0;&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; /* Some times its required to have a fixed set of decimal places for a&lt;br /&gt;  * number. We can set that by changing the precision number for a particular&lt;br /&gt;  * input BigDecimal Input String&lt;br /&gt;  */&lt;br /&gt; public static String changeToRequiredDecimals(String bigDecimalString,&lt;br /&gt;         int precision) {&lt;br /&gt;     String newFormattedString = null;&lt;br /&gt;     String afterDecimal = null;&lt;br /&gt;     if (bigDecimalString == null || bigDecimalString.length() == 0) {&lt;br /&gt;         return "0.0";&lt;br /&gt;     }&lt;br /&gt;     if (bigDecimalString.contains(".")) {&lt;br /&gt;         afterDecimal = bigDecimalString.substring(bigDecimalString&lt;br /&gt;                 .indexOf(".") + 1);&lt;br /&gt;         int length = Math.abs((afterDecimal.length() - precision));&lt;br /&gt;         if (afterDecimal.length() &lt; newformattedstring =" bigDecimalString;" i =" 0;" newformattedstring =" newFormattedString"&gt; precision) {&lt;br /&gt;             newFormattedString = bigDecimalString.substring(0,&lt;br /&gt;                     bigDecimalString.length() - length);&lt;br /&gt;             if (precision == 0) {&lt;br /&gt;                 newFormattedString = newFormattedString.substring(0,&lt;br /&gt;                         newFormattedString.indexOf("."));&lt;br /&gt;           } else {&lt;br /&gt;               newFormattedString = bigDecimalString;&lt;br /&gt;           }&lt;br /&gt;&lt;br /&gt;       } else {&lt;br /&gt;            if (precision &gt; 0)&lt;br /&gt;                newFormattedString = bigDecimalString + ".";&lt;br /&gt;            else&lt;br /&gt;                newFormattedString = bigDecimalString;&lt;br /&gt;            for (int i = 0; i &lt; newformattedstring =" newFormattedString" intvar =" 10;" doublevar =" 10.504000;" floatvar =" 343534534348.5687654F;" commastring = "343,534,535,000.0" bdnumber =" new"&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9218169636891156375-621820940925659731?l=corejavatudor.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://corejavatudor.blogspot.com/feeds/621820940925659731/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9218169636891156375&amp;postID=621820940925659731' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/621820940925659731'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9218169636891156375/posts/default/621820940925659731'/><link rel='alternate' type='text/html' href='http://corejavatudor.blogspot.com/2008/06/java-string-utility-this-program.html' title=''/><author><name>Spidermen,Ice age,Age Of Empire latest</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
