<?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>Andr&#233; L. S. &#187; Java</title>
	<atom:link href="http://www.andrels.com/wp-en_US/index.php/category/development/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andrels.com/wp-en_US</link>
	<description>Softwares Development, Technology and Games</description>
	<lastBuildDate>Wed, 08 Feb 2012 12:39:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Why to use File.separator and File.pathSeparator</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2011/08/why-to-use-file-separator-and-file-pathseparator/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2011/08/why-to-use-file-separator-and-file-pathseparator/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 16:17:49 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Quick tips]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[programing]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=190</guid>
		<description><![CDATA[Java programmers knows about methods quoted in title, but many doesn&#8217;t care with them. These methods are useful for programmer<a href="http://www.andrels.com/wp-en_US/index.php/2011/08/why-to-use-file-separator-and-file-pathseparator/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>Java programmers knows about methods quoted in title, but many doesn&#8217;t care with them.</p>
<p>These methods are useful for programmer that do not knows wich characters represents file separator and path separator at OS that supports your application.</p>
<p>Linux/Unix, the methods <b><a href="http://download.oracle.com/javase/1,5.0/docs/api/java/io/File.html#separator">File.separator</a></b> and <b><a href="http://download.oracle.com/javase/1,5.0/docs/api/java/io/File.html#pathSeparator">File.pathSeparator</a></b> returns &#8220;/&#8221; and &#8220;.&#8221;, while in Windows, these methods returns &#8220;\&#8221; (or &#8220;\\&#8221; &#8211; escape) and &#8220;;&#8221;.</p>
<p>In recent case, the code below threw exception FileNotFoundException running over Linux, but not running over Windows:</p>
<pre class="brush:java">
String appPath = ctx.getRealPath();
String filePath = appPath + "\\" + "WEB-INF/classes/my/application/packages/";

File file = new File(filePath, "report.pdf");
OutputStream out = new FileOutputStream(file);
...
</pre>
<p>Worked in both systems after to replace &#8220;\\&#8221; by File.separator in line 2:</p>
<pre class="brush:java">
String appPath = ctx.getRealPath();
String filePath = appPath + File.separator + "WEB-INF/classes/my/application/packages/";

File file = new File(filePath, "report.pdf");
OutputStream out = new FileOutputStream(file);
...
</pre>
<p>Utilization of these methods, besides a good practice, is very usefull when same version of an application is running over differents operacional systems.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2011/08/why-to-use-file-separator-and-file-pathseparator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to read and write CLOB fields</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2011/05/how-to-read-and-write-clob-fields/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2011/05/how-to-read-and-write-clob-fields/#comments</comments>
		<pubDate>Fri, 20 May 2011 16:39:34 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[blob]]></category>
		<category><![CDATA[clob]]></category>
		<category><![CDATA[data base]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=167</guid>
		<description><![CDATA[The Character Large Object (or CLOB) is a commonly found in databases and used to store high quantity of characters.<a href="http://www.andrels.com/wp-en_US/index.php/2011/05/how-to-read-and-write-clob-fields/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>The Character Large Object (or CLOB) is a commonly found in databases and used to store high quantity of characters.</p>
<p>At MySQL, for example, this field is called MEMO.</p>
<h4>Writing CLOB field</h4>
<p>The method <em>setAsciiStream</em> of <em>PreparedStatement</em> allow to pass data to a CLOB.</p>
<pre class="brush:sql">ps.setAsciiStream(bindPosition, inputStream, textLength);</pre>
<p><strong>bindPosition</strong> &#8211; Position in PreparedStatment&#8217;s CLOB field.<br />
<strong>inputStream</strong> &#8211; Used to pass data.<br />
<strong>textLength</strong> &#8211; Data (text) length.</p>
<p><strong>Full code:</strong></p>
<pre class="brush:java">String sql = "INSERT INTO TABLE (text) VALUES(?)";
		try{
			String txt = readTxtFile();
			ByteArrayInputStream bais = new ByteArrayInputStream(txt.getBytes());

			PreparedStatement ps = conexao.prepareStatement(sql);
			//CLOB is '?' at first position
			ps.setAsciiStream(1, bais, txt.length());

			ps.execute();

			ps.close();
		}catch (Exception e) {
			e.printStackTrace();
		}</pre>
<h4>Retrieving CLOB data</h4>
<p>We&#8217;re using SELECT clause, this clause returns a ResultSet to fetch data and, calling getClob method, passing column name or your position in the query, it give to you a Clob object.</p>
<pre class="brush:sql">rs.getClob("xml");</pre>
<p><strong>Full code:</strong></p>
<pre class="brush:java">String sql = "SELECT xml FROM TEST";
		try{
			PreparedStatement ps = conexao.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();

			while(rs.next()){
				Clob clob = rs.getClob("xml");
				BufferedReader reader = new BufferedReader(clob.getCharacterStream());
				StringBuffer strBuf = new StringBuffer();

				String linha = null;
				while((linha = reader.readLine()) != null){
					strBuf.append(linha);
//Character.LINE_SEPARATOR insert break line
					strBuf.append((char)Character.LINE_SEPARATOR);
				}

				System.out.println("=========== CLOB ===========");
				System.out.println(strBuf.toString());
			}

			rs.close();
			ps.close();
		}catch (Exception e) {
			e.printStackTrace();
		}</pre>
<p>That&#8217;s it! Easy and painless <img src='http://www.andrels.com/wp-en_US/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Download full code <a href="http://www.andrels.com/wp-pt_BR/wp-content/plugins/download-monitor/download.php?id=6">here</a></p>
<p>To write a BLOB see this <a href="http://www.andrels.com/wp-en_US/index.php/2010/02/saving-files-in-blob-table-column-of-a-data-base/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">tutorial</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2011/05/how-to-read-and-write-clob-fields/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up internet access through proxy server</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2010/03/setting-up-internet-access-through-proxy-server/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2010/03/setting-up-internet-access-through-proxy-server/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 01:54:22 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Quick tips]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[prompt]]></category>
		<category><![CDATA[proxy]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=116</guid>
		<description><![CDATA[Today I had a trouble in my workplace when a client application, running through a terminal (DOS prompt), not reach<a href="http://www.andrels.com/wp-en_US/index.php/2010/03/setting-up-internet-access-through-proxy-server/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>Today I had a trouble in my workplace when a client application, running through a terminal (DOS prompt), not reach the server hosted in the internet, this is because the company where I work use proxy.</p>
<p>After some tries I found two solutions to solve my access problem: first was pass as <em>Java</em> parameters the proxy&#8217;s configurations.</p>
<pre class="brush:shell">$ java -Dhttp.proxyHost=serv -Dhttp.proxyPort=port -Dhttp.proxyUser=user -Dhttp.proxyPassword=pass  ClassJava
</pre>
<p><strong>-Dhttp.proxyHost</strong> = IP or host name of server proxy<br />
<strong>-Dhttp.proxyPort</strong> = Proxy port<br />
<strong>-Dhttp.proxyUser</strong> = User<br />
<strong>-Dhttp.proxyPassword</strong> = Password</p>
<p>This way the class <em>ClassJava</em> will have access to internet through proxy server.</p>
<p>Another way, was insert the settings in own class:</p>
<pre class="brush:java">public static void main(String[] args){
...
System.getProperties().put("proxySet", "true");
System.getProperties().put("http.proxyHost", "serv");
System.getProperties().put("http.proxyPort", "port");
System.getProperties().put("http.proxyUser", "user");
System.getProperties().put("http.proxyPassword", "password");
...
}
</pre>
<p><strong>proxySet</strong> = Connect, or not, through proxy server<br />
<strong>http.proxyHost</strong> = IP or host name of server proxy<br />
<strong>http.proxyPortt</strong> = Proxy port<br />
<strong>http.proxyUse</strong> = User<br />
<strong>http.proxyPassword</strong> = Password</p>
<p>Using this resource you can set your application to access the internet through proxy server.</p>
<p>I hope help you.  Bye! <img src='http://www.andrels.com/wp-en_US/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2010/03/setting-up-internet-access-through-proxy-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating transparent and shaped windows using Java Swing/AWT</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2010/03/creating-transparent-and-shaped-windows-using-java-swingawt/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2010/03/creating-transparent-and-shaped-windows-using-java-swingawt/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 02:28:58 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[awt]]></category>
		<category><![CDATA[jframe]]></category>
		<category><![CDATA[swing]]></category>
		<category><![CDATA[transparency]]></category>
		<category><![CDATA[window]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=107</guid>
		<description><![CDATA[The Java AWT offer various possibilities about window manipulation. Today I&#8217;ll talk about two possibilities using class AWTUtilities. Building a<a href="http://www.andrels.com/wp-en_US/index.php/2010/03/creating-transparent-and-shaped-windows-using-java-swingawt/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>The Java AWT offer various possibilities about window manipulation. Today I&#8217;ll talk about two possibilities using class AWTUtilities.</p>
<h3><strong>Building a transparent window</strong></h3>
<p>To make a <strong>Window</strong> (JFrame, JDialog &#8230;) with alpha effect, you should invoke the method <strong>AWTUtilities.setWindowOpacity</strong>. This method parameters are: the window to apply transparency and transparency degree, that can be between 0 (zero) and 1, being 0 invisible and 1 totally visible.</p>
<pre class="brush:java">JFrame  window = new JFrame("My Window");

//70% of transparency
AWTUtilities.setWindowOpacity(window, .7f);
window.setSize(800,600);
window.setVisible(true);
</pre>
<p>The result will be:<a href="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2010/03/2.jpg"><img class="aligncenter size-full wp-image-174" title="2" src="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2010/03/2.jpg" alt="" width="480" height="368" /></a></p>
<h3><strong>Changing window shape</strong></h3>
<p>To change the window shape you should use the method <strong>AWTUtilities.setWindowShape</strong>. This method parameters are: window that will be changed and the new shape (java.awt.Shape) of the window.</p>
<p>The most efficiently form to use is to implement the method <em>componentResized()</em>, cause you may recompute the window and components size</p>
<p>Here I&#8217;ll use a triangle with 70% of transparency.</p>
<pre class="brush:java">final JFrame  window = new JFrame("My Window");

try {
	//Add the ComponentListener to implement componentResized method
	window.addComponentListener(new ComponentAdapter(){
		@Override
		//building componentResized
		public void componentResized(ComponentEvent e) {
			int[] x = {0,400,800}; //Pontos X do polígono
			int[] y = {600,0,600}; //Pontos Y do polígono

			//Triangle with 800 w x 600 h
			Shape shape = new Polygon(x, y, 3);

			AWTUtilities.setWindowShape(window, shape);

			//70% of transparency
			AWTUtilities.setWindowOpacity(window, 0.7f);
		}
	});
} catch (SecurityException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
} catch (IllegalArgumentException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}

window.setUndecorated(true); //removing title bar
window.setSize(800,600);
window.setVisible(true);
</pre>
<p>Notice that the method <strong><em>setUndecorated( )</em></strong> was invoked with <em>true</em> as value. This method are responsible by hide the title bar (one with icon and the maximize, minimize and close buttons).  This is really necessary, because with title bar visible the window are not be shaped.</p>
<p>The result:<a href="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2010/03/1.jpg"><img class="aligncenter size-full wp-image-175" title="1" src="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2010/03/1.jpg" alt="" width="480" height="365" /></a></p>
<p>I hope you enjoy&#8230; <img src='http://www.andrels.com/wp-en_US/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2010/03/creating-transparent-and-shaped-windows-using-java-swingawt/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Saving files in BLOB table column of a data base</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2010/02/saving-files-in-blob-table-column-of-a-data-base/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2010/02/saving-files-in-blob-table-column-of-a-data-base/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 00:46:06 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Quick tips]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[blob]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=102</guid>
		<description><![CDATA[To insert a file, is it in any format, you need call the method setBinaryStream, implemented by PreparedStatement. PreparedStatemente.setBinaryStream(int index,<a href="http://www.andrels.com/wp-en_US/index.php/2010/02/saving-files-in-blob-table-column-of-a-data-base/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>To insert a file, is it in any format, you need call the method <i>setBinaryStream</i>, implemented by PreparedStatement.</p>
<pre class="brush:java">
PreparedStatemente.setBinaryStream(int index, Inputstream is, int length);
</pre>
<p>In sample, we set a table called <i>FILE</i>that contains <b>BLOB</b> column called <i>BIN</i>.</p>
<pre class="brush:java">
//Normal connection, as any JDBC connection
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@&lt;IP&gt;:&lt;PORT&gt;:&lt;SID&gt;","&lt;USER&gt;","&lt;PASSWORD&gt;");

//Reading the file and retrieving an InputStream
File file= new File("&lt;COMPLETE_FILE_PATH&gt;");
FileInputStream fis = new FileInputStream(file);

//Preparing statement
PreparedStatement ps = conn.prepareStatement("INSERT INTO FILE(bin) VALUES(?)");

//Passing InputStream and file length
ps.setBinaryStream(1, fis, (int)file.length());

ps.execute();

ps.close();
conn.close();
</pre>
<p>I used Oracle 8i to execute this sample. I haven&#8217;t a MySQL/PostgreSQL/MS SQL Server in my dispose, then you&#8217;ll responsible for testing in this data bases and send me the results, OK <img src='http://www.andrels.com/wp-en_US/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Thanks! Until next time!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2010/02/saving-files-in-blob-table-column-of-a-data-base/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Retrieving an Oracle cursor in Java</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2010/01/retieving-an-oracle-cursor-in-java/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2010/01/retieving-an-oracle-cursor-in-java/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 16:22:32 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=99</guid>
		<description><![CDATA[Many people come here looking for one way to retrieve cursors of Oracle procedures in Java. To them, I&#8217;ve here<a href="http://www.andrels.com/wp-en_US/index.php/2010/01/retieving-an-oracle-cursor-in-java/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>Many people come here looking for one way to retrieve cursors of Oracle <i>procedures</i> in Java. To them, I&#8217;ve here are a tutorial showing how to do this.</p>
<p>To retrieve the cursor you should declare him how a <i>REF CURSOR</i> in <i>Package spec</i>.</p>
<pre class="brush:sql">  --Creating the REF CURSOR type
  type g_cursor is ref cursor;
</pre>
<p>In both, <i>spec</i> and <i>body</i>, you need declare an <i>out REF CURSOR</i> variable in procedure signature, how cited above.</p>
<pre class="brush:sql">  procedure PRO_RETURN_CARS(
    i_id     in     tbl_car.car_id%type,
    o_cursor in out g_cursor);
</pre>
<p>The cursor must be opened in <i>procedure&#8217;s body</i> to return, this way:</p>
<pre class="brush:sql">
open o_cursor for
          select car_id, company, model, color, hp, price
          from tbl_car
          where car_id = i_id;
</pre>
<p>The complete <i>Package</i>:</p>
<pre class="brush:sql">create or replace package PAC_CURSOR is
  --Creating REF CURSOR type
  type g_cursor is ref cursor;

  --Procedure that return the cursor
  procedure PRO_RETURN_CARS(
    i_id     in     tbl_car.car_id%type,
    o_cursor in out g_cursor); -- Our cursor

end PAC_CURSOR;
/

create or replace package body PAC_CURSOR is
  procedure PRO_RETURN_CARS(
    i_id     in     tbl_car.car_id%type,
    o_cursor in out g_cursor) is

       begin
        --Opening the cursor to return matched rows
        open o_cursor for
          select car_id, company, model, color, hp, price
          from tbl_car
          where car_id = i_id;

  end PRO_RETURN_CARS;

end PAC_CURSOR;
</pre>
<p>We have Oracle side ready, now we need create Java call</p>
<p>How the cursors are being returned by a <i>procedure</i>, we&#8217;ll used a <i>java.sql.CallableStatement</i> instance.</p>
<pre class="brush:java">
CallableStatement cs = conn.prepareCall("{call PAC_CURSOR.PRO_RETURN_CARS(?,?)}");
</pre>
<p>The <i>registerOutParameter</i> will obtain <i>oracle.jdbc.OracleTypes.CURSOR</i> type and return a <i>java.sql.ResultSet</i> instance. We can iterate the <i>ResultSet</i> like a common <i>Iterator</i>.<br />
Each row column returned by <i>SELECT</i> will be represented how a map, using correspondent getter. For example, we will call <i>getString(&lt;column name&gt;)</i> method when value of column is a <i>varchar</i>, <i>getDate(&lt;column name&gt;)</i> when is a date and etc.</p>
<p>The complete code will be like this:</p>
<pre class="brush:java">
//Calling Oracle procedure
CallableStatement cs = conn.prepareCall("{call PAC_CURSOR.PRO_RETURN_CARS(?,?)}");

//Defining type of return
cs.registerOutParameter("o_cursor", OracleTypes.CURSOR);
cs.setLong("i_id", id);

cs.execute();//Running the call

//Retrieving the cursor as ResultSet
ResultSet rs = (ResultSet)cs.getObject("o_cursor");

//Iterating the returned rows
while(rs.next()){
	//Getting column values
	System.out.println("ID: " + rs.getLong("car_id"));
	System.out.println("Manufacturer: " + rs.getString("company"));
	System.out.println("Model: " + rs.getString("model"));
	System.out.println("Color: " + rs.getString("color"));
	System.out.println("HP: " + rs.getString("hp"));
	System.out.println("Price: " + rs.getFloat("price"));
}
</pre>
<p>In the end you will get any value returned in a <i>SELECT</i> clause.</p>
<p>See ya!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2010/01/retieving-an-oracle-cursor-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating &#8216;EXE&#8217; to start your Java applications</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2009/10/generating-exe-to-start-your-java-applications/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2009/10/generating-exe-to-start-your-java-applications/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 23:52:08 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[exe]]></category>
		<category><![CDATA[jsmooth]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=89</guid>
		<description><![CDATA[Many developers need, or have needed, distribute their Java applications so that Windows users could start them naturally, not running<a href="http://www.andrels.com/wp-en_US/index.php/2009/10/generating-exe-to-start-your-java-applications/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>Many developers need, or have needed, distribute their Java applications so that Windows users could start them naturally, not running <em>java -jar &lt;jar file&gt;</em> command or batch (.BAT) file.</p>
<p>I&#8217;ve been there too, then I found a easy and with many resources solution: <a href="http://jsmooth.sourceforge.net/" target="_blank">JSmooth</a></p>
<p>This software allow you &#8220;transform&#8221; your JAR file in an executable (EXE), but, of course, will need the JVM already installed and running.</p>
<p>Here I only have mentioned the settings that I consider important, then let&#8217;s go!</p>
<hr />Download JSmooth in <a href="http://sourceforge.net/projects/jsmooth/files/" target="_blank">http://sourceforge.net/projects/jsmooth/files/</a>;</p>
<p>After install (or unzip, this depends of file that you have downloaded) run him;</p>
<p>In the side menu, click in &#8220;Skeleton&#8221;;</p>
<p style="text-align: center;"><a href="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/1.jpg"><img class="size-full wp-image-119 aligncenter" title="1" src="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/1.jpg" alt="1" width="524" height="364" /></a></p>
<p>In the &#8220;Skeleton Selection&#8221; screen you need define how application will be run, select &#8220;Window Wrapper&#8221;.</p>
<p>In &#8220;Skeleton Properties&#8221;, you need define a message when user have no JVM installed (&#8220;Message&#8221; field) and where can be downloaded (&#8220;URL&#8221; field).</p>
<p>The &#8220;Launch java app in the exe process&#8221; field define if JAR file will be executed in same process of EXE (only the executable process will be displayed in Windows Task Manager), otherwise the <em>javaw.exe</em> will be displayed too.</p>
<p>The &#8220;Single Instance&#8221; field define if more than one instance can be opened.</p>
<p>&#8220;Debug Console&#8221; open the EXE from prompt window, displaying possibles outputs.</p>
<p>Now click in &#8220;Executable&#8221;</p>
<p style="text-align: center;"><a href="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/2.jpg"><img class="aligncenter size-full wp-image-120" title="2" src="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/2.jpg" alt="2" width="524" height="364" /></a></p>
<p>In &#8220;Executable Setting&#8221; you inform where EXE will be builded (&#8220;Executable Binary&#8221; field), the EXE&#8217;s icon (&#8220;Executable Icon&#8221; filed) and what will be the application execution directory.</p>
<p>Click in &#8220;Application&#8221;</p>
<p style="text-align: center;"><a href="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/3.jpg"><img class="aligncenter size-full wp-image-121" title="3" src="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/3.jpg" alt="3" width="524" height="364" /></a></p>
<p>First, click in the icon <img class="size-full wp-image-125 alignnone" title="7" src="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/7.jpg" alt="7" width="50" height="27" /> and select JAR that contains the main class.</p>
<p>After, select the main class in the field &#8220;Main Class&#8221; clicking in button <img class="alignnone size-full wp-image-126" title="8" src="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/8.jpg" alt="8" width="39" height="20" />.</p>
<p>In the field &#8220;Application arguments&#8221; you can inform necessaries parameters for your main class.</p>
<p>&#8220;Embedded JAR&#8221; field allows you to aggregate your JAR file in EXE file, in other words, only EXE file will be necessarie, because the JAR will be uncompressed by EXE in each execution.</p>
<p>Now click in &#8220;JVM Selection&#8221;.</p>
<p style="text-align: center;"><a href="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/4.jpg"><img class="aligncenter size-full wp-image-122" title="4" src="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/4.jpg" alt="4" width="524" height="364" /></a></p>
<p>Here you can define the minimum and maximum version of JVM that your application support.</p>
<p>The &#8220;JVM Serach Sequence&#8221; inform the seek order of <em>javaw.exe</em> file, in this case, he search in resgistry first, after in JAVA_HOME enviroment and so.</p>
<p>Click in &#8220;JVM Configuration&#8221;.</p>
<p style="text-align: center;"><a href="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/5.jpg"><img class="aligncenter size-full wp-image-123" title="5" src="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/5.jpg" alt="5" width="524" height="364" /></a></p>
<p>Here the maximum and minimum memory available for your application can be configured, as the options that can passed to JVM.</p>
<p>Until here we only have configured the JSmooth. To build the EXE file click in button <img class="size-full wp-image-124 alignnone" title="6" src="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/6.jpg" alt="6" width="32" height="30" />. If you don&#8217;t have saved the project, a new window will open to choose the place to save. Done it, the EXE file will be create in directory mentioned in &#8220;Executable Binary&#8221; field of &#8220;Executable&#8221; screen.</p>
<p>Now just execute the EXE file and your application will be run!</p>
<p style="text-align: left;">
<p>To more information visit <a href="http://jsmooth.sourceforge.net/" target="_blank">http://jsmooth.sourceforge.net/</a></p>
<p style="text-align: left;">
<p style="text-align: left;">I hope you enjoyed, feel free to comment!</p>
<p style="text-align: left;">Until next! <img src='http://www.andrels.com/wp-en_US/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2009/10/generating-exe-to-start-your-java-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Retrieving objects collection from Oracle procedure</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2009/09/retrieving-objects-collection-from-oracle-procedure/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2009/09/retrieving-objects-collection-from-oracle-procedure/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 22:25:07 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[collection]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=79</guid>
		<description><![CDATA[As I&#8217;ve promised in post &#8220;Learn to pass a Java Object as Oracle Procedure parameter&#8220;, I&#8217;ll show how retrieve object<a href="http://www.andrels.com/wp-en_US/index.php/2009/09/retrieving-objects-collection-from-oracle-procedure/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>As I&#8217;ve promised in post &#8220;<a href="http://www.andrels.com/wp-en_US/index.php/2009/06/learn-to-pass-a-java-object-as-oracle-procedure-parameter#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">Learn to pass a Java Object as Oracle Procedure parameter</a>&#8220;, I&#8217;ll show how retrieve object that have a collection of objects as attribute through of an <a href="http://www.oracle.com/">Oracle</a> procedure. Is highly recommended to read <a href="http://www.andrels.com/wp-en_US/index.php/2009/06/learn-to-pass-a-java-object-as-oracle-procedure-parameter#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">previous post</a>.</p>
<p>For this tutorial, we&#8217;ll need create the table TBL_CLASS and add your primary key as foreign key in TBL_USER table.</p>
<pre class="brush:sql">--num class is PK and desc_class description
create table TBL_CLASS (num_class number, desc_class varchar(100));
alter table TBL_CLASS add primary key(num_class);

alter table TBL_USER add num_class number;
alter table TBL_USER add constraint FK_CLASS foreign key(num_class) references tbl_class(num_class);</pre>
<p>Now we need to include the new types:</p>
<pre class="brush:sql">create or replace type class_type as object (num_class number, desc_class varchar2(100), users arr_users);
/
create or replace type arr_class as table of class_type;
/</pre>
<p>The <em>class_type</em> type will be the Java Object. Notice that in your signature was included the <em>arr_users</em> type, that will be our collection of <em>user_type</em> (read <a href="http://www.andrels.com/wp-en_US/index.php/2009/06/learn-to-pass-a-java-object-as-oracle-procedure-parameter#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">previous post</a> for more information), the <em>arr_class</em> type will be the <em>class_type</em> collection.</p>
<p>Now we&#8217;ll include the procedure that returns our  <em>class_type</em> collection.</p>
<pre class="brush:sql">procedure pro_select_class(clas in class_type, class_return in out arr_class)is
  class_ref_cur ref_cur;
  --class_type array
  classes arr_class := arr_class();

  begin
    open class_ref_cur for
      select cast(
                multiset(
                  select num_class,
                         desc_class,
                         (select cast(
                                  multiset(
                                    select user_name,
                                           height,
                                           b_date
                                    from tbl_user
                                    --JOIN with TBL_USER
                                    where tbl_user.num_class = tbl_class.num_class
                                  ) as arr_users)
                          from dual) users
                  from tbl_class
                  --Using num_class attribute of in parameter
                  where num_class = clas.num_class) as arr_class
      ) classes
    from dual;

    --including the return in array
    fetch class_ref_cur into classes;
    --transferring arrar to variable out
    class_return := classes;
end pro_select_class;</pre>
<p>Notice that procedure receive <em>class_type</em> as parameter in and returns <em>arr_class</em> type.</p>
<p>Separating code charge back and set up our objects, we have:</p>
<pre class="brush:sql">
--Mount return
select cast(
        multiset(

          --Will returns the objects class_type and your attributes
          select num_class,
                 desc_class,

                 --Populate user_type collection
                 (select cast(
                          multiset(
                            select user_name,
                                   height,
                                   b_date
                            from tbl_user
                            where tbl_user.num_class = tbl_class.num_class
                          ) as arr_users)

                  from dual) users

          from tbl_class
          where num_class = clas.num_class) as arr_class
) classes
from dual;
</pre>
<p>Oracle objects done, now the Java code!</p>
<p>We&#8217;ll create the object that will be interpreted by the Oracle. Called TypeClass:</p>
<pre class="brush:java">
public class TypeClass implements SQLData{
	public static final String ORACLE_OBJECT_NAME = "CLASS_TYPE"; //Type name in Oracle
	public static final String ORACLE_CLASS_ARRAY_NAME = "ARR_CLASS"; //Array name in Oracle

        //Attibutes of TBL_CLASS table
	private Long number;
	private String desc;
	private Array users; //This will be user_type collection (or TypeUser in Java)

	public String getSQLTypeName() throws SQLException {
		return ORACLE_OBJECT_NAME;
	}

	public void readSQL(SQLInput stream, String typeName) throws SQLException {
		setNumber(stream.readLong());
		setDesc(stream.readString());
		setUsers(stream.readArray());//Used by JDBC driver to read the collection
	}

	public void writeSQL(SQLOutput stream) throws SQLException {
		stream.writeLong(getNumber());
		stream.writeString(getDesc());
		stream.writeArray(getUsers());//Used by JDBC driver to write the collection
	}
	//Getters and setters omitted
}
</pre>
<p>We need to map types interpreted in request, this way:</p>
<pre class="brush:java">
Map<String, Class<?>> typeMaps = connection.getTypeMap();
typeMaps.put(TypeUser.ORACLE_OBJECT_NAME, TypeUser.class);
typeMaps.put(TypeClass.ORACLE_OBJECT_NAME, TypeClass.class);
</pre>
<p>We need to map the <em>arrays</em> too:</p>
<pre class="brush:java">
typeMaps.put(TypeClass.ORACLE_CLASS_ARRAY_NAME, TypeClass[].class);//returned by procedure
typeMaps.put(TypeUser.ORACLE_USER_ARRAY_NAME, TypeUser[].class);//returned by class_type collection
</pre>
<p>For request, we do:</p>
<pre class="brush:java">
cs = conn.prepareCall("{call PAC_BEAN.PRO_SELECT_CLASS(?,?)}");
//registering out type, that will be a TypeClass array
cs.registerOutParameter("class_return", OracleTypes.ARRAY, TypeClass.ORACLE_CLASS_ARRAY_NAME);

//passing parameter object
cs.setObject("clas", classQry);

cs.execute();
//retrieving and looping the TypeClass array
Object[] array = (Object[])cs.getArray("class_return").getArray();

for(Object obj : array){
	TypeClass objClass = ((TypeClass)obj);

	System.out.println("Description: "+objClass.getDesc());

        //Here we obtains user_type(TypeUser) array returned by query.
	Object[] userArray = (Object[])objClass.getUsers().getArray();
	for(Object user : userArray){
		System.out.println("\tName: " + ((TypeUser)user).getName());
		System.out.println("\tHeight: " + ((TypeUser)user).getHeight());
		System.out.println("\tBirth: " + sdf.format(((TypeUser)user).getBirth())+ "\r\n");
	}
}
</pre>
<p>In the end you&#8217;ll have a <a href="http://www.j2ee.me/j2se/1.4.2/docs/api/java/sql/class-use/Array.html" target="_blank">java.sql.Array</a> of TypeUser in getUsers() attribute of TypeClass.</p>
<p>Here I fulfilled my promise. Download the source code of this sample (with previous post sample too) <a href="http://www.andrels.com/wp-en_US/wp-content/plugins/download-monitor/download.php?id=3" title="Downloaded 216 times">here</a>.</p>
<p>Until next time!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2009/09/retrieving-objects-collection-from-oracle-procedure/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Taking Screen Shots with Java</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2009/09/taking-screen-shots-with-java/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2009/09/taking-screen-shots-with-java/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 14:38:40 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[awt]]></category>
		<category><![CDATA[desktop]]></category>
		<category><![CDATA[image]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=75</guid>
		<description><![CDATA[Here I&#8217;ll show how to implements a class to take Screen shots. I thinking about the complexity of a class<a href="http://www.andrels.com/wp-en_US/index.php/2009/09/taking-screen-shots-with-java/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>Here I&#8217;ll show how to implements a class to take Screen shots.</p>
<p>I thinking about the complexity of a class that takes screen shots and store the files in hard disk and, asking to &#8220;uncle G&#8221;, I fonded the class <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Robot.html" target="_blank">Robot</a>, that provide <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Robot.html#createScreenCapture(java.awt.Rectangle)" target="_blank">createScreenCapture</a> method.</p>
<p>Now I&#8217;ll show how to implement this functionality:</p>
<pre class="brush:java">Robot robot = new Robot();
//Setting the rectangle that mark capture area. In this case, will be all screen..
Rectangle rect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());

BufferedImage img = robot.createScreenCapture(rect);</pre>
<p>Here we defined capture area and obtained a <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/awt/image/BufferedImage.html" target="_blank">BufferedImage</a>, our image. Now, we needed to persist in hard disk.</p>
<pre class="brush:java">//Capturing the ImageWriter and ImageWriterParam
ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next();
ImageWriteParam iwp = writer.getDefaultWriteParam();

//Setting compression mode and the image quality
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionQuality(1);

//Persisting the image
writer.setOutput(new FileImageOutputStream(arquivo));

IIOImage iioimage = new IIOImage(img, null, null);

writer.write(null, iioimage, iwp);
writer.dispose();</pre>
<p>We captured the <a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/imageio/ImageWriter.html" target="_blank">ImageWriter</a> and <a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/imageio/ImageWriteParam.html" target="_blank">ImageWriterParam</a> to set the compression method and the image quality.</p>
<p>In line <strong>07</strong> we defined the image quality as 1, where the value can be between 0 (zero), more compression and less quality and 1 (one), less compression and more quality. Then we have kept the file in HD.</p>
<p>We&#8217;ve done! Simple, isn&#8217;t?</p>
<p>Download this sample <a href="http://www.andrels.com/wp-en_US/wp-content/plugins/download-monitor/download.php?id=2" title="Downloaded 138 times">here</a>.</p>
<p>See ya!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2009/09/taking-screen-shots-with-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting maximum number of characters in JTextField</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2009/09/setting-maximum-number-of-characters-in-jtextfield/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2009/09/setting-maximum-number-of-characters-in-jtextfield/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 16:07:48 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Quick tips]]></category>
		<category><![CDATA[jtextfield]]></category>
		<category><![CDATA[swing]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=73</guid>
		<description><![CDATA[The default implementation of JTextField not allow set maximum number of characters. To enable this resource you need implements a<a href="http://www.andrels.com/wp-en_US/index.php/2009/09/setting-maximum-number-of-characters-in-jtextfield/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>The default implementation of <i>JTextField</i> not allow set maximum number of characters. To enable this resource you need implements a <i>Document</i>, overriding <i>insertString</i> method.</p>
<pre class="brush:java">
public class MaxLengthTextDocument extends PlainDocument {
	//Store maximum characters permitted
	private int maxChars;

	@Override
	public void insertString(int offs, String str, AttributeSet a)
			throws BadLocationException {
		if(str != null &#038;&#038; (getLength() + str.length() < maxChars)){
			super.insertString(offs, str, a);
		}
	}

	//getter e setter omitted
}
</pre>
<p>Here we defined one class called <i>MaxLengthTextDocument</i> that extends <i>PlainDocument</i>. In <i>insertString</i> attribute, we checked if quantity of characters minor than <i>maxChars</i> attribute, inserting in String if true.</p>
<p>After this, only insert our implementation in JTextField, this way:</p>
<pre class="brush:java">
	...
	MaxLengthTextDocument maxLength = new MaxLengthTextDocument();
	maxLength.setMaxChars(50);//50 is a maximum number of character 

	jTextField.setDocument(maxLength);
	...
</pre>
<p>And voilà!</p>
<p>See ya!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2009/09/setting-maximum-number-of-characters-in-jtextfield/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Inserting padding into a JLabel</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2009/08/inserting-padding-into-a-jlabel/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2009/08/inserting-padding-into-a-jlabel/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 15:07:38 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Quick tips]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[swing]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=63</guid>
		<description><![CDATA[To insert padding into a JLabel we should use an EmptyBorder, where the attribute &#8216;width&#8217; will be our padding. Like<a href="http://www.andrels.com/wp-en_US/index.php/2009/08/inserting-padding-into-a-jlabel/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>To insert padding into a JLabel we should use an EmptyBorder, where the attribute &#8216;width&#8217; will be our padding. Like this:</p>
<pre class="brush:java">...
JLabel jLabel = new JLabel("My JLabel");
//Border used as padding
Border paddingBorder = BorderFactory.createEmptyBorder(10,10,10,10);

jLabel.setBorder(BorderFactory.createCompoundBorder(border,paddingBorder));
...</pre>
<p>Here, the JLabel contains a padding with 10 pixels in top, right, bottom and left, respectively.</p>
<p><img class="aligncenter size-full wp-image-64" title="0" src="http://www.andrels.com/wp-en_US/wp-content/uploads/2009/08/0.jpg" alt="0" width="300" height="100" /></p>
<p>If you want to put border around the JLabel, you can use a CompoundBorder, setting Border and EmptyBorder (padding):</p>
<pre class="brush:java">...
JLabel jLabel = new JLabel("Meu JLabel");
//Border used as padding
Border paddingBorder = BorderFactory.createEmptyBorder(10,10,10,10);
//JLabel will be involved for this border
Border border = BorderFactory.createLineBorder(Color.BLUE);

jLabel.setBorder(BorderFactory.createCompoundBorder(border,paddingBorder));
...</pre>
<p><img src="http://www.andrels.com/wp-en_US/wp-content/uploads/2009/08/1.jpg" alt="1" title="1" width="300" height="100" class="aligncenter size-full wp-image-65" /></p>
<p>Download the source code of this sample <a href="http://www.andrels.com/wp-en_US/wp-content/plugins/download-monitor/download.php?id=1" title="Downloaded 275 times">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2009/08/inserting-padding-into-a-jlabel/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>iBatis tutorial, learning the basic</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2009/07/ibatis-tutorial-learning-the-basic/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2009/07/ibatis-tutorial-learning-the-basic/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 20:09:57 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[ibatis]]></category>
		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=56</guid>
		<description><![CDATA[When we talk about the persistence framework, we think in Hibernate/JPA. Recently I was presented to iBatis, a framework that<a href="http://www.andrels.com/wp-en_US/index.php/2009/07/ibatis-tutorial-learning-the-basic/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>When we talk about the persistence framework, we think in Hibernate/JPA. Recently I was presented to iBatis, a framework that so easy to install, to configure and to use. You can download it in your sponsor site, <a href="http://www.apache.org" target="_blank">Apache</a>, clicking <a href="http://ibatis.apache.org/javadownloads.cgi" target="_blank">here</a>.</p>
<p><em><strong>Setting iBatis</strong></em></p>
<p>Unlike another frameworks, to configure iBatis you need only one XML file, called <em>SqlMapConfig</em>.</p>
<p>The mains sections of XML are:</p>
<pre class="brush: xml">&lt;properties resource="tuto/ibatis/config/SqlMap.properties"/&gt;</pre>
<p>This code is optional and specifies the .properties file that&#8217;ll be used to declare variables used in configuration. </p>
<pre class="brush: xml">&lt;typeAlias alias="car" type="tuto.ibatis.beans.Car"/&gt;</pre>
<p>Defines the JavaBean used and your alias. You can set much lines, depending of modeling complexity.<br />
In example, we&#8217;ll Car bean below:</p>
<pre class="brush:java">public class Car {
	private Long carId;
	private String company;
	private String model;
	private String color;
	private Integer	hp;
	private Float price;

	//Setters and getters omitted
}</pre>
<pre class="brush: xml">&lt;transactionManager type="JDBC"&gt;
    &lt;dataSource type="SIMPLE"&gt;
        &lt;property name="JDBC.Driver" value="${driver}"/&gt;
        &lt;property name="JDBC.ConnectionURL" value="${url}"/&gt;
        &lt;property name="JDBC.Username" value="${username}"/&gt;
        &lt;property name="JDBC.Password" value="${password}"/&gt;
    &lt;/dataSource&gt;
&lt;/transactionManager&gt;</pre>
<p>Parameters used in database connection. The variables ${driver}, ${url}, ${username} and ${password} are defined in .properties file in section <i>properties</i>. If you prefer, can put the values directly in fields.</p>
<p>See the complete file:</p>
<pre class="brush: xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
        "http://ibatis.apache.org/dtd/sql-map-config-2.dtd"&gt;

&lt;sqlMapConfig&gt;
    &lt;properties resource="tuto/ibatis/config/SqlMap.properties"/&gt;

    &lt;settings
        cacheModelsEnabled="true"
        enhancementEnabled="true"
        lazyLoadingEnabled="true"
        maxRequests="32"
        maxSessions="10"
        maxTransactions="5"
        useStatementNamespaces="false" /&gt;

    &lt;typeAlias alias="car" type="tuto.ibatis.beans.Car"/&gt;

    &lt;transactionManager type="JDBC"&gt;
        &lt;dataSource type="SIMPLE"&gt;
            &lt;property name="JDBC.Driver" value="${driver}"/&gt;
            &lt;property name="JDBC.ConnectionURL" value="${url}"/&gt;
            &lt;property name="JDBC.Username" value="${username}"/&gt;
            &lt;property name="JDBC.Password" value="${password}"/&gt;
        &lt;/dataSource&gt;
    &lt;/transactionManager&gt;

    &lt;sqlMap resource="tuto/ibatis/sqlmaps/CarSqlMap.xml"/&gt;
&lt;/sqlMapConfig&gt;</pre>
<p>The <em>properties</em> have this content:</p>
<pre class="brush:plain">driver=oracle.jdbc.OracleDriver
url=jdbc:oracle:thin:@&lt;host&gt;:&lt;porta&gt;:&lt;sid&gt;
username=&lt;login&gt;
password=&lt;senha&gt;</pre>
<p>Next you need to configure the <i>SqlMap</i>. This XML contains the querys used in application and your name need be equals described in <i>sqlMap</i> section of <i>SqlMapConfig</i>, in our case will be <i>CarSqlMap.xml</i></p>
<p>In example only we will see utilization of tags select, insert, update and delete.</p>
<pre class="brush:xml">&lt;select id="getCars" resultClass="tuto.ibatis.beans.Car"
	parameterClass="java.lang.Long"&gt;
    SELECT COMPANY  as company,
           MODEL    as model,
           COLOR    as color,
           HP       as hp,
           PRICE    as price
    FROM TBL_CAR
    WHERE CAR_ID = #var#
&lt;/select&gt;</pre>
<p>Execute the <i>select</i> statement can return a single object or one collection of objects, the type is same of <i>resultClass</i> attribute, o <i>parameterClass</i> is the type sent to execute the <i>query</i> and the <i>id</i> is the query identification call.</p>
<p>We will use the SqlMap below:</p>
<pre class="brush:xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
	"http://ibatis.apache.org/dtd/sql-map-2.dtd"&gt;

&lt;sqlMap namespace="Car"&gt;
    &lt;select id="getCars" resultClass="tuto.ibatis.beans.Car"
    parameterClass="java.lang.Long"&gt;
        SELECT COMPANY  as company,
               MODEL    as model,
               COLOR    as color,
               HP       as hp,
               PRICE    as price
        FROM TBL_CAR
        WHERE CAR_ID = #var#
    &lt;/select&gt;

    &lt;insert id="addCar" parameterClass="tuto.ibatis.beans.Car"&gt;
        INSERT INTO TBL_CAR (CAR_ID, COMPANY, MODEL, COLOR, HP, PRICE)
        VALUES (#carId#, #company#, #model#, #color#, #hp#, #price#)
    &lt;/insert&gt;

    &lt;delete id="delCar" parameterClass="java.lang.Long"&gt;
        DELETE FROM TBL_CAR WHERE CAR_ID = #var#
    &lt;/delete&gt;

    &lt;update id="updCar" parameterClass="tuto.ibatis.beans.Car"&gt;
        UPDATE TBL_CAR
          SET COMPANY = #company#,
              MODEL = #model#,
              COLOR = #color#,
              HP = #hp#,
              PRICE = #price#
        WHERE CAR_ID = #carId#
    &lt;/update&gt;
&lt;/sqlMap&gt;</pre>
<p>Data base connection configured, now we will implements the singleton class the will used as <i>SqlMapClient</i>, called OracleMapConfig.</p>
<pre class="brush:java">package tuto.ibatis.connection;

import java.io.Reader;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class OracleMapConfig {
	private static final SqlMapClient sqlMapClient;

	static{
		try{
			//Defining path of SqlMapConfig and creating reader
			String res = "tuto/ibatis/config/SqlMapConfig.xml";
			Reader reader = Resources.getResourceAsReader(res);

			//Retrieving the client to SqlMap
			sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);
		} catch(Exception e){
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	//Method used to retrieve the client
	public static SqlMapClient getSqlMapClient(){
		return sqlMapClient;
	}
}</pre>
<p>The client is responsible  for execute the querys configured in SqlMap and return the results.</p>
<p><em><strong>Executing Querys and treating the return</strong></em></p>
<p>To call any query is too simple, only execute the correspondent method of client class.</p>
<p>The <em>select</em> can be called this way:</p>
<pre class="brush:java">OracleMapConfig.getSqlMapClient().queryForObject("&lt;id&gt;", &lt;parâmetro&gt;);</pre>
<p>The<i>id</i> need be equals of <i>id</i> specified in <b>SqlMap</b></p>
<p>Only one line is return in code above, to get all lines change to <em>queryForList</em>, this way:</p>
<pre class="brush:java">OracleMapConfig.getSqlMapClient().queryForList("&lt;id&gt;", &lt;parâmetro&gt;);</pre>
<p>Will be returned a <i>Collection</i> containing the objects;</p>
<p><strong>Select</strong></p>
<pre class="brush:java">try{
	Car car = (Car)OracleMapConfig.getSqlMapClient().queryForObject("getCars",
		new Long(readKeyboard()));

	System.out.println("Company: "+car.getCompany());
	System.out.println("Model: "+car.getModel());
	System.out.println("Color: "+car.getColor());
	System.out.println("HP: "+car.getHp());
	System.out.println("Price: "+car.getPrice());
}catch (Exception e) {
	e.printStackTrace();
}</pre>
<p>The <i>id</i> &#8220;getCars&#8221; are defined in select attributes of <em>SqlMap</em>, providing one Long type and retrieving a Car type, both defined in line &lt;select id=&#8221;<span style="color: #0000ff;">getCars</span>&#8221; resultClass=&#8221;<span style="color: #0000ff;">tuto.ibatis.beans.Car</span>&#8221; parameterClass=&#8221;<span style="color: #0000ff;">java.lang.Long</span>&#8220;&gt;.</p>
<p><strong>Insert</strong></p>
<pre class="brush:java">try{
	OracleMapConfig.getSqlMapClient().insert("addCar", newCar);
}catch (Exception e) {
	e.printStackTrace();
}</pre>
<p>Now we will provide as parameter a Car type, &lt;insert id=&#8221;<span style="color: #0000ff;">addCar</span>&#8221; parameterClass=&#8221;<span style="color: #0000ff;">tuto.ibatis.beans.Car</span>&#8220;&gt;, and call the methods using sharp (#), this way:</p>
<pre class="brush:plain">INSERT INTO TBL_CAR (CAR_ID, COMPANY, MODEL, COLOR, HP, PRICE)
VALUES (#carId#, #company#, #model#, #color#, #hp#, #price#)</pre>
<p><strong>Delete</strong></p>
<pre class="brush:java">try{
	int lines = OracleMapConfig.getSqlMapClient().delete("delCar",
		new Long(readKeyboard()));

	System.out.println(lines + " lines deleted");
}catch (Exception e) {
	e.printStackTrace();
}</pre>
<p>The method <em>delete</em> of <i>client</i> return a type int, this represents the number of rows deleted.</p>
<p><strong>Update</strong></p>
<pre class="brush:java">try{
	int lines = OracleMapConfig.getSqlMapClient().update("updCar", car);

	System.out.println(lines + " cars updated");
}catch (Exception e) {
	e.printStackTrace();
}</pre>
<p>Update return a type int, this represents the number of rows affected by update.</p>
<p>How you see, with only three XML and three classes we built a simple storage management and price consulting system.</p>
<p>You can download the source code of this tutorial clicking <a href="../wordpress_external/downloads/TutoIbatis.zip#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">here</a>.</p>
<p>Until next post!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2009/07/ibatis-tutorial-learning-the-basic/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Learn to pass a Java Object as Oracle Procedure parameter</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2009/06/learn-to-pass-a-java-object-as-oracle-procedure-parameter/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2009/06/learn-to-pass-a-java-object-as-oracle-procedure-parameter/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 03:19:51 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[jdbc]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=44</guid>
		<description><![CDATA[In the enterprise where I work was a discussion about possibility to pass a Java objects into an Oracle procure<a href="http://www.andrels.com/wp-en_US/index.php/2009/06/learn-to-pass-a-java-object-as-oracle-procedure-parameter/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>In the enterprise where I work was a discussion about possibility to pass a <a href="http://java.sun.com/" target="_blank">Java</a> objects into an <a href="http://www.oracle.com" target="_blank">Oracle</a> procure or function, then I looked for and here is a simple solution to reach this objective.</p>
<p><em>This tutorial only work with </em><em>Oracle</em><em>9i , or above, and using the JDBC driver ojdbc14g, or above</em><em>.</em></p>
<p>First, we create the tables, objects and procedures. Remember: the types <em>tbl_users </em>and <em>user_type </em>must be declared out of packages, as global types:</p>
<pre class="brush: sql">-- Creating table
create table tbl_user(user_name varchar2(100), height number, b_date date);
/
--Creating type user_type (own bean)
create or replace type user_type as object (user_name varchar2(100), height number, birth_date date);
/
--Creating type arr_users, table of user_type (array of user_type)
create or replace type arr_users as table of user_type;
/</pre>
<p>Creating specification and body of package<em>.</em></p>
<pre class="brush: sql">--Spec
create or replace package PAC_BEAN is
  type ref_cur is ref cursor;

  -- Procedure used to insert values
  procedure pro_insert_user(usu in user_type);

  -- Procedure used to select
  procedure pro_select_user(usu in user_type, user_return in out arr_users);
end PAC_BEAN;
/</pre>
<pre class="brush: sql">--Body
create or replace package body PAC_BEAN is
  --The insert procedure will receive user_type and put him into table tbl_user.
  procedure pro_insert_user(usu in user_type) is
    begin
      insert into tbl_user (user_name, height, b_date)
      values (usu.user_name, usu.height, usu.birth_date);

      commit;
    exception
      when others then
        rollback;
  end pro_insert_user;

  --The procedure used for select will receive a user_type (where clause) and will return the array arr_users
  procedure pro_select_user(usu in user_type, user_return in out arr_users)is
    user_ref_cur ref_cur;

    --Instancing the array
    users arr_users := arr_users();

    begin
      --Opening the cursor that will return the array
      open user_ref_cur for
        select cast(
                 multiset(
                   select user_name,
                          height,
                          b_date
                   from tbl_user
                   where user_name like '%'||usu.user_name||'%'
                 ) as arr_users
              ) arr
        from dual;

      --Putting the cursor into arr_users instance.
      fetch user_ref_cur into users;

      --Returning the instance through OUT variable
      user_return := users;
  end pro_select_user;
end PAC_BEAN;
/</pre>
<p><em>See <a href="http://download.oracle.com/docs/cd/B14117_01/server.101/b10759/functions015.htm#sthref1120" target="_blank">CAST</a> and <a href="http://download.oracle.com/docs/cd/B14117_01/server.101/b10759/operators006.htm" target="_blank">MULTISET</a> about how they work.</em></p>
<p>Built database objects, we need prepare the JavaBean. It&#8217;ll an implementation of <em>java.sql.SQLData</em>, because it will be necessary to implement the methods:</p>
<p><em>getSQLTypeName()</em> &#8211; Getter used to obtain the name of type.</p>
<p><em>readSQL(SQLInput, String)</em> &#8211;  Used to convert an object in Java object.</p>
<p><em>writeSQL(SQLOutput stream)</em> &#8211; Used to mount a SQL object, used byJDBC Driver.</p>
<pre class="brush: java">public class TypeUser implements SQLData{
	//Name declared in Oracle
	public static final String ORACLE_OBJECT_NAME = "USER_TYPE";
	//Array name declared in Oracle
	public static final String ORACLE_USER_ARRAY_NAME = "ARR_USERS";

	//The attributes
	private String name;
	private Float height;
	private Date birth;

	public TypeUser() {
		height = 0F;
	}

	public String getSQLTypeName() throws SQLException {
		return ORACLE_OBJECT_NAME;
	}

	public void readSQL(SQLInput stream, String typeName) throws SQLException {
		setName(stream.readString());
		setHeight(stream.readFloat());
		setBirth(stream.readDate());
	}

	public void writeSQL(SQLOutput stream) throws SQLException {
		stream.writeString(getName());
		stream.writeFloat(getHeight());
		stream.writeDate(getBirth() != null ?
				new java.sql.Date(getBirth().getTime()) : null);
	}

        //getters and setters omitted
}</pre>
<p>To define a type that can will be send to procedure be necessary add him  into type map<em> </em>through <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Connection.html#getTypeMap()" target="_blank"><em>Connection.getTypeMap()</em></a>. This method return the <em>Map&lt;String,Class&lt;?&gt;&gt;</em>, where type name is the key and class of SQLData implementation is the value, in own case the type <em>TypeUser</em>. Sample:</p>
<pre class="brush: java">Map&lt;String,Class&lt;?&gt;&gt; typeMaps = connection.getTypeMap();
typeMaps.put(TypeUser.ORACLE_OBJECT_NAME, TypeUser.class);</pre>
<p>Then the connection will be:</p>
<pre class="brush: java">//Making connection
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:&lt;host&gt;:&lt;port&gt;:&lt;db&gt;","&lt;user&gt;","&lt;pass&gt;");

//Mapping necessary tipes
Map&lt;String,Class&lt;?&gt;&gt; typeMaps = connection.getTypeMap();
typeMaps.put(TypeUser.ORACLE_OBJECT_NAME, TypeUser.class);</pre>
<p>Now, we create the insert method, it receive an instance of <em>TypeUser </em>and <em>Connection</em>:</p>
<pre class="brush: java">CallableStatement cs = null;
try {
	//call the procedure
	cs = conn.prepareCall("{call PAC_BEAN.PRO_INSERT_USER(?)}");

	//defining the instance of TypeUser as variable IN "usu"
	cs.setObject("usu", typeUser);

	cs.execute();
} catch (SQLException e) {
	e.printStackTrace();
}</pre>
<p>Now, the select method. This method return a object array, then be necessary insert the type of array in <em>Connection TypeMap</em>. The name passed as key should be equals of Oracle&#8217;s array name and the values will be the array class, like this:</p>
<pre class="brush: java">connection.getTypeMap().put(TypeUser.ORACLE_USER_ARRAY_NAME, TypeUser[].class);</pre>
<p>To call procedure and registerOutParameter<em>:</em></p>
<pre class="brush: java">cs = conn.prepareCall("{call PAC_BEAN.PRO_SELECT_USER(?,?)}");
cs.registerOutParameter("user_return", OracleTypes.ARRAY, TypeUser.ORACLE_USER_ARRAY_NAME);
cs.setObject("usu", typeUserQry);

cs.execute();</pre>
<p>To obtain the array, do it:</p>
<pre class="brush: java">//user_return is the OUT variable name
Object[] array = (Object[])cs.getArray("user_return").getArray();</pre>
<p>If until here is alright, smile, to obtain array values just iterate him and cast each index to Type User.</p>
<pre class="brush: java">for(Object obj : array){
	System.out.println("Nome: " + ((TypeUser)obj).getName());
	System.out.println("Altura: " + ((TypeUser)obj).getHeight());
	System.out.println("Data de Nascimento: " + sdf.format(((TypeUser)obj).getBirth()));
}</pre>
<p>So we can pass and retrieve simple Java objects of a Oracle procedure or function. The next step, <a href="http://www.andrels.com/wp-en_US/index.php/2009/09/retrieving-objects-collection-from-oracle-procedure/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">Retrieving objects collection from Oracle procedure</a>.</p>
<p>See ya!</p>
<p>Download the source code of this tutorial <a href="../wordpress_external/downloads/post31.zip#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed" target="_blank">here</a>.</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 2322px; width: 1px; height: 1px;">
<pre class="brush: java">&lt;host&gt;:&lt;porta&gt;:&lt;bd&gt;","&lt;usuario&gt;","&lt;senha&gt;"</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2009/06/learn-to-pass-a-java-object-as-oracle-procedure-parameter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Collections, what to use?</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2009/05/collections-what-to-use/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2009/05/collections-what-to-use/#comments</comments>
		<pubDate>Sun, 24 May 2009 16:38:49 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[collection]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=27</guid>
		<description><![CDATA[Collection interface has many implementations, like ArrayList, LinkedList, TreeSet and others. With so many variations, some times you don’t known<a href="http://www.andrels.com/wp-en_US/index.php/2009/05/collections-what-to-use/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>Collection interface has many implementations, like <a href="http://java.sun.com/javase/6/docs/api/java/util/ArrayList.html" target="_blank">ArrayList</a>, <a href="http://java.sun.com/javase/6/docs/api/java/util/LinkedList.html" target="_blank">LinkedList</a>, <a href="http://java.sun.com/javase/6/docs/api/java/util/TreeSet.html" target="_blank">TreeSet</a> and others. With so many variations, some times you don’t known what to use, this depends of your objective. Now I’ll try to explain some differences in ArrayList, LinkedList and TreeSet.</p>
<p><strong>ArrayList</strong><br />
The ArrayList Collection allow to store objects and null values, but your access is unordered, the first object inserted, can be a last to retrieve.</p>
<p><strong>LinkedList</strong><br />
This implementation of Collection is like ArrayList, but the difference is in access to objects stored, where each object is returned in your inserted order.</p>
<p><strong>TreeSet</strong><br />
If you want retrieve the objects of your Collection in specified order, this Collection can do the work! Insert values in TreeSet is equal previously classes, but your return depends of <a href="http://java.sun.com/javase/6/docs/api/java/lang/Comparable.html" target="_blank">Comparable</a> implemented in values. It sort your object values using result of <a href="http://java.sun.com/javase/6/docs/api/java/lang/Comparable.html#compareTo(T)" target="_blank">compareTo</a> method, inherited of Comparable Interface.</p>
<p>For more information, visits <a href="http://java.sun.com/javase/6/docs/api/java/util/Collection.html" target="_blank">Collection</a> Javadoc.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2009/05/collections-what-to-use/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learn JavaFX in 15 minutes</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2009/05/learn-javafx-in-15-minutes/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2009/05/learn-javafx-in-15-minutes/#comments</comments>
		<pubDate>Sun, 24 May 2009 16:04:58 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[javafx]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=13</guid>
		<description><![CDATA[This video show some commands for JavaFX, from a simple “Hello World” to functions and access modifiers. Thanks for Roberto<a href="http://www.andrels.com/wp-en_US/index.php/2009/05/learn-javafx-in-15-minutes/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>This <a href="http://tinyurl.com/bznwp5" target="_blank">video</a> show some commands for JavaFX, from a simple “Hello World” to functions and access modifiers.</p>
<p>Thanks for <a href="http://www.furutani.com.br">Roberto Furutani</a>!</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2009/05/learn-javafx-in-15-minutes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Retrieving hard drives or removable devices</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2009/05/retrieving-file-roots/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2009/05/retrieving-file-roots/#comments</comments>
		<pubDate>Sun, 24 May 2009 15:59:31 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[file]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=7</guid>
		<description><![CDATA[You&#8217;ve tried retrieve the hard drives or removable devices using java.io.File and passed &#8220;/&#8221; like parameter in class constructor? The<a href="http://www.andrels.com/wp-en_US/index.php/2009/05/retrieving-file-roots/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>You&#8217;ve tried retrieve the hard drives or removable devices using java.io.File and passed &#8220;/&#8221; like parameter in class constructor? The result is the root of classpath, isn&#8217;t?</p>
<p>To obtain the hard drives or removable devices, use <strong>File.<em>listRoots()</em></strong>. This code return a File array, where each index of array is a removable device or hard disk unit.</p>
<p>Follow this sample:</p>
<pre class="brush: java">File[] units = File.listRoots();

for(File unit : units){
    System.out.println(unit.getAbsolutePath());
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2009/05/retrieving-file-roots/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Manipulating ID3 Tags of MP3 files</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2009/05/hello-world/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2009/05/hello-world/#comments</comments>
		<pubDate>Sat, 23 May 2009 15:34:34 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[mp3 java]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=1</guid>
		<description><![CDATA[This post will teach you how to manipulate ID3 tags of MP3 files using Java Jid3Lib Tag Library. First, download<a href="http://www.andrels.com/wp-en_US/index.php/2009/05/hello-world/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>This post will teach you how to manipulate ID3 tags of MP3 files using Java Jid3Lib Tag Library. First, download the jar file from <a href="http://javamusictag.sourceforge.net/">http://javamusictag.sourceforge.net/</a>.</p>
<p>The code below will show you how to get any information of MP3 file:</p>
<pre class="brush: java">try {
    MP3File mp3 = new MP3File("D:\\Musics\\MP3\\ACDC\\ACDC - Back In Black.mp3");
    System.out.println("Album:" + mp3.getID3v2Tag().getAlbumTitle());
    System.out.println("Band:" + mp3.getID3v2Tag().getLeadArtist());
    System.out.println("Composer:" + mp3.getID3v2Tag().getAuthorComposer());
    System.out.println("Year:" + mp3.getID3v2Tag().getYearReleased());
} catch (Exception e) {
	e.printStackTrace();
}</pre>
<p>The result:</p>
<blockquote><p>Album: Back in Black<br />
Band: AC/DC<br />
Composer: Angus Young/Brian Johnson/Malcolm Young<br />
Year:</p></blockquote>
<p>To change any information of any ID3 tags, try the code bellow:</p>
<pre class="brush: java">mp3.getID3v2Tag().setYearReleased("1980");
mp3.save();</pre>
<p>This library has many methods that help you to customize any MP3 file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2009/05/hello-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

