View RSS Feed

All Blog Entries

  1. Serving Static Content in Spring

    by , 11-27-2011 at 10:06 PM
    If you are concern you that DispatcherServlet will be handling static content requests, Spring has features that can help you to deal with this. Spring’s mvc namespace includes a <mvc:resources> element that handles requests for static content for you. In the following example, I show you how you can create an xml file that the DispatcherServlet can use to create an application context.

    Java Code:
    <?xml version="1.0" encoding="UTF-8"?> 
    <beans xmlns="http://www.springframework.org/schema/beans"
    ...

    Updated 11-30-2011 at 12:59 PM by Spring Framework

    Categories
    MVC
  2. Spring MVC Basics

    by , 11-27-2011 at 10:03 PM
    Spring MVC’s key component is the DispatcherServlet. This servlet that functions as Spring MVC’s front controller. Like any servlet, DispatcherServlet must be configured in the web application’s web.xml file. If you need to setup the Dispatcher Servlet it is relatively straightforward. Below is what needs to be added to the web.xml file.

    Java Code:
    <servlet> 
         <servlet-name>springexamples</servlet-name> 
           <servlet-class>org.springframework.web.servlet.DispatcherServlet
    ...
    Tags: spring mvc Add / Edit Tags
    Categories
    MVC , Spring 3
  3. Configuring a Spring Data Source Continued

    by , 11-27-2011 at 10:02 PM
    There are a number of DataSource connection pool implementations provided by different vendors as well as projects like C3PO and Apache Commons DBCP providing popular open-source options. It is easy to switch between different data source implementations, because of the common DataSource interface. Spring provides a convenient data source implementations as well but it is not considered as powerful as the vendor or open source implementations. The simplest one is org.springframework.jdbc.datasource.DriverManagerD ataSource, ...
  4. Writing A Namespace Handler in Spring

    by , 11-27-2011 at 09:58 PM
    Custom XML namespaces were introduced in Spring 2.0. Similar to Java packages, custom namespaces make it possible to define components without concern of colliding with other named components. Spring has already some predefined namespaces such as jee, aop, util, as well as others. Custom namespaces are handled using the NamespaceHandlerSupport class that generates metadata to be consumed by the Spring framework. This metadata is processed by parser classes that are also supplied by a component developer. ...
  5. Introducing Behaviors to Your Spring Beans

    by , 11-27-2011 at 09:55 PM
    In Spring AOP, you can use what is called an introduction (a special type of advice) that enables your objects to implement an interface dynamically, by providing the implementation class for that interface. This behavior can be multiplied to give the impression of multiple inheritance to your beans. To define an introduction, use the @DeclareParents annotation, which gives matching types a new parent.

    Java Code:
    package com.acme.springexamples.derivautos;
    import org.aspectj.lang.annotation.Aspect;
    ...
    Categories
    Bean , Spring 3
  6. Configuring Data Sources in Spring

    by , 11-27-2011 at 09:51 PM
    Spring offers a number of options for configuring a data sources via data source beans. These sources include the following:
    • Data sources that use JNDI
    • Data sources that use JDBC drivers
    • Data sources that pool connections


    There is significant differences in the features available depending on what you are trying to do. In this tip, I will outline how to configure different data sources and what they are best used for.

    If you are looking to do really robust ...
  7. Reduce your Spring XML using Java Configuration

    by , 11-27-2011 at 09:47 PM
    As Spring has grown so has the need to configure more and more components leading to the xml configuration files growing larger and larger. In order to address this issue, the Java configuration project was started as a standalone project at SpringSource and developed over the years. It was finally integrated into the core Spring framework in version 3.0. Now you are able to use a powerful ApplicationContext configuration abstraction that has the same level of isolation as its XML cousin. In this ...
  8. Internationalization with Spring

    by , 11-27-2011 at 09:43 PM
    Often it is necessary for an application to be able to support several languages in order to address the requirements of customers located in different countries. For this java has support for what is called internationalization (i18n) that allows allows for an application to resolve text messages for different locales. The means of doing this in Java is to use what is called a ResourceBundle. These are property files that contain a key/message pair and have a special naming convention for the file ...
  9. How to Automatically Discover Spring Beans on the Classpath

    by , 11-27-2011 at 09:38 PM
    Since it’s appearance in Java 5, annotations has helped to simplify the configuration of application through component scanning. This removes the need for XML bean tags in many cases. Classes annotated as component stereotypes including the following: @Service, @Controller, @Configuration, @Component, @Repository as well as the JSR-330 annotations, such as @Named are included in the auto-scan default filter. Once auto-detected, these components become Spring beans and are automatically placed ...
  10. Using Spring Data Access Support with Hibernate

    by , 11-27-2011 at 09:35 PM
    In our previous tip, I gave an introduction to Spring’s persistence technology agnostic approach to data access. In this tip, we will show you how to use Spring with one of the most popular persistence technologies, Hibernate. Hibernate is an open source persistence framework that is one of the most successful persistence frameworks in the developer community. The reason for this is that it is a full featured object relational mapping (ORM) tool. It provides all the features you’d expect from a ...
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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. ...
  21. 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
  22. Jsr 75

    by , 11-22-2011 at 05: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
  23. Subversion (intro)

    by , 11-22-2011 at 05: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.

    ...
  24. Subclipse

    by , 11-22-2011 at 05: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
  25. Reading/writing files

    by , 11-22-2011 at 05: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());
    ...
  26. Sending SMS (snippet)

    by , 11-22-2011 at 05: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://");
    ...
  27. GPS location / Cell id / Placing a call

    by , 11-22-2011 at 05:16 PM (My Java Tips)
    This post presents miscellaneous tasks that you can do in your J2ME application.


    Firstly, how to get GPS location. javax.microedition.location.Location provides support for this. Review the snippet below:

    Java Code:
    LocationProvider loc = LocationProvider.getInstance(null);
    loc.setLocationListener(ll,0,-1,-1);
    Location location = loc.getLocation(60*3);
    String lat = location.getQualifiedCoordinates().getLatitude();
    String lon = location.getQualifiedCoordinates().getLongitude();
    ...
  28. MIDP packages

    by , 11-22-2011 at 04:53 PM (My Java Tips)
    MIDP provides a standard run-time environment that allows new applications and services to be deployed dynamically on end-user devices like cellular phones and pagers. The MIDP is built upon CLDC (Connected Limited Device Configuration).


    MIDP is an industry-standard profile for mobile devices and it is not dependent on a specific vendor. It is a provides foundation for mobile application development. MIDP contains following 3 core CLDC packages:

    java.lang
    java.io ...
  29. Ant Paths

    by , 11-21-2011 at 05:05 PM (My Java Tips)
    If you specify the PATH and the CLASSPATH type references using any of this, that is ":" and ";" as a separator characters, Ant can convert the separator to the correct character of the operating system in the use.


    A nested element can be used wherever path like values need to be specified. See the example below.
    Java Code:
        <classpath>
    <pathelement path="${classpath}"></pathelement>
    <pathelement location="lib/helper.jar"></pathelement>
    ...
    Categories
    Ant
  30. Package Explorer - Class Method

    by , 11-21-2011 at 05:01 PM (My Java Tips)
    In this post, I will write about Eclipse feature that shows the artifacts of a class method.


    Eclipse package explorer is a very useful explorer that gives the developer a birds eye view of the package, class and methods. Review the class below:

    Java Code:
    public class Student {
    
    	private int id;
    	private String name;
    	private static int counter;
    	private static final int MAXCOUNT=10;
    
    	public Student(int id, String name)
    ...
Page 33 of 48 FirstFirst ... 23313233343543 ... LastLast