View RSS Feed

All Blog Entries

  1. Compiling a Java class using JavaCompiler

    by , 11-28-2011 at 07: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
  2. Retrieving auto generated key (JDBC 3.0)

    by , 11-28-2011 at 07: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
  3. Returning multiple results (JDBC 3.0)

    by , 11-28-2011 at 07: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
  4. Prepared statement pooling (JDBC 3.0)

    by , 11-28-2011 at 07: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
  5. Transaction savepoints (JDBC 3.0)

    by , 11-28-2011 at 07: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
  6. Using the JAXP validation framework

    by , 11-28-2011 at 07: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
    XML , Java EE
  7. XSLT processing in Java

    by , 11-28-2011 at 07: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
  8. JAXP SAXParser class

    by , 11-28-2011 at 07: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
  9. SAXParserFactory Example

    by , 11-28-2011 at 07: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
  10. Introduction to JAXP

    by , 11-28-2011 at 07: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
  11. Java Web Start (advantages)

    by , 11-28-2011 at 07: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
  12. Creating the JNLP File (Java Web Start)

    by , 11-28-2011 at 07: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
  13. Accessing Resources in a JAR File

    by , 11-28-2011 at 07: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
  14. Creating JAR files

    by , 11-28-2011 at 07: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
  15. Netbeans 6.1 New Feature

    by , 11-27-2011 at 06: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
  16. Writing MIDlet for SMS

    by , 11-27-2011 at 06: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
  17. MIDlet Suite

    by , 11-27-2011 at 06: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
  18. Deploying MIDlets onto Mobile Devices

    by , 11-26-2011 at 07: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
  19. EJB - Entity Beans

    by , 11-26-2011 at 07: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
  20. Accessing Beans (EJB)

    by , 11-26-2011 at 07: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
  21. JBoss Application Server

    by , 11-26-2011 at 07: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
  22. Record Management System

    by , 11-22-2011 at 07: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
  23. TextField vs TextBox

    by , 11-22-2011 at 07: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
  24. Maven (intro)

    by , 11-22-2011 at 07: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. ...
  25. XML Pull Parsing (Demo)

    by , 11-22-2011 at 06: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
  26. Jsr 75

    by , 11-22-2011 at 06:52 PM (My Java Tips)
    JSR 75 specifies 2 optional packages for mobile devices. I will be talking about these in the next few posts.


    The two provided packages are:
    Java Code:
    javax.microedition.io.file
    javax.microedition.pim
    PIM stands for personal information and it contains following information:
    - contact list
    - todo list
    - events

    If you want to access these from a J2ME application, then javax.microedition.pim is to be used.

    ...
    Tags: j2me, jsr 75, pim Add / Edit Tags
    Categories
    Java ME
  27. Subversion (intro)

    by , 11-22-2011 at 06:45 PM (My Java Tips)
    Subversion is a centralized system for sharing information. It comprises of a repository, which is a central store of data. The repository stores information in the form of a file system. Clients can connect to this repository, and can read or write to these files. When a client writes data, it actually makes the information available to others; and when a client reads the data, it actually receives information from others. Its a typical client server system which uses version model.

    ...
  28. Subclipse

    by , 11-22-2011 at 06:41 PM (My Java Tips)
    Consider that you are working on a large/medium size Java project in teams. This is an ideal scenario for using Subversion to distribute and maintain source code. Good news is that you can use integrate your source code with Subversion within Eclipse environment.


    An Eclipse plugin called Subclipse is to be used for integrating source code with Subversion within Eclipse environment. You may download Subclipse from:
    http://subclipse.tigris.org/download.html

    Once ...
    Categories
    Subversion
  29. Reading/writing files

    by , 11-22-2011 at 06:26 PM (My Java Tips)
    This post is all about reading and writing text files on mobile device.


    In order to write files on the mobile device, you need com.motorola.file.writeaccess. If your application has that permission, you can write files easily using the following code.

    Java Code:
    FileConnection sc = (FileConnection)Connector.open("file:///phone/tmp.txt");
    OutputStream os = sc.openOutputStream();
    os.write(("text to go into the file").getBytes());
    ...
  30. Sending SMS (snippet)

    by , 11-22-2011 at 06:22 PM (My Java Tips)
    This post presents a snippet for sending short text messages from J2Me applications.


    The com.sun.midp.io.j2me.sms package provides an API for the Short Message Service Messaging system and allows MIDlet to access SMS functionality on a GSM mobile device. You need javax.wireless.messaging.sms.send premission to send SMS messages from your J2ME application. The sample code is presented below:

    Java Code:
    sender = (MessageConnection)Connector.open("sms://");
    ...
Page 3 of 17 FirstFirst 1234513 ... LastLast