Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Jan 26, 2011

Getting started with jBPM 5

I once wrote a blog on setting up jBPM 3 with jBoss ESB which proved useful to lot of folks. Now I am going to present a similar one for the all-new jBPM5. There is indeed a huge difference between the two and I must admit that the new product stack is looking very good, loaded with many must-have options any BPM product should ship with.
I will write about all the technical insights in a separate post. One good news you should know is that the installation has got a lot easier in this version. Let's just get started with jBPM 5, install it, and see it for ourselves.

Prerequisites:

  1. JDK 1.5 or higher (Download Page)
  2. Ant 1.7.1 or higher (Download Page)
  3. PATH variable: properly set for both.

Diving in...

  1. Get the Installer (Download Page) (Link last updated on Jan 7, 2013)
  2. Install jBPM5
  3. Import a sample project
  4. Run the sample project

Watch this video...

    Dec 21, 2010

    Reading stuffs in a HTTP Request

    A HTTP Request has unimaginably more content than you think it will have. In Java Server programming, all your requests are contained in a HTTPRequest object and you are supposed to read the request and send back a response.
    There are certain common or business fields that you may want to preserve across the application. Like the logged-in user's name, or a shopping cart that contains the list of items that the customer added to his cart. You have three options to store/retrieve such general details. Header, Session and Cookies.
    Below is a piece of Java Servlet code that will help read HTTPHeaders, HTTPSession variables, and HTTPCookies. Based on your situation, you can add conditions/modify them as per your needs.

    Code to read the available cookies:
    Cookie[] cookies = request.getCookies();
    if ((cookies != null) && (cookies.length > 0)) {
      for (int i = 0; i < cookies.length; i++) {
       Cookie cookie = cookies[i];
        System.out.print("Cookie Name: " + cookie.getName());
         System.out.println("  Cookie Value: " + cookie.getValue());
         }
       } 
    else{
    System.out.println("no cookies found");
         }

    Code to read the available variables in the HTTP Header:

    java.util.Enumeration names = request.getHeaderNames();
      while (names.hasMoreElements())
       {
        String name = (String) names.nextElement();
        System.out.print(" "+name+": "+request.getHeader(name));
       }        

    Use this code to read the available variables in the HTTP Session object.

    java.util.Enumeration sessionVars = request.getSession().getAttributeNames();
    while (sessionVars.hasMoreElements())
    {
    String name = (String) sessionVars.nextElement();
    System.out.print(" "+name+": "+request.getSession().getAttribute(name));
    }        
         

    Feb 7, 2010

    Connecting to MS SQL Server through JDBC

    This post is directed at any one who is in trouble trying to figure out a way to connect to Microsoft SQL Server from JAVA. The Java Database Connectivity (JDBC) is the API that helps establishing a connection to almost any Database from a Java program. Though a connectivity to MS SQL Server is rarely established from Java as the prominent participants in the communication would be Oracle & MySQL.
    JDBC is a generic API and the procedure is same for any Database communication.
    1. You download the JDBC driver for the appropriate Database (Like Oracle, MS-SQL Server)
    2. Start the Database server.
    3. Establish the connection from the Java program.
    4. Enjoy communication. Go ahead - Create, Delete, Update...What ever you want...
    The following article from Microsoft Support helps you find your way.
    http://support.microsoft.com/kb/313100

    Sep 30, 2009

    [Java] For-Each Loop

    Have you ever worried of using an Iterator to navigate thro' a collection object ?

    Here after there is no need to use Iterator , Enumerator & Blah…Blah Classes to Go through a collection Object.

    The New For Loop in JDK 1.5 Uses the : Operator………

    This simple FOR loop solves the problem.

    For-each Loop

    Purpose

    The basic for loop was extended in Java 5 to make iteration over arrays and other collections more convenient. This newer for statement is called the enhanced forfor-each (because it is called this in other programming languages). I've also heard it called the for-in loop. or

    Use it in preference to the standard for loop if applicable (see last section below) because it's much more readable.

    Series of values. The for-each loop is used to access each successive value in a collection of values.

    Arrays and Collections. It's commonly used to iterate over an array or a Collections class (eg, ArrayList).

    Iterable. It can also iterate over anything that implements the Iterable interface (must define iterator() method). Many of the Collections classes (eg, ArrayList) implement Iterable, which makes the for-each loop very useful. You can also implement Iterable for your own data structures.
    General Form

    The for-each and equivalent for statements have these forms. The two basic equivalent forms are given, depending one whether it is an array or an Iterable that is being traversed. In both cases an extra variable is required, an index for the array and an iterator for the collection.

    For-each loopEquivalent for loop
    for (type var : arr) {
    body-of-loop
    }
    for (int i = 0; i < arr.length; i++) {
    type var = arr[i];
    body-of-loop
    }
    for (type var : coll) {
    body-of-loop
    }
    for (Iterator<type> iter = coll.iterator(); iter.hasNext(); ) {
    type var = iter.next();
    body-of-loop
    }

    Example - Adding all elements of an array

    Here is a loop written as both a for-each loop and a basic for loop.

    double[] ar = {1.2, 3.0, 0.8};
    int sum = 0;
    for (double d : ar) { // d gets successively each value in ar.
    sum += d;
    }

    And here is the same loop using the basic for. It requires an extra iteration variable.

    double[] ar = {1.2, 3.0, 0.8};
    int sum = 0;
    for (int i = 0; i <>
    Where the for-each is appropriate


    Altho the enhanced for loop can make code much clearer, it can't be used in some common situations.
    • Only access. Elements can not be assigned to, eg, not to increment each element in a collection.
    • Only single structure. It's not possible to traverse two structures at once, eg, to compare two arrays.
    • Only single element. Use only for single element access, eg, not to compare successive elements.
    • Only forward. It's possible to iterate only forward by single steps.
    • At least Java 5. Don't use it if you need compatibility with versions before Java 5.

    Start Transforming………

    You may also like these writeups

    Related Posts with Thumbnails