<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Programming overloaded</title>
	<atom:link href="http://ucancode.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ucancode.wordpress.com</link>
	<description>Nothing new but everything is special</description>
	<lastBuildDate>Thu, 01 Dec 2011 18:11:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ucancode.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Programming overloaded</title>
		<link>http://ucancode.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ucancode.wordpress.com/osd.xml" title="Programming overloaded" />
	<atom:link rel='hub' href='http://ucancode.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Loading the JDBC driver</title>
		<link>http://ucancode.wordpress.com/2011/02/25/loading-jdbc-driver/</link>
		<comments>http://ucancode.wordpress.com/2011/02/25/loading-jdbc-driver/#comments</comments>
		<pubDate>Fri, 25 Feb 2011 11:36:52 +0000</pubDate>
		<dc:creator>ucancode</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JDBC]]></category>
		<category><![CDATA[Loading JDBC driver]]></category>
		<category><![CDATA[ucancode]]></category>

		<guid isPermaLink="false">http://ucancode.wordpress.com/?p=277</guid>
		<description><![CDATA[Most of the projects require connecting to a database, the basic steps involved in connecting to a database using JDBC are: Loading the appropriate driver, Establishing a connection to the database, Executing the SQL queries using objects of Statement, PreparedStatement, etc., and Using the ResultSet object and closing the connection. All these steps excluding the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ucancode.wordpress.com&amp;blog=4294209&amp;post=277&amp;subd=ucancode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Most of the projects require connecting to a database, the basic steps involved in connecting to a database using JDBC are:</p>
<ol>
<li>Loading the appropriate driver,</li>
<li>Establishing a connection to the database,</li>
<li>Executing the SQL queries using objects of Statement, PreparedStatement, etc., and</li>
<li>Using the ResultSet object and closing the connection.</li>
</ol>
<p>All these steps excluding the first step appears to have some purpose and can be understood intuitively. Loading of the driver can be explained as the process of loading the driver class into the memory for using its functionality during the execution process.</p>
<p>The different ways by which we can load a JDBC driver are illustrated:</p>
<p><span id="more-277"></span></p>
<p><pre class="brush: java;">
Class.forName(&quot;sun.jdbc.odbc.JdbcOdbcDriver&quot;);
</pre></p>
<p>In the above line, &#8220;Class&#8221; is a class in java.lang package and we are calling the static method &#8220;forName&#8221; in that &#8220;Class&#8221; class. The forName() takes one argument as  class name and returns the &#8220;Class&#8221; object associated with the argument class name so, an object associated with the driver class &#8220;sun.jdbc.odbc.JdbcOdbcDriver&#8221; is loaded into memory when the above statement is executed.</p>
<p><pre class="brush: java;">
Class.forName(&quot;sun.jdbc.odbc.JdbcOdbcDriver&quot;).newInstance();
</pre></p>
<p>The above statement is a bit different from the first one but, it is also used for the same purpose of loading a JDBC driver, except with a minute difference that it calls &#8220;newInstance&#8221; method of &#8220;Class&#8221; class which creates a new instance of the class represented by the calling &#8220;Class&#8221; object. Some programmers use the above statement to load a JDBC driver by specifying the reason that some JVM environments require instantiation of JDBC driver for its proper working, but i haven&#8217;t faced any issues when i didn&#8217;t used newInstance() method.</p>
<p><pre class="brush: java;">
new sun.jdbc.odbc.JdbcOdbcDriver();
</pre></p>
<p>The above statement creates an object of the JDBC driver, which signifies that the driver is loaded into memory because, whenever an object is instantiated it is loaded into memory.</p>
<p><pre class="brush: java;">
DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
</pre></p>
<p>The above statement not just creates an object of the JDBC driver but also register the driver with the DriverManager. The above statement is useful when dealing with more than one kind of driver classes.<br />
There are many other ways by which we can load a JDBC driver, all these ways eventually would lead to loading of the driver into the memory. Of all these ways, using forName() method is advised because, the JDBC driver class can be changed dynamically.<br />
Apart from all this stuff i would also want to mention that from JDBC 4.0 (included in Java SE 6) does not require loading the driver manually, driver is automatically loaded while the request for database connection is made so, no more worrying about choosing and loading JDBC drivers <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  .<br />
If you found this post of some use or, if there are any mistakes and so on, just leave your comments below.</p>
<p>&nbsp;</p>
<br />Filed under: <a href='http://ucancode.wordpress.com/category/java/'>Java</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ucancode.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ucancode.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ucancode.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ucancode.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ucancode.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ucancode.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ucancode.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ucancode.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ucancode.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ucancode.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ucancode.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ucancode.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ucancode.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ucancode.wordpress.com/277/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ucancode.wordpress.com&amp;blog=4294209&amp;post=277&amp;subd=ucancode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ucancode.wordpress.com/2011/02/25/loading-jdbc-driver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/21ff3fdc9568ec3a35d9b1ba6d85212e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ucancode</media:title>
		</media:content>
	</item>
		<item>
		<title>Solution to N-Queens problem</title>
		<link>http://ucancode.wordpress.com/2010/12/23/solution-to-n-queens-problem/</link>
		<comments>http://ucancode.wordpress.com/2010/12/23/solution-to-n-queens-problem/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 09:36:46 +0000</pubDate>
		<dc:creator>ucancode</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[8-queens problem]]></category>
		<category><![CDATA[8-queens puzzle]]></category>
		<category><![CDATA[N-queens problem solution]]></category>
		<category><![CDATA[solution to 8-queens problem]]></category>
		<category><![CDATA[ucancode]]></category>

		<guid isPermaLink="false">http://ucancode.wordpress.com/?p=258</guid>
		<description><![CDATA[N-queens problem is the generalization of classic 8-queens puzzle (or problem). In N-queens problem, &#8216;N&#8217; number of queens are to be placed onto a NxN square board (or chessboard), such that no two queens are attacking each other.The solution presented here uses the backtracking approach to solve the N-queens problem. The solution contains a recursive [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ucancode.wordpress.com&amp;blog=4294209&amp;post=258&amp;subd=ucancode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>N-queens problem is the generalization of classic 8-queens puzzle (or problem). In N-queens problem, &#8216;N&#8217; number of queens are to be placed onto a NxN square board (or chessboard), such that no two queens are attacking each other.The solution presented here uses the backtracking approach to solve the N-queens problem.</p>
<p><span id="more-258"></span>The solution contains a recursive function, backtrack( ) which i have used to implement the backtracking approach. In the below program, i have specified the size of the board as eight so the solution is specialized to 8-queens problem. To find the solution for some other value of &#8216;N&#8217;, edit line no.3  to required N value.</p>
<p><pre class="brush: cpp;">
#include &lt;stdio.h&gt;

#define BSIZE 8

void initBoard();
int placeQueen(const int , const int );
int checkCross(const int , const int );
void backtrack(int);
void printBoard();

//Chessboard array
char board[BSIZE][BSIZE];
//Row,column iteration variables
int row,col;
//Count for total number of solutions
int count;
int stop;

int main()
{
	int i,j;
	//Initializing count
	count =1;
	stop = 0;
	//Intializing Chessboard
	initBoard();
	//Finding first solution by placing queens in order of column 1,2,...BSIZE.
	for(i=0;i&lt;BSIZE;++i)
	{	
		if(placeQueen(0,i) == -1)
		{
			//If not positioned then backtracking
			backtrack(i);
			if(stop)
			{
				count = 0;
				break;
			}
		}
	}
	//If there is no solution found
	if(!stop)
	{
		printf(&quot;%d)&quot;,1);
		//Printing the solution obtained
		printBoard();
		//Obtainig remaining solutions
		while(1)
		{
			backtrack(BSIZE);
			if(stop)
			{
				break;
			}
			printf(&quot;%d)&quot;,++count);
			printBoard();
		}
	}
	printf(&quot;\nTotal number of solutions for %d-Queens problem: %d\n&quot;,BSIZE,count);
	return 0;
}

//Initializes Chessboard array with blanks specified with 'X' character
void initBoard()
{
	//Row iteration
	for(row = 0;row &lt; BSIZE;++row)
	{
		//Column iteration
		for(col = 0;col &lt; BSIZE;++col)
		{
			board[row][col] = 'X';
		}
	}
}

//This functions trys to place queen in column 'colnum' and after row 'rownum'
//It returns row number on success, and '-1' on failure
int placeQueen(const int rownum, const int colnum)
{
	int flag;
	int temp = 0;
	for(row = rownum;row &lt; BSIZE;++row)
	{
		flag = 0;
		for(col = 0;col &lt; colnum;++col)
		{
			//check column
			if(board[row][col] == 'Q')
			{
				flag = -1;
				break;
			}
		}
		if(flag != -1)
		{
			//Checking diagonal squares
			if(checkCross(row,colnum) != -1)
			{
				//Placing queen
				board[row][colnum] = 'Q';
				return row;
			}
		}
	}
	//backtrack
	return -1;
}

//This function checks for queens diagonal to specified row 'rownum' and column 'colnum' values
//It return 0 if no queens are there in its diagonal squares, otherwise it returns -1
int checkCross(const int rownum,const int colnum)
{
	int rowtmp = rownum;
	int coltmp = colnum;
	//Checking upper diagonal squares
	while(--rowtmp &gt;= 0 &amp;&amp; --coltmp &gt;= 0)
	{
		if(board[rowtmp][coltmp] == 'Q')
		{
			return -1;			
		}
	}
	rowtmp = rownum;
	coltmp = colnum;
	//Checking lower diagonal squares
	while(++rowtmp &lt; BSIZE &amp;&amp; --coltmp &gt;= 0)
	{	
		if(board[rowtmp][coltmp] == 'Q')
		{
			return -1;			
		}
	}
	return 0;
}

//Uses recursive backtracking to place the queens
void backtrack(int coltmp)
{
	int rowtmp;
	//Exhaustive condition check
	if(coltmp &lt;= 0)
	{
		stop = 1;
		return;
	}
	coltmp-=1;
	//Finding the position of already placed queen
	for(rowtmp = 0;rowtmp &lt; BSIZE;++rowtmp)
	{
		if(board[rowtmp][coltmp] == 'Q')
		{
			board[rowtmp][coltmp] = 'X';
			break;
		}
	}
	//Repositioning the queen in the column 'coltmp' after row 'rowtmp+1'
	if(placeQueen(rowtmp+1,coltmp) == -1)
	{
		//If not positioned then backtracking
		backtrack(coltmp);
	}
	//Checking boundary conditions
	if(coltmp+1 &lt; BSIZE &amp;&amp; coltmp+1 &gt;=0)
	{
		//Backtracking until the queen is placed in column 'coltmp+1'
		while(placeQueen(0,coltmp+1) == -1)
		{
			backtrack(coltmp+1);
		}
	}
}

//Prints the Chessboard onto console 
void printBoard()
{
	printf(&quot;\n\n&quot;);
	//Row iteration
	for(row = 0;row &lt; BSIZE;++row)
	{
		//Column iteration
		for(col = 0;col &lt; BSIZE;++col)
		{
			printf(&quot;%3c&quot;,board[row][col]);
		}
		printf(&quot;\n\n&quot;);
	}
}
</pre></p>
<p>If there are any bugs or modifications to be done, just leave your comments below.</pre>
<br />Filed under: <a href='http://ucancode.wordpress.com/category/random/'>Random</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ucancode.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ucancode.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ucancode.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ucancode.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ucancode.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ucancode.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ucancode.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ucancode.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ucancode.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ucancode.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ucancode.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ucancode.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ucancode.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ucancode.wordpress.com/258/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ucancode.wordpress.com&amp;blog=4294209&amp;post=258&amp;subd=ucancode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ucancode.wordpress.com/2010/12/23/solution-to-n-queens-problem/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/21ff3fdc9568ec3a35d9b1ba6d85212e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ucancode</media:title>
		</media:content>
	</item>
		<item>
		<title>Synchronous message passing in Client-Server architecture</title>
		<link>http://ucancode.wordpress.com/2010/09/15/synchronous-message-passing-in-client-server-architecture/</link>
		<comments>http://ucancode.wordpress.com/2010/09/15/synchronous-message-passing-in-client-server-architecture/#comments</comments>
		<pubDate>Wed, 15 Sep 2010 17:11:18 +0000</pubDate>
		<dc:creator>ucancode</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[client server chat]]></category>
		<category><![CDATA[java synchronous message passing]]></category>
		<category><![CDATA[message passing in client server architecture]]></category>

		<guid isPermaLink="false">http://ucancode.wordpress.com/?p=245</guid>
		<description><![CDATA[We often come across a client-server architecture, it consists of a service requester machine called client and service provider machine called server. The services are exchanged between these machines using simple message passing. The message passing is of two kinds, synchronous and asynchronous. In asynchronous message passing, the machines exchange messages without any predefined order. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ucancode.wordpress.com&amp;blog=4294209&amp;post=245&amp;subd=ucancode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We often come across a client-server architecture, it consists of a service requester machine called client and service provider machine called server. The services are exchanged between these machines using simple message passing. The message passing is of two kinds, synchronous and asynchronous. In asynchronous message passing, the machines exchange messages without any predefined order. In synchronous message passing, the machines exchange messages with a predefined order and time sequences.</p>
<p>Java SE provides us with all things required to communicate messages between machines. Below is the program which performs synchronous message passing between machines.</p>
<p><span id="more-245"></span> The program is divided into two java classes, class SimpleClient is to be stored on client machine and class SimpleServer is to be stored on server machine.The process of message passing starts with server being ready to accept clients, and then client can request to connect to server and both client-server can exchange messages thereafter.The client can close the connection by using ctrl-c or a blank message.</p>
<p><strong>Note:</strong>In the below class files i have used the same machine as both client as well as server so we need to open two terminals/command prompts and assume one terminal/command prompt shell as client and another terminal/command prompt shell as server.If you would like to do it on different machines edit the SimpleClient class file line no.18, to the server machine&#8217;s IP address.</p>
<p><strong>The process of compilation:</strong> Compile the SimpleClient and SimpleServer class files on client and server machines respectively.</p>
<p>Client:   javac SimpleClient.java</p>
<p>Server:  javac SimpleServer.java</p>
<p><strong>The process of execution:</strong></p>
<p>Follow the below steps in client &#8211; server machines in the order specified:</p>
<p>Server:  java SimpleServer</p>
<p>Client:  java SimpleClient</p>
<p><span style="text-decoration:underline;"><strong>SimpleClient.java</strong></span></p>
<p><pre class="brush: java;">
import java.net.*;
import java.io.*;

public class SimpleClient {
	Socket clientSocket;
	BufferedReader clientInput;
	PrintWriter clientOutput;
	BufferedReader keyboardInput;
	String hostname;
	int port;
	String inputMessage,outputMessage;
	static boolean connection = false;
	public SimpleClient()
	{
		try
		{
			//localhost or 127.0.0.1
			hostname = &quot;127.0.0.1&quot;;
			port = 9090;
			//Creating socket for communicating with server
			clientSocket = new Socket(hostname,port);
			//Obtaining the input stream of the client to clientInput object
			clientInput = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
			//Obtaining the output stream of the client to clientOutput object
			clientOutput = new PrintWriter(clientSocket.getOutputStream(),true);
			//Obtaining the input stream of keyboard
			keyboardInput = new BufferedReader(new InputStreamReader(System.in));
			connection = true;
		}
		catch(SocketException e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
		catch(IOException e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
		catch(Exception e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
	}
	public void send()
	{
		try
		{
			System.out.print(&quot;Client : &quot;);
			//Receiving input from keyboard
			outputMessage = keyboardInput.readLine();
			if(outputMessage != null &amp;&amp; outputMessage.length() != 0)
			{
				//Sending the input received from keyboard to server
				clientOutput.println(outputMessage);
			}
			else
			{
				//Sending null and calling closeall method
				clientOutput.println(&quot;&quot;);
				clientOutput.flush();
				closeall();
			}
		}
		catch(SocketException e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
		catch(IOException e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
		catch(Exception e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
	}
	public void receive()
	{
		try
		{
			//Receiving message from server
			inputMessage = clientInput.readLine();
			if(inputMessage != null)
			{
				//Displaying message on output screen of client
				System.out.println(&quot;Server : &quot;+inputMessage);
			}
		}
		catch(SocketException e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
		catch(IOException e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
		catch(Exception e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
	}
	public void closeall()
	{
		try
		{
			System.out.println(&quot;Closing all I/O devices&quot;);
			keyboardInput.close();
			clientOutput.close();
			clientInput.close();
			clientSocket.close();
			connection = false;
		}
		catch(SocketException e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
		catch(IOException e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
		catch(Exception e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {
		SimpleClient client = new SimpleClient();
		while(connection != false)
		{
			client.receive();
			client.send();
		}
		if(connection != false)
			client.closeall();
	}
}

</pre></p>
<p><span style="text-decoration:underline;"><strong>SimpleServer.java</strong></span> <img title="More..." src="../wp-includes/js/tinymce/plugins/wordpress/img/trans.gif" alt="" /></p>
<p><pre class="brush: java;">
import java.net.*;
import java.io.*;

public class SimpleServer {
	ServerSocket connectionSocket;
	Socket serverSocket;
	BufferedReader serverInput;
	PrintWriter serverOutput;
	BufferedReader keyboardInput;
	int port;
	String inputMessage,outputMessage;
	static boolean connection = false;
	public SimpleServer()
	{
		port = 9090;
		try
		{
			//Initializing Server Socket for obtaining client requests
			connectionSocket = new ServerSocket(port);
			System.out.println(&quot;Server started and is ready to accept clients&quot;);
			//Accepting client connection request and obtaining the socket for communicating with client
			serverSocket = connectionSocket.accept();
			System.out.println(&quot;Client connection accepted&quot;);
			//Obtaining the input stream of the server to serverInput object
			serverInput = new BufferedReader(new InputStreamReader(serverSocket.getInputStream()));
			//Obtaining the output stream of the server to serverOutput object
			serverOutput = new PrintWriter(serverSocket.getOutputStream(),true);
			//Obtaining the input stream of keyboard
			keyboardInput = new BufferedReader(new InputStreamReader(System.in));
			connection = true;
			serverOutput.println(&quot;Server is ready to exchange messages.Start typing&quot;);
		}
		catch(SocketException e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
		catch(IOException e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
		catch(Exception e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
	}
	public void send()
	{
		try
		{
			System.out.print(&quot;Server : &quot;);
			//Receiving Input from keyboard
			outputMessage = keyboardInput.readLine();
			//Sending the input received from keyboard to client
			serverOutput.println(outputMessage);
		}
		catch(SocketException e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
		catch(IOException e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
		catch(Exception e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
	}
	public void receive()
	{
		try
		{
			//Receiving message from client
			inputMessage = serverInput.readLine();
			if(inputMessage != null &amp;&amp; inputMessage.length() != 0)
			{
				//Displaying message on output screen of server
				System.out.println(&quot;Client : &quot;+inputMessage);
			}
			else
			{
				closeall();
			}
		}
		catch(SocketException e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
		catch(IOException e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
		catch(Exception e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
	}
	public void closeall()
	{
		try
		{
			System.out.println(&quot;Closing all I/O devices&quot;);
			keyboardInput.close();
			serverOutput.close();
			serverInput.close();
			serverSocket.close();
			connectionSocket.close();
			connection  = false;
		}
		catch(SocketException e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
		catch(IOException e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
		catch(Exception e)
		{
			System.out.println(&quot;Something went wrong : &quot;+e.getMessage());
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {
		SimpleServer server = new SimpleServer();
		while(connection != false)
		{
			server.send();
			server.receive();
		}
		if(connection != false)
			server.closeall();
	}
}

</pre></p>
<p>If there are any bugs or modifications to be done, just leave your comments below.</p>
<br />Filed under: <a href='http://ucancode.wordpress.com/category/java/'>Java</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ucancode.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ucancode.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ucancode.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ucancode.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ucancode.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ucancode.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ucancode.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ucancode.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ucancode.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ucancode.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ucancode.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ucancode.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ucancode.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ucancode.wordpress.com/245/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ucancode.wordpress.com&amp;blog=4294209&amp;post=245&amp;subd=ucancode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ucancode.wordpress.com/2010/09/15/synchronous-message-passing-in-client-server-architecture/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/21ff3fdc9568ec3a35d9b1ba6d85212e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ucancode</media:title>
		</media:content>
	</item>
		<item>
		<title>Configure Eclipse to use Apache Tomcat and MySQL</title>
		<link>http://ucancode.wordpress.com/2010/07/05/configure-eclipse-to-use-apache-tomcat-and-mysql/</link>
		<comments>http://ucancode.wordpress.com/2010/07/05/configure-eclipse-to-use-apache-tomcat-and-mysql/#comments</comments>
		<pubDate>Mon, 05 Jul 2010 15:54:33 +0000</pubDate>
		<dc:creator>ucancode</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Apache Tomcat]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://ucancode.wordpress.com/?p=228</guid>
		<description><![CDATA[Recently, I had to work on Eclipse for writing Servlet and JSP programs which connects to the MySQL database. I want to configure Eclipse to use Apache Tomcat as server and connects to MySQL database using Servlet program so, I googled it to find what to do as many of them does, but I haven&#8217;t [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ucancode.wordpress.com&amp;blog=4294209&amp;post=228&amp;subd=ucancode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently, I had to work on Eclipse for writing Servlet and JSP programs which connects to the MySQL database. I want to configure Eclipse to use Apache Tomcat as server and connects to MySQL database using Servlet program so, I googled it to find what to do as many of them does, but I haven&#8217;t found any resource which provides straight forward guide to fulfill my requirement.</p>
<p>After doing some experimental things i have understood the procedure of configuring it so thought of putting a post about it. By the end of the following steps you will be able to configure your eclipse to run Servlet and JSP programs to connect to the MySQL database.</p>
<ol>
<li>Install MySQL Database.</li>
<li>Install Apache Tomcat.</li>
<li>Install Eclipse IDE for Java EE Developers.</li>
<li>Check whether MySQL is properly installed and running on the system by following below steps:
<ul>
<li>Open terminal or command prompt.</li>
<li>Enter &#8220;mysql -u root -p&#8221; (Here the username is root).</li>
<li>Enter the password when prompted.</li>
<li>Now create a database using &#8220;CREATE DATABASE EXAMPLE&#8221;(Here EXAMPLE is the name of database).</li>
<li>Select the database using &#8220;USE EXAMPLE&#8221;.</li>
<li>Create the tables according the required schema.</li>
</ul>
<p><span id="more-228"></span>
</li>
<li>Check whether Apache Tomcat is properly installed and running on the system by following below steps:
<ul>
<li>Type http://localhost:8080 in browser&#8217;s location bar.</li>
<li>The browser should display a welcome home page of Apache Tomcat, if its not then:<br />
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Start the Apache Tomcat Service Runner and try again, or check whether port 8080 is the one on which the Tomcat is running.
</li>
</ul>
</li>
<li>Select the connector for MySQL  Database :<br />
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  I have used the Thin Driver which is mysql-connector-java-5.1.12-bin.jar.You can use other JDBC-ODBC driver available with JDK but I don’t prefer it. MySQL Connector/J is the official JDBC driver for MySQL. When you download MySQL Connector/J it contains mysql-connector-java-5.1.12-bin.jar. This jar file contains the connection implementations.
</li>
<li>Place the jar file into common/lib folder hierarchy of Tomcat Home directory.</li>
<li>To configure Eclipse to use Apache Tomcat as server:
<ul>
<li>Find the Servers view in Eclipse IDE. You can open it using menu Window/Show View/Servers.</li>
<li>Right-click on Servers view and select New/Server.</li>
<li>Select the server type as Tomcat version installed on your system and click Next.</li>
<li>Set the Tomcat installation directory and click finish.</li>
<li>Now you will find a &#8220;Apache Tomcat at localhost&#8221; in the Servers view.</li>
</ul>
</li>
<li>To create Project:
<ul>
<li>Create a new project using menu File/New/Other and then Web/Dynamic Web Project.</li>
<li>Enter the name of the project and select the target runtime as Apache Tomcat.</li>
<li>Set the configuration as Default configuration for Apache Tomcat and click Finish.</li>
</ul>
</li>
<li>To create Servlet:
<ul>
<li>Go to the folder hierarchy and right-click on the WebContent and select New/Other and then Web/Servlet.</li>
<li>Enter Package name and Class name for Servlet and other details and click Finish.</li>
</ul>
</li>
<li>Connection URL:Format of the Connection URL is “jdbc:mysql://[host][:port]/[database][?properties][=values]&#8220;.<br />
For example, &#8220;jdbc:mysql:localhost:3306/EXAMPLE?user=root&amp;password=ucancode&#8221;.<br />
Here,</p>
<ul>
<li>host is host name where MySQL Database is running(localhost or 127.0.0.1),</li>
<li> port is port number where MySQL Database is running(Default port number for MySQL is 3306),</li>
<li>database is database name which is to be connected(Database Name is EXAMPLE), and</li>
<li>property is supplied for purposes like username, password, etc(user is &#8220;root&#8221; and password is &#8220;ucancode&#8221;).</li>
</ul>
</li>
<li>To run Servlet,
<ul>
<li>Right-click on the Project name in Project Explorer, and select Run as/Run on server.</li>
<li>Select the Apache Tomcat and click finish.</li>
<li>The output will be generated in browser.</li>
</ul>
</li>
</ol>
<p>If you have some difficulties or doubts or any troubleshooting, leave a comment.</p>
<br />Filed under: <a href='http://ucancode.wordpress.com/category/eclipse/'>Eclipse</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ucancode.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ucancode.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ucancode.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ucancode.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ucancode.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ucancode.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ucancode.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ucancode.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ucancode.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ucancode.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ucancode.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ucancode.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ucancode.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ucancode.wordpress.com/228/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ucancode.wordpress.com&amp;blog=4294209&amp;post=228&amp;subd=ucancode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ucancode.wordpress.com/2010/07/05/configure-eclipse-to-use-apache-tomcat-and-mysql/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/21ff3fdc9568ec3a35d9b1ba6d85212e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ucancode</media:title>
		</media:content>
	</item>
		<item>
		<title>Applet : Part 4</title>
		<link>http://ucancode.wordpress.com/2009/07/26/applet-part-4/</link>
		<comments>http://ucancode.wordpress.com/2009/07/26/applet-part-4/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 09:58:41 +0000</pubDate>
		<dc:creator>ucancode</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[applet]]></category>
		<category><![CDATA[Infix to Postfix conversion]]></category>

		<guid isPermaLink="false">http://ucancode.wordpress.com/?p=219</guid>
		<description><![CDATA[This applet program takes an Infix expression and converts it into an Post-fix expression. Remember to give the Infix expression like this &#8220;a+b&#8221;, but not with the numbers like this &#8220;2+4&#8243;. If there are any bugs or modifications to be done, just leave your comments below. Posted in Java<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ucancode.wordpress.com&amp;blog=4294209&amp;post=219&amp;subd=ucancode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This applet program takes an Infix expression and converts it into an Post-fix expression.<br />
Remember to give the Infix expression like this &#8220;a+b&#8221;, but not with the numbers like this &#8220;2+4&#8243;.</p>
<p><span id="more-219"></span></p>
<p><pre class="brush: java;">
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class Applet4 extends Applet implements ActionListener
{
	TextField tf1,tf2;
	Button b1,b2;
	String mode,infix;
	StringBuffer postfix;
	Stack&lt;Character&gt; s1;
	public void init()
	{
		tf1=new TextField(25);
		tf2=new TextField(25);
		b1=new Button(&quot;Submit&quot;);
		b2=new Button(&quot;Clear&quot;);
		setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
		add(new Label(&quot;Infix to Postfix expression Conversion&quot;));
		add(new Label(&quot;Enter the expression:&quot;));
		add(tf1);
		add(b1);
		b1.addActionListener(this);
		add(b2);
		b2.addActionListener(this);
		add(new Label(&quot;The Postfix Expression is : &quot;));
		add(tf2);
		tf2.setEditable(false);
	}
	public void actionPerformed(ActionEvent ae)
	{
		mode=ae.getActionCommand();
		if(mode.equals(&quot;Submit&quot;))
		{
			infix=tf1.getText();
			postfix=new StringBuffer();
			s1=new Stack&lt;Character&gt;();
			convert();
			repaint();
		}
		else if(mode.equals(&quot;Clear&quot;))
		{
			repaint();
		}
	}
	public void convert()
	{
		s1.push('(');
		for(int i=0;i&lt;infix.length();i++)
		{
			if(Character.isLetter(infix.charAt(i)))
			{
				postfix.append(infix.charAt(i));
			}
			else if(infix.charAt(i)=='(')
			{
				s1.push(infix.charAt(i));
			}		
			else if(infix.charAt(i)==')')
			{
				while(s1.peek()!='(')
				{
					postfix.append(s1.pop());
				}
				s1.pop();
			}
			else if(icp(infix.charAt(i))&gt;=icp(s1.peek()))
			{
				s1.push(infix.charAt(i));
			}
			else
			{
				postfix.append(s1.pop());
				s1.push(infix.charAt(i));
			}
		}
		while(s1.peek()!='(')
		{
			postfix.append(s1.pop());
		}
	}
	public int icp(char x)
	{
		int k=-1;
		switch(x)
		{
			case '(':
				k=0;
				break;
			case '+':
			case '-':
				k=1;
				break;
			case '*':
			case '/':
			case '%':
				k=2;
				break;
			case '^':		
				k=4;
				break;
		}
		return k;
	}
	
	public void paint(Graphics g)
	{
		tf2.setText(&quot;&quot;);
		if(mode.equals(&quot;Submit&quot;))
		{	
			if(postfix.equals(&quot;&quot;)||infix.equals(&quot;&quot;))
			{
				tf2.setText(&quot;Enter a proper expression&quot;);
			}
			else
			{
				tf2.setText(new String(postfix));
			}
		}
		else if(mode.equals(&quot;Clear&quot;))
		{
			tf1.setText(&quot;&quot;);
		}
	}
}

/*&lt;applet code=&quot;Applet4&quot;  width=260 height=220&gt; Cannot load the applet&lt;/applet&gt;*/
</pre><br />
If there are any bugs or modifications to be done, just leave your comments below.</p>
<br />Posted in Java  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ucancode.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ucancode.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ucancode.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ucancode.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ucancode.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ucancode.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ucancode.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ucancode.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ucancode.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ucancode.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ucancode.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ucancode.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ucancode.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ucancode.wordpress.com/219/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ucancode.wordpress.com&amp;blog=4294209&amp;post=219&amp;subd=ucancode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ucancode.wordpress.com/2009/07/26/applet-part-4/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/21ff3fdc9568ec3a35d9b1ba6d85212e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ucancode</media:title>
		</media:content>
	</item>
		<item>
		<title>Applet : Part 3</title>
		<link>http://ucancode.wordpress.com/2009/07/26/applet-part-3/</link>
		<comments>http://ucancode.wordpress.com/2009/07/26/applet-part-3/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 09:53:39 +0000</pubDate>
		<dc:creator>ucancode</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[applet]]></category>
		<category><![CDATA[permutation with repetition]]></category>

		<guid isPermaLink="false">http://ucancode.wordpress.com/?p=217</guid>
		<description><![CDATA[This applet program is much different from the previously posted applet programs.This applet program takes a string and gives the possible permutations with repetition of words and total number of permutations with repetition of words. There are many ways to get permutation of a string with repetition of words, i have implemented it using the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ucancode.wordpress.com&amp;blog=4294209&amp;post=217&amp;subd=ucancode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This applet program is much different from the previously posted applet programs.This applet program takes a string and gives the possible permutations with repetition of words and total number of permutations with repetition of words.</p>
<p>There are many ways to get permutation of a string with repetition of words, i have implemented it using the following algorithm :</p>
<pre>
<code>
 //This is Countdown Quick-Perm Algorithm:

   let a[] represent an arbitrary list of objects to permute
   let N equal the length of a[]
   create an integer array p[] of size N+1 to control the iteration
   initialize p[0] to 0, p[1] to 1, p[2] to 2, ..., p[N] to N
   initialize index variable i to 1
   while (i &lt; N) do {
      decrement p[i] by 1
      if i is odd, then let j = p[i] otherwise let j = 0
      swap(a[j], a[i])
      let i = 1
      while (p[i] is equal to 0) do {
         let p[i] = i
         increment i by 1
      } // end while (p[i] is equal to 0)
   } // end while (i &lt; N)
</code>
</pre>
<p>If you are not clear with the above description try it yourself, the program is below:</p>
<p><span id="more-217"></span></p>
<p><pre class="brush: java;">
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class Applet3 extends Applet implements ActionListener
{
	TextField text;
	Button submit,clear;
	TextArea result;
	String mode,input,output;
	ArrayList&lt;String&gt; l1=new ArrayList&lt;String&gt;();
	Iterator&lt;String&gt; i1;
	int count;
	public void init()
	{
		text=new TextField(20);
		submit=new Button(&quot;Submit&quot;);
		clear=new Button(&quot;Clear&quot;);
		result=new TextArea(&quot;&quot;,15,30,TextArea.SCROLLBARS_VERTICAL_ONLY);
		result.setEditable(false);
		setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
		add(new Label(&quot;Permutations of a String with repetition of words&quot;,Label.CENTER));
		add(new Label(&quot;Enter a String:&quot;,Label.RIGHT));
		add(text);
		add(submit);
		submit.addActionListener(this);
		add(clear);
		clear.addActionListener(this);
		add(result);
	}
	public void actionPerformed(ActionEvent ae)
	{
		mode=ae.getActionCommand();
		if(mode.equals(&quot;Submit&quot;))
		{
			input=text.getText();
			permut();
		}
		repaint();
	}
	public void permut()
	{
		int i,j;
		char t;
		StringBuffer temp=new StringBuffer();
		char s[]=input.toCharArray();
		int N=input.length();
		int p[]=new int[N+1];
		l1.add(input);
		for(i=0;i&lt;N+1;i++)
		{
			p[i]=i;
		}
		i=1;
		while(i&lt;N)
		{
			p[i]-=1;
			if((i%2)!=0)
				j=p[i];
			else
				j=0;
			t=s[j];
			s[j]=s[i];
			s[i]=t;
			for(int k=0;k&lt;N;k++)
			{
				temp.append(s[k]);
			}
			output=new String(temp);
			if(l1.contains(output)==false)
				l1.add(output);
			temp.delete(0,N+1);
			i=1;
			while(p[i]==0)
			{
				p[i]=i;
				i++;
			}
		}
	}
	public void paint(Graphics g)
	{
		result.setText(&quot;&quot;);
		if(mode.equals(&quot;Submit&quot;))
		{
			if(input.equals(&quot;&quot;))
			{
				result.append(&quot;Enter a String&quot;);
			}
			else
			{
				i1=l1.iterator();
				while(i1.hasNext())
				{
					result.append(&quot;\n&quot;+i1.next());
				}
				result.append(&quot;\nTotal Permutations are : &quot;+l1.size());
			}
		}
		else
		if(mode.equals(&quot;Clear&quot;))
		{
			text.setText(&quot;&quot;);
		}
		input=&quot;&quot;;
		l1.clear();
	}
}

/*&lt;applet code=&quot;Applet3&quot;  width=330  height=360&gt; Cannot load the applet&lt;/applet&gt;*/
</pre></p>
<p>If there are any bugs or modifications to be done, just leave your comments below.</p>
<br />Posted in Java  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ucancode.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ucancode.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ucancode.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ucancode.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ucancode.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ucancode.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ucancode.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ucancode.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ucancode.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ucancode.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ucancode.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ucancode.wordpress.com/217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ucancode.wordpress.com/217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ucancode.wordpress.com/217/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ucancode.wordpress.com&amp;blog=4294209&amp;post=217&amp;subd=ucancode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ucancode.wordpress.com/2009/07/26/applet-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/21ff3fdc9568ec3a35d9b1ba6d85212e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ucancode</media:title>
		</media:content>
	</item>
	</channel>
</rss>
