<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Repeated Overflows</title>
	<atom:link href="http://code.christophervigliotti.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://code.christophervigliotti.com</link>
	<description>Christopher Vigliotti often speaks in CSS, ColdFusion, Flash, Grails, Java, JavaScript, Selenium and SQL</description>
	<lastBuildDate>Tue, 01 May 2012 13:11:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>SQL Server Quick Tip: Restoring A Database Backup</title>
		<link>http://code.christophervigliotti.com/2012/05/sql-server-quick-tip/</link>
		<comments>http://code.christophervigliotti.com/2012/05/sql-server-quick-tip/#comments</comments>
		<pubDate>Tue, 01 May 2012 13:10:59 +0000</pubDate>
		<dc:creator>Christopher Vigliotti</dc:creator>
				<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://code.christophervigliotti.com/?p=595</guid>
		<description><![CDATA[Restoring your SQL Server database using the GUI can leave your database stuck in the &#8220;restoring&#8221; state. One quick solution is to restore your database by using this simple SQL script. RESTORE DATABASE your-database-name FROM DISK='c:\your\backup\file\and\path\backup.bak' WITH REPLACE]]></description>
			<content:encoded><![CDATA[<p>Restoring your SQL Server database using the GUI can leave your database stuck in the &#8220;restoring&#8221; state.  One quick solution is to restore your database by using this simple SQL script.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">RESTORE DATABASE your<span style="color: #339933;">-</span>database<span style="color: #339933;">-</span>name FROM DISK<span style="color: #339933;">=</span><span style="color: #0000ff;">'c:<span style="color: #000099; font-weight: bold;">\y</span>our<span style="color: #000099; font-weight: bold;">\b</span>ackup<span style="color: #000099; font-weight: bold;">\f</span>ile<span style="color: #000099; font-weight: bold;">\a</span>nd<span style="color: #000099; font-weight: bold;">\p</span>ath<span style="color: #000099; font-weight: bold;">\b</span>ackup.bak'</span> WITH REPLACE</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://code.christophervigliotti.com/2012/05/sql-server-quick-tip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Feed The Google Black Bar&#8217;s Google Play Link A Plate Of Death, Greasemonkey Style</title>
		<link>http://code.christophervigliotti.com/2012/03/feed-the-google-black-bars-google-play-link-a-plate-of-death-greasemonkey-style/</link>
		<comments>http://code.christophervigliotti.com/2012/03/feed-the-google-black-bars-google-play-link-a-plate-of-death-greasemonkey-style/#comments</comments>
		<pubDate>Tue, 27 Mar 2012 14:59:25 +0000</pubDate>
		<dc:creator>Christopher Vigliotti</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://code.christophervigliotti.com/?p=594</guid>
		<description><![CDATA[Here&#8217;s a Greasemonkey script that I whipped up in 30 seconds that banishes the Google Black Bar&#8217;s new Google Play link back to the hell from whence it came. You may want to remove line 13. 1 2 3 4 5 6 7 8 9 10 11 12 13 // ==UserScript== // @name Oi Vei, [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a Greasemonkey script that I whipped up in 30 seconds that banishes the Google Black Bar&#8217;s new Google Play link back to the hell from whence it came.  You may want to remove line 13.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// ==UserScript==</span>
<span style="color: #666666; font-style: italic;">// @name 	Oi Vei, Google Play</span>
<span style="color: #666666; font-style: italic;">// @namespace  	http://code.christophervigliotti.com</span>
<span style="color: #666666; font-style: italic;">// @include    	http://*.google.*</span>
<span style="color: #666666; font-style: italic;">// @include     http://google.*</span>
<span style="color: #666666; font-style: italic;">// @include     https://*.google.*</span>
<span style="color: #666666; font-style: italic;">// @include     https://google.*</span>
<span style="color: #666666; font-style: italic;">// @include     https://accounts.google.*</span>
<span style="color: #666666; font-style: italic;">// @description Fixes Google's Black Bar</span>
<span style="color: #666666; font-style: italic;">// ==/UserScript==</span>
&nbsp;
document.<span style="color: #006633;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'gb_78'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">parentNode</span>.<span style="color: #006633;">style</span>.<span style="color: #006633;">display</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'none'</span><span style="color: #339933;">;</span>
alert<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'YOU SHALL NOT PASS'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://code.christophervigliotti.com/2012/03/feed-the-google-black-bars-google-play-link-a-plate-of-death-greasemonkey-style/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SCJA Chapter 2, Exercise 2-1</title>
		<link>http://code.christophervigliotti.com/2012/03/scja-chapter-2-exercise-2-1/</link>
		<comments>http://code.christophervigliotti.com/2012/03/scja-chapter-2-exercise-2-1/#comments</comments>
		<pubDate>Wed, 21 Mar 2012 08:30:46 +0000</pubDate>
		<dc:creator>Christopher Vigliotti</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://code.christophervigliotti.com/?p=592</guid>
		<description><![CDATA[I&#8217;ve decided to become a Sun Certified Java Associate and am studying for the exam. I&#8217;m sharing my answer to Exercise 2.1, as it took a bit of work to grok the answer. The goals of Exercise 2.1 are to create an ArrayList of floats, iterate through the list and printing out the values when [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve decided to become a Sun Certified Java Associate and am studying for the exam.  I&#8217;m sharing my answer to Exercise 2.1, as it took a bit of work to grok the answer.  The goals of Exercise 2.1 are to create an ArrayList of floats, iterate through the list and printing out the values when they meet a certain condition.  I know that this is Java 101 stuff here, but the key for me to complete this exercise was to realize that I could declare floats to numeric values that contained decimals easily by adding an f immediately after the number.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">float</span> requiredFishLength <span style="color: #339933;">=</span> <span style="color: #cc66cc;">28.0</span><span style="color: #339933;">;</span></pre></div></div>

<p><em>This code throws an error</em></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">float</span> requiredFishLength <span style="color: #339933;">=</span> 28.0f<span style="color: #339933;">;</span></pre></div></div>

<p><em>Just add f-bomb!</em></p>
<p>Lastly, here&#8217;s my solution for Exercise 2-1</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">float</span> requiredFishLength <span style="color: #339933;">=</span> 28.0f<span style="color: #339933;">;</span>
ArrayList<span style="color: #339933;">&lt;</span>Float<span style="color: #339933;">&gt;</span> fishLengthList <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>Float<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
fishLengthList.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>10.0f<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
fishLengthList.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>15.5f<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
fishLengthList.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>18.0f<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
fishLengthList.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>29.5f<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
fishLengthList.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>45.5f<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span> fishLength<span style="color: #339933;">:</span> fishLengthList<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>fishLength <span style="color: #339933;">&gt;</span> requiredFishLength<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>fishLength<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://code.christophervigliotti.com/2012/03/scja-chapter-2-exercise-2-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Firebug JavaScript Logging Gotcha</title>
		<link>http://code.christophervigliotti.com/2012/03/firebug-javascript-logging-gotcha/</link>
		<comments>http://code.christophervigliotti.com/2012/03/firebug-javascript-logging-gotcha/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 08:30:17 +0000</pubDate>
		<dc:creator>Christopher Vigliotti</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://code.christophervigliotti.com/?p=590</guid>
		<description><![CDATA[I&#8217;ve been doing a lot of Javascript / jQuery work over the last week and have been using Firebug&#8217;s handy-dandy console.log() debugging method. Thanks to the awesomeness that is Firebug the era of debugging one&#8217;s JavaScript code with irritating alert() messages is over. One gotcha that I&#8217;ve fallen for more than once this past week [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been doing a lot of Javascript / jQuery work over the last week and have been using Firebug&#8217;s handy-dandy console.log() debugging method.  Thanks to the awesomeness that is Firebug the era of debugging one&#8217;s JavaScript code with irritating alert() messages is over.  One gotcha that I&#8217;ve fallen for more than once this past week is that leaving console.log() calls in your code when you aren&#8217;t running Firebug will cause JavaScript errors.  A simple work-around for this problem is to have JavaScript test for the existence of console before attempting to log the message.  I&#8217;m doing this in the code sample below in a function that I&#8217;ve named consoleLog().</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">&nbsp;
function booya<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// this will make IE cry like a sad, sad baby when Firebug is not present</span>
    console.<span style="color: #006633;">log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'booya'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// this will appease the demon child</span>
    consoleLog<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'method booya() in the house'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
function consoleLog<span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>window.<span style="color: #006633;">console</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        console.<span style="color: #006633;">log</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Ideally one should not be leaving debug code in their completed work, but I make an exception in cases where the debugging code serves as a code comment that may be helpful to other developers.</p>
<p>You can read more about Firebug and Logging <a href="http://getfirebug.com/logging">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.christophervigliotti.com/2012/03/firebug-javascript-logging-gotcha/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery Add &#8216;Em Up</title>
		<link>http://code.christophervigliotti.com/2012/03/jquery-add-em-up/</link>
		<comments>http://code.christophervigliotti.com/2012/03/jquery-add-em-up/#comments</comments>
		<pubDate>Tue, 06 Mar 2012 20:53:40 +0000</pubDate>
		<dc:creator>Christopher Vigliotti</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://code.christophervigliotti.com/?p=589</guid>
		<description><![CDATA[Here&#8217;s a bit of code that calculates the sum of the values found in a group of form fields. Dollar signs, decimals and commas are added to each form field as-needed, non-numeric characters are brought to the user&#8217;s attention. I chose not to leverage the jQuery Calculation Plug-in because I wanted small/light code that targeted [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a bit of code that calculates the sum of the values found in a group of form fields.  Dollar signs, decimals and commas are added to each form field as-needed, non-numeric characters are brought to the user&#8217;s attention.  I chose not to leverage the <a href="http://www.pengoworks.com/workshop/jquery/calculation/calculation.plugin.htm" target="_blank">jQuery Calculation Plug-in</a> because I wanted small/light code that targeted the following requirements:</p>
<ol>
<li>calculate the sum of a group of form fields</li>
<li>add dollar signs, decimals and commas as-needed</li>
<li>ignore non-numeric form field values during calculation, but alert the user</li>
</ol>
<p>You can check out a working example <a href="/wp-content/uploads/2012/03/calc2.htm" target="_blank">here</a> and check out the code below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">ready</span><span style="color: #009900;">&#40;</span>function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// call doTotals() once when the page loads</span>
	doTotals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'calc'</span>,<span style="color: #0000ff;">'total'</span>,<span style="color: #0000ff;">'error_'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>						
	doTotals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'morecalc'</span>,<span style="color: #0000ff;">'anothertotal'</span>,<span style="color: #0000ff;">'error_'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>						
&nbsp;
	<span style="color: #666666; font-style: italic;">// call doTotals() each time one of the 'calc' fields or 'morecalc' fields change</span>
	jQuery<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.calc'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">change</span><span style="color: #009900;">&#40;</span>function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		doTotals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'calc'</span>, <span style="color: #0000ff;">'total'</span>,<span style="color: #0000ff;">'error_'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	jQuery<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.morecalc'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">change</span><span style="color: #009900;">&#40;</span>function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		doTotals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'morecalc'</span>,<span style="color: #0000ff;">'anothertotal'</span>,<span style="color: #0000ff;">'error_'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// spiffy function that adds commas to a number</span>
function addCommas<span style="color: #009900;">&#40;</span>nStr<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	nStr <span style="color: #339933;">+=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	x <span style="color: #339933;">=</span> nStr.<span style="color: #006633;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	x1 <span style="color: #339933;">=</span> x<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	x2 <span style="color: #339933;">=</span> x.<span style="color: #006633;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">?</span> <span style="color: #0000ff;">'.'</span> <span style="color: #339933;">+</span> x<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	var rgx <span style="color: #339933;">=</span> <span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>\d<span style="color: #339933;">+</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>\d<span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/;</span>
	<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>rgx.<span style="color: #006633;">test</span><span style="color: #009900;">&#40;</span>x1<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	    x1 <span style="color: #339933;">=</span> x1.<span style="color: #006633;">replace</span><span style="color: #009900;">&#40;</span>rgx, <span style="color: #0000ff;">'$1'</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">','</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">'$2'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">return</span> x1 <span style="color: #339933;">+</span> x2<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 this function...
	1. adds a group of form fields
	2. formats the form fields
	3. writes the total
	4. highlights any errors
&nbsp;
usage...
&nbsp;
	doTotals('calc','total','error_');
	where
		'calc' is a the class name that is present in each form field that you want to add
		and
		'total' is the id of the span/div that you wish to display the total in
		and
		'error_'
		is the name of the span that accompanies each form field.  an error message will be displayed in this span
*/</span>
function doTotals<span style="color: #009900;">&#40;</span>valuesClassName, totalIdName, errorIdPrefix<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
	var doWriteDollarSignsToFormFields <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	var total <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	jQuery<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span> <span style="color: #339933;">+</span> valuesClassName<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">each</span><span style="color: #009900;">&#40;</span>function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	value <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// remove all whitespace</span>
	<span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>value.<span style="color: #006633;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		value <span style="color: #339933;">=</span> value.<span style="color: #006633;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span>, <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// remove all dollar signs</span>
	<span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>value.<span style="color: #006633;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		value <span style="color: #339933;">=</span> value.<span style="color: #006633;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$'</span>, <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// remove all commas</span>
	<span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>value.<span style="color: #006633;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		value <span style="color: #339933;">=</span> value.<span style="color: #006633;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span>, <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>			
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// if at this point value is blank, change it to 0</span>
	<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>value <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		value <span style="color: #339933;">=</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// if at this point the value is not blank and is a number...				</span>
	errorFieldName <span style="color: #339933;">=</span> <span style="color: #0000ff;">'#'</span> <span style="color: #339933;">+</span> errorIdPrefix <span style="color: #339933;">+</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>value <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span> isNaN<span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// write the cleaned value (with commas) to the form field</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>doWriteDollarSignsToFormFields <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			jQuery<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">val</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$'</span> <span style="color: #339933;">+</span> addCommas<span style="color: #009900;">&#40;</span>parseFloat<span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toFixed</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
			jQuery<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">val</span><span style="color: #009900;">&#40;</span>addCommas<span style="color: #009900;">&#40;</span>parseFloat<span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toFixed</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// convert the value and add it to the total</span>
		valueParsed <span style="color: #339933;">=</span> parseFloat<span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		total <span style="color: #339933;">=</span> total <span style="color: #339933;">+</span> valueParsed<span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// console.log('remove error from span id ' + errorFieldName);</span>
		jQuery<span style="color: #009900;">&#40;</span>errorFieldName<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">html</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// console.log('write error to span id ' + errorFieldName);</span>
		jQuery<span style="color: #009900;">&#40;</span>errorFieldName<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">html</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;&lt; please enter a numeric value&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// update the total</span>
	<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>doWriteDollarSignsToFormFields <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		jQuery<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#'</span> <span style="color: #339933;">+</span> totalIdName<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">html</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$'</span> <span style="color: #339933;">+</span> addCommas<span style="color: #009900;">&#40;</span>parseFloat<span style="color: #009900;">&#40;</span>total<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toFixed</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
		jQuery<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#'</span> <span style="color: #339933;">+</span> totalIdName<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">html</span><span style="color: #009900;">&#40;</span>addCommas<span style="color: #009900;">&#40;</span>parseFloat<span style="color: #009900;">&#40;</span>total<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toFixed</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>&#8230;and here&#8217;s an HTML table&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
</pre></td><td class="code"><pre class="htm" style="font-family:monospace;">&lt;h1&gt;add em' up!&lt;/h1&gt;
&lt;table style=&quot;width:800px;&quot;&gt;
&lt;tr&gt;
	&lt;td style=&quot;width:400px;vertical-align:top;&quot;&gt;
		&lt;h2&gt;group a&lt;/h2&gt;
		&lt;input type=&quot;text&quot; class=&quot;calc&quot; id=&quot;calc1&quot; value=&quot;$55.50&quot; /&gt;
		&lt;span id=&quot;error_calc1&quot;&gt;error_calc1&lt;/span&gt;&lt;br /&gt;
		&lt;input type=&quot;text&quot; class=&quot;calc&quot; id=&quot;calc2&quot; value=&quot;19.99&quot; /&gt;
		&lt;span id=&quot;error_calc2&quot;&gt;error_calc2&lt;/span&gt;&lt;br /&gt;
		&lt;input type=&quot;text&quot; class=&quot;calc&quot; id=&quot;calc3&quot; value=&quot;&quot; /&gt;
		&lt;span id=&quot;error_calc3&quot;&gt;error_calc3&lt;/span&gt;&lt;br /&gt;
		&lt;input type=&quot;text&quot; class=&quot;calc&quot; id=&quot;calc4&quot; value=&quot;&quot; /&gt;
		&lt;span id=&quot;error_calc4&quot;&gt;error_calc4&lt;/span&gt;&lt;br /&gt;
		&lt;input type=&quot;text&quot; class=&quot;calc&quot; id=&quot;calc5&quot; value=&quot;cheese&quot; /&gt;
		&lt;span id=&quot;error_calc5&quot;&gt;error_calc5&lt;/span&gt;&lt;br /&gt;
	&lt;/td&gt;
	&lt;td style=&quot;width:400px;vertical-align:top;&quot;&gt;
		&lt;h2&gt;group b&lt;/h2&gt;
		&lt;input type=&quot;text&quot; class=&quot;morecalc&quot; id=&quot;calc6&quot; value=&quot;&quot; /&gt;
		&lt;span id=&quot;error_calc6&quot;&gt;error_calc6&lt;/span&gt;&lt;br /&gt;
		&lt;input type=&quot;text&quot; class=&quot;morecalc&quot; id=&quot;calc7&quot; value=&quot;&quot; /&gt;
		&lt;span id=&quot;error_calc7&quot;&gt;error_calc7&lt;/span&gt;&lt;br /&gt;
		&lt;input type=&quot;text&quot; class=&quot;morecalc&quot; id=&quot;calc8&quot; value=&quot;&quot; /&gt;
		&lt;span id=&quot;error_calc8&quot;&gt;error_calc8&lt;/span&gt;&lt;br /&gt;
	&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;
		&lt;h2&gt;total a&lt;/h2&gt;
		&lt;span id=&quot;total&quot;&gt;0.00&lt;/span&gt;
	&lt;/td&gt;
	&lt;td&gt;
		&lt;h2&gt;total b&lt;/h2&gt;
		&lt;span id=&quot;anothertotal&quot;&gt;0.00&lt;/span&gt;
	&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;</pre></td></tr></table></div>

<p>The power of jQuery compels me!</p>
]]></content:encoded>
			<wfw:commentRss>http://code.christophervigliotti.com/2012/03/jquery-add-em-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java-licious Java Primer: Properties</title>
		<link>http://code.christophervigliotti.com/2012/02/java-licious-java-primer-properties/</link>
		<comments>http://code.christophervigliotti.com/2012/02/java-licious-java-primer-properties/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 15:40:04 +0000</pubDate>
		<dc:creator>Christopher Vigliotti</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[O-O]]></category>

		<guid isPermaLink="false">http://code.christophervigliotti.com/?p=524</guid>
		<description><![CDATA[In this second installment of the Java-licious Java Primer series we are going to focus on &#8220;properties&#8221;. Arguments Methods may require arguments in order to function. Arguments are the values that you pass into a method. Lets compare these two examples&#8230; 1 2 3 public static void displayYourName&#40;&#41;&#123; System.out.println&#40;&#34;John Jacob Jingleheimer-Schmidt&#34;&#41;; &#125; Example 1a &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>In this second installment of the Java-licious Java Primer series we are going to focus on &#8220;properties&#8221;.</p>
<h2>Arguments</h2>
<p>Methods <em>may</em> require arguments in order to function.  Arguments are the values that you pass into a method.  Lets compare these two examples&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> displayYourName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;John Jacob Jingleheimer-Schmidt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>Example 1a &#8211; a method that does not require any arguments</em></p>
<p>We can determine that the above method does not require any arguments because the arguments are not defined in the parenthesis &#8220;()&#8221; on line 1.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> displayYourName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> yourName<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>yourName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>Example 1b &#8211; a method that requires one argument</em></p>
<p>Check out the code inside of the parenthesis &#8220;()&#8221; on line 1.  &#8220;String yourName&#8221; means that the method expects you to pass in a string when calling this method.  The method will refer to this string as &#8220;yourName&#8221;.</p>
<p>Remember that methods may (or may not) require arguments.  </p>
<h2>Returned Values</h2>
<p>Additionally methods <em>may</em> return values.  Lets compare these two examples&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> displayYourName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;John Jacob Jingleheimer-Schmidt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>Example 2a &#8211; a method that does not return a value</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> getYourName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;John Jacob Jingleheimer-Schmidt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>Example 2b &#8211; a method that returns a string</em></p>
<p>Remember that methods may (or may not) return values.  </p>
<h2>Methods And Properties</h2>
<p>A class is made up of methods and properties.  Methods (covered in the previous post) define the behavior of classes.  Properties on the other hand define the non-behavioral aspects of a class.  For example, if we were to think of a Person as a class, breathing, running and jumping would be considered methods.  Name, hair color, height, weight and gender would be some of the properties of the Person class.  </p>
<p>Lets create a class called &#8220;RegularDrip.java&#8221; into a package named &#8220;coffee&#8221;.  Your code should look like the example in Figure 1.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">coffee</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> RegularDrip <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> whoAreYou <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;I am a cup of regular drip coffee&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> getWhoAreYou<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> whoAreYou<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>Figure 3a &#8211; Class RegularDrip.java</em></p>
<p>Two items of note here.  The first is the code on line 5.  This is the classes only property.  It&#8217;s name is &#8220;whoAreYou&#8221; and it&#8217;s type is a &#8220;String&#8221;.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>5
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> whoAreYou <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;I am a cup of regular drip coffee&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><em>Figure 3b &#8211; the whoAreYou property of class RegularDrip.java</em></p>
<h2>Data Types</h2>
<p>All properties have a data type.  Data types are just that&#8230;one of the many different type of data.  Our whoAreYou property on line 5 is the &#8220;string&#8221; datatype.  Let&#8217;s add another property to our object.  Add the code below after line 5.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> ouncesRemaining <span style="color: #339933;">=</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">;</span></pre></div></div>

<p><em>Figure 4a &#8211; the ouncesRemaining property of class RegularDrip.java</em></p>
<p>Our RegularDrip class now has two properties!  There are a few differences between the two properties that we should look into.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>5
6
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> whoAreYou <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;I am a cup of regular drip coffee&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> ouncesRemaining <span style="color: #339933;">=</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><em>Figure 4b &#8211; the properties of class RegularDrip.java</em></p>
<p>The second one has a type of &#8220;int&#8221;.  That&#8217;s Java-speak for &#8220;integer&#8221;, which is math speak for &#8220;number&#8221;.  The other difference is on the right side of the equals sign.  The whoAreYou property is a string, which means that we have to wrap it&#8217;s value in quotes.  The ouncesRemaining property however, is an int&#8230;which means that we need to declare it&#8217;s value without quotes.</p>
<h2>Lets Make Coffee</h2>
<p>Using MrJava5000.java from the previous lesson lets add a few additional lines of code.   After the package declaration add the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">coffee.RegularDrip</span><span style="color: #339933;">;</span></pre></div></div>

<p><em>Figure 5a &#8211; an import statement</em></p>
<p>This code is an import statement.  It allows us to access the RegularDrip class.</p>
<p>And after the sayHello() method call in the main() method add this code:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">RegularDrip myMorningCup <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RegularDrip<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// new</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>myMorningCup.<span style="color: #006633;">getWhoAreYou</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><em>Figure 5b &#8211; make a new cup of coffee, then tell us about it</em></p>
<p>This code creates a new instance of RegularDrip named &#8216;myMorningCup&#8217;, then sends the returned value of the RegularDrip instance&#8217;s getWhoAreYou() method to the console window.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">coffeemakers</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">coffee.RegularDrip</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// new</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MrJava5000 <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		sayHello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		RegularDrip myMorningCup <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RegularDrip<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// new</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>myMorningCup.<span style="color: #006633;">getWhoAreYou</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> sayHello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hello world&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>Figure 5c &#8211; MrJava5000.java</em></p>
<p>Run the MrJava5000.java class now and prepare to be amazed as your creation actually produces a (fake) cup of coffee!</p>
<h2>Many Ways To Say Hello</h2>
<p>Lets take a look at the println() method.  We know that </p>
<p>Here are a In all three examples we output the word &#8220;hello&#8221; to the console window.  In each of the three examples we pass a string into the println() method.  In the first example we create a string on-the-fly simply by wrapping some text in quotes.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// say hello</span>
	<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hello...is it me you're looking for&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>Example 6a &#8211; Hello</em></p>
<p>Check out the println() method call.  Note that &#8220;hello&#8221; is wrapped in quotes because println() expects a string.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// say hello again</span>
	<span style="color: #003399;">String</span> greeting <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;hello...is it me you're looking for&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>greeting<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>Example 6b &#8211; Hello</em></p>
<p>Again focusing on println(), note that &#8220;greeting&#8221; is not wrapped in quotes.  This is because &#8220;greeting&#8221; is a variable of type &#8220;string&#8221;.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// say hello a third time</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> string getHello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;hello...is it me you're looking for&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>getHello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>Example 6c &#8211; Hello</em></p>
<p>This time we pass the returned value from the getHello() method into the println() method.</p>
<h2>Next Time</h2>
<p>Next time we&#8217;ll dig deeper into what an &#8220;instance&#8221; of a class is.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.christophervigliotti.com/2012/02/java-licious-java-primer-properties/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java-licious Java Primer: Methods</title>
		<link>http://code.christophervigliotti.com/2012/02/java-licious-java-primer-create-a-class-a-method/</link>
		<comments>http://code.christophervigliotti.com/2012/02/java-licious-java-primer-create-a-class-a-method/#comments</comments>
		<pubDate>Mon, 13 Feb 2012 19:18:48 +0000</pubDate>
		<dc:creator>Christopher Vigliotti</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[O-O]]></category>

		<guid isPermaLink="false">http://code.christophervigliotti.com/?p=497</guid>
		<description><![CDATA[Welcome to the first of the &#8220;Java-licious Java Primer&#8221; series. The series was created for folks that are new to software development (experienced code-heads and vulcans may want to skip this one). In this post we&#8217;ll be covering how to create a class, how to add a method to the class, and how to &#8220;call&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to the first of the &#8220;Java-licious Java Primer&#8221; series.  The series was created for folks that are new to software development (experienced code-heads and vulcans may want to skip this one).  In this post we&#8217;ll be covering how to create a class, how to add a method to the class, and how to &#8220;call&#8221; the method.</p>
<p><img src="http://code.christophervigliotti.com/wp-content/uploads/2012/02/eclipse.png" align="right" /></p>
<h2>Start Here</h2>
<p>In order to follow along you will need to download and install the Eclipse IDE.  IDE is fancy-talk for &#8220;interactive development environment&#8221;&#8230;which is fancy talk for &#8220;the program that we will edit and run java files in&#8221;.  Download the zip file, and unzip the contents to to c:\Eclipse.  To open Eclipse simply browse to c:\Eclipse and double-click eclipse.exe.</p>
<h2>Create A New Project</h2>
<p>In Eclipse follow these two simple steps to create a new project&#8230;</p>
<ol>
<li>Click on &#8220;File&#8221; > &#8220;New&#8221; > &#8220;New Java Project&#8221;</li>
<li>Name your project &#8220;Javalicious&#8221; and click &#8220;Finish&#8221;</li>
</ol>
<h2>Create Your First Class</h2>
<ol>
<li>In the Package Explorer pane, right click on the Javalicious project, select &#8220;New&#8221; > &#8220;Class&#8221;</li>
<li>Name your class &#8220;MrJava5000&#8243; and give it a package name of &#8220;coffeemakers&#8221;</li>
<li>Under &#8220;Which method stubs would you like to create&#8221; make sure that &#8220;public static void main(String[] args)&#8221; is checked.</li>
<li>Click &#8220;Finish&#8221;</li>
</ol>
<p>Your new class is now created and should look like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">coffeemakers</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MrJava5000 <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * @param args
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>Figure 1 &#8211; MrJava5000.java</em></p>
<h2>What Does It All Mean?</h2>
<p>Before we proceed with attempting to understand all the strange letters, squiggles and assorted shapes in Figure 1 lets take a step back and talk about code comments.  Here is how code comments are written in Java.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// I am a single-line code comment.</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
* I am a multi-line 
* code comment.
*/</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*
 I am also a multi-line 
 code comment.
*/</span></pre></div></div>

<p>Code comments are the ideal place to leave notes for yourself, and to explain what a given section/line of code does to other developers.  I&#8217;ve modified the code in Figure 1, adding comments and removing a few things.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// this is the package declaration</span>
<span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">coffeemakers</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* 
this is the class declaration.  it's &quot;public&quot; which means that it can be used by other classes.
note the curly brace '{' after the class name.  it's matching curly brace is on line 14
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MrJava5000 <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// this is a method named 'main'.  this method begins on line 11 and ends on line 13.</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>Figure 2 &#8211; MrJava5000.java with lots of code comments</em></p>
<h3>Package Declaration</h3>
<p>So the code on line 2 is the package declaration.  It basically says &#8220;the MrJava5000 class is found in the folder named &#8216;coffeemakers&#8217;.  Think of packages as folders.  If we were to change the name to from &#8220;coffeemakers&#8221; to &#8220;coffeemakers.mrjava&#8221; Eclipse would simply move the file from [project root]\src\coffeemakers\ to [project root]\src\coffeemakers\mrjava\.</p>
<h3>Class Declaration</h3>
<p>You may notice several occurrences of the left and right curly braces &#8220;{&#8221; and &#8220;}&#8221;.  The class declaration on line 8 has a left curly brace.  It&#8217;s matching right curly brace is found on line 14.  Everything between these two symbols is a part of class body.  </p>
<h3>The &#8220;Main&#8221; Method</h3>
<p>Lines 11 through 13 contain the a method.  This is a special method named &#8216;main&#8217;.  It is special in that it will run whenever you run the class.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>11
12
13
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>Figure 3 &#8211; The &#8220;main&#8221; Method</em></p>
<h2>Lets Add Another Method</h2>
<p>Below the closing curly brace for the main method(and before the closing curly brace for the class) add the following code.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> sayHello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hello world&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><em>Figure 3a &#8211; The &#8220;sayHello&#8221; Method</em></p>
<p>This is a new method named &#8220;sayHello&#8221;.  It calls a method named &#8220;println&#8221;.  This method displays whatever text is contained within the parenthesis and quotes.  </p>
<p>Your code should look like this&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">coffeemakers</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MrJava5000 <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> sayHello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hello world&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>Figure 3b &#8211; MrJava5000.java, including our new &#8220;sayHello&#8221; method</em></p>
<p>Now let&#8217;s run this Java class and see what happens.  Highlight MrJava5000.java in the Package Explorer window and press the green play button.  Observe the results.  Actually that&#8217;s a joke, as there are no results to observe.  The reason why we didn&#8217;t see the &#8220;hello world&#8221; text that we wanted to is due to the fact that we aren&#8217;t &#8220;calling&#8221; the helloWorld() method from our main() method.  Let&#8217;s do that now by adding the following code to the main method.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">sayHello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><em>Figure 4a &#8211; calling the &#8220;sayHello&#8221; method</em></p>
<p>OK, now we have added code inside of the main() method that calls the helloWorld() method.  Your code should now look like this&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">coffeemakers</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MrJava5000 <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		sayHello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> sayHello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hello world&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>Figure 4b &#8211; MrJava5000.java, ready to say hello</em></p>
<p>Run the code again and you should see the following text in the Console panel.</p>
<pre>hello world</pre>
<p>You&#8217;ve just created your first Java class.  When run, this classes main method runs.  The main method calls the sayHello method, which in turn outputs the text &#8220;hello world&#8221; to the console panel.  This of course means that you are one step closer to becoming a Java legend! </p>
<p><img src="http://draw.christophervigliotti.com/wp-content/uploads/2011/09/Twins-500.jpg" align="center" /></p>
]]></content:encoded>
			<wfw:commentRss>http://code.christophervigliotti.com/2012/02/java-licious-java-primer-create-a-class-a-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New To Java?  Read This Book</title>
		<link>http://code.christophervigliotti.com/2012/02/new-to-java-read-this-book/</link>
		<comments>http://code.christophervigliotti.com/2012/02/new-to-java-read-this-book/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 19:10:10 +0000</pubDate>
		<dc:creator>Christopher Vigliotti</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[O-O]]></category>

		<guid isPermaLink="false">http://code.christophervigliotti.com/?p=492</guid>
		<description><![CDATA[If you are new to the strange and wonderful world of Java development, Head First Java is the essential primer. Do you have a favorite &#8220;Intro to Java&#8221; or &#8220;Intro to Object Oriented Development&#8221; resource? Please share in the comments]]></description>
			<content:encoded><![CDATA[<p>If you are new to the strange and wonderful world of Java development, <a href="http://www.amazon.com/gp/product/0596009208/ref=as_li_ss_tl?ie=UTF8&#038;tag=chrisviglivis-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0596009208">Head First Java</a> is the essential primer.</p>
<p>Do you have a favorite &#8220;Intro to Java&#8221; or &#8220;Intro to Object Oriented Development&#8221; resource?  Please share in the comments <img src='http://code.christophervigliotti.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://code.christophervigliotti.com/2012/02/new-to-java-read-this-book/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>&#8220;Zeus, There It Is&#8221; or &#8220;Don&#8217;t Bring Me Down&#8230;Zeus&#8221;</title>
		<link>http://code.christophervigliotti.com/2012/01/zeus-there-it-is-or-dont-bring-me-down-zeus/</link>
		<comments>http://code.christophervigliotti.com/2012/01/zeus-there-it-is-or-dont-bring-me-down-zeus/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 18:29:15 +0000</pubDate>
		<dc:creator>Christopher Vigliotti</dc:creator>
				<category><![CDATA[ColdFusion]]></category>

		<guid isPermaLink="false">http://code.christophervigliotti.com/?p=487</guid>
		<description><![CDATA[I&#8217;ll be participating on a preview of ColdFusion Zeus tomorrow at noon. See you there.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll be participating on a preview of ColdFusion Zeus tomorrow at noon.  See you <a href="http://www.meetup.com/coldfusionmeetup/events/45355792/">there</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.christophervigliotti.com/2012/01/zeus-there-it-is-or-dont-bring-me-down-zeus/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Selenium Conditional Statements And Assertions</title>
		<link>http://code.christophervigliotti.com/2012/01/selenium-conditional-statements-and-assertions/</link>
		<comments>http://code.christophervigliotti.com/2012/01/selenium-conditional-statements-and-assertions/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 16:27:56 +0000</pubDate>
		<dc:creator>Christopher Vigliotti</dc:creator>
				<category><![CDATA[Selenium]]></category>

		<guid isPermaLink="false">http://code.christophervigliotti.com/?p=485</guid>
		<description><![CDATA[This post is a part of my Learn Selenium series. Here&#8217;s a test case that demonstrates the use of conditional statements and assertions in Selenium RC. This code uses the parent class BigDaddyKane, which is explored in detail in a previous post. 1 2 3 4 5 6 7 8 9 10 11 12 13 [...]]]></description>
			<content:encoded><![CDATA[<p><em>This post is a part of my <a href="http://code.christophervigliotti.com/learn-selenium/">Learn Selenium</a> series.</em></p>
<p>Here&#8217;s a test case that demonstrates the use of conditional statements and assertions in Selenium RC.  This code uses the parent class BigDaddyKane, which is explored in detail <a href="http://code.christophervigliotti.com/2012/01/selenium-rc-tests-now-with-more-big-daddy-kane/">in a previous post</a>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// package declaration, imports, etc.</span>
<span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">awesomeTests</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.security.SecureRandom</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.math.BigInteger</span><span style="color: #339933;">;</span>
@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;deprecation&quot;</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// class decaration</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> FancyTests <span style="color: #000000; font-weight: bold;">extends</span> BigDaddyKane <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// This is a method for generating a random string.  </span>
	<span style="color: #666666; font-style: italic;">// You can disregard it for now, just note that we'll be using this later.</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getRandomString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">SecureRandom</span> random <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">SecureRandom</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BigInteger</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">130</span>, random<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Here is our first test case.  It verifies that the text </span>
	<span style="color: #666666; font-style: italic;">// &quot;Repeated Overflows&quot; appears in the h1 of the main page.</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testIsBlogTitleCorrect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// open the root page of the site</span>
		selenium.<span style="color: #006633;">open</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Lastly we use assertEquals().  This test will fail if the text </span>
		<span style="color: #666666; font-style: italic;">// &quot;Repeated Overflows&quot; is not present in an h1 element</span>
		assertEquals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Repeated Overflows&quot;</span>, selenium.<span style="color: #006633;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;css=h1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* Here is our second test case.  This example demonstrates the use of conditional logic in conjunction with 
	 * the Selenium function isElementPresent().  
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testAddCommentToBlog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// open the root page of the site</span>
		selenium.<span style="color: #006633;">open</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// click on the top-most post and wait for the page to load</span>
		selenium.<span style="color: #006633;">click</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;xpath=//div[2]/div/h1/a&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		selenium.<span style="color: #006633;">waitForPageToLoad</span><span style="color: #009900;">&#40;</span>pageReloadTime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
		<span style="color: #666666; font-style: italic;">// using this variable to determine the user's logged in state</span>
		<span style="color: #000066; font-weight: bold;">boolean</span> userIsLoggedIn <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/* since Wordpress will now allow duplicate comments we need to make the comment text unique each time this test is run.  
		 * Note the use of the + symbol when declaring the string.  This means that the text to the left of the plus in quotes will be 
		 * appended by the results of the getRandomString() function call.
		 */</span>
		<span style="color: #003399;">String</span> comment <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;the chicken says: &quot;</span> <span style="color: #339933;">+</span> getRandomString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>comment<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// are these elements present?</span>
		<span style="color: #000066; font-weight: bold;">boolean</span> nameFieldExists <span style="color: #339933;">=</span> selenium.<span style="color: #006633;">isElementPresent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id=author&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">boolean</span> mailFieldExists <span style="color: #339933;">=</span> selenium.<span style="color: #006633;">isElementPresent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id=email&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">boolean</span> urlFieldExists <span style="color: #339933;">=</span> selenium.<span style="color: #006633;">isElementPresent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id=url&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// displays the above boolean values in the console screen (so you can see what's going on)</span>
		<span style="color: #666666; font-style: italic;">/*
		System.out.println(nameFieldExists);
		System.out.println(mailFieldExists);
		System.out.println(urlFieldExists);
		*/</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// note: in cases where the author, email and url fields are not present the user is already logged in</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// if the name, email and url fields do not exist, then the user is logged in</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>nameFieldExists <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">false</span> <span style="color: #339933;">&amp;&amp;</span> mailFieldExists <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">false</span> <span style="color: #339933;">&amp;&amp;</span> urlFieldExists <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			userIsLoggedIn <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// if the user is not logged in, fill in the name, mail and url fields</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>userIsLoggedIn <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;user is logged in&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			selenium.<span style="color: #006633;">type</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id=author&quot;</span>, <span style="color: #0000ff;">&quot;Paul McCartney&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			selenium.<span style="color: #006633;">type</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id=email&quot;</span>, <span style="color: #0000ff;">&quot;billgates@microsoft.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			selenium.<span style="color: #006633;">type</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id=url&quot;</span>, <span style="color: #0000ff;">&quot;http://wikipedia.org&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;user is not logged in&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// fill in the comment field and click the submit button</span>
		selenium.<span style="color: #006633;">type</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id=comment&quot;</span>, comment<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		selenium.<span style="color: #006633;">click</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id=submit&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		selenium.<span style="color: #006633;">waitForPageToLoad</span><span style="color: #009900;">&#40;</span>pageReloadTime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// if the comment was added either the text &quot;Your comment is awaiting moderation.&quot; or the value of the String 'comment' should be present</span>
		<span style="color: #000066; font-weight: bold;">boolean</span> expectedResult <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>selenium.<span style="color: #006633;">isTextPresent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Your comment is awaiting moderation&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> selenium.<span style="color: #006633;">isTextPresent</span><span style="color: #009900;">&#40;</span>comment<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			expectedResult <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// lets display the expected result</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>expectedResult<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// use assertEquals to conclude this test case.  note that we could also use assertTrue(expectedResult) here...</span>
		assertEquals<span style="color: #009900;">&#40;</span>expectedResult, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://code.christophervigliotti.com/2012/01/selenium-conditional-statements-and-assertions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

