View RSS Feed

My Java Tips

  1. OMA standard for data synchronisation - SyncML

    by , 11-28-2011 at 07:06 PM (My Java Tips)
    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.


    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.
    ...
    Tags: oma, syncml Add / Edit Tags
    Categories
    Java ME
  2. Using the DocumentBuilderFactory

    by , 11-28-2011 at 07:02 PM (My Java Tips)
    In this post, I will present an example to show how to use the DocumentBuilderFactory.


    First step is to import the required classes.

    Java Code:
    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;
    ...
    Categories
    Java EE
  3. Working with the DOM parser

    by , 11-28-2011 at 06:59 PM (My Java Tips)
    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 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 ...
    Categories
    Java EE
  4. Reading RSS using Informa API

    by , 11-28-2011 at 06:56 PM (My Java Tips)
    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.


    To read RSS feeds in a Java application is easy. You have to use Informa API which is availabel at:
    http://informa.sourceforge.net/.

    The code snippet given below shows how to read RSS using Informa API.

    Java Code:
    try {
    ...
    Tags: informa, rss Add / Edit Tags
    Categories
    Java EE
  5. Java Compiler API (brief intro)

    by , 11-28-2011 at 06:49 PM (My Java Tips)
    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.


    The classes related to Java compiler are packed into javax.tools package.

    There is a class called ToolProvider (javax.tools) whose getSystemJavaCompiler() method returns an instance of some class ...
    Tags: ide, javac Add / Edit Tags
    Categories
    Java SE
  6. Compiling a Java class using JavaCompiler

    by , 11-28-2011 at 06:47 PM (My Java Tips)
    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 Test.java file:

    Java Code:
    public class Test{
    
    public static void main(String[] args) {
            // TODO code application logic here
            System.out.println("Hello World");
    callMe();
    }
        public static void callMe(){
         System.out.println("Hello Babar dost");
    ...
    Categories
    Java SE
  7. Retrieving auto generated key (JDBC 3.0)

    by , 11-28-2011 at 06:41 PM (My Java Tips)
    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.


    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 ...
    Categories
    JDBC
  8. Returning multiple results (JDBC 3.0)

    by , 11-28-2011 at 06:38 PM (My Java Tips)
    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.



    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 ...
    Categories
    JDBC
  9. Prepared statement pooling (JDBC 3.0)

    by , 11-28-2011 at 06:35 PM (My Java Tips)
    JDBC 3.0 provides improved connection pooling. This post is all about that.



    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 ...
    Categories
    JDBC
  10. Transaction savepoints (JDBC 3.0)

    by , 11-28-2011 at 06:32 PM (My Java Tips)
    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.


    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.

    Lets see how to do this. Review the following ...
    Tags: jdbc 2, savepoint Add / Edit Tags
    Categories
    JDBC
  11. Using the JAXP validation framework

    by , 11-28-2011 at 06:29 PM (My Java Tips)
    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.


    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:

    1. Load the model in to ...
    Tags: dom, java 5.0, jaxp, sax Add / Edit Tags
    Categories
    Java EE , XML
  12. XSLT processing in Java

    by , 11-28-2011 at 06:25 PM (My Java Tips)
    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.


    An XSLT processor takes two inputs: an XML file and an XSLT stylesheet.

    For this post, I have chosen Xalan-Java library for the transformation. ...
    Tags: html, xalan-java, xml, xslt Add / Edit Tags
    Categories
    XML
  13. JAXP SAXParser class

    by , 11-28-2011 at 06:19 PM (My Java Tips)
    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.


    JAXP provides methods to determine the parser's settings. For instance:

    isValidating()
    use this method to see if the parser will perform validation or not

    isNamespaceAware()
    use this method to determine if the parser can process namespaces in an XML document ...
    Categories
    Java EE
  14. SAXParserFactory Example

    by , 11-28-2011 at 06:17 PM (My Java Tips)
    To change the parser implementations, JAXP provides a class called SAXParserFactory. I will present an example that will show how to use this class.


    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 ...
    Categories
    Java EE
  15. Introduction to JAXP

    by , 11-28-2011 at 06:14 PM (My Java Tips)
    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.


    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 ...
    Tags: dom, jaxp, sax Add / Edit Tags
    Categories
    Java EE
  16. Java Web Start (advantages)

    by , 11-28-2011 at 06:12 PM (My Java Tips)
    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.


    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 ...
    Categories
    Java Web Start
  17. Creating the JNLP File (Java Web Start)

    by , 11-28-2011 at 06:08 PM (My Java Tips)
    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.


    The JNLP file is an XML file and it contains elements and attributes that tell Java Web Start how to run the application.

    Presented below is a JNLP file for the Notepad application:

    <!--?xml version="1.0" encoding="utf-8"?-->
    Java Code:
    <jnlp spec="1.0">codebase="URL
    ...
    Tags: jnlp file, xml Add / Edit Tags
    Categories
    Java Web Start
  18. Accessing Resources in a JAR File

    by , 11-28-2011 at 06:05 PM (My Java Tips)
    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.



    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.

    Java Code:
    // Get current classloader
    ClassLoader cl = this.getClass().getClassLoader();
    // Create icons
    ...
    Categories
    Java SE
  19. Creating JAR files

    by , 11-28-2011 at 06:02 PM (My Java Tips)
    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 command syntax is as follows:

    jar cf myjar input-file(s)

    Let me explain the command;

    - c option indicates that I want to create a JAR file
    - f option indicates that I want the output to go to a file rather than to stdout
    - myjar is the name that I want the JAR file to have. It can be ...
    Categories
    Java SE
  20. Netbeans 6.1 New Feature

    by , 11-27-2011 at 05:56 PM (My Java Tips)
    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.



    Mobility (Java ME)
    source: http://www.netbeans.org/features/javame/index.html
    - Visual Mobile Designer (new)
    - Mobile Game Builder (new)
    - Modular Build System (new)

    Swing GUI Builder
    source: http://www.netbeans.org/features/java/swing.html
    - Beans Binding technology (JSR 295) ...
    Categories
    NetBeans
  21. Writing MIDlet for SMS

    by , 11-27-2011 at 05:53 PM (My Java Tips)
    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.


    I will write a MIDlet to show how to create a messaging system using javax.wireless.messaging.
    First step is to import all the required APIs:

    Java Code:
    import javax.microedition.midlet.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.wireless.messaging.*;
    ...
    Tags: api, midletj2me, sms Add / Edit Tags
    Categories
    Java ME
  22. MIDlet Suite

    by , 11-27-2011 at 05:44 PM (My Java Tips)
    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 the contents of the project are placed in the project folder. It is an approach for managing the work.

    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 ...
    Categories
    Java ME
  23. Deploying MIDlets onto Mobile Devices

    by , 11-26-2011 at 06:43 PM (My Java Tips)
    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.


    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.
    ...
    Categories
    Java ME
  24. EJB - Entity Beans

    by , 11-26-2011 at 06:39 PM (My Java Tips)
    This post contains an introduction to Entity Beans.


    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.

    Some people mix Entity beans with session ...
    Categories
    Java EE
  25. Accessing Beans (EJB)

    by , 11-26-2011 at 06:36 PM (My Java Tips)
    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 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:

    jboss-client.jar, jnp-client.jar, EJB interfaces, and the directory where the JNDI properties file is stored

    Remember, two JNDI settings ...
    Tags: beans, ejb, jndi Add / Edit Tags
    Categories
    Java EE
  26. JBoss Application Server

    by , 11-26-2011 at 06:35 PM (My Java Tips)
    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.


    Some of the interesting features provided by JBOSS are:

    - enterprise-class security
    - transaction support
    - resource management
    - load balancing
    - clustering
    - database connection pooling
    - JavaMail support ...
    Tags: ejb, jboss Add / Edit Tags
    Categories
    Java EE
  27. Record Management System

    by , 11-22-2011 at 06:14 PM (My Java Tips)
    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 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.
    ...
    Tags: midlet, rms, timestamp Add / Edit Tags
    Categories
    Java ME
  28. TextField vs TextBox

    by , 11-22-2011 at 06:08 PM (My Java Tips)
    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.


    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: ...
    Categories
    Java ME
  29. Maven (intro)

    by , 11-22-2011 at 06:02 PM (My Java Tips)
    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.


    Following are worth mentioning features of Maven:

    - Provides a uniform build system
    - Provides quality project information
    - Provides guidelines for best practices development
    - Allows transparent migration to new features

    When to use Maven is an interesting question. ...
  30. XML Pull Parsing (Demo)

    by , 11-22-2011 at 05:58 PM (My Java Tips)
    XML Pull Parsing makes parsing XML documents easier and efficient. This post introduces this API.


    You may get the required API from http://www.xmlpull.org/.
    Java docs are available at: http://www.xmlpull.org/v1/doc/api/or...ullParser.html

    Let me present an example of parsing XML using XML Pull Parsing.




    Java Code:
    public class SimpleXmlPullApp
     {
    
         public static void main (String args[])
    ...
    Categories
    XML
Page 1 of 15 12311 ... LastLast