<?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>Turnleaf Design &#187; Noob Corner</title>
	<atom:link href="http://www.turnleafdesign.com/category/noob-corner/feed" rel="self" type="application/rss+xml" />
	<link>http://www.turnleafdesign.com</link>
	<description>Ramblings of a junior developer</description>
	<lastBuildDate>Wed, 11 Nov 2009 05:56:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>12 Tips to make you more productive using Eclipse</title>
		<link>http://www.turnleafdesign.com/12-tips-to-make-you-more-productive-using-eclipse</link>
		<comments>http://www.turnleafdesign.com/12-tips-to-make-you-more-productive-using-eclipse#comments</comments>
		<pubDate>Tue, 20 Oct 2009 04:28:16 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Noob Corner]]></category>
		<category><![CDATA[Ramblings]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=240</guid>
		<description><![CDATA[Integrated development environments make developing application fair easier. They highlight syntax, let you know if you have a compilation error, and allow you to step through your code among so many other things. Like all IDEs Eclipse has a bunch of little shortcuts and tools that can make your life a lot easier, I've compiled [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2F12-tips-to-make-you-more-productive-using-eclipse"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2F12-tips-to-make-you-more-productive-using-eclipse" height="61" width="51" /></a></div><p>Integrated development environments make developing application fair easier. They highlight syntax, let you know if you have a compilation error, and allow you to step through your code among so many other things. Like all IDEs Eclipse has a bunch of little shortcuts and tools that can make your life a lot easier, I've compiled a list of several that I use on a daily basis:</p>
<p><strong>1. Auto-complete</strong> – Eclipse has an auto-complete feature that can be accessed with ctrl + space. When clicked a small pop-up box is displayed with a list of context sensitive suggestions. If there is only one possibility then Eclipse completes it for you.<br />
<span id="more-240"></span><br />
<strong>2. Quickly format your code</strong> – Code that is being heavily modified can quickly become an ugly sight. Without proper indention it can become extremely difficult to determine what is happening in code. Code can be quickly formatted using the shortcut: Ctrl + shift + F. You can even setup your own style rules by going to: Project&gt;Preferences&gt;Java Code Style&gt;Formatter, check “enable project specific settings” edit the profile and then save it under a new name.</p>
<p><strong>3. Get rid of unnecessary code </strong>– Heavily worked on projects that aren't maintained well can quickly build up a bunch of unnecessary imports, casts, among other common easily detectable coding mistakes. Quickly remove these mistakes by running a code clean up. Right click on your project folder&gt;source&gt;clean up. Like the code formatter you can also customize your code clean up.</p>
<p><strong>4. Go to declaration</strong> – Want to know where that method, variable, or class is declared? This can easily be done by holding down ctrl and then clicking on the reference.</p>
<p><strong>5. Find all references</strong> – If you need to find all the references for a method, variable, or class highlight the desired reference right click&gt;reference and select the desired search scope.</p>
<p><strong>6. Quickly select groups of characters</strong> – Need to delete an entire string, or everything within a method's argument declaration? Select the enclosing character (e.g. the “ or "(" respectively), this will select everything within the enclosing characters. This even works with the bodies of classes and methods. You can also select an entire line by triple clicking.</p>
<p><strong>7. Rename all instances </strong>– If you need to rename a method, variable, or class you can rename ever instance by highlighting a reference and pressing alt + shift + r an box will highlight the reference and you can rename it. Upon pressing enter all instance will be renamed in your project.</p>
<p><strong>8. Change a method signature</strong> – If you need to change any part of a methods signature; a methods name, its arguments, or return type, you can quickly make a change to all references of the method in the project by highlighting the method and pressing alt + shift + c a pop-up box will appear giving you options to change the method's signature.</p>
<p><strong>9. Automatically generate getters and setters</strong> – Writing getters and setters is for suckers. After you write out all the members of a class right click anywhere in the code screen&gt;source&gt;generate getters and setters. Select the variables you want to have getters and setters made for.</p>
<p><strong>10. Javadoc is a cinch</strong> – Eclipse makes writing Javadoc easy, just type “/**” and press eneter above a declaration. Eclipse automatically creates context sensitive Javadoc annotations (i.e. a methods parameters, or the author of a class). After that you only have to write out what the method actually does.</p>
<p><strong>11. Run a unit test</strong> – To run a unit test highlight the unit test and press alt + shift + x followed by t. You can also run a unit test in the debugger by pressing alt + shift + <span style="text-decoration: line-through;"></span>d followed by t.</p>
<p><strong>12. Comment out code</strong> – If you need to quickly comment out a chunk of code, highlight the corresponding lines and press ctrl + /, you can uncomment code the say way.</p>
<p>Chime in with your own Eclipse shortcuts.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x60, created 9/14/09 */
google_ad_slot = "1115297999";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/12-tips-to-make-you-more-productive-using-eclipse/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>8 tips for new programmers</title>
		<link>http://www.turnleafdesign.com/8-tips-for-new-programmers</link>
		<comments>http://www.turnleafdesign.com/8-tips-for-new-programmers#comments</comments>
		<pubDate>Tue, 06 Oct 2009 03:32:11 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Noob Corner]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=168</guid>
		<description><![CDATA[A successor in spirt to my 7 tips for every person wishing to be a programmer, here are 8 tips for when you finally land your first development job. These tips will hopefully help prepare you for your new job, or help get you up to speed with the rest of your team.
1.You don't know [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2F8-tips-for-new-programmers"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2F8-tips-for-new-programmers" height="61" width="51" /></a></div><p>A successor in spirt to my <a href="http://www.turnleafdesign.com/?p=114" target="_blank">7 tips for every person wishing to be a programmer</a>, here are 8 tips for when you finally land your first development job. These tips will hopefully help prepare you for your new job, or help get you up to speed with the rest of your team.</p>
<p><strong>1.You don't know anything</strong> – So you finally have your degree and after four years of intensive studying you think you know everything there is to know about programming. Like every other developer you will soon learn (or already have) that you know nothing. Be humble, put in your hard work, and know that over time you will learn.<span id="more-168"></span></p>
<p><strong>2.Ask questions</strong> – As you come across bugs, or areas of code that you don't understand, ask a developer on your team for help or an explanation. Make these questions opportunities to learn, don't just ask what a section of code is doing, but why it was written the way it was.</p>
<p><strong>3.Study up</strong> – If you have free time at work or home, use it to learn about a concept you are having trouble with. <a href="http://www.coderanch.com/forums" target="_blank">Talk to other developers</a>, look at code examples, or Google it/read a book. (Author note: maybe start a blog and let everybody know what you have learned)</p>
<p><strong>4.Don't break the build</strong> – Everybody is guilty of it, but whenever you check your code into the repository make sure it is in a compilable state, there is nothing more frustrating to a developer then to get the latest code from the repository only to find out it doesn't work. A reputation of breaking the build is not one you want to gain.</p>
<p><strong>5.Learn shop standards</strong> – Every shop has a different way writing code and/or fixing problems. Take time to learn how your shop behaves. While it may had been ok to constantly restart the server when working on a project in school, it probably won't fly with your coworkers.</p>
<p><strong>6.Comment when you check in code</strong> – When you check code into the repository make sure you say why you are checking it in. This can greatly help when attempting a fix a bug that has recently been introduced into the code base. The more descriptive the better, but even a simple “Fixing issue #123” or “Fixed login bug” is far better than nothing.</p>
<p><strong>7.It has probably already been done </strong>– Every business has industry specific issues to deal with. For example data may need to be in a certain format before it can be inserted into the database. So check with other developers or look through the code base to see if a solution already exists to a seemingly common business requirement.</p>
<p><strong>8.Learn about the industry you are in</strong> – Understanding the needs of the users that will be using the application(s) you are working on will help save time by catching poorly written or counter-intuitive business requirements. Just like developers have QA to catch the mistakes we make, developers must occasionally catch the mistakes of business rule writers. If you think there are any other tips I missed please feel free to add them in the comments section.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x60, created 9/14/09 */
google_ad_slot = "1115297999";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Best+practices' rel='tag' target='_blank'>Best practices</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/8-tips-for-new-programmers/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>A brief intro into unit testing with JUnit</title>
		<link>http://www.turnleafdesign.com/a-brief-intro-into-unit-testing-with-junit</link>
		<comments>http://www.turnleafdesign.com/a-brief-intro-into-unit-testing-with-junit#comments</comments>
		<pubDate>Wed, 30 Sep 2009 23:42:10 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Noob Corner]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Unit testing]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=145</guid>
		<description><![CDATA[Learning how to use the built-in IDE debuggers and write unit tests is as fundamental to being a developer as knowing how to write a for loop. These two tools will save you countless hours of frustration and help you write better code. Entire books are written on just these subjects, however today I will [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fa-brief-intro-into-unit-testing-with-junit"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fa-brief-intro-into-unit-testing-with-junit" height="61" width="51" /></a></div><p>Learning how to use the built-in IDE debuggers and write unit tests is as fundamental to being a developer as knowing how to write a for loop. These two tools will save you countless hours of frustration and help you write better code. Entire books are written on just these subjects, however today I will just give a simple tutorial on writing unit tests.<span id="more-145"></span> In this example I will be testing a <a href="http://www.turnleafdesign.com/?p=52" target="_blank">JavaBean</a> that could be used in a simple inventory system. You can download the project <a href="http://turnleafdesign.com/code_examples/UnitTestExample.zip" target="_blank">here</a>. If you need help setting up the project you can follow the instructions <a href="http://www.turnleafdesign.com/?page_id=142" target="_blank">here</a>.</p>
<blockquote><p>package com.dining;</p>
<p>public class Item {<br />
public String name;<br />
public int id;</p>
<p>public Item(String name, String id) throws IllegalArgumentException{<br />
if((name != null &amp;&amp; !name.equalsIgnoreCase("")) &amp;&amp; (id != null &amp;&amp; !id.equalsIgnoreCase("") &amp;&amp; id.matches("\\d*"))){<br />
this.name = name;<br />
this.id = Integer.parseInt(id);<br />
} else {<br />
throw new IllegalArgumentException("Invalid argument(s)");<br />
}<br />
}</p>
<p>public String getName() {<br />
return name;<br />
}</p>
<p>public void setName(String name) {<br />
this.name = name;<br />
}</p>
<p>public int getId() {<br />
return id;<br />
}</p>
<p>public void setId(int id) {<br />
this.id = id;<br />
}<br />
}</p></blockquote>
<p>For my unit test I want to make sure my two argument constructor is working as expected. That is, it will require me to give a valid name, a String object with at least one character, and a valid id, a number. If either of these arguments are incorrect I will throw an IllegalArgumentException.</p>
<p>First we need to create a unit test class to run unit tests. To do this I will create a JUnit class, in Eclipse you can right click in your package explorer view and in the pop menu scroll down to the “JUnit” option, be sure to do this under the “com.unittest” package in the “test” folder. I will be using JUnit 3 for this example. The convention for naming for unit test classes is “Test” followed by the name of the class you will be testing, so in this case “TestItem.” The defaults should be fine so go ahead and click ok.</p>
<p>Each unit test case is its own method. Again the convention with unit tests is to start the name with “test” followed by the method under test. This is can be a looser practice as you might want to name the unit test based upon the type of test your are running. In this case I will name the unit test “testItemValidArguments” because I will be only passing valid arguments into the constructor. Inside the unit test you will make a call to the method you are testing and you will run an assertion to check to make sure the right value is being returned. There are numerous assertion types:</p>
<p>assetEquals(expected, actual) which compares what you are expecting to what is actually returned<br />
assertTrue(condition) expects the passed condition to return true<br />
assertFalse(condition) expects the passed condition to return false</p>
<p>There are a couple of other ways of running tests but these are the major ones. When these methods return an unexpected value; unequal values, false when true expected and vice versa, this causes the test to fail. If you are running your test in Eclipse the JUnit view will display red. Conversely if the test passes the JUnit view will display Green.</p>
<p>So lets write our first unit test:</p>
<blockquote><p>public void testItemValidArguments() {<br />
Item item = new Item("Wrench", "1");<br />
assertEquals(2, item.getId());<br />
}</p></blockquote>
<p>No, I did not make a typo, go ahead and run the test an see what happens. Your test should fail (if it doesn't you have a problem). The JUnit view should look like this:<br />
<img src="http://turnleafdesign.com/code_examples/UnitTestImages/Picture%202.png" alt="" /></p>
<p>JUnit will let you know when you failed a test. In this case it's telling us that it was expecting “2” to be returned, but actually got “1.” Go ahead and change the expected value back to “1” and run the test again and it should pass. Ok so when we pass valid arguments the constructor works correctly. Now let's make sure the constructor lets us know when the arguments passed in are not valid. Let's write another units test:</p>
<blockquote><p>public void testIteamInvalidArguments() {<br />
Item item = new Item("Wrench", "A");<br />
assertEquals(“A”, item.getId());<br />
}</p></blockquote>
<p>Try running the test. Your JUnit view should look like this:<br />
<img src="http://turnleafdesign.com/code_examples/UnitTestImages/Picture%203.png" alt="" /><br />
Well good news bad news. The constructor validates the second field correctly, it is requiring a number, however we don't want our unit tests failing. All unit tests should “pass” when they run correctly so a change needs to be made. To cut to the chase this is one possible way of fixing the unit test:</p>
<blockquote><p>public void testIteamInvalidArguments() {<br />
try {<br />
Item item = new Item("Wrench", "A");<br />
fail("You should have thrown an exception!");<br />
} catch (IllegalArgumentException e) {<br />
//Do nothing<br />
}<br />
}</p></blockquote>
<p>As long as a fail is not returned within a JUnit test case the test passes, so in the test case if the IllegalArgumentException is thrown then we won't do anything because we are expecting that, however if the exception is not thrown then we want the test to fail. So on the line below where I create an Item object I call fail() and pass in a message, so if the exception is not thrown the test will fail and I will know I have a problem (and a message will be displayed in the JUnit view).</p>
<p>I will end my tutorial here. This should be enough to get your feet wet in unit testing. There are several other tests that could be written, for example checking to make sure name validation works. I plan on covering this subject in more depth so check back later. This is my first real tutorial, so please let me know if I glossed over anything. If you have any other questions please let me know.</p>
<p style="text-align: center;"><script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x15, created 9/22/09 */
google_ad_slot = "6237316105";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Best+practices' rel='tag' target='_blank'>Best practices</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a>, <a class='technorati-link' href='http://technorati.com/tag/Testing' rel='tag' target='_blank'>Testing</a>, <a class='technorati-link' href='http://technorati.com/tag/Unit+testing' rel='tag' target='_blank'>Unit testing</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/a-brief-intro-into-unit-testing-with-junit/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>7 tips for every person wishing to be a programmer</title>
		<link>http://www.turnleafdesign.com/7-tips-for-every-person-wishing-to-be-a-programmer</link>
		<comments>http://www.turnleafdesign.com/7-tips-for-every-person-wishing-to-be-a-programmer#comments</comments>
		<pubDate>Sun, 27 Sep 2009 23:20:35 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Noob Corner]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=114</guid>
		<description><![CDATA[If you are interested in pursuing a career in software development these tips could help make the road to accomplishing that goal a lot less bumpy. Below is seven tips that can help prepare you for a career in software development and make the first few months a lot less painful. 
1.Don't accept the minimum [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2F7-tips-for-every-person-wishing-to-be-a-programmer"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2F7-tips-for-every-person-wishing-to-be-a-programmer" height="61" width="51" /></a></div><p>If you are interested in pursuing a career in software development these tips could help make the road to accomplishing that goal a lot less bumpy. Below is seven tips that can help prepare you for a career in software development and make the first few months a lot less painful. <span id="more-114"></span></p>
<p><strong>1.Don't accept the minimum</strong> – You get minimal returns from minimal work. You're not just going to school to get a degree so you can get a job, but to get an education so you can actually do that job. After completing a project look for ways you can improve upon your work and/or expand on the scope of the project.</p>
<p><strong>2.Learn from a code guru</strong> – Be it a professor or someone else, if you know a capable developer take time to learn from him/her. Don't just blithely look at the developer as someone to find the bug in your code, but a means to writing better code. There are also plenty of good forums out there, such as this one for <a href="http://www.coderanch.com/forums/f-33/Beginning-Java" target="_blank">Java developers</a></p>
<p><strong>3.Be multi-lingual</strong> – Don't pigeonhole yourself into only knowing one programming language, learn a couple of languages outside your college curriculum. I would strongly suggest Java and C# as both are widely used in industry. Other good ones would be C++ and PHP.</p>
<p><strong>4.Learn how to use the debugger</strong> – Understanding how to use the debugger that comes built-in to virtually every IDE will save you countless hours of frustration. For those who use Eclipse I would recommend these <a href="http://eclipsetutorial.sourceforge.net/debugger.html" target="_blank">video casts</a>.</p>
<p><strong>5.Learn how to work in a team</strong> – Working as a team in software development introduces new dynamics. Often projects are dependent upon other projects and if one of projects you depend doesn't work you might find yourself incapable of dong work. There are also issues that arise from working on the same code file concurrently. Having experience in this area can be very helpful and potentially avoid ugly situations with your co-workers. I would also recommend looking into using <a href="http://en.wikipedia.org/wiki/Revision_control" target="_blank">version control software</a> when working in a team.</p>
<p><strong>6.Do projects on the side</strong> – Showing you have done work outside of the classroom not only shows you are a motivated developer, but it will also goes a long ways towards fleshing out your knowledge. This could be a good opportunity to learn how to work in a team.</p>
<p><strong>7.Get an internship</strong> – Work with your university (or your own personal connections) to get an internship. Many companies see internships as extended interviews so this is an excellent way to get your foot in the door. Don't limit yourself to only development internship positions either, I worked as a QA intern prior to obtaining my development job.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x60, created 9/14/09 */
google_ad_slot = "1115297999";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Best+practices' rel='tag' target='_blank'>Best practices</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/7-tips-for-every-person-wishing-to-be-a-programmer/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>If, else and nothing else</title>
		<link>http://www.turnleafdesign.com/if-else-and-nothing-else</link>
		<comments>http://www.turnleafdesign.com/if-else-and-nothing-else#comments</comments>
		<pubDate>Sat, 19 Sep 2009 19:52:03 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Noob Corner]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=81</guid>
		<description><![CDATA[When I was still very new to programming I had a bad habit of writing bloated code. One of my worse areas was when it came to the usage of If statements. Often times I would write a whole if/else block when I could had just as easily gotten the same results in just one [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fif-else-and-nothing-else"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fif-else-and-nothing-else" height="61" width="51" /></a></div><p>When I was still very new to programming I had a bad habit of writing bloated code. One of my worse areas was when it came to the usage of If statements. Often times I would write a whole if/else block when I could had just as easily gotten the same results in just one line of code.<span id="more-81"></span></p>
<blockquote><p>public class IfExample {</p>
<p>public static void main(String[] args){<br />
boolean getBoolValue;<br />
int a = 1, b = 2;</p>
<p>if(a &gt; b){<br />
getBoolValue = true;<br />
} else{<br />
getBoolValue = false;<br />
}<br />
}</p></blockquote>
<p>Instead of writing the whole if/else statement instead you can just directly take the result of the test condition.</p>
<blockquote><p>getBoolValue = a &gt; b;</p></blockquote>
<p>Some prefer to put parentheses around the comparison, however they are optional. I personally prefer a more minimalist code style.</p>
<h3>Be the ternary</h3>
<p>So what if you need something other than a boolean value? Enter the Java ternary operator. Which looks like this:</p>
<blockquote><p>String isEven = (3 % 2 == 0) ? "Yes" : "No";</p></blockquote>
<p>The element before the “?” is the test condition that is to be performed. The element before the “:” is the value that will be returned if the test condition is true and the element after the “:” is what will be returned if the test condition is false.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x60, created 9/14/09 */
google_ad_slot = "1115297999";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Java' rel='tag' target='_blank'>Java</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/if-else-and-nothing-else/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>What are Java beans?!</title>
		<link>http://www.turnleafdesign.com/52</link>
		<comments>http://www.turnleafdesign.com/52#comments</comments>
		<pubDate>Thu, 17 Sep 2009 01:21:53 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Noob Corner]]></category>
		<category><![CDATA[Ramblings]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=52</guid>
		<description><![CDATA[Sometimes developers use programming jargon that new developers have a hard time comprehending. One term I frequently hear is “bean.” All a JavaBean is, is a class used to define the attributes of a entity; examples of commonly used beans would be person, customer, and employee. A JavaBean typically only contain private attributes and the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2F52"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2F52" height="61" width="51" /></a></div><p>Sometimes developers use programming jargon that new developers have a hard time comprehending. One term I frequently hear is “bean.” All a JavaBean is, is a class used to define the attributes of a entity; examples of commonly used beans would be person, customer, and employee. A JavaBean typically only contain private attributes and the getter and setter methods to access and set those attributes respectively. <span id="more-52"></span>Here is a simple example of what a Java bean looks like:</p>
<blockquote><p>public class Employee {<br />
private String firstName;<br />
private String lastName;<br />
private int yearsExp;<br />
private String title;<br />
private double salary;</p>
<p>public String getFirstName() {<br />
return firstName;<br />
}</p>
<p>public void setFirstName(String firstName) {<br />
this.firstName = firstName;<br />
}</p>
<p>public String getLastName() {<br />
return lastName;<br />
}</p>
<p>public void setLastName(String lastName) {<br />
this.lastName = lastName;<br />
}</p>
<p>public int getYearsExp() {<br />
return yearsExp;<br />
}</p>
<p>public void setYearsExp(int yearsExp) {<br />
this.yearsExp = yearsExp;<br />
}</p>
<p>public String getTitle() {<br />
return title;<br />
}</p>
<p>public void setTitle(String title) {<br />
this.title = title;<br />
}</p>
<p>public double getSalary() {<br />
return salary;<br />
}</p>
<p>public void setSalary(double salary) {<br />
this.salary = salary;<br />
}<br />
}</p></blockquote>
<p>JavaBeans are also commonly referred to as POJOs (Plain old Java objects). The terms are not entirely synonymous, <a href="http://en.wikipedia.org/wiki/Plain_Old_Java_Object">as a POJO refers to a specific type of class</a>, but is none the less often used interchangeably.</p>
<p>Tip: Most IDEs can automatically generate the getter and setter methods for a class' attributes, so don't waste your precious time doing it! In Eclipse just right click any where on the code screen select source&gt;generate getters and setters, and follow the instructions. Simple as pie!<br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x60, created 9/14/09 */
google_ad_slot = "1115297999";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.01 -->

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/52/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How Java handles objects</title>
		<link>http://www.turnleafdesign.com/how-objects-work-in-java</link>
		<comments>http://www.turnleafdesign.com/how-objects-work-in-java#comments</comments>
		<pubDate>Tue, 15 Sep 2009 04:14:23 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Noob Corner]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=5</guid>
		<description><![CDATA[How Java handles objects had always been a thorny issue for me. I don't know if it was a case of never being taught properly or my personal inability to learn, but I either way by the time I began my professional development career I only had very loose understanding of how Java handles objects. [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fhow-objects-work-in-java"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fhow-objects-work-in-java" height="61" width="51" /></a></div><p>How Java handles objects had always been a thorny issue for me. I don't know if it was a case of never being taught properly or my personal inability to learn, but I either way by the time I began my professional development career I only had very loose understanding of how Java handles objects. This gap in my knowledge impacted my ability to be an effective developer; my code had more bugs and implementing changes was more difficult. I remember many of my friends back in school also having trouble here, so I will spend my first real post (yay!) covering this important subject.<span id="more-5"></span></p>
<h3>All object variables are pointers</h3>
<p>Probably one of the first things you learned, or at least heard, about Java, was all object variables are pointers, but what does this mean and what are the implications? In simplest terms it means that a variable that holds an object doesn't actually store the value of the object, but its location in memory. Take for example the code snippet below:</p>
<p>String name = “Bob”;</p>
<p>The variable “name” doesn't hold the value “Bob,” but the location of where “Bob” is stored in memory. It's a difficult concept to grasp, I hope to make it easier to understand as well as go over the significance of this characteristic below.</p>
<h3>The implications</h3>
<p>So an object variable holds reference to an address in memory, but how will it effect your day to day programming? Well probably the first problem every programmer runs into when working with objects is comparing two Strings using the “==” operator instead of “.equals().” Using the “==” operator doesn't work as excepted on Strings (or any object), because like stated previously object variables do not contain the value of an object, but the address to where the value is stored. So when you are performing this operation: (name == “Bob”), you are actually comparing the the addresses in memory of the two objects, not their values. Whereas with name.equals(“Bob”) you are retrieving the value stored at the memory address the name variable references and comparing it to the String object passed into the equals(String) method. So while comparing two strings, or any other object requires more work than comparing two primitive data types like int or char there are some advantages.</p>
<h3>Passing by reference can often be used in place of returning</h3>
<p>Before I fully understood objects, if I wanted to use a method to manipulate an object I would often have that method returning a value. An example of this:</p>
<blockquote><p>public class ObjectExample {</p>
<p>public static void main(String args[]){<br />
Person a = new Person()<br />
a = changeFirstName(a);<br />
System.out.println(a.getFirstName());<br />
}</p>
<p>public static Person changeFirstName(Person a){<br />
a.setFirstName("Joe");<br />
//Prints Joe<br />
return a;<br />
}<br />
}</p></blockquote>
<p>While there is technically nothing wrong with this behavior, it is not the most efficient or readable way of handling this scenario. Also as you will likely notice in my next example the return statement is largely redundant. So here is an example of passing by reference:</p>
<blockquote><p>public class ObjectExample {</p>
<p>public static void main(String args[]){<br />
Person a = new Person();<br />
changeFirstName(a);<br />
System.out.println(a.getFirstName());<br />
//Prints Joe<br />
}</p>
<p>public static void changeFirstName(Person a){<br />
a.setFirstName("Joe");<br />
}<br />
}</p></blockquote>
<p>This code prints the name “Joe”, because remember you are not passing the value of the object, but its address in memory. So the method changeFirstName(Person) is manipulating the value stored at the address of the Person object passed in.</p>
<h3>Remember</h3>
<p>When you assign an object variable to another object variable you are not copying the value of the assigner variable to the assignee, but the reference. What this means is when you change the value of either variable, you change the value for both variables as shown in the example below:</p>
<blockquote><p>public class ObjectExample {</p>
<p>public static void main(String args[]){<br />
Person a = new Person();<br />
Person b = a;</p>
<p>a.setFirstName("Joe");</p>
<p>System.out.println(a.getFirstName());<br />
//prints Joe<br />
System.out.println(b.getFirstName());<br />
//prints Joe<br />
}<br />
}</p></blockquote>
<p>That sums up a fairly basic overview of how Java handles objects. If you have any questions or comments please leave a comment and I will try to respond as best I can.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x60, created 9/14/09 */
google_ad_slot = "1115297999";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Java' rel='tag' target='_blank'>Java</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/how-objects-work-in-java/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
