<?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>TechieDan &#187; Tutorial</title>
	<atom:link href="http://techiedan.com/category/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://techiedan.com</link>
	<description>Your Search for The Tech Stuffs</description>
	<lastBuildDate>Tue, 22 May 2012 08:10:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>SEO Help From Expert</title>
		<link>http://techiedan.com/2012/05/17/seo-help-expert/</link>
		<comments>http://techiedan.com/2012/05/17/seo-help-expert/#comments</comments>
		<pubDate>Wed, 16 May 2012 19:33:42 +0000</pubDate>
		<dc:creator>techieDan</dc:creator>
				<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://techiedan.com/?p=1318</guid>
		<description><![CDATA[<p>Finally you created your website. Problem is you published the site and expecting people to locate your webpage on the Internet search engines. After few days, you use the search engine and still could not find lots of searches for your site. Something must be wrong. What do we call these? That is where something [...]]]></description>
			<content:encoded><![CDATA[<p>Finally you created your website. Problem is you published the site and expecting people to locate your webpage on the Internet search engines. After few days, you use the search engine and still could not find lots of searches for your site. Something must be wrong. What do we call these? That is where something called Search Engine Optimization comes into mind.</p>
<p><img class="alignnone size-full wp-image-1319" title="SEO" src="http://techiedan.com/wp-content/uploads/2012/05/seo.jpg" alt="SEO" width="400" height="300" /></p>
<p>Nowadays there are many people out there who sought help from SEO experts to help garner hits to their websites, thus ensuring that they are back on top of the search engines. One can also look at SEO tips from SEO sites like <a href="http://2chixseo.com/category/tips-and-stuff/">2chix Seo Service Company</a> which has a very funky name to it. 2chix? Well considerably it is really 2 females behind the foundation of this company that will help in your SEO ranking.</p>
<p>TechieDan ain&#8217;t gonna lie, as his website still has moderate SEO elements to help push him up the search engines, but there are also many SEO alternatives not done yet. One simple SEO that I can teach you is do write proper names for your post. If you still do not get it, you may consult me for some simple help.</p>
<p>Of course SEO is not really for anyone and also not for those who does not want the unnecessary limelight to their personal blogs. Though there is a catch, if you do not bother about SEO and you are running CPM ads on your blog, you will lose the big fish. Of course, but that is another story though.</p>
]]></content:encoded>
			<wfw:commentRss>http://techiedan.com/2012/05/17/seo-help-expert/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL LIKE query in PHP mysqli error</title>
		<link>http://techiedan.com/2011/11/30/sql-like-query-in-php-mysqli-error/</link>
		<comments>http://techiedan.com/2011/11/30/sql-like-query-in-php-mysqli-error/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 05:45:08 +0000</pubDate>
		<dc:creator>techieDan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[mysqli]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[preparedstatement]]></category>

		<guid isPermaLink="false">http://techiedan.com/?p=1201</guid>
		<description><![CDATA[mysqli preparedstatement for SQL LIKE for php has some small bugs. You have to use CONCAT to solve this part. Perfect for those people in php development shifting from mysql to mysqli]]></description>
			<content:encoded><![CDATA[<p>A while back, Techiedan has started using <strong>mysqli in his php testing</strong> and education. Seemingly all seemed to work fine as there is no need for real_escape_string of the old mysql php syntax. There is now the new <strong>preparedstatement</strong> (<em>it is actually quite a long time but recently caught on as more is aware of it</em>)</p>
<p><img title="PHP Logo" src="http://techiedan.com/wp-content/uploads/2011/11/php-logo.jpg" alt="PHP Logo" width="400" height="210" /></p>
<p>Though an issue arose which I would like to address. Seemingly MySQL queries like this happen sometimes.</p>
<blockquote><p><strong>&#8220;SELECT card_name FROM cards WHERE card_name like %some kind of string%&#8221;;</strong></p></blockquote>
<p>In the older php mysql we would just replace the string into the syntax. For the improved mysqli, we would use the question mark (?) instead.</p>
<blockquote><p><strong>&#8220;SELECT card_name FROM cards WHERE card_name LIKE %?%&#8221;;</strong></p></blockquote>
<p>From the syntax it should work right? Here is the initial program in php.</p>
<pre class="brush: php; title: ; notranslate">
$con = mysqli_connect($nameIp,$nameAdmin,$namePass,$nameDataB);
$card2Name = $_REQUEST[&quot;cardName&quot;];
$query = &quot;select card_name from mtg_card where card_name like %?%&quot;;
$stmt = mysqli_prepare($con,$query);
$stmt-&gt;bind_param(&quot;s&quot;,$card2Name);
$stmt-&gt;execute();
$stmt-&gt;bind_result($abc);
</pre>
<p>Running this though has given the following errors though.</p>
<blockquote><p><strong>Fatal error: Call to a member function bind_param() on a non-object</strong></p></blockquote>
<p>Was there something wrong? So trying to figure it out, here was another way that TechieDan tried.</p>
<pre class="brush: php; title: ; notranslate">
$query = &quot;select card_name from mtg_card where card_name like ?&quot;;
$stmt = mysqli_prepare($con,$query);
$stmt-&gt;bind_param(&quot;s&quot;,&quot;%&quot;.$card2Name.&quot;%&quot;);
</pre>
<p>Another way, though after testing it produced this error.</p>
<blockquote><p>Fatal error: Cannot pass parameter 2 by reference</p></blockquote>
<p>Seems like it is getting error after error even though the syntax should be correct!</p>
<p>After going through the Internet on what certain error meant and also some play testing it looks like someone has mentioned that mysqli does not parse the query properly. We would have to use CONCAT to solve it.</p>
<pre class="brush: php; title: ; notranslate">
$query = &quot;select card_name from mtg_card where card_name like CONCAT('%',?,'%')&quot;;
$stmt = mysqli_prepare($con,$query);
$stmt-&gt;bind_param(&quot;s&quot;,$card2Name);
$stmt-&gt;execute();
$stmt-&gt;bind_result($abc);
</pre>
<p>Look at the syntax. What was changed was just the $query line. It seems it is the LIKE clause for mysqli should be used this way.</p>
]]></content:encoded>
			<wfw:commentRss>http://techiedan.com/2011/11/30/sql-like-query-in-php-mysqli-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Auto Submit Form in IE using VB Script</title>
		<link>http://techiedan.com/2011/11/29/auto-submit-form-in-ie-using-vb-script/</link>
		<comments>http://techiedan.com/2011/11/29/auto-submit-form-in-ie-using-vb-script/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 03:43:39 +0000</pubDate>
		<dc:creator>techieDan</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://techiedan.com/?p=1186</guid>
		<description><![CDATA[Automate Sending a form using VB Script by opening Internet Explorer. All just by clicking the vbscript and sending to GMAIL. Login at your convenience. Can be done at almost every login forms. Modify it to your hearts content. ]]></description>
			<content:encoded><![CDATA[<p>Sometimes developers, users and scripters are so lazy to process <strong>form submission on the Internet</strong>, they have to write some scripts to help them <strong>automate the submission of a form</strong>.</p>
<p>This is where TechieDan will roughly teach you how to abuse this script sending to form. Utilizing <strong>Internet Explorer</strong> (IE) and <strong>vbscript</strong>, I will automate sending a login to GMail.</p>
<p>Create an empty text document as name it anything you like ex: gmail-automate.vbs<br />
Let’s begin with the vbscript opening an Internet Explorer application to run it.</p>
<pre>Set IE = CreateObject("InternetExplorer.Application")</pre>
<p>Now we have to designate the URL the Internet Explorer needed to run.</p>
<pre>IE.Navigate "http://www.gmail.com"
IE.Visible = True</pre>
<p>Surprise? It opens up an Internet Explorer at the page we are looking at. Now for each form, it is understood that all of them have different property names and that is where we have to first do a manual investigation of the form properties.</p>
<p>Added a timer so that the form would be able to take some time to load before it submits. Also if you wanted to, you can use IE.Busy to check if it finished loading</p>
<pre>Wscript.Sleep 6000</pre>
<p>Finally it is time to put in your details and this will work.</p>
<pre>IE.Document.All.Item("Email").Value = "<span style="color: #ff0000;">youremail</span>"
IE.Document.All.Item("Passwd").Value = "<span style="color: #ff0000;">yourpassword</span>"
IE.Document.All.Item("signIn").Click</pre>
<p><span style="text-decoration: underline;"><strong>Thoughts</strong></span><br />
Using the above method works. Of course by understanding this concept, one could actually write a script which might subsequently try to login as many times by doing a loop function (after submit – reload form – and so on). We are getting lazier by the moment but sometimes it is the convenience of just a click and we are in.<br />
For those still clueless, below is the final script.</p>
<pre>Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "http://www.gmail.com"
IE.Visible = True
Wscript.Sleep 6000
IE.Document.All.Item("Email").Value = "<span style="color: #ff0000;">youremail</span>"
IE.Document.All.Item("Passwd").Value = "<span style="color: #ff0000;">yourpassword</span>"
IE.Document.All.Item("signIn").Click</pre>
<p>Do note that you should use this wisely.</p>
]]></content:encoded>
			<wfw:commentRss>http://techiedan.com/2011/11/29/auto-submit-form-in-ie-using-vb-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Center a Page using CSS</title>
		<link>http://techiedan.com/2011/11/15/center-a-page-using-css/</link>
		<comments>http://techiedan.com/2011/11/15/center-a-page-using-css/#comments</comments>
		<pubDate>Tue, 15 Nov 2011 04:45:27 +0000</pubDate>
		<dc:creator>techieDan</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[IE]]></category>

		<guid isPermaLink="false">http://techiedan.com/?p=1170</guid>
		<description><![CDATA[How do you center a page using CSS? It is pretty easy, but then there is also an issue with Internet Explorer where it does not center the page. A simple CSS modification would help it. Follow these steps. It will solve your IE CSS headache. ]]></description>
			<content:encoded><![CDATA[<p>IE is giving a headache. All TechieDan wanted to do was to do a <strong>centering of the specific &lt;div&gt; in the web page</strong>.  That also brought me to think that this would actually be enough. Of course, if you are looking to do a centering vertically, then this is not the page you are looking for.</p>
<pre class="brush: css; title: ; notranslate">
#page {
width: 800px;
margin: auto;
}
</pre>
<p>Surprisingly most of my developments and testing were done on Mozilla&#8217;s very own Firefox. After finishing the testing and procedures it was time to put it online to the World Wide Web. Little did TechieDan know, something was practically wrong when I have comments saying that the <strong>web page looks out of place and not in order</strong>?</p>
<p>This baffled TechieDan for some time until he tried using Internet Explorer to view the desired page. It was freaking out of place. Looks like some modifications were needed. It seems that <strong>IE does not really render the CSS given properly</strong> and needed some IE hack to help resolve this CSS issue.</p>
<p>Here is how to resolve the <strong>centering of a page or a div or anything you wanted which also would display properly in Internet Explorer</strong>.<br />
Add this to your CSS.</p>
<pre class="brush: css; title: ; notranslate">
body {
text-align: center;
}
</pre>
<p>It seems that IE has very weird way of solving this issue. Of course, by doing so in the body, everything else would also be centered. This is where you would only want the page to be centered but not the text or the elements in it.</p>
<pre class="brush: css; title: ; notranslate">
#page {
width: 800px;
margin: auto;
text-align: left; //add this part too
}
</pre>
<p>From the desired element, put <em><strong>text-align: left;</strong></em> and it now should work very well. EGADS!!!! It has been awhile since a new post.</p>
]]></content:encoded>
			<wfw:commentRss>http://techiedan.com/2011/11/15/center-a-page-using-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java &#8211; Compare Strings</title>
		<link>http://techiedan.com/2011/06/07/java-compare-strings/</link>
		<comments>http://techiedan.com/2011/06/07/java-compare-strings/#comments</comments>
		<pubDate>Tue, 07 Jun 2011 03:58:45 +0000</pubDate>
		<dc:creator>techieDan</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[StringUtils]]></category>

		<guid isPermaLink="false">http://techiedan.com/?p=1126</guid>
		<description><![CDATA[Comparing Strings in Java has evolved from the character comparisons to String comparisons to StringUtils comparison. Using the StringUtils to compare Strings is so much safer and faster to code.]]></description>
			<content:encoded><![CDATA[<p>During the old Java days, the String object was a object to store a string of characters. Those days to <strong>compare Strings in Java</strong>, one would have to break down the characters in the String and compare them character by character.</p>
<p>Of course fast forward to the time now, one can just use the String methods to accomplish this. All thanks to the guys behind Java. Now how do we compare it now in Java? We would use Java 6 for this.</p>
<p><img class="alignnone size-full wp-image-1134" title="Why Choose Java Language" src="http://techiedan.com/wp-content/uploads/2011/06/why-choose-java-language.jpg" alt="Why Choose Java Language" width="480" height="272" /></p>
<p>The common way people use to compare Strings is the</p>
<p><strong>String.equals();</strong> or the <strong>String.equalsIgnoreCase();</strong></p>
<pre class="brush: java; title: ; notranslate">
package com.Test;

public class TestString {

  public static void main(String... args) {

  // The 2 strings that we will test
  String testA = &quot;Welcome&quot;;
  String testB = &quot;Bye&quot;;

  // The additional String which is set to null
  String testC = null;

  if (testA.equals(testB))
    System.out.println(&quot;It is the same&quot;);
  else
    System.out.println(&quot;It is different&quot;);

  // Test it when testC is assigned to testA

  testA = testC;
  if (testA.equals(testB))
    System.out.println(&quot;Not same&quot;);

  System.exit(0);
  }

}
</pre>
<p>The above is the example of how to compare two Strings using equals. If you were to run the above code, a <strong>runtime error would occur</strong>upon running this application. How could this happen?</p>
<p>Reason is due to this syntax!</p>
<pre class="brush: java; title: ; notranslate">

testA = testC;
if (testA.equals(testB))
  System.out.println(&quot;Not same&quot;);
</pre>
<p>testA was null during the comparison. Due to this, a null pointer exception would be thrown. Before this, this was how it was checked when TechieDan was doing coding many years back.</p>
<pre class="brush: java; title: ; notranslate">

if (testA != null &amp;&amp; testA.equals(testB))
  System.out.println(&quot;Not same&quot;);
</pre>
<p>By doing so, we have <strong>eliminated the problem regarding the null pointer exception</strong>. Somehow Java has evolved and instead of writing long codes to solve this issue, so why not we try importing a library to help with the solution.</p>
<p>We could use <strong>Commons Lang 2.6</strong> (<em>as of time of writing</em>) which we could download at this page.<br />
<a title="Commons Lang download page" href="http://commons.apache.org/lang/download_lang.cgi" target="_blank">Commons Lang Download Page</a></p>
<p>Of course by including this lib into a project, one can now look at the wonders of comparison between Strings.</p>
<p>Now one can just write something like this.</p>
<pre class="brush: java; title: ; notranslate">

if (StringUtils.equals(testA, testB))
  System.out.println(&quot;Not same&quot;);
</pre>
<p>It is that simple. By importing the library to one&#8217;s project, it <strong>negates off the null part</strong> and<strong> will not throw a null pointer exception</strong> if it was caught. If one is developing for a big project, this should be the standard of doing <strong>String comparisons</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://techiedan.com/2011/06/07/java-compare-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java 7 &#8211; New Try Catch Blocks</title>
		<link>http://techiedan.com/2011/03/15/java-7-new-try-catch-blocks/</link>
		<comments>http://techiedan.com/2011/03/15/java-7-new-try-catch-blocks/#comments</comments>
		<pubDate>Tue, 15 Mar 2011 09:42:06 +0000</pubDate>
		<dc:creator>techieDan</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[java7]]></category>

		<guid isPermaLink="false">http://techiedan.com/?p=1072</guid>
		<description><![CDATA[How can you try and catch and error and avoiding code redundancy in Java 7. With Java 7 still in beta mode, there are more upgrades to this amazing programming language. ]]></description>
			<content:encoded><![CDATA[<p><strong>Java 7 is still under Beta</strong> as time of writing and this time TechieDan would preview a whole new way of <strong>writing your try and catch statement blocks</strong>.</p>
<p><a href="http://techiedan.com/wp-content/uploads/2011/03/java-7.jpg"><img class="alignnone size-full wp-image-1063" title="Java 7" src="http://techiedan.com/wp-content/uploads/2011/03/java-7.jpg" alt="Java 7" width="467" height="341" /></a></p>
<p><span style="text-decoration: underline;"><strong>What is a try catch block?</strong></span><br />
It is good practice to be able to catch errors that are not handled by the user input so that the program would not throw an error with its own garbage error messages. Here is an example of what a garbage message would look like to a user screen.</p>
<blockquote><p><em>Exception in thread &#8220;main&#8221; java.lang.NumberFormatException: For input string: &#8220;hello&#8221;</em><br />
<em> at java.lang.NumberFormatException.forInputString(Unknown Source)</em><br />
<em> at java.lang.Integer.parseInt(Unknown Source)</em><br />
<em> at java.lang.Integer.parseInt(Unknown Source)</em><br />
<em> at com.Test.TestSME.main(TestSME.java:10)</em></p></blockquote>
<p>This was the program that created this garbage message using the command prompt.</p>
<pre class="brush: java; title: ; notranslate">
public class TestSME {

  public static void main(String... args) {
    String result = null;
    String a = &quot;hello&quot;;
    result = a;

    System.out.println(Integer.parseInt(result));

    System.exit(0);
  }
}
</pre>
<p>From the code, there were no compilation errors. <strong>Errors will only be present at runtime</strong>.</p>
<p>So how does one handle it? Well, we can always use the <strong>try catch block</strong>.</p>
<pre class="brush: java; title: ; notranslate">
public class TestSME {

  public static void main(String... args) {
    String result = null;
    String a = &quot;hello&quot;;
    result = a;

    try {
      System.out.println(&quot;This is the result: &quot; + Integer.parseInt(result));
    } catch (Exception e) {
      System.out.println(&quot;Cannot print result as result is not numeric, it is \&quot;&quot; + result + &quot;\&quot;&quot;);
    }
    System.exit(0);
  }
}
</pre>
<p>Finally, no more garbage messages. If one were to run this program, it will produce this error message now.</p>
<blockquote><p><em><span style="color: #ff0000;">Cannot print result as result is not numeric, it is &#8220;hello&#8221;.</span></em></p></blockquote>
<p>Of course, something about this code is bad practice too. Most importantly, one should not catch<strong> Exception or throw plain Exception in a try catch handler</strong>.</p>
<p>Here is the reason why?</p>
<blockquote><p><em>It&#8217;s very bad style to declare a method as throws Exception, because that forces the caller to always catch ALL Exceptions, including those he might have wanted to pass up to some more global error handler. Always use specific exception classes &#8211; in case there isn&#8217;t one handy, make up your own.</em></p></blockquote>
<p>Here is a simple scenario then. By doing so, let us say that if the result was empty, it will also display the same error message and there is no meaning to the error message. So we want to catch the exception that was meant for that specific error.</p>
<p><strong>Good practices come from writing good codes</strong>.</p>
<p>Of course, so how should we handle it?</p>
<pre class="brush: java; title: ; notranslate">
try {
  System.out.println(&quot;This is the result: &quot; + Integer.parseInt(result));
} catch (NumberFormatException e) {
  System.out.println(&quot;Cannot print result as result is not numeric, it is \&quot;&quot; + result + &quot;\&quot;.&quot;);
} catch (NullPointerException e) {
  System.out.println(&quot;result is null.&quot;);
}
</pre>
<p>Now this is multiple catch blocks. This is good if there are multiple and different scenarios to catch errors which are specifically meant for that error type. Of course, the above would not really work as the NumberFormatException would eventually catch the NULL value too. Is it just an example of how to write this in Java.</p>
<p>Of course, now let us look at<strong> Java 7</strong>. Java 7 has a different approach in terms of doing a catch block. It is easy to maintain and if one has to catch a few exceptions and give the same answer, it is best to use the Java 7 way.</p>
<p>A single catch block can handle more than one type of exception. This feature can reduce code duplication and lessen the temptation to catch an overly broad exception.</p>
<p>In the catch clause, specify the types of exceptions that block can handle, and <strong>separate each exception type with a vertical bar (|)</strong>:</p>
<pre class="brush: java; title: ; notranslate">
try {
  System.out.println(&quot;This is the result: &quot; + Integer.parseInt(result));
} catch (NumberFormatException | NullPointerException e) {
  System.out.println(&quot;Cannot print result as result is not numeric, it is \&quot;&quot; + result + &quot;\&quot;.&quot;);
}
</pre>
<p>Just by using the (|) bar, that is how easy it is for Java 7. I seriously love the flexibility of Java 7. What other exciting <strong>new features of Java 7</strong>?</p>
]]></content:encoded>
			<wfw:commentRss>http://techiedan.com/2011/03/15/java-7-new-try-catch-blocks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Java 7 &#8211; New Switch Statement</title>
		<link>http://techiedan.com/2011/03/07/java7-switch-statement/</link>
		<comments>http://techiedan.com/2011/03/07/java7-switch-statement/#comments</comments>
		<pubDate>Mon, 07 Mar 2011 03:24:06 +0000</pubDate>
		<dc:creator>techieDan</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Java 7]]></category>
		<category><![CDATA[JDK]]></category>
		<category><![CDATA[switch]]></category>

		<guid isPermaLink="false">http://techiedan.com/?p=1058</guid>
		<description><![CDATA[Fast forward to Java SE 7, you can now use Strings inside a switch statement. Unlike previous versions, putting Strings on a switch would produce an error but on Java 7, finally a switch comparator is enabled. Much more flexibility now.]]></description>
			<content:encoded><![CDATA[<p><strong>Java SE 7</strong> is still just around the corner. It is still in Beta mode, so many things are still under test. TechieDan has been reading and researching about Java 7 in order to keep abreast of what Java has to offer in the coming future.</p>
<p><img class="alignnone size-full wp-image-1063" title="Java 7" src="http://techiedan.com/wp-content/uploads/2011/03/java-7.jpg" alt="Java 7" width="467" height="341" /></p>
<p>There is this <strong>Project CoinFish</strong> that the Java people has put up that there are loads and loads of contribution. As of Java 7, one of these features is the new way of using <strong>SWITCH statements</strong>.</p>
<p>I am sure most programmers would know that a <strong>switch statement is just like a if else statement</strong>. Though, the switch statement feels cleaner in terms of coding practice.</p>
<pre class="brush: java; title: ; notranslate">

public static void getLove() {
  int test = 1;
  switch(test) {
    case 1: System.out.println(&quot;This is number 1&quot;); break;
    default: System.out.println(&quot;Chose no love&quot;);
  }
}
</pre>
<p>The above is a sample switch statement if the method getLove() is called, it will print <strong>&#8220;This is number 1&#8243;</strong>.</p>
<p>Of course, one thing that many people still uses the if statement is because it is able to compare with Strings.</p>
<pre class="brush: java; title: ; notranslate">
If (StringA.equals(StringB))
  System.out.println(&quot;It’s the same&quot;);
</pre>
<p>Now fast forward to Java SE 7, you can now use Strings inside a switch statement. TechieDan will now explore this possibility with you and how it has changed in Java SE 7 onwards. It’s still in beta so you can wait till it’s finalized.</p>
<p>Here I have a full complete source code so that you can run on your java source code editor and try to run it as an application.</p>
<pre class="brush: java; title: ; notranslate">
public class SwitchJava7 {
  public static int getAge(String name) {

    int expectedAge = 0;

    if (name == null) { return expectedAge; }

    switch (name.toLowerCase()) {
      case &quot;takeshi&quot;: expectedAge = 17; break;
      case &quot;justin&quot;: expectedAge = 18; break;
      case &quot;tony&quot;: expectedAge = 19; break;
      case &quot;techiedan&quot;: expectedAge = 20; break;
      case &quot;apek&quot;: expectedAge = 25; break;
      case &quot;timorthy&quot;: expectedAge = 26; break;
      case &quot;richard&quot;: expectedAge = 27; break;
      case &quot;james&quot;: expectedAge = 28; break;
      case &quot;max&quot;: expectedAge = 35; break;
      case &quot;jason&quot;:  expectedAge = 36; break;
      case &quot;david&quot;: expectedAge = 37; break;
      case &quot;darren&quot;: expectedAge = 40; break;
      default: expectedAge =  0; break;
    }

    return expectedAge;
  }

  public static void main(String[] args) {

    String name = &quot;TechieDan&quot;;
    int expectedAge = Java7Switch.getAge(name);

    if (expectedAge == 0) {
      System.out.println(&quot;You must be a Bieber fan. Strange?&quot;);
    } else {
      System.out.println(&quot;This is your age: &quot; + expectedAge);
    }
  }
}
</pre>
<p>Forgive me on the Bieber pun intended but I definitely am not a fan of Bieber. Running this will yield this result.</p>
<blockquote><p>This is your age: 20</p></blockquote>
<p>Previous versions of Java while compiling this will produce an error below.</p>
<blockquote><p><em>Cannot switch on a value of type String. Only convertible int values or enum constants are permitted.</em></p></blockquote>
<p><strong>Java 7 makes it flexible</strong> and the above is an example of how it is similar to String.equals() method. <strong>Java 7 promises more enhancement</strong> and this is where we all learn the language together.</p>
<p>Until next time, TechieDan would cover a few more enhancements on Java SE 7.</p>
]]></content:encoded>
			<wfw:commentRss>http://techiedan.com/2011/03/07/java7-switch-statement/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>More AutoBoxing in Java</title>
		<link>http://techiedan.com/2011/03/03/more-autoboxing-in-java/</link>
		<comments>http://techiedan.com/2011/03/03/more-autoboxing-in-java/#comments</comments>
		<pubDate>Thu, 03 Mar 2011 06:46:47 +0000</pubDate>
		<dc:creator>techieDan</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[autoboxing]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[scjp]]></category>

		<guid isPermaLink="false">http://techiedan.com/?p=1046</guid>
		<description><![CDATA[Some tips on Autoboxing to be applied in Java and for your SCJP 6 exams. The flexibility of the Java language has made programming easy and in some ways less complicated for the beginners.]]></description>
			<content:encoded><![CDATA[<p>Previously when we touched on <a title="AutoBoxing in Java 5" href="http://techiedan.com/2009/10/20/autoboxing-java-5/">AutoBoxing in Java</a>, we only had a glimpse of what Java 5 onwards could do. If you are studying for <strong>SCJP 6</strong> (<em>the latest SCJP as of date of print</em>), this will definitely help yourself to be prepared for the Exam. Now let’s have a look at some of the examples.</p>
<p><img class="alignnone size-full wp-image-1055" title="Autoboxing SCJP Java 6 tips" src="http://techiedan.com/wp-content/uploads/2011/03/autoboxing-SCJP-tips.jpg" alt="Autoboxing SCJP Java 6 tips" width="312" height="309" /></p>
<p>It is definitely correct if one does a <strong>comparison of numeric values</strong> like the following example.</p>
<pre class="brush: java; title: ; notranslate">
Integer first = 1;
int one = 1;

if (one == first)
  System.out.println(&quot;Same value&quot;);
</pre>
<p>Now what about if I were to do it this way?</p>
<pre class="brush: java; title: ; notranslate">
Integer First = 1;
int one = first;

System.out.println(&quot;Value of one is: &quot; + one);
</pre>
<p>So now we know that <strong>Integer and int can co-relate</strong> with each another ever since AutoBoxing was introduced into Java 5. Now here&#8217;s a question. Which of these is illegal?</p>
<pre class="brush: java; title: ; notranslate">
Integer a = 01;
Integer string = null;
Integer lock = 2.4;
Integer enum = 1;
</pre>
<p>The answer to this is a little bit tricky.</p>
<p>First there are only 2 right answers. The answers for this little quiz is Number 1 and 2 is legal. Yes, and this will be the outcome if they were both printed seperately.</p>
<pre class="brush: plain; title: ; notranslate">
Integer a is 1
Integer string is null
</pre>
<p>Number 3 and 4 are both deemed illegal and would not even be able to compile due to the <strong>value 2.4 is a double</strong> that cannot be casted to Integer. For Number 4, <strong>enum is a reserved word</strong>. Some of us might even get confused as to why number 2 is right? Shouldn&#8217;t string be a reserved word?</p>
<p>Of course, <strong><span style="color: #3366ff;">String</span> is a reserved word</strong>, while <strong><span style="color: #339966;">string </span>is not a reserved word</strong>. One is uppercase, one is lowercase. Java is indeed more flexible compared to the Java 1.4 days.</p>
]]></content:encoded>
			<wfw:commentRss>http://techiedan.com/2011/03/03/more-autoboxing-in-java/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Track Records on Database using DB2</title>
		<link>http://techiedan.com/2011/02/10/track-records-database-db2/</link>
		<comments>http://techiedan.com/2011/02/10/track-records-database-db2/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 03:55:17 +0000</pubDate>
		<dc:creator>techieDan</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[DB2]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[timestamp]]></category>

		<guid isPermaLink="false">http://techiedan.com/?p=1029</guid>
		<description><![CDATA[For Database Administrators and Developers, this is a common practice. Sometimes we would love to track who has accessed a particular record from the users' perspective based on ID and time. The usage of TIMESTAMP would be the best way.]]></description>
			<content:encoded><![CDATA[<p>For <strong>Database Administrators</strong> and <strong>Developers</strong>, this is a common practice. Sometimes we would love to <strong>track who has accessed a particular record from the users&#8217; perspective based on ID and time</strong>.</p>
<p>How can we track it then? This is usually the job for the developer to code into their <strong>SQL query to do a simple INSERT or a simple UPDATE</strong>. It is known to anyone who wants to start coding, the best way to track is to get the user ID of the specific user and the date and time of the transaction was done. For the simplicity and best way to track date and time, the usage of <strong>TIMESTAMP</strong> would be the best way.</p>
<p>If you’ve just joined a company and they have a field name <strong>DATE_UPDATED</strong> and values <strong><em>1/7/2011 2:39:35 PM</em></strong>, now how do you update this?</p>
<p>Yes, just by using <strong>TIMESTAMP</strong>.</p>
<p><img class="alignnone size-full wp-image-1035" title="SQL DB2" src="http://techiedan.com/wp-content/uploads/2011/02/sql-db2.jpg" alt="SQL DB2" width="226" height="199" /></p>
<p>Using <strong>DB2 as the platform</strong> to perform my SQL queries, this is how a TIMESTAMP could be updated from the previous TIMESTAMP.</p>
<pre class="brush: sql; title: ; notranslate">UPDATE [tablename] SET DATE_UPDATED = (CURRENT TIMESTAMP);</pre>
<p>Make sure to always use <strong>CURRENT TIMESTAMP</strong> in order to get the latest date and time. Now you can track when was the last transaction done. This only applies for developers that are still using native SQL to update their database. <strong>Those using <a title="Hibernate" href="http://www.hibernate.org" target="_blank">Hibernate</a></strong>would not have a big problem with this.</p>
]]></content:encoded>
			<wfw:commentRss>http://techiedan.com/2011/02/10/track-records-database-db2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MS Excel Wrap Text Vertically</title>
		<link>http://techiedan.com/2011/01/27/ms-excel-wrap-text-vertically/</link>
		<comments>http://techiedan.com/2011/01/27/ms-excel-wrap-text-vertically/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 07:57:02 +0000</pubDate>
		<dc:creator>techieDan</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[MS]]></category>
		<category><![CDATA[wraptext]]></category>

		<guid isPermaLink="false">http://techiedan.com/?p=1010</guid>
		<description><![CDATA[So how do you wrap a long text in MS Excel? Follow these steps in order to learn how to wrap your text in just one column in Microsoft Excel sheet.]]></description>
			<content:encoded><![CDATA[<p>How many times when we wanted to do a <strong>report in MS Excel</strong>, we will have to use the Merge tool to merge a few columns together so that it’ll look presentable.</p>
<p><img class="alignnone size-full wp-image-1019" title="Microsoft Excel Logo" src="http://techiedan.com/wp-content/uploads/2011/01/microsoft_excel.jpg" alt="Microsoft Excel Logo" width="388" height="321" /></p>
<p>What about writing a <strong>few text on multiple lines</strong> and we instead enter the <strong>new line of words</strong> on a separate row?</p>
<p>It could be easier with this tutorial on how to <strong>Wrap your Sentences into One Column</strong>.</p>
<p><img class="alignnone size-full wp-image-1012" style="border: 1px solid black;" title="Sample Excel Wrapped Sheet" src="http://techiedan.com/wp-content/uploads/2011/01/excel-wrapped-sheet.jpg" alt="Sample Excel Wrapped Sheet" width="502" height="225" /></p>
<p>Refer the above picture, if you would like to wrap the text into one column, here is what you should do.</p>
<blockquote>
<ol>
<li><em>Right click on the specific cell and click <strong>Format Cells</strong>.</em></li>
<li><em>Go to <strong>Alignment tab</strong>. Choose <strong>Vertical Option</strong> and set it to <span style="color: #ff0000;"><strong>Top</strong></span>.</em></li>
<li><em><span style="color: #ff0000;"><strong>Tick</strong> </span>the <strong>Wrap Text</strong> and click OK.</em></li>
</ol>
</blockquote>
<p>If you would like to view the instructions in graphical manner look at the <strong>graphical steps</strong> below.</p>
<p><img class="alignnone size-full wp-image-1014" style="border: 1px solid black;" title="Select Format Cells in Excel" src="http://techiedan.com/wp-content/uploads/2011/01/select-format-cells.jpg" alt="Select Format Cells in Excel" width="460" height="360" /></p>
<p><img class="alignnone size-full wp-image-1013" title="Format Cells Option" src="http://techiedan.com/wp-content/uploads/2011/01/format-cells-option.jpg" alt="Format Cells Option" width="397" height="377" /></p>
<p>Finally the result you are looking for is displayed.</p>
<p><img class="alignnone size-full wp-image-1011" title="Text Wrapped Excel Result" src="http://techiedan.com/wp-content/uploads/2011/01/text-wrapped-result-excel.jpg" alt="Text Wrapped Excel Result" width="474" height="259" /></p>
<p>Need assistance, comment here and I&#8217;ll get back to you.</p>
]]></content:encoded>
			<wfw:commentRss>http://techiedan.com/2011/01/27/ms-excel-wrap-text-vertically/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

