<?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-3416407328338427543</id><updated>2012-01-22T03:16:48.469+05:30</updated><category term='Sorting'/><category term='Java Interview Notes Lesson'/><category term='Java Code'/><category term='Java Tutorial'/><category term='Java Example'/><category term='Fibonacci Series'/><category term='ArrayList'/><category term='String'/><category term='Java Interview Questions'/><category term='String In Java'/><category term='Recursion'/><category term='Math'/><category term='File Handling'/><category term='Java Basics'/><category term='SCJP'/><category term='Armstrong Number'/><category term='java.io package'/><category term='Oracle'/><category term='Interface'/><category term='Floyd Triangle'/><category term='Java Program'/><category term='TreeSet'/><category term='JDBC'/><category term='Addition'/><category term='Palindrome'/><category term='File'/><category term='Collections'/><category term='Factorial'/><category term='Java Resources'/><category term='OOPS Principles'/><category term='Pascal Triangle'/><category term='Prime Number'/><category term='SQL Developer'/><category term='Scanner'/><category term='Java Certifications'/><category term='final'/><category term='Rectangle'/><category term='Inner Classes'/><category term='Method'/><category term='Java on Ubuntu'/><category term='Triangular Number'/><category term='Circle'/><category term='Factors'/><title type='text'>Java Tutorial Online</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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>96</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3416407328338427543.post-2273726918253437079</id><published>2012-01-22T03:13:00.004+05:30</published><updated>2012-01-22T03:15:52.543+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='String In Java'/><title type='text'>Delete a Substring From a String Using Java</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;b style="color: #20124d;"&gt;Task:- Delete a substring from a String.&lt;/b&gt;&lt;br /&gt;&lt;b style="color: #20124d;"&gt;Solution: There are two approaches for the same. We might need to delete a specific substring from the String, or we might need to delete a substring using the index positions. Both the approaches are shown below:- &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;i style="color: #4c1130;"&gt;Delete a specific substring from a string. The below code deletes the word "substring" from the original String. &lt;/i&gt;&lt;br /&gt;The code is given below:-&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;package javaTest1;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;//Delete using the name of the substring to be deleted&lt;br /&gt;&amp;nbsp;public class DeleteSubString1 {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public static void main(String[] args) {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; String oldStr = "Hello, this is the string from which a substring will be deleted";&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; String delStr = "substring";&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; String newStr;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newStr = oldStr.replace(delStr, "");&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(oldStr);&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(newStr);&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp;}&lt;/div&gt;&lt;br /&gt;When the above code is executed the output is:-&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;Hello, this is the string from which a substring will be deleted&lt;br /&gt;&amp;nbsp;Hello, this is the string from which a&amp;nbsp; will be deleted&lt;/div&gt;&lt;div style="background-color: #999999;"&gt;&lt;/div&gt;&lt;div style="background-color: #999999;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;i style="color: #4c1130;"&gt;Delete a substring from a string using index positions. The below code deletes the word "substring" from the original String based on the index positions provided.&lt;/i&gt;&lt;br /&gt;The code is given below:-&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;package javaTest1;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;//Delete using the index positions to be deleted&lt;br /&gt;&amp;nbsp;public class DeleteSubString2 {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /**&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;* @param args&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;*/&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String[] args) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String oldStr = "Hello, this is the string from which a substring will be deleted";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String delStr;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String newStr;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; delStr = oldStr.substring(39, 48);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; newStr = oldStr.replace(delStr, "");&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(oldStr);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(newStr);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;}&lt;/div&gt;&lt;div style="background-color: #999999;"&gt;&lt;/div&gt;&lt;div style="background-color: #999999;"&gt;&lt;/div&gt;&lt;br /&gt;When the above code is run, the output is:-&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;Hello, this is the string from which a substring will be deleted&lt;br /&gt;&amp;nbsp;Hello, this is the string from which a&amp;nbsp; will be deleted&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: white; color: #4c1130;"&gt;&lt;span style="font-size: medium;"&gt;&lt;b&gt;Related Articles&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white;"&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/length-of-string-java-program.html"&gt;Java String Length Program&lt;/a&gt;&lt;/div&gt;&lt;div style="background-color: white;"&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/reverse-string-java-program.html"&gt;Reverse a String in Java&lt;/a&gt;&lt;/div&gt;&lt;a href="http://javacodeonline.blogspot.com/2010/12/substring-index-out-of-range-or.html"&gt;Substring Index Out of Range Exception &lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2010/12/search-and-replace-substring-in-java.html"&gt;Search and Replace a Substring in Java Example &lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-2273726918253437079?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/2273726918253437079/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2012/01/delete-substring-from-string-using-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/2273726918253437079'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/2273726918253437079'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2012/01/delete-substring-from-string-using-java.html' title='Delete a Substring From a String Using Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-4562116029457112490</id><published>2011-08-17T01:04:00.000+05:30</published><updated>2011-08-17T01:04:11.742+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Notes Lesson'/><title type='text'>Java Interview Notes Lesson 1</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;These notes below are aimed to be a quick reference to any one gearing for a Java Interview. I have broken the series in parts, and this is part one of the tutorial lesson.&lt;br /&gt;&lt;br /&gt;&lt;div style="color: #4c1130;"&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Classes&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;A source code file can have only one public class.&lt;/li&gt;&lt;li&gt;If the source file contains a public class, the filename must match the public class name.&lt;/li&gt;&lt;li&gt;There can be more than one nonpublic class in a file.&lt;/li&gt;&lt;li&gt;Files with no public classes have no naming restrictions.&lt;/li&gt;&lt;li&gt;Classes can also be final or abstract, but not both at the same time.&lt;/li&gt;&lt;li&gt;Classes can have only public or default access.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;A class with default access can be seen only by classes within the same package.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;A class with public access can be seen by all classes from all packages &lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;&lt;span style="color: #4c1130;"&gt;Local Variables&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size: large;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="color: black;"&gt;Local variables can not have &lt;i&gt;access modifiers&lt;/i&gt;, and final is the only modifier applicable for them.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div style="color: #4c1130;"&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Interface&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;&lt;span style="font-size: large;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="color: black;"&gt;Interface methods are by default public and abstract. Explicit declaration of these modifiers is optional.&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size: large;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="color: black;"&gt;Interfaces can have variables declared which are by implicitly constants as they are always implicitly&amp;nbsp; public, static, and final.&lt;/span&gt;&lt;/span&gt;&lt;b&gt; &lt;/b&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div style="color: #4c1130;"&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Polymorphism&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;&lt;i&gt;&lt;span style="font-size: small;"&gt;The reference variable's type (not the object's type), determines which methods can be called.&lt;/span&gt;&lt;span style="font-size: large;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="color: #4c1130;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #4c1130;"&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/i&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size: large;"&gt;&lt;i&gt;&lt;span style="font-size: small;"&gt;&lt;span style="color: black;"&gt;Object type (not the reference variable's type), determines which overridden method is used at runtime.&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;b&gt;&lt;span style="color: #4c1130;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;&lt;span style="color: #4c1130;"&gt;Some Pointer Notes:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;&lt;span style="color: #4c1130;"&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size: large;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="color: black;"&gt;&lt;span style="font-size: small;"&gt;Abstract class cannot be instantiated&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;.&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size: large;"&gt;&lt;span style="font-size: small;"&gt;Final class cannot be subclassed.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size: large;"&gt;&lt;span style="font-size: small;"&gt;Private instance variables and methods are not visible to subclass, so they cannot be inherited.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size: large;"&gt;&lt;span style="font-size: small;"&gt;Final methods cannot be overridden in a subclass.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size: large;"&gt;&lt;span style="font-size: small;"&gt;Abstract classes have constructors that are called when a concrete subclass is instantiated.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size: large;"&gt;&lt;span style="font-size: small;"&gt; Interfaces do not have constructors.&lt;/span&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-4562116029457112490?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/4562116029457112490/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2011/08/java-interview-notes-lesson-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/4562116029457112490'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/4562116029457112490'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2011/08/java-interview-notes-lesson-1.html' title='Java Interview Notes Lesson 1'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-6501901470982596170</id><published>2011-08-11T04:02:00.036+05:30</published><updated>2011-08-11T04:15:31.352+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java on Ubuntu'/><title type='text'>Enabling Java in Ubuntu and Mozilla, Jar execution</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Hi folks.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;Today's Aim &lt;/span&gt;&lt;br /&gt;&lt;ol style="color: #741b47; text-align: left;"&gt;&lt;li&gt;&lt;i&gt;Enable Java in Ubuntu 11. &lt;/i&gt;&lt;/li&gt;&lt;li&gt;&lt;i&gt;Execute Applets in Mozilla in Ubuntu, adding the Java plug-in to Mozilla Firefox in Ubuntu.&lt;/i&gt;&lt;/li&gt;&lt;li&gt;&lt;i&gt;Execute Jar files directly in Ubuntu for which we do not have execute access.&lt;/i&gt;&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;I have been working on Java for a long time on Windows systems. Yesterday I was giving a try on Ubuntu and really felt the pain of getting Java up in Ubuntu. So I decided to dot my learning in this article.&lt;br /&gt;&lt;br /&gt;&lt;div style="color: #741b47;"&gt;&lt;b&gt;Task 1: Enable Java in Ubuntu 11&lt;/b&gt;&lt;/div&gt;Ubuntu comes with an open jdk for running Java. We need to install it, or else we may get it from Sun Microsystems (Now Oracle) also. I preferred the open-jdk as it was much easier to install and get running.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Steps:&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;&lt;ul style="color: #073763; text-align: left;"&gt;&lt;li&gt;Open Terminal&lt;/li&gt;&lt;/ul&gt;&lt;ul style="color: #073763; text-align: left;"&gt;&lt;li&gt;Type:&lt;i&gt; java -version&lt;/i&gt;. This will give the list of packages containg java.I got the below listing on my machine.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: left;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #4c1130;"&gt;$ java -version&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #4c1130; text-align: left;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; The program 'java' can be found in the following packages:&lt;/div&gt;&lt;div style="color: #4c1130; text-align: left;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * gcj-4.4-jre-headless&lt;/div&gt;&lt;div style="color: #4c1130; text-align: left;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * gcj-4.5-jre-headless&lt;/div&gt;&lt;div style="color: #4c1130; text-align: left;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * openjdk-6-jre-headless&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;span style="color: #4c1130;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Try: sudo apt-get install &lt;/span&gt;&lt;selected package=""&gt;&lt;br /&gt;&lt;/selected&gt;&lt;/div&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;&lt;selected package=""&gt; &lt;span style="color: #073763;"&gt;Select the openjdk to be installed. My machine's screen text is below:&lt;/span&gt;&lt;/selected&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style="color: #073763; text-align: left;"&gt;&lt;selected package=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #4c1130;"&gt;$ sudo apt-get install openjdk-6-jre-headless&lt;/span&gt;&lt;br /&gt;&lt;/selected&gt;&lt;/div&gt;&lt;ul style="color: #073763; text-align: left;"&gt;&lt;li&gt;&lt;selected package=""&gt; This will install Java in your Ubuntu machine.&lt;/selected&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: left;"&gt;&lt;selected package=""&gt; &lt;br /&gt;&lt;b style="color: #4c1130;"&gt;Task 2: Execute Applets in Mozilla in Ubuntu, adding the Java plug-in to Mozilla Firefox in Ubuntu.&lt;/b&gt;&lt;br /&gt;For enabling Java in Mozilla Firefox in Ubuntu so that it can run Java Applets, follow the below steps.&lt;/selected&gt;&lt;/div&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;&lt;selected package=""&gt; &lt;span style="color: #073763;"&gt;Open Terminal&lt;/span&gt;&lt;/selected&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style="color: #073763; text-align: left;"&gt;&lt;selected package=""&gt; &lt;/selected&gt;&lt;/div&gt;&lt;ul style="color: #073763; text-align: left;"&gt;&lt;li&gt;&lt;selected package=""&gt; Install icedtea6-plugin. The screen-text from my machine is:&lt;/selected&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style="color: #073763; text-align: left;"&gt;&lt;selected package=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #4c1130;"&gt; $ sudo apt-get install icedtea6-plugin&lt;/span&gt;&lt;br /&gt;&lt;/selected&gt;&lt;/div&gt;&lt;ul style="color: #073763; text-align: left;"&gt;&lt;li&gt;&lt;selected package=""&gt; This will install the icedtea6-plugin on your Ubuntu Mozilla Firefox and will enable you to run Java Applets.&lt;/selected&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: left;"&gt;&lt;selected package=""&gt;  &lt;b style="color: #4c1130;"&gt;&amp;nbsp;&lt;/b&gt;&lt;/selected&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;selected package=""&gt;&lt;b style="color: #4c1130;"&gt;Task 3: Execute Jar files directly in Ubuntu for which we do not have execute access.&lt;/b&gt;&lt;br /&gt;This was the most tricky of all. I had a jar file which i made through my Windows login for which i do not have execute access on Ubuntu machine. I tried chmod, chown, manually changing the permissions, etc, but all failed. The trick that finally worked was with Terminal again.&lt;br /&gt;&lt;br /&gt;Use the following command to execute jar files in Ubuntu from Terminal.&lt;br /&gt;&lt;span style="color: #4c1130;"&gt;$ java -jar filename&lt;/span&gt;&lt;/selected&gt;&lt;br /&gt;&lt;selected package=""&gt;&lt;br /&gt;The screentext from my machine is:-&lt;br /&gt;&lt;span style="color: #4c1130;"&gt;$ java -jar HelloWorld.jar&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;the above jar is a Java Applet and it executed just perfectly fine on Ubuntu. I also heard about some software called Wine for the same purpose, but did not tried it, as my job got done with the Terminal.&lt;br /&gt;&lt;br /&gt;I hope the article will be useful to my readers. Will keep posting on more updates from my-side on this Java blog.&lt;br /&gt;&lt;br /&gt;&lt;/selected&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-6501901470982596170?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/6501901470982596170/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2011/08/enabling-java-in-ubuntu-and-mozilla-jar.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/6501901470982596170'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/6501901470982596170'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2011/08/enabling-java-in-ubuntu-and-mozilla-jar.html' title='Enabling Java in Ubuntu and Mozilla, Jar execution'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-4360995786181011740</id><published>2010-12-13T03:15:00.002+05:30</published><updated>2010-12-13T03:18:19.278+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='String In Java'/><title type='text'>Java Substring Compare Example</title><content type='html'>Welcome back to &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Today's tutorial discusses comparison of a substring with other strings which is often required in Java programs.&lt;br /&gt;&lt;br /&gt;In my last project I used to receive a large String message from a JMS sender via MQ. I was supposed to extract substrings from that original String using already known starting and ending index values. If the substring found matches the substring required, then the comparison is successful.&lt;br /&gt;&lt;br /&gt;Today's example is based on the above process of comparison and matching the substrings. &lt;br /&gt;&lt;br /&gt;&lt;div style="color: #4c1130;"&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Compare a substring &lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;b style="color: #20124d;"&gt;Task:- Extract a substring from a string starting at index value 5 and ending at index value 9. Compare it with the word "test", if a match occurs then display success else display no match.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The code is given below:-&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; package JavaTest1;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; class TestIntToString {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String[] args) {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String subStr = null;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // Suppose this is the initial String,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // we may also get this String from&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // the user or another external source&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String str = "I am testing substring comparision";&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // This is the word we are looking for in the&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // above string&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String strCompare = "test";&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // The starting Index value is&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; int startIndexVal = 5;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // The ending index value is&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; int endIndexVal = 9;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // Extract the substring in subStr&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; subStr = str.substring(startIndexVal, endIndexVal);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // Compare the subStr with strCompare&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (subStr.equals(strCompare)) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("Match Found in comparison, Success");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } else {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("No Match found in comparison, Faliure");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/div&gt;&lt;br /&gt;When the above code is executed, the output is:-&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Match Found in comparison, Success&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="color: #4c1130;"&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Related Articles&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;a href="http://javacodeonline.blogspot.com/2010/12/search-and-replace-substring-in-java.html"&gt;Search and Replace a Substring in Java Example&lt;/a&gt;&lt;br /&gt;&lt;div style="background-color: white;"&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/08/convert-int-to-string-in-java-code.html"&gt;Convert int to String in Java&lt;/a&gt;&lt;/div&gt;&lt;div style="background-color: white;"&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/length-of-string-java-program.html"&gt;Java String Length Program&lt;/a&gt;&lt;/div&gt;&lt;div style="background-color: white;"&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/reverse-string-java-program.html"&gt;Reverse a String in Java&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-4360995786181011740?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2010/12/java-substring-compare-example.html' title='Java Substring Compare Example'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/4360995786181011740/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2010/12/java-substring-compare-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/4360995786181011740'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/4360995786181011740'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2010/12/java-substring-compare-example.html' title='Java Substring Compare Example'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-7380751492466137768</id><published>2010-12-12T18:55:00.003+05:30</published><updated>2010-12-12T19:00:15.685+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='String In Java'/><title type='text'>Substring Index Out of Range or StringIndexOutOfBoundsException Java</title><content type='html'>While working with Strings in Java, we may get &lt;b&gt;StringIndexOutOfBoundsException &lt;/b&gt;for the substring() method of the &lt;a href="http://javacodeonline.blogspot.com/2010/12/string-in-java.html"&gt;String&lt;/a&gt; class. This is to signify that the Index specified is out of the range.&lt;br /&gt;&lt;br /&gt;For substring() method, we need to provide the start and end index values or only the start index value. The &lt;a href="http://javacodeonline.blogspot.com/2010/12/java-substring-index.html"&gt;index value of String in Java&lt;/a&gt; starts from 0 and goes till one less then the string length. Substring method uses this information to extract a part of the original String.&lt;br /&gt;&lt;br /&gt;While extracting a part of the String, if the starting index value is negative, or the end index value is greater then the String length. If such a case occurs then we get an &lt;b&gt;StringIndexOutOfBoundsException, &lt;/b&gt;it is a message from the &lt;a href="http://javacodeonline.blogspot.com/2008/12/what-is-java-virtual-machinejvm.html"&gt;JVM&lt;/a&gt; to tell us that the index is out of range.&lt;br /&gt;&lt;br /&gt;The below examples clarify it better:-&lt;br /&gt;&lt;br /&gt;&lt;div style="color: #4c1130;"&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Reasons for StringIndexOutOfBoundsException&lt;/b&gt;&lt;span style="font-size: small;"&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="color: black;"&gt;The below code explains the occurrence of the StringIndexOutOfBoundsException.&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; package JavaTest1;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public class IndexOutOfRangeExample {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;/**&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; * @param args&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; */&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public static void main(String[] args) {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;String str = "Testing a string for Index out of range";&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;System.out.println("The original String is: " + str);&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;System.out.println("The length of the String is: " + str.length());&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span style="background-color: #a64d79;"&gt;str = str.substring(-1);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;System.out.println("The modified String is: " + str);&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/div&gt;&lt;br /&gt;The above code will result in a run time exception. The output is shown below:-&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; The original String is: Testing a string for Index out of range&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; The length of the String is: 39&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; at java.lang.String.substring(Unknown Source)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; at java.lang.String.substring(Unknown Source)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; at JavaTest1.IndexOutOfRangeExample.main(IndexOutOfRangeExample.java:14)&lt;/div&gt;&lt;div style="background-color: white;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="background-color: white;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="background-color: white;"&gt;&amp;nbsp;The line &lt;span style="background-color: #a64d79;"&gt;str = str.substring(-1);&lt;span style="background-color: white;"&gt; is the root cause of this error. We will get the same exception if the line is replaced with any of the below line examples:-&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white;"&gt;&lt;ul style="color: #4c1130;"&gt;&lt;li&gt;&lt;span style="background-color: #a64d79;"&gt;&lt;span style="background-color: white;"&gt;&amp;nbsp;str = str.substring(0, 40);&amp;nbsp;&amp;nbsp; //The length of the string considered is 39, so anything greater will cause index out of range.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="background-color: #a64d79;"&gt;&lt;span style="background-color: white;"&gt;str = str.substring(40, 49); &amp;nbsp; //The start index value is larger then the length of the String, so again the exception will be thrown.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="background-color: #a64d79;"&gt;&lt;span style="background-color: white;"&gt;str = str.substring(40);&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="background-color: #a64d79;"&gt;&lt;span style="background-color: white;"&gt;str = str.substring(-58); //&amp;nbsp; Negative value for start index is cause of exception.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="background-color: #a64d79;"&gt;&lt;span style="background-color: white;"&gt;&amp;nbsp;To avoid this exception, make sure that you stay within the bounds of the String length.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white;"&gt;&lt;span style="background-color: #a64d79;"&gt;&lt;span style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white; color: #4c1130;"&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Related Articles&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white;"&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/08/convert-int-to-string-in-java-code.html"&gt;Convert int to String in Java&lt;/a&gt;&lt;/div&gt;&lt;div style="background-color: white;"&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/09/convert-int-to-string-using-wrapper-in.html"&gt;Convert int to String using Wrapper in Java&lt;/a&gt;&lt;/div&gt;&lt;div style="background-color: white;"&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/length-of-string-java-program.html"&gt;Java String Length Program&lt;/a&gt;&lt;/div&gt;&lt;div style="background-color: white;"&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/reverse-string-java-program.html"&gt;Reverse a String in Java&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-7380751492466137768?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2010/12/substring-index-out-of-range-or.html' title='Substring Index Out of Range or StringIndexOutOfBoundsException Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/7380751492466137768/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2010/12/substring-index-out-of-range-or.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/7380751492466137768'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/7380751492466137768'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2010/12/substring-index-out-of-range-or.html' title='Substring Index Out of Range or StringIndexOutOfBoundsException Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-4088039631084627999</id><published>2010-12-12T15:35:00.002+05:30</published><updated>2010-12-12T15:53:58.802+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='String In Java'/><title type='text'>Search and Replace a Substring in Java Example</title><content type='html'>Welcome back to&lt;a href="http://javacodeonline.blogspot.com/"&gt; Java Code Online&lt;/a&gt;. Very often in programming we need to search and replace particular instances of substring in a String. There are multiple ways of doing it, and the Java String class provides many methods and ways to doing the same. I am presenting some of the most common ways to achieve the same.&lt;br /&gt;&lt;br /&gt;&lt;div style="color: #4c1130;"&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Using substring() method&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;The substring() method could be used to search and replace a substring in the main String. The below example searches and replaces the first instance of a substring in the original String.&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&lt;/div&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; package JavaTest1;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //This class search and replace the first &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //instance of a String in the main String.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class SearchReplaceSubString {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; /**&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;* @param args&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;*/&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String[] args) {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String str = "This is a search and replace of substring example";&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("The original String is: " + str);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // We want to look for the String "search" and replace it with "find"&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String searchQuery = "search";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String replaceWord = "find";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; int startIndexVal = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; int endIndexVal = 0;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // look for the starting index of searchQuery&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; startIndexVal = str.indexOf(searchQuery);&lt;/div&gt;&lt;div style="background-color: #999999;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // evaluate the ending Index of searchQuery&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; endIndexVal = startIndexVal + searchQuery.length();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // Form the string again using the substring() method&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; str = str.substring(0, startIndexVal) + replaceWord&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; + str.substring(endIndexVal);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("The modified String is: " + str);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;&lt;br /&gt;When the above code is executed the output is:-&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; The original String is: This is a search and replace of substring example&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; The modified String is: This is a find and replace of substring example&lt;/div&gt;&lt;br /&gt;&lt;div style="color: #4c1130;"&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Using replace() method&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;The String Class provides a very effective way to replace all the occurrences of a substring in the main string&lt;br /&gt;It uses the replace() method of the String class. The example below looks for a substring and replaces all the occurrences of that substring with a new substring.&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; package JavaTest1;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //This class search and replace all the &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //instances of a substring in the main String.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class SearchReplaceSubString {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; /**&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;* @param args&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;*/&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String[] args) {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String str = "Using Replace method for the searching and searching and replacing of a substring in a String";&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("The original String is: " + str);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // We want to look for the String "search" and replace it with "find"&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String searchWord = "search";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String replaceWord = "find";&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // Replace all the occurrences of the searchWord with the replaceWord&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; str = str.replace(searchWord, replaceWord);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("The modified String is: " + str);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;&lt;br /&gt;When the example code is run, then the output is:-&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The original String is: Using Replace method for the searching and searching and replacing of a substring in a String&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;The modified String is: Using Replace method for the finding and finding and replacing of a substring in a String&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: white;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="background-color: white; color: #4c1130;"&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Related Articles&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white;"&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/08/convert-int-to-string-in-java-code.html"&gt;Convert int to String in Java&lt;/a&gt;&lt;/div&gt;&lt;div style="background-color: white;"&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/09/convert-int-to-string-using-wrapper-in.html"&gt;Convert int to String using Wrapper in Java&lt;/a&gt;&lt;/div&gt;&lt;div style="background-color: white;"&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/length-of-string-java-program.html"&gt;Java String Length Program&lt;/a&gt;&lt;/div&gt;&lt;div style="background-color: white;"&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/reverse-string-java-program.html"&gt;Reverse a String in Java&lt;/a&gt;&lt;/div&gt;&lt;div style="background-color: white;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="background-color: white;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-4088039631084627999?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2010/12/search-and-replace-substring-in-java.html' title='Search and Replace a Substring in Java Example'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/4088039631084627999/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2010/12/search-and-replace-substring-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/4088039631084627999'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/4088039631084627999'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2010/12/search-and-replace-substring-in-java.html' title='Search and Replace a Substring in Java Example'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-818636412578253856</id><published>2010-12-12T13:43:00.002+05:30</published><updated>2010-12-12T23:33:04.591+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='String In Java'/><title type='text'>Java Substring Index</title><content type='html'>Welcome back to &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. The index of java substring is used to retrieve the starting and ending value of the substring in the original String. Understanding how the concept of index works in substring is vital to get a hold of this Java string method.&lt;br /&gt;&lt;br /&gt;&lt;div style="color: #4c1130;"&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Index Value of Java Substring&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;When we use a substring to extract a part of the String, then we we provide the starting index value. We may use both the starting and ending value of index also.&lt;br /&gt;&lt;br /&gt;The index value of a String stats from 0 and goes till one less then the length of the String. The below diagram clears this.&lt;br /&gt;&lt;br /&gt;Suppose that we have a string called:-&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; String str = "index value of substring";&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;In memory the string is stored as:-&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_-Gl5MQel5-0/TQR9dHCQZ4I/AAAAAAAAAFA/xJRQJU27ltc/s1600/substring-index.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="77" src="http://4.bp.blogspot.com/_-Gl5MQel5-0/TQR9dHCQZ4I/AAAAAAAAAFA/xJRQJU27ltc/s400/substring-index.JPG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;So the string is stored starting at an index value of 0 to one less then the string length. Now there are two substring() operation possible on this. They are explained below:-&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #4c1130; font-size: large;"&gt;&lt;b&gt;substring(startIndex)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;When we want to retrive a substring from the original string, such that it starts from some index vale of the string and goes till the end of the String, then we use this method.&lt;br /&gt;&lt;br /&gt;Using the above example, suppose we say:-&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; String subStr1 = str.substring(6); &lt;/div&gt;&lt;br /&gt;Then the output is:-&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value of substring&lt;/div&gt;&lt;div style="background-color: #999999;"&gt;&lt;/div&gt;&lt;br /&gt;The below diagram explains this:-&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_-Gl5MQel5-0/TQSAgrBqAnI/AAAAAAAAAFI/PSK3Q8dCCyE/s1600/substring-index-value11.JPG" imageanchor="1" style="margin-left: 0em; margin-right: 1em;"&gt;&lt;img border="0" height="87" src="http://2.bp.blogspot.com/_-Gl5MQel5-0/TQSAgrBqAnI/AAAAAAAAAFI/PSK3Q8dCCyE/s400/substring-index-value11.JPG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;So the method substring(startIndex) includes the starting index value while extracting the substring.&lt;br /&gt;&lt;span style="color: #4c1130; font-size: large;"&gt;&lt;b&gt; &lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #4c1130; font-size: large;"&gt;&lt;b&gt;substring(startIndex, endIndex)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: black; font-size: small;"&gt;This method is used to extract a part of the string starting from the startIndex value and ending at the endIndex value.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: black; font-size: small;"&gt;Using the same example, suppose we say:-&lt;/span&gt;&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&lt;span style="color: black; font-size: small;"&gt;&amp;nbsp;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; String subStr1 = str.substring(6, 18);&amp;nbsp;&lt;/div&gt;&lt;div style="background-color: #999999;"&gt;&lt;span style="color: #4c1130; font-size: large;"&gt;&lt;b&gt; &lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;Then the output is:-&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value of sub&lt;/div&gt;&lt;br /&gt;The below image explains this:-&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_-Gl5MQel5-0/TQSB4sCpIhI/AAAAAAAAAFM/CgLjTPS1SYY/s1600/substring-index-value12.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="87" src="http://4.bp.blogspot.com/_-Gl5MQel5-0/TQSB4sCpIhI/AAAAAAAAAFM/CgLjTPS1SYY/s400/substring-index-value12.JPG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;So the method substring(startIndex, endIndex) includes the starting Index value but excludes the ending Index value.&lt;br /&gt;&lt;br /&gt;&lt;div style="color: #4c1130;"&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Related Articles&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;a href="http://javacodeonline.blogspot.com/2010/12/substring-index-out-of-range-or.html"&gt;Substring Index Out of Range Exception &lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/08/convert-int-to-string-in-java-code.html"&gt;Convert int to String in Java&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/09/convert-int-to-string-using-wrapper-in.html"&gt;Convert int to String using Wrapper in Java&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/length-of-string-java-program.html"&gt;Java String Length Program&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/reverse-string-java-program.html"&gt;Reverse a String in Java&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-818636412578253856?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2010/12/java-substring-index.html' title='Java Substring Index'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/818636412578253856/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2010/12/java-substring-index.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/818636412578253856'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/818636412578253856'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2010/12/java-substring-index.html' title='Java Substring Index'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_-Gl5MQel5-0/TQR9dHCQZ4I/AAAAAAAAAFA/xJRQJU27ltc/s72-c/substring-index.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3416407328338427543.post-7324925853886095540</id><published>2010-12-12T01:13:00.005+05:30</published><updated>2012-01-22T03:16:48.484+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='String In Java'/><title type='text'>Java Substring Examples</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div style="font-family: inherit;"&gt;Welcome back to &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Today we would be discussing examples of Java substring() method. Substring is a method of the String class in Java. It is used to extract a part of the original String. The examples for Java substring() function are shown below.&lt;/div&gt;&lt;div style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: inherit;"&gt;&lt;b&gt;&lt;span style="font-size: large;"&gt;&lt;span style="color: #4c1130;"&gt;Get a character from a String using substring()&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: inherit;"&gt;This example extracts a character from the specified index value using the substring method.&lt;/div&gt;&lt;div style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="background-color: #999999; font-family: inherit;"&gt;&lt;/div&gt;&lt;div style="background-color: #999999; font-family: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; package JavaTest1;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Get a character at a specified index using substring&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class SubStringChar {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String[] args) {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String str = "substring() method example";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String singleStr;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; singleStr = str.substring(5, 6);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(singleStr);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;&lt;div style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: inherit;"&gt;When the above code is executed, the output is:-&lt;/div&gt;&lt;div style="background-color: #999999; font-family: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r&lt;/div&gt;&lt;div style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: inherit;"&gt;The above code is useful when we want to extract a single character from a string. There are other methods also in the String class which can perform the above operation like charAt().&lt;/div&gt;&lt;div style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #4c1130; font-family: inherit;"&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Get a substring from a string using the substring() method&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: inherit;"&gt;The above example could be modified to extract a substring from the original String. The code is show below:-&lt;/div&gt;&lt;div style="font-family: inherit;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="background-color: #999999; font-family: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; package JavaTest1;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class SubStringPart {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String[] args) {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String str = "substring() method example";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String singleStr;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; singleStr = str.substring(5, 16);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(singleStr);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;&lt;div style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: inherit;"&gt;The output of the above code is:-&lt;/div&gt;&lt;div style="background-color: #999999; font-family: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ring() meth&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;A very useful example when we want to extract some part of a string.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #4c1130; font-size: large;"&gt;&lt;b&gt;Search for a file type using substring() method&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="font-family: inherit;"&gt;Suppose that we want to search a directory for a particular file type. We have many files in the directory, but we want a single file that is of a particular type (for example "pdf"). There are other files also in the directory which are of other file types(for example html, ppt, xml, xls, etc.).&lt;br /&gt;&lt;br /&gt;The code below searches the directory for a &lt;b&gt;pdf &lt;/b&gt;file and returns the name of the first pdf file found. This name could be used for &lt;a href="http://javacodeonline.blogspot.com/2009/09/java-code-to-read-file.html"&gt;reading the file in java&lt;/a&gt;, or for checking that a particular file type is present or not.&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&lt;/div&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; package JavaTest1;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; import java.io.File;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class SearchSubString {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; private static final String fileExtensionDesired = "pdf";&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String[] args) {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String fileName = null;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String fileExtension = null;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String fileFound = null;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; int indexVal = 0;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // Note the "\\" used in the path of the directory instead of "\",&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // this is required to read the path in the String format.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; File f = new File("D:\\JavaCodeFile");&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // Check if the directory exists&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (f.exists()) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; /*&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;* Retrieve all the files in the directory in the form of a File&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;* Array&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;*/&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; File[] fileArray = f.listFiles();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 0; i &amp;lt; fileArray.length; i++) {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // Get the file name and in a String&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; fileName = fileArray[i].getName();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // Get the index value of extension of the file&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; indexVal = fileName.lastIndexOf(".");&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // Extension of the file starts from indexVal + 1&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; fileExtension = fileName.substring(indexVal + 1);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (fileExtension.equals(fileExtensionDesired)) {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; fileFound = fileName;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // Since we have found the first file, we can exit the&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // for loop&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } else {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; fileFound = null;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; continue;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // if the file is found&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (null != fileFound) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // Display the name of the pdf file we were looking&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("Got the desired file: " + fileFound);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("No file found with the extension: " + fileExtensionDesired);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } else {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("The directory does not exist");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;&lt;div style="background-color: #999999;"&gt;&lt;/div&gt;&lt;br /&gt;When the above code is run on my machine, then the output is:-&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Got the desired file: JavaString.pdf&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;That's all from my side for the day. I hope the substring examples were helpful. Keep buzzing Java Code Online.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #4c1130; font-size: large;"&gt;&lt;b&gt;Related Readings&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2010/12/java-substring-index.html"&gt;Java Substring Index&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2010/12/search-and-replace-substring-in-java.html"&gt;Search and Replace a Substring in Java Example&amp;nbsp;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2010/12/java-substring-compare-example.html"&gt;Java Substring Compare Example&amp;nbsp;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2012/01/delete-substring-from-string-using-java.html"&gt;Delete a Substring From a String Using Java&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;&lt;b style="color: #4c1130;"&gt;Related Articles &lt;/b&gt;&lt;/span&gt;&lt;span style="color: #4c1130; font-size: large;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/08/convert-int-to-string-in-java-code.html"&gt;Convert int to String in Java&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/09/convert-int-to-string-using-wrapper-in.html"&gt;Convert int to String using Wrapper in Java&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/length-of-string-java-program.html"&gt;Java String Length Program&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/reverse-string-java-program.html"&gt;Reverse a String in Java&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-7324925853886095540?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2010/12/java-substring-examples.html' title='Java Substring Examples'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/7324925853886095540/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2010/12/java-substring-examples.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/7324925853886095540'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/7324925853886095540'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2010/12/java-substring-examples.html' title='Java Substring Examples'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-3319295682466103704</id><published>2010-12-11T02:30:00.007+05:30</published><updated>2010-12-12T18:58:27.893+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='String In Java'/><title type='text'>Substring in Java</title><content type='html'>Substring is one of the most commonly used methods of the String class. Is is used for extracting a portion of the original string. This method is very useful when we are dealing with file names and extensions and want to extract some part of the Staring value.&lt;br /&gt;&lt;br /&gt;&lt;div style="color: #4c1130;"&gt;&lt;span style="font-size: large;"&gt;Understanding substring()&lt;/span&gt;&lt;/div&gt;For a good understanding of substring(), it is essential that we first see how Java stores the String in memory. For example if we say that:-&lt;br /&gt;&lt;div style="background-color: #999999; color: black;"&gt;String str = "substring() is a method";&lt;/div&gt;&lt;br /&gt;then in the memory the above String is stored as:-&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_-Gl5MQel5-0/TQKJ3KfPKzI/AAAAAAAAAE0/1lo94T10wLY/s1600/String-in-memory.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/_-Gl5MQel5-0/TQKJ3KfPKzI/AAAAAAAAAE0/1lo94T10wLY/s1600/String-in-memory.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;from the above diagram it is clear that the indexing of Strings always start from zero, and goes till one less then the String length.&lt;br /&gt;&lt;br /&gt;Substring uses this information to retrieve a part of the original string by providing the (starting) or (starting,ending) index values. The numbers mentioned in the above diagram are the index values for the characters of that String.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #4c1130; font-size: large;"&gt;Syntax of substring() in Java&lt;/span&gt;&lt;br /&gt;Substring comes in two flavor in Java. The two syntax of the method are:-&lt;br /&gt;&lt;br /&gt;&lt;b&gt;public String substring(int beginIndex)&lt;/b&gt;&lt;br /&gt;Used to extract a portion of the String. The substring returned by this method starts from the character specified by the beginIndex value, and it ends till the last character of the original String.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;public String substring(int beginIndex, int endIndex)&lt;/b&gt;&lt;br /&gt;This method extracts a portion of the String. The substring returned by this method starts from the character specified by the beginIndex value and ends at the character specified by the endIndex value.&lt;br /&gt;&lt;br /&gt;&lt;div style="color: #4c1130;"&gt;&lt;span style="font-size: large;"&gt;Exceptions for substring()&lt;/span&gt;&lt;/div&gt;In case the starting Index value or the end Index value in the substring() method is out of the range of the String length, then the &lt;a href="http://javacodeonline.blogspot.com/2008/12/what-is-java-virtual-machinejvm.html"&gt;Java Virtual Machine&lt;/a&gt; throws a &lt;b&gt;IndexOutOfBoundsException&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;This exception shows that the Index value provided for the substring() method is either negative or larger than the String length.&lt;br /&gt;&lt;br /&gt;&lt;div style="color: #4c1130;"&gt;&lt;span style="font-size: large;"&gt;substring() Examples&lt;/span&gt;&lt;/div&gt;&lt;b&gt;Example 1&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt; &lt;/b&gt;&lt;br /&gt;&lt;div style="background-color: #999999; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; package JavaTest1;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class StringTest {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String[] args) {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String str = "substring() is a method";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String subStr;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style="color: #351c75;"&gt;&amp;nbsp; &lt;span style="color: black;"&gt;subStr = str.substring(5);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(subStr);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/div&gt;&lt;br /&gt;When the above code is executed, the output is:-&lt;br /&gt;&lt;div style="background-color: #999999; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ring() is a method&lt;/div&gt;&lt;br /&gt;The below diagram explains the output received after the substring() operation.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_-Gl5MQel5-0/TQKRSLMLmwI/AAAAAAAAAE4/jwppMgP5y58/s1600/substring-java-1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/_-Gl5MQel5-0/TQKRSLMLmwI/AAAAAAAAAE4/jwppMgP5y58/s1600/substring-java-1.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Example 2&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #999999; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; package JavaTest1;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class StringTest {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String[] args) {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String str = "substring() is a method";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String subStrBeginEnd;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; subStrBeginEnd = str.substring(5, 21);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(subStrBeginEnd);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;&lt;br /&gt;On execution of the above code, the output is:- &lt;br /&gt;&lt;div style="background-color: #999999; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ring() is a meth&lt;/div&gt;&lt;br /&gt;The substring example is further explained by the diagram below.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_-Gl5MQel5-0/TQKT3erBtnI/AAAAAAAAAE8/XRQodclX54Q/s1600/substring-java-2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/_-Gl5MQel5-0/TQKT3erBtnI/AAAAAAAAAE8/XRQodclX54Q/s1600/substring-java-2.JPG" /&gt;&amp;nbsp;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="color: #4c1130;"&gt;&lt;i&gt;Note:-The above diagram clears that the substring() method includes the starting index, but excludes the end index.&lt;/i&gt;&lt;/div&gt;&lt;br /&gt;Do raise any queries if you need explanation on any part.&lt;br /&gt;&lt;br /&gt;&lt;div style="color: #4c1130;"&gt;&lt;span style="font-size: large;"&gt;Related Readings&lt;/span&gt;&lt;/div&gt;&lt;a href="http://javacodeonline.blogspot.com/2010/12/java-substring-examples.html"&gt;Java Substring Examples&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2010/12/java-substring-index.html"&gt;Java Substring Index&amp;nbsp;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2010/12/substring-index-out-of-range-or.html"&gt;Substring Index Out of Range Exception &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;&lt;span style="color: #4c1130;"&gt;Related Articles&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/08/convert-int-to-string-in-java-code.html"&gt;Convert int to String in Java&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/09/convert-int-to-string-using-wrapper-in.html"&gt;Convert int to String using Wrapper in Java&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/length-of-string-java-program.html"&gt;Java String Length Program&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/reverse-string-java-program.html"&gt;Reverse a String in Java&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-3319295682466103704?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2010/12/substring-in-java.html' title='Substring in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/3319295682466103704/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2010/12/substring-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3319295682466103704'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3319295682466103704'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2010/12/substring-in-java.html' title='Substring in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_-Gl5MQel5-0/TQKJ3KfPKzI/AAAAAAAAAE0/1lo94T10wLY/s72-c/String-in-memory.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3416407328338427543.post-3652737776974837879</id><published>2010-12-10T02:17:00.005+05:30</published><updated>2010-12-11T02:38:49.048+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='String In Java'/><title type='text'>String In Java</title><content type='html'>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_-Gl5MQel5-0/TQEvCO33epI/AAAAAAAAAEo/o9v8o5q0qmY/s1600/java-strings.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://1.bp.blogspot.com/_-Gl5MQel5-0/TQEvCO33epI/AAAAAAAAAEo/o9v8o5q0qmY/s200/java-strings.jpg" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;Strings are Immutable &lt;a href="http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Objects&lt;/a&gt; in Java. They are very commonly used in programs. The point that they are &lt;b&gt;immutable &lt;/b&gt;means that whenever we modify or concat the previous string, then a new String Object is created. Moreover Strings are not Garbage collected by the &lt;a href="http://javacodeonline.blogspot.com/2008/12/what-is-purpose-of-garbage-collection.html"&gt;garbage collector&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;When we create a String object then the &lt;a href="http://javacodeonline.blogspot.com/2008/12/what-is-java-virtual-machinejvm.html"&gt;Java Virtual Machine (JVM)&lt;/a&gt; puts that String in the String Pool. If there is some String already existing in the String pool with the same value, then the JVM don't create a duplicate of that previous String. It just simply refers our reference variable to that already existing entry.&lt;br /&gt;&lt;br /&gt;In Java programming we avoid using too many strings. the reason is that they are not garbage collected, and so when our programs are large, then the JVM ends up consuming lots of memory. This also makes the program execution slower.&lt;br /&gt;&lt;br /&gt;For example if we just go through the below Java code:-&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;String str = "abc";&lt;/div&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;for(int counter= 0; counter&amp;lt;10; counter++)&lt;/div&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;{&lt;/div&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; str = str + counter;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(str); &lt;/div&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;}&lt;/div&gt;&lt;br /&gt;What do you think will happen after the above code is executed. What we are doing is creating 11 different string objects. When the code is executed, the output is:-&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;abc0&lt;br /&gt;&amp;nbsp;abc01&lt;br /&gt;&amp;nbsp;abc012&lt;br /&gt;&amp;nbsp;abc0123&lt;br /&gt;&amp;nbsp;abc01234&lt;br /&gt;&amp;nbsp;abc012345&lt;br /&gt;&amp;nbsp;abc0123456&lt;br /&gt;&amp;nbsp;abc01234567&lt;br /&gt;&amp;nbsp;abc012345678&lt;br /&gt;&amp;nbsp;abc0123456789&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;So we created 11 strings including the first one "abc". And the main part is that all these strings are in existence in the String pool even after you used the "+" operator to modify them. In-fact we cannot modify Strings, we concat them and thereby create new Strings with the new value.&lt;br /&gt;&lt;br /&gt;It's for this reason that we use classes like &lt;b&gt;StringBuffer &lt;/b&gt;and &lt;b&gt;StringBuilder &lt;/b&gt;to do the appending operation. I will discuss StringBiffer and StringBuilder later.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #4c1130; font-size: large;"&gt;&lt;b&gt;Creation of a String in Java&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;The Java builders provide many Constructors to create a String. We can create a Java string simply by using the "new" keyword, since Strings are Objects in Java, and we can instantiate objects by using the "new" keyword.&lt;br /&gt;&lt;br /&gt;So the below code creates a Java String and assigns it a value:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;String str = new String ();&lt;/div&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;str = "I love Java";&lt;/div&gt;&lt;br /&gt;also this can be done by using a shorter way:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;String str = new String ("I love Java");&lt;/div&gt;&lt;br /&gt;both the code snippets do the same job of creating a new Java string and assigning it a value. Java provides an even better way of creating Strings:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;String str = "I love Java";&lt;/div&gt;&lt;br /&gt;Yes the above code did not used the "new" keyword, but does the same job. there are minor difference in the last method for creating Strings as compared to the previous ones.&lt;br /&gt;&lt;br /&gt;When we say&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;String str = "I love Java";&lt;/div&gt;here we create a reference variable called "str", we place a String Object called "I love Java" in the String pool&amp;nbsp; and link them. So this method resulted in generation of an Object in the String pool and a reference variable. But when we say:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;String str = new String ("I love Java"); &lt;/div&gt;here we create a reference variable called "str", we create a new Object on the Java heap(since we used the "new" keyword), and link them, finally we place the value Object "I love Java" on the String pool. So this method resulted in generation of two objects (one on the heap and the second on the String pool) and a reference variable.&lt;br /&gt;&lt;br /&gt;Clearly direct invocation is better since it resulted in creating lesser Objects.&lt;br /&gt;&amp;nbsp;&lt;b style="color: #4c1130;"&gt;&lt;span style="font-size: large;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;b style="color: #4c1130;"&gt;&lt;span style="font-size: large;"&gt;Methods in the String Class&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;Java provides multiple methods in the String class. These methods take care of almost any requirement we have regarding programming. The most commonly used and important methods of the String class are:-&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt;concat()&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;This method creates a new String with the value of the previous String appended to the new one.The usage of this method is shown below:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;String str = "Java is fun";&lt;br /&gt;&amp;nbsp;System.out.println(str.concat(" when you work hard") );&lt;/div&gt;&lt;br /&gt;The output is:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;Java is fun when you work hard&lt;/div&gt;&lt;br /&gt;&lt;b&gt;length()&lt;/b&gt;&lt;br /&gt;This method returns the number of characters in the String. though the String indexing start from zero, but still the length counting starts from one. So for the below code:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;String str = "Strings are intresting";&lt;/div&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;System.out.println( str.length());&lt;/div&gt;&lt;br /&gt;The output is:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;22&lt;/div&gt;&amp;nbsp;You may count yourself and check, don't forget to count the blank spaces in between, they are also characters and are therefore counted.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;substring()&lt;/b&gt;&lt;br /&gt;One of the most used method of the Java String class. It returns a part of the original String. It has two variations, they are substring(int begin) and substring(int begin, int end). The first one gives a sub part of the original string from the begin number till the end of the String. The second one is used to get a part of the original String from the begin number to the end number.&lt;br /&gt;&lt;br /&gt;For example consider the below code snippet:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;String str = "Strings are Immutable objects in Java";&amp;nbsp;&lt;/div&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;System.out.println(str.substring(12));&lt;/div&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;System.out.println(str.substring(12, 21));&lt;/div&gt;&lt;br /&gt;the output of the above code snippet is:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;Immutable objects in Java&lt;br /&gt;&amp;nbsp;Immutable&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;trim()&lt;/b&gt;&lt;br /&gt;This method removes blank (whitespaces) from starting and ending of the String. It does not interfere with any blank space in between the words of the String.&lt;br /&gt;&lt;br /&gt;Consider the below code snippet:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;String str = "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; trim&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; testing&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ";&lt;/div&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;System.out.println( str.trim()); &lt;/div&gt;&lt;br /&gt;the output of the above code snippet is:-&lt;br /&gt;&lt;span style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;trim&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; testing&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Note that the blank spaces at the start and end of the String are removed.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;equals()&lt;/b&gt;&lt;br /&gt;The most commonly used method to check the equality of two String Objects. Strings are compared using the equals() method since they are Objects and not primitives, Primitives are compared using "= =". The usage of equals() method is shown below:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String str = "Hello Java";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(str.equals("HeLLO JAVA"));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println( str.equals("Hello Java"));&lt;/div&gt;&lt;br /&gt;When this code is executed, the output is:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;false&lt;br /&gt;&amp;nbsp;true&lt;/div&gt;&lt;br /&gt;this shows that equals() is case sensitive.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;equalsIgnoreCase()&lt;/b&gt;&lt;br /&gt;When we want to compare two Strings irrespective of their being in uppercase or lowercase, then we use equalsIgnoreCase(). This method is not case sensitive. Consider the previous example with the equals() replaced with equalsIgnoreCase():-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String str = "Hello Java";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(str.equalsIgnoreCase("HeLLO JAVA"));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println( str.equalsIgnoreCase("Hello Java"));&lt;/div&gt;&lt;br /&gt;the output for this code is:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;true&lt;br /&gt;&amp;nbsp;true&lt;/div&gt;&lt;br /&gt;&lt;b&gt;replace()&lt;/b&gt;&lt;br /&gt;This method is used to replace any occurrence of a character with a new character. It is a handy method and is often used in String manipulation. The example is given below:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String str = "java sample source code example";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println( str.replace('a', 'b') );&lt;/div&gt;&lt;br /&gt;When executed the output is:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;jbvb sbmple source code exbmple&lt;/div&gt;&lt;br /&gt;&lt;b&gt;charAt()&lt;/b&gt;&lt;br /&gt;This method is used to retrieve a character at a particular index in the String. The method returns a single character which is at the specified index location in the original String. Consider the code below:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String str = "Java";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println( str.charAt(2) );&lt;/div&gt;&lt;br /&gt;The output for the above code is:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;v&lt;/div&gt;&lt;br /&gt;&lt;b&gt;toLowerCase()&lt;/b&gt;&lt;br /&gt;This is a useful method to convert all the characters in the string to lower case. All the charcacters which are in uppercase in the original string are converted to lowercase. The code explains it further:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String str = "Java Is An Interesting Language";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(str.toLowerCase());&lt;/div&gt;&lt;br /&gt;When executed the output is:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;java is an interesting language&lt;/div&gt;&lt;br /&gt;&lt;b&gt;toUpperCase()&lt;/b&gt;&lt;br /&gt;This is a useful method to convert all the characters in the string  to upper case. All the charcacters which are in lowercase in the  original string are converted to uppercase. The code explains it  further:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String str = "Java Is An Interesting Language";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(str.toUpperCase());&lt;/div&gt;&lt;br /&gt;When executed the output is:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;JAVA IS AN INTERESTING LANGUAGE&lt;/div&gt;&lt;br /&gt;&lt;b&gt;toString()&lt;/b&gt;&lt;br /&gt;This method simply returns the value of the string. Why would we need this method when we already have String? The answer is that this method is very useful when converting from StringBuffer to String and StringBuilder to String. The usage is shown below:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String str = "Java sample code";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(str.toString());&lt;/div&gt;&lt;br /&gt;When executed the output is:-&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;Java sample code&lt;/div&gt;&lt;br /&gt;I will discuss the StringBuilder and StringBuffer in my later articles.&lt;br /&gt;&lt;br /&gt;Java class has lots of other methods which are useful. You may get the entire listing at:-&lt;br /&gt;http://download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #4c1130; font-size: large;"&gt;&lt;b&gt;Java String Examples&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #4c1130; font-size: large;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="color: black;"&gt;I would discuss few Java String Examples to make the topic more clear.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="color: #4c1130; font-size: large;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="color: black;"&gt;Java String Example 1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;span style="color: #4c1130; font-size: large;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="color: black;"&gt; Task:- Conversion from an array of Strings to a single string using "," as a separator.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #4c1130; font-size: large;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="color: black;"&gt;The code is given below:-&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="background-color: #7f6000;"&gt;&lt;span style="color: #4c1130; font-size: large;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="color: black;"&gt;public class StringTest {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String[] args) {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String[] str = { "Java", "Example", "for", "conversion", "from", "array", "of", "Strings", "to", "String" };&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String filler = "-";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String output = "";&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // Check if the string array is not empty&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (str.length &amp;gt; 0) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; output = str[0];&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 1; i &amp;lt; str.length; i++) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; output = output + filler + str[i];&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(output);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #4c1130; font-size: large;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="color: black;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #4c1130; font-size: large;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="color: black;"&gt;&amp;nbsp;The output of the above code is:-&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&lt;span style="color: #4c1130; font-size: large;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="color: black;"&gt;&amp;nbsp;Java-Example-for-conversion-from-array-of-Strings-to-String&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #4c1130; font-size: large;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="color: #4c1130; font-size: large;"&gt;Java String Example Links&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/09/convert-string-to-integer-int-in-java.html"&gt;Convert Java String to int&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/08/convert-int-to-string-in-java-code.html"&gt;Convert int to String in Java&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/09/convert-int-to-string-using-wrapper-in.html"&gt;Convert int to String using Wrapper in Java&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/length-of-string-java-program.html"&gt;Java String Length Program&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/reverse-string-java-program.html"&gt;Reverse a String in Java&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;&lt;b style="color: #4c1130;"&gt;Other Java Examples you might be interested in&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/java-code-for-prime-number-prime-number.html"&gt;Java Program for Prime Numbers&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/java-program-for-fibonacci-series.html"&gt;Java Program for Fibonacci Series&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/factorial-program-in-java-java-program.html"&gt;Factorial Program in Java&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/08/palindrome-java-program.html"&gt;Palindrome example in Java &lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/09/java-code-to-convert-decimal-to-binary.html"&gt;Conversion from Decimal to Binary in Java&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/09/java-code-to-convert-binary-to-decimal.html"&gt;Conversion from Binary to Decimal in Java&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="color: #4c1130;"&gt;&lt;b&gt;&lt;span style="font-size: large;"&gt;Related readings&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;a href="http://javacodeonline.blogspot.com/2010/12/substring-in-java.html"&gt;Substring in Java&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;&lt;b style="color: #4c1130;"&gt;External Readings&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;http://download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-3652737776974837879?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2010/12/string-in-java.html' title='String In Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/3652737776974837879/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2010/12/string-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3652737776974837879'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3652737776974837879'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2010/12/string-in-java.html' title='String In Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_-Gl5MQel5-0/TQEvCO33epI/AAAAAAAAAEo/o9v8o5q0qmY/s72-c/java-strings.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3416407328338427543.post-3084149133520088803</id><published>2010-03-16T03:49:00.002+05:30</published><updated>2010-03-16T03:58:24.568+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='JDBC'/><title type='text'>Java DataBase Connectivity JDBC</title><content type='html'>&lt;div style="color: #4c1130;"&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;JDBC Basics&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="background-color: #eeeeee; color: #4c1130;"&gt;Types of JDBC Drivers&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;Type 1:- Bridge drivers. Example JDBC-ODBC Bridge&lt;br /&gt;Type 2:- Native API drivers, partially in Java.&lt;br /&gt;Type 3:-Middleware is involved in communication from client's request and data source.&lt;br /&gt;Type 4:-The client connects directly to DataSource, pure Java drivers.&lt;br /&gt;&lt;br /&gt;&lt;b style="color: #4c1130;"&gt;Establishing the Connection&lt;/b&gt;&lt;br /&gt;Two ways:-&lt;br /&gt;1) DriverManager class&lt;br /&gt;2) DataSource interface&lt;br /&gt;&lt;br /&gt;&lt;b style="color: #4c1130;"&gt;Using DriverManager class for making connection&lt;/b&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Load the driver:-&lt;/span&gt;&amp;nbsp;&amp;nbsp; Class.forName("oracle.jdbc.driver.OracleDriver");&lt;br /&gt;&lt;span style="color: blue;"&gt;Define Connection URL:-&lt;/span&gt;&amp;nbsp; String url = "jdbc:oracle:thin:@" + hostName + ":" + portName + ":" + dbName;&lt;br /&gt;&lt;span style="color: blue;"&gt;Establish Connection:-&lt;/span&gt; Connection conn =DriverManager.getConnection(url,username,password);&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="color: #4c1130;"&gt;Using DataSource interface for making connection&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;InitialContext initContext = new InitialContext(); &lt;br /&gt;DataSource ds = initContext.lookup("java:comp/env/jdbc/ownDataBase");&lt;br /&gt;Connection con = ds.getConnection();&lt;br /&gt;&lt;br /&gt;The above method uses &lt;b&gt;JNDI &lt;/b&gt;lookup to get the datasource.&lt;br /&gt;&lt;br /&gt;Using Datasource for getting JDBC connection is preferred over DriverManager class.&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_-Gl5MQel5-0/S560WkD_n_I/AAAAAAAAAB4/zUDaQDNYfWk/s1600-h/JDBC.bmp" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="182" src="http://2.bp.blogspot.com/_-Gl5MQel5-0/S560WkD_n_I/AAAAAAAAAB4/zUDaQDNYfWk/s400/JDBC.bmp" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-3084149133520088803?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/3084149133520088803/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2010/03/java-database-connectivity-jdbc.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3084149133520088803'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3084149133520088803'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2010/03/java-database-connectivity-jdbc.html' title='Java DataBase Connectivity JDBC'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_-Gl5MQel5-0/S560WkD_n_I/AAAAAAAAAB4/zUDaQDNYfWk/s72-c/JDBC.bmp' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3416407328338427543.post-1692668521735315975</id><published>2010-03-06T03:51:00.000+05:30</published><updated>2010-03-06T03:51:35.526+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Developer'/><category scheme='http://www.blogger.com/atom/ns#' term='Oracle'/><title type='text'>Creating a database in Oracle using dmp file</title><content type='html'>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;Hi,&lt;br /&gt;&lt;br /&gt;Today I will pick up a very interesting, simple and yet important job of Software development, and that is creation of a database.&lt;br /&gt;&lt;br /&gt;There are many databases available in the market. I prefer Oracle. Today I will show how to create a database in Oracle using a .dmp file.&lt;br /&gt;&lt;br /&gt;I am working with Oracle 10g right now, so I will use it for reference.&lt;br /&gt;&lt;br /&gt;If you do not have Oracle on your machine, just go to the Oracle download center, and download the required version from there. And the best part is that the basic version is free, and works for most of the applications we work for.&lt;br /&gt;&lt;br /&gt;So, after copying the exe file from Oracle, and installing it on your machine, now we need to create a Database instance from the .dmp file.&lt;br /&gt;&lt;br /&gt;For that follow the steps below:-&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Log in the Oracle Database home page with "SYSTEM" id and password(set during Oracle installation) . The url may vary from version to version and user to user. In my case  it is:- http://127.0.0.1:8080/apex/f?p=4550:11:2121390824271097::NO:::&lt;/li&gt;&lt;li&gt;Create a user in the Oracle Database using the Oracle database home screen.&lt;/li&gt;&lt;li&gt;Grant the user all the rights and make him SYSDBA, so that he can import the .dmp file.&lt;/li&gt;&lt;li&gt;&amp;nbsp;Now open the dos prompt by typing “cmd” in the “Run” dialogue box, or by clicking on it’s shortcut.&lt;/li&gt;&lt;li&gt;&amp;nbsp;Type “IMP” on the dos prompt. Your screen will be something like shown below:-&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_-Gl5MQel5-0/S5F_tQbRo2I/AAAAAAAAABQ/WYRhC65FnN0/s1600-h/IMP.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="161" src="http://2.bp.blogspot.com/_-Gl5MQel5-0/S5F_tQbRo2I/AAAAAAAAABQ/WYRhC65FnN0/s320/IMP.JPG" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Enter the Username and password for the User which you have created in the Oracle.&lt;br /&gt;&lt;br /&gt;For my case, it is shown below:-&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_-Gl5MQel5-0/S5GArw6TwGI/AAAAAAAAABY/M2bvL09UN7w/s1600-h/ConnectOracle.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/_-Gl5MQel5-0/S5GArw6TwGI/AAAAAAAAABY/M2bvL09UN7w/s320/ConnectOracle.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Now it is asking for the path of the .dmp file, just copy the path followed by the .dmp file name and press enter. You will see something like below:-&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_-Gl5MQel5-0/S5GB4mGfmkI/AAAAAAAAABo/mWqQ3TegyGU/s1600-h/DmpFile.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/_-Gl5MQel5-0/S5GB4mGfmkI/AAAAAAAAABo/mWqQ3TegyGU/s320/DmpFile.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;After pressing enter it will ask you to enter many other parameters, you may choose to use my configuration. The image below displays the configuration which I choose.&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_-Gl5MQel5-0/S5GC5RTEHlI/AAAAAAAAABw/PxPWczuy4Yg/s1600-h/OracleCreate1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/_-Gl5MQel5-0/S5GC5RTEHlI/AAAAAAAAABw/PxPWczuy4Yg/s320/OracleCreate1.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;This is all you need to do, the import should terminate successfully, there might be some warnings, but usually they are not important.&lt;br /&gt;&lt;br /&gt;In my coming articles, I will demonstrate how to use SQL Developer to interact with this database.&lt;br /&gt;&lt;br /&gt;That's all for now. See you later.&lt;br /&gt;&lt;br /&gt;Cheers....&lt;br /&gt;Amit&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-1692668521735315975?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/1692668521735315975/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2010/03/creating-database-in-oracle-using-dmp.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1692668521735315975'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1692668521735315975'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2010/03/creating-database-in-oracle-using-dmp.html' title='Creating a database in Oracle using dmp file'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_-Gl5MQel5-0/S5F_tQbRo2I/AAAAAAAAABQ/WYRhC65FnN0/s72-c/IMP.JPG' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3416407328338427543.post-5873487597622001234</id><published>2009-10-11T21:04:00.001+05:30</published><updated>2009-10-11T21:06:52.582+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><category scheme='http://www.blogger.com/atom/ns#' term='Inner Classes'/><title type='text'>Static Inner Class Example in Java</title><content type='html'>Hello and welcome back to &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;, there has been a request from many of my users to come up with an example for static inner class. So the topic of today is to to illustrate Static Inner Class in action.&lt;br /&gt;&lt;br /&gt;You may any time check my previous article on &lt;a href="http://javacodeonline.blogspot.com/2009/08/static-inner-nested-class-in-java.html"&gt;Static Inner Class in Java&lt;/a&gt; for an illustration of what it is and what are the details for the other type of Inner classes in Java. today I will straight move to the example for it.&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;div style="color: #351c75;"&gt;class Cover&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #351c75;"&gt;{&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #351c75;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; static class InnerCover&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #351c75;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #351c75;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void go()&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #351c75;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #351c75;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("I am the first Static Inner Class");&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #351c75;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #351c75;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #351c75;"&gt;&amp;nbsp;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="color: #741b47;"&gt;class Broom&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47;"&gt;{&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static class InnerBroom&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void go1()&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("I am second Static Inner Class");&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String[] args) {&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #0b5394;"&gt;// You have to use the names of both the classes&lt;/span&gt; &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Cover.InnerCover demo = new Cover.InnerCover(); &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; demo.go();&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0b5394;"&gt; // Here we are accessing the enclosed class&lt;/span&gt; &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InnerBroom innerBroom = new InnerBroom ();&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; innerBroom .go1();&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47;"&gt;&amp;nbsp;}&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47;"&gt;}&lt;br /&gt;&lt;/div&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;When the above code is executed, the output is something like as displayed below:-&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;div style="color: #351c75;"&gt;&amp;nbsp;I am the first Static Inner Class&lt;br /&gt;&lt;/div&gt;&lt;span style="color: #741b47;"&gt;&amp;nbsp;I am second Static Inner Class&lt;/span&gt; &lt;br /&gt;------------------------------------ &lt;br /&gt;&lt;br /&gt;We know that a Static inner class is just a class which is a &lt;b&gt;static&amp;nbsp; &lt;/b&gt;member of the main class. So the same concept is applied here. Here we have two outer classes, one is called Cover, and the second is called Broom. Both of these outer classes have one static class within them.&lt;br /&gt;&lt;br /&gt;The method of accessing both the inner classes is shown in the main method of the Broom class. I hope the example will be helpful to all of you. Do post a comment if you have any query or if you liked the article. &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; will soon be back with yet another informative article.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-5873487597622001234?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/5873487597622001234/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/10/static-inner-class-example-in-java.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/5873487597622001234'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/5873487597622001234'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/10/static-inner-class-example-in-java.html' title='Static Inner Class Example in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-6012059548268574181</id><published>2009-09-23T00:18:00.000+05:30</published><updated>2009-09-23T00:18:13.376+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><title type='text'>Convert Celsius to Fahrenheit Java Code</title><content type='html'>&lt;div style="text-align: justify;"&gt;The Java Code discussed today at &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; deals with conversion of temperature from Celsius or Centigrade to Fahrenheit. The temperature conversions are required normally many times in our daily purposes. Like the body temperature in degree Fahrenheit and degree Celsius.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The only meeting point of these two temperature scales is -40 degree. At this temperature both the Celsius and the Fahrenheit scales are equal.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The Java code for this temperature conversion from Celsius to Fahrenheit is given below. The code requests the user to enter a temperature value in Celsius, and then displays the equivalent Fahrenheit Temperature.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/////////////////////////////////&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;package developer;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;import java.util.Scanner;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;public class CelsiusToFahrenheit {&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String[] args) {&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("Enter a temperature in Celsius: ");&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Scanner scanCelsius = new Scanner(System.in);&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; double Fahrenheit = 0;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (scanCelsius.hasNextDouble())&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Fahrenheit = (scanCelsius.nextDouble()*9) / 5 + 32;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("The temperature in Fahrenheit is: " + Fahrenheit);&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;}&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/////////////////////////////////&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;When this Java Code was executed on my &lt;a href="http://javacodeonline.blogspot.com/2008/12/what-is-java-virtual-machinejvm.html"&gt;JVM&lt;/a&gt;, then the output was as shown below.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/////////////////////////////////&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;Enter a temperature in Celsius: &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;102.87&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;The temperature in Fahrenheit is: 217.166&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/////////////////////////////////&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Hope that the Java code provide for conversion from Celsius to Fahrenheit was beneficial to all. Keep checking &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; for more Java updates and codes.&lt;br /&gt;&lt;br /&gt;Related Java Code&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/09/convert-fahrenheit-to-celsius-java-code.html"&gt;Java Code to convert Fahrenheit to Celsius&lt;/a&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/3416407328338427543-6012059548268574181?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/6012059548268574181/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/convert-celsius-to-fahrenheit-java-code.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/6012059548268574181'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/6012059548268574181'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/convert-celsius-to-fahrenheit-java-code.html' title='Convert Celsius to Fahrenheit Java Code'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-7707431563209517515</id><published>2009-09-22T22:45:00.003+05:30</published><updated>2009-09-23T00:19:25.105+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><title type='text'>Convert Fahrenheit to Celsius Java Code</title><content type='html'>&lt;div style="text-align: justify;"&gt;&lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; has come up with a new Java Program, and that is for converting a &lt;b&gt;temperature&lt;/b&gt; from Fahrenheit to Celsius or Centigrade. Fahrenheit and Celsius are the two main scales used for temperature measurement. The temperature of the normal human body is 98.4 degree Fahrenheit or 36.88 degree Celsius.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;So temperature conversion is used normally in daily life. The only place where Fahrenheit and Celsius scales meet is at the temperature of -40 degree. That is to say that -40 degree Fahrenheit is equal to -40 degree Celsius.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The Java code for this &lt;b&gt;temperature conversion&lt;/b&gt; from Fahrenheit to Celsius is given below. the code starts by asking the user to enter a temperature in Fahrenheit scale and then displays the equivalent Celsius Temperature.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/////////////////////////////////&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;package developer;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;import java.util.Scanner;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;public class FahrenheitToCelsius {&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public static void main(String[] args) {&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;System.out.println("Enter a temperature in Fahrenheit: ");&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;Scanner scanFaren = new Scanner(System.in);&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;double Celsius = 0;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if(scanFaren.hasNextDouble())&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;Celsius = (scanFaren.nextDouble() - 32)*5/9;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;System.out.println("The temperature in Celsius is: "+Celsius);&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;}&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/////////////////////////////////&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;When this Java Code was executed on my JVM, then the output was as shown below.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/////////////////////////////////&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;Enter a temperature in Fahrenheit: &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;56&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;The temperature in Celsius is: 13.333333333333334&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/////////////////////////////////&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Hope that the Java code provide for conversion from Fahrenheit to Celsius was useful to you all. &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; will soon be back with another important Java Code.&lt;br /&gt;&lt;br /&gt;Related Java Code:-&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/09/convert-celsius-to-fahrenheit-java-code.html"&gt;Java Code to convert Celsius to Fahrenheit&lt;/a&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/3416407328338427543-7707431563209517515?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/7707431563209517515/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/convert-fahrenheit-to-celsius-java-code.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/7707431563209517515'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/7707431563209517515'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/convert-fahrenheit-to-celsius-java-code.html' title='Convert Fahrenheit to Celsius Java Code'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-1598123093354499722</id><published>2009-09-22T21:43:00.000+05:30</published><updated>2009-09-22T21:43:35.740+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><title type='text'>Java Code to Convert Binary to Decimal</title><content type='html'>&lt;div style="text-align: justify;"&gt;Java has deal with many different situations. So &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; is going to discuss a case when a number entered as binary is to be converted to a decimal number. A binary number which consists of only 1 and 0, while a decimal number is a number which consists of numbers between 0-9.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;We normally use decimal numbers in our daily purposes. Binary numbers on the other hand are very important and used for computers data transfer.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The Java code for converting a binary number to a decimal number, starts by asking the user to enter a binary number. The result is a decimal number which is displayed to the user. In case the number entered is not a binary number, i.e. it contains numbers other then 0 and 1. In that a &lt;b&gt;NumberFormatException&lt;/b&gt; will be thrown. I have &lt;b&gt;catch&lt;/b&gt; this exception, so that the developer can use there custom message in that place.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The Java Code is displayed below:-&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/////////////////////////////////////&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;package developer;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;import java.util.Scanner;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;public class BinaryToDecimal {&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public static void main(String[] args) {&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;System.out.println("Enter a binary number: ");&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;Scanner scanStr = new Scanner(System.in);&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;int decimalNum = 0;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if(scanStr.hasNext())&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{ &amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;try&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;decimalNum = Integer.parseInt(scanStr.next(),2);&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;System.out.println("Binary number in decimal is: "+decimalNum);&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;catch(NumberFormatException nfe)&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;System.out.println("The number is not a binary number.");&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;}&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/////////////////////////////////////&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;When this code is executed on my system, the output is as shown below.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/////////////////////////////////////&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;Enter a binary number: &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;10100011&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;The binary number in decimal is: 163&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/////////////////////////////////////&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;In case the number entered is not a binary number, then the output is as shown below:-&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/////////////////////////////////////&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;Enter a binary number: &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;123456&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;The number is not a binary number.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/////////////////////////////////////&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Hope that I was able to make my point clear. If you liked the article then do post a comment. Kepp checking &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; for more Java Codes.&lt;br /&gt;&lt;br /&gt;Related Java Codes&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/09/java-code-to-convert-decimal-to-binary.html"&gt;Java Code to Convert Decimal to Binary&lt;/a&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/3416407328338427543-1598123093354499722?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/1598123093354499722/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/java-code-to-convert-binary-to-decimal.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1598123093354499722'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1598123093354499722'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/java-code-to-convert-binary-to-decimal.html' title='Java Code to Convert Binary to Decimal'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-8864968506878701234</id><published>2009-09-22T21:08:00.001+05:30</published><updated>2009-09-22T21:44:43.793+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><title type='text'>Java Code to Convert Decimal to Binary</title><content type='html'>&lt;div style="text-align: justify;"&gt;The &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; is today going to discuss the Java code for converting a decimal number to binary number. A decimal number is known to all of us. It is number whose base value is 10. All the numbers we use in normal practice are usually decimal numbers. It implies that decimal numbers can consist of numbers from 0-9.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;A binary number is a number whose base value is 2. It means that a binary number system consists of only 0 and 1. In computers all the data is transferred in the form of binary numbers.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The Java Code presented today, asks the user to enter a decimal number, and displays the binary equivalent of that number.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The Java code is displayed below:-&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/////////////////////////////////////////////&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;package developer;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;import java.util.Scanner;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;public class DecimalToBinary {&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public static void main(String[] args) {&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;System.out.println("Enter a decimal number: ");&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;Scanner scanStr = new Scanner(System.in);&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;String num = null;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;//Check for an integer number entered by the user&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if(scanStr.hasNextInt())&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{ &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;//Convert the decimal number to binary String&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;num = Integer.toBinaryString(scanStr.nextInt());&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;System.out.println("The decimal number in binary is: "+num);&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;}&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/////////////////////////////////////////////&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;When the code is executed, the output is as shown below:-&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/////////////////////////////////////////////&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;Enter a decimal number: &lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;23&lt;br /&gt;&lt;/div&gt;&lt;div style="color: #741b47; text-align: justify;"&gt;The decimal number in binary is: 10111&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/////////////////////////////////////////////&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Hope that the code was useful to all of you. Keep buzzing &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Related Java Codes&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/09/java-code-to-convert-binary-to-decimal.html"&gt;Java Code to Convert Binary to Decimal&lt;/a&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/3416407328338427543-8864968506878701234?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/8864968506878701234/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/java-code-to-convert-decimal-to-binary.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/8864968506878701234'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/8864968506878701234'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/java-code-to-convert-decimal-to-binary.html' title='Java Code to Convert Decimal to Binary'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-1048734331307493740</id><published>2009-09-21T01:39:00.000+05:30</published><updated>2009-09-21T01:39:02.700+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='File Handling'/><category scheme='http://www.blogger.com/atom/ns#' term='File'/><title type='text'>Java Code to write to CSV  File</title><content type='html'>&lt;div class="separator" style="clear: both; text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Hello guys, &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; is back again with an important code. The code for today is for making a &lt;b&gt;CSV&lt;/b&gt; &lt;b&gt;(Comma Separated File)&lt;/b&gt; file. The operation to make a CSV file in Java is similar to the &lt;a href="http://javacodeonline.blogspot.com/2009/09/java-code-to-write-to-file.html"&gt;Java Code to write to a file&lt;/a&gt;. The difference between these two is that a comma is inserted within the text, where ever we want the columns in &lt;b&gt;MS EXCEL&lt;/b&gt; to change to new column.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The beauty of the .csv file is that, when this file is opened in MS Excel, then all the values which are separated by comma, are displayed in a new column. This is required many times, if we want to send data to different columns. Even there is an option to switch rows while writing.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The Java Code displayed today, makes a .csv file at a particular location on your hard disk. You need to change the path, according to your requirements. The code writes some data to the .csv file. It generates 3 columns and 2 rows. You can modify it, according to your own requirements.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The Java Code is provided below:-&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/////////////////////////////////////&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/** The below Java Code writes &lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;* some data to a file in CSV&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;* (Comma Separated Value) File&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;*/&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;package developer;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;import java.io.FileWriter;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;import java.io.IOException;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;import java.io.PrintWriter;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;public class MakeCSVFile {&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String[] args) throws IOException {&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //Note the "\\" used in the path of the file &lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //instead of "\", this is required to read &lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //the path in the String format.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; FileWriter fw = new FileWriter("D:\\JavaCodeFile\\WriteTest.csv");&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; PrintWriter pw = new PrintWriter(fw);&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //Write to file for the first row&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; pw.print("Hello guys");&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; pw.print(",");&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; pw.print("Java Code Online is maing");&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; pw.print(",");&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; pw.println("a csv file and now a new line is going to come");&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //Write to file for the second row&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; pw.print("Hey");&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; pw.print(",");&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; pw.print("It's a");&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; pw.print(",");&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; pw.print("New Line");&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //Flush the output to the file&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; pw.flush();&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //Close the Print Writer&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; pw.close();&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //Close the File Writer&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; fw.close();&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;}&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;/////////////////////////////////////&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The code when run on my system a produces a file called WriteTest.csv, when opened with MS EXCEL, the output is shown below:-&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: justify;"&gt;&lt;a href="http://3.bp.blogspot.com/_-Gl5MQel5-0/SraLY09_oYI/AAAAAAAAAAM/ozEDnlmAuy4/s1600-h/screenShot1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/_-Gl5MQel5-0/SraLY09_oYI/AAAAAAAAAAM/ozEDnlmAuy4/s400/screenShot1.JPG" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;I hoe that the code was useful to all of you. &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; is going to be back soon.&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/3416407328338427543-1048734331307493740?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/1048734331307493740/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/java-code-to-write-to-csv-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1048734331307493740'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1048734331307493740'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/java-code-to-write-to-csv-file.html' title='Java Code to write to CSV  File'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_-Gl5MQel5-0/SraLY09_oYI/AAAAAAAAAAM/ozEDnlmAuy4/s72-c/screenShot1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3416407328338427543.post-1114180316876898285</id><published>2009-09-21T01:18:00.001+05:30</published><updated>2009-09-23T21:18:23.282+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Resources'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><title type='text'>Check out the tutorial at the Sun site</title><content type='html'>&lt;div style="text-align: justify;"&gt;&amp;nbsp;Java is everywhere. Of the most&amp;nbsp; authenticate sources, that could be used for learning Java, I trust &lt;b&gt;sun&lt;/b&gt; the most. The tutorial provided by java.sun.com normally called as the Java Tutorial at java.sun.com/docs/books/tutorial , is a very good one. I have scanned the tutorial many times earlier also, and every-time found it to be the most updated and authentic resource on the net.&lt;br /&gt;&lt;br /&gt;The Java technology always keep coming up with new changes and features. Therefore the need to continuously update the link and site is very important. Sun is the provider of Java, and so they have to maintain the most updated links and material. The best part I found with this site was that the tutorial was concise and up to the point.&lt;br /&gt;&lt;br /&gt;The site does not go in unnecessary examples or extra elaboration. It sticks to the basics and explains them well. The section for Trail Covering the basics, consists of many great Java technology articles. It does not deal only with basic Java, but the tutorial for &lt;b&gt;Java Collections&lt;/b&gt; and &lt;b&gt;Swing&lt;/b&gt; is also provided. This is an extra bonus for all those who are interested in getting to the roots of Java.&lt;br /&gt;&lt;br /&gt;The section of specialized trails and lessons consists of many advanced Java related &lt;b&gt;tutorials&lt;/b&gt; and articles. To name a few, the trail consists of articles and tutorials on &lt;b&gt;Networking&lt;/b&gt;, &lt;b&gt;Generics&lt;/b&gt;, &lt;b&gt;JavaBeans&lt;/b&gt;, &lt;b&gt;JDBC&lt;/b&gt;, &lt;b&gt;JMX&lt;/b&gt;, &lt;b&gt;JNDI&lt;/b&gt;, &lt;b&gt;RMI&lt;/b&gt;, &lt;b&gt;Reflection&lt;/b&gt;, &lt;b&gt;Java Security&lt;/b&gt;, &lt;b&gt;Graphics&lt;/b&gt;, &lt;b&gt;Socket Programming in Java&lt;/b&gt;, etc.&lt;br /&gt;&lt;br /&gt;All these are very important fields of Java for an advanced programmer. Like JDBC which is used for Database connection establishment, and retrieval and updation of records. The process involves many commands and is a separate field altogether.&lt;br /&gt;&lt;br /&gt;JNDI and RMI, are used for Remote Method Invocation. This is a very large field in itself. The part of RMI is important for a distributed architecture. Like your server is at a particular place, and the application is running at a different place. There need to be interaction between this application and the server. RMI along with JNDI are used here.&lt;br /&gt;&lt;br /&gt;Like this there are many fields from which the person can choose depending upon his or her intrest. It is vast ocean of resources for Java. Go ahead and give it a look, Hope that you will also find something very interesting and useful from this site.&lt;br /&gt;&lt;br /&gt;That's it for now. Keep buzzing Java Code Online.&lt;br /&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/3416407328338427543-1114180316876898285?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/09/check-out-tutorial-at-sun-site.html' title='Check out the tutorial at the Sun site'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/1114180316876898285/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/check-out-tutorial-at-sun-site.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1114180316876898285'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1114180316876898285'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/check-out-tutorial-at-sun-site.html' title='Check out the tutorial at the Sun site'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-1638055131614690865</id><published>2009-09-19T03:49:00.003+05:30</published><updated>2009-09-23T21:17:07.293+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>How to get Java</title><content type='html'>&lt;div style="text-align: justify;"&gt;Some of my readers have raised a concern on how to install java on their computers. So &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; has come up with this simple yet important article on downloading Java to your system. It might be that the computer does not contain Java, or it is also possible, that the version of Java installed is an old one. This hampers many of the different features of your computer.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Getting Java on your computer is very easy. Just go to www.java.com/en. Click on the "Free Java Download" button. It will verify, that whether your computer has Java installed on it or not. and if Java is installed already, then whether the version is an old one or a new one. If you have the latest version of Java installed, then you will get the message &lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;"Verifying Java Version&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Congratulations!&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;You have the recommended Java installed (Version x Update xx).&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;If the computer does not have Java, or the latest version of Java, then it will allow the computer to download the latest version form there. The best part is that it is free, so need to worry about paying to anyone. &lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Java is a must for almost all of the applications that work on your computer, and is also required by many sites that you visit. So don't hesitate in getting the latest version of Java. The only exclusion from this are the programmers who are working on an earlier version of Java, and do not want to switch to a new version. Remember that with every new version, some of the old features are deprecated. The depricated features are the one, which should no longer be used by any programmer.&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/3416407328338427543-1638055131614690865?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/09/how-to-get-java.html' title='How to get Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/1638055131614690865/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/how-to-get-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1638055131614690865'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1638055131614690865'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/how-to-get-java.html' title='How to get Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-2539077476141088567</id><published>2009-09-11T22:28:00.003+05:30</published><updated>2009-09-23T21:29:21.012+05:30</updated><title type='text'>Blogger Blogging on Blogspot</title><content type='html'>Hi and welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Today I will not be discussing any Java topic. I have been blogging for some time now, and wish to take it to the next level. The thought that crawled through my mind, was regarding various Gadgets that various blogs use. They definitely make the blog look more attractive, handy and useful. It increase your traffic, as the viewer loves to come back to your blog. Moreover it is a feeling of self satisfaction, that yes I have made a beautiful thing.&lt;br /&gt;&lt;br /&gt;The aim of this post is to invite all Bloggers who use Blogger.com for blogging, to discuss about the various gadgets that they use. This will help all the bloggers to be aware of various widgets provide by Blogger and third parties to improve their blog. Some blogs which I checked have really great templates, it would be a pleasure if all of you come up with your resources. It would be a great help to all the bloggers, and especially to beginners who are just preparing to start their blog.&lt;br /&gt;&lt;br /&gt;The gadgets I am using are for Google Friend Connect for tracking the followers of this blog, and the RSS feed for subscribing to the postings. Apart from that there is Google Adsense for monetization. I have used the labels and archives tab to make the blog look more handy and comfortable to all the viewers. I suppose that all of us will be using similar kind of tools, but there are many more and the shared information could be beneficial to all of us.&lt;br /&gt;&lt;br /&gt;As a programmer, i feel to enhance my blog using the technology on which I am working. I have been working on Java for a long time, and my current application areas include JSP, Servlets, Struts, J2EE , JavaScript etc. Though the list is a long one, I am not able to apply anything apart from some JavaScript and HTML on my blog.&lt;br /&gt;&lt;br /&gt;Recently I was checking the site code.google.com/apis/blogger/docs/2.0/developers_guide_java.html, for support on Blogger. And in fact I came to know that, I can do much more with Java. Java can help in posting, deleting, publishing, retrieving, saving as draft etc. of articles to your blog. There is complete library waiting to be explored. It can open a new perspective that how we integrate our blogs with the technology. I am posting the information I have, and encourage to all of you to come with various ideas to improve the way we blog.&lt;br /&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; hopes that this article will definitely help in improving the way we blog, and definitely makes our blog look much better. It's the technology that will drive it, and I love Java for that.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-2539077476141088567?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/09/blogger-blogging-on-blogspot.html' title='Blogger Blogging on Blogspot'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/2539077476141088567/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/blogger-blogging-on-blogspot.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/2539077476141088567'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/2539077476141088567'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/blogger-blogging-on-blogspot.html' title='Blogger Blogging on Blogspot'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3416407328338427543.post-2881125635678026180</id><published>2009-09-10T21:41:00.001+05:30</published><updated>2009-09-10T21:43:37.904+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='File Handling'/><category scheme='http://www.blogger.com/atom/ns#' term='File'/><title type='text'>Java Code to Delete a File</title><content type='html'>Hello and welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. The topic for today's discussion is to delete a File in Java, though a very simple process, it is very important. It is one of the most basic aspects of File Handling. So this Java Blog has decided to pick this topic in this tutorial.&lt;br /&gt;&lt;br /&gt;The Java Code discussed today, starts by taking the path for the file, and checks for its existence. If the file exists, then the delete() command is fired on it. After deletion of the file, the presence of the file is checked. This step is to ensure that the deletion activity of the file is properly achieved or not.&lt;br /&gt;&lt;br /&gt;The Java code is provided below:-&lt;br /&gt;&lt;br /&gt;/////////////////////////////////&lt;br /&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-java-package.html"&gt;package&lt;/a&gt; developer;&lt;br /&gt;&lt;br /&gt;import java.io.File;&lt;br /&gt;&lt;br /&gt;public &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;class&lt;/a&gt; DeleteFile {&lt;br /&gt;&lt;br /&gt; &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-reason-for-each-keyword-of.html"&gt;public static void main(String[] args)&lt;/a&gt; {&lt;br /&gt;  &lt;br /&gt;  File fileTest = new File("D:\\JavaCodeFile\\WriteTest.txt");&lt;br /&gt;  &lt;br /&gt;  //Check for the existence of the file before deletion of it&lt;br /&gt;  System.out.println("Is the file present in the current location before deletion? ");&lt;br /&gt;  System.out.println(fileTest.exists());&lt;br /&gt;  &lt;br /&gt;  if(fileTest.exists())&lt;br /&gt;  {&lt;br /&gt;   //Delete the file&lt;br /&gt;   fileTest.delete();&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  //Check for the existence of the file after deletion of it&lt;br /&gt;  System.out.println("Is the file present in the current location after deletion? ");&lt;br /&gt;  System.out.println(fileTest.exists());&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/////////////////////////////////&lt;br /&gt;&lt;br /&gt;This Java Code when executed on my &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-java-virtual-machinejvm.html"&gt;JVM&lt;/a&gt;, resulted in the following output.&lt;br /&gt;&lt;br /&gt;/////////////////////////////////&lt;br /&gt;&lt;br /&gt;Is the file present in the current location before deletion? &lt;br /&gt;true&lt;br /&gt;Is the file present in the current location after deletion? &lt;br /&gt;false&lt;br /&gt;&lt;br /&gt;/////////////////////////////////&lt;br /&gt;&lt;br /&gt;Simple isn't it. yes the process of deletion of a file is very simple, and now you know it too. Keep checking &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; for more Java articles.&lt;br /&gt;&lt;br /&gt;Related articles that might be of interest:-&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/09/java-code-to-read-file.html"&gt;Java Code to Read a File&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/09/java-code-to-write-to-file.html"&gt;Java Code to Write to a File&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/09/java-code-to-create-file.html"&gt;Java Code to Create to a File&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/08/java-code-for-file-extension.html"&gt;Java Code for File Extension&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/08/remove-extension-of-file-java-code.html"&gt;Java Code for Removing File Extension&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-2881125635678026180?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/09/java-code-to-delete-file.html' title='Java Code to Delete a File'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/2881125635678026180/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/java-code-to-delete-file.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/2881125635678026180'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/2881125635678026180'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/java-code-to-delete-file.html' title='Java Code to Delete a File'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-4277791427144108905</id><published>2009-09-09T22:32:00.002+05:30</published><updated>2009-09-09T22:35:16.921+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='java.io package'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><category scheme='http://www.blogger.com/atom/ns#' term='File Handling'/><category scheme='http://www.blogger.com/atom/ns#' term='File'/><title type='text'>Java Code to Create a File</title><content type='html'>This Java Blog is today picking the topic of how to create File in Java. &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; hopes that the article will be helpful to you all. In &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-java.html"&gt;Java&lt;/a&gt; there are various possibilities for File Manipulation and handling. I suppose the simplest of them is regarding creation of a File. There are cases when we need to create a File for backing up some data, or write some important data, or might be some other reason. For all of the above we need to know first of all, how to create a File.&lt;br /&gt;&lt;br /&gt;Creating a file is a simple process, and it uses just two methods of the File Class which is in the &lt;b&gt;java.io&lt;/b&gt; package. They are:-&lt;br /&gt;&lt;br /&gt;1. exists()&lt;br /&gt;2. createNewFile()&lt;br /&gt;&lt;br /&gt;The exists() method checks that whether the file exists or not. The createNewFile() method creates new File. Though creation of the File can be easily done by the createNewFile() method, it is a good practice to check that the file exists prior to creation or not. This case is important in scenarios where we need to create a File in case it does not exists, if it exists, then we need to modify it. So here the exists() method is very important, as it checks beforehand that the File exists or not.&lt;br /&gt;&lt;br /&gt;The Java Code discussed today starts by declaring a new File at a particular path. You need to configure the path according to your application. I suppose that this is the only change apart from the package name, that you may need to do in this program, so as to compile and run it successfully.&lt;br /&gt;&lt;br /&gt;The File is then tested for its existence using the method exists(), and if the file is found to be non existent, then a new File is created using createNewFile() method.&lt;br /&gt;&lt;br /&gt;The Java Code is provide below for your reference:-&lt;br /&gt;&lt;br /&gt;/////////////////////////////////////////&lt;br /&gt;&lt;font color = "green"&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-java-package.html"&gt;package&lt;/a&gt; developer;&lt;br /&gt;&lt;br /&gt;import java.io.File;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;&lt;br /&gt;public &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;class&lt;/a&gt; CreateFile {&lt;br /&gt; &lt;br /&gt; &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-reason-for-each-keyword-of.html"&gt;public static void main(String[] args)&lt;/a&gt; throws IOException {&lt;br /&gt;  &lt;br /&gt;  File fileTest = new File("D:\\JavaCodeFile\\CreateTest.txt");&lt;br /&gt;  &lt;br /&gt;  //Check for the existence of the file&lt;br /&gt;  System.out.println("Does the file exists before execution of the code? ");&lt;br /&gt;  System.out.println(fileTest.exists());&lt;br /&gt;  &lt;br /&gt;  if(!fileTest.exists())&lt;br /&gt;  {&lt;br /&gt;   //Create a new file at the specified path&lt;br /&gt;   fileTest.createNewFile();&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  //Check again for the existence of the file&lt;br /&gt;  System.out.println("Does the file exists after execution of the code? ");&lt;br /&gt;  System.out.println(fileTest.exists());&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;/////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;The output on my console after compiling the application using the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-java-compiler.html"&gt;Java compiler&lt;/a&gt; and running this program on my &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-java-virtual-machinejvm.html"&gt;JVM&lt;/a&gt; was as below:-&lt;br /&gt;&lt;br /&gt;/////////////////////////////////////////&lt;br /&gt;&lt;font color = "green"&gt;&lt;br /&gt;Does the file exists before execution of the code? &lt;br /&gt;false&lt;br /&gt;Does the file exists after execution of the code? &lt;br /&gt;true&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;/////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;Hope that now you can easily create a file in Java. Do post comments if you have issues or if you liked the article. &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; is working on new articles for Java lovers.&lt;br /&gt;&lt;br /&gt;Related articles that might be of interest:-&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/09/java-code-to-read-file.html"&gt;Java Code to Read a File&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/09/java-code-to-write-to-file.html"&gt;Java Code to Write to a File&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/08/java-code-for-file-extension.html"&gt;Java Code for File Extension&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/08/remove-extension-of-file-java-code.html"&gt;Java Code for Removing File Extension&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-4277791427144108905?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/09/java-code-to-create-file.html' title='Java Code to Create a File'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/4277791427144108905/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/java-code-to-create-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/4277791427144108905'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/4277791427144108905'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/java-code-to-create-file.html' title='Java Code to Create a File'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-2790133548084179641</id><published>2009-09-07T23:12:00.002+05:30</published><updated>2009-09-09T22:36:31.589+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='java.io package'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><category scheme='http://www.blogger.com/atom/ns#' term='File Handling'/><category scheme='http://www.blogger.com/atom/ns#' term='File'/><title type='text'>Java Code to Write to a File</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. The article for today is for writing some text to a file in Java. There are often various cases when we need to write or save some data in an external file. Java provides a very powerful set of libraries for handling this operation.&lt;br /&gt;&lt;br /&gt;First for writing to a file you need to have write permission on it, So first we need to check that whether we can write on it or not. If the file is writable, then we use the FileWriter class provided by Java to perform this operation. This file is part of the java.io package, which includes many powerful classes for handling the Java input output operations.&lt;br /&gt;&lt;br /&gt;The writing to a file operation is used in many cases like when we need to save some content in a file, which could be read or used afterward. this file may also be sent to some other application for some other operations required on it.&lt;br /&gt;&lt;br /&gt;The Java Code for writing to a file is provided below. We assumed a path as per our local machine. You need to set the path according to your folder structure. This code writes the content in a file. If the file is not present, then it creates one and then write to it.  So anyhow your writing operation will be successful.&lt;br /&gt;&lt;br /&gt;The Java Code is:-&lt;br /&gt;&lt;br /&gt;////////////////////////&lt;br /&gt;&lt;font color = "green"&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-java-package.html"&gt;package&lt;/a&gt; developer;&lt;br /&gt;&lt;br /&gt;import java.io.FileWriter;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.io.PrintWriter;&lt;br /&gt;&lt;br /&gt;public &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;class&lt;/a&gt; WriteToFile {&lt;br /&gt;&lt;br /&gt; &lt;br /&gt; &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-reason-for-each-keyword-of.html"&gt;public static void main(String[] args)&lt;/a&gt; throws IOException {&lt;br /&gt;  //Note the "\\" used in the path of the file instead of "\",&lt;br /&gt;//this is required to read the path in the String format.&lt;br /&gt;  FileWriter fw = new FileWriter("D:\\JavaCodeFile\\WriteTest.txt");&lt;br /&gt;  PrintWriter pw = new PrintWriter(fw);&lt;br /&gt;  &lt;br /&gt;  //Write to file line by line&lt;br /&gt;  pw.println("Hello guys");&lt;br /&gt;  pw.println("Java Code Online is testing");&lt;br /&gt;  pw.println("writing to a file operation");&lt;br /&gt;  &lt;br /&gt;  //Flush the output to the file&lt;br /&gt;  pw.flush();&lt;br /&gt;  &lt;br /&gt;  //Close the Print Writer&lt;br /&gt;  pw.close();&lt;br /&gt;  &lt;br /&gt;  //Close the File Writer&lt;br /&gt;  fw.close();  &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;////////////////////////&lt;br /&gt;&lt;br /&gt;The beauty of the code lies in its compactness and simplicity of use. Note the use of flush on the PrintWriter Class Object. This helps in writing any buffered output to the file. This ensures that all the content is written to the file, before the writer is closed.&lt;br /&gt;&lt;br /&gt;I hope the code for writing to a file was useful to all. Keep posting comments, because that's the way we can be in touch. Keep checking &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; for more Java articles.&lt;br /&gt;&lt;br /&gt;Related Java articles:-&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/09/java-code-to-read-file.html"&gt;Java Code to Read a File&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-2790133548084179641?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/09/java-code-to-write-to-file.html' title='Java Code to Write to a File'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/2790133548084179641/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/java-code-to-write-to-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/2790133548084179641'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/2790133548084179641'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/java-code-to-write-to-file.html' title='Java Code to Write to a File'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-7270702870729468581</id><published>2009-09-06T22:34:00.004+05:30</published><updated>2009-09-09T22:37:49.327+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='java.io package'/><category scheme='http://www.blogger.com/atom/ns#' term='File Handling'/><category scheme='http://www.blogger.com/atom/ns#' term='File'/><title type='text'>Java Code to Read a File</title><content type='html'>Today &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; is going to pick a very important topic, and that is regarding File Reading in Java. There are often various scenarios when the data required is to be read from a particular file that is not part of the application.&lt;br /&gt;&lt;br /&gt;The external file may be a .txt, .xml, .csv etc. type of file. The thing that matters is that we need to read it in the Java application. The code discussed here is applicable for a .txt file. Though the processing will differ a bit for the other type of files.&lt;br /&gt;&lt;br /&gt;I have taken an example, where a file is read from a particular folder. Replace the path with the path of your file, and you are all set to go. I have added extra comments for each line of code, so as to make there purpose clear in the Java Program.&lt;br /&gt;&lt;br /&gt;The Java code is provided below:-&lt;br /&gt;&lt;br /&gt;///////////////////////////////////////&lt;br /&gt;&lt;br /&gt;&lt;font color = "green"&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-java-package.html"&gt;package&lt;/a&gt; developer;&lt;br /&gt;&lt;br /&gt;import java.io.BufferedReader;&lt;br /&gt;import java.io.FileReader;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;&lt;br /&gt;public &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;class&lt;/a&gt; ReadFile {&lt;br /&gt; &lt;br /&gt; &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-reason-for-each-keyword-of.html"&gt;public static void main(String[] args)&lt;/a&gt; throws IOException {&lt;br /&gt;  &lt;br /&gt;  String fileStore = null;&lt;br /&gt;  &lt;br /&gt;  //Note the "\\" used in the path of the file instead of "\",&lt;br /&gt;//this is required to read the path in the String format.&lt;br /&gt;  FileReader fr = new FileReader("D:\\JavaCodeFile\\Test.txt");&lt;br /&gt;&lt;br /&gt;  BufferedReader br = new BufferedReader(fr);&lt;br /&gt;  &lt;br /&gt;  //save the line of the file in a String variable and compare it with null, and continue till null (End of File) is not achieved&lt;br /&gt;  while(null != (fileStore = br.readLine()))&lt;br /&gt;  {&lt;br /&gt;   //Print the file line by line&lt;br /&gt;   System.out.println(fileStore);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  //close the Buffered Reader&lt;br /&gt;  br.close();&lt;br /&gt;&lt;br /&gt;  //Close the File Reader&lt;br /&gt;  fr.close();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;///////////////////////////////////////&lt;br /&gt;&lt;br /&gt;When the code is executed, it will display the content of the file line by line on the console. for my case the output was as given below. Your output may differ based on the file content.&lt;br /&gt;&lt;br /&gt;///////////////////////////////////////&lt;br /&gt;&lt;br /&gt;&lt;font color = "green"&gt;&lt;br /&gt;Hello&lt;br /&gt;Welcome to Java Code Online&lt;br /&gt;This is a test file&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;///////////////////////////////////////&lt;br /&gt;&lt;br /&gt;It should be enough to clear all your doubts for how to read a file in Java. If you liked the article then do leave a comment. &lt;a href = ""&gt;Java Code Online&lt;/a&gt; will be coming up with more articles on file handling soon.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-7270702870729468581?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/09/java-code-to-read-file.html' title='Java Code to Read a File'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/7270702870729468581/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/java-code-to-read-file.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/7270702870729468581'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/7270702870729468581'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/java-code-to-read-file.html' title='Java Code to Read a File'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-3673867768349300983</id><published>2009-09-06T20:42:00.008+05:30</published><updated>2010-12-10T20:12:10.539+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><category scheme='http://www.blogger.com/atom/ns#' term='Scanner'/><category scheme='http://www.blogger.com/atom/ns#' term='String'/><title type='text'>Convert String to integer (int) in Java</title><content type='html'>&lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; will discuss the Java Code to convert a String to an int. There is a feature provided in Java, which helps to perform this operation. The conversion is done with the help of a method called &lt;b&gt;parseInt()&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;Actually any String which could be converted to a primitive can be converted to it, by using the parseXxx() method, where Xxx will replace the type in which it is to be converted, like int, float, etc.&lt;br /&gt;&lt;br /&gt;I have provided a sample Java Code which asks the user to enter a number, which is taken as a String by the application. Later it is converted to an integer by using the parseInt() method. Go through the code for a clear understanding on how it is to be used.&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #7f6000;"&gt;&lt;span style="color: green;"&gt;&amp;nbsp; &lt;span style="color: black;"&gt;package developer;&lt;/span&gt;&lt;br style="color: black;" /&gt; &lt;br style="color: black;" /&gt;&lt;span style="color: black;"&gt;&amp;nbsp; import java.util.Scanner;&lt;/span&gt;&lt;br style="color: black;" /&gt; &lt;br style="color: black;" /&gt;&lt;span style="color: black;"&gt;&amp;nbsp; public class StringToInt {&lt;/span&gt;&lt;br style="color: black;" /&gt; &lt;br style="color: black;" /&gt;&lt;span style="color: black;"&gt;&amp;nbsp; public static void main(String[] args) {&lt;/span&gt;&lt;br style="color: black;" /&gt; &lt;br style="color: black;" /&gt; &lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("Enter a number which would be taken as a String by the application");&lt;/span&gt;&lt;br style="color: black;" /&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Scanner scanStr = new Scanner(System.in);&lt;/span&gt;&lt;br style="color: black;" /&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String numStore = null;&lt;/span&gt;&lt;br style="color: black;" /&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; int numConvert = 0;&lt;/span&gt;&lt;br style="color: black;" /&gt;&lt;br style="color: black;" /&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // Takes the input as a String&lt;/span&gt;&lt;br style="color: black;" /&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (scanStr.hasNext()) {&lt;/span&gt;&lt;br style="color: black;" /&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; numStore = scanStr.next();&lt;/span&gt;&lt;br style="color: black;" /&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br style="color: black;" /&gt;&lt;br style="color: black;" /&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // Convert the String to int by using the Integer.parseInt() method&lt;/span&gt;&lt;br style="color: black;" /&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; numConvert = Integer.parseInt(numStore);&lt;/span&gt;&lt;br style="color: black;" /&gt;&lt;br style="color: black;" /&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("The number entered by you is: " + numConvert);&lt;/span&gt;&lt;br style="color: black;" /&gt; &lt;br style="color: black;" /&gt;&lt;span style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br style="color: black;" /&gt;&lt;span style="color: black;"&gt;&amp;nbsp; } &lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: #7f6000;"&gt;&lt;/div&gt;&lt;br /&gt;The output is something like as shown below.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #7f6000;"&gt;&lt;span style="color: green;"&gt;&amp;nbsp; &lt;span style="color: black;"&gt;Enter a number which would be taken as a String by the application&lt;/span&gt;&lt;br style="color: black;" /&gt;&lt;span style="color: black;"&gt;&amp;nbsp; 22&lt;/span&gt;&lt;br style="color: black;" /&gt;&lt;span style="color: black;"&gt;&amp;nbsp; The number entered by you is: 22&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Some observation points are:-&lt;br /&gt;&lt;div style="color: #4c1130;"&gt;The String which is to be converted to a number must be a number in the String format. This is required so that the Java parser can parse the String successfully into an int.&lt;/div&gt;&lt;br /&gt;&lt;div style="color: #4c1130;"&gt;If the value entered is not a number, suppose that you entered a String in words in place of a number in String format, then the output is shown below:-&lt;/div&gt;&lt;br /&gt;&lt;div style="background-color: #7f6000; color: black;"&gt;&amp;nbsp;Enter a number which would be taken as a String by the application&lt;br /&gt;&amp;nbsp;Conversion from String to int &lt;br /&gt;&amp;nbsp;Exception in thread "main" java.lang.NumberFormatException: For input string: "Conversion"&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at java.lang.NumberFormatException.forInputString(Unknown Source)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at java.lang.Integer.parseInt(Unknown Source)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at java.lang.Integer.parseInt(Unknown Source)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at &lt;span style="color: green;"&gt;&lt;span style="color: black;"&gt;developer&lt;/span&gt;&lt;/span&gt;.&lt;span style="color: green;"&gt;&lt;span style="color: black;"&gt;StringToInt &lt;/span&gt;&lt;/span&gt;.main(&lt;span style="color: green;"&gt;&lt;span style="color: black;"&gt;StringToInt &lt;/span&gt;&lt;/span&gt;.java:20)&lt;/div&gt;&lt;br /&gt;So we see that if a String is entered to be parsed as an int, then the &lt;a href="http://javacodeonline.blogspot.com/2008/12/what-is-java-compiler.html"&gt;Java Compiler&lt;/a&gt; gives a big fat &lt;b&gt;"NumberFormatException"&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;I hope the Java Code provide to convert an a String to an int was helpful. Do leave a comment if you liked the article. &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; will soon be back with another interesting Java article.&lt;br /&gt;&lt;br /&gt;Related Java Codes:-&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/08/convert-int-to-string-in-java-code.html"&gt;Convert int to String in Java&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/09/convert-int-to-string-using-wrapper-in.html"&gt;Convert int to String in Java using Wrapper Classes&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-3673867768349300983?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/09/convert-string-to-integer-int-in-java.html' title='Convert String to integer (int) in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/3673867768349300983/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/convert-string-to-integer-int-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3673867768349300983'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3673867768349300983'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/convert-string-to-integer-int-in-java.html' title='Convert String to integer (int) in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-5686993073084068158</id><published>2009-09-06T14:59:00.003+05:30</published><updated>2009-09-06T15:12:44.737+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><category scheme='http://www.blogger.com/atom/ns#' term='String'/><title type='text'>Convert int to String using Wrapper in Java</title><content type='html'>Hello and welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. I have seen a few comments from some of my readers, it was regarding an alternative way to &lt;a href = "http://javacodeonline.blogspot.com/2009/08/convert-int-to-string-in-java-code.html"&gt;convert an integer to String&lt;/a&gt;. This method uses the Wrapper Objects to convert an int to an Integer Object. Or you can say that, the process is:-&lt;br /&gt;&lt;br /&gt;1. Convert a primitive to an Object using the Wrapper Classes.&lt;br /&gt;2. Then convert the Wrapper Object in to a String. &lt;br /&gt;&lt;br /&gt;Though it is a lengthier process, and is therefore rarely used for converting an ant to String. The best process is the one which I discussed in the previous article to convert an int to String. It is the most easiest and fastest way for making the conversion. Anyhow I will give you the alternative way also which I have discussed write now.&lt;br /&gt;&lt;br /&gt;The Java Code starts by asking the user to enter an integer number. This number is then converted to an Integer Wrapper Object, which is later converted to a String, by using the toString() method on it.&lt;br /&gt;&lt;br /&gt;The Java Code for a sample program on it is given below.&lt;br /&gt;&lt;br /&gt;///////////////////////////////////////&lt;br /&gt;&lt;font color = "green"&gt;&lt;br /&gt;/*&lt;br /&gt; * This class converts an int number to an Integer Wrapper Object and then transforms that Object in to a String&lt;br /&gt; */&lt;br /&gt;&lt;br /&gt;package developer;&lt;br /&gt;&lt;br /&gt;import java.util.Scanner;&lt;br /&gt;&lt;br /&gt;public class IntToStringUsingWrapper {&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  &lt;br /&gt;  int number = 0;&lt;br /&gt;  System.out.println("Enter a number which would be taken as an Integer by the application");&lt;br /&gt;  &lt;br /&gt;  Scanner scanInt = new Scanner(System.in);&lt;br /&gt;  &lt;br /&gt;  //Execute if the number entered is an integer&lt;br /&gt;  if(scanInt.hasNextInt())&lt;br /&gt;  {&lt;br /&gt;   number = scanInt.nextInt();&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  //Wrap the number in the Integer Wrapper Object&lt;br /&gt;  Integer num = new Integer(number);&lt;br /&gt;  &lt;br /&gt;  //The num is converted to a String&lt;br /&gt;  String strNum = num.toString();&lt;br /&gt;  &lt;br /&gt;  //Use the toString() method to convert the object in to String&lt;br /&gt;  System.out.println("The number entered is: "+strNum);&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;///////////////////////////////////////&lt;br /&gt;&lt;br /&gt;The output is something like shown below:-&lt;br /&gt;&lt;br /&gt;///////////////////////////////////////&lt;br /&gt;&lt;font color = "green"&gt;&lt;br /&gt;Enter a number which would be taken as an Integer by the application&lt;br /&gt;33&lt;br /&gt;The number entered is: 33&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;///////////////////////////////////////&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; hope that this article was helpful to resolve the issue of an alternative way to convert an int to a String. If you find the article useful, then do leave a comment. Keep checking &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; for more Java topics.&lt;br /&gt;&lt;br /&gt; Related articles:-&lt;br /&gt; &lt;a href = "http://javacodeonline.blogspot.com/2009/08/convert-int-to-string-in-java-code.html"&gt;Convert int to String in Java&lt;/a&gt;&lt;br /&gt; &lt;a href = "http://javacodeonline.blogspot.com/2009/08/number-of-words-in-string-java-program.html"&gt;Java Code for Number of Words in a String&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-5686993073084068158?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/09/convert-int-to-string-using-wrapper-in.html' title='Convert int to String using Wrapper in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/5686993073084068158/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/convert-int-to-string-using-wrapper-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/5686993073084068158'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/5686993073084068158'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/09/convert-int-to-string-using-wrapper-in.html' title='Convert int to String using Wrapper in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-4244477673259477500</id><published>2009-08-26T21:47:00.008+05:30</published><updated>2010-12-13T01:19:21.600+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='String In Java'/><title type='text'>Convert int to String in Java Code</title><content type='html'>&lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; is going to discuss the way to convert an int into a String in Java. It is often required in Java programming, to convert an integer into a String value, and operate on it assuming it to be String.&lt;br /&gt;&lt;br /&gt;Converting an integer into a String, provides many powerful features and methods which are inherent to Strings, but not to primitives like integer. That make the operating on the value much more easier when the value is used as a String. &lt;br /&gt;&lt;br /&gt;I will discuss the most commonly used, and in fact the most easiest and effective method of converting an int into a String.&lt;br /&gt;&lt;br /&gt;&lt;div style="color: #4c1130;"&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;Use the + operator to convert int to String&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;1. Use the "+" operator, for converting an int into a String.&lt;br /&gt;&lt;br /&gt;Simple isn't it. The logic is that the "+" operator is overloaded in Java. It performs many functions. When used with two integers, it produces the sum. But when a string is used with an int and the "+" operator in between, the the result is a String. For example:-&lt;br /&gt;&lt;br /&gt;&lt;b style="color: #4c1130;"&gt;The issue with + operator for int&lt;/b&gt;&lt;br /&gt;Using the + operator with ints result in their addition. The example demonstrates this:-&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;&amp;nbsp; package JavaTest1;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;class TestIntToString {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public static void main(String[] args)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;int i = 2;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;int j = 3;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;System.out.println(i + j);&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The above code wil&lt;span style="background-color: white;"&gt;l result in printing &lt;/span&gt;&lt;b&gt;&lt;span style="background-color: white; color: #7f6000;"&gt;5&lt;/span&gt;&lt;/b&gt;&lt;span style="background-color: white;"&gt;. This is not what we wanted, so the solution is to use a string in between.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="color: #4c1130;"&gt;Solution for converting int to String in Java&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;If we change the above code such that the variable "j" is a String with some String assigned to it. Then the output will be a String. For example:-&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&lt;/div&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; package JavaTest1;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;class TestIntToString {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public static void main(String[] args)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;int i = 2;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;String j = "";&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;int k = 3;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;System.out.println(i + j + k);&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/div&gt;&lt;br /&gt;When the above code is executed, the the output is:-&lt;br /&gt;&lt;div style="background-color: #999999;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 23&lt;/div&gt;&lt;br /&gt;So we see that this time the two numbers do not get added, but they resulted in concatenating to each other. This is because they are converted to String. That's really cool. Now this String can use all the methods which are available to Strings. So making it really powerful.&lt;br /&gt;&lt;br /&gt;So you can see that by using the "+" operator, you can easily convert an int into a String. I hope the post was helpful to you all. Keep buzzing &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; for more info on Java.&lt;br /&gt;&lt;br /&gt;Other Links of interest:-&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/09/convert-int-to-string-using-wrapper-in.html"&gt;Convert int to String using Wrapper in Java&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/reverse-string-java-program.html"&gt;Reverse a String&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/length-of-string-java-program.html"&gt;Length of String&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/08/number-of-words-in-string-java-program.html"&gt;Number of words in String&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/08/palindrome-java-program.html"&gt;Palindrome Java program&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-4244477673259477500?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/convert-int-to-string-in-java-code.html' title='Convert int to String in Java Code'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/4244477673259477500/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/convert-int-to-string-in-java-code.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/4244477673259477500'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/4244477673259477500'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/convert-int-to-string-in-java-code.html' title='Convert int to String in Java Code'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3416407328338427543.post-2231615015133669854</id><published>2009-08-26T00:17:00.002+05:30</published><updated>2009-10-06T18:00:19.055+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><category scheme='http://www.blogger.com/atom/ns#' term='Interface'/><title type='text'>Deadly Diamond of Death</title><content type='html'>Hearty welcome from &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Today's topic is DDD, that is Deadly Diamond of Death. As promised in my earlier post, and as asked by some of my friends in their comments, I will pick this topic to clarify all the myths and doubts. Though the name is Deadly, the topic is not so Deadly, since it is avoided in Java. Java as we all know is a very powerful language. It has all the good features, and avoids all the bad features including the one which will be discussed today.&lt;br /&gt;&lt;br /&gt;Java does not support multiple Inheritance. Though it is supported in C++, Java avoids it. The reason for avoiding multiple Inheritance is the &lt;b&gt;Deadly Diamond of Death&lt;/b&gt;. Actually the class diagram that is formed in this scenario, is that of a diamond, and it is like a no solution output, so the code gets locked, so it is called Deadly Diamond of death. Thus the Java language do support multiple implementations, but not multiple Inheritance. So a class can &lt;b&gt;implement&lt;/b&gt; many &lt;a href = "http://javacodeonline.blogspot.com/2009/08/what-is-interface-in-java.html"&gt;Interfaces&lt;/a&gt;, but can not &lt;b&gt;extend&lt;/b&gt; more than one class.&lt;br /&gt;&lt;br /&gt;I will explain the issue by taking an example. Suppose that Java supports multiple inheritance (though it does not, but still we will assume it to understand the current concept). Just go through the following points for a clearer understanding:-&lt;br /&gt;&lt;br /&gt;1. Suppose that we have an abstract super class, with an abstract method in it.&lt;br /&gt;&lt;br /&gt;2. Now two concrete class extend this abstract super class, and provides the implementation of the abstract method in the super class, in two different ways.&lt;br /&gt;&lt;br /&gt;3. Now a fourth class comes into picture which &lt;b&gt;extends&lt;/b&gt; the above two concrete classes. So now by the principle of inheritance it inherits all the methods of the parent class, but we have a common method in the two concrete classes but with different implementations, so which implementation will be used for the last child class which inherits both these classes?&lt;br /&gt;&lt;br /&gt;Actually no one has got the answer to the above question, and so to avoid this sort of critical issue, Java banned multiple inheritance. The class diagram which is formed above is like that of a diamond, but with no solution or outcome, and so it is called Deadly Diamond of Death.&lt;br /&gt;&lt;br /&gt;I will try to make it more clear, by taking an example. Take this:-&lt;br /&gt;&lt;br /&gt;// This is our top most abstract class.&lt;br /&gt;class AbstractSuperClass{&lt;br /&gt;abstract void do();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// These are the two concrete sub classes which extend the above super class&lt;br /&gt;class ConcreteOne extends AbstractSuperClass{&lt;br /&gt;void do(){&lt;br /&gt;System.out.println("I am going to test multiple Inheritance");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class ConcreteTwo extends AbstractSuperClass{&lt;br /&gt;void do(){&lt;br /&gt;System.out.println("I will cause the Deadly Diamond of Death");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// This is our last class which extends both of the above concrete classes&lt;br /&gt;class DiamondEffect extends ConcreteOne, ConcreteTwo{&lt;br /&gt;//Some methods of this class&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;!-- You will NOT be able to see the ad on your site! This unit is hidden on your page, and will only display to your search engine traffic (from US and CA). To preview, paste the code up on your site, then add #chitikatest=mortgage to the end of your URL in your browser's address bar.  Example:  www.yourwebsite.com#chitikatest=mortgage. This will show you what the ad would look like to a user who is interested in "mortgages." --&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;!--ch_client = "amittechno";ch_type = "mpu";ch_width = 728;ch_height = 90;ch_non_contextual = 4;ch_vertical ="premium";ch_sid = "Chitika Premium";var ch_queries = new Array( );var ch_selected=Math.floor((Math.random()*ch_queries.length));if ( ch_selected &lt; ch_queries.length ) {ch_query = ch_queries[ch_selected];}//--&gt;&lt;/script&gt;&lt;br /&gt;&lt;script  src="http://scripts.chitika.net/eminimalls/amm.js" type="text/javascript"&gt;&lt;/script&gt;&lt;br /&gt;Now what do you think will happen, when an Object of class DiamondEffect is made, and the do method is called?&lt;br /&gt;&lt;br /&gt;Since the DiamondEffect class extends both the ConcreteOne and ConcreteTwo classes, it inherits the "do" method from both of them, but the DiamondEffect class does not know which one to use when the method is called on it. The structure of class diagram here is like a diamond. This is the Deadly Diamond of Death.&lt;br /&gt;&lt;br /&gt;I hope I was able to make my point clear. If you have any doubts or issues, then do write a comment for me, and I will try my best to answer you. You may leave a comment if you like the article. &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; will see you later in the next post.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-2231615015133669854?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/deadly-diamond-of-death.html' title='Deadly Diamond of Death'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/2231615015133669854/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/deadly-diamond-of-death.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/2231615015133669854'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/2231615015133669854'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/deadly-diamond-of-death.html' title='Deadly Diamond of Death'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3416407328338427543.post-404951052362982450</id><published>2009-08-25T22:54:00.003+05:30</published><updated>2009-08-25T23:01:30.654+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='final'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>What are final methods in Java</title><content type='html'>Hello guys, &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; welcomes you back again, and is going to discuss about the &lt;b&gt;final methods&lt;/b&gt; in the Java Programming Language. The Java language provides its users with many resources and tools. There are many features in the Java language that makes it very powerful. Final access modifier is one of those features, that makes Java really solid.&lt;br /&gt;&lt;br /&gt;If a method is marked as &lt;b&gt;final&lt;/b&gt;, then it implies that it cannot be overridden. So any class that extends the class containing the final methods, cannot override the methods marked final. If any attempt is done to override a final method in a sub class, leads to &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-java-compiler.html"&gt;Java Compiler&lt;/a&gt; error.&lt;br /&gt;&lt;br /&gt;An example of a final method in a class is:-&lt;br /&gt;&lt;br /&gt;/////////////////////////////&lt;br /&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;class&lt;/a&gt; TestFinal{&lt;br /&gt;&lt;br /&gt;public final void finalTested(){&lt;br /&gt;//Working of this method&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//Some other methods&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/////////////////////////////&lt;br /&gt;&lt;br /&gt;The above Java code depicts the use of &lt;b&gt;final&lt;/b&gt; when applied to methods.&lt;br /&gt;&lt;br /&gt;You may be thinking that what is the advantage of making a method final, though it defies the basic &lt;a href = "http://javacodeonline.blogspot.com/2008/12/principle-of-oops.html"&gt;principle of OOPS&lt;/a&gt;, that is the final methods are non supportive of inheritance, as they cannot be overridden. It implies that they cannot be extended, and so also makes Polymorphism not feasible for it. &lt;br /&gt;&lt;br /&gt;Hmmm... it implies that there are many drawbacks of the final method, but still Java provides it. So there must be some advantage of it also... Lets check them out.&lt;br /&gt;&lt;br /&gt;Think of a scenario, that you have made a class, and you want a particular method to be implemented in exactly a particular way, and one should be never allowed to change this implementation. There are many possibilities for it. Like there are many methods in the Java API, which are guaranteed to work in a fixed way, and there is no way we can change them. This scenario calls for marking the method of the class as final. Later I will tell you about the &lt;b&gt;Template Design Pattern&lt;/b&gt; which is based on this concept.&lt;br /&gt;&lt;br /&gt;I hope you got my point. Whenever you want the methods to be locked, and should not be allowed to be modified, then &lt;b&gt;final&lt;/b&gt; is the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/java-keywords-and-reserved-words.html"&gt;keyword&lt;/a&gt; to be used. The class can still be inherited since it is not marked final, and so the concept of Inheritance and Polymorphism can easily work here, but only for methods which are not marked as final in the super class. &lt;br /&gt;&lt;br /&gt;Hope that the article was helpful to you all in understanding the final methods in Java. Keep ticking &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; for more details on Java.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-404951052362982450?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/what-are-final-methods-in-java.html' title='What are final methods in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/404951052362982450/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/what-are-final-methods-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/404951052362982450'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/404951052362982450'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/what-are-final-methods-in-java.html' title='What are final methods in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-2413799222971170471</id><published>2009-08-22T04:40:00.002+05:30</published><updated>2009-08-22T04:45:12.172+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><category scheme='http://www.blogger.com/atom/ns#' term='Interface'/><category scheme='http://www.blogger.com/atom/ns#' term='OOPS Principles'/><title type='text'>What is an Interface in Java</title><content type='html'>Bingo, so we are going to discuss a very important topic today at &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Interfaces has been he heart of most of the Java fundamentals and coding, mostly because there existence support Polymorphism, which is one of the four &lt;a href = "http://javacodeonline.blogspot.com/2008/12/principle-of-oops.html"&gt;Principle of OOPS&lt;/a&gt; apart from &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-abstraction.html"&gt;Abstraction&lt;/a&gt;, Encapsulation and Inheritance.&lt;br /&gt;&lt;br /&gt;Interface as the name suggests is a "Contract". Yes you read it right. It is contract between the interface provider and the interface implementer that the methods mentioned in the Interface will be implemented. Mostly Interfaces are used vis a vis Inheritance, and there is much research done before choosing one.&lt;br /&gt;&lt;br /&gt;An Interface is like a pure &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-abstract-class.html"&gt;abstract class&lt;/a&gt;, with the difference that the all the methods of the interface are abstract, so any class that implements this interface has to implement all the methods mentioned in this interface. That's the law. So actually the interface tells that which methods are to be implemented, but not that how we are going to implement. It is left for the subclasses to decide how to implement this.&lt;br /&gt;&lt;br /&gt;One important part of Java is that it supports multiple Implementations, but not multiple Inheritance. So a subclass can &lt;b&gt;implement&lt;/b&gt; multiple Interfaces, but cannot &lt;b&gt;extend&lt;/b&gt; multiple classes. I will detail on this in a later post where I will tell you that if multiple Inheritance is allowed, then how it may lead to the &lt;b&gt;Deadly Diamond of death&lt;/b&gt;. Anyhow that's a bit deviating from the main topic. Our primary concern are the Interfaces.&lt;br /&gt;&lt;br /&gt;An example of an Interface is shown below:-&lt;br /&gt;&lt;br /&gt;////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;Interface JavaTest{&lt;br /&gt;public static final int val = 3;&lt;br /&gt;&lt;br /&gt;public abstract doTest();&lt;br /&gt;public abstract takeResult();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;Here in this Interface declaration file, the keywords public and abstract are not required for the methods as they are implicit. Moreover the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/java-keywords-and-reserved-words.html"&gt;keywords&lt;/a&gt; for the variable declared in the Interface are also not required as they are also implicit. &lt;br /&gt;&lt;br /&gt;So any variable declared in an Interface is practically a constant, and all the methods which are declared in the interface have to be implemented by the first concrete subclass that implements this interface.&lt;br /&gt;&lt;br /&gt;There is one key point regarding the Interfaces, and that is you cannot declare the methods of the Interface to be &lt;b&gt;final&lt;/b&gt;. Remember that final methods cannot be overridden, and an abstract method is useless if we do not override it. That is the main reason that abstract and final are never used together for any method.&lt;br /&gt;&lt;br /&gt;I hope the article was helpful in understanding the Interface in Java. Do post a comment if you liked the article. For more Java info &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; is the key.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-2413799222971170471?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/what-is-interface-in-java.html' title='What is an Interface in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/2413799222971170471/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/what-is-interface-in-java.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/2413799222971170471'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/2413799222971170471'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/what-is-interface-in-java.html' title='What is an Interface in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3416407328338427543.post-8891230273176322443</id><published>2009-08-22T03:44:00.002+05:30</published><updated>2009-08-22T03:53:01.963+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Method'/><category scheme='http://www.blogger.com/atom/ns#' term='Scanner'/><category scheme='http://www.blogger.com/atom/ns#' term='File'/><title type='text'>Java Code for File Extension</title><content type='html'>Hi friends, Java Code Online welcomes you back again. The last post I have made was for getting the &lt;a href = "http://javacodeonline.blogspot.com/2009/08/remove-extension-of-file-java-code.html"&gt;file name without the extension of the file&lt;/a&gt;. But there are many scenarios when we desire the extension of the file, and not the name of the file.&lt;br /&gt;&lt;br /&gt;The Java code here asks the user to enter a valid file name, and then remove the file name but keep the extension of it. So the user enters a file name and gets the extension of it.&lt;br /&gt;&lt;br /&gt;The Java Code is provided below:-&lt;br /&gt;&lt;br /&gt;///////////////////////////////////&lt;br /&gt;package developer;&lt;br /&gt;&lt;br /&gt;import java.util.Scanner;&lt;br /&gt;&lt;br /&gt;public class FileExtension {&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * @param args&lt;br /&gt;  */&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  &lt;br /&gt;  String fileExt = null;&lt;br /&gt;  &lt;br /&gt;  System.out.println("Enter a valid file name whose extension is desired:");&lt;br /&gt;  &lt;br /&gt;  Scanner scan = new Scanner(System.in);&lt;br /&gt;  &lt;br /&gt;  if(scan.hasNext())&lt;br /&gt;  {&lt;br /&gt;   fileExt = getFileExtension(scan.next());&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  if(null != fileExt)&lt;br /&gt;  {&lt;br /&gt;  System.out.println("The extension of the file is: "+fileExt);&lt;br /&gt;  }&lt;br /&gt;  else&lt;br /&gt;  {&lt;br /&gt;   System.out.println("Not a valid file name");&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //get the file extension of the file entered&lt;br /&gt; public static String getFileExtension(String filePath)&lt;br /&gt; {&lt;br /&gt;  String extension = null;&lt;br /&gt;  if(null != filePath &amp;&amp; filePath.contains("."))&lt;br /&gt;  {&lt;br /&gt;   extension = filePath.substring(filePath.lastIndexOf("."), filePath.length());   &lt;br /&gt;  }&lt;br /&gt;  return extension;  &lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;When this code is executed, the output is something like as given below:-&lt;br /&gt;&lt;br /&gt;//////////////////////////////////////////&lt;br /&gt;Output&lt;br /&gt;&lt;br /&gt;Enter a valid file name whose extension is desired:&lt;br /&gt;javadeveloper.java&lt;br /&gt;The extension of the file is: .java&lt;br /&gt;/////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;I hope the article was helpful, and my efforts did not went in vain. Keep ticking &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; for more Java details.&lt;br /&gt;&lt;br /&gt;Other article of interest:-&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/08/remove-extension-of-file-java-code.html"&gt;Remove the extension from the filename&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-8891230273176322443?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/java-code-for-file-extension.html' title='Java Code for File Extension'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/8891230273176322443/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/java-code-for-file-extension.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/8891230273176322443'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/8891230273176322443'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/java-code-for-file-extension.html' title='Java Code for File Extension'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-2975803899442379696</id><published>2009-08-22T03:33:00.002+05:30</published><updated>2009-08-22T03:43:53.824+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Method'/><category scheme='http://www.blogger.com/atom/ns#' term='Scanner'/><category scheme='http://www.blogger.com/atom/ns#' term='File'/><title type='text'>Remove Extension of File Java Code</title><content type='html'>Hello friends, welcome once again at &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. The topic of the day is the Java code that helps in removing the extension of a file name that is entered by the user.&lt;br /&gt;&lt;br /&gt;The operation is a simple one and is crucial in case of file handling. Though mostly we need to remove the file extension before processing the file, there may be other requirements that ask for this requirement.&lt;br /&gt;&lt;br /&gt;Anyhow the Java Code is provided below:-&lt;br /&gt;&lt;br /&gt;//////////////////////////////&lt;br /&gt;&lt;br /&gt;package developer;&lt;br /&gt;&lt;br /&gt;import java.util.Scanner;&lt;br /&gt;&lt;br /&gt;public class RemoveFileExtension {&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  &lt;br /&gt;  String fileRemExt = null;&lt;br /&gt;  &lt;br /&gt;  System.out.println("Enter a valid file name whose extension is to be removed:");&lt;br /&gt;  &lt;br /&gt;  Scanner rem = new Scanner(System.in);&lt;br /&gt;  &lt;br /&gt;  if(rem.hasNext())&lt;br /&gt;  {&lt;br /&gt;   fileRemExt = removeFileExtension(rem.next());&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  if(null != fileRemExt)&lt;br /&gt;  {&lt;br /&gt;  System.out.println("The file name without extension is: "+fileRemExt);&lt;br /&gt;  }&lt;br /&gt;  else&lt;br /&gt;  {&lt;br /&gt;   System.out.println("Not a valid file name");&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //remove the file extension of the file entered&lt;br /&gt; public static String removeFileExtension(String fileName)&lt;br /&gt; {  &lt;br /&gt;  if(null != fileName &amp;&amp; fileName.contains("."))&lt;br /&gt;  {&lt;br /&gt;   return fileName.substring(0, fileName.lastIndexOf("."));&lt;br /&gt;  }&lt;br /&gt;  return null;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;////////////////////////////////////&lt;br /&gt;&lt;br /&gt;Once this code is executed, the output is something like:-&lt;br /&gt;&lt;br /&gt;////////////////////////////////////&lt;br /&gt;Output&lt;br /&gt;&lt;br /&gt;Enter a valid file name whose extension is to be removed:&lt;br /&gt;test.java&lt;br /&gt;The file name without extension is: test&lt;br /&gt;////////////////////////////////////&lt;br /&gt;&lt;br /&gt;I hope the article was helpful to most of you. In case you liked the article then do leave a comment at &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-2975803899442379696?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/remove-extension-of-file-java-code.html' title='Remove Extension of File Java Code'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/2975803899442379696/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/remove-extension-of-file-java-code.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/2975803899442379696'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/2975803899442379696'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/remove-extension-of-file-java-code.html' title='Remove Extension of File Java Code'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-3557083386106091875</id><published>2009-08-20T23:15:00.002+05:30</published><updated>2009-08-20T23:22:39.743+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><category scheme='http://www.blogger.com/atom/ns#' term='Inner Classes'/><title type='text'>Anonymous Inner Class in Java</title><content type='html'>Hi everybody, &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; is going to discuss the Anonymous Inner Class in Java today. This class as the name specifies is not named. It means that this class has a body but no name. And so it is anonymous.&lt;br /&gt;&lt;br /&gt;It is one of the most bizarre type of Inner class. It is always invoked from outside the Outer class. When the invocation is done, then this class is placed after the brackets of the method invocation. The key to understand this is that, actually the Anonymous inner class always &lt;b&gt;extend&lt;/b&gt; or &lt;b&gt;implement&lt;/b&gt;, but not both at the same time.&lt;br /&gt;&lt;br /&gt;When the Outer class is invoked, then the syntax is something like:-&lt;br /&gt;&lt;br /&gt;OuterClass oc = new OuterClass();&lt;br /&gt;&lt;br /&gt;But when the anonymous inner class comes into picture the code is something like:-&lt;br /&gt;&lt;br /&gt;OuterClass oc = new OuterClass(){&lt;br /&gt;//some inherited method&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;The syntax though very much strange is the correct one. Here the curly braces after the instantiation call infact causes an anonymous inner class to be formed which either inherits or implements the method of the instantiated class. So the only methods available here are the one by inheritance or implements. Note the semicolon at the end of the curly braces, strange but true. Here the main concept is of Polymorphism as the name of the super class is used to refer the sub class, which is our anonymous inner class in this case.&lt;br /&gt;&lt;br /&gt;For reference,&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/08/types-of-inner-class-in-java.html"&gt;Types of Inner Class&lt;/a&gt;&lt;br /&gt;1. &lt;a href = "http://javacodeonline.blogspot.com/2009/08/regular-inner-class-in-java.html"&gt;Regular Inner Class&lt;/a&gt;&lt;br /&gt;2. &lt;a href = "http://javacodeonline.blogspot.com/2009/08/method-local-inner-class-in-java.html"&gt;Method Local Inner Class&lt;/a&gt;&lt;br /&gt;3. &lt;a href = "http://javacodeonline.blogspot.com/2009/08/anonymous-inner-class-in-java.html"&gt;Anonymous Inner Class&lt;/a&gt;&lt;br /&gt;4. &lt;a href = "http://javacodeonline.blogspot.com/2009/08/static-inner-nested-class-in-java.html"&gt;Static Nested Inner Class&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Hope that the article helped solved your issues with this type of class. Remember &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; is the key to a vast pool of Java. That's it for now. See you later.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-3557083386106091875?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/anonymous-inner-class-in-java.html' title='Anonymous Inner Class in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/3557083386106091875/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/anonymous-inner-class-in-java.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3557083386106091875'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3557083386106091875'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/anonymous-inner-class-in-java.html' title='Anonymous Inner Class in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-3021460741023793496</id><published>2009-08-20T23:12:00.001+05:30</published><updated>2009-08-20T23:24:18.676+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><category scheme='http://www.blogger.com/atom/ns#' term='Inner Classes'/><title type='text'>Method Local Inner Class in Java</title><content type='html'>Hello and welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Today I will be discussing about the Method Local Inner Class in Java. It is one of the four subtypes of Inner Classes.&lt;br /&gt;&lt;br /&gt;The Method Local Inner class, as the name specifies is local to a method. It implies that the method local Inner class is defined inside a method of a &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;class&lt;/a&gt;. As the class is defined inside a method, it needs to be instantiated from with in the same method, but after the class definition is finished. As a mater of fact this inner class cannot use the variables of the same method, unless they are declared &lt;b&gt;final&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;If you did not instantiate the class within the same method and after the class definition is finished, then that inner class though valid will be useless, as there is no other way to instantiate it. Moreover the Instantiation must be after the class definition or else the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-java-compiler.html"&gt;Java Compiler&lt;/a&gt; will not be able to see it.&lt;br /&gt;&lt;br /&gt;Hoping that this article was helpful to you all. Do post a comment if you liked this article.&lt;br /&gt;&lt;br /&gt;For reference,&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/08/types-of-inner-class-in-java.html"&gt;Types of Inner Class&lt;/a&gt;&lt;br /&gt;1. &lt;a href = "http://javacodeonline.blogspot.com/2009/08/regular-inner-class-in-java.html"&gt;Regular Inner Class&lt;/a&gt;&lt;br /&gt;2. &lt;a href = "http://javacodeonline.blogspot.com/2009/08/method-local-inner-class-in-java.html"&gt;Method Local Inner Class&lt;/a&gt;&lt;br /&gt;3. &lt;a href = "http://javacodeonline.blogspot.com/2009/08/anonymous-inner-class-in-java.html"&gt;Anonymous Inner Class&lt;/a&gt;&lt;br /&gt;4. &lt;a href = "http://javacodeonline.blogspot.com/2009/08/static-inner-nested-class-in-java.html"&gt;Static Nested Inner Class&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; for more Java Information.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-3021460741023793496?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/method-local-inner-class-in-java.html' title='Method Local Inner Class in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/3021460741023793496/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/method-local-inner-class-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3021460741023793496'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3021460741023793496'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/method-local-inner-class-in-java.html' title='Method Local Inner Class in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-7475107249130168535</id><published>2009-08-20T23:09:00.003+05:30</published><updated>2009-10-13T03:03:29.335+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><category scheme='http://www.blogger.com/atom/ns#' term='Inner Classes'/><title type='text'>Static Inner Nested Class in Java</title><content type='html'>Hi friends, welcome back to &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. This article is in continuation to the previous article on Regular Inner Class, here I will discuss the second type of Inner Class called Static Inner Nested Class.&lt;br /&gt;&lt;br /&gt;The static Inner Nested Classes are nothing else, but are like Regular Inner class, but are marked &lt;b&gt;static&lt;/b&gt;. So the behavior of these classes is static in nature. This explains most of the behavior of the static inner class. Like it behaves like a class level variable. I mean to say that, you need not instantiate the outer class for creating an instance of the static inner class, and that the static inner class can be directly instantiated.&lt;br /&gt;&lt;br /&gt;Moreover as the behavior of a static member is, the static inner class cannot access the non static members of the class, this is in sync with the basic properties of a static variable or member of a class. For instantiating a Static Inner Class, you need to use the name of both the Outer class and Inner class. For example:-&lt;br /&gt;&lt;br /&gt;OuterClass.InnerClass ocic = new OuterClass.InnerClass();&lt;br /&gt;&lt;br /&gt;I hope the article was helpful. In case it was, the do leave a comment.&lt;br /&gt;&lt;br /&gt;For reference,&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/08/types-of-inner-class-in-java.html"&gt;Types of Inner Class&lt;/a&gt;&lt;br /&gt;1. &lt;a href="http://javacodeonline.blogspot.com/2009/08/regular-inner-class-in-java.html"&gt;Regular Inner Class&lt;/a&gt;&lt;br /&gt;2. &lt;a href="http://javacodeonline.blogspot.com/2009/08/method-local-inner-class-in-java.html"&gt;Method Local Inner Class&lt;/a&gt;&lt;br /&gt;3. &lt;a href="http://javacodeonline.blogspot.com/2009/08/anonymous-inner-class-in-java.html"&gt;Anonymous Inner Class&lt;/a&gt;&lt;br /&gt;4. &lt;a href="http://javacodeonline.blogspot.com/2009/08/static-inner-nested-class-in-java.html"&gt;Static Nested Inner Class&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Keep checking &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; for more Java info.&lt;br /&gt;&lt;br /&gt;You might be interested in these too:-&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/10/static-inner-class-example-in-java.html"&gt;Static Inner Class Example in Java&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-7475107249130168535?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/static-inner-nested-class-in-java.html' title='Static Inner Nested Class in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/7475107249130168535/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/static-inner-nested-class-in-java.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/7475107249130168535'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/7475107249130168535'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/static-inner-nested-class-in-java.html' title='Static Inner Nested Class in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-1340892383897915995</id><published>2009-08-20T23:05:00.002+05:30</published><updated>2009-08-20T23:26:13.390+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><category scheme='http://www.blogger.com/atom/ns#' term='Inner Classes'/><title type='text'>Regular Inner Class in Java</title><content type='html'>Hi friends, welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Today's article discuss the regular inner class in Java. Though the inner classes could be classified in 4 sub types, regular inner classes is the most commonly used sub type.&lt;br /&gt;&lt;br /&gt;The regular inner class is a full fledged member of the outer class, so it shares all the features of a member of a &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;class&lt;/a&gt;. Like an Inner class has access to all the variable of the outer class including the private variables. There is a special way to instantiate an Inner class. For instantiating a regular Inner Class, you need to instantiate the Outer class first.&lt;br /&gt;&lt;br /&gt;If you are invoking the regular inner class from inside the Outer class, then it could be instantiated like a regular class, like:-&lt;br /&gt;&lt;br /&gt;InnerClass ic = &lt;a href = "http://javacodeonline.blogspot.com/2008/12/how-to-create-new-object-in-java.html"&gt;new&lt;/a&gt; InnerClass();&lt;br /&gt;&lt;br /&gt;But if the Inner class needs to be instantiated from outside the Outer class, then first you need to get a reference of the Outer class &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt;, and then create an Object of the Inner class from that. The syntax is something like given below:-&lt;br /&gt;&lt;br /&gt;OuterClass oc = new Outer Class();&lt;br /&gt;OuterClass.InnerClass ic = oc.new InnerClass();&lt;br /&gt;&lt;br /&gt;I hope that this article was helpful in clearing all your doubts about Regular Inner Classes.&lt;br /&gt;&lt;br /&gt;For reference,&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/08/types-of-inner-class-in-java.html"&gt;Types of Inner Class&lt;/a&gt;&lt;br /&gt;1. &lt;a href = "http://javacodeonline.blogspot.com/2009/08/regular-inner-class-in-java.html"&gt;Regular Inner Class&lt;/a&gt;&lt;br /&gt;2. &lt;a href = "http://javacodeonline.blogspot.com/2009/08/method-local-inner-class-in-java.html"&gt;Method Local Inner Class&lt;/a&gt;&lt;br /&gt;3. &lt;a href = "http://javacodeonline.blogspot.com/2009/08/anonymous-inner-class-in-java.html"&gt;Anonymous Inner Class&lt;/a&gt;&lt;br /&gt;4. &lt;a href = "http://javacodeonline.blogspot.com/2009/08/static-inner-nested-class-in-java.html"&gt;Static Nested Inner Class&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;For more information on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-1340892383897915995?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/regular-inner-class-in-java.html' title='Regular Inner Class in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/1340892383897915995/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/regular-inner-class-in-java.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1340892383897915995'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1340892383897915995'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/regular-inner-class-in-java.html' title='Regular Inner Class in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-1293999263472735949</id><published>2009-08-20T23:01:00.003+05:30</published><updated>2009-08-20T23:28:04.153+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><category scheme='http://www.blogger.com/atom/ns#' term='Inner Classes'/><title type='text'>Types of Inner Class in Java</title><content type='html'>Hi friends, &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; welcomes you back again. Today's article discuss the Inner classes in Java. An Inner class is like a &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;class&lt;/a&gt; but it is defined inside another class. So the behavior is like of a class but is internal to a class.&lt;br /&gt;&lt;br /&gt;The Inner Classes can be classified in four types. They are:-&lt;br /&gt;1. &lt;a href = "http://javacodeonline.blogspot.com/2009/08/regular-inner-class-in-java.html"&gt;Regular Inner Class&lt;/a&gt;&lt;br /&gt;2. &lt;a href = "http://javacodeonline.blogspot.com/2009/08/method-local-inner-class-in-java.html"&gt;Method Local Inner Class&lt;/a&gt;&lt;br /&gt;3. &lt;a href = "http://javacodeonline.blogspot.com/2009/08/anonymous-inner-class-in-java.html"&gt;Anonymous Inner Class&lt;/a&gt;&lt;br /&gt;4. &lt;a href = "http://javacodeonline.blogspot.com/2009/08/static-inner-nested-class-in-java.html"&gt;Static Nested Inner Class&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;All the types of inner classes are defined in their respective articles. The Inner classes though not much commonly used in Java, still find some important place in some programs. Though it is a bit too odd to see a class being placed inside another class, the behavior is more or less like a local method of the outer class. There is different functionality for all the different types of Inner classes. You may find the details in the individual articles for each type of Inner class.&lt;br /&gt;&lt;br /&gt;I hope the article was able to clear your myth and doubts about the Inner classes in Java. If you liked the article then do leave a comment. Keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; for more Java articles.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-1293999263472735949?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/types-of-inner-class-in-java.html' title='Types of Inner Class in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/1293999263472735949/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/types-of-inner-class-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1293999263472735949'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1293999263472735949'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/types-of-inner-class-in-java.html' title='Types of Inner Class in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-3339098103931678621</id><published>2009-08-19T01:53:00.005+05:30</published><updated>2009-08-19T02:07:31.363+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Math'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='Armstrong Number'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><category scheme='http://www.blogger.com/atom/ns#' term='Scanner'/><title type='text'>Armstrong Number Java Program</title><content type='html'>Hello, welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Today I would be discussing an important mathematical Java Code. This Java Code is for Armstrong Number. The code asks the user to enter a number, and then checks that whether it is Armstrong Number or not.&lt;br /&gt;&lt;br /&gt;An Armstrong Number is one in which the sum of the individual numbers raised to the power of the number of words in that number is equal to that particular number itself. For example 1 raised to the power 1 is equal to 1, so it is an Armstrong Number. Again 153, implies 1 raised to the power 3, 5 raised to the power 3, and then 3 raised to the power 3 are added, then it gives 153 again, so it is also an Armstrong Number.&lt;br /&gt;&lt;br /&gt;The Java Code is given below:-&lt;br /&gt;&lt;br /&gt;////////////////////////////////////&lt;br /&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-java-package.html"&gt;package&lt;/a&gt; developer;&lt;br /&gt;&lt;br /&gt;import java.util.Scanner;&lt;br /&gt;&lt;br /&gt;public class ArmstrongNumber {&lt;br /&gt;&lt;br /&gt; static double finalValue = 0;&lt;br /&gt;&lt;br /&gt; &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-reason-for-each-keyword-of.html"&gt;public static void main(String[] args)&lt;/a&gt; {&lt;br /&gt;  &lt;br /&gt;  int valueTaker = 0; &lt;br /&gt;  &lt;br /&gt;  System.out.println("Enter a number to be checked for Armstrong Number: ");&lt;br /&gt;  &lt;br /&gt;  Scanner armstScan = new Scanner(System.in);&lt;br /&gt;  &lt;br /&gt;  if(armstScan.hasNextInt())&lt;br /&gt;  {&lt;br /&gt;   valueTaker = armstScan.nextInt();&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  StringBuffer sb = new StringBuffer().append(valueTaker);&lt;br /&gt;  &lt;br /&gt;  double lengthSBKeeper = sb.length();&lt;br /&gt;  &lt;br /&gt;  for(int lengthKeeper = 0; lengthKeeper &lt; sb.length(); lengthKeeper++)&lt;br /&gt;  {  &lt;br /&gt;   double zxc = Integer.parseInt(sb.substring(lengthKeeper, lengthKeeper+1));&lt;br /&gt;   &lt;br /&gt;   finalValue = Math.pow(zxc, lengthSBKeeper) + finalValue;  &lt;br /&gt;   &lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  if(finalValue == valueTaker)&lt;br /&gt;  {&lt;br /&gt;   System.out.println("The entered number "+valueTaker+" is an Armstrong Number");&lt;br /&gt;  }&lt;br /&gt;  else&lt;br /&gt;  {&lt;br /&gt;   System.out.println("The entered number is not an Armstrong Number");&lt;br /&gt;  }  &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;///////////////////////////////////////&lt;br /&gt;&lt;br /&gt;I hope the code above was helpful to all of you. Just copy the code in your IDE, and change the package name accordingly, and you are set to roll. Keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; for more Java information.&lt;br /&gt;&lt;br /&gt;Other Java Programs that might be of some interest:-&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/07/factorial-program-in-java-java-program.html"&gt;Factorial Program in Java&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/08/palindrome-java-program.html"&gt;Palindrome Program in Java&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/07/java-code-for-prime-number-prime-number.html"&gt;Prime Number Program in Java&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/07/java-program-for-fibonacci-series.html"&gt;Fibonacci Series Program in Java&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-3339098103931678621?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/armstrong-number-java-program.html' title='Armstrong Number Java Program'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/3339098103931678621/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/armstrong-number-java-program.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3339098103931678621'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3339098103931678621'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/armstrong-number-java-program.html' title='Armstrong Number Java Program'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-32517535548467765</id><published>2009-08-19T00:27:00.004+05:30</published><updated>2009-08-19T00:44:47.705+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><category scheme='http://www.blogger.com/atom/ns#' term='Collections'/><category scheme='http://www.blogger.com/atom/ns#' term='ArrayList'/><title type='text'>Difference ArrayList and Array in Java</title><content type='html'>Welcome back again on &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Today I would be discussing the main difference between an ArrayList and an Array in Java.&lt;br /&gt;&lt;br /&gt;In Java an Array is always of fixed size. The size has to be defined at the initializing time of the array. The number of the rows is a must for any array, though the number of columns may be specified later. By using Array, there is comparatively less flexibility, as the size need to be known before hand. And if you initialize an array that is too long, then it results in wastage of precious memory of the heap. The &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-purpose-of-garbage-collection.html"&gt;Garbage Collector&lt;/a&gt; then has a tough time maintaining the memory for other resources.&lt;br /&gt;&lt;br /&gt;On the other hand, the ArrayList is dynamic in nature. It provides for automatic resizing of the List. Moreover you need not specify the size at the beginning of the initialization part. The ArrayList is therefore much more widely used as compared to an Array in Java. ArrayList is and extension of the List Interface. So it is a part of the Collections framework.&lt;br /&gt;&lt;br /&gt;Talking about the drawbacks of ArrayList, then there is probably only one, and that is typecasting. When an Object is added to an ArrayList it goes inside as an Object, and so when it is retrieved back, then it needs to be typecast back into the original &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The Arrays have a positive point in this regard, that is an array is always of a particular type that is an array of ints, or an array of Strings, etc. So when data is retrieved back from an Array, then no typecasting is required.&lt;br /&gt;&lt;br /&gt;More or less the advantages of an ArrayList makes it one of the most versatile and important tool in the Java coding, and arrays are left far behind in the race of fame.&lt;br /&gt;&lt;br /&gt;Keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; for more info on Java.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-32517535548467765?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/difference-arraylist-and-array-in-java.html' title='Difference ArrayList and Array in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/32517535548467765/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/difference-arraylist-and-array-in-java.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/32517535548467765'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/32517535548467765'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/difference-arraylist-and-array-in-java.html' title='Difference ArrayList and Array in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3416407328338427543.post-9519058045556159</id><published>2009-08-19T00:00:00.004+05:30</published><updated>2009-08-19T00:09:49.497+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><category scheme='http://www.blogger.com/atom/ns#' term='Scanner'/><category scheme='http://www.blogger.com/atom/ns#' term='Addition'/><title type='text'>Addition of two numbers Java Program</title><content type='html'>Hello all of you. Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Today I will be giving you a very simple and basic program of Java, that is the addition of two numbers. The code makes use of Scanner for getting the input from the console.&lt;br /&gt;&lt;br /&gt;The code starts by asking the user to enter two numbers to be added. The user enters the first number, press enter, and then enters the second number and then press enter again. After this the code computes the addition of these two numbers.&lt;br /&gt;&lt;br /&gt;The Java Code is provided below:-&lt;br /&gt;&lt;br /&gt;//////////////////////////////////////&lt;br /&gt;&lt;br /&gt;package developer;&lt;br /&gt;&lt;br /&gt;import java.util.Scanner;&lt;br /&gt;&lt;br /&gt;public class AddTwoNumber {&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * @param args&lt;br /&gt;  */&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  System.out.println("Enter the first and second numbers");&lt;br /&gt;  //Get the first number&lt;br /&gt;  Scanner scanOne = new Scanner(System.in);&lt;br /&gt;  //Get the second number&lt;br /&gt;  Scanner scanTwo = new Scanner(System.in);&lt;br /&gt;  &lt;br /&gt;  if(scanOne.hasNextInt() &amp;&amp; scanTwo.hasNextInt())&lt;br /&gt;  {&lt;br /&gt;   System.out.print("The sum of the two numbers entered is: ");&lt;br /&gt;   System.out.println(scanOne.nextInt()+scanTwo.nextInt());&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;I hope that this basic code was beneficial for the beginners to Java Programming. For more information and programs on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Related Programs&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/01/hello-world-program-in-java.html"&gt; Hello World Program in Java&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/07/length-of-string-java-program.html"&gt;Length of a String Java Program&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/08/palindrome-java-program.html"&gt;Palindrome Program in Java&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-9519058045556159?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/addition-of-two-numbers-java-program.html' title='Addition of two numbers Java Program'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/9519058045556159/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/addition-of-two-numbers-java-program.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/9519058045556159'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/9519058045556159'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/addition-of-two-numbers-java-program.html' title='Addition of two numbers Java Program'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-958923876022862340</id><published>2009-08-18T20:39:00.003+05:30</published><updated>2009-08-18T20:51:58.169+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><category scheme='http://www.blogger.com/atom/ns#' term='Factors'/><title type='text'>Factors of a number Java Program</title><content type='html'>Hi all of you. The following article at &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; is going to discuss the code for finding the factors of a number entered by the user. The Java Program starts by prompting the user to enter a number, and then displays the all the factors of the number entered by the user.&lt;br /&gt;&lt;br /&gt;The factors of a number are the numbers which divide the number entered by the user completely.&lt;br /&gt;&lt;br /&gt;The Java Example Code is given below:-&lt;br /&gt;&lt;br /&gt;/////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-java-package.html"&gt;package&lt;/a&gt; developer;&lt;br /&gt;&lt;br /&gt;import java.util.Scanner;&lt;br /&gt;&lt;br /&gt;public &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;class&lt;/a&gt; Factor {&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * @param args&lt;br /&gt;  */&lt;br /&gt; &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-reason-for-each-keyword-of.html"&gt;public static void main(String[] args)&lt;/a&gt; {&lt;br /&gt;  System.out.println("Enter a number whose factors are desired: ");&lt;br /&gt;  Scanner scanNum = new Scanner(System.in);&lt;br /&gt;  int numFac = 0;&lt;br /&gt;  if(scanNum.hasNextInt())&lt;br /&gt;  {&lt;br /&gt;   numFac = scanNum.nextInt();&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  System.out.println("The Factors of the entered number are:-");&lt;br /&gt;  &lt;br /&gt;  for(int i = 1; i &lt;= numFac; i++)&lt;br /&gt;  {&lt;br /&gt;   if(numFac%i == 0)&lt;br /&gt;   {&lt;br /&gt;    System.out.print(i+" ");&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;The Java Code above finds all the factors of the number entered by the user. For more interesting information on Java, keep checking &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Related links:-&lt;br /&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/08/prime-factors-java-program.html"&gt;Prime Factors Java Program&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/07/factorial-program-in-java-java-program.html"&gt;Factorial of a Number Java Program&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-958923876022862340?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/factors-of-number-java-program.html' title='Factors of a number Java Program'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/958923876022862340/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/factors-of-number-java-program.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/958923876022862340'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/958923876022862340'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/factors-of-number-java-program.html' title='Factors of a number Java Program'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-5116871327077299261</id><published>2009-08-18T20:27:00.003+05:30</published><updated>2009-08-18T20:38:21.585+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Prime Number'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><category scheme='http://www.blogger.com/atom/ns#' term='Factors'/><title type='text'>Prime Factors Java Program</title><content type='html'>Hello all of you. Today at &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;, I would be discussing the Java Code for finding all the prime factors of an entered number.&lt;br /&gt;&lt;br /&gt;Prime Factors are those numbers which are factors of the entered number, and also are Prime in nature. For being a factor, the number needs to divide completely the entered number. For example, f I say that the user entered 20, then the factors of this number are 1 2 4 5 10 and 20, but when we say about Prime Factors then out of these only 2 and 5 are prime, so 2 and 5 are the Prime factors of the number 20 which is entered by the user.&lt;br /&gt;&lt;br /&gt;The complete Java code is given below:-&lt;br /&gt;&lt;br /&gt;////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;package developer;&lt;br /&gt;&lt;br /&gt;import java.util.Scanner;&lt;br /&gt;&lt;br /&gt;public class PrimeFactor {&lt;br /&gt;&lt;br /&gt; static int primeCheck = 1;&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  System.out.println("Enter a number whose Prime factors are desired: ");&lt;br /&gt;  Scanner numS = new Scanner(System.in);&lt;br /&gt;  int numPriFac = 0;&lt;br /&gt;  if(numS.hasNextInt())&lt;br /&gt;  {&lt;br /&gt;   numPriFac = numS.nextInt();&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  System.out.println("All the Prime Factors of the entered number are:-");&lt;br /&gt;  &lt;br /&gt;  for(int tap = 1; tap &lt;= numPriFac; tap++)&lt;br /&gt;  {&lt;br /&gt;   if(numPriFac%tap == 0)&lt;br /&gt;   {&lt;br /&gt;    for(int primeTest = 2; primeTest &lt; tap; primeTest++)&lt;br /&gt;    {&lt;br /&gt;     if(tap%primeTest == 0)&lt;br /&gt;     {&lt;br /&gt;      primeCheck = 1;&lt;br /&gt;      break;&lt;br /&gt;     }&lt;br /&gt;     else&lt;br /&gt;     {&lt;br /&gt;      primeCheck = 0;&lt;br /&gt;     }&lt;br /&gt;    }&lt;br /&gt;    if(primeCheck == 0 || tap == 2)&lt;br /&gt;    {&lt;br /&gt;     System.out.print(tap+ "  ");&lt;br /&gt;    }    &lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;///////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;I hope the code was helpful to all of you. &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; keeps on discussing various Java codes, so keep checking for new updates.&lt;br /&gt;&lt;br /&gt;Related Links:-&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/07/java-code-for-prime-number-prime-number.html"&gt;Prime Number program in Java&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/08/largest-prime-number-java-program.html"&gt;Largest Prime number Java Program&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/08/smallest-prime-number-java-program.html"&gt;Smallest Prime Number Java Program&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/08/prime-number-series-java-program.html"&gt;Prime Number Series Java Program&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-5116871327077299261?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/prime-factors-java-program.html' title='Prime Factors Java Program'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/5116871327077299261/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/prime-factors-java-program.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/5116871327077299261'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/5116871327077299261'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/prime-factors-java-program.html' title='Prime Factors Java Program'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-3808548692806941117</id><published>2009-08-17T21:05:00.004+05:30</published><updated>2009-08-17T21:18:08.490+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Recursion'/><category scheme='http://www.blogger.com/atom/ns#' term='Prime Number'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><title type='text'>Prime Number Series Java Program</title><content type='html'>Hi friends, welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Today I will be discussing the Java Code to generate a series of Prime Numbers. The series of Prime Numbers all the Prime numbers which are less then the number provided by the user.&lt;br /&gt;&lt;br /&gt;The Java Code starts by asking the user to enter a number, and then displays all the Prime Numbers which are less then or equal to that number. This program generates all the prime numbers less then a number, so it is a series of Prime Numbers.&lt;br /&gt;&lt;br /&gt;The Java Code is provided below:-&lt;br /&gt;&lt;br /&gt;///////////////////////////////////////&lt;br /&gt;&lt;br /&gt;package developer;&lt;br /&gt;&lt;br /&gt;import java.util.Scanner;&lt;br /&gt;&lt;br /&gt;public class PrimeNumberSeries {&lt;br /&gt;&lt;br /&gt; public static void main(String[] args)&lt;br /&gt;   {    &lt;br /&gt;     int numero = 0;&lt;br /&gt;     System.out.println("Enter a number:");&lt;br /&gt;     Scanner takeValue = new Scanner(System.in);     &lt;br /&gt;     if(takeValue.hasNextInt())&lt;br /&gt;     {&lt;br /&gt;      numero = takeValue.nextInt();&lt;br /&gt;     }    &lt;br /&gt;     System.out.println("All the Prime Numbers, which are less then or equal to the number entered are:");&lt;br /&gt;         checkPrimeNumber(numero);&lt;br /&gt;   }&lt;br /&gt; &lt;br /&gt; static void checkPrimeNumber(int val)&lt;br /&gt; {&lt;br /&gt;  int tapper = 0;  &lt;br /&gt;  &lt;br /&gt;     for (int i=2; i &lt; val; i++ ){&lt;br /&gt;      if(val%i == 0)&lt;br /&gt;      {       &lt;br /&gt;       tapper = 0;&lt;br /&gt;       break;&lt;br /&gt;      } &lt;br /&gt;      else&lt;br /&gt;      {&lt;br /&gt;       tapper = 1;&lt;br /&gt;      }&lt;br /&gt;     }&lt;br /&gt;     if(tapper == 1 || val == 2)&lt;br /&gt;     {&lt;br /&gt;      System.out.print(val+" ");&lt;br /&gt;      if(val &gt; 2)&lt;br /&gt;       checkPrimeNumber(val-1);       &lt;br /&gt;     }&lt;br /&gt;     else&lt;br /&gt;     {&lt;br /&gt;      if(val &gt; 2)&lt;br /&gt;      checkPrimeNumber(val-1);&lt;br /&gt;      else&lt;br /&gt;       System.out.println("Number out of range");      &lt;br /&gt;     }   &lt;br /&gt; }&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;///////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;I hope the Java Code was helpful to you all. Keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;, for more info on Java.&lt;br /&gt;&lt;br /&gt;Related Java Programs&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/07/java-code-for-prime-number-prime-number.html"&gt;Prime Number program in Java&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/08/largest-prime-number-java-program.html"&gt;Largest Prime number Java Program&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/08/smallest-prime-number-java-program.html"&gt;Smallest Prime Number Java Program&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-3808548692806941117?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/prime-number-series-java-program.html' title='Prime Number Series Java Program'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/3808548692806941117/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/prime-number-series-java-program.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3808548692806941117'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3808548692806941117'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/prime-number-series-java-program.html' title='Prime Number Series Java Program'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-6211503174420955287</id><published>2009-08-17T20:49:00.006+05:30</published><updated>2009-08-17T21:03:53.497+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SCJP'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Certifications'/><title type='text'>Sun Certified Java Programer (SCJP) Syllabus</title><content type='html'>Hi friends, today at &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code online&lt;/a&gt;, I would be giving you the syllabus for SCJP 6.0, SCJP stands for Sun Certified Java Programmer. The exam is a very prestigious exam, and clearing the exam implies acknowledgment in the elite class of SCJP certified professionals.&lt;br /&gt;&lt;br /&gt;The SCJP 6.0 Exam Objectives are given below:-&lt;br /&gt;&lt;br /&gt;Section 1: Declarations, Initialization and Scoping&lt;br /&gt;&lt;br /&gt;    * Develop code that declares classes (including abstract and all forms of nested classes), interfaces, and enums, and includes the appropriate use of package and import statements (including static imports).&lt;br /&gt;    * Develop code that declares an interface. Develop code that implements or extends one or more interfaces. Develop code that declares an abstract class. Develop code that extends an abstract class.&lt;br /&gt;    * Develop code that declares, initializes, and uses primitives, arrays, enums, and objects as static, instance, and local variables. Also, use legal identifiers for variable names.&lt;br /&gt;    * Given a code example, determine if a method is correctly overriding or overloading another method, and identify legal return values (including covariant returns), for the method.&lt;br /&gt;    * Given a set of classes and superclasses, develop constructors for one or more of the classes. Given a class declaration, determine if a default constructor will be created, and if so, determine the behavior of that constructor. Given a nested or non-nested class listing, write code to instantiate the class.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Section 2: Flow Control&lt;br /&gt;&lt;br /&gt;    * Develop code that implements an if or switch statement; and identify legal argument types for these statements.&lt;br /&gt;    * Develop code that implements all forms of loops and iterators, including the use of for, the enhanced for loop (for-each), do, while, labels, break, and continue; and explain the values taken by loop counter variables during and after loop execution.&lt;br /&gt;    * Develop code that makes use of assertions, and distinguish appropriate from inappropriate uses of assertions.&lt;br /&gt;    * Develop code that makes use of exceptions and exception handling clauses (try, catch, finally), and declares methods and overriding methods that throw exceptions.&lt;br /&gt;    * Recognize the effect of an exception arising at a specified point in a code fragment. Note that the exception may be a runtime exception, a checked exception, or an error.&lt;br /&gt;    * Recognize situations that will result in any of the following being thrown: ArrayIndexOutOfBoundsException,ClassCastException, IllegalArgumentException, IllegalStateException, NullPointerException, NumberFormatException, AssertionError, ExceptionInInitializerError, StackOverflowError or NoClassDefFoundError. Understand which of these are thrown by the virtual machine and recognize situations in which others should be thrown programatically.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Section 3: API Contents&lt;br /&gt;&lt;br /&gt;    * Develop code that uses the primitive wrapper classes (such as Boolean, Character, Double, Integer, etc.), and/or autoboxing &amp; unboxing. Discuss the differences between the String, StringBuilder, and StringBuffer classes.&lt;br /&gt;    * Given a scenario involving navigating file systems, reading from files, writing to files, or interacting with the user, develop the correct solution using the following classes (sometimes in combination), from java.io: BufferedReader, BufferedWriter, File, FileReader, FileWriter, PrintWriter, and Console.&lt;br /&gt;    * Use standard J2SE APIs in the java.text package to correctly format or parse dates, numbers, and currency values for a specific locale; and, given a scenario, determine the appropriate methods to use if you want to use the default locale or a specific locale. Describe the purpose and use of the java.util.Locale class.&lt;br /&gt;    * Write code that uses standard J2SE APIs in the java.util and java.util.regex packages to format or parse strings or streams. For strings, write code that uses the Pattern and Matcher classes and the String.split method. Recognize and use regular expression patterns for matching (limited to: . (dot), * (star), + (plus), ?, \d, \s, \w, [], ()). The use of *, +, and ? will be limited to greedy quantifiers, and the parenthesis operator will only be used as a grouping mechanism, not for capturing content during matching. For streams, write code using the Formatter and Scanner classes and the PrintWriter.format/printf methods. Recognize and use formatting parameters (limited to: %b, %c, %d, %f, %s) in format strings.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Section 4: Concurrency&lt;br /&gt;&lt;br /&gt;    * Write code to define, instantiate, and start new threads using both java.lang.Thread and java.lang.Runnable.&lt;br /&gt;    * Recognize the states in which a thread can exist, and identify ways in which a thread can transition from one state to another.&lt;br /&gt;    * Given a scenario, write code that makes appropriate use of object locking to protect static or instance variables from concurrent access problems.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Section 5: OO Concepts&lt;br /&gt;&lt;br /&gt;    * Develop code that implements tight encapsulation, loose coupling, and high cohesion in classes, and describe the benefits.&lt;br /&gt;    * Given a scenario, develop code that demonstrates the use of polymorphism. Further, determine when casting will be necessary and recognize compiler vs. runtime errors related to object reference casting.&lt;br /&gt;    * Explain the effect of modifiers on inheritance with respect to constructors, instance or static variables, and instance or static methods.&lt;br /&gt;    * Given a scenario, develop code that declares and/or invokes overridden or overloaded methods and code that declares and/or invokes superclass, or overloaded constructors.&lt;br /&gt;    * Develop code that implements "is-a" and/or "has-a" relationships.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Section 6: Collections / Generics&lt;br /&gt;&lt;br /&gt;    * Given a design scenario, determine which collection classes and/or interfaces should be used to properly implement that design, including the use of the Comparable interface.&lt;br /&gt;    * Distinguish between correct and incorrect overrides of corresponding hashCode and equals methods, and explain the difference between == and the equals method.&lt;br /&gt;    * Write code that uses the generic versions of the Collections API, in particular, the Set, List, and Map interfaces and implementation classes. Recognize the limitations of the non-generic Collections API and how to refactor code to use the generic versions. Write code that uses the NavigableSet and NavigableMap interfaces.&lt;br /&gt;    * Develop code that makes proper use of type parameters in class/interface declarations, instance variables, method arguments, and return types; and write generic methods or methods that make use of wildcard types and understand the similarities and differences between these two approaches.&lt;br /&gt;    * Use capabilities in the java.util package to write code to manipulate a list by sorting, performing a binary search, or converting the list to an array. Use capabilities in the java.util package to write code to manipulate an array by sorting, performing a binary search, or converting the array to a list. Use the java.util.Comparator and java.lang.Comparable interfaces to affect the sorting of lists and arrays. Furthermore, recognize the effect of the "natural ordering" of primitive wrapper classes and java.lang.String on sorting.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Section 7: Fundamentals&lt;br /&gt;&lt;br /&gt;    * Given a code example and a scenario, write code that uses the appropriate access modifiers, package declarations, and import statements to interact with (through access or inheritance) the code in the example.&lt;br /&gt;    * Given an example of a class and a command-line, determine the expected runtime behavior.&lt;br /&gt;    * Determine the effect upon object references and primitive values when they are passed into methods that perform assignments or other modifying operations on the parameters.&lt;br /&gt;    * Given a code example, recognize the point at which an object becomes eligible for garbage collection, determine what is and is not guaranteed by the garbage collection system, and recognize the behaviors of the Object.finalize() method.&lt;br /&gt;    * Given the fully-qualified name of a class that is deployed inside and/or outside a JAR file, construct the appropriate directory structure for that class. Given a code example and a classpath, determine whether the classpath will allow the code to compile successfully.&lt;br /&gt;    * Write code that correctly applies the appropriate operators including assignment operators (limited to: =, +=, -=), arithmetic operators (limited to: +, -, *, /, %, ++, --), relational operators (limited to: &lt;, &lt;=, &gt;, &gt;=, ==, !=), the instanceof operator, logical operators (limited to: &amp;, |, ^, !, &amp;&amp;, ||), and the conditional operator ( ? : ), to produce a desired result. Write code that determines the equality of two objects or two primitives.&lt;br /&gt;&lt;br /&gt;This syllabus and exam Objective can be viewed at &lt;a href = "http://in.sun.com/training/catalog/courses/CX-310-065.xml"&gt;Sun Official site&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Preparing for the SCJP exam provides an oppurtunity to strength your Java Concepts. It makes your programming skills established in front of the world, and also is helpful in building confidence for the Java Interviews.&lt;br /&gt;&lt;br /&gt;I hope the syllabus provided was helpful to you all. For more info on Java keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Related article&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/07/sun-certified-java-programmer-scjp.html"&gt;Sun Certified Java Programmer SCJP&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-6211503174420955287?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/sun-certified-java-programer-scjp.html' title='Sun Certified Java Programer (SCJP) Syllabus'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/6211503174420955287/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/sun-certified-java-programer-scjp.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/6211503174420955287'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/6211503174420955287'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/sun-certified-java-programer-scjp.html' title='Sun Certified Java Programer (SCJP) Syllabus'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-1836750440451451680</id><published>2009-08-16T22:39:00.004+05:30</published><updated>2009-08-16T22:49:14.792+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Recursion'/><category scheme='http://www.blogger.com/atom/ns#' term='Prime Number'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><title type='text'>Smallest Prime Number Java Program</title><content type='html'>Hi friends, today &lt;a href = "http://javacodeonline.blogspot.com"&gt;Java Code Online&lt;/a&gt; will be discussing the Java code for finding the smallest Prime number, which is greater then the number provided by the user.&lt;br /&gt;&lt;br /&gt;The Java code starts by asking the user to enter a number, and then it generates the smallest Prime number which is greater then the user provided number.&lt;br /&gt;&lt;br /&gt;The Java Code is given below:-&lt;br /&gt;&lt;br /&gt;////////////////////////////////////&lt;br /&gt;&lt;br /&gt;package developer;&lt;br /&gt;&lt;br /&gt;import java.util.Scanner;&lt;br /&gt;&lt;br /&gt;public class SmallestPrime {&lt;br /&gt;&lt;br /&gt; public static void main(String[] args)&lt;br /&gt;   {    &lt;br /&gt;     int num = 0;&lt;br /&gt;     System.out.println("Enter a number:");&lt;br /&gt;//get the input from the console&lt;br /&gt;     Scanner scan = new Scanner(System.in);     &lt;br /&gt;     if(scan.hasNextInt())&lt;br /&gt;     {&lt;br /&gt;      num = scan.nextInt();&lt;br /&gt;     }    &lt;br /&gt;         checkPrime(num);&lt;br /&gt;   }&lt;br /&gt; &lt;br /&gt; static void checkPrime(int num)&lt;br /&gt; {&lt;br /&gt;  int check = 0;  &lt;br /&gt;  &lt;br /&gt;     for (int i=2; i &lt; num; i++ ){&lt;br /&gt;      if(num%i == 0)&lt;br /&gt;      {       &lt;br /&gt;       check = 0;&lt;br /&gt;       break;&lt;br /&gt;      } &lt;br /&gt;      else&lt;br /&gt;      {&lt;br /&gt;       check = 1;&lt;br /&gt;      }&lt;br /&gt;     }&lt;br /&gt;     if(check == 1 || num == 2)&lt;br /&gt;     {&lt;br /&gt;      System.out.println("The smallest prime number which is greater then or equal to the number provided is: "+num);&lt;br /&gt;     }&lt;br /&gt;     else&lt;br /&gt;     {&lt;br /&gt;      if(num &gt; 0)&lt;br /&gt;      checkPrime(num+1);//Recursion in use&lt;br /&gt;      else&lt;br /&gt;       System.out.println("Number out of range");      &lt;br /&gt;     }   &lt;br /&gt; }&lt;br /&gt;} &lt;br /&gt;////////////////////////////////&lt;br /&gt;&lt;br /&gt;Hope that the provided Java code was beneficial to you all. Keep checking &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; for more info on Java.&lt;br /&gt;&lt;br /&gt;Related Programs&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/07/java-code-for-prime-number-prime-number.html"&gt;Prime Number program in Java&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/08/largest-prime-number-java-program.html"&gt;Largest Prime number Java Program&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-1836750440451451680?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/smallest-prime-number-java-program.html' title='Smallest Prime Number Java Program'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/1836750440451451680/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/smallest-prime-number-java-program.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1836750440451451680'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1836750440451451680'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/smallest-prime-number-java-program.html' title='Smallest Prime Number Java Program'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-1423211679846448609</id><published>2009-08-16T22:28:00.006+05:30</published><updated>2009-08-16T22:46:48.378+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Recursion'/><category scheme='http://www.blogger.com/atom/ns#' term='Prime Number'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><title type='text'>Largest Prime Number Java Program</title><content type='html'>Hi friends, welcome back to &lt;a href = "http://www.javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Today I will be discussing the Java Code, to find the largest prime number, which is smaller then the number provided by the user.&lt;br /&gt;&lt;br /&gt;A prime number is a positive integer which is divisible by 1 and itself only. The Java Code for finding the largest Prime number which is lower then the number provided by the user is given below:-&lt;br /&gt;&lt;br /&gt;///////////////////////////////////&lt;br /&gt;package developer;&lt;br /&gt;&lt;br /&gt;import java.util.Scanner;&lt;br /&gt;&lt;br /&gt;public class LargestPrime {&lt;br /&gt;&lt;br /&gt; public static void main(String[] args)&lt;br /&gt;   {    &lt;br /&gt;     int num = 0;&lt;br /&gt;     System.out.println("Enter a number:");&lt;br /&gt;     Scanner scan = new Scanner(System.in);     &lt;br /&gt;     if(scan.hasNextInt())&lt;br /&gt;     {&lt;br /&gt;      num = scan.nextInt();&lt;br /&gt;     }    &lt;br /&gt;         checkPrime(num);&lt;br /&gt;   }&lt;br /&gt; &lt;br /&gt; static void checkPrime(int num)&lt;br /&gt; {&lt;br /&gt;  int check = 0;  &lt;br /&gt;  &lt;br /&gt;     for (int i=2; i &lt; num; i++ ){&lt;br /&gt;      if(num%i == 0)&lt;br /&gt;      {       &lt;br /&gt;       check = 0;&lt;br /&gt;       break;&lt;br /&gt;      } &lt;br /&gt;      else&lt;br /&gt;      {&lt;br /&gt;       check = 1;&lt;br /&gt;      }&lt;br /&gt;     }&lt;br /&gt;     if(check == 1 || num == 2)&lt;br /&gt;     {&lt;br /&gt;      System.out.println("The largest prime number which is less then or equal to the number provided is: "+num);&lt;br /&gt;     }&lt;br /&gt;     else&lt;br /&gt;     {&lt;br /&gt;      if(num &gt; 2)&lt;br /&gt;      checkPrime(num-1);&lt;br /&gt;      else&lt;br /&gt;       System.out.println("Number out of range");      &lt;br /&gt;     }   &lt;br /&gt; }&lt;br /&gt;} &lt;br /&gt;//////////////////////////////&lt;br /&gt;&lt;br /&gt;I hope the above Java code was helpful to you all. For more info on Java keep buzzing &lt;a href = "http://www.javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Related Java Programs&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/07/java-code-for-prime-number-prime-number.html"&gt;Prime Number program in Java&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-1423211679846448609?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/largest-prime-number-java-program.html' title='Largest Prime Number Java Program'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/1423211679846448609/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/largest-prime-number-java-program.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1423211679846448609'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1423211679846448609'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/largest-prime-number-java-program.html' title='Largest Prime Number Java Program'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-4960622703375981942</id><published>2009-08-16T02:34:00.005+05:30</published><updated>2009-08-16T02:46:33.964+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='Triangular Number'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><category scheme='http://www.blogger.com/atom/ns#' term='Floyd Triangle'/><title type='text'>Floyd Triangle Program in Java</title><content type='html'>Welcome back again, today at &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;, I would be discussing the Java code for &lt;b&gt;Floyd's Triangle&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;The Floyd's triangle starts from 1, it is a right angled triangle, consisting of consecutive numbers. If suppose four rows of the Floyd's Triangle need to be generated, then the output will be, the first row contains 1, the second row contains 2 3, the third row contains 4 5 6, and the last row contains 7 8 9 10. I hope that will clear your concept about the Floyd's Triangle. One more intresting fact about this triangle is that all the last numbers of each row are &lt;a href = "http://javacodeonline.blogspot.com/2009/08/triangular-number-program-in-java.html"&gt;Triangular numbers&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The Java Code provided, asks the user to enter the number of rows till which the Floyd's Triangle is desired, and then generates it. The Java Program is given below:-&lt;br /&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-java-package.html"&gt;package&lt;/a&gt; developer;&lt;br /&gt;&lt;br /&gt;import java.io.BufferedReader;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.io.InputStreamReader;&lt;br /&gt;&lt;br /&gt;public class FloydTriangle {&lt;br /&gt;&lt;br /&gt; static int counter = 0;&lt;br /&gt; /**&lt;br /&gt;  * @param args&lt;br /&gt;  * @throws IOException &lt;br /&gt;  * @throws NumberFormatException &lt;br /&gt;  */&lt;br /&gt; &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-reason-for-each-keyword-of.html"&gt;public static void main(String[] args)&lt;/a&gt; throws NumberFormatException, IOException {&lt;br /&gt;  System.out.println("Enter the number of rows for Floyd Triangle:");&lt;br /&gt;  InputStreamReader ir = new InputStreamReader(System.in);&lt;br /&gt;     BufferedReader br = new BufferedReader(ir);&lt;br /&gt;     &lt;br /&gt;      &lt;br /&gt;     int  num = Integer.parseInt(br.readLine());&lt;br /&gt;     &lt;br /&gt;     for(int i = 1; i &lt;= num; i++)&lt;br /&gt;     {&lt;br /&gt;      for(int j = 1; j &lt;= i; j++)&lt;br /&gt;      {&lt;br /&gt;       counter = counter + 1;&lt;br /&gt;       System.out.print(counter);&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;br /&gt;}&lt;br /&gt;&lt;br /&gt;I hope that this post was helpful to you all. Kindly leave your comments in case you liked the above code. For more info on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-4960622703375981942?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/floyd-triangle-program-in-java.html' title='Floyd Triangle Program in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/4960622703375981942/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/floyd-triangle-program-in-java.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/4960622703375981942'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/4960622703375981942'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/floyd-triangle-program-in-java.html' title='Floyd Triangle Program in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3416407328338427543.post-1254066177529284502</id><published>2009-08-16T02:23:00.005+05:30</published><updated>2009-08-16T02:34:24.109+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='Triangular Number'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><category scheme='http://www.blogger.com/atom/ns#' term='Floyd Triangle'/><title type='text'>Triangular Number Program in Java</title><content type='html'>Hi friends, today &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; is going to discuss the Java Code for generating the &lt;b&gt;Triangular Numbers&lt;/b&gt; up to the entered number of times.&lt;br /&gt;&lt;br /&gt;A Triangular Number is one which is the sum of all the numbers starting from 1 up to that particular number. For example if I say the number is 3, then 1+2+3=6, so 6 is the third Triangular Number.&lt;br /&gt;&lt;br /&gt;The provided Java code asks the user, to enter the required number of Triangular Numbers, and then generate that many Triangular Numbers starting from 1.&lt;br /&gt;&lt;br /&gt;The Java Code is provided below:-&lt;br /&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-java-package.html"&gt;package&lt;/a&gt; developer;&lt;br /&gt;&lt;br /&gt;import java.io.BufferedReader;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.io.InputStreamReader;&lt;br /&gt;&lt;br /&gt;public class TriangularNumber {&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * @param args&lt;br /&gt;  * @throws IOException &lt;br /&gt;  * @throws NumberFormatException &lt;br /&gt;  */&lt;br /&gt; &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-reason-for-each-keyword-of.html"&gt;public static void main(String[] args)&lt;/a&gt; throws NumberFormatException, IOException {&lt;br /&gt;  System.out.println("How many Triangular Numbers are required:");&lt;br /&gt;  InputStreamReader ir = new InputStreamReader(System.in);&lt;br /&gt;     BufferedReader br = new BufferedReader(ir);&lt;br /&gt;     int j = 1;    &lt;br /&gt;     int  num = Integer.parseInt(br.readLine());&lt;br /&gt;     &lt;br /&gt;     for(int i = 1; i&lt;= num; i++)&lt;br /&gt;     {&lt;br /&gt;      j = i * (i+1)/2;&lt;br /&gt;      System.out.print(j + " ");&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;I hope the above Java Code was helpful to you all. Keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; for more interesting Java information and programs.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-1254066177529284502?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/triangular-number-program-in-java.html' title='Triangular Number Program in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/1254066177529284502/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/triangular-number-program-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1254066177529284502'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1254066177529284502'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/triangular-number-program-in-java.html' title='Triangular Number Program in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-7000009696705784193</id><published>2009-08-16T00:55:00.008+05:30</published><updated>2010-12-11T15:50:08.835+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Pascal Triangle'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><title type='text'>Pascal Triangle in Java</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;Hi friends, today at &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;, I am going to discuss a very interesting yet basic Java program, that displays the Pascal Triangle for any given integer value.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;A Pascal Triangle is a triangle in which a triangle is formed of numbers, in which 1 is displayed one time, 2 is displayed two times, 3 is displayed three times, and so on, up to the entered value of the integer value. Each of these different numbers are displayed on different lines, but the same number is displayed on the same line. The whole structure is in the form of a triangle, and it is called Pascal Triangle. &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;The Java Code is provided below, the code asks the user to enter a number, and then prints the Pascal Triangle up to that many rows:-&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="background-color: #7f6000; font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="background-color: #7f6000; color: black; font-family: Verdana,sans-serif;"&gt;&amp;nbsp;package developer;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;import java.io.BufferedReader;&lt;br /&gt;&amp;nbsp;import java.io.IOException;&lt;br /&gt;&amp;nbsp;import java.io.InputStreamReader;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;public class Pascal {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String[] args) throws IOException {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("Enter the number of rows for which the Pascal Triangle is requird: ");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; InputStreamReader is = new InputStreamReader(System.in);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; BufferedReader bf = new BufferedReader(is);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; int numRow = Integer.parseInt(bf.readLine());&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 1; i &amp;lt;= numRow; i++) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // Prints the blank spaces&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; for (int j = 1; j &amp;lt;= numRow - i; j++) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.print(" ");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // Prints the value of the number&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; for (int k = 1; k &amp;lt;= i; k++) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.print(i + " ");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;}&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;I hope the above code was helpful to you all. For more information on Java, you know that &lt;a href="http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; is the place you need to be at.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Other Java Programs that might be of interest:-&lt;/div&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/08/palindrome-java-program.html" style="font-family: Verdana,sans-serif;"&gt;Palindrome Program in Java&lt;/a&gt;&lt;br style="font-family: Verdana,sans-serif;" /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/factorial-program-in-java-java-program.html" style="font-family: Verdana,sans-serif;"&gt;Factorial Program in Java&lt;/a&gt;&lt;br style="font-family: Verdana,sans-serif;" /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/java-program-for-fibonacci-series.html" style="font-family: Verdana,sans-serif;"&gt;Fibonacci Series Program in Java&lt;/a&gt;&lt;br style="font-family: Verdana,sans-serif;" /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/java-code-for-prime-number-prime-number.html" style="font-family: Verdana,sans-serif;"&gt;Prime Number Program in Java&lt;/a&gt;&lt;br style="font-family: Verdana,sans-serif;" /&gt;&lt;a href="http://javacodeonline.blogspot.com/2010/12/string-in-java.html" style="font-family: Verdana,sans-serif;"&gt;String In Java &lt;/a&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-4780283616457623";/* 336x280, created 12/10/10 */google_ad_slot = "1174064275";google_ad_width = 336;google_ad_height = 280;//--&gt;&lt;/script&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-7000009696705784193?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/pascal-triangle-in-java.html' title='Pascal Triangle in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/7000009696705784193/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/pascal-triangle-in-java.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/7000009696705784193'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/7000009696705784193'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/pascal-triangle-in-java.html' title='Pascal Triangle in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-4454684603807672936</id><published>2009-08-14T22:58:00.004+05:30</published><updated>2009-08-14T23:05:49.061+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='Palindrome'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><category scheme='http://www.blogger.com/atom/ns#' term='String'/><title type='text'>Palindrome Java Program</title><content type='html'>Hi friends, welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Today I will be discussing the Java Program to find out whether any entered String or number or any combination of them is a Palindrome or not.&lt;br /&gt;&lt;br /&gt;A Palindrome is a string or number, that is exactly the same when it is read in the reverse order. That is for example "anna" is a palindrome, i.e. read the same either way.&lt;br /&gt;&lt;br /&gt;The Java code for finding the Palindrome is given below:-&lt;br /&gt;&lt;br /&gt;//////////////////////////////&lt;br /&gt;import java.io.BufferedReader;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.io.InputStreamReader;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class Palindrome {&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * @param args&lt;br /&gt;  * @throws IOException &lt;br /&gt;  */&lt;br /&gt; public static void main(String[] args) throws IOException {&lt;br /&gt;  System.out.println("Enter a number or String to be checked for Palindrome");&lt;br /&gt;  InputStreamReader io = new InputStreamReader(System.in);&lt;br /&gt;  BufferedReader br = new BufferedReader(io);&lt;br /&gt;  String num = br.readLine();&lt;br /&gt;  StringBuffer num2 = new StringBuffer().append(num);   &lt;br /&gt;  if(num.equals(num2.reverse().toString()))&lt;br /&gt;  {&lt;br /&gt;   System.out.println("It is a Palindrome");&lt;br /&gt;  }&lt;br /&gt;  else&lt;br /&gt;  {&lt;br /&gt;   System.out.println("It is not Palindrome"); &lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;/////////////////////////////&lt;br /&gt;&lt;br /&gt;I hope the Java code provided for finding the Palindrome was helpful to you all. For more info on Java, keep checking &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-4454684603807672936?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/palindrome-java-program.html' title='Palindrome Java Program'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/4454684603807672936/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/palindrome-java-program.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/4454684603807672936'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/4454684603807672936'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/palindrome-java-program.html' title='Palindrome Java Program'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-5464623273535047258</id><published>2009-08-14T22:46:00.003+05:30</published><updated>2009-08-14T22:56:02.058+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><category scheme='http://www.blogger.com/atom/ns#' term='String'/><title type='text'>Number of words in a String - Java Program</title><content type='html'>Hi friends, welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Today I will discuss a simple Java Program to find the number of words in any String entered by the user. The Java application starts by asking the user to enter a String, and then finds the number of words in that String.&lt;br /&gt;&lt;br /&gt;The Java Code is displayed below for reference:-&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import java.io.BufferedReader;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.io.InputStreamReader;&lt;br /&gt;&lt;br /&gt;public class NoOfWordsInString {&lt;br /&gt; &lt;br /&gt; public static void main(String[] args) throws IOException {&lt;br /&gt;  System.out.println("Enter a string or number for which the number of words is to be counted: ");&lt;br /&gt;  InputStreamReader isr = new InputStreamReader(System.in);&lt;br /&gt;  BufferedReader br = new BufferedReader(isr);&lt;br /&gt;  String str = br.readLine();&lt;br /&gt;  System.out.println("The no of words in the string are: "+str.length());&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;I hope the Java code above was helpful to you all, for more info on Java keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Related Java Programs&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/07/reverse-string-java-program.html"&gt;Reverse Java String&lt;/a&gt;&lt;br /&gt;&lt;a href="http://javacodeonline.blogspot.com/2009/07/length-of-string-java-program.html"&gt;Length of a String&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-5464623273535047258?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/number-of-words-in-string-java-program.html' title='Number of words in a String - Java Program'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/5464623273535047258/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/number-of-words-in-string-java-program.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/5464623273535047258'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/5464623273535047258'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/number-of-words-in-string-java-program.html' title='Number of words in a String - Java Program'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-4267984587420183111</id><published>2009-08-09T14:49:00.003+05:30</published><updated>2009-08-09T14:58:54.753+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='TreeSet'/><category scheme='http://www.blogger.com/atom/ns#' term='Sorting'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><title type='text'>Desending Sort - Java Program</title><content type='html'>Hi friends, welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Today I will discuss the Java Program for sorting an array of numbers in descending order. It is similar to the previous Java program I discussed for &lt;a href = "http://javacodeonline.blogspot.com/2009/07/sorting-ascending-java-program.html"&gt;ascending sort&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The strong point of this Java code is that, we make use of TreeSet Collection for sorting the array in reverse order. The Java code is provided below:-&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import java.util.TreeSet;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class SortingDescending {&lt;br /&gt; &lt;br /&gt; @SuppressWarnings("unchecked")&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  int[] num = {3,5,9,2,1,0,45,23,67,93};&lt;br /&gt;  TreeSet ts = new TreeSet();&lt;br /&gt;  &lt;br /&gt;  for(int i = 0; i &lt; num.length; i++)&lt;br /&gt;  {&lt;br /&gt;   ts.add(num[i]);&lt;br /&gt;  }&lt;br /&gt;  System.out.println("The numbers of the array in descrending order are: "+ts.descendingSet());&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I hope the Java Code provided was helpful to you all. For more info on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-4267984587420183111?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/08/desending-sort-java-program.html' title='Desending Sort - Java Program'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/4267984587420183111/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/desending-sort-java-program.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/4267984587420183111'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/4267984587420183111'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/08/desending-sort-java-program.html' title='Desending Sort - Java Program'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-8763626403775055530</id><published>2009-07-28T20:48:00.004+05:30</published><updated>2009-07-28T20:53:38.439+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='TreeSet'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><category scheme='http://www.blogger.com/atom/ns#' term='Collections'/><title type='text'>Sorting Ascending - Java Program</title><content type='html'>Hi friends, welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. This tutorial discusses the Java Code to sort the numbers in an &lt;b&gt;Array&lt;/b&gt; in ascending order. This Java Code is helpful in getting a better idea of the Java fundamentals, and also provide the advantage of one of the most commonly used Java Collection named TreeSet.&lt;br /&gt;&lt;br /&gt;The Java Code is given below:-&lt;br /&gt;&lt;br /&gt;import java.util.TreeSet;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class SortingAscending {&lt;br /&gt; &lt;br /&gt; @SuppressWarnings("unchecked")&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  int[] num = {3,5,9,2,1,0,45,23,67,93};&lt;br /&gt;  TreeSet ts = new TreeSet();&lt;br /&gt;  &lt;br /&gt;  for(int i = 0; i &lt; num.length; i++)&lt;br /&gt;  {&lt;br /&gt;   ts.add(num[i]);&lt;br /&gt;  }&lt;br /&gt;  System.out.println("The numbers of the array in ascending order are: "+ts);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For more information on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-8763626403775055530?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/07/sorting-ascending-java-program.html' title='Sorting Ascending - Java Program'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/8763626403775055530/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/07/sorting-ascending-java-program.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/8763626403775055530'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/8763626403775055530'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/07/sorting-ascending-java-program.html' title='Sorting Ascending - Java Program'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-5142344535236352371</id><published>2009-07-28T20:39:00.003+05:30</published><updated>2009-07-28T20:47:28.043+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><category scheme='http://www.blogger.com/atom/ns#' term='String'/><title type='text'>Reverse a String - Java Program</title><content type='html'>Hi friends, welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. The Java Code discussed today, helps in reversing any String that is entered to the system. It displays the reverse String of the String that is entered in the system.&lt;br /&gt;&lt;br /&gt;The Java Code is given below:-&lt;br /&gt;&lt;br /&gt;import java.io.BufferedReader;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.io.InputStreamReader;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class ReverseString {&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * @param args&lt;br /&gt;  * @throws IOException &lt;br /&gt;  */&lt;br /&gt; public static void main(String[] args) throws IOException {&lt;br /&gt;  System.out.println("Enter a string to be reversed: ");&lt;br /&gt;  InputStreamReader isr = new InputStreamReader(System.in);&lt;br /&gt;  BufferedReader br = new BufferedReader(isr);&lt;br /&gt;  String str = br.readLine();&lt;br /&gt;  StringBuffer sb = new StringBuffer().append(str);&lt;br /&gt;  System.out.println("The reversed string is:\n"+sb.reverse().toString());&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; for more info on Java.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-5142344535236352371?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/07/reverse-string-java-program.html' title='Reverse a String - Java Program'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/5142344535236352371/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/07/reverse-string-java-program.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/5142344535236352371'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/5142344535236352371'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/07/reverse-string-java-program.html' title='Reverse a String - Java Program'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-183647125911513850</id><published>2009-07-28T20:31:00.001+05:30</published><updated>2009-07-28T20:38:27.183+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><category scheme='http://www.blogger.com/atom/ns#' term='String'/><title type='text'>Length of a String - Java Program</title><content type='html'>Hi friends, welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Today's tutorial consists of a Java Program to find the number of characters in a String or number. This Java Program is helpful in finding the length of any String that is entered.&lt;br /&gt;&lt;br /&gt;The Java Code begins by asking the user to enter any String or number, and then it displays the length of that entered String.&lt;br /&gt;&lt;br /&gt;The Java Code is given below:-&lt;br /&gt;&lt;br /&gt;import java.io.BufferedReader;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.io.InputStreamReader;&lt;br /&gt;&lt;br /&gt;public class NoOfWordsInString {&lt;br /&gt; &lt;br /&gt; public static void main(String[] args) throws IOException {&lt;br /&gt;  System.out.println("Enter a string or number for which the number of words is to be counted: ");&lt;br /&gt;  InputStreamReader isr = new InputStreamReader(System.in);&lt;br /&gt;  BufferedReader br = new BufferedReader(isr);&lt;br /&gt;  String str = br.readLine();&lt;br /&gt;  System.out.println("The no of words in the string are: "+str.length());&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For more information on Java, and to get more of Java Code and Examples, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-183647125911513850?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/07/length-of-string-java-program.html' title='Length of a String - Java Program'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/183647125911513850/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/07/length-of-string-java-program.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/183647125911513850'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/183647125911513850'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/07/length-of-string-java-program.html' title='Length of a String - Java Program'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-8477855610365525310</id><published>2009-07-27T23:40:00.003+05:30</published><updated>2009-07-27T23:47:01.128+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><category scheme='http://www.blogger.com/atom/ns#' term='Rectangle'/><title type='text'>Java Program for Area and Perimeter of Rectangle</title><content type='html'>Hi friends, welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;, the Java code that is discussed today, finds the area and Perimeter of a rectangle depending on the length and width of the rectangle. When you run this Java Code, then provide the length and width of the rectangle as the input arguments yo the file.&lt;br /&gt;&lt;br /&gt;The Java code for finding the Area and Permiter of Rectangle is given below:-&lt;br /&gt;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class AreaPerimeterRectangle {&lt;br /&gt; &lt;br /&gt; public static void main(String[] args) throws NumberFormatException, IOException {&lt;br /&gt;  System.out.println("Enter the length and width of the rectangle: ");&lt;br /&gt;  float length = Float.parseFloat(args[0]);&lt;br /&gt;  float width = Float.parseFloat(args[1]);&lt;br /&gt;  System.out.println("Area of the Rectangle is: "+length*width);&lt;br /&gt;  System.out.println("Perimeter of the Rectangle is: "+2*(length+width));&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;For more information on Java, kepp buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-8477855610365525310?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/07/java-program-for-area-and-perimeter-of.html' title='Java Program for Area and Perimeter of Rectangle'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/8477855610365525310/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/07/java-program-for-area-and-perimeter-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/8477855610365525310'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/8477855610365525310'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/07/java-program-for-area-and-perimeter-of.html' title='Java Program for Area and Perimeter of Rectangle'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-7448623630918920078</id><published>2009-07-27T23:31:00.002+05:30</published><updated>2009-07-27T23:39:57.882+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='Circle'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><title type='text'>Java Program to find the Area and Circumference of Circle</title><content type='html'>Hi friends, welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Today I will give you a simple Java Program to find the Area and Circumference of a Circle.&lt;br /&gt;&lt;br /&gt;The Area and Circumference depends on the radius of the circle, so the code first asks the user for the radius of the circle, and then computes the area and circumference of the circle.&lt;br /&gt;The code is given below:-&lt;br /&gt;&lt;br /&gt;import java.io.BufferedReader;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.io.InputStreamReader;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class AreaCircumferenceCircle {&lt;br /&gt;final static float pi = 22/7f; &lt;br /&gt; &lt;br /&gt; public static void main(String[] args) throws NumberFormatException, IOException {&lt;br /&gt;  System.out.println("Enter the radius of the circle: ");&lt;br /&gt;  InputStreamReader io= new InputStreamReader(System.in);&lt;br /&gt;  BufferedReader br = new BufferedReader(io);&lt;br /&gt;  float radius = Float.parseFloat(br.readLine());&lt;br /&gt;  System.out.println("Area of the Circle is: "+radius*radius*pi);&lt;br /&gt;  System.out.println("Circumference of the Circle is: "+2*radius*pi);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;I hope the above code was helpful to you all. For more info on Java, keep checking &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-7448623630918920078?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/07/java-program-to-find-area-and.html' title='Java Program to find the Area and Circumference of Circle'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/7448623630918920078/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/07/java-program-to-find-area-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/7448623630918920078'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/7448623630918920078'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/07/java-program-to-find-area-and.html' title='Java Program to find the Area and Circumference of Circle'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-6077178813093217011</id><published>2009-07-22T21:17:00.006+05:30</published><updated>2009-08-16T22:51:26.110+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Recursion'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='Factorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><title type='text'>Factorial Program in Java, Java program for finding the Factorial of a number</title><content type='html'>Hi friends, welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Today I will give you the Java code for finding the factorial of an entered number. The factorial of a number is the product of all the numbers starting from 1 till that particular number.&lt;br /&gt;&lt;br /&gt;The Java code provided asks the user to enter a number for which the factorial is desired. It then uses recursion to find the factorial of that number. Though recursion is not always the best approach for solving a Java problem, since it can lead to core dump or Dr. Watson error in Windows. It implies that if recursion is used improperly, then it can loop again and again into itself, causing stackOverflowError in Java, leading to crashing of the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-java-virtual-machinejvm.html"&gt;JVM&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The Java Code is provided below:-&lt;br /&gt;&lt;br /&gt;import java.io.BufferedReader;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.io.InputStreamReader;&lt;br /&gt;&lt;br /&gt;public class Factorial {&lt;br /&gt; &lt;br /&gt; public static void main(String[] args) throws NumberFormatException, IOException {&lt;br /&gt;  long num;&lt;br /&gt;  System.out.println("Enter a number greater then or equal to 0 and less then 40 for which the factorial is desired:-");&lt;br /&gt;  InputStreamReader ir = new InputStreamReader(System.in);&lt;br /&gt;     BufferedReader br = new BufferedReader(ir);&lt;br /&gt;  num = Integer.parseInt(br.readLine());&lt;br /&gt;  if(num&gt;=0 &amp;&amp; num &lt; 40)&lt;br /&gt;  {&lt;br /&gt;   if(num == 0)&lt;br /&gt;    {&lt;br /&gt;     num =1;&lt;br /&gt;    }&lt;br /&gt;   System.out.println(factorial(num));&lt;br /&gt;  }&lt;br /&gt;  else&lt;br /&gt;  {&lt;br /&gt;   System.out.println("Number out of range");&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private static long factorial(long num) {     &lt;br /&gt;   if(num &gt; 1)&lt;br /&gt;   {&lt;br /&gt;   num = num * factorial(num-1);&lt;br /&gt;   }&lt;br /&gt;   else&lt;br /&gt;   {&lt;br /&gt;    return num; &lt;br /&gt;   }   &lt;br /&gt;   return num;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;I hope that the Java code provided for finding the factorial of a number is useful to you all. If you like the post, then do leave a comment. For more info on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-6077178813093217011?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/07/factorial-program-in-java-java-program.html' title='Factorial Program in Java, Java program for finding the Factorial of a number'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/6077178813093217011/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/07/factorial-program-in-java-java-program.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/6077178813093217011'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/6077178813093217011'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/07/factorial-program-in-java-java-program.html' title='Factorial Program in Java, Java program for finding the Factorial of a number'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-6330444162054817299</id><published>2009-07-21T23:43:00.004+05:30</published><updated>2009-07-27T21:49:17.583+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><category scheme='http://www.blogger.com/atom/ns#' term='Fibonacci Series'/><title type='text'>Java Program for Fibonacci Series, Fibonacci Series Example in Java</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Today I am going to give you the Java code for generating Fibonacci Series up to a particular number. A Fibonacci Number is one which is the sum of previous two numbers in that series.&lt;br /&gt;&lt;br /&gt;A Fibonacci series always starts with 0, 1 and then the sum of last two digits in the series i.e 0 1 1 2 3 5 8 13 21.... This is an example of a Fibonacci series.&lt;br /&gt;&lt;br /&gt;This Java Code asks for a number till which the Fibonacci series is to be generated, and then generates the Fibonacci series up till that number. &lt;br /&gt;&lt;br /&gt;The Java code is shown below:-&lt;br /&gt;&lt;br /&gt;import java.io.*;&lt;br /&gt;&lt;br /&gt;public class Fibonacci {&lt;br /&gt;  public static void main(String[] args)&lt;br /&gt;  {    &lt;br /&gt;    InputStreamReader ir = new InputStreamReader(System.in);&lt;br /&gt;    BufferedReader br = new BufferedReader(ir);&lt;br /&gt;    System.out.println("Enter the number till which Fibonnaci Series is desired:");    &lt;br /&gt;    int num;&lt;br /&gt; try {&lt;br /&gt;  num = Integer.parseInt(br.readLine());&lt;br /&gt;  getFibonnaci(num);  &lt;br /&gt; } catch (NumberFormatException e) {  &lt;br /&gt;  e.printStackTrace();&lt;br /&gt; } catch (IOException e) {  &lt;br /&gt;  e.printStackTrace();&lt;br /&gt; }   &lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;   static void getFibonnaci(int fibonnaci)&lt;br /&gt;  {&lt;br /&gt;   System.out.println("The Fibonnaci Series till "+fibonnaci+" is:-");&lt;br /&gt;   System.out.print("0 ");   &lt;br /&gt;   int f1 =0, f2 = 1,f3;&lt;br /&gt;   while(f2 &lt;=fibonnaci){    &lt;br /&gt;    System.out.print(f2+" ");&lt;br /&gt;    f1 = f1 + f2;    &lt;br /&gt;    f3 = f2;&lt;br /&gt;    f2 = f1;&lt;br /&gt;    f1 = f3;    &lt;br /&gt;   }     &lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;I hope the code for generating the Fibonacci series is helpful to you all. If you like the post useful, then do leave a comment. For more info on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-6330444162054817299?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/07/java-program-for-fibonacci-series.html' title='Java Program for Fibonacci Series, Fibonacci Series Example in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/6330444162054817299/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/07/java-program-for-fibonacci-series.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/6330444162054817299'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/6330444162054817299'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/07/java-program-for-fibonacci-series.html' title='Java Program for Fibonacci Series, Fibonacci Series Example in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-1764922713603787963</id><published>2009-07-20T22:11:00.005+05:30</published><updated>2009-07-27T21:49:55.180+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Prime Number'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Program'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Example'/><title type='text'>Java code for Prime Number, Prime Number Example in Java</title><content type='html'>Hi friends, welcome back to &lt;a href = "http://javacodeonline.blogspot.com"&gt;Java Code Online&lt;/a&gt;. Today I am going to give you the Java Code for finding out whether a number is prime or not. A prime number is a number which is divisible by 1 or by itself only. The prime number is divisible by no other number except one and itself. Prime number is of utmost importance in Mathematics, and is used extensively in this field.&lt;br /&gt;&lt;br /&gt;The Java code for finding a number is prime or not, is displayed below:-&lt;br /&gt;&lt;br /&gt;import java.io.*;&lt;br /&gt;&lt;br /&gt;public class primeNumber {&lt;br /&gt;  public static void main(String[] args)&lt;br /&gt;  {    &lt;br /&gt;    InputStreamReader ir = new InputStreamReader(System.in);&lt;br /&gt;    BufferedReader br = new BufferedReader(ir);&lt;br /&gt;    System.out.println("Enter the number you want to test for prime number:");&lt;br /&gt;    int num =0;&lt;br /&gt;    int check = 0;&lt;br /&gt; try {&lt;br /&gt;  num = Integer.parseInt(br.readLine());  &lt;br /&gt;     for (int i=2; i &lt; num/2; i++ ){&lt;br /&gt;      if(num%i == 0)&lt;br /&gt;      {       &lt;br /&gt;       check = 0;&lt;br /&gt;       break;&lt;br /&gt;      } &lt;br /&gt;      else&lt;br /&gt;      {&lt;br /&gt;       check = 1;&lt;br /&gt;      }&lt;br /&gt;     }&lt;br /&gt;     if(check == 1 || num == 2)&lt;br /&gt;     {&lt;br /&gt;      System.out.println("The number is prime");&lt;br /&gt;     }&lt;br /&gt;     else&lt;br /&gt;     {&lt;br /&gt;      System.out.println("The number is not prime");&lt;br /&gt;     }     &lt;br /&gt; } catch (NumberFormatException e) {&lt;br /&gt;  System.out.println("Kindly enter a proper integer number");&lt;br /&gt;  &lt;br /&gt; } catch (IOException e) {&lt;br /&gt;  System.out.println("There is some error in the input output handling");  &lt;br /&gt; }    &lt;br /&gt;  }&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;I hope that this Java Code for finding a number is prime or not is helpful to you all. For more info on Java,keep buzzing &lt;a href = "http://javacodeonline.blogspot.com"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-1764922713603787963?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/07/java-code-for-prime-number-prime-number.html' title='Java code for Prime Number, Prime Number Example in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/1764922713603787963/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/07/java-code-for-prime-number-prime-number.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1764922713603787963'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1764922713603787963'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/07/java-code-for-prime-number-prime-number.html' title='Java code for Prime Number, Prime Number Example in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-1631844968296960727</id><published>2009-07-07T00:01:00.007+05:30</published><updated>2009-07-27T21:50:36.743+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SCJP'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Certifications'/><title type='text'>Sun Certified Java Programmer (SCJP)</title><content type='html'>Hello friends, welcome back to &lt;a href = "http://www.javacodeonline.blogspot.com"&gt;Java Code Online&lt;/a&gt;. I am sorry for being absent for such a long time. Actually I had a lot of job load, and was very busy in that. As a Java programmer I have to meet many deadlines one after another.&lt;br /&gt;&lt;br /&gt;Meeting deadlines was not the only thing that kept me apart from blogging. The main thing was SCJP 5.0 exam. Actually recentely I gave the SCJP exam, and cleared it easily. I found that preparing for SCJP 5.0 was one of the best way for strenthening your Java roots.&lt;br /&gt;&lt;br /&gt;I found the exam to be truly overwhelming. As an overview SCJP stands for Sun Certified Java Programmer. It is a 3 and 1/2 hour exam, though the questions are pretty simple and could be finished much before the given time. Once again I will like to tell you that the level and comfort of exam depends upon your preparation.&lt;br /&gt;&lt;br /&gt;It took me around 1 month, to cover the entire syllabus (I had mostly weekends). Regarding the book and course material to study, I strongly recommend Kathy Sierra for SCJP 5.0. Go ahead, read this and you will love Java.&lt;br /&gt;&lt;br /&gt;The question are objective in nature and there are also drag and drop type, where you are suppose to drag the right answer to its right place. These questions actually test your Java Coding knowledge.&lt;br /&gt;&lt;br /&gt;SCJP 5.0 includes core Java. They just want to test you on the core Java concepts. This includes basic programming, threads, generics, collections, etc. I will advise a strong hold on collections and threads, since they seem to have many questions.&lt;br /&gt;&lt;br /&gt;The sections were cool and comfortable, though I have to fight a bit in the sections of Threads and Garbage collection concepts. These topic seem to be simple, but beleive me, garbage collection is linked with &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-java-virtual-machinejvm.html"&gt;JVM&lt;/a&gt;, and very difficult questions can be made on  it.&lt;br /&gt;&lt;br /&gt;I will suggest, that all of you preparing for Java, and wish to have a carrier in Java, should go ahead and give the SCJP exam. My best wishes to all. For more info on Java keep buzzing &lt;a href = "http://www.javacodeonline.blogspot.com"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-1631844968296960727?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/07/sun-certified-java-programmer-scjp.html' title='Sun Certified Java Programmer (SCJP)'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/1631844968296960727/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/07/sun-certified-java-programmer-scjp.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1631844968296960727'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1631844968296960727'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/07/sun-certified-java-programmer-scjp.html' title='Sun Certified Java Programmer (SCJP)'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3416407328338427543.post-135306074543731124</id><published>2009-02-01T23:45:00.005+05:30</published><updated>2009-07-27T21:52:47.002+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><category scheme='http://www.blogger.com/atom/ns#' term='OOPS Principles'/><title type='text'>Why do we need Abstraction</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-abstraction.html"&gt;Abstraction&lt;/a&gt; is one of the basic and most important &lt;a href = "http://javacodeonline.blogspot.com/2008/12/principle-of-oops.html"&gt;Principle of OOPS&lt;/a&gt; and of Java itself. I have discussed &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-abstraction.html"&gt;Abstraction&lt;/a&gt; in my earlier post, and I have made this clear that how Abstraction is important for OOPS to function properly.&lt;br /&gt;&lt;br /&gt;In this article I will discuss, the basic advantage that a programmer gets by using Abstraction while coding in Java. &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-abstraction.html"&gt;Abstraction&lt;/a&gt; in itself has many advantage. They are:-&lt;br /&gt;&lt;br /&gt;1. &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-abstraction.html"&gt;Abstraction&lt;/a&gt; make your code readable. Since the code is structured and is &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; Oriented, you define a hierarchy. So your code becomes more readable for the viewer and is better t understand.&lt;br /&gt;&lt;br /&gt;2. &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-abstraction.html"&gt;Abstraction&lt;/a&gt; makes your code small. Since you abstract out the common things from a class, you need not write that same code again and again. So it implies less coding for applications when you extend your code.&lt;br /&gt;&lt;br /&gt;3. By using &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-abstraction.html"&gt;Abstraction&lt;/a&gt;, it becomes much more easier to maintain the code then otherwise. In Java or any other language which is based on &lt;a href = "http://javacodeonline.blogspot.com/2008/12/principle-of-oops.html"&gt;OOPS&lt;/a&gt;, Abstraction helps to structure your code and hence it helps to make the code easy and easier to maintain. Whenever you need to change or modify something, you know where in the structure you need to make the change. Indeed a happy life for the developer.&lt;br /&gt;&lt;br /&gt;4.&lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-abstraction.html"&gt;Abstraction&lt;/a&gt; helps to generalize your code. Since you have already abstracted the common code, you may easily generalize your code by extending the Abstract class.&lt;br /&gt;&lt;br /&gt;5. &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-abstraction.html"&gt;Abstraction&lt;/a&gt; matches with the practical world and is therefore easier to code and maintain. Abstraction is based on the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/principle-of-oops.html"&gt;Principle of OOPS&lt;/a&gt; and is thus &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; oriented, it is built with the practical world in mind. Here whenever you start something, you always start with an Abstract idea and then you extend it. In Java coding also the same thing occurs. Abstraction is just the abstract of the main thing.&lt;br /&gt;&lt;br /&gt;I hope the article helped you understand the requirement of &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-abstraction.html"&gt;Abstraction&lt;/a&gt;. If you liked the article then do leave a comment. For more info on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-135306074543731124?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/02/why-do-we-need-abstraction.html' title='Why do we need Abstraction'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/135306074543731124/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/02/why-do-we-need-abstraction.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/135306074543731124'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/135306074543731124'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/02/why-do-we-need-abstraction.html' title='Why do we need Abstraction'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3416407328338427543.post-3852535603456866963</id><published>2009-01-22T21:56:00.004+05:30</published><updated>2009-07-27T21:53:33.299+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>Is a "main" method required for every class in Java?</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. One of the most basic conception for a fresher is to put a main method in each Java &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;class&lt;/a&gt; he or she writes. Most often they never know that, not all Java Class need a main method.&lt;br /&gt;&lt;br /&gt;Java is an Object Oriented language based on the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/principle-of-oops.html"&gt;Principle of OOPS&lt;/a&gt;. The basic principle of OOPS is to visualize everything as an Object. The best coding practice is to make a separate class for each &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; that is required by your Java Code.&lt;br /&gt;&lt;br /&gt;The "main" method is required to start the program. Whenever the Java program is executed, the JVM looks for the method containing the "main" method. It gets it in the form of &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-reason-for-each-keyword-of.html"&gt;public static void main(String args[])&lt;/a&gt;. This method tells the JVM that ok, I am the main method and you need to start reading the code from me.&lt;br /&gt;&lt;br /&gt;There could be multiple classes with different methods serving different functionality, though none of them may contain a "main" method. There could be a single class which controls or more specifically uses these other classes, make their Objects and use them in the Java Code. &lt;br /&gt;&lt;br /&gt;So, now I think that I am clear. It is not compulsory for every class in Java to have a "main" method, though there has to be class with a main method which uses uses these classes.&lt;br /&gt;&lt;br /&gt;I hope the article was beneficial in understanding the requirement of the "main" method in the Java Code. If you liked the article then do leave a comment. For more info on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-3852535603456866963?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/01/is-main-method-required-for-every-class.html' title='Is a &quot;main&quot; method required for every class in Java?'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/3852535603456866963/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/01/is-main-method-required-for-every-class.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3852535603456866963'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3852535603456866963'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/01/is-main-method-required-for-every-class.html' title='Is a &quot;main&quot; method required for every class in Java?'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-3152332470141665496</id><published>2009-01-21T21:45:00.002+05:30</published><updated>2009-07-27T21:54:11.366+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>Difference between Sysyem.out.println and System.out.print in Java</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. System.out.print and System.out.println are used to print the output at the console. It is one of the most commonly used command in Java.&lt;br /&gt;&lt;br /&gt;Often while coding we come across System.out.print and System.out.println. Have you ever wondered what could be the possible difference between these two Java Commands. I will explain it to you:-&lt;br /&gt;1. System.out.print prints the output in the same line.&lt;br /&gt;2. System.out.println inserts a new line there by enhancing the beauty of the output.&lt;br /&gt;&lt;br /&gt;println of System.out.println is normally interpreted as print new line. So you can remember it easily. If you want that your Java code output appears in a new line each time, then use System.out.println. But if you want that all the Java Code output should continue coming on the same line, then use System.out.print.&lt;br /&gt;&lt;br /&gt;I hope the article clarifies your doubt about System.out.print and System.out.println. If you liked the article then do leave a comment. For more info on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-3152332470141665496?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/01/difference-between-sysyemoutprintln-and.html' title='Difference between Sysyem.out.println and System.out.print in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/3152332470141665496/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/01/difference-between-sysyemoutprintln-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3152332470141665496'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3152332470141665496'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/01/difference-between-sysyemoutprintln-and.html' title='Difference between Sysyem.out.println and System.out.print in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-7634201386471114634</id><published>2009-01-21T00:16:00.003+05:30</published><updated>2009-07-27T21:54:49.144+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><category scheme='http://www.blogger.com/atom/ns#' term='OOPS Principles'/><title type='text'>Why is everything in Java written in a class</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. We all know that Java is an Object oriented language based on the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/principle-of-oops.html"&gt;Principle of OOPS&lt;/a&gt;. The basic principle of Java is to recognize your &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Objects&lt;/a&gt;. Whenever you need to start coding, just ask yourself, what are the Objects involved in this Java code.&lt;br /&gt;&lt;br /&gt;Now once you have finalized your Objects, then you need to put them in code. But if you start putting all your Object code in a single large Java file, then it will look very unclean and messy, moreover the beauty of the code is lost. What best can be done is that we put the code in classes.&lt;br /&gt;&lt;br /&gt;A &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;class&lt;/a&gt; is a blueprint of an Object, so it define the Object. So as a natural process of coding in Java, you recognize your Objects put them in separate classes and then write a main class that make Objects of those classes and perform the operations required.&lt;br /&gt;&lt;br /&gt;It is simply equivalent to the human body, where the main class is the brain of our human body, we have limbs, legs, fingers, joints, heart, etc. each performing its own function. So it is like all the parts are Objects in Java for which we write separate classes, now these separate classes are used by the main class (brain of the human body), and so we see that all the parts coordinate and perform the tasks they are made for. Simple.&lt;br /&gt;&lt;br /&gt;If you really want to understand the basics of Java, then do often relate it to practical life things, and you will find Java very easy, this is because Java is built to work on practical situations.&lt;br /&gt;&lt;br /&gt;I hope the article answered the question that why everything in Java is written in a class. If you liked the article then do leave a comment. For more info on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-7634201386471114634?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/01/why-is-everything-in-java-written-in.html' title='Why is everything in Java written in a class'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/7634201386471114634/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/01/why-is-everything-in-java-written-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/7634201386471114634'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/7634201386471114634'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/01/why-is-everything-in-java-written-in.html' title='Why is everything in Java written in a class'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-7661991655566267979</id><published>2009-01-11T16:04:00.003+05:30</published><updated>2009-07-27T21:55:39.400+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>What is the difference between instance variable and local variable</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. While working with Java, you must have multiple times come across words like instance variable and local variable. But have you ever wondered that what is the difference between them. Well, today I am going to discuss that. But before proceeding on this topic you need to know what is an instance variable and what is a &lt;a href = "http://javacodeonline.blogspot.com/2009/01/what-is-local-variable-in-java.html"&gt;local variable in Java&lt;/a&gt;. Refer to my previous post for information on the instance variable and local variable in Java.&lt;br /&gt;&lt;br /&gt;There are two major differences between an instance variable and a local variable in Java. They are:-&lt;br /&gt;&lt;br /&gt;1. Instance variable is declared within a class but not within a method, while a local variable is declared within a method.&lt;br /&gt;&lt;br /&gt;2. Instance variable get a default value, so if they are used before initializing them, then also they compile fine. But in the case of local variable in Java, local variable in Java do not get an initial value, so if you use them in your code without initializing them, then you will get a compile time exception.&lt;br /&gt;&lt;br /&gt;I hope the article was helpful in understanding the difference between instance variable and local variable in Java. If you liked the article, then do leave a comment. For more information on Java keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-7661991655566267979?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/01/what-is-difference-between-instance.html' title='What is the difference between instance variable and local variable'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/7661991655566267979/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/01/what-is-difference-between-instance.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/7661991655566267979'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/7661991655566267979'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/01/what-is-difference-between-instance.html' title='What is the difference between instance variable and local variable'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-4450094732147317704</id><published>2009-01-10T19:40:00.002+05:30</published><updated>2009-07-27T21:59:35.480+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>What is an instance variable in Java</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. You must have heard the instance variable a multiple number of times while writing your Java code, but do you really understand what is a instance variable in Java. Today I will discussing about instance variables in Java.&lt;br /&gt;&lt;br /&gt;An instance variable in Java is one which is declared within a &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;class&lt;/a&gt; and not within a method. Whenever you write code in Java, you do it with the help of classes. In most of the classes you need to declare some variables for some purpose or the other. These variables which are declared within the class but not within the method are called instance variables in Java.&lt;br /&gt;&lt;br /&gt;If you declare the variable within a method, then it becomes a &lt;a href = "http://javacodeonline.blogspot.com/2009/01/what-is-local-variable-in-java.html"&gt;local variable&lt;/a&gt; of that method and not an instance variable of the class. So you need to declare it within a class but outside any method. I will clarify my point with an example.&lt;br /&gt;&lt;br /&gt;class JavaCode{&lt;br /&gt;int code;&lt;br /&gt;float test;&lt;br /&gt;//Some Java Code here&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;In the above Java Code, the variables "code" and "test" are local to a class but are outside any method, and are therefore instance variables of this class. I hope you got my point now.&lt;br /&gt;&lt;br /&gt;One important point about instance variable is that, they always get a default value. If you declare any instance variable in your Java Code and use them without initializing them, then also the compiler will not complain, and it will compile properly. This happens because the compiler assigns the instance variables a default value. So if the instance variables are not initialized then the default value is used in their place.&lt;br /&gt;&lt;br /&gt;The default values of the various type of variables is shown below:-&lt;br /&gt;integers-----------0&lt;br /&gt;floating points----0.0&lt;br /&gt;booleans-----------false&lt;br /&gt;references---------null&lt;br /&gt;&lt;br /&gt;These are default values which are assigned to various types of variables. So to summarize the whole thing.&lt;br /&gt;1. instance variables are declared inside a class but not within a method.&lt;br /&gt;2. instance variables always have a default value assigned to them.&lt;br /&gt;&lt;br /&gt;I hope this article helped you to understand what is an instance variable in Java. If you liked the article then do leave a comment. For more info on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-4450094732147317704?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/01/what-is-instance-variable-in-java.html' title='What is an instance variable in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/4450094732147317704/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/01/what-is-instance-variable-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/4450094732147317704'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/4450094732147317704'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/01/what-is-instance-variable-in-java.html' title='What is an instance variable in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-1624312394612774869</id><published>2009-01-09T22:02:00.002+05:30</published><updated>2009-07-27T22:00:17.132+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>What is a local variable in Java</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. You must have used local variables a multiple number of times in your Java Code. Today we will discuss what actually is a local variable in Java. &lt;br /&gt;&lt;br /&gt;A local variable in Java is one which is defined in a "method". Whenever you write your code, you make methods to do things in Java. Then you call those methods and perform the necessary operations. Any variable that is declared within a method is called a local variable.&lt;br /&gt;&lt;br /&gt;I will take an example here:-&lt;br /&gt;&lt;br /&gt;class JavaCode{&lt;br /&gt;public int code(){&lt;br /&gt;int codeLength = 20;&lt;br /&gt;System.out.println("The Java Code length is:-"+codeLength);&lt;br /&gt;return codeLength;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;This is simple Java Code for declaring a class called JavaCode with a method called code(), which returns an integer. Here you can see that the variable "codeLength" is declared within method and is therefore a local variable.&lt;br /&gt;&lt;br /&gt;Whenever you have to judge that a variable is local or not in Java, just ask yourself, that is the variable local to a method or not. If a variable is defined in a method or is local to a method, then it is a local variable otherwise not.&lt;br /&gt;&lt;br /&gt;One more very important feature of local variable in Java is that they do not have an initial value. So if you declare a local variable in your code and do not initialize it, then that local variable can not be used. Mark my words here, if you use a local variable in Java before initializing it then it will give a compile time exception.&lt;br /&gt;&lt;br /&gt;So to summarize the whole thing, there are two properties of a local variable in Java. They are:-&lt;br /&gt;1. A local variable must be defined within a method.&lt;br /&gt;2. A local variable must be initialized before using it in your code.&lt;br /&gt;&lt;br /&gt;I hope the article helped you understand what is a local variable in Java. If you liked the article then do leave a comment. For more info on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-1624312394612774869?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/01/what-is-local-variable-in-java.html' title='What is a local variable in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/1624312394612774869/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/01/what-is-local-variable-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1624312394612774869'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1624312394612774869'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/01/what-is-local-variable-in-java.html' title='What is a local variable in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-6228337956823562331</id><published>2009-01-08T21:27:00.001+05:30</published><updated>2009-07-27T22:00:53.605+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>What is a variable in Java</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Today I will be discussing about what is a variable in Java. In Java, whatever you do, you need to do that with the help of variables.&lt;br /&gt;&lt;br /&gt;A variable as the name signifies is something that can vary. I do not mean that it will always vary, there are modifiers in Java like "final" which if used along with the variable, makes it impossible to vary. A variable is like a container, which has the capability to hold something.&lt;br /&gt;&lt;br /&gt;You remember that when you are feeling sleepy, then your mom gives you tea. The tea is in a cup or glass. This cup or glass is a container, that holds the tea. Similarly in Java, the variable which is like a container holds some value or some reference parameter.&lt;br /&gt;&lt;br /&gt;A variable in Java could be of two types:-&lt;br /&gt;1. primitive variable&lt;br /&gt;2. object reference variable&lt;br /&gt;&lt;br /&gt;Primitives variables are used to hold basic values needed for normal computation bu Java, like some number, or an integer or a floating point number or it could be a boolean also. Object Reference variables are used to reference to some &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;A variable has to follow some rules, in order to qualify as variable in Java. The rules are simple and must always be implemented. The rules are:-&lt;br /&gt;1. A variable must have a type.&lt;br /&gt;2. A variable must have a name.&lt;br /&gt;&lt;br /&gt;I will clarify on this point with an example. If you say:-&lt;br /&gt;&lt;br /&gt;float marks;&lt;br /&gt;&lt;br /&gt;Then in the above Java code, "float" is the type of variable and "marks" is the name of the variable. Simple isn't it. &lt;br /&gt;&lt;br /&gt; I hope the article helped you in understanding what is a variable in Java. If you liked the article then do leave a comment. Foe more info on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-6228337956823562331?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/01/what-is-variable-in-java.html' title='What is a variable in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/6228337956823562331/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/01/what-is-variable-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/6228337956823562331'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/6228337956823562331'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/01/what-is-variable-in-java.html' title='What is a variable in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-505252183411441494</id><published>2009-01-02T23:48:00.004+05:30</published><updated>2009-07-27T22:01:35.666+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Code'/><title type='text'>Hello World Program in Java</title><content type='html'>Hello all, Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Today I will start with a very simple Java Code program. This is called the Hello World Program, and when executed prints "Hello World" at the output.&lt;br /&gt;&lt;br /&gt;public &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;class&lt;/a&gt; MyFirstCode{&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-reason-for-each-keyword-of.html"&gt;public static void main(String args[])&lt;/a&gt;{&lt;br /&gt;System.out.println("Hello World");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;This program needs to be saved with the name of MyFirstCode.java, because in Java the name of the class containing the main method, needs to be the name of the java file itself.&lt;br /&gt;&lt;br /&gt;When you execute this code, then you will get the output as "Hello World".&lt;br /&gt;&lt;br /&gt;So, enjoy the world of Java, and make your own experiments with coding. See you later guys and gals. Keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-505252183411441494?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/01/hello-world-program-in-java.html' title='Hello World Program in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/505252183411441494/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/01/hello-world-program-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/505252183411441494'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/505252183411441494'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/01/hello-world-program-in-java.html' title='Hello World Program in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-7049248580289120818</id><published>2009-01-01T21:23:00.004+05:30</published><updated>2009-07-27T22:02:05.552+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>Character Escape Sequence in Java</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. The character escape sequence in Java is highly useful when dealing with Strings. These escape sequence help in formatting the output as required. This gives the developer a greater control over the text and the output.&lt;br /&gt;&lt;br /&gt;For example suppose that you need to print a String "Hello, I am Learning Java". Then the code for this will be:-&lt;br /&gt;&lt;br /&gt;String str = "Hello, I am Learning Java";&lt;br /&gt;&lt;br /&gt;Now suppose that you want to enclose Java in double quotes, like you want the output to be something like:-&lt;br /&gt;&lt;br /&gt;Hello, I am Learning "Java"&lt;br /&gt;&lt;br /&gt;For this you need to place double quotes withing the String statement. But oops, there is a problem, if you put double quotes in a String statement, then it will break the String. I mean, if you say that:&lt;br /&gt;&lt;br /&gt;String str = "Hello, I am Learning "Java"";&lt;br /&gt;&lt;br /&gt;Now this will create blunder as in Java the declaration of a String is done in double quotes, so Java will assume that the statement starting from the first double quote is the starting point of the String, and the second double quote will close the String. But this approach will leave the word "Java" outside the String declaration.&lt;br /&gt;&lt;br /&gt;Java comes with a solution to that, here the Character Escape Sequence of Java comes to rescue. The escape sequence allows you to embed special characters like double quotes, line feed, carriage return, tab, etc. into the same String. The above example is corrected as follows:-&lt;br /&gt;&lt;br /&gt;String str = "Hello, I am Learning \"Java\"";&lt;br /&gt;&lt;br /&gt;Now this is the correct way as per Java. What Java sees is that anything after the "\" symbol is to be placed as it is, and is a part of the whole String overall. Though the symbol "\" has different implications with regard to other escape sequences, like "\n" inserts a new line, etc.&lt;br /&gt;&lt;br /&gt;The Character escape Sequence in Java is shown below:-&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Escape Sequence&lt;/b&gt; ------------&lt;b&gt;Purpose&lt;/b&gt;&lt;br /&gt;\ddd ------------  Octal character (ddd)&lt;br /&gt;\uxxxx ------------  Hexadecimal UNICODE character (xxxx)&lt;br /&gt;\’ ------------  Single quote&lt;br /&gt;\” ------------  Double quote&lt;br /&gt;\\ ------------  Backslash&lt;br /&gt;\r ------------  Carriage return&lt;br /&gt;\n ------------  New line (also known as line feed)&lt;br /&gt;\f ------------  Form feed&lt;br /&gt;\t ------------  Tab&lt;br /&gt;\b ------------  Backspace&lt;br /&gt;&lt;br /&gt;I hope the article was helpful in understanding the Character Escape Sequence in Java. If you liked the article then do leave a comment. For more info on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-7049248580289120818?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2009/01/character-escape-sequence-in-java.html' title='Character Escape Sequence in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/7049248580289120818/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2009/01/character-escape-sequence-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/7049248580289120818'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/7049248580289120818'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2009/01/character-escape-sequence-in-java.html' title='Character Escape Sequence in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-3872899340389080475</id><published>2008-12-31T23:40:00.003+05:30</published><updated>2009-08-16T01:22:38.960+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>What are Boolean Data types in Java</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Boolean Data Type is one of the most useful data type, when you need some sort of definitive action. Like it has to be a yes or no, nothing in between. It is exactly like binary, where the numbers could be 0 or 1, nothing else. Boolean Data type is one of the four groups of &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-are-java-data-types.html"&gt;data types in Java&lt;/a&gt; which are &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-are-integer-data-types-in-java.html"&gt;Integer Data Type in Java&lt;/a&gt;, &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-are-floating-point-data-types-in.html"&gt;Floating Point Data Type&lt;/a&gt;, &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-are-character-data-types-in-java.html"&gt;Character Data Types&lt;/a&gt; and the fourth is Boolean Data type itself.&lt;br /&gt;&lt;br /&gt;The Boolean data type tests a particular condition or expression, and evaluates that the condition is "true" "false". The true and false are in quotes because these are the values which are returned while using a Boolean Data Type in Java.&lt;br /&gt;&lt;br /&gt;In the Boolean Data type Category, there is only a single data type called:-&lt;br /&gt;1. boolean (&lt;b&gt;true&lt;/b&gt; or &lt;b&gt;false&lt;/b&gt;)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;boolean&lt;/b&gt;&lt;br /&gt;The boolean data type tests a logical condition, and returns either true or false. The number of bits that a boolean variable occupies is JVM specific. Only two values are possible that are "true" or "false". The boolean data type is used extensively by the relational operators as the return type is always boolean, and also in loops. I will cover loops in Java later. For example:-&lt;br /&gt;&lt;br /&gt;boolean b;&lt;br /&gt;&lt;br /&gt;Then it is implicit that this variable "b" can have only two possible values and they are "true" or "false". Boolean data type are very handy while testing conditions.&lt;br /&gt;&lt;br /&gt;I hope the article helped you get a groove on the Boolean Data types in Java. If you like this article then do post a comment. For more info on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-3872899340389080475?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2008/12/what-are-boolean-data-types-in-java.html' title='What are Boolean Data types in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/3872899340389080475/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-are-boolean-data-types-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3872899340389080475'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3872899340389080475'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-are-boolean-data-types-in-java.html' title='What are Boolean Data types in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-784489311448161256</id><published>2008-12-30T20:26:00.004+05:30</published><updated>2009-08-16T01:22:12.232+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>What are Character Data Types in Java</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. The &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-are-java-data-types.html"&gt;data types in Java&lt;/a&gt; can be categorized in four categories. Character Data Types is the third category after &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-are-integer-data-types-in-java.html"&gt;Integer Data Types&lt;/a&gt; and &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-are-floating-point-data-types-in.html"&gt;Floating Point Data Types&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;In Java the Character Data type is of single type. It is:-&lt;br /&gt;1. char (16 bits) (range: 0 to 65535)&lt;br /&gt;&lt;br /&gt;We will discuss this data type of Java in detail now.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;char&lt;/b&gt;&lt;br /&gt;"char data type in Java" has some special features which were not present in its predecessors like C and C++. In Java the "char" Data Type is 16 bit long. Java uses Unicode to represent characters, and so for languages which have long Unicode representations do have characters which require more then 8 bit of data. That makes Java a truly international language, since by using Unicode charset, Java can define any language in the world.&lt;br /&gt;&lt;br /&gt;If you have noticed above, then you would have seen that the range of "char" data type is from 0 to 65535, there are no negative chars. The range that the "char" data type enjoy in Java, is truly awesome, and makes Java one of the most global languages in the world.&lt;br /&gt;&lt;br /&gt;Regarding functionality of the "char" data type. A "char" data type in Java is capable of handling one character at a time. For example:-&lt;br /&gt;&lt;br /&gt;char testing = 'j';&lt;br /&gt;&lt;br /&gt;Here the variable testing is of "char" Data Type, and is assigned equal to the character 'j'. So isn't it simple.&lt;br /&gt;&lt;br /&gt;Now the Character Data types in Java must be clear to you. In case you liked my article or if if you have any doubt, then do leave a comment. For more info on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-784489311448161256?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2008/12/what-are-character-data-types-in-java.html' title='What are Character Data Types in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/784489311448161256/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-are-character-data-types-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/784489311448161256'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/784489311448161256'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-are-character-data-types-in-java.html' title='What are Character Data Types in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-6018464206574866150</id><published>2008-12-29T21:36:00.003+05:30</published><updated>2009-08-16T01:21:48.064+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>What are Floating Point Data Types in Java</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. As I have promised in my previous article, that i will discuss all the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-are-java-data-types.html"&gt;data types in Java&lt;/a&gt;. So here I am back again, with the second &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-are-java-data-types.html"&gt;data type in Java&lt;/a&gt; known as the Floating Point Data Types. Floating point data Types are useful when dealing with fractional values and are actually linked with the "real" numbers. This is unlike &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-are-integer-data-types-in-java.html"&gt;Integer Data Type in Java&lt;/a&gt; which are linked to "whole" numbers.&lt;br /&gt;&lt;br /&gt;Floating Point Data Types in Java are of two types. they are:-&lt;br /&gt;1. float (32 bits)&lt;br /&gt;2. double (64 bits)&lt;br /&gt;&lt;br /&gt;I will discuss both of these data types in detail below. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;float&lt;/b&gt;&lt;br /&gt;"float" data type takes 32 bits, and is single precision. Since the value of precision is lower then the "double" data type, the "float" data type occupy less memory as compared to the "double" data type. Moreover the processing of "float" is comparatively faster as compared to a "double" data type in Java.&lt;br /&gt;&lt;br /&gt;The downside of using "float" is that, the precision is smaller then "double". So very small and very large values cannot be stored in a "float". Apart from that "float" meets all the requirements for a normal coder.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;double&lt;/b&gt;&lt;br /&gt;"double" consumes 64 bit of storage and is double precision. This data type is most used for scientific calculations, or places where very high degree of precision is required by the application.&lt;br /&gt;&lt;br /&gt;I hope the article helped you understand about Floating Point Data Types in Java. If you liked this article then do leave a comment. For more info on Java keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-6018464206574866150?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2008/12/what-are-floating-point-data-types-in.html' title='What are Floating Point Data Types in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/6018464206574866150/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-are-floating-point-data-types-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/6018464206574866150'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/6018464206574866150'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-are-floating-point-data-types-in.html' title='What are Floating Point Data Types in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-6913450534148849101</id><published>2008-12-28T16:51:00.003+05:30</published><updated>2009-08-16T01:21:21.024+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>What are Integer Data Types in Java</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Integer Data types are the most commonly used &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-are-java-data-types.html"&gt;data types in Java&lt;/a&gt;. They provide the developers with an extraordinary power to deal with numbers. The Integer data types are the ones which deal with whole numbers.&lt;br /&gt;&lt;br /&gt;The integer data types in Java is of four types. They are :-&lt;br /&gt;1. byte (8 bits) (range: -128 to 127)&lt;br /&gt;2. short (16 bits) (range: -32768 to 32767)&lt;br /&gt;3. int (32 bits) (range: -2147483648 to 2147483647)&lt;br /&gt;4. long (64 bits) (range: –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)&lt;br /&gt;&lt;br /&gt;The order is from smallest to largest. All the Integer Data types in Java are signed numbers, and they could be positive or negative. The above order depicts all the key features of the four Integer data types. I will cover each of them in detail below.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;byte&lt;/b&gt;&lt;br /&gt;This is the smallest of all the Integer Data Types consisting of 8 bits. These are signed 8 bit data types used for handling very small amount of data. As you can see from the above rankings, they can store up to a maximum of 8 bits, or the highest decimal possible is 127, i.e 2^7 - 1. Here 7 is used for power because one bit is reserved for the positive or negative sign., so it leaves it with 7 bits.&lt;br /&gt;&lt;br /&gt;As the value which could be hold is very small, they are not much used in applications, apart from handing some binary operations where the data range is very small.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;short&lt;/b&gt;&lt;br /&gt;"short" data type comes after the "byte" data type in the hierarchy, they are 16 bit signed data types. These data types are the least used data types among all the various data types in Java.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;int&lt;/b&gt;&lt;br /&gt;After "short" data type comes the most used and most common data type in Java, and that is "int". The point that makes it the most versatile data type in Java, is the fact that its range covers almost all the possible numbers which could be used by a common person. The rankings above show that in case of an "int", the range is large enough to hold any kind of number. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;long&lt;/b&gt;&lt;br /&gt;"long" is the last data type in the rankings and comes after "int" data type. The range that a "long" can accommodate is huge, and is infact only used in those rare occasions when the int is not sufficient to hold the number. This data type is quite useful when dealing with very large numbers.&lt;br /&gt;&lt;br /&gt;I hope the article helped you understand about the Integer Data types in Java. If you liked this article, then do leave a comment. For more information on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-6913450534148849101?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2008/12/what-are-integer-data-types-in-java.html' title='What are Integer Data Types in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/6913450534148849101/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-are-integer-data-types-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/6913450534148849101'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/6913450534148849101'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-are-integer-data-types-in-java.html' title='What are Integer Data Types in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-6308940586816482403</id><published>2008-12-27T19:34:00.001+05:30</published><updated>2009-08-16T01:20:55.589+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>What are Java Data Types</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. You will come to know that Java care about its variables, and would not allow a larger value in a smaller variable. Every variable in Java can be classified as:-&lt;br /&gt;1. Primitive&lt;br /&gt;2. Reference&lt;br /&gt;&lt;br /&gt;The data types in Java are concerned with the Primitive type variables, and I will only discuss these in this article. In my later article I will discuss about the reference variables.&lt;br /&gt;&lt;br /&gt;In Java, we need variables to store values and perform operations, for these they need to be assigned some sort of data type. A Data Type defines the intrinsic property of the variable, like its range, the maximum and minimum value it can hold, etc. A correct data type need to be used for every operation in Java.&lt;br /&gt;&lt;br /&gt;Java supports eight Data Types which could be grouped in four domains. They are:-&lt;br /&gt;1. Integers (byte, short, int, long)&lt;br /&gt;2. Floating Point Numbers (float, double)&lt;br /&gt;3. Characters (char)&lt;br /&gt;4. Boolean (boolean)&lt;br /&gt;&lt;br /&gt;The names in the bracket are the actual Data Types used in Java. For example for a mathematical operation, most probably an Integer type or Floating type of data variable will be required. There might be values which are very large and may need a long or double data type. Similarly for a logical condition giving output as 1 or 0, or could be true or false needs to be assigned a Boolean data type. So we see that assigning a correct Data Type is essential for the correct operation of the Java Code.&lt;br /&gt;&lt;br /&gt;I would be covering all these four data types in my next consecutive articles. I will also discuss, why and where to use which type of Data Type. And the most important thing is that why not to use the data type with the largest range if it is not required. As it is commonly seen, that while performing a mathematical operation, we assign the Data Type with the largest range, so as to avoid any range overflow. But this is a bad practice. We should be aware of, that where to use which type of Data Type and where not to.&lt;br /&gt;&lt;br /&gt;I hope this article gave you a good glimpse of Java Data Type. If you liked this article then do leave a comment. For more info on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-6308940586816482403?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2008/12/what-are-java-data-types.html' title='What are Java Data Types'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/6308940586816482403/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-are-java-data-types.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/6308940586816482403'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/6308940586816482403'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-are-java-data-types.html' title='What are Java Data Types'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-5819317269691552717</id><published>2008-12-26T23:31:00.005+05:30</published><updated>2009-08-16T01:20:19.283+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>What is Java Virtual Machine(JVM)</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Java Virtual Machine(JVM) is a program specific to Java used for executing Java &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-bytecode-in-java.html"&gt;Bytecode&lt;/a&gt;. The compiler converts the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-java-source-code.html"&gt;Java Source Code&lt;/a&gt; into Java bytecode.&lt;br /&gt;&lt;br /&gt;The main advantage of JVM is that, once a code is written and compiled on any platform, then it could be executed on the same on any other platform. The only requirement is that JVM must be installed on that device. JVM accepts standardized binary code. So if a developer can write &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-bytecode-in-java.html"&gt;Bytecode&lt;/a&gt; directly, then he does not need a compiler. He can directly run the bytecode using JVM.&lt;br /&gt;&lt;br /&gt;But the developer writing bytecode is totally absurd, no developer how much talented he is can write directly bytecode. Java &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-bytecode-in-java.html"&gt;Bytecode&lt;/a&gt; is highly optimized binary code understood only by the JVM.&lt;br /&gt;&lt;br /&gt;So the main point that comes out is the Sun Microsystems slogan that "write once and run anywhere". JVM provides Java with a specifically great advantage of security and portability. The security feature comes along due to the fact the JVM is like an enclosed shell, which encloses everything regarding execution of the program, so nothing goes out of JVM. And thus the threat of affecting the system by the Java Code is removed.&lt;br /&gt;&lt;br /&gt;Portability comes along due to the fact that, once you have written and compiled the code, you can carry the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-bytecode-in-java.html"&gt;Bytecode&lt;/a&gt; file anywhere and run it, the only requirement is that JVM should be present on that device you internet to run your bytecode. And regarding the current scenario, Java is everywhere and so is JVM.&lt;br /&gt;&lt;br /&gt;I hope the article was helpful in explaining JVM properly to you. If you like the article then do leave a comment. For more information on Java keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-5819317269691552717?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2008/12/what-is-java-virtual-machinejvm.html' title='What is Java Virtual Machine(JVM)'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/5819317269691552717/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-java-virtual-machinejvm.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/5819317269691552717'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/5819317269691552717'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-java-virtual-machinejvm.html' title='What is Java Virtual Machine(JVM)'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3416407328338427543.post-218886762641301442</id><published>2008-12-24T22:38:00.003+05:30</published><updated>2009-08-16T01:19:46.920+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>What is Java Source Code</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Java Source Code is simply the code you write in Java. There are many editors available right now for writing Java Code. The most simple editor for writing Java Source Code is the "Notepad" provided by Windows.&lt;br /&gt;&lt;br /&gt;There are many pioneers in Java Technology, in industry major of the Java applications are written in Eclipse. One more tool that is becoming very famous recently is WSAD(Web Sphere Application Developer) by IBM. This tool is really good.&lt;br /&gt;&lt;br /&gt;I have been using this tool for a long time now, and believe me it meets all your requirements for Java coding. The tools provided in WSAD are awesome. If you have a chance then do put your hands on this tool. WSAD is built on Eclipse itself, so having a knowledge of Eclipse will be very beneficial in using WSAD for writing Java Source Code.&lt;br /&gt;&lt;br /&gt;By default the Java Source Code files have .java extension. So that's it for now guys. If you liked this article then do leave a comment. For more info on Java keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-218886762641301442?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2008/12/what-is-java-source-code.html' title='What is Java Source Code'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/218886762641301442/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-java-source-code.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/218886762641301442'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/218886762641301442'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-java-source-code.html' title='What is Java Source Code'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-5209623646224794413</id><published>2008-12-23T21:13:00.004+05:30</published><updated>2009-08-16T01:19:21.333+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>What is Java Compiler</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Understanding the functionality of the Java Compiler helps in understanding the processing at the back end of Java. A Java Compiler compiles the source code in Java and converts it into &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-bytecode-in-java.html"&gt;Bytecode&lt;/a&gt; which is used by the JVM in running the application.&lt;br /&gt;&lt;br /&gt;In case of most of the programming languages like C, the compiler compiles the source code straight into executable code. This has the drawback of effecting the system configuration or programming viruses that can affect the functionality of the system.&lt;br /&gt;&lt;br /&gt;Java has a two tier architecture that helps in avoiding the above mentioned issue. In Java, the source code is converted into &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-bytecode-in-java.html"&gt;Bytecode&lt;/a&gt; by Compiler, this &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-bytecode-in-java.html"&gt;Bytecode&lt;/a&gt; is only understood by the JVM. And then the JVM runs this bytecode. So anyhow nothing can go out of the shell of the JVM(Java Virtual Machine). The main advantage of this is security.&lt;br /&gt;&lt;br /&gt;You can develop really secure applications in Java, without the fear that it may affect the system's functionality. Moreover any device like mobile or ipod or any other electronic gadget can use mostly use Java application without the fear of it being a virus. This and some other features of Java make it real strong and robust for any sort of conditions.&lt;br /&gt;&lt;br /&gt;The functionality of the Java Compiler comprises of checking any violations of the syntax, and catching any exceptions that may occur during the execution of the program. Only run time exceptions are not checked during compilation of the Java Code by the Java Compiler. This is because Java wants to add an extra feature called "dynamic binding" which occurs at runtime, this concept comes under polymorphism, and I will discuss it again in the article for polymorphism. The comiler provided by Java is called "&lt;b&gt;javac&lt;/b&gt;".&lt;br /&gt;&lt;br /&gt;The "dynamic binding" provides the Java Code flexibility to bind Objects at runtime, that is the developer also does not know which Object will bind during the execution of the program. This is one of the most powerful concepts of Java.&lt;br /&gt;&lt;br /&gt;I hope that this article help you understand the Java Compiler. In case you liked the article, do leave a comment. Remember to check my next article regarding Java on &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt; again.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-5209623646224794413?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2008/12/what-is-java-compiler.html' title='What is Java Compiler'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/5209623646224794413/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-java-compiler.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/5209623646224794413'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/5209623646224794413'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-java-compiler.html' title='What is Java Compiler'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-5674518582000864122</id><published>2008-12-22T20:53:00.007+05:30</published><updated>2009-08-16T01:18:51.065+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>What is Java Package</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Java Package is a very convenient way of grouping similar classes, or classes having similar functionality. Java is a pile of classes, innumerable if you go on reading one by one. It would be impossible to remember every class, just by the name of the class. So what Java does is that group them together into packages.&lt;br /&gt;&lt;br /&gt;Java consists of many packages, each serving some or the other functionality. Whenever you need to use some particular class from a package, you need to import the package. There is another way though, you can use the complete name of the class including the package name every time you need to use that class. But believe me, that is truly ridiculous. It is always better to import the package in which the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;class&lt;/a&gt; is present.&lt;br /&gt;&lt;br /&gt;For example you need the ArrayList class, then there are two ways of using this class in your java code. They are:-&lt;br /&gt;1. import java.util.ArrayList;&lt;br /&gt;2. java.util.ArrayList al = new java.util.ArrayList();&lt;br /&gt;&lt;br /&gt;The first way is the normal and regular way of importing a Java Package in a Java Class. If you do not want to go by the first way, then there is a more tedious way of doing the same thing. The second way demonstrates this thing, here you use the full qualified name of the class required. The problem with this second way is that, here every time you need to use the full qualified name of the Java Class required. That is a bit more tiring as compared to the first and easier way of importing the package once, and that's all that is required.&lt;br /&gt;&lt;br /&gt;So now you must have a good understanding about Java Package. If you like the article then do leave a comment and keep learning Java at &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-5674518582000864122?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2008/12/what-is-java-package.html' title='What is Java Package'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/5674518582000864122/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-java-package.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/5674518582000864122'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/5674518582000864122'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-java-package.html' title='What is Java Package'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-6683189865433035664</id><published>2008-12-21T14:23:00.004+05:30</published><updated>2009-08-16T01:18:14.087+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>What is Java</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Java is one of the most powerful tools available for programming right now. Java was originally created by James Gosling. Originally names as "Oak", it was named as "Java" in 1995. Java was built on the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/principle-of-oops.html"&gt;Principle of OOPS&lt;/a&gt;, which actually provided it a very robust structure.&lt;br /&gt;&lt;br /&gt;Java was built with the main motive of platform independence. That is to develop a language which could be executed on any platform. The thing that makes Java special is the feature that you write your code once, compile it once and then run it anywhere. This has been possible by the use of &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-bytecode-in-java.html"&gt;Bytecode&lt;/a&gt; in Java.&lt;br /&gt;&lt;br /&gt;When the developer writes code in Java, and then compiles the code, the compiler changes the code not into executable code, but into &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-bytecode-in-java.html"&gt;Bytecode&lt;/a&gt;. This &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-bytecode-in-java.html"&gt;Bytecode&lt;/a&gt; is special because it requires JVM to run. So now any machine which has JVM installed on it, can run this Java bytecode. The JVM provides a shell like structure, which encapsulates all the processing of the Java bytecode, so nothing goes out of this shell.&lt;br /&gt;&lt;br /&gt;This is good because, it helps in maintaining security and portability of the code. Currently any system you can think of like your mobile, refrigerator, microwave oven, etc., have somewhere Java inbuilt in them. That's the power of Java.&lt;br /&gt;&lt;br /&gt;The syntax of Java is very much derived from C and C++, this has been done intentionally, so as to make easy for the developers to switch from C or C++ to Java, thereby making the life of the developer easy, and allowing easy adoption of Java in the programming community.&lt;br /&gt;&lt;br /&gt;Today Java is everywhere. If you like this article then do leave a comment. For more information on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-6683189865433035664?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2008/12/what-is-java.html' title='What is Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/6683189865433035664/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-java.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/6683189865433035664'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/6683189865433035664'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-java.html' title='What is Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-3376950495832986879</id><published>2008-12-19T21:39:00.004+05:30</published><updated>2009-08-16T01:17:42.663+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><category scheme='http://www.blogger.com/atom/ns#' term='OOPS Principles'/><title type='text'>How to create a new Object in Java</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Creating of Objects is a very easy thing, if you understand the actual processing going on at the back end. Understanding how to create a new &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; is essential for getting a good hold on the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/principle-of-oops.html"&gt;Principle of OOPS&lt;/a&gt; and Java itself. &lt;br /&gt;&lt;br /&gt;For creating a new &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; in Java, we use the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/java-keywords-and-reserved-words.html"&gt;keyword&lt;/a&gt; "new". Simple isn't it. For illustrating this concept, we create a &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;class&lt;/a&gt; called BMW, and then make a new &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; of this &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;class&lt;/a&gt; in a new &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;class&lt;/a&gt; called TestDrive. Here we will step by step understand the steps involved in creation of a new &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; and its importance on the heap. Oh! I forget to tell you, every &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; in Java lives on the heap. Every time you create a new &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; it takes some space on the heap, which must be cleared once the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; gets useless or out of reach. For this we use Garbage Collection in Java.&lt;br /&gt;&lt;br /&gt;Anyhow, here is your first &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;class&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;class BMW&lt;br /&gt;{&lt;br /&gt;String color,&lt;br /&gt;int speed;&lt;br /&gt;void showSpeed()&lt;br /&gt;{&lt;br /&gt;System.out.println("Speed is 100 miles/hr");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;class TestDrive&lt;br /&gt;{&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-reason-for-each-keyword-of.html"&gt;Public Static void main(String args[])&lt;/a&gt;&lt;br /&gt;{&lt;br /&gt;BMW b = new BMW();&lt;br /&gt;b.color = "red";&lt;br /&gt;b.showSpeed();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The above &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;class&lt;/a&gt; TestDrive when runs, it prints the output as "Speed is 100 miles/hr". In the above program, we have created a &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;class&lt;/a&gt; called BMW and in that defined its instance variables and methods. Then we have defined a seprate class called TestDrive in which we make an &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; of type BMW, we set the color of this BMW to red, and then we call the showSpeed() method, which displays the speed of the BMW.&lt;br /&gt;&lt;br /&gt;Here the "." operator in b.showSpeed() is used for calling the showSpeed function of the BMW. The main thing here is that we have created a new &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; by using the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/java-keywords-and-reserved-words.html"&gt;keyword&lt;/a&gt; "new".&lt;br /&gt;&lt;br /&gt;When we say:-&lt;br /&gt;&lt;br /&gt;BMW b = new BMW();&lt;br /&gt;&lt;br /&gt;Here there are three steps involved, they are:-&lt;br /&gt;1. Declaration of a reference variable&lt;br /&gt;2. Creation of an &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt;&lt;br /&gt;3. Assignment of the new &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; to the refernce variable.&lt;br /&gt;&lt;br /&gt;I hope you got my point. Anyhow I will explain it again. When we say:-&lt;br /&gt;&lt;br /&gt;BMW b&lt;br /&gt;&lt;br /&gt;we have just created a new refernve variable of type BMW. And then we say:-&lt;br /&gt;&lt;br /&gt;new BMW();&lt;br /&gt;&lt;br /&gt;here we have just created a new &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; of type BMW. And then we equate them by using the "=" operator.&lt;br /&gt;&lt;br /&gt;So now, we have created a new &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; and then assigned it a reference variable, and we have done this because now we can use this reference variable to perform operations on this Object. &lt;br /&gt;&lt;br /&gt;Now I am pretty sure that you have got my point. In case you like my article, do leave me a comment. For more information on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-3376950495832986879?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2008/12/how-to-create-new-object-in-java.html' title='How to create a new Object in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/3376950495832986879/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/how-to-create-new-object-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3376950495832986879'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/3376950495832986879'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/how-to-create-new-object-in-java.html' title='How to create a new Object in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-8214138804126059205</id><published>2008-12-18T22:00:00.004+05:30</published><updated>2009-08-16T01:17:16.526+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><category scheme='http://www.blogger.com/atom/ns#' term='OOPS Principles'/><title type='text'>What is an abstract Class</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. This is one of the most commonly asked interview questions. Now that we have learned &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-abstraction.html"&gt;What is Abstraction&lt;/a&gt; and &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-class.html"&gt;What is a Class&lt;/a&gt;, we are ready to learn what is an abstract class in Java. If anyone is not clear about abstraction, then I do insist that first read my previous post of &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-abstraction.html"&gt;What is Abstraction&lt;/a&gt;. This will help you in a better understanding of this concept.&lt;br /&gt;&lt;br /&gt;An abstract class in Java is one which cannot be instantiated. I know that this was bouncer for you, but this is the actual definition of abstract class. I will explain you what I mean by this. In my last article on &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-abstraction.html"&gt;What is Abstraction&lt;/a&gt;, I discussed about the Tiger Object and the abstract class called Animal. So now we are aware that the animal class is an abstract class.&lt;br /&gt;&lt;br /&gt;We know that we can create new Objects in Java using the "new" operator. So what will happen, when someone write the code as:-&lt;br /&gt;&lt;br /&gt;Animal anim = new Animal();&lt;br /&gt;&lt;br /&gt;This is the code for instantiating an Animal class, but wait, you can't define an Animal Object. It is too abstract to define it. What color it would be, what size it would be, what shape it would be. There are so many questions for that. Infact the abstract classes should never be instantiated. You can do this by writing the keyword "abstract" before the access modifier of the class. I will show you how:-&lt;br /&gt;&lt;br /&gt;abstract public class Animal&lt;br /&gt;{&lt;br /&gt; public void color()&lt;br /&gt; {&lt;br /&gt; // Your code here.&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Now the above class is declared as abstract. So whenever anyone tries to make a new Object of type Animal by saying that:-&lt;br /&gt;&lt;br /&gt;Animal anim = new Animal();&lt;br /&gt;&lt;br /&gt;The compiler will complain with the error:-&lt;br /&gt;&lt;br /&gt;Animal is abstract; cannot be instantiated&lt;br /&gt;Animal anim = new Animal();&lt;br /&gt;1 error&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you don't want your compiler to complain, you better take care of this point.&lt;br /&gt;&lt;br /&gt;Abstract classes are practically useless if not extended. By this I mean that, if you cannot create an &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; of an abstract class in Java, what good it would be for you. You cannot perform operation on the class, infact you can do nothing on that class. An abstract class is only helpful, if it is extended. Here I am taking about Inheritance, which is another strong &lt;a href = "http://javacodeonline.blogspot.com/2008/12/principle-of-oops.html"&gt;Principle of OOPS&lt;/a&gt;. Actually all the four &lt;a href = "http://javacodeonline.blogspot.com/2008/12/principle-of-oops.html"&gt;Principle of OOPS&lt;/a&gt; &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-abstraction.html"&gt;abstraction&lt;/a&gt;, encapsulation, inheritance and polymorphism work together in making Java as a very powerful tool for development of applications.&lt;br /&gt;&lt;br /&gt;So I was taking about extending an abstract class. When you extend an Abstract class, you inherit all the methods and instance variable defined in the abstract class, then on that you can perform your operations. I will discuss more on this in my article on Inheritance. For the time being just concentrate on the abstract class part. &lt;br /&gt;&lt;br /&gt;So now you are aware that an abstract class should not be instantiated, and you can avoid it by using the keyword "abstract". If you like this article then do leave a comment. For more info on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-8214138804126059205?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2008/12/what-is-abstract-class.html' title='What is an abstract Class'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/8214138804126059205/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-abstract-class.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/8214138804126059205'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/8214138804126059205'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-abstract-class.html' title='What is an abstract Class'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-4510887594316614090</id><published>2008-12-17T22:57:00.008+05:30</published><updated>2009-08-16T01:16:51.699+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><category scheme='http://www.blogger.com/atom/ns#' term='OOPS Principles'/><title type='text'>What is a Class</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Class is the most commonly thing in Java. Having a good understanding of class is essential for getting a firm grip on the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/principle-of-oops.html"&gt;Principle of OOPS&lt;/a&gt; and Java itself. A class is called the blueprint of an &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt;. Everything that is done in Java, has to be enclosed within a class.&lt;br /&gt;&lt;br /&gt;As I said before that the class is a blueprint of an &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt;, it is used for making Objects. I Java we know that everything is an &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt;, and if we don't know then we must know this. Java is built on the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/principle-of-oops.html"&gt;Principle of OOPS&lt;/a&gt; and is totally &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; Oriented. So Java see everything as an &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I will take you through a through understanding of this concept. A class is used to define a new data type, and normally a separate class is used to make Objects of this new data type. Think of a class as something which defines what an Object knows and what an &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; does. Therefore a class is also called a template for an Object and an Object is called an instance of the class. Thus a class contains the instance variables (things which an &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; knows) and methods (things which an &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; does).&lt;br /&gt;&lt;br /&gt;A class is just like a blueprint and it covers every intricate detail about the Object that will be made from it. The normal structure of class is that it defines everything about an &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt;, so suppose that your application consists of some Objects, and so you make classes for each. Now you define a main class which will initiate all the calling procedure.&lt;br /&gt;&lt;br /&gt;The main class always contain the method "main". This method tell the JVM that this is the main class and it need to start execution from here. Once in the main class, you can define Objects of other classes that you have made. I will take a simple example to clarify my point.&lt;br /&gt;&lt;br /&gt;// This program declares two Car objects.&lt;br /&gt;class Square {&lt;br /&gt;int width;&lt;br /&gt;int height;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class SquareDemo2 {&lt;br /&gt;public static void main(String args[]) {&lt;br /&gt;Square mySquare1 = new Square();&lt;br /&gt;Square mySquare2 = new Square();&lt;br /&gt;int area;&lt;br /&gt;// assign values to mySquare1's instance variables&lt;br /&gt;mySquare1.width = 10;&lt;br /&gt;mySquare1.height = 20;&lt;br /&gt;/* assign different values to mySquare2's instance variables */&lt;br /&gt;mySquare2.width = 15;&lt;br /&gt;mySquare2.height = 15;&lt;br /&gt;// compute area of first Square&lt;br /&gt;area = mySquare1.width * mySquare1.height;&lt;br /&gt;System.out.println("Area is " + area);&lt;br /&gt;// compute area of second box&lt;br /&gt;area = mySquare2.width * mySquare2.height;&lt;br /&gt;System.out.println("Area is " + area);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The first System.out.println results in:- 200&lt;br /&gt;The second System.out.println results in:- 225&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now you must be wondering about so many new things, I have shown above. I will cover each of them.&lt;br /&gt;&lt;br /&gt;Here we have defined two classes Square and SquareDemo2. The first class is used for making an &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; of type Car. The second Class uses this new data type for making new Objects. Now as told before, the execution begins from the class containing the "main" method.&lt;br /&gt;&lt;br /&gt;Now as you can see that there are two different outputs for the two Objects, this shows that both the Objects are unique and are independent of each other. Here System.out.println is used for displaying the results at the console or output screen.&lt;br /&gt;&lt;br /&gt;The lines starting with // are skipped by the Java compiler. Infact the // is the syntax for &lt;a href = "http://javacodeonline.blogspot.com/2008/12/comments-in-java.html"&gt;Comment&lt;/a&gt; in Java. These are very helpful in explaining the functioning of the code.&lt;br /&gt;&lt;br /&gt;If you have any problems with the code that I have explained right now, then do leave me a comment and I will try my best to clarify your doubt.&lt;br /&gt;&lt;br /&gt;The most important thing that you must have noticed here is the parameter "new". This is the magic keyword of Java and is used for creating new Objects. I will discuss more on creating a new &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; in my later posts. &lt;br /&gt;&lt;br /&gt;I hope the article was helpful in explaining you about What is a Class. If you like this article then do leave a comment. For more information on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-4510887594316614090?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2008/12/what-is-class.html' title='What is a Class'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/4510887594316614090/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-class.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/4510887594316614090'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/4510887594316614090'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-class.html' title='What is a Class'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-1684330802557738886</id><published>2008-12-16T22:44:00.003+05:30</published><updated>2009-08-16T01:16:26.953+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>Comments in Java</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. This is a small article on the type of comments available in Java. A comment is line in the Java Program which is not executed by the JVM. The syntax of the comment tells the JVM, that this line or these lines are not to be compiled and these lines of code need to be skipped. &lt;br /&gt;&lt;br /&gt;Comments help in Java code by making the code clearer, providing a mechanism to maintain a history in the java files, and helps the developer in understanding what the code is doing. History is helpful in telling the developer that what is this class for, and what was the last time it was updated. Comments are an essential component of Java, and must be taken into practice, if you want to make your and others life easy.&lt;br /&gt;&lt;br /&gt;Suppose that you write a code for making a dog &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt;. After around a year or so, there is a change requirement or some bug found in the code. Now you come back to the same code, but you can't remember what was the functionality of the code that you have written one year back. In this case comments help the developer remember the functioning of the code. &lt;br /&gt;&lt;br /&gt;Java has two types of comments possible in its code. They are:-&lt;br /&gt;&lt;br /&gt;1. Single line comment&lt;br /&gt;2. Multiple line comment&lt;br /&gt;&lt;br /&gt;Java provides you the option to comment a single line at a time, or to comment multiple lines at the same time.&lt;br /&gt;&lt;br /&gt;For commenting a single line, use double forward slash(//) before the line you want to comment. For example:-&lt;br /&gt;&lt;br /&gt;// The code below is for making a new Dog Object&lt;br /&gt;Dog d = new Dog();&lt;br /&gt;&lt;br /&gt;In the two lines of code written above, the first line will be skipped by the JVM, and will jump to the second line. The first line helps to tell the developer that the code below is for making a new Dog &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;There are instances when you would like to comment multiple lines at one shot. Suppose that your comments span to multiple lines, then will you proceed by putting a "//" before every line. It would be tedious, so Java provides a different mechanism for this , the syntax for commenting multiple lines of Java is:-&lt;br /&gt;&lt;br /&gt;/*  The code is below for making a Dog Object&lt;br /&gt;This code has the benefit that it simplifies the logic.&lt;br /&gt;This is a multiple line comment.&lt;br /&gt;And you are reading its syntax  */&lt;br /&gt;Dog d = new Dog();&lt;br /&gt;&lt;br /&gt;Here everything in between "/*" and  "*/" are skipped by the JVM compiler. So you can now comment multiple lines of code easily. If this article was beneficial then do leave a comment. For more info on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-1684330802557738886?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2008/12/comments-in-java.html' title='Comments in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/1684330802557738886/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/comments-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1684330802557738886'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1684330802557738886'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/comments-in-java.html' title='Comments in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-1204261417928459963</id><published>2008-12-15T21:03:00.005+05:30</published><updated>2009-08-16T01:15:58.645+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>What is Bytecode in Java</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. ByteCode is the biggest improvement in Java, when compared to other languages like C++. I will discuss what is Bytecode and why it is needed, and what is the benefit of using Bytecode in Java.&lt;br /&gt;&lt;br /&gt;Most of the languages that developers work in face two main problems. They are:-&lt;br /&gt;&lt;br /&gt;1. Security&lt;br /&gt;2. Portability&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Security&lt;/b&gt;&lt;br /&gt;We all know that, while downloading any file from anywhere on the internet, we face two major problems, they are a viral infection, that is the file may be corrupted with virus. And the second is that the file may contain a spyware, that is some malicious code in the file scans your computer for your data. No one likes that, but that's a big reality. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Portability&lt;/b&gt;&lt;br /&gt;We all want that, once we do the coding, we can easily take the output to many other platforms. But the issue is that most of the systems, don't provide compatibility to the previous code. It may be that you are coding on the windows machine and tomorrow you want to run the code on a linux machine, in that case there could be portability issues. Java has the benefit of "code once and use anywhere". I will tell you how.&lt;br /&gt;&lt;br /&gt;Java faces both of these threats by a simple means called the &lt;b&gt;Bytecode&lt;/b&gt;. Bytecode is a highly optimized code that runs only on JVM(Java Virtual Machine). The issue of virus and spyware protection is solved by making sure that, everything runs with the JVM environment, and nothing goes out of that, so there is no chance of getting the files infected by virus or spyware. JVM provides a complete shell like environment which encloses all the processing of the Java operations.&lt;br /&gt;&lt;br /&gt;The issue of portability is again resolved by using Bytecode. Bytecode is not the normal executable code, it need the JVM for its operations. So you just need to ensure that JVM is installed on the system on which you are working, and the Bytecode will run perfectly fine. So infact you may code the program once, compile it to convert it into Bytecode, and then use the Bytecode on any JVM compatible machine. So it is simply "Code once and use anywhere". That's the power of Java.&lt;br /&gt;&lt;br /&gt;The Bytecode is a highly optimized code which is understood only by the JVM. The JVM is the interpreter of the ByteCode. There could be various versions of JVM operating on various machines, but all interpret the same Bytecode, and so it provides a highly cool feature of portability.&lt;br /&gt;&lt;br /&gt;I hope that the article was beneficial in explaining you, what is Bytecode in Java, and what are it's advantages. If you liked the article then do leave a comment. For more information on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-1204261417928459963?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2008/12/what-is-bytecode-in-java.html' title='What is Bytecode in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/1204261417928459963/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-bytecode-in-java.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1204261417928459963'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1204261417928459963'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-bytecode-in-java.html' title='What is Bytecode in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-1739544391230933761</id><published>2008-12-14T17:50:00.005+05:30</published><updated>2009-09-06T02:16:03.865+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><category scheme='http://www.blogger.com/atom/ns#' term='OOPS Principles'/><title type='text'>What is Abstraction</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Abstraction is the first Principle of OOPS and one of the core concepts of Java. First of all if you really want to get a hold on the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/principle-of-oops.html"&gt;Principle of OOPS&lt;/a&gt; and gain a strong understanding on the concepts of Java, then forget everything you have read about Abstraction and start from scratch. Trust me, you won't be disappointed.&lt;br /&gt;&lt;br /&gt;Abstraction in laymen term means taking out the common things. First of all concentrate on the word Abstraction, it comes from the word "Abstract". Here you abstract the most common features of an &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; and place them in a separate class. I will take some real life examples to make your life more easy.&lt;br /&gt;&lt;br /&gt;Suppose that you need to make an &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; of Tiger type. I mean to say that, you need a class for making a Tiger. Now just think that, what does a Tiger "do", and what does a Tiger "know". The stress her is on the words "do" and "know", because whatever the Tiger "do" are its methods and whatever the Tiger "knows" are its instance variables.&lt;br /&gt;&lt;br /&gt;Now we know that every Tiger has a some basic properties like hunger, location, color, etc. These are the instance variables of Tiger. And every Tiger "does" some basic things like makes noise, eat, sleep, roam around, etc. &lt;br /&gt;&lt;br /&gt;Now if we have to make only Tiger Objects then a class for Tiger is ok. But what if we need to add other animals too, like cat, dog, wolf etc. Will you write a seprate class for every animal, knowing that every animal has the same basic properties. Won't it be a waste of energy and time, rewriting the same methods again for every animal.&lt;br /&gt;&lt;br /&gt;Here is where Abstraction comes into picture. In abstraction, what you do is take out the common instance variables and methods, so that you need not write them again, you write the basic methods and instance variables in a single abstract class, and then you "extend" other classes from it depending upon their behavior. And just by magic all the methods and instance variables in the abstract class are available to the "extended" classes. The part of extending a class is called Inheritance and is the second &lt;a href = "http://javacodeonline.blogspot.com/2008/12/principle-of-oops.html"&gt;Principle of OOPS&lt;/a&gt;, I will discuss it in my later posts. For the time being just concentrate on the word Abstraction.&lt;br /&gt;&lt;br /&gt;So now for the Tiger class, we make a parent abstract class called Animal. We know that all the animals have more or less the same features. So we write the instance variables like color, hunger, location, etc. into the abstract class. And also we define the methods common to all the animals like makeNoise(), eat(),&lt;br /&gt;roam(), sleep(), etc. and then use these methods and instance variables in the child classes. So now even a wolf, cat and dog can use the code of the abstract animal class, and no need to rewrite the code again for them.&lt;br /&gt;&lt;br /&gt;So in technical terms Abstraction is taking out the common code from similar classes and placing it in one particular class, so that it could be used by all the classes using the same functionality. It helps in code reusability, makes the code clearer and better to read and interpret, and most of all makes your life easy.&lt;br /&gt;&lt;br /&gt;I hope that I was able to keep my word in explaining you about what is Abstraction. If you liked the article then do leave a comment. For more info on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Related Articles&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2008/12/principle-of-oops.html"&gt;Principle of OOPS&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2009/02/why-do-we-need-abstraction.html"&gt;Advantage of Abstraction&lt;/a&gt;&lt;br /&gt;&lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;What is Object&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-1739544391230933761?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2008/12/what-is-abstraction.html' title='What is Abstraction'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/1739544391230933761/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-abstraction.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1739544391230933761'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/1739544391230933761'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-abstraction.html' title='What is Abstraction'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3416407328338427543.post-9029853901539016926</id><published>2008-12-13T23:38:00.003+05:30</published><updated>2009-08-16T01:14:58.529+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>What is an identifier in Java</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Java is a very powerful language. The power in it comes from the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/principle-of-oops.html"&gt;Principle of OOPS&lt;/a&gt; that it follows. Identifiers in Java are used for naming a variable, method, class or label. I will cover each of these topics in detail, in my later posts. For the time being just concentrate on the word identifier.&lt;br /&gt;&lt;br /&gt;Identifiers are required by Java, so that you may give your variable a name. Though as seen above it is also used for naming method, class and label. There are some rules that need to be followed, while naming an identifier.&lt;br /&gt;&lt;br /&gt;The rules for naming an identifier are simple and must be practiced thoroughly, if you don't want your JVM to shout that it cant compile the class. The rules for naming an identifier are:-&lt;br /&gt;&lt;br /&gt;1. An identifier in Java can start with a letter.&lt;br /&gt;2. An identifier in Java can start with a dollar sign($)&lt;br /&gt;3. An identifier in Java can start with an underscore(_) &lt;br /&gt;4. Subsequent characters in the identifier after the first character can be letters, dollar sign, underscore, or a digit.&lt;br /&gt;&lt;br /&gt;Any other rule for identifiers is not there, so just stick to these basic four rules and you won't face any problem in compilation of your code.&lt;br /&gt;&lt;br /&gt;I will take a few examples so as to make the situation more clear to you.&lt;br /&gt;&lt;br /&gt;companyName  //legal&lt;br /&gt;BigClass  //legal: you may embed the keywords in between&lt;br /&gt;$money   //legal&lt;br /&gt;8_node   //illegal(Cannot start with a digit)&lt;br /&gt;!node   //illegal(special characters not allowed in starting except "$" and "_")&lt;br /&gt;&lt;br /&gt;Now you would be able to clearly distinguish, which one is a valid identifier and which one is not. Having good understating of these basic concepts of Java help make the life of the developer easy, as he faces less errors. The life of a developer is already very hard, faced with coding requirements, meeting deadline, and debugging bugs.&lt;br /&gt;&lt;br /&gt;So it would be good to avoid small pitfalls like naming an identifier. I hope the article was handy for all those looking for information on Identifiers in Java. If you like the article then do leave a comment. For more info on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-9029853901539016926?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2008/12/what-is-identifier-in-java.html' title='What is an identifier in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/9029853901539016926/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-identifier-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/9029853901539016926'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/9029853901539016926'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-identifier-in-java.html' title='What is an identifier in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-247123693961122127</id><published>2008-12-12T23:00:00.004+05:30</published><updated>2009-08-16T01:14:31.104+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>What is the purpose of garbage collection in Java</title><content type='html'>Welcome back to Java Code Online&lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. The garbage collector is one of the best things in Java. In Java every &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; lives on a heap. Heap is the play area of Objects. Whenever we create Objects, some area on the heap is allocated to this new &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt;. But what will happen, when this &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; is of no use. &lt;br /&gt;&lt;br /&gt;I mean to say that, when the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; refers nothing, then it consumes unnecessary space on the heap, which must be freed. This space could be used by other &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Objects&lt;/a&gt;, and also helps the JVM in speeding up the operations of processing.&lt;br /&gt;&lt;br /&gt;This is where the garbage collector comes into picture. The Garbage collector in Java, checks at regular intervals about the Objects that are no more referenced by any variable. These Objects are eligible for Garbage collection. Garbage Collector checks for the Objects that are unreachable for the program, and so are consuming unnecessary space, so Garbage Collector considers these Objects as Garbage, and so it collects them. Thereby freeing space on the heap.&lt;br /&gt;&lt;br /&gt;For example, if I say that:-&lt;br /&gt;&lt;br /&gt;Object a = new Object();&lt;br /&gt;&lt;br /&gt; This line of code allots space on the heap for the new &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt;. But suppose that later in the code, we say that:-&lt;br /&gt;&lt;br /&gt; a = null;&lt;br /&gt;&lt;br /&gt; This statement will cause the reference of this &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; to refer null, and so the &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; is lost in the heap and is now unreachable. This &lt;a href = "http://javacodeonline.blogspot.com/2008/12/what-is-object.html"&gt;Object&lt;/a&gt; is now eligible for Garbage collection, so that space could be freed on the heap. This space helps the JVM in performing better and faster.&lt;br /&gt;&lt;br /&gt; I hope that this article was helpful in explaining you the role of Garbage Collector in Java. If you liked this article, then do leave a comment. For more information on Java, keep buzzing &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3416407328338427543-247123693961122127?l=javacodeonline.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://javacodeonline.blogspot.com/2008/12/what-is-purpose-of-garbage-collection.html' title='What is the purpose of garbage collection in Java'/><link rel='replies' type='application/atom+xml' href='http://javacodeonline.blogspot.com/feeds/247123693961122127/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-purpose-of-garbage-collection.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/247123693961122127'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3416407328338427543/posts/default/247123693961122127'/><link rel='alternate' type='text/html' href='http://javacodeonline.blogspot.com/2008/12/what-is-purpose-of-garbage-collection.html' title='What is the purpose of garbage collection in Java'/><author><name>amitberiwal</name><uri>http://www.blogger.com/profile/10392899541218382481</uri><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-3416407328338427543.post-4252973333424867242</id><published>2008-12-11T22:43:00.003+05:30</published><updated>2009-08-16T01:14:06.604+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Basics'/><title type='text'>Java Keywords and Reserved Words</title><content type='html'>Welcome back to &lt;a href = "http://javacodeonline.blogspot.com/"&gt;Java Code Online&lt;/a&gt;. Java keywords are those which are defined by the programming language. These keywords are used by programmers to code easily. You cannot use keywords in place of variable names, that is not allowed.&lt;br /&gt;&lt;br /&gt;Reserved words in Java are actually words which are reserved by the programming language. It might be, that the meaning of these keywords is not defined by the compiler but they are reserved. So you cannot use these also for your variable names in Java.&lt;br /&gt;&lt;br /&gt;A list of Java Keywords and Reserved Words is given below. This list is correct as per the Tiger version of Java, that is Java 2.&lt;br /&gt;&lt;br /&gt;List of Keywords and Reserved Words in Java:-&lt;br /&gt;1. abstract&lt;br /&gt;2. class&lt;br /&gt;3. extends&lt;br /&gt;4. implements&lt;br /&gt;5. null&lt;br /&gt;6. strictfp&lt;br /&gt;7. true&lt;br /&gt;8. assert&lt;br /&gt;9. const&lt;br /&gt;10. false&lt;br /&gt;11. import&lt;br /&gt;12. package&lt;br /&gt;13. super&lt;br /&gt;14. try&lt;br /&gt;15. boolean&lt;br /&gt;16. continue&lt;br /&gt;17. final&lt;br /&gt;18. instanceof&lt;br /&gt;19. private&lt;br /&gt;20. switch&lt;br /&gt;21. void&lt;br /&gt;22. break&lt;br /&gt;23. default&lt;br /&gt;24. finally&lt;br /&gt;25. int&lt;br /&gt;26. pr
