<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>Java Programming Forum - Learn Java Programming - Blogs - My Java Tips by Java Tip</title>
		<link>http://www.java-forums.org/blogs/java-tip/</link>
		<description>Java Programming Forum - Learning Java easily</description>
		<language>en</language>
		<lastBuildDate>Tue, 21 May 2013 14:40:41 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://www.java-forums.org/images/misc/rss.jpg</url>
			<title>Java Programming Forum - Learn Java Programming - Blogs - My Java Tips by Java Tip</title>
			<link>http://www.java-forums.org/blogs/java-tip/</link>
		</image>
		<item>
			<title>OMA standard for data synchronisation - SyncML</title>
			<link>http://www.java-forums.org/blogs/java-tip/597-oma-standard-data-synchronisation-syncml.html</link>
			<pubDate>Mon, 28 Nov 2011 18:06:37 GMT</pubDate>
			<description>SyncML is the standard for data synchronization and is accepted by Open Mobile Alliance (OMA). All the major players, including Ericsson, Nokia, IBM,...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">SyncML is the standard for data synchronization and is accepted by Open Mobile Alliance (OMA). All the major players, including Ericsson, Nokia, IBM, Motorola, and Symbian support this protocol.<br />
<hr /><br />
The synchronization of data has great importance in today’s world. You carry email applications, contact database, files and other stuff on your handheld devices. It would be great of you can synchronize those with your desktop/notebook. For that there has to be a agreed format.<br />
<br />
SyncMLconsists of: SyncML representation protocol and SyncML synchronization protocol. The representation protocol defines the representation format in for of XML The synchronization protocol defines the actions between a client and a server. Both the protocols combine together to ensure a consistent set of data is available on any device or application at any time.</blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/597-oma-standard-data-synchronisation-syncml.html</guid>
		</item>
		<item>
			<title>Using the DocumentBuilderFactory</title>
			<link>http://www.java-forums.org/blogs/java-tip/595-using-documentbuilderfactory.html</link>
			<pubDate>Mon, 28 Nov 2011 18:02:15 GMT</pubDate>
			<description><![CDATA[In this post, I will present an example to show how to use the DocumentBuilderFactory. 
 
First step is to import the required classes. 
 
<div...]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">In this post, I will present an example to show how to use the DocumentBuilderFactory.<br />
<hr /><br />
First step is to import the required classes.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;

// JAXP
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;

// DOM
import org.w3c.dom.Document;
import org.w3c.dom.DocumentType;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 Now lets come tot he real thing. We have to obtain an instance of DocumentBuilderFactory. Then we have to configure the factory to handle validation and namespaces.<br />
<br />
We also need a DocumentBuilder instance, which is created using DocumentBuilderFactory instance. Now we may start parsing and the resultant DOM Document object is handed off to a method that prints the DOM tree.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">public class TestDOMParsing {

    public static void main(String&#91;&#93; args) {
        try {
            if (args.length != 1) {
                System.err.println (&quot;Usage: java TestDOMParsing &quot; +
                                    &quot;&#91;filename&#93;&quot;);
                System.exit (1);
            }

            // Get Document Builder Factory
            DocumentBuilderFactory factory =
                DocumentBuilderFactory.newInstance();

            // Turn on validation, and turn off namespaces
            factory.setValidating(true);
            factory.setNamespaceAware(false);

            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.parse(new File(args&#91;0&#93;));

            // Print the document from the DOM tree and
            //   feed it an initial indentation of nothing
            printNode(doc, &quot;&quot;);

        } catch (ParserConfigurationException e) {
            System.out.println(&quot;The underlying parser does not &quot; +
                               &quot;support the requested features.&quot;);
        } catch (FactoryConfigurationError e) {
            System.out.println(&quot;Error occurred obtaining Document &quot; +
                               &quot;Builder Factory.&quot;);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void printNode(Node node, String indent)  {
        // print the DOM tree
    }

}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 </blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/595-using-documentbuilderfactory.html</guid>
		</item>
		<item>
			<title>Working with the DOM parser</title>
			<link>http://www.java-forums.org/blogs/java-tip/594-working-dom-parser.html</link>
			<pubDate>Mon, 28 Nov 2011 17:59:22 GMT</pubDate>
			<description>You will be introduced to the working of DOM parser in this post. 
 
We can get a DocumentBuilder instance as soon as we have a DOM factory. The...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">You will be introduced to the working of DOM parser in this post.<br />
<hr /><br />
We can get a DocumentBuilder instance as soon as we have a DOM factory. The methods available for the DocumentBuilder instance are very similar to those available to its SAX counterpart. But there is a slight difference when we talk about the parse() method. The parse method in case of DOM do not take an instance of the SAX DefaultHandler class. It returns a DOM Document instance representing the XML document that was parsed.<br />
<br />
Review the code snippet below. There are comments in the code, which will make the code self explainatory.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">// Get a DocumentBuilder instance
DocumentBuilder builder = builderFactory.newDocumentBuilder();
// Find out if validation is supported
boolean isValidating = builder.isValidating();
// Find out if namespaces are supported
boolean isNamespaceAware = builder.isNamespaceAware();
// Set a SAX ErrorHandler
builder.setErrorHandler(myErrorHandlerImpl);
// Set a SAX EntityResolver
builder.setEntityResolver(myEntityResolverImpl);
// Parse, in a variety of ways
// Use a file
Document doc = builder.parse(new File(args&#91;0&#93;));
// Use a SAX InputSource
Document doc = builder.parse(mySaxInputSource);
// Use an InputStream
Document doc = builder.parse(myInputStream, myDefaultHandlerInstance);
// Use a URI
Document doc = builder.parse(&quot;http://www.sitename.com/xml/doc.xml&quot;);</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 </blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/594-working-dom-parser.html</guid>
		</item>
		<item>
			<title>Reading RSS using Informa API</title>
			<link>http://www.java-forums.org/blogs/java-tip/592-reading-rss-using-informa-api.html</link>
			<pubDate>Mon, 28 Nov 2011 17:56:43 GMT</pubDate>
			<description>RSS (Really Simple Syndication) is a family of Web feed formats used to publish frequently updated content such as blog entries, news headlines, and...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">RSS (Really Simple Syndication) is a family of Web feed formats used to publish frequently updated content such as blog entries, news headlines, and podcasts. It is actually a specification for XML files to provide syndicated data.<br />
<hr /><br />
To read RSS feeds in a Java application is easy. You have to use Informa API which is availabel at:<br />
<a href="http://informa.sourceforge.net/" target="_blank" rel="nofollow">http://informa.sourceforge.net/</a>.<br />
<br />
The code snippet given below shows how to read RSS using Informa API.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">try {
  URL feed = new URL(&quot;file:/C:/samplefeed.rss&quot;);
  ChannelFormat format = FormatDetector.getFormat(feed);
  ChannelParserCollection parsers =
                          ChannelParserCollection.getInstance();

  ChannelParserIF parser =
    parsers.getParser(format, feed);

  parser.setBuilder(new ChannelBuilder());
  ChannelIF channel = parser.parse();

  for (Iterator iter = channel.getItems().iterator();
                                     iter.hasNext();) {
    ItemIF item = (ItemIF)iter.next();
    System.out.println(item.getTitle());
  }
} catch (MalformedURLException mue) {
  mue.printStackTrace();
} catch (UnsupportedFormatException ufe) {
  ufe.printStackTrace();
} catch (ParseException pe) {
  pe.printStackTrace();
}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 This given example gets the RSS feed and prints out the news items on the console.</blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/592-reading-rss-using-informa-api.html</guid>
		</item>
		<item>
			<title>Java Compiler API (brief intro)</title>
			<link>http://www.java-forums.org/blogs/java-tip/590-java-compiler-api-brief-intro.html</link>
			<pubDate>Mon, 28 Nov 2011 17:49:50 GMT</pubDate>
			<description>We all know that javac command is used to compile the java classes. Even if we are using some IDE (Eclipse, JBuilder, NetBeans), javac is called at...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">We all know that javac command is used to compile the java classes. Even if we are using some IDE (Eclipse, JBuilder, NetBeans), javac is called at the background for compilation. But with the release of Java 6, it has become possible to compile Java class from a Java class.<br />
<hr /><br />
The classes related to Java compiler are packed into javax.tools package.<br />
<br />
There is a class called ToolProvider (javax.tools) whose getSystemJavaCompiler() method returns an instance of some class that implements the JavaCompiler interface. Now we can use this compiler instance to create a compilation task that will perform the actual compilation. We have to provide the classes to be compiled to the compilation task. The compiler API provides a file manager abstraction called JavaFileManager for this. The JavaFileManager is used to allow Java files to be retrieved from various sources.<br />
<br />
Lets review the code snippet:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">//Get an instance of java compiler
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

//Get a new instance of the standard file manager implementation
StandardJavaFileManager fileManager = compiler.
        getStandardFileManager(null, null, null);

// Get the list of java file objects, in this case we have only
// one file, TestClass.java
Iterable compilationUnits1 =
        fileManager.getJavaFileObjectsFromFiles(&quot;TestClass.java&quot;);</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 </blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/590-java-compiler-api-brief-intro.html</guid>
		</item>
		<item>
			<title>Compiling a Java class using JavaCompiler</title>
			<link>http://www.java-forums.org/blogs/java-tip/588-compiling-java-class-using-javacompiler.html</link>
			<pubDate>Mon, 28 Nov 2011 17:47:19 GMT</pubDate>
			<description>Java 6 introduces a way to compile Java classes from a Java class. In this post, I will present an example to show how this is done. 
 
I have a...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">Java 6 introduces a way to compile Java classes from a Java class. In this post, I will present an example to show how this is done.<br />
<hr /><br />
I have a Test.java file:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">public class Test{

public static void main(String&#91;&#93; args) {
        // TODO code application logic here
        System.out.println(&quot;Hello World&quot;);
callMe();
}
    public static void callMe(){
     System.out.println(&quot;Hello Babar dost&quot;);
    }
}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 I want to compile it from my Java class. This is possible in Java 6 using javax.tools package. Lets see how this is done:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">import javax.tools.*;
import java.io.*;
import java.util.Arrays;

public class Main {

    public static void main(String&#91;&#93; args) {

        File file = new File(&quot;C:\Test.java&quot;);

        File files1 = file ; // input for first compilation task
       JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
       StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);

       Iterable compilationUnits1 =
           fileManager.getJavaFileObjectsFromFiles(Arrays.asList(files1));
       compiler.getTask(null, fileManager, null, null, null, compilationUnits1).call();
    }
}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 I compiled Main.Java and executed it. After execution, I could see Test.class in the c drive which means that Test.java was compiled successfully.<br />
<br />
 <br />
You may want to compile more than one classes from a Java class using javax.tools package.Only difference is that I will use a File array and will put the file objects referring to Java classes.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">import javax.tools.*;
import java.io.*;
import java.util.Arrays;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String&#91;&#93; args) {
        // TODO code application logic here
        System.out.println(&quot;Hello World&quot;);

        File file1 = new File(&quot;C:\ClassA.java&quot;);
        File file2= new File(&quot;C:\ClassB.java&quot;);
        File &#91;&#93;fileArray;
        fileArray = new File&#91;2&#93;;

        fileArray&#91;0&#93;= file1;
        fileArray&#91;1&#93;= file2;  

       // File files1 = file ; // input for first compilation task
       JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
       StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);

       Iterable compilationUnits1 =
           fileManager.getJavaFileObjectsFromFiles(Arrays.asList(fileArray));
       compiler.getTask(null, fileManager, null, null, null, compilationUnits1).call();
    }

}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 I compiled this class and on execution, got the desired results. Try at your end and see the power of Java 6.0 (MUSTANG).</blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/588-compiling-java-class-using-javacompiler.html</guid>
		</item>
		<item>
			<title>Retrieving auto generated key (JDBC 3.0)</title>
			<link>http://www.java-forums.org/blogs/java-tip/586-retrieving-auto-generated-key-jdbc-3-0.html</link>
			<pubDate>Mon, 28 Nov 2011 17:41:49 GMT</pubDate>
			<description>JDBC 3.0 introduces a lot of interesting and exciting features which makes database programming simpler. In this post, I will address how to retrieve...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">JDBC 3.0 introduces a lot of interesting and exciting features which makes database programming simpler. In this post, I will address how to retrieve auto generated keys using JDBC 3.0.<br />
<hr /><br />
To get the key, simply specify in the statement's execute() method an optional flag denoting that you are interested in the generated value. Flags of your interest are: Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS. Execute the statement and now you can obtain the values of the generated keysby retrieving a ResultSet from a Statement's instance method, getGeneratedKeys(). Now the ResultSet contains a row for each generated key.<br />
<br />
Time for an example:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">Statement stmt = conn.createStatement();
// Obtain the generated key that results from the query.
stmt.executeUpdate(&quot;INSERT INTO authors &quot; +
                   &quot;(first_name, last_name) &quot; +
                   &quot;VALUES ('George', 'Orwell')&quot;,
                   Statement.RETURN_GENERATED_KEYS);
ResultSet rs = stmt.getGeneratedKeys();
if ( rs.next() ) {
    // Retrieve the auto generated key(s).
    int key = rs.getInt(1);
}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 </blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/586-retrieving-auto-generated-key-jdbc-3-0.html</guid>
		</item>
		<item>
			<title>Returning multiple results (JDBC 3.0)</title>
			<link>http://www.java-forums.org/blogs/java-tip/585-returning-multiple-results-jdbc-3-0.html</link>
			<pubDate>Mon, 28 Nov 2011 17:38:18 GMT</pubDate>
			<description>If you have worked with JDBC 2, you might be knowing that if your statement is returning multiple results, only one ResultSet can be opened at a...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">If you have worked with JDBC 2, you might be knowing that if your statement is returning multiple results, only one ResultSet can be opened at a time. This is a limitation. Good new is that JDBC 3.0 specification allows the Statement interface to support multiple open ResultSets. Lets see hot this can be done.<br />
<br />
<hr /><br />
Please note that the execute() method closes any ResultSets that were opened from a previous call. To support multiple open results, the Statement interface adds an overloaded version of the method getMoreResults(). This method takes an integer flag which actually specifies the behavior of previously opened ResultSets when the getResultSet() method is called. The interface defines the flags as follows:<br />
<br />
CLOSE_ALL_RESULTS<br />
All previously opened ResultSet objects should be closed when calling getMoreResults().<br />
<br />
CLOSE_CURRENT_RESULT<br />
The current ResultSet object should be closed when calling getMoreResults().<br />
<br />
KEEP_CURRENT_RESULT<br />
The current ResultSet object should not be closed when calling getMoreResults().<br />
<br />
Time for an example:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">String procCall = &quot;&quot;;
// Set the value of procCall to call a stored procedure.
// ...

CallableStatement cstmt = connection.prepareCall(procCall);
boolean retval = cstmt.execute();
if (retval == false) {
    // The statement returned an update count, so handle it.
    // ...
} else { // ResultSet
    ResultSet rs1 = cstmt.getResultSet();
    // ...

    retval = cstmt.getMoreResults(Statement.KEEP_CURRENT_RESULT);
    if (retval == true) {
        ResultSet rs2 = cstmt.getResultSet();

        // Both ResultSets are open and ready for use.
        rs2.next();
        rs1.next();
        // ...
    }
}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 </blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/585-returning-multiple-results-jdbc-3-0.html</guid>
		</item>
		<item>
			<title>Prepared statement pooling (JDBC 3.0)</title>
			<link>http://www.java-forums.org/blogs/java-tip/583-prepared-statement-pooling-jdbc-3-0.html</link>
			<pubDate>Mon, 28 Nov 2011 17:35:38 GMT</pubDate>
			<description>JDBC 3.0 provides improved connection pooling. This post is all about that. 
 
 
It is also possible to pool prepared statements. A prepared...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">JDBC 3.0 provides improved connection pooling. This post is all about that.<br />
<hr /><br />
<br />
It is also possible to pool prepared statements. A prepared statement allows us to keep frequently used SQL statement in a pre-compile form, thus improving performance if that statement is executed multiple times. But there is a dark side of this. Creating a PreparedStatement object introduces a certain amount of overhead. There are some developers sometimes change their object models to increase the lifetime of a PreparedStatement object. Good thing is that JDBC 3.0 frees the developer from this, by making data source layer responsible for caching prepared statements.<br />
<br />
The code snippet shows how to take advantage of JDBC's prepared statement pooling support.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">String INSERT_BOOK_QUERY = &quot;INSERT INTO BOOKLIST &quot; +
                           &quot;(AUTHOR, TITLE) &quot; +
                           &quot;VALUES (?, ?) &quot;;
Connection conn = aPooledConnection.getConnection();
PreparedStatement ps = conn.prepareStatement(INSERT_BOOK_QUERY);
ps.setString(1, &quot;Orwell, George&quot;);
ps.setString(2, &quot;1984&quot;);
ps.executeUpdate();
ps.close();
conn.close();

// ...

conn = aPooledConnection.getConnection();
// Since the connection is from a PooledConnection, the data layer has
// the option to retrieve this statement from its statement pool,
// saving the VM from re-compiling the statement again.
PreparedStatement cachedStatement =
conn.prepareStatement(INSERT_BOOK_QUERY);
// ...</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 </blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/583-prepared-statement-pooling-jdbc-3-0.html</guid>
		</item>
		<item>
			<title>Transaction savepoints (JDBC 3.0)</title>
			<link>http://www.java-forums.org/blogs/java-tip/582-transaction-savepoints-jdbc-3-0.html</link>
			<pubDate>Mon, 28 Nov 2011 17:32:13 GMT</pubDate>
			<description>JDBC 2 provides complete transaction rollback control over transaction. But if you want to rollback to a point, you cannot do so. JDBC 3.0 introduces...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">JDBC 2 provides complete transaction rollback control over transaction. But if you want to rollback to a point, you cannot do so. JDBC 3.0 introduces savepoints which makes this possible.<br />
<hr /><br />
JDBC 3.0 provides more control over transactions using savepoints. The Savepoint interface allows us to partition a transaction into logical breakpoints. This in turn provides control over how much of the transaction we wish to rolled back.<br />
<br />
Lets see how to do this. Review the following example:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">conn.setAutoCommit(false);
// Set a conservative transaction isolation level.
conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
Statement stmt = conn.createStatement();
int rows = stmt.executeUpdate(    &quot;INSERT INTO authors &quot; +
                &quot;(first_name, last_name) VALUES &quot; +
                &quot;('Lewis', 'Carroll')&quot;);
// Set a named savepoint.
Savepoint svpt = conn.setSavepoint(&quot;NewAuthor&quot;);
// ...

rows = stmt.executeUpdate(    &quot;UPDATE authors set type = 'fiction' &quot; +
                &quot;WHERE last_name = 'Carroll'&quot;);

// ...
conn.rollback(svpt);
// ...
// The author has been added, but not updated.
conn.commit();</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 Its really an interesting feature. Try it out.</blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/582-transaction-savepoints-jdbc-3-0.html</guid>
		</item>
		<item>
			<title>Using the JAXP validation framework</title>
			<link>http://www.java-forums.org/blogs/java-tip/580-using-jaxp-validation-framework.html</link>
			<pubDate>Mon, 28 Nov 2011 17:29:47 GMT</pubDate>
			<description>While working with XML documents, you need to validate the documents. You may use setValidating() method on a SAX or DOM factory. But Java 5.0 (JAXP...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">While working with XML documents, you need to validate the documents. You may use setValidating() method on a SAX or DOM factory. But Java 5.0 (JAXP 1.3) introduces JAXP validation framework which can also be used for validating XML documents.<br />
<hr /><br />
Using the JAXP validation framework is fairly simple and efficient. In JAXP 1.3, the validation is broken out into several classes within the new javax.xml.validation package. Lets go through the steps:<br />
<br />
1. Load the model in to a JAXP compatible format.<br />
2. Create SchemaFactory and then load the schema using SchemaFactory.newSchema(Source). It will return a new Schema object.<br />
3. Use the returned schema object to create a new Validator object with Schema.newValidator().<br />
<br />
Review the code below for better understanding.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new File(args&#91;0&#93;));

// Handle validation
SchemaFactory constraintFactory =
    SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Source constraints = new StreamSource(new File(args&#91;1&#93;));
Schema schema = constraintFactory.newSchema(constraints);
Validator validator = schema.newValidator();

// Validate the DOM tree
try {
    validator.validate(new DOMSource(doc));
    System.out.println(&quot;Document validates fine.&quot;);
} catch (org.xml.sax.SAXException e) {
    System.out.println(&quot;Validation error: &quot; + e.getMessage());
}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 </blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/580-using-jaxp-validation-framework.html</guid>
		</item>
		<item>
			<title>XSLT processing in Java</title>
			<link>http://www.java-forums.org/blogs/java-tip/578-xslt-processing-java.html</link>
			<pubDate>Mon, 28 Nov 2011 17:25:09 GMT</pubDate>
			<description>XSLT (Extensible Stylesheet Language Transformations) is used to transform XML files into other formats like HTML format. There are many XSLT...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">XSLT (Extensible Stylesheet Language Transformations) is used to transform XML files into other formats like HTML format. There are many XSLT processors (libraries) available to be used in Java for XSLT transformation. These libraries can be used from a  Java application like JSP/Servlet to read a XML file and to transform it into a HTML.<br />
<hr /><br />
An XSLT processor takes two inputs: an XML file and an XSLT stylesheet.<br />
<br />
For this post, I have chosen Xalan-Java library for the transformation.<br />
<br />
Xalan-Java is an XSLT processor for transforming XML documents into HTML, text, or other XML document types.  It implements XSL Transformations (XSLT) Version 1.0 and XML Path Language (XPath) Version 1.0 and can be used from the command line,  in an applet or a servlet, or as a module in other program.<br />
<br />
Source: <a href="http://xml.apache.org/xalan-j/" target="_blank" rel="nofollow">http://xml.apache.org/xalan-j/</a><br />
<br />
To use Xalan-Java, we have to include its JAR file in the class path so we can invoke the appropriate methods. You may download the required JARs from:<br />
<br />
<a href="http://xml.apache.org/xalan-j/downloads.html" target="_blank" rel="nofollow">http://xml.apache.org/xalan-j/downloads.html</a><br />
<br />
Now lets take an example. We have following XML file:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?--&gt;
&lt;message&gt;Yep, it worked!&lt;/message&gt;</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 <hr /><br />
<br />
For the XML file given in the first part of this post, we have the following XSLT stylesheet.<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?--&gt;
&lt;xsl:stylesheet
    version=&quot;1.0&quot;
    xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&amp;gt;
  &lt;xsl:output method=&quot;text&quot; encoding=&quot;UTF-8&quot;&gt;

  &lt;xsl:template match=&quot;/&quot;&gt;
    &lt;xsl:value-of select=&quot;message&quot;&gt;
  &lt;/xsl:value-of&gt;&lt;/xsl:template&gt;

&lt;/xsl:output&gt;&lt;/xsl:stylesheet</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 Now we want to transform the XML file using XSLT stylesheet and want to print it on the console. We will use xalan engine for this.<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import org.xml.sax.SAXException;

public class SimpleXalan1 {

    public static void main(String&#91;&#93; args)
            throws MalformedURLException, SAXException {
        if (args.length != 2) {
            System.err.println(&quot;Usage:&quot;);
            System.err.println(&quot;  java &quot; + SimpleXalan1.class.getName(  )
                    + &quot; xmlFileName xsltFileName&quot;);
            System.exit(1);
        }

        String xmlFileName = args&#91;0&#93;;
        String xsltFileName = args&#91;1&#93;;

        String xmlSystemId = new File(xmlFileName).toURL().toExternalForm(  );
        String xsltSystemId = new File(xsltFileName).toURL().toExternalForm(  );

        org.apache.xalan.xslt.XSLTProcessor processor =
                org.apache.xalan.xslt.XSLTProcessorFactory.getProcessor(  );

        org.apache.xalan.xslt.XSLTInputSource xmlInputSource =
                new org.apache.xalan.xslt.XSLTInputSource(xmlSystemId);

        org.apache.xalan.xslt.XSLTInputSource xsltInputSource =
                new org.apache.xalan.xslt.XSLTInputSource(xsltSystemId);

        org.apache.xalan.xslt.XSLTResultTarget resultTree =
                new org.apache.xalan.xslt.XSLTResultTarget(System.out);

        processor.process(xmlInputSource, xsltInputSource, resultTree);
    }
}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 Happy codding!</blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/578-xslt-processing-java.html</guid>
		</item>
		<item>
			<title>JAXP SAXParser class</title>
			<link>http://www.java-forums.org/blogs/java-tip/576-jaxp-saxparser-class.html</link>
			<pubDate>Mon, 28 Nov 2011 17:19:54 GMT</pubDate>
			<description>You can doa lot if interesting stuff once you have the instance of SAXParser class. I will introduce a code snippet that will show you what you can...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">You can doa lot if interesting stuff once you have the instance of SAXParser class. I will introduce a code snippet that will show you what you can do with an instance of SAXParser.<br />
<hr /><br />
JAXP provides methods to determine the parser's settings. For instance:<br />
<br />
isValidating()<br />
use this method to see if the parser will perform validation or not<br />
<br />
isNamespaceAware()<br />
use this method to determine if the parser can process namespaces in an XML document<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">// Get a SAX Parser instance
SAXParser saxParser = saxFactory.newSAXParser();
// Find out if validation is supported
boolean isValidating = saxParser.isValidating();
// Find out if namespaces are supported
boolean isNamespaceAware = saxParser.isNamespaceAware();
// Parse, in a variety of ways
// Use a file and a SAX DefaultHandler instance
saxParser.parse(new File(args&#91;0&#93;), myDefaultHandlerInstance);
// Use a SAX InputSource and a SAX DefaultHandler instance
saxParser.parse(mySaxInputSource, myDefaultHandlerInstance);
// Use an InputStream and a SAX DefaultHandler instance
saxParser.parse(myInputStream, myDefaultHandlerInstance);
// Use a URI and a SAX DefaultHandler instance
saxParser.parse(&quot;http://www.newInstance.com/xml/doc.xml&quot;,
                myDefaultHandlerInstance);
// Get the underlying (wrapped) SAX parser
org.xml.sax.XMLReader parser = saxParser.getXMLReader();
// Use the underlying parser
parser.setContentHandler(myContentHandlerInstance);
parser.setErrorHandler(myErrorHandlerInstance);
parser.parse(new org.xml.sax.InputSource(args&#91;0&#93;));</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 These methods can give you information about what the parser can do, but users with just a SAXParser instance --<br />
and not the SAXParserFactory itself -- do not have the means to change these features. You must do this at the parser factory level.<br />
<br />
There are different ways to request parsing of a document. The SAXParser's parse() method can also accept the following:<br />
<br />
a SAX InputSource<br />
a Java InputStream<br />
a URL in String form<br />
<br />
These all should have DefaultHandler instance. This means that you can still parse documents wrapped in various forms.</blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/576-jaxp-saxparser-class.html</guid>
		</item>
		<item>
			<title>SAXParserFactory Example</title>
			<link>http://www.java-forums.org/blogs/java-tip/575-saxparserfactory-example.html</link>
			<pubDate>Mon, 28 Nov 2011 17:17:34 GMT</pubDate>
			<description>To change the parser implementations, JAXP provides a class called SAXParserFactory. I will present an example that will show how to use this class....</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">To change the parser implementations, JAXP provides a class called SAXParserFactory. I will present an example that will show how to use this class.<br />
<hr /><br />
First thing is to create an instance of SAXParserFactory. After creating the new instance, we have to get he SAX-capable parser. For thos, factory provides a method. Good thing is that the JAXP implementation takes care of the vendor-dependent code and thus keeps the code clean. This factory has some other nice features, as well. Do explore those.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">import java.io.OutputStreamWriter;
import java.io.Writer;

// JAXP
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;

// SAX
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class TestSAXParsing {
    public static void main(String&#91;&#93; args) {
        try {
            if (args.length != 1) {
                System.err.println (&quot;Usage: java TestSAXParsing &#91;filename&#93;&quot;);
                System.exit (1);
            }
            // Get SAX Parser Factory
            SAXParserFactory factory = SAXParserFactory.newInstance();
            // Turn on validation, and turn off namespaces
            factory.setValidating(true);
            factory.setNamespaceAware(false);
            SAXParser parser = factory.newSAXParser();
            parser.parse(new File(args&#91;0&#93;), new MyHandler());
        } catch (ParserConfigurationException e) {
            System.out.println(&quot;The underlying parser does not support &quot; +
                               &quot; the requested features.&quot;);
        } catch (FactoryConfigurationError e) {
            System.out.println(&quot;Error occurred obtaining SAX Parser Factory.&quot;);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

class MyHandler extends DefaultHandler {
    // SAX callback implementations from ContentHandler, ErrorHandler, etc.
}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 </blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/575-saxparserfactory-example.html</guid>
		</item>
		<item>
			<title>Introduction to JAXP</title>
			<link>http://www.java-forums.org/blogs/java-tip/574-introduction-jaxp.html</link>
			<pubDate>Mon, 28 Nov 2011 17:14:55 GMT</pubDate>
			<description>If you want to process XML data using applications written in the Java programming language, then JAXP is the best choice. JAXP stands for Java API...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">If you want to process XML data using applications written in the Java programming language, then JAXP is the best choice. JAXP stands for Java API for XML Processing. I will introduce JAXP in this post.<br />
<hr /><br />
JAXP can be called an abstraction layer since it does not introduces any new way to parse XML documents nor it provides different way of handling XML documents. Actually it makes using DOM and SAX easier. Using JAXP, you may habdle vendor-specific tasks that may arise when dealing with DOM and SAX APIs,<br />
<br />
JAXP also supports the XSLT (XML Stylesheet Language Transformations), which means that you can control the presentation of the data. Talking about namespace support, JAXP supports namespaces as well and thus allows you to work with schemas that might otherwise have naming conflicts.<br />
<br />
You may use any XML-compliant parser from within your application since JAXP is flexible. JAXP provides pluggability layer which allows you to plug in an implementation of the SAX or DOM APIs. This pluggability layer helps you to plug in an XSL processor, which means that you can transform XML data in a variety of ways.</blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/574-introduction-jaxp.html</guid>
		</item>
		<item>
			<title>Java Web Start (advantages)</title>
			<link>http://www.java-forums.org/blogs/java-tip/573-java-web-start-advantages.html</link>
			<pubDate>Mon, 28 Nov 2011 17:12:00 GMT</pubDate>
			<description>Ever thought of launching full-featured Java applications with a single click? Java Web Start provided with Java Standard Edition (J2SE™), version...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">Ever thought of launching full-featured Java applications with a single click? Java Web Start provided with Java Standard Edition (J2SE™), version 5.0 helps making this possible. In this post, I will introduce you to this new and exciting feature.<br />
<hr /><br />
Java Web Start simplifies a lot of things. For instance a complete spreadsheet program or an Internet chat client normally involves going through complicated installation procedures. But with Java Web Start, you can download and launch applications without any fuss.<br />
<br />
When you access an application through Java Web Start, the application integrates with your desktop. So for you, the application will work as a native application.<br />
<br />
Java Web Start also manages Java™ Runtime Environment versions by automatically updating the application version. It also simplifies deployment of the applications. The design and development of applications using Java Web Start is the same as it is for any other Java applications. Another plus point is that migrating a legacy application to Java Web Start is trivial. If you want to deploy the web applications, Java Web Start is the right choice for you since it involves just a few simple steps on the Web server.<br />
<br />
advantages of Java Web Start, hence motivating you to use it.<br />
<hr /><br />
<br />
Easy installation<br />
A a new application can be installed by clicking a link on a web page.<br />
<br />
Platform independence<br />
A Java application can be placed on a web server and it can be deployed on to a variety of platforms for instance: Windows 98/NT/2000/ME/XP, Linux, and Solaris.<br />
<br />
Java Runtime Environment management<br />
Another good thing about Java Web Start is that it supports multiple versions of the Java. An application can request the required Java versions without conflicting with the different needs of other applications. The downloading and installing of correct version of Java is handled by Java Web Start.<br />
<br />
Desktop integration<br />
Java Web Start integrates the Java applications on to desktop. A user can access a network application just as a native application using Java Web Start .<br />
<br />
Application updates<br />
When you run an application using Java Web Start, it connects to the web server and checks for the updates. This means, that if you have an application on a web server in JAR format, you simply need to replace it with the updated copy and all the users will get the updates through Java Web Start.<br />
<br />
<hr /><br />
Security<br />
Java Web Start uses security of the Java platform. Users should not be worried about the security model because a Java Web Start application is restricted to a sandbox and cannot corrupt user's systems. If the application provides additional security (signed JAR files), , then the user has to decide if he trusts the application's source and, if so, allow it to run. Nothing can happen behind the scenes without the user's awareness and approval. So its safe.<br />
<br />
Performance<br />
Applications launched with Java Web Start are cached locally, for improved performance.<br />
<br />
Familiar Java development requirements<br />
Applications developed to run with Java Web Start are developed in the same way as ordinary Java applications. You just have to take care of packaging requirements. Another good thing is that updating a legacy application to be deployed through Java Web Start is, in most cases, a simple process.</blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/573-java-web-start-advantages.html</guid>
		</item>
		<item>
			<title>Creating the JNLP File (Java Web Start)</title>
			<link>http://www.java-forums.org/blogs/java-tip/572-creating-jnlp-file-java-web-start.html</link>
			<pubDate>Mon, 28 Nov 2011 17:08:21 GMT</pubDate>
			<description>If you plan to run an application with Java Web Start, you have to create JNLP (Java Network Launching Protocol) file. In this post, I will briefly...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">If you plan to run an application with Java Web Start, you have to create JNLP (Java Network Launching Protocol) file. In this post, I will briefly explain how to do that.<br />
<hr /><br />
The JNLP file is an XML file and it contains elements and attributes that tell Java Web Start how to run the application.<br />
<br />
Presented below is a JNLP file for the Notepad application:<br />
<br />
&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?--&gt;<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">&lt;jnlp spec=&quot;1.0&quot;&gt;codebase=&quot;URL of application on your Web server&quot;
href=&quot;Notepad.jnlp&quot;&amp;gt;
&lt;information&gt;

&lt;vendor&gt;Sun Microsystems, Inc.&lt;/vendor&gt;
&lt;offline-allowed&gt;
&lt;/offline-allowed&gt;&lt;/information&gt;
&lt;resources&gt;
&lt;jar&gt;
&lt;j2se version=&quot;1.3+&quot;&gt;
&lt;/j2se&gt;&lt;/jar&gt;&lt;/resources&gt;
&lt;application-desc main-class=&quot;Notepad&quot;&gt;
&lt;/application-desc&gt;&lt;/jnlp&gt;</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 Once the file is ready, you have to place the application on the web server. Place all the JAR files and the<br />
JNLP file on the web server. Make sure that the locations specified by the href attribute of the jar element in the JNLP file.</blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/572-creating-jnlp-file-java-web-start.html</guid>
		</item>
		<item>
			<title>Accessing Resources in a JAR File</title>
			<link>http://www.java-forums.org/blogs/java-tip/570-accessing-resources-jar-file.html</link>
			<pubDate>Mon, 28 Nov 2011 17:05:30 GMT</pubDate>
			<description>JAR files are used to deploy applications. They comprise of java classes and other resources like images etc. In this post, I will explain how to...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">JAR files are used to deploy applications. They comprise of java classes and other resources like images etc. In this post, I will explain how to access resources packed in a JAR file.<br />
<hr /><br />
<br />
To access resources in a JAR file, we use getResource method. Lets do this practically. The code snippet provided shows how to retrieve images from a JAR file.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">// Get current classloader
ClassLoader cl = this.getClass().getClassLoader();
// Create icons
Icon saveIcon = new ImageIcon(cl.getResource(&quot;http://www.java-forums.org/images/save.gif&quot;));
Icon cutIcon = new ImageIcon(cl.getResource(&quot;http://www.java-forums.org/images/cut.gif&quot;));</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 The example assumes that the following entries exist in the JAR file.<br />
<br />
-images/save.gif<br />
-images/cut.gif<br />
<br />
Hope this helps.</blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/570-accessing-resources-jar-file.html</guid>
		</item>
		<item>
			<title>Creating JAR files</title>
			<link>http://www.java-forums.org/blogs/java-tip/568-creating-jar-files.html</link>
			<pubDate>Mon, 28 Nov 2011 17:02:49 GMT</pubDate>
			<description>This post is all about learning how to create JAR files. After going through this, you will be able to easily create JAR files. 
 
The basic JAR...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">This post is all about learning how to create JAR files. After going through this, you will be able to easily create JAR files.<br />
<hr /><br />
The basic JAR command syntax is as follows:<br />
<br />
jar cf myjar input-file(s)<br />
<br />
Let me explain the command;<br />
<br />
- c option indicates that I want to create a JAR file<br />
- f option indicates that I want the output to go to a file rather than to stdout<br />
- myjar is the name that I want the JAR file to have. It can be any name you wish to have.<br />
(Convention is to give JAR file name with the .JAR extension. This is not mandatory)<br />
- input-file(s) argument is a list of one or more files that we want to include in the JAR file. Its space-separated list.<br />
We may use wildcard * symbol in the argument.<br />
- c and f options can appear in either order (without space)<br />
<br />
jar cf myjar input-file(s) - CORRECT<br />
jar fc myjar input-file(s) - CORRECT<br />
jar c f myjar input-file(s) - INCORRECT<br />
<br />
<hr /><br />
<br />
jar cf myjar input-file(s)<br />
<br />
The above command will also generate a compressed JAR file in the current directory. A manifest file for the JAR archive will also be generated.<br />
<br />
An interesting information for you is that metadata in the JAR file (entry names, comments, contents of the manifest are encoded in UTF8).<br />
<br />
So far we have seen the JAR command in the simplest form. There are few additional options to the cf options of the basic command which are given below:<br />
<br />
v - V is for verbose output on stdout. This option can be used if you are interested in seeing the name of each file as it's added to the JAR file.<br />
<br />
0 - Zero is used if you dont want to compress the JAR file.<br />
<br />
M - M is used if you do not want the default manifest.<br />
<br />
m - m can be used to include manifest information from an existing manifest file (jar cmf existing-manifest jar-file input-file(s))<br />
<br />
I hope this was useful.</blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/568-creating-jar-files.html</guid>
		</item>
		<item>
			<title>Netbeans 6.1 New Feature</title>
			<link>http://www.java-forums.org/blogs/java-tip/507-netbeans-6-1-new-feature.html</link>
			<pubDate>Sun, 27 Nov 2011 16:56:53 GMT</pubDate>
			<description>Netbeans 6.1 is available now. There are many new and improved in NetBeans 6.x. In this post, I will list the newly added and improved features. 
 
...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">Netbeans 6.1 is available now. There are many new and improved in NetBeans 6.x. In this post, I will list the newly added and improved features.<br />
<hr /><br />
<br />
Mobility (Java ME)<br />
source: <a href="http://www.netbeans.org/features/javame/index.html" target="_blank" rel="nofollow">http://www.netbeans.org/features/javame/index.html</a><br />
- Visual Mobile Designer (new)<br />
- Mobile Game Builder (new)<br />
- Modular Build System (new)<br />
<br />
Swing GUI Builder<br />
source: <a href="http://www.netbeans.org/features/java/swing.html" target="_blank" rel="nofollow">http://www.netbeans.org/features/java/swing.html</a><br />
- Beans Binding technology (JSR 295) Support (new)<br />
- Swing Application Framework (JSR 296) Support (new)<br />
<br />
Web and Java EE<br />
Source: <a href="http://www.netbeans.org/features/web/index.html" target="_blank" rel="nofollow">http://www.netbeans.org/features/web/index.html</a><br />
- Easy migration from Java Studio Creator (new)<br />
<br />
UML<br />
source: <a href="http://www.netbeans.org/features/uml/index.html" target="_blank" rel="nofollow">http://www.netbeans.org/features/uml/index.html</a><br />
- Customizable Code Generation (new)<br />
<br />
Programming with Ajax (improvements)<br />
source: <a href="http://www.netbeans.org/features/web/ajax.html" target="_blank" rel="nofollow">http://www.netbeans.org/features/web/ajax.html</a><br />
- JavaScript Editor<br />
- Ajax Framework and Toolkit Integration<br />
- jMaki Support<br />
- Databases<br />
<br />
Java EE (Enterprise Edition)<br />
source: <a href="http://www.netbeans.org/features/web/java-ee.html" target="_blank" rel="nofollow">http://www.netbeans.org/features/web/java-ee.html</a><br />
- Server Deployment (new)<br />
<br />
Java web Applications (new and improved features)<br />
source: <a href="http://www.netbeans.org/features/web/web-app.html" target="_blank" rel="nofollow">http://www.netbeans.org/features/web/web-app.html</a><br />
- Visual Web JSF Development (improved)<br />
- JavaScript Editor (new)<br />
- CSS Editor (new)<br />
- Databases (improved)<br />
- Database and Data Binding Tools (improved)</blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/507-netbeans-6-1-new-feature.html</guid>
		</item>
		<item>
			<title>Writing MIDlet for SMS</title>
			<link>http://www.java-forums.org/blogs/java-tip/506-writing-midlet-sms.html</link>
			<pubDate>Sun, 27 Nov 2011 16:53:12 GMT</pubDate>
			<description>SMS stands for Short Messaging Service and it is very common in mobile communication. J2ME provides an API for SMS which makes messaging very easy. 
...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">SMS stands for Short Messaging Service and it is very common in mobile communication. J2ME provides an API for SMS which makes messaging very easy.<br />
<hr /><br />
I will write a MIDlet to show how to create a messaging system using javax.wireless.messaging.<br />
First step is to import all the required APIs:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">import javax.microedition.midlet.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.wireless.messaging.*;
import java.io.IOException;</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 MIDlet class should extend MIDlet class. Since it will be a multithreaded application, we need to implement Runnable interface. To provide action listeners, we will also implement CommandListener and MessageListener interfaces.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">public class SMSReceive extends MIDlet
implements CommandListener, Runnable, MessageListener {</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 Now we may declare the commands we want to have in our MIDlet.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">/** user interface command for indicating Exit request. */
Command exitCommand = new Command(&quot;Exit&quot;, Command.EXIT, 2);
/** user interface command for indicating Reply request */
Command replyCommand = new Command(&quot;Reply&quot;, Command.OK, 1);
/** user interface text box for the contents of the fetched URL.</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 */<br />
<br />
<hr /><br />
<br />
will continue with writing the MIDlet.<br />
Now we will declare other stuff (Thread, Alert, String arrays etc) as shown below:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">Alert content;
/** current display. */
Display display;
/** instance of a thread for asynchronous networking and user interface. */
Thread thread;
/** Connections detected at start up. */
String&#91;&#93; connections;
/** Flag to signal end of processing. */
boolean done;
/** The port on which we listen for SMS messages */
String smsPort;
/** SMS message connection for inbound text messages. */
MessageConnection smsconn = null;
/** Current message read from the network. */
Message msg;
/** Address of the message's sender */
String senderAddress;
/** Alert that is displayed when replying */
Alert sendingMessageAlert;
/** Prompts for and sends the text reply */
SMSSender sender;
/** The screen to display when we return from being paused */
Displayable resumeScreen;</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 We need to initialize the MIDlet with the current display object and graphical components. I will do that in the SMSReceive method as shown below.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">public SMSReceive() {
smsPort = getAppProperty(&quot;SMS-Port&quot;);

display = Display.getDisplay(this);

content = new Alert(&quot;SMS Receive&quot;);
content.setTimeout(Alert.FOREVER);
content.addCommand(exitCommand);
content.setCommandListener(this);
content.setString(&quot;Receiving...&quot;);

sendingMessageAlert = new Alert(&quot;SMS&quot;, null, null, AlertType.INFO);
sendingMessageAlert.setTimeout(5000);
sendingMessageAlert.setCommandListener(this);

sender = new SMSSender(smsPort, display, content, sendingMessageAlert);

resumeScreen = content;
}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 I will write startApp() method. This is part of MIDlet lifecycle. Application Management System calls it after calling the constructor.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">public void startApp() {
// SMS connection to be read.
String smsConnection = &quot;sms://:&quot; + smsPort;
content.setString(smsConnection);

// Open the message connection.

try {
smsconn = (MessageConnection)Connector.open(smsConnection, Connector.READ);
} catch (Throwable t) {
content.setString(t.toString());
}
display.setCurrent(resumeScreen);
}

For handling notification that a message arrived, we will write notifyIncomingMessage method that will take MessageConnection as argument.


public void notifyIncomingMessage(MessageConnection conn) {
if (thread == null) {
done = false;
thread = new Thread(this);
thread.start();
}
}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 Do remember that we are writing a multi threaded SMS MIDLet. The MIDLet signature reads like:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">public class SMSReceive extends MIDlet
implements CommandListener, Runnable, MessageListener {
...
}

Lets define the run method:


public void run() {

try {
msg = smsconn.receive();
if (msg != null) {
senderAddress = msg.getAddress();
content.setTitle(&quot;From: &quot; + senderAddress);
if (msg instanceof TextMessage) {
content.setString(((TextMessage)msg).getPayloadText());
} else {
StringBuffer buf = new StringBuffer();
byte&#91;&#93; data = ((BinaryMessage)msg).getPayloadData();
for (int i = 0; i &lt; data.length; i++) {
int intData = (int)data &amp; 0xFF;
if (intData &lt; 0x10) {
buf.append(&quot;0&quot;);
}
buf.append(Integer.toHexString(intData));
buf.append(' ');
}
content.setString(buf.toString());
}
content.addCommand(replyCommand);
display.setCurrent(content);
}
} catch (IOException e) {
 e.printStackTrace();
}
}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 The method is used to read the SMS message. If the message is a text message then things are simple. In the other case we have to read the message in a byte array.<br />
In this post, I will present pauseApp and destroyApp methods. You are supposed to write these in your application. Do revise MIDlet life cycle for better understanding.<br />
<hr /><br />
<br />
Pause signals the thread to stop by clearing the thread field. If stopped before done with the iterations it will be restarted from scratch later.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">public void pauseApp() {
done = true;
thread = null;
resumeScreen = display.getCurrent();
}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 Destroy must cleanup everything. The thread is signaled to stop and no result is produced.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">public void destroyApp(boolean unconditional) {
done = true;
thread = null;
if (smsconn != null) {
try {
smsconn.close();
} catch (IOException e) {
// Ignore any errors on shutdown
}
}
}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 This is the final part of &quot;Writing MIDlet for SMS &quot;. This post presents commandAction method which is a command listener.<br />
More...<br />
<br />
The following methiod responds to commands for example exit, reply etc.<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">
public void commandAction(Command c, Displayable s) {
try {
if (c == exitCommand || c == Alert.DISMISS_COMMAND) {
destroyApp(false);
notifyDestroyed();
} else if (c == replyCommand) {
reply();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 // Allow the user to reply to the received message<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">private void reply() {
// remove the leading &quot;sms://&quot; for diplaying the destination address
String address = senderAddress.substring(6);
String statusMessage = &quot;Sending message to &quot; + address + &quot;...&quot;;
sendingMessageAlert.setString(statusMessage);
sender.promptAndSend(senderAddress);
}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 I hope you have gone through all parts of &quot;Writing MIDlet for SMS&quot;. Put the code together and try it yourself. Do some experiments and explore more. Remember, you will learn a lot while doing experiments.<br />
<br />
Happy coding!!</blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/506-writing-midlet-sms.html</guid>
		</item>
		<item>
			<title>MIDlet Suite</title>
			<link>http://www.java-forums.org/blogs/java-tip/505-midlet-suite.html</link>
			<pubDate>Sun, 27 Nov 2011 16:44:51 GMT</pubDate>
			<description>In this post, I will introduce you to the MIDlet suite. 
 
I assume that you people have worked with Eclipse. In Eclipse, you create projects and all...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">In this post, I will introduce you to the MIDlet suite.<br />
<hr /><br />
I assume that you people have worked with Eclipse. In Eclipse, you create projects and all the contents of the project are placed in the project folder. It is an approach for managing the work.<br />
<br />
MIDlet suite is very much like a standard Java project in Eclipse. Please note that it's not a requirement to place MIDlets inside a Java Archive (JAR) file, but JAR files provide the most common means of distributing MIDP applications. The MIDlet Suite comproses of all files and resources that may be required as part of a MIDlet. The MIDlet Suite consists of<br />
<br />
- Java class files enclosed in a JAR file<br />
- manifest file describing the contents of the JAR<br />
- resources (images, etc) enclosed in a JAR file<br />
- Java Application Descriptor file (JAD)</blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/505-midlet-suite.html</guid>
		</item>
		<item>
			<title>Deploying MIDlets onto Mobile Devices</title>
			<link>http://www.java-forums.org/blogs/java-tip/504-deploying-midlets-onto-mobile-devices.html</link>
			<pubDate>Sat, 26 Nov 2011 17:43:08 GMT</pubDate>
			<description>The subject topic is very interesting and a lot of people have asked me about this. It is just a matter of knowing how this works. I am sure you will...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">The subject topic is very interesting and a lot of people have asked me about this. It is just a matter of knowing how this works. I am sure you will find it very interesting.<br />
<hr /><br />
MIDlets are programmed using Java Development environments like Eclipse, JBuilder,Netbeans or Sun Java wireless Toolkit. Once coded, they are build and tested on emulators. When all the tests are passed, you want to finally deploy it to your mobile device to see how it works in real world scenerio.<br />
<br />
There are actually two ways to deploy MIDlets.<br />
<br />
- transferring JAR through dada cable<br />
- transferring JAR through web<br />
<br />
For testing, the first method is OK but it cannot be used for mass distribution, since you cannot even think of transferring JARs to hundreds and thousands of mobile phones.<br />
We will transfer the JARs through a PC to the phone. There are few options to do this:<br />
<br />
<hr /><br />
- Explicit physical connection via USB cable<br />
- Direct InfraRed (IR) connection<br />
- Direct Bluetooth connection<br />
<br />
which option to choicer, depends on the cell phone you have.<br />
<br />
Will will need a USB cable for the first option, which is provided by your phone manufacturer and also there will be a software from the manufacturer. Do read the manual before opting this.<br />
<br />
You may also use InfraRed and Bluetooth options as well.<br />
<br />
If your phone and your PC both have InfraRed, then you can transfer files via InfraRed. This is very useful option if you are suing Windows XP.<br />
<br />
<hr /><br />
JAD (Java Application Decription files) contains the JAR file name and size attributes. From mobile phone, you will make an HTTP request for the JAR file. In response, you will get the JAD file on to your mobile device. Mobile device have AMS (Application Management System) that will read zthe required attributes and will make another HTTP request to the server for the required JAR file. In response, you will get the JAR file on to your mobile device which actually is the MIDlet.<br />
<br />
An example JAD file is given below:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">MIDlet-Name: Show Properties MIDlet
MIDlet-Version: 1.0.1
MIDlet-Vendor: My Corporation Inc.
MIDlet-Jar-URL: file://showProperties.jar
MIDlet-Jar-Size: 1132
MIDlet-1: ShowProps, , showProperties
JadFile-Version: 1.5
MIDlet-Data-Size: 500</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 </blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/504-deploying-midlets-onto-mobile-devices.html</guid>
		</item>
		<item>
			<title>EJB - Entity Beans</title>
			<link>http://www.java-forums.org/blogs/java-tip/503-ejb-entity-beans.html</link>
			<pubDate>Sat, 26 Nov 2011 17:39:40 GMT</pubDate>
			<description>This post contains an introduction to Entity Beans. 
 
An entity beans are used to represent a business object in a persistent storage mechanism for...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">This post contains an introduction to Entity Beans.<br />
<hr /><br />
An entity beans are used to represent a business object in a persistent storage mechanism for example: customers, orders, products, employees etc. We normally refer persistent storage mechanism as a relational database. Normally, each entity bean has an underlying table in a relational database. Please note that each instance of the bean corresponds to a row in that table.<br />
<br />
Some people mix Entity beans with session means. Both are different in many ways. Some properties of Entity beans are listed below which are not present in Session beans:<br />
<br />
- persistent<br />
- shared access<br />
- primary keys<br />
- may participate in relationships with other entity beans<br />
<br />
Lets talk about persistence. The state of Entity bean is saved in a storage mechanism, therefore it is persistent. It means that the entity bean’s state exists beyond the lifetime of the application or the J2EE server process. You all know that the data in a database is persistent because it stays even after database server or the applications are turned off/shutdown.<br />
<br />
<hr /><br />
Multiple clients can share Entity beans. This is useful because there may exist situations where multiple clients might want to change the same data. So it is important that entity beans work within transactions. EJB container (JBOSS, BEA Web Logic, Web Sphere) provides transaction management, so you as a developer should not be bothered about this. For this, you have to specify the transaction attributes in the bean's deployment descriptor.<br />
<br />
Now lets talk about primary key in Entity bean. It is important that each entity bean has a unique object identifier. For example, an employee entity bean, will be identified by a unique employee number. This primary key, enables the client to locate a particular entity bean.<br />
<br />
<br />
<hr /><br />
A primary key class must meet the following requirements:<br />
<br />
- class must be serializable<br />
- access control modifier of the class must be public.<br />
- all fields must be declared as public.<br />
- fields must be a subset of the bean's persistent fields.<br />
- public default constructor is a must<br />
- class should implement the hashCode() and equals(Object other) methods<br />
<br />
Lets take an example. The example class has a composite primary key.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">public class PurchaseOrderKey implements java.io.Serializable {

  public String productModel;
  public String vendorId;

  public PurchaseOrderKey() { };

  public boolean equals(Object other) {

    if (other instanceof PurchaseOrderKey) {
      return (productModel.equals(
          ((PurchaseOrderKey)other).productModel) &amp;&amp;
          vendorId.equals(
          ((PurchaseOrderKey)other).vendorId));
    }
    return false;
  }

  public int hashCode() {
    return productModel.concat(vendorId).hashCode();
  }
}</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 </blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/503-ejb-entity-beans.html</guid>
		</item>
		<item>
			<title>Accessing Beans (EJB)</title>
			<link>http://www.java-forums.org/blogs/java-tip/502-accessing-beans-ejb.html</link>
			<pubDate>Sat, 26 Nov 2011 17:36:42 GMT</pubDate>
			<description>In the post, I will write about how to accessing a bean in EJB. 
 
Accessing deployed beans is simple. First write the the client code and set up...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">In the post, I will write about how to accessing a bean in EJB.<br />
<hr /><br />
Accessing deployed beans is simple. First write the the client code and set up JNDI environment settings for the client. It can be done via a JNDI properties file. Now you have to set the class path for the client and add the following file locations to it:<br />
<br />
jboss-client.jar, jnp-client.jar, EJB interfaces, and the directory where the JNDI properties file is stored<br />
<br />
Remember, two JNDI settings must be made which are:<br />
- the initial context factory<br />
- the provider URL<br />
<br />
These properties are best established in a JNDI properties file.<br />
<br />
After setting jndi.properties file, place it in a directory and place that directory into the client's classpath.<br />
Now simply drop the JAR into the deploy directory, start the client, and invoke the EJB service.</blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/502-accessing-beans-ejb.html</guid>
		</item>
		<item>
			<title>JBoss Application Server</title>
			<link>http://www.java-forums.org/blogs/java-tip/501-jboss-application-server.html</link>
			<pubDate>Sat, 26 Nov 2011 17:35:11 GMT</pubDate>
			<description>Talking about J2EE application servers, JBOSS is a popular choice. The reason is that JBOSS is open-source EJB solution with lot of impressive...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">Talking about J2EE application servers, JBOSS is a popular choice. The reason is that JBOSS is open-source EJB solution with lot of impressive features that are missing in Weblogic, WebSphere, and the other big players.<br />
<hr /><br />
Some of the interesting features provided by JBOSS are:<br />
<br />
- enterprise-class security<br />
- transaction support<br />
- resource management<br />
- load balancing<br />
- clustering<br />
- database connection pooling<br />
- JavaMail support<br />
<br />
JBOSS is a container for the following:<br />
<br />
- Servlets<br />
- JSPs<br />
- EJB (Entity Beans, Session Beans, and Message Driven Beans)<br />
- Web Services<br />
<br />
JBoss Application Server ships with Apache Tomcat for the web tier, Hypersonic for embedded database services, and Hibernate for object-relational mapping.<br />
<br />
<hr /><br />
<br />
The first step is to download and install the server. I would prefer JVM 1.5 but you can use older versions as well but it should be 1.3+ version of JVM.<br />
<br />
Download the latest stable version of the JBoss distribution at <a href="http://www.jboss.org/" target="_blank" rel="nofollow">http://www.jboss.org/</a>.<br />
<br />
Unzip the compressed file into the desired directory. Note: An installation directory (JBoss-x.x.x/) will be created there.<br />
<br />
Now you have to create an environment variable (variable name: JBOSS_DIST) pointing to the location of the JBoss directory (variable value: path_to_jboss).<br />
<br />
Setting environment variable in Windows NT/2000/XP is simple and is discussed in the next post.<br />
<br />
<hr /><br />
Follow the following steps to set environment variable:<br />
<br />
- Open Control Panel<br />
- Click the System icon<br />
- Go to the Advanced pane<br />
- Click the Environment Variables button<br />
- There are two separated windows showing two sets of environment variables. Select the &quot;new&quot; button for the upper window to create a new environment variable.<br />
- Select the &quot;Edit&quot; button for the upper window to edit an existing environment variable.<br />
<br />
Now test the installation by executing the run script from the /bin directory.<br />
<br />
When you start the server up, you will see a bunch of output from the script giving you more information than you could ever want about exactly what is going on with JBoss. Several screens of text will scroll past you. No need to worry as this is normal. How will you know that everything is ok or not. The answer is that at the end, if you see a single line indicating that the JBoss server started in a certain number of seconds, it means all is fine and server has started. Also see if any exception was thrown.<br />
<br />
<hr /><br />
Enterprise beans are packaged in a JAR file (Java ARchive) with the appropriate XML files in the META-INF folder. Most J2EE app servers require the deployment of an EJB JAR within a WAR (Web ARchive) file, and even within an EAR file (Enterprise ARchive). The process of packaging up an enterprise bean with deployment descriptors into a larger archive with its deployment descriptors can become rather complex. This process may be necessary in a production environment, but in development, you need quick, efficient deployment. JBoss provides the best of both worlds.<br />
<br />
In order to deploy EJBs in JBoss, simply drop the archive into the deploy directory. The JBoss engine immediately inspects the contents of the archive and attempts to deploy the beans. To undeploy, simply delete the archive from the deploy directory.<br />
<br />
Following features make deployment process highly efficient with JBoss:<br />
<br />
- supports the deployment of EJB JARs contained within WARs and EARs<br />
- supports the native deployment of EJB JARs<br />
- does not require the inclusion of the server-specific XML file unless specific changes are made</blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/501-jboss-application-server.html</guid>
		</item>
		<item>
			<title>Record Management System</title>
			<link>http://www.java-forums.org/blogs/java-tip/500-record-management-system.html</link>
			<pubDate>Tue, 22 Nov 2011 17:14:02 GMT</pubDate>
			<description>RMS is a database (flat file) which MIDlets can use to persist data. In this post, I will introduce the audience with RMS. 
 
The device platform...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">RMS is a database (flat file) which MIDlets can use to persist data. In this post, I will introduce the audience with RMS.<br />
<hr /><br />
The device platform maintains the integrity of the MIDlet's record stores throughout the normal use. The reboots, battery changes, etc. won’t affect the RMS. An interesting question developers ask is, where is this Record Store created? It is created at platformdependent location, like nonvolatile device memory, and is not directly exposed to the MIDlets.<br />
<br />
an important thing to note is that that record store implementations ensure that all record store operations are atomic, synchronous, and serialized, so no corruption of data will occur during multiple accesses.<br />
The record store maintains the following information:<br />
<br />
- timestamp to indicate when it was modified.<br />
- version information (integer) which is incremented for each operation that modifies the contents of the record store.<br />
<br />
The version and timestamp info is of great use when you want to start the synchronization process. An interesting info for you is that each record in a Record Store has an array of bytes with a unique integer identifier.<br />
<br />
There arises an interesting question: What if a MIDlet uses multiple threads to access a record store? You as a developer should not address this. Its MIDlet's responsibility to coordinate this access; and if it fails to do so, unintended consequences may result. Also note that if a platform performs a synchronization of a record store with multiple threads trying to access the record store simultaneously, the platform will manage everything.<br />
Do read the first part of this post. This post is code specific. I will present some sode snippets to make things obvious.<br />
<hr /><br />
<br />
Opening the Record Set is very easy.<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">
RecordStore rs = RecordStore.openRecordStore(&quot;MyContact&quot;,true);</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 To add a record, javax.microedition.rms.RecordStore provides the followig method:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">public int addRecord(byte&#91;&#93; data, int offset, int numBytes)</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 Example follows below:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">String appt = &quot;new record&quot;;
byte bytes&#91;&#93; = appt.getBytes();
rs.addRecord(bytes,0,bytes.length);</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 Let me show you how to delete a record from a Record Store:<br />
To update a record, you first have to get that record using the following method:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">public int getRecord(int recordId, byte&#91;&#93; buffer, int offset)</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 It will return the data stored in the given record in form of byte array<br />
<br />
Now use the setRecord method to update the record:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">public void setRecord(int recordId, byte&#91;&#93; newData, int offset, int numBytes)</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 Example follows below:<br />
<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">tring newappt = &quot;update record&quot;;
Byte data = newappt.getBytes();
Rs.setRecord(1, data, 0, data.length());</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 </blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/500-record-management-system.html</guid>
		</item>
		<item>
			<title>TextField vs TextBox</title>
			<link>http://www.java-forums.org/blogs/java-tip/499-textfield-vs-textbox.html</link>
			<pubDate>Tue, 22 Nov 2011 17:08:55 GMT</pubDate>
			<description>javax.microedition.lcdui provides TextField and TextBox which are sometimes confusing. Both are to allow the user to enter text, but question arises,...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">javax.microedition.lcdui provides TextField and TextBox which are sometimes confusing. Both are to allow the user to enter text, but question arises, when to use which one? In this post, I will try to address this issue.<br />
<hr /><br />
Let me first explain TextField (javax.microedition.lcdui.TextField). This class inherits from javax.microedition.lcdui.Item, so you should know that its an item that can be placed on a form. To create an instance of TextField, we use the TextField constructor:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">TextField(String label, String text, int maxSize, int constraints)</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 The parameters are self explanatory. Let me present an example:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">...
Display display;
Form form;
TextField textField;
...
protected void startApp() throws MIDletStateChangeException {
System.out.println(&quot;startApp.&quot;);
display = Display.getDisplay(this);
form = new Form(&quot;Helloworld example&quot;);
StringItem body = new StringItem(null,&quot;Hello World!&quot;);
textField = new TextField(&quot;Name&quot;, &quot;your last name&quot;, 15, 0);
form.append(body);
form.append(textField);
display.setCurrent(form);</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 Output:<br />
<img src="http://www.java-tips.org/blog/wp-content/uploads/2008/04/textbox.PNG" border="0" alt="" /><br />
<br />
So use Textfield when you want to take input from the user and want to place the field on a form.<br />
<br />
I will write about TextBox (javax.microedition.lcdui.TextBox). This class inherits from javax.microedition.lcdui.Screen, so you should know that its a Screen and unlike TextField, it cannot be appended to a Form.<br />
<br />
<hr /><br />
To create an instance of TextBox, we use the TextBox constructor:<br />
<br />
<br />
TextBox(String label, String text, int maxSize, int constraints)<br />
<br />
The parameters are self explainatory. Let me present an example:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">...
Display display;
TextBox textBox;
...
protected void startApp() throws MIDletStateChangeException {
System.out.println(&quot;startApp.&quot;);
display = Display.getDisplay(this);
form = new Form(&quot;Helloworld example&quot;);
StringItem body = new StringItem(null,&quot;Hello World!&quot;);
textBox = new TextBox(&quot;Location&quot;, &quot;your location&quot;, 15, 0); 

display.setCurrent(textBox);</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 Output:<br />
TextBox example <br />
<img src="http://www.java-tips.org/blog/wp-content/uploads/2008/04/textbox_1.PNG" border="0" alt="" /><br />
<br />
So use TextBox when you want to take input from the user without using Form. Since TextBox is a Screen, you may append commands on it as well.</blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/499-textfield-vs-textbox.html</guid>
		</item>
		<item>
			<title>Maven (intro)</title>
			<link>http://www.java-forums.org/blogs/java-tip/498-maven-intro.html</link>
			<pubDate>Tue, 22 Nov 2011 17:02:08 GMT</pubDate>
			<description>Maven is a software project management tool, based on project object model. It aims at reducing the load of developer by making in software build...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">Maven is a software project management tool, based on project object model. It aims at reducing the load of developer by making in software build process simple and faster.<br />
<hr /><br />
Following are worth mentioning features of Maven:<br />
<br />
- Provides a uniform build system<br />
- Provides quality project information<br />
- Provides guidelines for best practices development<br />
- Allows transparent migration to new features<br />
<br />
When to use Maven is an interesting question. If you have a complex software underdevelopment, that has a lot of classes in different packages, and there exists dependencies between the classes, then<br />
use Maven.<br />
<br />
Maven can do the following:<br />
- code compiling<br />
- Javadoc documentation<br />
- runs unit tests.<br />
- runs source code metrics and analysis<br />
- creates a report detailing violations of your team's coding standards<br />
- create a report of the most recent CVS commits and CVS activity, pivoted by file and developer<br />
- also create HTML cross-referenced source code, and more<br />
<br />
You can download Maven from:<br />
<a href="http://maven.apache.org/download.html" target="_blank" rel="nofollow">http://maven.apache.org/download.html</a></blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/498-maven-intro.html</guid>
		</item>
		<item>
			<title>XML Pull Parsing (Demo)</title>
			<link>http://www.java-forums.org/blogs/java-tip/497-xml-pull-parsing-demo.html</link>
			<pubDate>Tue, 22 Nov 2011 16:58:10 GMT</pubDate>
			<description>XML Pull Parsing makes parsing XML documents easier and efficient. This post introduces this API. 
 
You may get the required API from...</description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">XML Pull Parsing makes parsing XML documents easier and efficient. This post introduces this API.<br />
<hr /><br />
You may get the required API from <a href="http://www.xmlpull.org/" target="_blank" rel="nofollow">http://www.xmlpull.org/</a>.<br />
Java docs are available at: <a href="http://www.xmlpull.org/v1/doc/api/org/xmlpull/v1/XmlPullParser.html" target="_blank" rel="nofollow">http://www.xmlpull.org/v1/doc/api/or...ullParser.html</a><br />
<br />
Let me present an example of parsing XML using XML Pull Parsing.<br />
<br />
<hr /><br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Java Code: </div>

	<pre class="brush: java">public class SimpleXmlPullApp
 {

     public static void main (String args&#91;&#93;)
         throws XmlPullParserException, IOException
     {
         XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
         factory.setNamespaceAware(true);
         XmlPullParser xpp = factory.newPullParser();

         xpp.setInput( new StringReader ( &quot;Hello World!&quot; ) );
         int eventType = xpp.getEventType();
         while (eventType != XmlPullParser.END_DOCUMENT) {
          if(eventType == XmlPullParser.START_DOCUMENT) {
              System.out.println(&quot;Start document&quot;);
          } else if(eventType == XmlPullParser.END_DOCUMENT) {
              System.out.println(&quot;End document&quot;);
          } else if(eventType == XmlPullParser.START_TAG) {
              System.out.println(&quot;Start tag &quot;+xpp.getName());
          } else if(eventType == XmlPullParser.END_TAG) {
              System.out.println(&quot;End tag &quot;+xpp.getName());
          } else if(eventType == XmlPullParser.TEXT) {
              System.out.println(&quot;Text &quot;+xpp.getText());
          }
          eventType = xpp.next();
         }
     }
 }</pre>
	<script type="text/javascript">mh_sh_highlight_all('java');</script>

</div>
 Output:<br />
<br />
<br />
 Start document<br />
 Start tag foo<br />
 Text Hello World!<br />
 End tag foo</blockquote>

]]></content:encoded>
			<dc:creator>Java Tip</dc:creator>
			<guid isPermaLink="true">http://www.java-forums.org/blogs/java-tip/497-xml-pull-parsing-demo.html</guid>
		</item>
	</channel>
</rss>
