View RSS Feed

All Blog Entries

  1. How to sign a Java applet

    by , 12-09-2011 at 06:16 AM
    Why signing an applet?

    By default, a Java applet is running inside a restricted environment called “sandbox”. The sandbox isolates the applet outside the browser environment and user’s computer, preventing maliciously coded applets from running without user’s granted permission.
    Applets are considered to be untrusted if they are not signed with a security certificate. Untrusted applets are also referred to as unsigned applets. Being inside the security sandbox, unsigned applets ...

    Updated 12-09-2011 at 03:41 PM by Java Applet

    Java Applet , Tutorial
  2. How to use HTML to display an Applet in browsers

    by , 12-08-2011 at 11:19 AM
    Applet is a Java based application which is embedded into a web page. Its advantage is to provide rich user interface experience and interaction just like other desktop applications, while still keeping the powerful features of Java like cross-platform, security, multi-threading…
    This article will guide you through some basic steps to build a simple applet, use HTML code to display the applet in browsers. In addition, you will learn how to passing parameters and loading external libraries ...
  3. Using Spring Web Flow Part 2

    by , 11-30-2011 at 05:00 AM
    In the previous article, we looked at the components of Spring Web Flow. In this article, I will tie all the pieces together for the application.

    As you know, Spring Web Flow provides a powerful controller to control the user navigation in case your application requires it. Below is the definition of a simple flow to carry out a booking process is shown graphically below:

    Why Spring Web Flow
    We know that defining and understanding page flow of a complex web application ...

    Updated 12-05-2011 at 01:45 PM by Spring Framework

    MVC , Spring 3 , Web Flow , Spring Flow , Webflow
  4. Using Spring Web Flow Part 1

    by , 11-30-2011 at 04:52 AM
    In a previous article, I gave an introduction to Spring Web Flow. In this article, I will delve into the details of how to use Spring Web Flow.

    In Spring Web Flow, a flow is defined by three primary elements: states, transitions, and flow data. States are points in a flow where something happens. Consider if you want to plan a short holiday in Florence. You need to first choose your flights, then you choose your hotel, you might also choose a car, etc. Similarly, as a flow progresses, ...
  5. Viewing Options in Spring

    by , 11-30-2011 at 04:38 AM
    In your application, once the service have handled the request and returned the results desired, you will need to render the results in a useful manner to the user. This is the purpose of viewing technology such as JavaServer Pages (JSP). Although you can use JSPs in Spring there are a number of other viewing technologies that Spring support. In this tip, I will outline some of the other view technologies that are available.

    When Spring is looking to render some content, the DispatcherServlet ...
  6. Using Inheritance - Substitution vs. Extension

    by , 11-30-2011 at 02:51 AM
    We are going to look at inheritance hierarchy. If we take a classic approach, as shown below we would see the methods that have been defined in the base class overridden in the derived classes. Inheritance guarantees that any derived class will have the interface of the base class. If you follow this diagram below, derived classes will also have no more than the base-class interface.

    Name:  Inheritance-Example.jpg
Views: 915
Size:  16.7 KB

    This can be thought of as pure substitution, because ...
  7. Design Principle: Choose Composition vs. Inheritance

    by , 11-30-2011 at 02:48 AM
    With composition or inheritance you can place sub-objects inside your new class. If you do this explicitly than you are using composition otherwise if you do this implicitly, you are using inheritance. I will outline the difference between the two below as well as point out one of the key design patterns to use in your development. Prefer composition vs inheritance.

    Composition is used when you want the features of an existing class to be included inside your new class, but not be ...
  8. Using Name Hiding for Overriding

    by , 11-30-2011 at 02:45 AM
    Sometimes you will have a java base class that has a method that’s been overloaded several times. It is important for the programmer to remember that redefining the method name in the derived class does not hide any of the base-class versions. Therefore you should keep in mind that overloading works irrespective of whether the method has been defined at this level or in a base class:

    Java Code:
    import static com.acme.examples.Print.*;
    public class Mother {
    	char foo(char
  9. Using Imports to Change Behaviour

    by , 11-30-2011 at 02:36 AM
    One thing that would be great to have is a feature that I know well from my previous experience coding in C. That is the possibility to conditional compile in order to modify the behavior of the application. A feature that is missing from Java is C’s conditional compilation, which allows you to change a switch and get different behavior without changing any other code. I think is was left out of Java is that I remember using this feature often to address issues related to compiling a program on ...
    Tutorial , Import
  10. Use an Interface to Compare Objects in Generics

    by , 11-29-2011 at 11:25 PM
    A key aspect of using generics is being able to compare different objects. Consider an example where you are comparing different species of felines.
    Java Code:
    public class ComparableFeline implements Comparable<ComparableFeline> {
    	public int compareTo(ComparableFeline arg0) {
    		return 0;
    So if you wanted to narrow ComparableFeline for use only among different types of domesticated cats instead of other felines such as ...

    Updated 11-30-2011 at 08:37 AM by Advanced Java

  11. Use Lists instead Arrays in Generics

    by , 11-29-2011 at 11:20 PM
    Generics were added to java in release 1.5. It allows you to avoid needing to cast objects as they are read from a collection. Instead you tell the compiler what types of objects that you want to hold in the collection. Often it is difficult to know which generic to use when you have two or more who seem to be able to complete the same function. Consider the choice between whether to use a list or an array. Now a key thing to remember is that arrays are covariant and know and enforce their element ...
  12. Wildcards with Generics

    by , 11-29-2011 at 11:16 PM
    Unlike with arrays, it is important to remember with generics that is not possible to upcast an object from its superclass to its subclass. So for example, this will create a compile time error.

    Java Code:
    import java.util.*;
    public class NonCovariantGenerics { 
    // Compile Error: incompatible types: 
    List<Shape> slist = new ArrayList<Rectangle>();
    In this listing List of Rectangle is not type-equivalent to a List of Shape, even if an Rectangle ...
  13. Supertype Wildcards with Generics

    by , 11-29-2011 at 11:12 PM
    In my last tip, I showed how you can use a wildcard with generics. It is also possible to use a supertype wildcards. In this case the wildcard is bounded by any base class of a particular class, by specifying <? super MyClass> or even using a type parameter: <? super T> (although you cannot give a generic parameter a supertype bound; that is, you cannot say <T super MyClass>). This allows you to safely pass a typed object into a generic type. Thus, with supertype wildcards you ...
  14. Unbounded Wildcards with Generics

    by , 11-29-2011 at 11:09 PM
    When you as a programmer decide to use an unbounded wildcard <?>, it appears to mean anything. and so using an unbounded wildcard seems equivalent to using a raw type. There are time that the compiler is indifferent as to using raw type or <?>. If you use <?> it can be considered as a decoration. When you are using the raw type, the generic parameter can hold any type. In this example I show an important use of unbounded wildcards. If you are dealing with multiple generic parameters, ...
  15. Unnecessary Object Creation with Immutable Objects

    by , 11-29-2011 at 11:05 PM
    Programmers are often not aware of how to create objects that can be reused. The key to understanding how to create reusable objects is that they must be immutable. So for example if you a running a loop in which each loop a string instance is required, rather than create a new instance every time it executes, you simply reuse the existing instance.

    Rather than create a new String instance.

    Java Code:
    public void BuildingLoop{
    	int total = 10;
    	for(int i=0;
  16. Unnecessary Object Creation with Mutable Objects

    by , 11-29-2011 at 10:59 PM
    Continuing with our last tip on immutable objects, we now look at re-using mutable objects. Although you cannot modify a mutable object, you can avoid unnecessarily waste memory by reusing the existing instance. So consider for example mutable Date objects. Once the values are computed, they are never modified. So for example if you a running a loop in which each loop a string instance is required, rather than create a new instance every time it executes, you simply reuse the existing instance. ...
  17. Dynamic Type Safety in Pre Java 5 Code Collections

    by , 11-29-2011 at 10:40 PM
    Sometimes is might be necessary to pass generic containers to pre-Java5 code. In those cases, it is possible that the old-style code can corrupt your containers. In order to address this issue, there are a set of utilities in the java.util.Collections package to address the issues around type-checking. There are a number of static methods designed for this. They all take the container that you are checking as the first argument and the type you want to enforce as the second argument. They are shown ...
  18. Comparing Objects and HashCode

    by , 11-29-2011 at 10:30 PM
    Another thing that many programmers forget when they make objects that they need to compare in their applications is that it is not enough to assume that if your object is a subclass of Object, that the hashCode method that you can use it in a HashMap, Hashtable or HashSet. In fact, the Java specification states that you must always override the hashCode when ever you override the equals method. Otherwise, you have violated one of the key tenants of Java in not ensuring that equal objects have equal ...
  19. Sorting Collections

    by , 11-29-2011 at 05:23 PM
    If you are interested in sorting your collections, the good news is that since the inception of Java 5 it is now possible for collections and arrays to be sorted. This is very useful because it is a hell of a lot easier to find something in a sorted set than in an unsorted set. There are a number of sorting algorithms that can be used for your collections. There are listed below.
    • Bubble Sort algorithm
    • Bi-direction Bubble Sort algorithm
    • Quick Sort algorithm
    • Generic Sorting algorithm
    Tutorial , Sorting
  20. Composition Syntax for Reuse

    by , 11-29-2011 at 05:21 PM
    One of the best features of Java is code reuse. But like any tool, it needs to be used effectively. Most programmers might be lead to think that when I talk of reuse only relates to extending a class. Now there is nothing wrong with reusing a class by extending it or using it directly. This type of reuse is using the class without the risk changing the existing code. First we can create objects of the existing class inside the new class. We call this composition. It is a new class composed of objects ...
  21. How to do Overloading with Generics

    by , 11-29-2011 at 04:12 PM
    Overloading is a technique often used in object orientated programming languages such as java. In the context of generics unfortunately, classic type of overloading will produce a compile time error because of erasure.

    Java Code:
    import java.util.List;
    public class OverloadingExample<W, T> {
    	void f(List<T> v) {
    	void f(List<W> v) {

    What you must do to overcome this problem is to provide ...
  22. Generics - Exceptions

    by , 11-29-2011 at 03:35 AM
    Due to erasure, exception use is limited with generics. As exceptions are know at both compile and at run time, it renders redundant the use of catch clauses. This also means that a generic class cannot inherit directly or indirectly from Throwable.

    One can though use type parameters in the throws clause of a method declaration. This will allow you to write generic code that varies with the type of a checked exception:

    Java Code:
    import java.util.List;
    public interface
  23. Using Imports to Change Behaviour

    by , 11-29-2011 at 03:24 AM
    One thing that would be great to have is a feature that I know well from my previous experience coding in C. That is the possibility to conditional compile in order to modify the behaviour of the application. A feature that is missing from Java is C’s conditional compilation, which allows you to change a switch and get different behaviour without changing any other code. I think is was left out of Java is that I remember using this feature often to address issues related to compiling a program ...
  24. Managing Initialization and Class Loading

    by , 11-29-2011 at 03:20 AM
    Java avoids many of the problems found with other languages related to the startup and initialization of objects in the right order, by taking a different approach to loading. The key to this is that everything in Java is an object. Each class exists in its own separate file. Therefore files are not loaded until the code is needed. The expression of this is that “class code is loaded at the point of first use.” This is usually when the first object of that class is constructed, but loading also ...
  25. Basics of Exceptions

    by , 11-29-2011 at 03:09 AM
    One of the key aspects of programming is understanding how to handle exceptions. An exception is a problem that prevents the continuation of the current method or scope. It’s important to distinguish an exceptional condition from a normal problem, in which you have enough information in the current context to somehow cope with the difficulty. With an exception, you cannot continue processing because you lack the information necessary to address the problem in its current context. The only recourse ...

    Updated 11-30-2011 at 03:19 AM by Java Exception

    Error Handling , Tutorial
  26. Catching an Exception

    by , 11-29-2011 at 03:07 AM
    Following on from our previous tip on exceptions, in this tip we will look at catching an exception. One of the key concepts to understand is the concept of a guarded region. It is a section of code that might produce exceptions and is followed by the code to handle a particular exception. They are often grouped into all the possible exceptions for a particular method or piece of code.

    The try block
    The first part of the region is the try block. This is when you’re inside a ...
  27. How to Handle Input with Spring MVC

    by , 11-29-2011 at 02:57 AM
    Spring MVC is structured to handle state management, workflow and validation. It is an application of the Model-View-Controller pattern. As with all things Spring, it follows the principles of loose coupling and flexibility. When a request is made, it reaches the DispatcherServlet whose role is to forward the request to the relevant Spring MVC controller, it is the controller that processes the request. In this article we will look in depth in what a Spring Controller does when it processes input. ...
  28. How to Inject AspectJ Aspects into Spring

    by , 11-29-2011 at 02:53 AM
    For those of you who have already worked with Spring AOP knows that it is sufficient for many of the applications of aspects that are generally done in a system. Still it is weak in certain areas of AOP solution in contrast to AspectJ that has added a number of powerful features over time. There are now many types of AspectJ pointcuts that aren’t possible with Spring AOP.

    For example, Spring’s proxy-based AOP is not able to advise on object creation. This is because constructors in ...
    AOP , Spring 3
  29. Introduction to Spring Web Flow

    by , 11-29-2011 at 02:49 AM
    When you are developing an user interaction for an application, one of the most challenging aspects is to define a proper narrative for the behavior of the application so that the user can get into a flow while using the application. Sometimes it is necessary to step a user through a process, such as ordering a plane ticket. This is called a flowed application. Now is a possible to use any web framework, such as Struts or Java Server Faces, in order to do this. Unfortunately none of them properly ...
  30. Data Access with Java Persistence API

    by , 11-29-2011 at 02:44 AM
    Spring integration with Java Persistence API (JPA) came about on the release of Spring 2.0. It is very easy to use JPA with Spring because it is all based on plain old java beans (POJOs). In this tip, we will outline the steps required for you to use JPA with Spring.

    JPA-based applications are based on the implementation of EntityManagerFactory in order to get an instance of an EntityManager. There are two kinds of entity managers from the JPA Specification that both implement the ...

    Updated 11-30-2011 at 03:23 AM by Spring Framework

    JPA , Spring 3 , EntityManager , EntityManagerFactory
Page 30 of 48 FirstFirst ... 20282930313240 ... LastLast