<?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>OpenPeta &#187; Java</title>
	<atom:link href="http://openpeta.com/index.php/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://openpeta.com</link>
	<description>Open Mind ....  Open Source ...</description>
	<lastBuildDate>Wed, 21 Jul 2010 03:20:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Eclipse or Netbeans ? Which one to Choose ?</title>
		<link>http://openpeta.com/index.php/2010/03/eclipse-or-netbeans-which-one-to-choose/</link>
		<comments>http://openpeta.com/index.php/2010/03/eclipse-or-netbeans-which-one-to-choose/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 02:29:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Source Programming]]></category>

		<guid isPermaLink="false">http://www.openpeta.com/index.php/eclipse-or-netbeans-which-one-to-choose/</guid>
		<description><![CDATA[This article is absolutely for beginners those who want to choose / learn best IDE for their project Development. Both IDE has lot of features and supporting major programming languages [ Java , C , C++ , PHP , HTML , Perl , Python , Ruby Etc .. ] . The Comparison of these IDE [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><span style="font-family: sans-serif;">This article is absolutely for beginners those who want to choose / learn best IDE for their project Development. Both IDE has lot of features and supporting major programming languages [ Java , C , C++ , PHP , HTML , Perl , Python , Ruby Etc .. ] . </span>The Comparison of these IDE are given here<br />
Eclipse IDE</p>
<div><img style="max-width: 800px;" title="Eclipse IDE" src="http://www.openpeta.com/wp-content/uploads/2010/03/Screenshot-Java-Sample-src-First.java-Eclipse-.png" alt="" width="546" height="339" /></div>
<p>Pros</p>
<ol>
<li>IDE Features [ Syntax Highlighting , Debugging , Preview ...]</li>
<li>Full Java , J2EE Development Support.</li>
<li>Various Flavors are available [Eclipse Classic , Eclipse for Java  , Eclipse for J2EE ... ]</li>
<li>Plug-in Development Support</li>
<li>Perl , Python , C , C++ , Ruby on Rails language support</li>
<li>Plug-in s are more [ You can find from Eclipse Plug-in Site ]</li>
<li>Execution Speed is good ,Memory Consumption is less, Eclipse will also work in 512 MB RAM ,</li>
<li>Debugging support for all languages.</li>
<li>Developer friendly</li>
</ol>
<p>Cons</p>
<ol>
<li>Single Bundle or package is not available for all features.</li>
<li>Lacks for Java Swing Designing</li>
<li>No Internal Server for running Client / Server Script like apache or tomcat or glassfish</li>
</ol>
<p>Netbeans IDE</p>
<div><img style="max-width: 800px;" src="http://openpeta.com/wp-content/uploads/2010/03/Screenshot-Sample-NetBeans-IDE-6.81.png" alt="" width="569" height="338" /></p>
<div>Pros</p>
<ol>
<li>All IDE Features</li>
<li>Java, C , C++ , PHP , Ruby , groovy languages support</li>
<li>Bundled with single package for all features</li>
<li>Various flavors are available [Netbeans Java , J2EE , C ..]</li>
<li>Debugging is good</li>
<li>WYSIWYG design for Java Swing Application</li>
<li>Full Java Script and CSS support</li>
<li>Tomcat and Glassfish serves are in built with Netbeans IDE</li>
<li>Developer friendly</li>
<li>Option for uploading project into open source community [ using Kenai]</li>
</ol>
<p>Cons</p>
<ol>
<li>Occupying More Memory (Min 512 MB)</li>
<li>Execution Speed is somewhat low comparing to eclipse [But its  based on processor and memory )</li>
<li>Plug-ins are less</li>
</ol>
<p>Final Words</p>
<blockquote><p>In my working experience with IDEs , If you want to develop Java Swing and J2EE Related Applications, you can move for Netbeans , or always choose Eclipse to code.</p></blockquote>
</div>
</div>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" src="http://img.zemanta.com/pixy.gif?x-id=b5aa4a13-a7f4-8413-8f6b-45ac24d43b7a" alt="" /></div>
]]></content:encoded>
			<wfw:commentRss>http://openpeta.com/index.php/2010/03/eclipse-or-netbeans-which-one-to-choose/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Syntax Sheet &#8211; Basics</title>
		<link>http://openpeta.com/index.php/2010/02/java-syntax-sheet-basics/</link>
		<comments>http://openpeta.com/index.php/2010/02/java-syntax-sheet-basics/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 11:46:45 +0000</pubDate>
		<dc:creator>ANTHONIRAJ</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.openpeta.com/?p=618</guid>
		<description><![CDATA[Dear Open Peta Users I have prepared Java basics syntax sheet which would be very useful for beginners and students . The following topics has been covered in style sheet Java Comments Data Types Variables Constants Operators Mathematical Functions Reading Input String Class Conditional Statements Branching and Looping Classes and Objects Inner Class Interface The [...]]]></description>
			<content:encoded><![CDATA[<p>Dear Open Peta Users</p>
<p>I have prepared Java basics syntax sheet which would be very useful for beginners and students . The following topics has been covered in style sheet</p>
<blockquote>
<ol>
<li>Java Comments</li>
<li>Data Types</li>
<li>Variables</li>
<li>Constants</li>
<li>Operators</li>
<li>Mathematical Functions</li>
<li>Reading Input</li>
<li>String Class</li>
<li>Conditional Statements</li>
<li>Branching and Looping</li>
<li>Classes and Objects</li>
<li>Inner Class</li>
<li>Interface</li>
</ol>
</blockquote>
<p>The Remaining topics will be released in next version .</p>
<p style="text-align: left;"><a href="http://www.openpeta.com/wp-content/uploads/2010/02/Java-Sysntax-Sheet-Antony.pdf" target="_blank"> Click Here To Download the Syntax Sheet</a></p>
<p>You can modify , use , distribute to anyone . No restrictions apply to this Syntax Sheet.</p>
]]></content:encoded>
			<wfw:commentRss>http://openpeta.com/index.php/2010/02/java-syntax-sheet-basics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Object Serialization in Java</title>
		<link>http://openpeta.com/index.php/2009/07/object-serialization-in-java/</link>
		<comments>http://openpeta.com/index.php/2009/07/object-serialization-in-java/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 03:46:10 +0000</pubDate>
		<dc:creator>ANTHONIRAJ</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.openpeta.com/?p=360</guid>
		<description><![CDATA[Since Java is pure object oriented programming , all things must be done using the help of the objects. Some times if  developer wants to transfer the object from one JVM to another JVM or one network to another network , its very difficult to pack or unpack the object contents, because the object can [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Since Java is pure object oriented programming , all things must be done using the help of the objects. Some times if  developer wants to transfer the object from one JVM to another JVM or one network to another network , its very difficult to pack or unpack the object contents, because the object can have any type of datatypes or methods like images ,videos etc .. , serialization helps to do this task.</p>
<p><strong>Object Serialization</strong></p>
<p style="text-align: justify;">Object Serialization is the process of converting object into stream of bytes which would be transferred via network. In other end the stream of bytes would be converted into original object , this process is called object de-serialization. The stream of bytes will be stored into a file in local disk after serialization.Now lets take small review about classes and methods used for Serialization and De-serialization process.</p>
<p>Package Name : java.io</p>
<p>Classes :</p>
<ol>
<li>ObjectOutputStream</li>
<li>ObjectInputStream</li>
<li>FileOutputStream</li>
<li>FileInputStream</li>
</ol>
<p>Methods :</p>
<ol>
<li>Object readObject()</li>
<li>void writeObject(Object obj)</li>
</ol>
<p>Example Program</p>
<p>Now lets create one Employee Object with some fields then we can apply the serialization concept.</p>
<p><strong>1. Employee.java</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.rmi.serial</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Author :Anthoniraj.A
 * Date  : 30/06/09
 * Description : Program For Object Creation
 */</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.Serializable</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Employee <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Serializable</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">String</span> name<span style="color: #339933;">;</span>
    <span style="color: #003399;">String</span> designation<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">double</span> salary<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">int</span> exp<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>2.Employee Serialization</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.rmi.serial</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
 * Author :Anthoniraj.A
 * Date  : 30/06/09
 * Description : Program For Object Serialization
 */</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.File</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.FileOutputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.ObjectOutputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.logging.Level</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.logging.Logger</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EmpSerializable
<span style="color: #009900;">&#123;</span>
  Employee emp <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;;</span>
  <span style="color: #003399;">ObjectOutputStream</span> oos <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> setValues<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
      emp <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Employee<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      emp.<span style="color: #006633;">name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Antony&quot;</span><span style="color: #339933;">;</span>
      emp.<span style="color: #006633;">designation</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;AssistantProfessor&quot;</span><span style="color: #339933;">;</span>
      emp.<span style="color: #006633;">salary</span> <span style="color: #339933;">=</span><span style="color: #cc66cc;">32000</span><span style="color: #339933;">;</span>
      emp.<span style="color: #006633;">exp</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> serializeValues<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span>
        <span style="color: #009900;">&#123;</span>
          oos <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ObjectOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">FileOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sample.ser&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          oos.<span style="color: #006633;">writeObject</span><span style="color: #009900;">&#40;</span>emp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;An Employee Object is serialized into sample.ser file&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> ex<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
             ex.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">finally</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">try</span>
            <span style="color: #009900;">&#123;</span>
               oos.<span style="color: #006633;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               oos.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> ex<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>EmpSerializable.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">log</span><span style="color: #009900;">&#40;</span>Level.<span style="color: #006633;">SEVERE</span>, <span style="color: #000066; font-weight: bold;">null</span>, ex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> a<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
       EmpSerializable es <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> EmpSerializable<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       es.<span style="color: #006633;">setValues</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       es.<span style="color: #006633;">serializeValues</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
OutPut
An Employee <span style="color: #003399;">Object</span> is serialized into sample.<span style="color: #006633;">ser</span> file</pre></div></div>

<p><strong>3.Employee DeSerialization</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.rmi.serial</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
 * Author :Anthoniraj.A
 * Date  : 30/06/09
 * Description : Program For Object Deserialization
 */</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.File</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.FileInputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.ObjectInputStream</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EmpDeserializable
<span style="color: #009900;">&#123;</span>
  <span style="color: #003399;">ObjectInputStream</span> ois <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> getValues<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span>
        <span style="color: #009900;">&#123;</span>
           ois <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ObjectInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">FileInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sample.ser&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
           Employee em <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Employee<span style="color: #009900;">&#41;</span> ois.<span style="color: #006633;">readObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Employee Name :&quot;</span> <span style="color: #339933;">+</span> em.<span style="color: #006633;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Employee Designation :&quot;</span> <span style="color: #339933;">+</span> em.<span style="color: #006633;">designation</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Employee Salary :&quot;</span><span style="color: #339933;">+</span>em.<span style="color: #006633;">salary</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Employee Experience :&quot;</span> <span style="color: #339933;">+</span> em.<span style="color: #006633;">exp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> ex<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
           ex.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">finally</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">try</span>
            <span style="color: #009900;">&#123;</span>
                ois.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> ex<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
               ex.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
     <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> a<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">new</span> EmpDeserializable<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getValues</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
output
Employee <span style="color: #003399;">Name</span> <span style="color: #339933;">:</span>Antony
Employee Designation <span style="color: #339933;">:</span>AssistantProfessor
Employee Salary <span style="color: #339933;">:</span><span style="color: #cc66cc;">32000.0</span>
Employee Experience <span style="color: #339933;">:</span><span style="color: #cc66cc;">3</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://openpeta.com/index.php/2009/07/object-serialization-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wrapper Class and Vector in Java</title>
		<link>http://openpeta.com/index.php/2009/02/wrapper-class-and-vector-in-java/</link>
		<comments>http://openpeta.com/index.php/2009/02/wrapper-class-and-vector-in-java/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 13:17:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.openpeta.com/2009/02/16/wrapper-class-and-vector-in-java/</guid>
		<description><![CDATA[1.Wrapper Classes Primitive Types &#8211; Wrapper Class byte &#8211; Byte short &#8211; Short char &#8211; Character boolean &#8211; Boolean int &#8211; Integer long &#8211; Long float &#8211; Float double &#8211; Double package org.vit.java.collections; public class WrapperTest &#123; &#160; public static void main&#40;String&#91;&#93; args&#41; &#123; double d1 = 1.1234; Double d = new Double&#40;d1&#41;; System.out.println&#40;d.intValue&#40;&#41;&#41;; System.out.println&#40;d.doubleValue&#40;&#41;&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>1.Wrapper Classes</p>
<p>Primitive Types &#8211; Wrapper Class<br />
byte &#8211; Byte<br />
short &#8211; Short<br />
char &#8211; Character<br />
boolean &#8211; Boolean<br />
int &#8211; Integer<br />
long &#8211; Long<br />
float &#8211; Float<br />
double &#8211; Double</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">org.vit.java.collections</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> WrapperTest <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000066; font-weight: bold;">double</span> d1 <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1.1234</span><span style="color: #339933;">;</span>
<span style="color: #003399;">Double</span> d <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Double</span><span style="color: #009900;">&#40;</span>d1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>d.<span style="color: #006633;">intValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>d.<span style="color: #006633;">doubleValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>d.<span style="color: #006633;">floatValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>d.<span style="color: #006633;">isNaN</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>d.<span style="color: #006633;">byteValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>d.<span style="color: #006633;">compareTo</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0.0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Double</span>.<span style="color: #006633;">MIN_VALUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Double</span>.<span style="color: #006633;">MAX_VALUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Output :<br />
1<br />
1.1234<br />
1.1234<br />
false<br />
1<br />
1<br />
4.9E-324<br />
1.7976931348623157E308</p>
<p>2.Type Casting</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">org.vit.java.collections</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.JOptionPane</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TypeCasting
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #000066; font-weight: bold;">int</span> x <span style="color: #339933;">=</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> str <span style="color: #339933;">=</span> <span style="color: #003399;">String</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">float</span> f <span style="color: #339933;">=</span> <span style="color: #003399;">Float</span>.<span style="color: #006633;">parseFloat</span><span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">JOptionPane</span>.<span style="color: #006633;">showMessageDialog</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span>,x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Output:<br />
The result is 10.0</p>
<p>3. Vector Example</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">org.vit.java.collections</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Vector</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> VectorTest <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003399;">Vector</span> v <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Vector</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The Default Capacity is &quot;</span><span style="color: #339933;">+</span>v.<span style="color: #006633;">capacity</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
v.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;antony&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
v.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;raj&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
v.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;10&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
v.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;23.4&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
v.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;kamal&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
v.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;234&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
v.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;214.40&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
v.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;java&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
v.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;2.0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
v.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;2.4&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
v.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;11&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
v.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;end&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The Vector is growing its size doubled s&quot;</span><span style="color: #339933;">+</span>v.<span style="color: #006633;">capacity</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The first element of vector is &quot;</span><span style="color: #339933;">+</span>v.<span style="color: #006633;">firstElement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The last element of vector is &quot;</span><span style="color: #339933;">+</span>v.<span style="color: #006633;">lastElement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The 10th element of vector is &quot;</span><span style="color: #339933;">+</span>v.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The size of the vector is &quot;</span><span style="color: #339933;">+</span>v.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
v.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #0000ff;">&quot;start&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The first element of vector is &quot;</span><span style="color: #339933;">+</span>v.<span style="color: #006633;">firstElement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
v.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The Vector Values are&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>v.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span>v.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
v.<span style="color: #006633;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Output :<br />
The Default Capacity is 10<br />
The Vector is growing its size doubled s20<br />
The first element of vector is antony<br />
The last element of vector is end<br />
The 10th element of vector is 2.4<br />
The size of the vector is 12<br />
The first element of vector is start<br />
The Vector Values are<br />
start raj 10 23.4 kamal 234 214.40 java 2.0 11 end</p>
]]></content:encoded>
			<wfw:commentRss>http://openpeta.com/index.php/2009/02/wrapper-class-and-vector-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some Basic Network Programs in Java</title>
		<link>http://openpeta.com/index.php/2009/02/some-basic-network-programs-in-java/</link>
		<comments>http://openpeta.com/index.php/2009/02/some-basic-network-programs-in-java/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 13:15:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.openpeta.com/2009/02/16/some-basic-network-programs-in-java/</guid>
		<description><![CDATA[Java Networking 1. Finding Address package com.java.net;import java.net.InetAddress;import java.net.UnknownHostException; public class FindingAddress{ public static void main(String[] args) throws UnknownHostException { System.out.println(InetAddress.getLocalHost()); System.out.println(InetAddress.getByName(&#8220;127.0.0.1&#8243;)); }} Output : VITSCS0197/127.0.1.1/127.0.0.1 2.URL Classpackage com.java.net;import java.net.*; public class UrlSample{ public static void main(String[] args) throws MalformedURLException { URL u =new URL(&#8220;http://www.google.com&#8221;); System.out.println(&#8220;Protocol: &#8220;+ u.getProtocol()); System.out.println(&#8220;Port: &#8221; + u.getPort()); System.out.println(&#8220;Default Port: &#8220;+ [...]]]></description>
			<content:encoded><![CDATA[<p>Java Networking</p>
<p>1. Finding Address</p>
<p>package com.java.net;<br />import java.net.InetAddress;<br />import java.net.UnknownHostException;</p>
<p>public class FindingAddress<br />{</p>
<p>     public static void main(String[] args) throws UnknownHostException<br />    {<br />            System.out.println(InetAddress.getLocalHost());<br />           System.out.println(InetAddress.getByName(&#8220;127.0.0.1&#8243;));</p>
<p>    }<br />}</p>
<p>Output :</p>
<p>VITSCS0197/127.0.1.1<br />/127.0.0.1</p>
<p>2.URL Class<br />package com.java.net;<br />import java.net.*;</p>
<p>public class UrlSample<br />{</p>
<p>   public static void main(String[] args) throws MalformedURLException<br />    {<br />       URL u =new URL(&#8220;http://www.google.com&#8221;);<br />       System.out.println(&#8220;Protocol: &#8220;+ u.getProtocol());<br />       System.out.println(&#8220;Port: &#8221; + u.getPort());<br />       System.out.println(&#8220;Default Port: &#8220;+ u.getDefaultPort());<br />       System.out.println(&#8220;Host: &#8221; + u.getHost());<br />       System.out.println(&#8220;File: &#8221; + u.getFile());<br />       System.out.println(&#8220;User: &#8221; + u.getUserInfo());<br />       System.out.println(&#8220;Path: &#8221; + u.getPath());</p>
<p>   }</p>
<p>}</p>
<p>Output</p>
<p>Protocol: http<br />Port: -1<br />Default Port: 80<br />Host: www.google.com<br />File:<br />User: null<br />Path:</p>
]]></content:encoded>
			<wfw:commentRss>http://openpeta.com/index.php/2009/02/some-basic-network-programs-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Applet</title>
		<link>http://openpeta.com/index.php/2009/02/java-applet/</link>
		<comments>http://openpeta.com/index.php/2009/02/java-applet/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 13:02:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.openpeta.com/2009/02/16/java-applet/</guid>
		<description><![CDATA[1. Applet Sample package com.java.myapplet;/** Class Name :AppletSample.java* Date :Mar 21, 2007* Author :Antony*/import java.awt.*;import java.applet.*; public class AppletSample extends Applet{public void paint(Graphics g){ g.setColor(Color.GREEN); g.drawString(&#8220;Welcome to VIT&#8221;, 50,50);}} 2. Audio Player package com.java.myapplet; /*** Program:AudioPlay.java* @author Antony* Date:Jan 5, 2007* Time:5:32:00 AM*/import java.applet.*;import java.awt.*;import java.net.URL; public class AudioPlay extends Applet{ String filename; URL codebase; [...]]]></description>
			<content:encoded><![CDATA[<p>1. Applet Sample</p>
<p>package com.java.myapplet;<br />/*<br />* Class Name :AppletSample.java<br />* Date :Mar 21, 2007<br />* Author :Antony<br />*/<br />import java.awt.*;<br />import java.applet.*;</p>
<p>public class AppletSample extends Applet<br />{<br />public void paint(Graphics g)<br />{<br />    g.setColor(Color.GREEN);<br />    g.drawString(&#8220;Welcome to VIT&#8221;, 50,50);<br />}<br />}</p>
<p>2. Audio Player</p>
<p>package com.java.myapplet;</p>
<p>/**<br />* Program:AudioPlay.java<br />* @author Antony<br />* Date:Jan 5, 2007<br />* Time:5:32:00 AM<br />*/<br />import java.applet.*;<br />import java.awt.*;<br />import java.net.URL;</p>
<p>public class AudioPlay extends Applet<br />{<br /> String filename;<br /> URL codebase;<br /> AudioClip song;</p>
<p> public void init()<br /> {<br />     filename =&#8221;sample3.wav&#8221;;<br />     codebase = getCodeBase();<br />     song =getAudioClip(codebase,filename);<br />     song.play();</p>
<p> }<br /> public void paint(Graphics g)<br /> {<br />     g.setFont(new Font(&#8220;Verdana&#8221;,Font.BOLD,20));<br />     g.setColor(Color.GREEN);<br />     g.drawString(&#8220;Playing the Illayaraja Music&#8230;&#8221;,50,50);</p>
<p> }<br />}</p>
<p>3. Digital Clock</p>
<p>package com.java.myapplet;</p>
<p>/**<br />* Program:DigitalClock.java<br />* @author Antony<br />* Date:Jan 16, 2007<br />* Time:9:00:07 PM<br />*/<br />import java.awt.Graphics;<br />import java.awt.Font;<br />import java.util.Date;</p>
<p>public class DigitalClock extends java.applet.Applet implements Runnable<br />{</p>
<p>   Font theFont = new Font(&#8220;TimesRoman&#8221;, Font.BOLD, 24);</p>
<p>   Date theDate;</p>
<p>   Thread runner;</p>
<p>   public void start()<br />   {<br />       if (runner == null)<br />       {<br />           runner = new Thread(this);<br />           runner.start();<br />       }<br />   }</p>
<p>   public void stop()<br />   {<br />       if (runner != null)<br />       {<br />           runner.stop();<br />           runner = null;<br />       }<br />   }</p>
<p>   public void run()<br />   {<br />       while (true)<br />       {<br />           theDate = new Date();<br />           repaint();<br />           try<br />           {<br />               Thread.sleep(1000);<br />           }<br />           catch (InterruptedException e)<br />           {<br />           }<br />       }<br />   }</p>
<p>   public void paint(Graphics g)<br />   {<br />       g.setFont(theFont);<br />       g.drawString(theDate.toString(), 10, 50);<br />   }<br />}</p>
<p>4. String Animation</p>
<p>package com.java.myapplet;</p>
<p>import java.applet.Applet;<br />import java.awt.Color;<br />import java.awt.Font;<br />import java.awt.Graphics;</p>
<p>/**<br />* Program:StringAnimation.java<br />* @author Antony<br />* Date:Jan 19, 2007<br />* Time:4:55:34 PM<br />*/<br />public class StringAnimation extends Applet implements Runnable<br />{<br />   String name;<br />   Thread t;<br />   Font f;<br />   int x,y;<br />   public void init()<br />   {<br />               setSize(300,300);<br />       setBackground(Color.BLACK);<br />       f =new Font(&#8220;verdana&#8221;,Font.ITALIC,24);<br />       name =&#8221;VIT UNIVERSITY&#8221;;<br />       x=50;<br />       y=10;</p>
<p>       t = new Thread(this);<br />       t.start();<br />   }</p>
<p>   public void run()<br />   {<br />       while(true)<br />       {<br />          y++;<br />          if(y>500)<br />            y=10;  <br />          repaint();<br />           try<br />           {<br />               Thread.sleep(10);<br />           }<br />           catch (InterruptedException e)<br />           {<br />               e.printStackTrace();<br />           }<br />       }</p>
<p>   }<br />   public void paint(Graphics g)<br />   {<br />       g.setColor(Color.GREEN);<br />       g.setFont(f);<br />       g.drawString(name, x, y);</p>
<p>   }</p>
<p>}</p>
<p>5. Border layout</p>
<p>package org.vit.java.labcycle2;</p>
<p>import java.applet.Applet;<br />import java.awt.BorderLayout;<br />import java.awt.Button;<br />import java.awt.FlowLayout;<br />import java.awt.Label;<br />import java.awt.Panel;<br />import java.awt.TextField;</p>
<p>/**<br />* Program:BorderLayoutDemo.java<br />* @author Antony<br />* Date:Jan 19, 2007<br />* Time:8:53:27 PM<br />*/</p>
<p>public class BorderLayoutDemo extends Applet<br />{<br /> Button b1;<br /> Button b2;<br /> Button b3;<br /> Button b4;<br /> Button b5;<br /> Panel p;<br /> Label l;<br /> TextField t;</p>
<p> public void init()<br /> {<br />     setSize(300,300);<br />     setLayout(new BorderLayout());<br />     b1 =new Button(&#8220;North&#8221;);<br />     add(b1,BorderLayout.NORTH);<br />     b2=new Button(&#8220;South&#8221;);<br />     add(b2,BorderLayout.SOUTH);<br />     b3=new Button(&#8220;West&#8221;);<br />     add(b3,BorderLayout.WEST);<br />     b4=new Button(&#8220;East&#8221;);<br />     add(b4,BorderLayout.EAST);</p>
<p>     p=new Panel();<br />     p.setLayout(new FlowLayout());<br />     l= new Label(&#8220;Sample Label&#8221;);<br />     p.add(l);<br />     t= new TextField();<br />     t.setColumns(10);<br />     p.add(t);<br />     b5 =new Button(&#8220;Submit&#8221;);<br />     p.add(b5);<br />     add(p,BorderLayout.CENTER); <br />  }<br />}</p>
<p>6. Flow Layout Demo<br />package org.vit.java.labcycle2;</p>
<p>import java.awt.Button;<br />import java.awt.FlowLayout;<br />import java.awt.Frame;<br />import java.awt.event.WindowAdapter;<br />import java.awt.event.WindowEvent;</p>
<p>/**<br />* Program:FlowLayoutDemo.java<br />* @author Antony<br />* Date:Jan 19, 2007<br />* Time:9:23:39 PM<br />*/</p>
<p>public class FlowLayoutDemo extends Frame<br />{<br />   Button b1;<br />   Button b2;<br />   Button b3;<br />   Button b4;<br />   public FlowLayoutDemo()<br />   {<br />       setSize(400,400);<br />       setLayout(new FlowLayout());<br />       b1 =new Button(&#8220;One&#8221;);<br />       b2 =new Button(&#8220;Two&#8221;);<br />       b3 =new Button(&#8220;Three&#8221;);<br />       b4 =new Button(&#8220;Four&#8221;);<br />       add(b1);<br />       add(b2);<br />       add(b3);<br />       add(b4);  </p>
<p>   }<br />   public static void main(String[] args)<br />   {<br />       FlowLayoutDemo f = new FlowLayoutDemo();<br />       f.setVisible(true);<br />       f.setTitle(&#8220;FlowLayoutExample&#8221;);<br />       f.addWindowListener(new WindowAdapter()<br />       {<br />           public void windowClosing(WindowEvent e)<br />           {<br />                    System.exit(0);<br />           }<br />       }<br />       );</p>
<p>   }}</p>
]]></content:encoded>
			<wfw:commentRss>http://openpeta.com/index.php/2009/02/java-applet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multithreading in Java</title>
		<link>http://openpeta.com/index.php/2009/02/multithreading-in-java/</link>
		<comments>http://openpeta.com/index.php/2009/02/multithreading-in-java/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 12:57:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.openpeta.com/2009/02/16/multithreading-in-java/</guid>
		<description><![CDATA[1. Creating Simple Thread Using Thread class package org.vit.java.multithreading; public class SampleThread extends Thread{ public void run(){ for(int i=0;i]]></description>
			<content:encoded><![CDATA[<p>1. Creating Simple Thread Using Thread class</p>
<p>package org.vit.java.multithreading;</p>
<p>public class SampleThread extends Thread<br />{</p>
<p>   public void run(){<br />       for(int i=0;i<10;i++)<br />       {<br />           System.out.println(Thread.currentThread().toString());<br />       }<br />   }<br />   public static void main(String[] args)<br />   {<br />        SampleThread s =new SampleThread();<br />        s.run();     <br />   }</p>
<p>}</p>
<p>Output<br />Thread[main,5,main]<br />Thread[main,5,main]<br />Thread[main,5,main]<br />Thread[main,5,main]<br />Thread[main,5,main]<br />Thread[main,5,main]<br />Thread[main,5,main]<br />Thread[main,5,main]<br />Thread[main,5,main]<br />Thread[main,5,main]</p>
<p>2. Creating Simple Thread Using Runnable Interface<br />package org.vit.java.multithreading;</p>
<p>class Simple implements Runnable<br />{</p>
<p>   public void run() {<br />       first();</p>
<p>   }<br />   public void first()<br />   {<br />       second();<br />   }<br />   public void second()<br />   {<br />       System.out.println(&#8220;Child Thread&#8221;);<br />   }<br />}<br /> public class SimpleMethod {<br />   public static void main(String[] args)<br />   {<br />    Runnable r = new Simple();<br />    Thread t = new Thread(r);<br />    t.start();<br />    System.out.println(&#8220;Main Thread&#8221;);</p>
<p>   }</p>
<p>Output 1:<br />Main Thread<br />Child Thread</p>
<p>Output 2:<br />Child Thread<br />Main Thread</p>
<p>Output 3:<br />Child Thread<br />Main Thread</p>
<p>3.Starting Multiple Threads<br />package org.vit.java.multithreading;<br />public class ThreadStart implements Runnable<br />{</p>
<p>   public void run()<br />   {<br />       for (int i=0;i<5;i++)<br />       {<br />           String name = Thread.currentThread().getName();<br />           System.out.println(name +&#8221; is running&#8221;);<br />       }</p>
<p>   }<br />   public static void main(String[] args)<br />   {<br />       Runnable r =new ThreadStart();<br />       Thread t1 = new Thread(r);<br />       Thread t2 = new Thread(r);<br />       t1.setName(&#8220;First Thread&#8221;);<br />       t2.setName(&#8220;Second Thread&#8221;);<br />       t1.start();<br />       t2.start();      <br />   }<br />}</p>
<p>Output 1:<br />First Thread is running<br />First Thread is running<br />First Thread is running<br />First Thread is running<br />First Thread is running<br />Second Thread is running<br />Second Thread is running<br />Second Thread is running<br />Second Thread is running<br />Second Thread is running</p>
<p>Output 2<br />Second Thread is running<br />Second Thread is running<br />Second Thread is running<br />Second Thread is running<br />Second Thread is running<br />First Thread is running<br />First Thread is running<br />First Thread is running<br />First Thread is running<br />First Thread is running</p>
<p>4. Thread Sleep Method</p>
<p>package org.vit.java.multithreading;</p>
<p>public class ThreadSleep<br />{<br />   public void run()<br />   {<br />     first();<br />   }<br />  public void first()<br />  {<br />        try<br />       {<br />           Thread.sleep(2000);<br />       }<br />       catch (InterruptedException e)<br />       {<br />           e.printStackTrace();<br />       }</p>
<p>          second();</p>
<p>  }<br />  public void second()<br />  {<br />      System.out.println(&#8220;Child Thread&#8221;);<br />  }</p>
<p>  public static void main(String[] args)<br />   {<br />      Runnable r= new ThreadTest();<br />      Thread t =new Thread(r);<br />      //t.setPriority(t.MIN_PRIORITY);</p>
<p>      t.start();<br />      System.out.println(&#8220;Main Thread&#8221;);</p>
<p>   }</p>
<p>}</p>
<p>Output<br />Main Thread<br />Child Thread</p>
<p>5. Example</p>
<p>package org.vit.java.multithreading;</p>
<p>class Fibonacci implements Runnable<br />{</p>
<p>   public void run()<br />   {<br />       long a=1;<br />       long b=1;<br />       long c;<br />       for(int k =1;k<=50 ;k++)<br />       {<br />           if(k==1)<br />               System.out.println(&#8220;Fibo :&#8221; +a);<br />           else if(k==2)<br />               System.out.println(&#8220;Fibo :&#8221; +b);<br />           else<br />           {<br />               c=a+b;<br />               System.out.println(&#8220;Fibo :&#8221; +c);<br />               a=b;<br />               b=c;<br />           }<br />           if(k==25)<br />           {<br />               try<br />               {<br />                   Thread.sleep(10);<br />               }<br />               catch (InterruptedException e)<br />               {<br />                   e.printStackTrace();<br />               }<br />           }</p>
<p>       }<br />   }<br />}<br />class Prime implements Runnable<br />{</p>
<p>   public void run()<br />   {<br />       int count=0;<br />       for(int i=1;i<=500 &amp;&amp; count<25;i++)<br />       {<br />           if(i==1)<br />           {  <br />            System.out.println(&#8220;Prime :&#8221;+i);<br />            count++;<br />           }<br />           else if(i==2)<br />           {<br />            System.out.println(&#8220;Prime :&#8221; +i);<br />            count++;<br />           }<br />           else<br />           {<br />               boolean flag =false;<br />               for(int j=2;j<i;j++)><br />               {<br />                   if(i%j!=0)<br />                   {<br />                       flag =true;<br />                   }<br />                   else<br />                   {<br />                       flag =false;<br />                       break;<br />                   }</p>
<p>               }<br />               if(flag ==true)<br />               {  <br />                System.out.println(&#8220;Prime :&#8221; +i);<br />                count++;<br />               }<br />           }</p>
<p>       }<br />   }</p>
<p>}</p>
<p>public class ComputeTest<br />{</p>
<p>   public static void main(String[] args)<br />   {</p>
<p>       Prime p = new Prime();<br />       Thread t1 = new Thread(p);<br />       Fibonacci f = new Fibonacci();<br />       Thread t2 = new Thread(f);</p>
<p>       t1.setPriority(5);<br />       t2.setPriority(7);</p>
<p>       t1.start();<br />       t2.start();</p>
<p>   }<br />}</p>
<p></i;j++)></p>
]]></content:encoded>
			<wfw:commentRss>http://openpeta.com/index.php/2009/02/multithreading-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java And MySql</title>
		<link>http://openpeta.com/index.php/2008/10/java-and-mysql/</link>
		<comments>http://openpeta.com/index.php/2008/10/java-and-mysql/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 10:02:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.openpeta.com/2008/10/23/java-and-mysql/</guid>
		<description><![CDATA[MySql Connect package com.java.mysql; import java.sql.*; public class MysqlConnect { public static void main (String[] args) { Connection conn = null; try { String userName = "root"; String password = "123456"; String url = "jdbc:mysql://localhost/Check"; Class.forName ("com.mysql.jdbc.Driver").newInstance (); conn = DriverManager.getConnection (url, userName, password); System.out.println ("Database connection established"); } catch (Exception e) { System.err.println ("Cannot [...]]]></description>
			<content:encoded><![CDATA[<p>MySql Connect</p>
<pre lang ="java">
package com.java.mysql;
import java.sql.*;
public class MysqlConnect
 {
   public static void main (String[] args)
   {
     Connection conn = null;
     try
     {
         String userName = "root";
         String password = "123456";
         String url = "jdbc:mysql://localhost/Check";
         Class.forName ("com.mysql.jdbc.Driver").newInstance ();
         conn = DriverManager.getConnection (url, userName, password);
         System.out.println ("Database connection established");
     }
   catch (Exception e)
    {
        System.err.println ("Cannot connect to database server");
    }
   finally
   {
       if (conn != null)
        {
            try
              {
                 conn.close ();
                 System.out.println ("Database connection terminated");
              }
            catch (Exception e) { /* ignore close errors */ }
         }
    }
  }
}
</pre>
<p>Output:<br />
Database connection established<br />
Database connection terminated</p>
<p>MySQL Create and Insert</p>
<p>package com.java.mysql;</p>
<p>import java.sql.Connection;<br />
import java.sql.DriverManager;<br />
import java.sql.Statement;</p>
<p>public class MysqlCreate<br />
{<br />
public static void main (String[] args)<br />
{<br />
Connection conn = null;</p>
<p>try<br />
{<br />
String userName = &#8220;root&#8221;;<br />
String password = &#8220;123456&#8243;;<br />
String url = &#8220;jdbc:mysql://localhost/Check&#8221;;<br />
Class.forName (&#8220;com.mysql.jdbc.Driver&#8221;).newInstance ();<br />
conn = DriverManager.getConnection (url, userName, password);<br />
System.out.println (&#8220;Database connection established&#8221;);<br />
Statement s = conn.createStatement ();<br />
int count;<br />
s.executeUpdate (&#8220;DROP TABLE IF EXISTS student&#8221;);<br />
s.executeUpdate (<br />
&#8220;CREATE TABLE student (&#8221;<br />
+ &#8220;id INT UNSIGNED NOT NULL AUTO_INCREMENT,&#8221;<br />
+ &#8220;PRIMARY KEY (id),&#8221;<br />
+ &#8220;name CHAR(40), branch CHAR(40))&#8221;);<br />
count = s.executeUpdate (<br />
&#8220;INSERT INTO student (name, branch)&#8221;<br />
+ &#8221; VALUES&#8221;<br />
+ &#8220;(&#8216;Amar&#8217;, &#8216;IT&#8217;),&#8221;<br />
+ &#8220;(&#8216;Amit&#8217;, &#8216;CSE&#8217;),&#8221;<br />
+ &#8220;(&#8216;Antony&#8217;, &#8216;MECH&#8217;),&#8221;<br />
+ &#8220;(&#8216;Anbu&#8217;, &#8216;ECE&#8217;)&#8221;);<br />
s.close ();<br />
System.out.println (count + &#8221; rows were inserted&#8221;);</p>
<p>}<br />
catch (Exception e)<br />
{<br />
System.err.println (&#8220;Cannot connect to database server&#8221;);<br />
}<br />
finally<br />
{<br />
if (conn != null)<br />
{<br />
try<br />
{<br />
conn.close ();<br />
System.out.println (&#8220;Database connection terminated&#8221;);<br />
}<br />
catch (Exception e) { /* ignore close errors */ }<br />
}<br />
}<br />
}<br />
}</p>
<p>Output<br />
Database connection established<br />
4 rows were inserted<br />
Database connection terminated</p>
<p>MySQL Select</p>
<p>package com.java.mysql;<br />
import java.sql.*;</p>
<p>public class MysqlSelect<br />
{<br />
public static void main (String[] args)<br />
{<br />
Connection conn = null;</p>
<p>try<br />
{<br />
String userName = &#8220;root&#8221;;<br />
String password = &#8220;123456&#8243;;<br />
String url = &#8220;jdbc:mysql://localhost/Check&#8221;;<br />
Class.forName (&#8220;com.mysql.jdbc.Driver&#8221;).newInstance ();<br />
conn = DriverManager.getConnection (url, userName, password);<br />
System.out.println (&#8220;Database connection established&#8221;);<br />
Statement s = conn.createStatement ();<br />
s.executeQuery (&#8220;SELECT id, name, branch FROM student&#8221;);<br />
ResultSet rs = s.getResultSet ();<br />
int count = 0;<br />
while (rs.next ())<br />
{<br />
int idVal = rs.getInt (&#8220;id&#8221;);<br />
String nameVal = rs.getString (&#8220;name&#8221;);<br />
String catVal = rs.getString (&#8220;branch&#8221;);<br />
System.out.println (<br />
&#8220;id = &#8221; + idVal<br />
+ &#8220;, name = &#8221; + nameVal<br />
+ &#8220;, category = &#8221; + catVal);<br />
++count;<br />
}<br />
rs.close ();<br />
s.close ();<br />
System.out.println (count + &#8221; rows were retrieved&#8221;);</p>
<p>}<br />
catch (Exception e)<br />
{<br />
System.err.println (&#8220;Cannot connect to database server&#8221;);<br />
}<br />
finally<br />
{<br />
if (conn != null)<br />
{<br />
try<br />
{<br />
conn.close ();<br />
System.out.println (&#8220;Database connection terminated&#8221;);<br />
}<br />
catch (Exception e) { /* ignore close errors */ }<br />
}<br />
}<br />
}<br />
}</p>
<p>Output<br />
Database connection established<br />
id = 1, name = Amar, category = IT<br />
id = 2, name = Amit, category = CSE<br />
id = 3, name = Antony, category = MECH<br />
id = 4, name = Anbu, category = ECE<br />
4 rows were retrieved<br />
Database connection terminated</p>
]]></content:encoded>
			<wfw:commentRss>http://openpeta.com/index.php/2008/10/java-and-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Networking</title>
		<link>http://openpeta.com/index.php/2008/10/java-networking/</link>
		<comments>http://openpeta.com/index.php/2008/10/java-networking/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 10:01:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.openpeta.com/2008/10/23/java-networking/</guid>
		<description><![CDATA[1. Finding Address package com.java.net; import java.net.InetAddress; import java.net.UnknownHostException; public class FindingAddress &#123; public static void main&#40;String&#91;&#93; args&#41; throws UnknownHostException &#123; System.out.println&#40;InetAddress.getLocalHost&#40;&#41;&#41;; System.out.println&#40;InetAddress.getByName&#40;&#34;127.0.0.1&#34;&#41;&#41;; &#125; &#125; Output : VITSCS0197/127.0.1.1 /127.0.0.1 2.URL Class package com.java.net; import java.net.*; public class UrlSample &#123; public static void main&#40;String&#91;&#93; args&#41; throws MalformedURLException &#123; URL u =new URL&#40;&#34;http://www.google.com&#34;&#41;; System.out.println&#40;&#34;Protocol: &#34;+ u.getProtocol&#40;&#41;&#41;; System.out.println&#40;&#34;Port: [...]]]></description>
			<content:encoded><![CDATA[<p>1. Finding Address</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.java.net</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.InetAddress</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.UnknownHostException</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> FindingAddress
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">UnknownHostException</span>
      <span style="color: #009900;">&#123;</span>
          <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">InetAddress</span>.<span style="color: #006633;">getLocalHost</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">InetAddress</span>.<span style="color: #006633;">getByName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;127.0.0.1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Output :</p>
<p>VITSCS0197/127.0.1.1<br />
/127.0.0.1</p>
<p>2.URL Class</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.java.net</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.*</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UrlSample
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">MalformedURLException</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">URL</span> u <span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">URL</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.google.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Protocol: &quot;</span><span style="color: #339933;">+</span> u.<span style="color: #006633;">getProtocol</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Port: &quot;</span> <span style="color: #339933;">+</span> u.<span style="color: #006633;">getPort</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Default Port: &quot;</span><span style="color: #339933;">+</span> u.<span style="color: #006633;">getDefaultPort</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Host: &quot;</span> <span style="color: #339933;">+</span> u.<span style="color: #006633;">getHost</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;File: &quot;</span> <span style="color: #339933;">+</span> u.<span style="color: #006633;">getFile</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;User: &quot;</span> <span style="color: #339933;">+</span> u.<span style="color: #006633;">getUserInfo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Path: &quot;</span> <span style="color: #339933;">+</span> u.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Output</p>
<p>Protocol: http<br />
Port: -1<br />
Default Port: 80<br />
Host: www.google.com<br />
File:<br />
User: null<br />
Path:</p>
]]></content:encoded>
			<wfw:commentRss>http://openpeta.com/index.php/2008/10/java-networking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exception Handling in Java</title>
		<link>http://openpeta.com/index.php/2008/10/exception-handling-in-java/</link>
		<comments>http://openpeta.com/index.php/2008/10/exception-handling-in-java/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 10:00:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.openpeta.com/2008/10/23/exception-handling-in-java/</guid>
		<description><![CDATA[keyworks1. try2. catch3. finally4. throw5. throws 1. try-catch-finallypackage org.vit.java.exception; import java.util.Scanner; public class Divison{ public static void main(String[] args) throws OwnException { Scanner in = new Scanner(System.in); System.out.println(&#8220;Enter the First Number:&#8221;); int x =in.nextInt(); System.out.println(&#8220;Enter the First Number:&#8221;); int y = in.nextInt(); float z = 0; try { z = x / y; System.out.print(&#8220;The Divison [...]]]></description>
			<content:encoded><![CDATA[<p>keyworks<br />1. try<br />2. catch<br />3. finally<br />4. throw<br />5. throws</p>
<p>1. try-catch-finally<br />package org.vit.java.exception;</p>
<p>import java.util.Scanner;</p>
<p>public class Divison<br />{</p>
<p>   public static void main(String[] args) throws OwnException<br />   {<br />           Scanner in = new Scanner(System.in);<br />           System.out.println(&#8220;Enter the First Number:&#8221;);<br />         int x =in.nextInt();</p>
<p>         System.out.println(&#8220;Enter the First Number:&#8221;);<br />         int y = in.nextInt();<br />         float z = 0;</p>
<p>           try<br />           {<br />               z = x / y;<br />               System.out.print(&#8220;The Divison value is&#8221; +z);</p>
<p>           }               <br />           catch(ArithmeticException a)<br />           {<br />               System.out.println(a.toString());<br />           }<br />           finally<br />           {<br />               System.out.print(&#8220;I am always here&#8221;);<br />           }       </p>
<p>   }</p>
<p>}</p>
<p>package org.vit.java.exception;</p>
<p>import java.io.File;<br />import java.io.FileInputStream;<br />import java.io.FileNotFoundException;</p>
<p>public class Sample {</p>
<p>   public void getFile(String name)<br />   {<br />       try<br />       {<br />           FileInputStream f = new FileInputStream(new File(name));</p>
<p>       }<br />       catch (FileNotFoundException e)<br />       {</p>
<p>           System.out.print(e.toString());<br />       }<br />   }<br />   public static void main(String[] args)<br />   {<br />       Sample s = new Sample();<br />       s.getFile(&#8220;ss.txt&#8221;);<br />   }</p>
<p>}</p>
<p>2. Creating User Defined Exception</p>
<p>package org.vit.java.exception;</p>
<p>import java.util.Scanner;</p>
<p>class MyException extends Exception<br />{<br />   public String toString()<br />   {<br />       return &#8220;Number is less than 10&#8243;;<br />   }<br />}</p>
<p>public class MyExceptionTest<br />{</p>
<p>   public static void main(String[] args)<br />   {<br />         Scanner in = new Scanner(System.in);<br />             System.out.println(&#8220;Enter the First Number:&#8221;);<br />         int x =in.nextInt();</p>
<p>         System.out.println(&#8220;Enter the First Number:&#8221;);<br />         int y = in.nextInt();<br />         float z = 0;</p>
<p>           try<br />           {<br />               z = x / y;<br />               if(z < 10.0)<br />               {   <br />                 throw new MyException();<br />               }<br />           }<br />           catch (MyException e)<br />           {<br />               System.out.println(e.toString());<br />           }       <br />           catch(ArithmeticException a)<br />           {<br />               System.out.println(a.toString());<br />           }<br />           finally<br />           {<br />               System.out.print(&#8220;The Divison value is&#8221; +z);<br />           }<br />       }<br />   }</p>
<p>3. Throws Example</p>
<p>package org.vit.java.exception;</p>
<p>import java.io.File;<br />import java.io.FileInputStream;<br />import java.io.FileNotFoundException;</p>
<p>public class Sample {</p>
<p>   public void getFile(String name) throws FileNotFoundException<br />   {</p>
<p>           FileInputStream f = new FileInputStream(new File(name));</p>
<p>   }<br />   public static void main(String[] args) throws FileNotFoundException<br />   {<br />       Sample s = new Sample();<br />       s.getFile(&#8220;ss.txt&#8221;);<br />   }</p>
<p>}</p>
]]></content:encoded>
			<wfw:commentRss>http://openpeta.com/index.php/2008/10/exception-handling-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
