<?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>JavaBeat &#187; Muthukumar</title>
	<atom:link href="http://www.javabeat.net/author/muthukumar/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javabeat.net</link>
	<description>Java Technology News</description>
	<lastBuildDate>Fri, 24 May 2013 01:32:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Comparing Objects in Java</title>
		<link>http://www.javabeat.net/2008/07/comparing-objects-in-java/</link>
		<comments>http://www.javabeat.net/2008/07/comparing-objects-in-java/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 00:33:22 +0000</pubDate>
		<dc:creator>Muthukumar</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/examples/?p=315</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Comparing Objects in Java In Java comparing two value object is not straight forward. Here we will see how we can compare two value objects in Java. For that first we will create a value object called &#8220;MyValueObject&#8221;. This value object contains two properties. 1) firstName 2) lastName. Both the properties are of type string. [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><a id="dd_start"></a><h3>Comparing Objects in Java</h3>
<p>In Java comparing two value object is not straight forward. Here we will see how we can compare two value objects in Java.</p>
<p>For that first we will create a value object called &#8220;MyValueObject&#8221;. This value object contains two properties. 1) firstName 2) lastName. Both the properties are of type string.</p>
<p>In the same class we also have a <b><i>overridden</i></b> method which does the <b><i>comparison</i></b> for us. This method &#8220;public boolean equals(Object obj)&#8221; takes the properties and compare them individually. if the properties values are all equal then it returns true or it will return false. By doing this our test class will just call the equals method on the object to make sure if the objects are equal or not.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>

<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
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">package com.blogspot.javawave;
&nbsp;
/**
 *
 * @author dhanago
 */
public class MyValueObject
{
&nbsp;
    private String firstName;
    private String lastName;
&nbsp;
    /**
     * This constructor is used to set the two properties values in the class.
     *
     * @param firstName
     * @param lastName
     */
    public MyValueObject(String firstName,
                          String lastName)
    {
        this.firstName = firstName;
        this.lastName = lastName;
    }
&nbsp;
    @Override
    public boolean equals(Object obj)
    {
        boolean isEqual = false;
        if (this.getClass() == obj.getClass())
        {
            MyValueObject myValueObject = (MyValueObject) obj;
            if ((myValueObject.firstName).equals(this.firstName) &amp;&amp;
                    (myValueObject.lastName).equals(this.lastName))
            {
                isEqual = true;
            }
        }
&nbsp;
        return isEqual;
    }
}
Test class is given below:
&nbsp;
&nbsp;
/*
 */
package com.blogspot.javawave;
&nbsp;
/**
 *This class is used to test compare the value object.
 *
 * @author dhanago
 */
public class TestCompareValueObject
{
&nbsp;
    /**
     * This is the main method used to test compare the value object.
     * @param arg
     */
    public static void main(String[] arg)
    {
        MyValueObject obj1 = new MyValueObject(&quot;Muthu&quot;, &quot;Kumar&quot;);
        MyValueObject obj2 = new MyValueObject(&quot;Muthu&quot;, &quot;Kumar&quot;);
&nbsp;
        if (obj1.equals(obj2))
        {
            System.out.println(&quot;Both the objects are equal&quot;);
        }
        else
        {
            System.out.println(&quot;Both the objects are not equal&quot;);
        }
    }
}</pre></td></tr></table></div>

<p>This one of the way we can easily compare the value objects in Java.</p>
<p>
    <i>Note : This article is originally published in : <a href="http://javawave.blogspot.com" target="_blank">http://javawave.blogspot.com</a>.<br />
    Republished here with author&#8217;s permission.</i></p>
<div class='dd_outer'><div class='dd_inner'><div id='dd_ajax_float'><div class='dd_button_v'><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="http%3A%2F%2Fwww.javabeat.net%2Fauthor%2Fmuthukumar%2Ffeed%2F" send="false" show_faces="false"  layout="box_count" width="50"  ></fb:like></div><div style='clear:left'></div><div class='dd_button_v'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='tall' href='http://www.javabeat.net/author/muthukumar/feed/'></g:plusone></div><div style='clear:left'></div><div class='dd_button_v'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.javabeat.net/author/muthukumar/feed/" data-count="vertical" data-text="" data-via="javabeat" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style='clear:left'></div><div class='dd_button_extra_v'><script type="text/javascript">jQuery(document).load(function(){ stLight.options({publisher:'bab47279-62c9-46af-addc-79fd1fe8fee0'}); });</script><div class="st_email_custom"><span id='dd_email_text'>email</span></div></div><div style='clear:left'></div><div class='dd_button_extra_v'><div id='dd_print_button'><span id='dd_print_text'><a href='javascript:window:print()'>print</a></span></div></div><div style='clear:left'></div></div></div></div><script type="text/javascript">var dd_offset_from_content = 44; var dd_top_offset_from_content = 0;</script><script type="text/javascript" src="http://www.javabeat.net/wp-content/plugins/digg-digg//js/diggdigg-floating-bar.js?ver=5.3.0"></script><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2008/07/comparing-objects-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>File Upload and Download using Java</title>
		<link>http://www.javabeat.net/2007/10/file-upload-and-download-using-java/</link>
		<comments>http://www.javabeat.net/2007/10/file-upload-and-download-using-java/#comments</comments>
		<pubDate>Wed, 10 Oct 2007 00:32:26 +0000</pubDate>
		<dc:creator>Muthukumar</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/examples/?p=313</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>File Upload and Download is always a handy utility to know. There will be some need to upload a file to an FTP server, Like if you generate a report or store some data in .xls file, then it needs to be uploaded to a FTP server for further use. like wise we need to [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p><strong style="font-size: 13px;"><em>File Upload and Download</em></strong><span style="font-size: 13px;"> is always a handy utility to know. There will be some need to upload a file to an FTP server, Like if you generate a report or store some data in .xls file, then it needs to be uploaded to a FTP server for further use. like wise we need to download some data (data stored in .xls files)for manuplation from the server in our projects. Here we have the code to do this for us. The FileUploadDownload utility.</span></p>
<p>This fille has the two classes one for upload a file to the <strong>FTP server</strong> and the other one for downloading the file from the FTP server. This program is written in very simple and easy startegy to upload or download the files using Java. It is using <strong>BufferedOutputStream</strong> and <strong>BufferedInputStream</strong> IO classes. This program can be effectively reuse for your purpose incase if you want to upload or download the files from your website or your project work. If you like the program and feels it is very useful for you, please write comment and let us know if there is any improvement needed in the code.</p>
<p><span style="text-decoration: underline;"><strong>also read</strong>: </span>follow us on <a href="http://www.twitter.com/javabeat" target="_blank">@twitter</a> and <a href="https://www.facebook.com/javabeat.net" target="_blank">@facebook</a></p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<ul>
<li><a title="Copying File Contents using FileChannel" href="http://www.javabeat.net/examples/2007/10/09/copying-file-contents-using-filechannel/" rel="bookmark">Copying File Contents using FileChannel</a></li>
<li><a title="Randomly accessing the file contents" href="http://www.javabeat.net/2007/09/randomly-accessing-the-file-contents/" rel="bookmark">Randomly accessing the file contents</a></li>
</ul>
<p>If you have any doubts on the code and looking for the help on this code, please post your queries in the comments section.</p>
<h2>File Upload and Download Code Example</h2>
<pre class="brush: java; title: ; notranslate">
package com.resource.util;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * This class is used to upload a file to a FTP server.
 *
 * @author Muthu
 */
public class FileUpload
{

   /**
    * Upload a file to a FTP server. A FTP URL is generated with the
    * following syntax:
    * ftp://user:password@host:port/filePath;type=i.
    *
    * @param ftpServer , FTP server address (optional port ':portNumber').
    * @param user , Optional user name to login.
    * @param password , Optional password for user.
    * @param fileName , Destination file name on FTP server (with optional
    *            preceding relative path, e.g. &quot;myDir/myFile.txt&quot;).
    * @param source , Source file to upload.
    * @throws MalformedURLException, IOException on error.
    */
   public void upload( String ftpServer, String user, String password,
         String fileName, File source ) throws MalformedURLException,
         IOException
   {
      if (ftpServer != null &amp;amp;&amp;amp; fileName != null &amp;amp;&amp;amp; source != null)
      {
         StringBuffer sb = new StringBuffer( &quot;ftp://&quot; );
         // check for authentication else assume its anonymous access.
         if (user != null &amp;amp;&amp;amp; password != null)
         {
            sb.append( user );
            sb.append( ':' );
            sb.append( password );
            sb.append( '@' );
         }
         sb.append( ftpServer );
         sb.append( '/' );
         sb.append( fileName );
         /*
          * type ==&amp;gt; a=ASCII mode, i=image (binary) mode, d= file directory
          * listing
          */
         sb.append( &quot;;type=i&quot; );

         BufferedInputStream bis = null;
         BufferedOutputStream bos = null;
         try
         {
            URL url = new URL( sb.toString() );
            URLConnection urlc = url.openConnection();

            bos = new BufferedOutputStream( urlc.getOutputStream() );
            bis = new BufferedInputStream( new FileInputStream( source ) );

            int i;
            // read byte by byte until end of stream
            while ((i = bis.read()) != -1)
            {
               bos.write( i );
            }
         }
         finally
         {
            if (bis != null)
               try
               {
                  bis.close();
               }
               catch (IOException ioe)
               {
                  ioe.printStackTrace();
               }
            if (bos != null)
               try
               {
                  bos.close();
               }
               catch (IOException ioe)
               {
                  ioe.printStackTrace();
               }
         }
      }
      else
      {
         System.out.println( &quot;Input not available.&quot; );
      }
   }

   /**
    * Download a file from a FTP server. A FTP URL is generated with the
    * following syntax:
    * ftp://user:password@host:port/filePath;type=i.
    *
    * @param ftpServer , FTP server address (optional port ':portNumber').
    * @param user , Optional user name to login.
    * @param password , Optional password for user.
    * @param fileName , Name of file to download (with optional preceeding
    *            relative path, e.g. one/two/three.txt).
    * @param destination , Destination file to save.
    * @throws MalformedURLException, IOException on error.
    */
   public void download( String ftpServer, String user, String password,
         String fileName, File destination ) throws MalformedURLException,
         IOException
   {
      if (ftpServer != null &amp;amp;&amp;amp; fileName != null &amp;amp;&amp;amp; destination != null)
      {
         StringBuffer sb = new StringBuffer( &quot;ftp://&quot; );
         // check for authentication else assume its anonymous access.
         if (user != null &amp;amp;&amp;amp; password != null)
         {
            sb.append( user );
            sb.append( ':' );
            sb.append( password );
            sb.append( '@' );
         }
         sb.append( ftpServer );
         sb.append( '/' );
         sb.append( fileName );
         /*
          * type ==&amp;gt; a=ASCII mode, i=image (binary) mode, d= file directory
          * listing
          */
         sb.append( &quot;;type=i&quot; );
         BufferedInputStream bis = null;
         BufferedOutputStream bos = null;
         try
         {
            URL url = new URL( sb.toString() );
            URLConnection urlc = url.openConnection();

            bis = new BufferedInputStream( urlc.getInputStream() );
            bos = new BufferedOutputStream( new FileOutputStream(
                  destination.getName() ) );

            int i;
            while ((i = bis.read()) != -1)
            {
               bos.write( i );
            }
         }
         finally
         {
            if (bis != null)
               try
               {
                  bis.close();
               }
               catch (IOException ioe)
               {
                  ioe.printStackTrace();
               }
            if (bos != null)
               try
               {
                  bos.close();
               }
               catch (IOException ioe)
               {
                  ioe.printStackTrace();
               }
         }
      }
      else
      {
         System.out.println( &quot;Input not available&quot; );
      }
   }
}</pre>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2007/10/file-upload-and-download-using-java/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
	</channel>
</rss>
