<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title><![CDATA[Java Programming Forums - The Java Community - Blogs - JD1's Personal Development Blog by OA-OD-JD1]]></title>
		<link>http://www.javaprogrammingforums.com/blogs/oa-od-jd1/</link>
		<description>The Java Programming Forums are a community of Java programmers from all around the World. Join us now to solve all your Java problems!</description>
		<language>en</language>
		<lastBuildDate>Mon, 20 May 2013 06:09:40 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://www.javaprogrammingforums.com/images/misc/rss.jpg</url>
			<title><![CDATA[Java Programming Forums - The Java Community - Blogs - JD1's Personal Development Blog by OA-OD-JD1]]></title>
			<link>http://www.javaprogrammingforums.com/blogs/oa-od-jd1/</link>
		</image>
		<item>
			<title>Enhanced For Statement - JavaDevelopmentForums.com</title>
			<link>http://www.javaprogrammingforums.com/blogs/oa-od-jd1/62-enhanced-statement-javadevelopmentforums-com.html</link>
			<pubDate>Sun, 29 Jan 2012 22:08:01 GMT</pubDate>
			<description><![CDATA[When working with arrays, there's an easier way to loop through the indices than manually doing so. We can use the enhanced for statement for this. 
...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">When working with arrays, there's an easier way to loop through the indices than manually doing so. We can use the enhanced for statement for this.<br />
<br />
<div class="bbcode_container">
                
<div class="bbcode_description" style="height:24px; background-image: url('http://www.javaprogrammingforums.com/images/javacode2.png'); background-repeat: no-repeat; margin-bottom:0px"></div>

<div class="bbcode_code" style="height:144px;"><div class="java" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7F0055; font-weight: bold;">class</span> Class1<span style="color: #000000;">&#123;</span>
   <span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">static</span> <span style="color: #7F0055; font-weight: bold;">void</span> main<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
	   <span style="color: #000066; font-weight: bold;">int</span> aryOne<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">=</span> <span style="color: #000000;">&#123;</span><span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">4</span>,<span style="color: #cc66cc;">5</span>,<span style="color: #cc66cc;">6</span>,<span style="color: #cc66cc;">7</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">;</span>
	   <span style="color: #000066; font-weight: bold;">int</span> total <span style="color: #000000;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #000000;">;</span>
	   <span style="color: #7F0055; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> x<span style="color: #000000;">:</span> aryOne<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		   total <span style="color: #000000;">+=</span> x<span style="color: #000000;">;</span>
	   <span style="color: #000000;">&#125;</span>
	   <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span>total<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</div> <br />
First of all, we create our array (aryOne) and use an array initialiser to give it some values. We then create a total variable which is going to store the sum of these values. Next, we create a for statement containing firstly type and identifier (int x). Using a colon, we set this equal to the name of the array we're working with (aryOne). What this does is loops all the indices in the array and for each iteration, the current index is stored in x. We add them together like so: <b>total += x;</b>. Too easy.<br />
<br />
<a href="http://javadevelopmentforums.com/" target="_blank">http://javadevelopmentforums.com/</a></blockquote>

]]></content:encoded>
			<dc:creator>OA-OD-JD1</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/blogs/oa-od-jd1/62-enhanced-statement-javadevelopmentforums-com.html</guid>
		</item>
		<item>
			<title>Array Elements As Counters - JavaDevelopmentForums.com</title>
			<link>http://www.javaprogrammingforums.com/blogs/oa-od-jd1/61-array-elements-counters-javadevelopmentforums-com.html</link>
			<pubDate>Sun, 29 Jan 2012 22:07:23 GMT</pubDate>
			<description><![CDATA[We're going to build a program to re-enact a dice being rolled one thousand times. We're going to output how many times each face of the dice is...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">We're going to build a program to re-enact a dice being rolled one thousand times. We're going to output how many times each face of the dice is rolled.<br />
<br />
<div class="bbcode_container">
                
<div class="bbcode_description" style="height:24px; background-image: url('http://www.javaprogrammingforums.com/images/javacode2.png'); background-repeat: no-repeat; margin-bottom:0px"></div>

<div class="bbcode_code" style="height:216px;"><div class="java" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7F0055; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Random</span><span style="color: #000000;">;</span>
&nbsp;
<span style="color: #7F0055; font-weight: bold;">class</span> RollDice<span style="color: #000000;">&#123;</span>
   <span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">static</span> <span style="color: #7F0055; font-weight: bold;">void</span> main<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
	   <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arandom+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Random</span></a> rand <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arandom+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Random</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
	   <span style="color: #000066; font-weight: bold;">int</span> freq<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #000000;">&#91;</span><span style="color: #cc66cc;">7</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">;</span>
&nbsp;
	   <span style="color: #7F0055; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> roll <span style="color: #000000;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #000000;">;</span> roll <span style="color: #000000;">&lt;=</span> <span style="color: #cc66cc;">1000</span><span style="color: #000000;">;</span> roll<span style="color: #000000;">++</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		   <span style="color: #000000;">++</span>freq<span style="color: #000000;">&#91;</span><span style="color: #cc66cc;">1</span> <span style="color: #000000;">+</span> rand.<span style="color: #000000;">nextInt</span><span style="color: #000000;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">;</span>
	   <span style="color: #000000;">&#125;</span>
	   <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">&quot;Face<span style="color: #000099; font-weight: bold;">\t</span>Frequency&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
	   <span style="color: #7F0055; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> face <span style="color: #000000;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #000000;">;</span> face <span style="color: #000000;">&lt;</span> freq.<span style="color: #000000;">length</span><span style="color: #000000;">;</span> face<span style="color: #000000;">++</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		   <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span>face <span style="color: #000000;">+</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> <span style="color: #000000;">+</span> freq<span style="color: #000000;">&#91;</span>face<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
	   <span style="color: #000000;">&#125;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</div> <br />
First of all, we have to import our random class. Then, we create a new random number object called <b>rand</b>. We create a new integer array called <b>freq</b>. We set this equal to 7 because we want the numbers 1-6. 7 Will give us 0-6 but we'll just ignore the zero.<br />
<br />
Next up is our for loop set to iterate one thousand times. In that we increment the index of our frequency array by a random number ranging from 1 through to 6. This line of code stores the values of each face of the die.<br />
<br />
We then output a header (face and frequency) separated by a tab and create a small for loop to output the face and value of each face. This is really just six iterations.<br />
<br />
<a href="http://javadevelopmentforums.com/" target="_blank">Java Development Forums</a></blockquote>

]]></content:encoded>
			<dc:creator>OA-OD-JD1</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/blogs/oa-od-jd1/61-array-elements-counters-javadevelopmentforums-com.html</guid>
		</item>
		<item>
			<title>Summing The Elements of An Array</title>
			<link>http://www.javaprogrammingforums.com/blogs/oa-od-jd1/60-summing-elements-array.html</link>
			<pubDate>Sun, 29 Jan 2012 22:02:01 GMT</pubDate>
			<description>Say we have an array with ten indices. Below is how we can calculate the sum of these indices. 
 
class Class1{ 
	public static void main(String...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">Say we have an array with ten indices. Below is how we can calculate the sum of these indices.<br />
<br />
<div class="bbcode_container">
                
<div class="bbcode_description" style="height:24px; background-image: url('http://www.javaprogrammingforums.com/images/javacode2.png'); background-repeat: no-repeat; margin-bottom:0px"></div>

<div class="bbcode_code" style="height:180px;"><div class="java" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7F0055; font-weight: bold;">class</span> Class1<span style="color: #000000;">&#123;</span>
	<span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">static</span> <span style="color: #7F0055; font-weight: bold;">void</span> main<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> array1 <span style="color: #000000;">=</span> <span style="color: #000000;">&#123;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">2</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">4</span>,<span style="color: #cc66cc;">5</span>,<span style="color: #cc66cc;">6</span>,<span style="color: #cc66cc;">7</span>,<span style="color: #cc66cc;">8</span>,<span style="color: #cc66cc;">9</span>,<span style="color: #cc66cc;">10</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> total <span style="color: #000000;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #000000;">;</span>
&nbsp;
		<span style="color: #7F0055; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> counter <span style="color: #000000;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #000000;">;</span> counter <span style="color: #000000;">&lt;</span> array1.<span style="color: #000000;">length</span><span style="color: #000000;">;</span> counter<span style="color: #000000;">++</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
			total <span style="color: #000000;">+=</span> array1<span style="color: #000000;">&#91;</span>counter<span style="color: #000000;">&#93;</span><span style="color: #000000;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">&quot;Total<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> <span style="color: #000000;">+</span> total<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</div> <br />
Firstly, initialise your array. Then, create a variable to store the total. A simple <b>For Loop </b>set to iterate to the length of our array will do the trick. All you need to do is set the total to the total plus the array with the index if the current counter. A very simple concept.<br />
<br />
In an unrelated topic, I'm now up to my 30th Java tutorial. I'm making some nice leadway here, though I've still got a heck of a lot to learn.</blockquote>

]]></content:encoded>
			<dc:creator>OA-OD-JD1</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/blogs/oa-od-jd1/60-summing-elements-array.html</guid>
		</item>
		<item>
			<title>Arrays</title>
			<link>http://www.javaprogrammingforums.com/blogs/oa-od-jd1/59-arrays.html</link>
			<pubDate>Sun, 29 Jan 2012 22:01:00 GMT</pubDate>
			<description>Arrays are used to store many values under the one variable, so to speak. You can initialise an array the long and drawn out way by manually...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">Arrays are used to store many values under the one variable, so to speak. You can initialise an array the long and drawn out way by manually assigning each index a value or you can implement an array initialiser to do the job for you.<br />
<br />
<div class="bbcode_container">
                
<div class="bbcode_description" style="height:24px; background-image: url('http://www.javaprogrammingforums.com/images/javacode2.png'); background-repeat: no-repeat; margin-bottom:0px"></div>

<div class="bbcode_code" style="height:180px;"><div class="java" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7F0055; font-weight: bold;">class</span> Class1<span style="color: #000000;">&#123;</span>
	<span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">static</span> <span style="color: #7F0055; font-weight: bold;">void</span> main<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> array1<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #000000;">&#91;</span><span style="color: #cc66cc;">10</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">;</span>
		array1<span style="color: #000000;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">=</span> <span style="color: #cc66cc;">87</span><span style="color: #000000;">;</span>
		array1<span style="color: #000000;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">=</span> <span style="color: #cc66cc;">543</span><span style="color: #000000;">;</span>
		array1<span style="color: #000000;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">=</span> <span style="color: #cc66cc;">65</span><span style="color: #000000;">;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span>array1<span style="color: #000000;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">int</span> array2<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">=</span> <span style="color: #000000;">&#123;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">2</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">4</span>,<span style="color: #cc66cc;">5</span>,<span style="color: #cc66cc;">6</span>,<span style="color: #cc66cc;">7</span>,<span style="color: #cc66cc;">8</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span>array2<span style="color: #000000;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</div> <br />
In this example, <b>array1 </b>is the slow way, and <b>array2 </b>makes use of an array initialiser. To build an array, you must first create the variable. You do this by typing the data type (int) followed by the array name (array1) and then add two square brackets ([]) to show that we're working with an array. Set this equal to a new int (if that is the chosen data type) followed by the number of indices in square brackets. That's the slow way of course.<br />
<br />
You can use an array initialiser as follows. <b>Data Type arrayName[] = {index1, index2, index3, etc};</b>. That's a much easier was of going about building an array.</blockquote>

]]></content:encoded>
			<dc:creator>OA-OD-JD1</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/blogs/oa-od-jd1/59-arrays.html</guid>
		</item>
		<item>
			<title>Random Number Generator</title>
			<link>http://www.javaprogrammingforums.com/blogs/oa-od-jd1/58-random-number-generator.html</link>
			<pubDate>Sun, 29 Jan 2012 22:00:35 GMT</pubDate>
			<description><![CDATA[Random numbers can be used in Java. Here's a small random number generator and how it works. 
 
import java.util.Random; 
class Class1{ 
	public...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">Random numbers can be used in Java. Here's a small random number generator and how it works.<br />
<br />
<div class="bbcode_container">
                
<div class="bbcode_description" style="height:24px; background-image: url('http://www.javaprogrammingforums.com/images/javacode2.png'); background-repeat: no-repeat; margin-bottom:0px"></div>

<div class="bbcode_code" style="height:168px;"><div class="java" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7F0055; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Random</span><span style="color: #000000;">;</span>
<span style="color: #7F0055; font-weight: bold;">class</span> Class1<span style="color: #000000;">&#123;</span>
	<span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">static</span> <span style="color: #7F0055; font-weight: bold;">void</span> main<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arandom+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Random</span></a> dice <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arandom+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Random</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> number<span style="color: #000000;">;</span>
&nbsp;
		<span style="color: #7F0055; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> counter <span style="color: #000000;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #000000;">;</span> counter <span style="color: #000000;">&lt;=</span> <span style="color: #cc66cc;">10</span><span style="color: #000000;">;</span> counter<span style="color: #000000;">++</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
			number <span style="color: #000000;">=</span> dice.<span style="color: #000000;">nextInt</span><span style="color: #000000;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #000000;">;</span>
			<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span>number<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</div> <br />
First of all, we need to import the random class. Type <b>import java.util.Random;</b> at the top of your code. We then created an object to use this random numer and we named it <b>dice</b>. We made an integer named <b>number</b> to store this value. We then created a loop iterating ten times and each time it did we assigned <b>number</b> a new random number using our <b>dice </b>object. We did this by typing <b>dice.nextInt(6) + 1;</b>. The reason we've added one to the output is to prevent us from receiving numbers 0-5. We want numbers 1-6, so we simply add one to the output.</blockquote>

]]></content:encoded>
			<dc:creator>OA-OD-JD1</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/blogs/oa-od-jd1/58-random-number-generator.html</guid>
		</item>
		<item>
			<title>Math Class Methods</title>
			<link>http://www.javaprogrammingforums.com/blogs/oa-od-jd1/57-math-class-methods.html</link>
			<pubDate>Sun, 29 Jan 2012 22:00:10 GMT</pubDate>
			<description>There are many built in methods we can use to conduct mathematical operations to numbers. Here are some of them. 
 
class Class1{ 
	public static...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">There are many built in methods we can use to conduct mathematical operations to numbers. Here are some of them.<br />
<br />
<div class="bbcode_container">
                
<div class="bbcode_description" style="height:24px; background-image: url('http://www.javaprogrammingforums.com/images/javacode2.png'); background-repeat: no-repeat; margin-bottom:0px"></div>

<div class="bbcode_code" style="height:240px;"><div class="java" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7F0055; font-weight: bold;">class</span> Class1<span style="color: #000000;">&#123;</span>
	<span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">static</span> <span style="color: #7F0055; font-weight: bold;">void</span> main<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		<span style="color: #3F7F5F; font-style: italic;">//How far number is from zero.</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amath+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Math</span></a>.<span style="color: #000000;">abs</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">-</span><span style="color: #cc66cc;">26.7</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		<span style="color: #3F7F5F; font-style: italic;">//Rounds number up.</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amath+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Math</span></a>.<span style="color: #000000;">ceil</span><span style="color: #000000;">&#40;</span><span style="color: #cc66cc;">7.4</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		<span style="color: #3F7F5F; font-style: italic;">//Rounds number down.</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amath+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Math</span></a>.<span style="color: #000000;">floor</span><span style="color: #000000;">&#40;</span><span style="color: #cc66cc;">7.8</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		<span style="color: #3F7F5F; font-style: italic;">//Greater of the two numbers.</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amath+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Math</span></a>.<span style="color: #000000;">max</span><span style="color: #000000;">&#40;</span><span style="color: #cc66cc;">8.6</span>, <span style="color: #cc66cc;">5.2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		<span style="color: #3F7F5F; font-style: italic;">//Smaller of the two numbers.</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amath+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Math</span></a>.<span style="color: #000000;">min</span><span style="color: #000000;">&#40;</span><span style="color: #cc66cc;">8.6</span>, <span style="color: #cc66cc;">5.2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		<span style="color: #3F7F5F; font-style: italic;">//First number to the power of the second number.</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amath+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Math</span></a>.<span style="color: #000000;">pow</span><span style="color: #000000;">&#40;</span><span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">3</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		<span style="color: #3F7F5F; font-style: italic;">//Square root of the number.</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amath+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Math</span></a>.<span style="color: #000000;">sqrt</span><span style="color: #000000;">&#40;</span><span style="color: #cc66cc;">9</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</div> <br />
All pretty self explanatory.</blockquote>

]]></content:encoded>
			<dc:creator>OA-OD-JD1</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/blogs/oa-od-jd1/57-math-class-methods.html</guid>
		</item>
		<item>
			<title>Do While Loop</title>
			<link>http://www.javaprogrammingforums.com/blogs/oa-od-jd1/56-do-while-loop.html</link>
			<pubDate>Sun, 29 Jan 2012 21:58:06 GMT</pubDate>
			<description>We use the Do While Loop when we want to run a set of instructions before testing to see if a condition is true. The difference between a Do While...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">We use the Do While Loop when we want to run a set of instructions before testing to see if a condition is true. The difference between a Do While Loop and a While Loop is that the While Loop tests the condition first and then runs the instructions.<br />
<br />
<div class="bbcode_container">
                
<div class="bbcode_description" style="height:24px; background-image: url('http://www.javaprogrammingforums.com/images/javacode2.png'); background-repeat: no-repeat; margin-bottom:0px"></div>

<div class="bbcode_code" style="height:132px;"><div class="java" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7F0055; font-weight: bold;">class</span> Class1<span style="color: #000000;">&#123;</span>
	<span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">static</span> <span style="color: #7F0055; font-weight: bold;">void</span> main<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> counter <span style="color: #000000;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #000000;">;</span>
		<span style="color: #7F0055; font-weight: bold;">do</span><span style="color: #000000;">&#123;</span>
			<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span>counter<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
			counter<span style="color: #000000;">++;</span>
		<span style="color: #000000;">&#125;</span><span style="color: #7F0055; font-weight: bold;">while</span><span style="color: #000000;">&#40;</span>counter <span style="color: #000000;">&lt;=</span> <span style="color: #cc66cc;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</div> <br />
We have a counter initialised to zero. It's going to then output the counter as zero and then increment it by 1. It then checks to see if the while section will permit it to iterate again.<br />
<br />
If our counter had been initialised to 50, it would output 50 and then end, because the while section sees that the counter isn't actually &lt;= 10.<br />
<br />
The only perameter used in the while part is when you want it to iterate. In this case it's while the counter is less than or equal to 10. Simple enough?</blockquote>

]]></content:encoded>
			<dc:creator>OA-OD-JD1</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/blogs/oa-od-jd1/56-do-while-loop.html</guid>
		</item>
		<item>
			<title>Compound Interest Calculator</title>
			<link>http://www.javaprogrammingforums.com/blogs/oa-od-jd1/55-compound-interest-calculator.html</link>
			<pubDate>Sun, 29 Jan 2012 21:57:47 GMT</pubDate>
			<description>Compound interest can be calculated with the following formula. 
 
A = Amount 
P = Principal 
R = Rate 
n = Years 
 
*A=P(1+R)^n* 
 
We can calculate...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">Compound interest can be calculated with the following formula.<br />
<br />
A = Amount<br />
P = Principal<br />
R = Rate<br />
n = Years<br />
<br />
<b>A=P(1+R)^n</b><br />
<br />
We can calculate the amount in Java as shown below. We currently know the principal (10,000) and the rate (1%). The years can change depending on how much information we want. In this application, we'll just use 20.<br />
<br />
<div class="bbcode_container">
                
<div class="bbcode_description" style="height:24px; background-image: url('http://www.javaprogrammingforums.com/images/javacode2.png'); background-repeat: no-repeat; margin-bottom:0px"></div>

<div class="bbcode_code" style="height:168px;"><div class="java" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7F0055; font-weight: bold;">class</span> Class1<span style="color: #000000;">&#123;</span>
	<span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">static</span> <span style="color: #7F0055; font-weight: bold;">void</span> main<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">double</span> amount<span style="color: #000000;">;</span>
		<span style="color: #000066; font-weight: bold;">double</span> principal <span style="color: #000000;">=</span> <span style="color: #cc66cc;">10000</span><span style="color: #000000;">;</span>
		<span style="color: #000066; font-weight: bold;">double</span> rate <span style="color: #000000;">=</span> .01<span style="color: #000000;">;</span>
&nbsp;
		<span style="color: #7F0055; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> year <span style="color: #000000;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #000000;">;</span> year <span style="color: #000000;">&lt;=</span> <span style="color: #cc66cc;">20</span><span style="color: #000000;">;</span> year<span style="color: #000000;">++</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
			amount <span style="color: #000000;">=</span> principal <span style="color: #000000;">*</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amath+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Math</span></a>.<span style="color: #000000;">pow</span><span style="color: #000000;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #000000;">+</span> rate, year<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
			<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span>year <span style="color: #000000;">+</span> <span style="color: #0000ff;">&quot;  &quot;</span> <span style="color: #000000;">+</span> amount<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</div> <br />
We initialise our variables as per usual. We then construct a For Loop which will give us 20 iterations. Using our formula, we calculate the <b>amount</b>. We used the <b>Math.pow</b> function because it allows us to use indices. The first parameter is what you want in the parentheses and the second parameter is what you want the power to be. Quite a simple calculator.</blockquote>

]]></content:encoded>
			<dc:creator>OA-OD-JD1</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/blogs/oa-od-jd1/55-compound-interest-calculator.html</guid>
		</item>
		<item>
			<title>For Loops</title>
			<link>http://www.javaprogrammingforums.com/blogs/oa-od-jd1/54-loops.html</link>
			<pubDate>Sun, 29 Jan 2012 21:57:29 GMT</pubDate>
			<description><![CDATA[The For Loop is probably the most common loop used in any programming language. Here's how it works in Java. 
 
 
class Class1{ 
	public static void...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">The For Loop is probably the most common loop used in any programming language. Here's how it works in Java.<br />
<br />
<div class="bbcode_container">
                
<div class="bbcode_description" style="height:24px; background-image: url('http://www.javaprogrammingforums.com/images/javacode2.png'); background-repeat: no-repeat; margin-bottom:0px"></div>

<div class="bbcode_code" style="height:108px;"><div class="java" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7F0055; font-weight: bold;">class</span> Class1<span style="color: #000000;">&#123;</span>
	<span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">static</span> <span style="color: #7F0055; font-weight: bold;">void</span> main<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		<span style="color: #7F0055; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> counter<span style="color: #000000;">=</span><span style="color: #cc66cc;">1</span><span style="color: #000000;">;</span> counter<span style="color: #000000;">&lt;=</span><span style="color: #cc66cc;">10</span><span style="color: #000000;">;</span> counter<span style="color: #000000;">++</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
			<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span>counter<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</div> <br />
The For Loop takes three arguments: where you want it to start, where you want it to end, and how you'd like to increment the counter. Take a look at the below For Loop setup.<br />
<br />
<b>for(int counter=1; counter&lt;=10; counter++)</b><br />
<br />
What this is saying is that it's going to start at 1. It's going to keep running until it reaches 11 (that's ten iterations). And it's going to increment the counter by one each time. Pretty simple.</blockquote>

]]></content:encoded>
			<dc:creator>OA-OD-JD1</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/blogs/oa-od-jd1/54-loops.html</guid>
		</item>
		<item>
			<title>Simple Averaging Program</title>
			<link>http://www.javaprogrammingforums.com/blogs/oa-od-jd1/53-simple-averaging-program.html</link>
			<pubDate>Sun, 29 Jan 2012 21:56:18 GMT</pubDate>
			<description>What this application does is collects a number of inputs from the user via a scanner. These inputs are numbers. They are then averaged and the...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">What this application does is collects a number of inputs from the user via a scanner. These inputs are numbers. They are then averaged and the average is outputted. Pretty simple stuff.<br />
<br />
<div class="bbcode_container">
                
<div class="bbcode_description" style="height:24px; background-image: url('http://www.javaprogrammingforums.com/images/javacode2.png'); background-repeat: no-repeat; margin-bottom:0px"></div>

<div class="bbcode_code" style="height:264px;"><div class="java" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7F0055; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Scanner</span><span style="color: #000000;">;</span>
<span style="color: #7F0055; font-weight: bold;">class</span> Class1<span style="color: #000000;">&#123;</span>
	<span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">static</span> <span style="color: #7F0055; font-weight: bold;">void</span> main<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		Scanner input <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> Scanner<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">in</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> total <span style="color: #000000;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #000000;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> grade<span style="color: #000000;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> average<span style="color: #000000;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> counter <span style="color: #000000;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #000000;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> numGrades <span style="color: #000000;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #000000;">;</span>
&nbsp;
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">&quot;Please enter &quot;</span> <span style="color: #000000;">+</span> numGrades <span style="color: #000000;">+</span> <span style="color: #0000ff;">&quot; numbers to be averaged&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		<span style="color: #7F0055; font-weight: bold;">while</span><span style="color: #000000;">&#40;</span>counter <span style="color: #000000;">&lt;</span> numGrades<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
			grade <span style="color: #000000;">=</span> input.<span style="color: #000000;">nextInt</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
			total <span style="color: #000000;">=</span> total <span style="color: #000000;">+</span> grade<span style="color: #000000;">;</span>
			counter<span style="color: #000000;">++;</span>
		<span style="color: #000000;">&#125;</span>
		average <span style="color: #000000;">=</span> total<span style="color: #000000;">/</span>numGrades<span style="color: #000000;">;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">&quot;Your average is &quot;</span> <span style="color: #000000;">+</span> average <span style="color: #000000;">+</span> <span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</div> <br />
How could I change this to make it more challenging to create? I could have used multiple classes or multiple methods to do various tasks. For example, one method could be used to loop through the inputs, and another could be used to find the average. In fact, I'm going to do this now. Check it out.<br />
<br />
<div class="bbcode_container">
                
<div class="bbcode_description" style="height:24px; background-image: url('http://www.javaprogrammingforums.com/images/javacode2.png'); background-repeat: no-repeat; margin-bottom:0px"></div>

<div class="bbcode_code" style="height:336px;"><div class="java" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7F0055; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Scanner</span><span style="color: #000000;">;</span>
<span style="color: #7F0055; font-weight: bold;">class</span> Class1<span style="color: #000000;">&#123;</span>
	<span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">static</span> <span style="color: #7F0055; font-weight: bold;">void</span> main<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> numGrades <span style="color: #000000;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #000000;">;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">&quot;Please enter &quot;</span> <span style="color: #000000;">+</span> numGrades <span style="color: #000000;">+</span> <span style="color: #0000ff;">&quot; numbers to be averaged&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		<span style="color: #3F7F5F; font-style: italic;">//Start loop/average method</span>
		Class1 class1Object <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> Class1<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		class1Object.<span style="color: #000000;">loopAverage</span><span style="color: #000000;">&#40;</span>numGrades<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">void</span> loopAverage<span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> numGrades<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> grade<span style="color: #000000;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> counter <span style="color: #000000;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #000000;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">int</span> total <span style="color: #000000;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #000000;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> average<span style="color: #000000;">;</span>
		Scanner input <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> Scanner<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">in</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
		<span style="color: #7F0055; font-weight: bold;">while</span><span style="color: #000000;">&#40;</span>counter <span style="color: #000000;">&lt;</span> numGrades<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
			grade <span style="color: #000000;">=</span> input.<span style="color: #000000;">nextInt</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
			total <span style="color: #000000;">=</span> total <span style="color: #000000;">+</span> grade<span style="color: #000000;">;</span>
			counter<span style="color: #000000;">++;</span>		
		<span style="color: #000000;">&#125;</span>
		average <span style="color: #000000;">=</span> total<span style="color: #000000;">/</span>numGrades<span style="color: #000000;">;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">&quot;Your average is &quot;</span> <span style="color: #000000;">+</span> average <span style="color: #000000;">+</span> <span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>		
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</div> <br />
I managed to use the main method for the introduction and to call the second method. I tried using three methods, one for the main method, one for the loop, and one for the average, however, when I tried sending variables from the loop method to the average method, it was reading the variables from the main method. I wasn't sure how to go about fixing this, so if anyone could help out, I'd really appreciate that. I'll look into it myself now.<br />
<br />
Maybe I could use something like this.<br />
<br />
<div class="bbcode_container">
                
<div class="bbcode_description" style="height:24px; background-image: url('http://www.javaprogrammingforums.com/images/javacode2.png'); background-repeat: no-repeat; margin-bottom:0px"></div>

<div class="bbcode_code" style="height:60px;"><div class="java" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7F0055; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getTotal<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
   <span style="color: #7F0055; font-weight: bold;">return</span> total<span style="color: #000000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</div> <br />
But then how would this know to get the <b>total</b> from the <b>loop</b> method and not the <b>main</b> method? And I want to send the <b>total </b>from the <b>loop </b>method and the <b>numGrades </b>from the main method? Not sure how to go about doing this.</blockquote>

]]></content:encoded>
			<dc:creator>OA-OD-JD1</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/blogs/oa-od-jd1/53-simple-averaging-program.html</guid>
		</item>
		<item>
			<title>Scanners</title>
			<link>http://www.javaprogrammingforums.com/blogs/oa-od-jd1/52-scanners.html</link>
			<pubDate>Sun, 29 Jan 2012 21:55:57 GMT</pubDate>
			<description><![CDATA[I forgot to write about the scanner, so I'm going to do that now. 
 
Basically, a scanner is used to get information from the user. At this stage,...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">I forgot to write about the scanner, so I'm going to do that now.<br />
<br />
Basically, a scanner is used to get information from the user. At this stage, the scanner will be used only to gather information from the keyboard. Here's how it works.<br />
<br />
<div class="bbcode_container">
                
<div class="bbcode_description" style="height:24px; background-image: url('http://www.javaprogrammingforums.com/images/javacode2.png'); background-repeat: no-repeat; margin-bottom:0px"></div>

<div class="bbcode_code" style="height:120px;"><div class="java" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7F0055; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Scanner</span><span style="color: #000000;">;</span>
<span style="color: #7F0055; font-weight: bold;">class</span> Class1<span style="color: #000000;">&#123;</span>
	<span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">static</span> <span style="color: #7F0055; font-weight: bold;">void</span> main<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		Scanner input <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> Scanner<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">in</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">&quot;Enter some text:&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">&quot;The text you entered was: &quot;</span> <span style="color: #000000;">+</span> input.<span style="color: #000000;">nextLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>		
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</div> <br />
Firstly, we must import the scanner, since it's not available in the default library. It's found in the <b>java.util</b> library, so we write <b>import java.util.Scanner;</b> at the top of our code to allow us to use the scanner. Capitalisation here is important.<br />
<br />
Next, we need to create a new scanner variable to let us use the scanner. Do this by typing <b>Scanner</b> followed by the name of the object (in this case, I called mine <b>input</b>). Set the object equal to <b>new Scanner</b> with the parameter of <b>System.in</b> - this allows us to read the keyboard input.<br />
<br />
Now whenever you type into the console (or other field), the text you enter before pressing enter will be stored in the <b>input</b> scanner variable. To output this, we need to figure out what data type we're working with. In this case, it's a string of text so we use <b>input.nextLine()</b>. That's really all there is to it!</blockquote>

]]></content:encoded>
			<dc:creator>OA-OD-JD1</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/blogs/oa-od-jd1/52-scanners.html</guid>
		</item>
		<item>
			<title><![CDATA[JD1's Personal Development Blog]]></title>
			<link>http://www.javaprogrammingforums.com/blogs/oa-od-jd1/51-jd1s-personal-development-blog.html</link>
			<pubDate>Sun, 29 Jan 2012 21:54:04 GMT</pubDate>
			<description><![CDATA[---Quote (Originally by KevinWorkman)--- 
Again, just to nitpick, the tertiary (conditional) operator isn't exactly like an if statement- it simply...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore"><div class="bbcode_container">
	<div class="bbcode_quote">
		<div class="quote_container">
			<div class="bbcode_quote_container"></div>
			
				<div class="bbcode_postedby">
					<img src="images/misc/quote_icon.png" alt="Quote" /> Originally Posted by <strong>KevinWorkman</strong>
					<a href="showthread.php?p=56083#post56083" rel="nofollow"><img class="inlineimg" src="images/buttons/viewpost-right.png" alt="View Post" /></a>
				</div>
				<div class="message">Again, just to nitpick, the tertiary (conditional) operator isn't exactly like an if statement- it simply chooses between two values. You can't, for example, do this:<br />
<br />
<br />
boolean blue = true;<br />
blue ? System.out.println(&quot;blue&quot;) : System.out.println(&quot;red&quot;);<br />
<br />
Instead, you'd have to do something like this:<br />
<br />
boolean blue = true;<br />
String print = blue ? &quot;blue&quot; : &quot;red&quot;;<br />
System.out.println(print);</div>
			
		</div>
	</div>
</div></blockquote>

]]></content:encoded>
			<dc:creator>OA-OD-JD1</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/blogs/oa-od-jd1/51-jd1s-personal-development-blog.html</guid>
		</item>
		<item>
			<title>20 Tutorials Summarised!</title>
			<link>http://www.javaprogrammingforums.com/blogs/oa-od-jd1/50-20-tutorials-summarised.html</link>
			<pubDate>Sun, 29 Jan 2012 21:53:16 GMT</pubDate>
			<description><![CDATA[Well, I've finally finished watching and summarising (in this thread) the first twenty tutorials of TheNewBoston...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">Well, I've finally finished watching and summarising (in this thread) the first twenty tutorials of <a href="http://www.youtube.com/user/thenewboston?feature=watch" target="_blank">TheNewBoston</a>'s <a href="http://www.youtube.com/watch?v=Hl-zzrqQoSE&amp;feature=channel_video_title" target="_blank">Java Programming Tutorial</a> series. I've previously watched all 87 tutorials, but never summarised any of them to the point that the information stuck in my head long enough for me to retain.<br />
<br />
I plan on doing the same sort of thing for the next 67 tutorials and then into the <a href="http://www.youtube.com/watch?v=vW53w7me4AE&amp;feature=channel_video_title" target="_blank">Intermediate Java tutorials</a>.<br />
<br />
Thank you to everyone who has helped me out along the way. I have a long way to go but that will be made much easier with your continued support.<br />
<br />
Thanks,<br />
JD1</blockquote>

]]></content:encoded>
			<dc:creator>OA-OD-JD1</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/blogs/oa-od-jd1/50-20-tutorials-summarised.html</guid>
		</item>
		<item>
			<title>Conditional Operators</title>
			<link>http://www.javaprogrammingforums.com/blogs/oa-od-jd1/49-conditional-operators.html</link>
			<pubDate>Sun, 29 Jan 2012 21:52:59 GMT</pubDate>
			<description><![CDATA[Basically, I like to look at Conditional Operators as a quick way of implementing an If Statement. That's really all they are. Take a look at this...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">Basically, I like to look at Conditional Operators as a quick way of implementing an If Statement. That's really all they are. Take a look at this code.<br />
<br />
<div class="bbcode_container">
                
<div class="bbcode_description" style="height:24px; background-image: url('http://www.javaprogrammingforums.com/images/javacode2.png'); background-repeat: no-repeat; margin-bottom:0px"></div>

<div class="bbcode_code" style="height:96px;"><div class="java" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7F0055; font-weight: bold;">class</span> Class1<span style="color: #000000;">&#123;</span>
	<span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">static</span> <span style="color: #7F0055; font-weight: bold;">void</span> main<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> age <span style="color: #000000;">=</span><span style="color: #cc66cc;">50</span><span style="color: #000000;">;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #000000;">&#40;</span>age <span style="color: #000000;">&gt;</span> <span style="color: #cc66cc;">30</span> <span style="color: #000000;">?</span> <span style="color: #0000ff;">&quot;You are quite old!&quot;</span> <span style="color: #000000;">:</span> <span style="color: #0000ff;">&quot;You are still young!&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</div> <br />
You can see that we've initalised an integer with the value of 50. Our Conditional Operator then checks to see if it's greater than thirty (<b>age &gt; 30 ?</b>). We use a question mark to see if the condition is true. You then write the true and false outputs separated by a colon. That's really all there is to it!</blockquote>

]]></content:encoded>
			<dc:creator>OA-OD-JD1</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/blogs/oa-od-jd1/49-conditional-operators.html</guid>
		</item>
		<item>
			<title>Constructors</title>
			<link>http://www.javaprogrammingforums.com/blogs/oa-od-jd1/48-constructors.html</link>
			<pubDate>Sun, 29 Jan 2012 21:52:40 GMT</pubDate>
			<description><![CDATA[We can use a constructor to quickly initialise variables as soon as our object is created. If you haven't read the above post, please do - you will...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">We can use a constructor to quickly initialise variables as soon as our object is created. If you haven't read the above post, please do - you will become familiar with the code we're using for these examples.<br />
<br />
Here's <b>Class1</b>.<br />
<br />
<div class="bbcode_container">
                
<div class="bbcode_description" style="height:24px; background-image: url('http://www.javaprogrammingforums.com/images/javacode2.png'); background-repeat: no-repeat; margin-bottom:0px"></div>

<div class="bbcode_code" style="height:96px;"><div class="java" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7F0055; font-weight: bold;">class</span> Class1<span style="color: #000000;">&#123;</span>
	<span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">static</span> <span style="color: #7F0055; font-weight: bold;">void</span> main<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		Class2 class2Object <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> Class2<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">&quot;Tony&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
		class2Object.<span style="color: #000000;">outputName</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</div> <br />
You can see what we've done here is added an argument of <b>&quot;Tony&quot;</b> to our <b>class2Object</b>. To use this constructor, you must make a method with the exact same name as the class in which it's in. Take a look at our <b>Class2</b> code.<br />
<br />
<div class="bbcode_container">
                
<div class="bbcode_description" style="height:24px; background-image: url('http://www.javaprogrammingforums.com/images/javacode2.png'); background-repeat: no-repeat; margin-bottom:0px"></div>

<div class="bbcode_code" style="height:216px;"><div class="java" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">class</span> Class2 <span style="color: #000000;">&#123;</span>
	<span style="color: #7F0055; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> friendName<span style="color: #000000;">;</span>
&nbsp;
	<span style="color: #7F0055; font-weight: bold;">public</span> Class2<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> name<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		friendName <span style="color: #000000;">=</span> name<span style="color: #000000;">;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">void</span> setName<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> name<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		friendName <span style="color: #000000;">=</span> name<span style="color: #000000;">;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #7F0055; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getName<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		<span style="color: #7F0055; font-weight: bold;">return</span> friendName<span style="color: #000000;">;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #7F0055; font-weight: bold;">public</span> <span style="color: #7F0055; font-weight: bold;">void</span> outputName<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #000000;">out</span>.<span style="color: #000000;">printf</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">&quot;Your friend's name is %s&quot;</span>, getName<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</div> <br />
You will notice this new method.<br />
<br />
<div class="bbcode_container">
                
<div class="bbcode_description" style="height:24px; background-image: url('http://www.javaprogrammingforums.com/images/javacode2.png'); background-repeat: no-repeat; margin-bottom:0px"></div>

<div class="bbcode_code" style="height:60px;"><div class="java" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7F0055; font-weight: bold;">public</span> Class2<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> name<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		friendName <span style="color: #000000;">=</span> name<span style="color: #000000;">;</span>
	<span style="color: #000000;">&#125;</span></pre></div></div>

</div> <br />
The method's name is <b>Class2</b>, identicle to that of our class name. Since we were able to send the name variable over to <b>Class2</b> as the object was created, this now makes our <b>setName</b> method redundant. Its job has been taken care of.<br />
<br />
Constructors are useful if we wanted to use multiple objects. Each object has its own set of variables. What we could do, if we wanted, would be to create another object like this.<br />
<br />
<div class="bbcode_container">
                
<div class="bbcode_description" style="height:24px; background-image: url('http://www.javaprogrammingforums.com/images/javacode2.png'); background-repeat: no-repeat; margin-bottom:0px"></div>

<div class="bbcode_code" style="height:36px;"><div class="java" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">Class2 class2Object2 <span style="color: #000000;">=</span> <span style="color: #7F0055; font-weight: bold;">new</span> Class2<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">&quot;Betty&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span></pre></div></div>

</div> <br />
We could now decide to output <b>class2Object2 </b>or <b>class2Object1</b>; each would produce a different output.</blockquote>

]]></content:encoded>
			<dc:creator>OA-OD-JD1</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/blogs/oa-od-jd1/48-constructors.html</guid>
		</item>
	</channel>
</rss>
