woensdag 27 juni 2007

workaholics (NL)

70% zelfstandigen werkt meer dan 50u per week
25% zelfstandigen werkt zelfs meer dan 70u per week

bron
trends

woensdag 20 juni 2007

project management the big picture

Currently I use subversion for version control and maven (for some projects ant is used) for building. If you know ant but never used maven start reading about the diffrerences first. Most important is that these two projects have different goals. Maven is based on ant and provides more overall project management functionality, which is what I'm looking for here. As far as I know ant focuses more on platform independent building.

Still my IDE needs to be optimized so I need to look into the more general picture of project management. Like release management and of course the integration of all this into eclipse, the IDE of my choice.

An interesting thesis on this subject:

http://www.idi.ntnu.no/grupper/su/su-diploma-2006/dipl-enes-24feb07.pdf

SCM

System Configuration Management is what we're looking for. At the above link you can find a good dscription and brief history of SCM. Read it, it's interesting.

The document handles most aspects of SCM in the context of build and release management. Exactly what I'm looking for.

workspace pc for development, local file system, eclipse, sources (checked out)

versioning svn for versioning all sources assigning revision numbers and keeping track of changes, history, on file level

building make/ant/maven for compiling sources

release management maven, compiling sources for deployment, assign version number, on libraries/software level

dependency management maven, what libraries (jar for java) are needed to compile this artifact

repository management maven, managing a repositoruy of dependencies, holds several releases of libraries

change management following up changes of software components, like bugs, change requests, ...

Except for release and change management mvn + svn suit all my needs. Change management is a big issue and will most likely require more than one tool. For now I will just ignore it. Maybe I need to get back to this later on. What I really want to get into is the release management.

release management

Does maven have any support for release management? Yes it have, I'll find out in my mighty maven post.

mighty maven

You read my previous post on SCM?

Then we can continue by telling you more about maven. A great page to start is the maven project home page. For the quickies there is maven in 5 minutes.

Installation you'll really have to figure out yourself, is no more than unzipping package and setting some path variables.

Create your first project by the following commands
mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-app
cd my-app


With the create goal you can generate the basic project structure and a basic pom file. The cd (change directory) was only to get yourself in your new project folder in order to continue.

To get this project into eclipse simply execute the following command.
mvn eclipse:eclipse

You can then import the project into eclipse as an existing java project. Dependencies will then be added to the classpath for your eclipse project (you might have to set the M2_REPO variable in eclipse to point to your maven repository). If you don't like the command way you can look for the maven eclipse plugin. This enables you to graphically manage your dependencies from within eclipse.

Then you can start developping, to compile use
mvn compile

You'll see that your junit tests form the test packages are executed before compiling the project itself. This is how it should be so keep your tests up to date.

Once the project is stable you can package project facets into jar with
mvn package

To be able to use this jar as a dependency in one of your next projects you can install the jar into your repository
mvn install


So far all of this was very straight forward. Now we'll get into more realistic situations with version control and release management.

Let us first configure our version control so we've got something to fall back to when we have a bad day. If you haven't any svn set up you can read the subversion setup post. Therefore add the following lines to your pom file

...
find out what's the best way to combine maven project structure and svn structure + give an overview of the different structures here, probably something like workspace/trunk/mavenproject/...

Also you'll want to deploy a complete project ... parent pom
war and ear packaging
...


resources
o list of build tools
o http://www.javaworld.com/javaworld/jw-10-2002/jw-1011-maven.html
o http://www.ibm.com/developerworks/java/library/j-maven/
o alternative maven repo

subversion setup

This is a quick subversion setup. really quick because to be honest it's my first time. Normally I only get the repository url and an account, setup done for me.

Start by downloading the latest subversion build for your system at http://subversion.tigris.org/project_packages.html.

Unzip this archive somewhere and ad the bin to your path variable.

Create your local repository with the following command
svnadmin create /path/to/repos


Next you can import your first project with the following command
svn import /tmp/project file:///path/to/repos -m "initial import"


An important note about your project structure,
subversion expects the following 3 root folders:

/tmp/project/branches/
/tmp/project/tags/
/tmp/project/trunk/


Then you can check the project out again with
svn checkout file:///path/to/repos/trunk project


All is done, you can now start importing other projects, commit changes, checkout elsewhere, etc...

Note that these examples all work locally so we can use the file:// protocol. Remotely this would be http:// or others.


how to delete a repository:
Deleting a complete repository is done by deleting the database
If you only want to delete a project or file use
svn delete -m "Deleting file 'yourfile'" file:///tmp/repos/test/yourfile


try and explain how to setup a svn server


resources
project home page: http://subversion.tigris.org/
ebook: http://svnbook.red-bean.com/en/1.1/ch01s05.html
cheat sheet: http://www.abbeyworkshop.com/howto/misc/svn01/

maandag 18 juni 2007

Unsuppported Class Version 49.0

I started programming Java with 1.3. Switching towards 1.4 was no problem at all. The 1.5 release at the other hand resulted in a lot of unsopperted class version exceptions.

The solution was easy, compile with -target 1.4. When I started working as a Java Developer I went through the same evolution. I started with 1.4 and bit by bit I could start using 1.5. And yes again those errors. So It's time to digg a bit deeper:

http://www.javaworld.com/javaqa/2003-05/02-qa-0523-version.html?page=1

donderdag 14 juni 2007

use http gzip compression

Looking for a way to speed up my webapps I found the following article:

http://www.onjava.com/pub/a/onjava/2003/11/19/filters.html?page=1

At first I got some nullpointer exceptions using the CacheFilter. Had to change the following line of code:

if (path!= null && path.equals("nocache")) {
chain.doFilter(request, response);
return;
}

into

if (path == null || "nocache".equals(path)) {
chain.doFilter(request, response);
return;
}

This way I avoided having this filter looking for non existing cached files when requesting the root context.

woensdag 13 juni 2007

notes java agents

resources:


debugging
http://www-128.ibm.com/developerworks/lotus/library/notes-eclipse/
http://www.domiclipse.com/frunobulax/domiclipse.nsf/pages/tut-debug-config-notes

maandag 11 juni 2007

a reusable sap pool

Through SAP JCO we can gather SAP information within Java. I'll explain the basics here while I'm revealing a library piece by piece.

SAP Connection

First we need to connect to SAP. Therefore create a connectionpool
public SAPPool(){
    // create pool
    JCO.addClientPool(
    ((String) properties.get(SAP_POOL_NAME), // Alias for this pool
    Integer.parseInt((String) properties.get(SAP_NR_CONNECTIONS)),// nr of connections
    (String) properties.get(SAP_CLIENT), // SAP client
    (String) properties.get(SAP_USERID), // userid
    (String) properties.get(SAP_PASSWORD), // password
    (String) properties.get(SAP_LANGUAGE), // language
    (String) properties.get(SAP_HOST_NAME), // host name
    (String) properties.get(SAP_SYSTEM_NUMBER) // system number
    );
    //...

Next you create a repository
    //...
    // Create a new repository
    repository = JCO.createRepository((String) properties
        .get(SAP_REPOSITORY_NAME), ((String) properties
        .get(SAP_POOL_NAME));
} //end of ctor

To reference a function through your repository
public IFunctionTemplate getSAPFunction(String functionName){
    repository.getFunctionTemplate(functionName);
}

Also you can get the client
public JCO.Client getSAPClient(){
    JCO.getClient(poolName)
}

And very important is not to forget to release it again
public void releaseClient(){
    JCO.releaseClient(client)
}


Because It's so important not to forget releasing your resources again and because of some other default handling of calling SAP functions we'll use an abstract class. Read more about my interface vs abstract class post to understand why.

What are the defaults?

get function let's do this in the ctor which takes the functionName as an argument. Also we preserve some references towards the input, output and tables parameterLists (SAPPool references to class holding the previous posted code)
public BaseSAPFunction(String functionName){
    IFunctionTemplate ftemplate = SAPPool.getSAPFunction(functionName);
    function = new JCO.Function(ftemplate);
    input = function.getImportParameterList();
    output = function.getExportParameterList();
    tables = function.getTableParameterList();
}

set input next we need to set the input parameters. In the BaseClass I did so by having an abstract method handling this. In the actual implementation the input parameterlist can be referenced. The actual implementation will follow in calling a function.
public abstract void setInput();

execute function for actual execution of function first get a client on which you can invoke the execute function like this
public void executeFunction(){
    client = SAPPool.getSAPClient();
    client.execute(function);
}

handle results this will also be abstract here because this depends on the actual implementation. Here it returns an Object for compatibility with non 1.5 code. This implies that you'll need to cast it the right way. If you can ensure you'll have only 1.5 using this library then use generics. Again the actual implementation will follow in calling a function.
public abstract Object getData();

release client is done by executing
    SAPPool.releaseClient();


All together this wil be chained in the right order with some general execute function like the following
 public Object execute() {
  setInput(); //see implementation for details
  executeFunction();
  Object obj = getData(); //see implementation for details
  SAPPool.releaseClient();
  return obj;
 }


calling a function

Now for calling a specific function I extend the previous explained BaseSAPFunction. Then I only need to make a ctor calling the super ctor with functionName as argument and implement the 2 abstract methods (and maybe some helpers). Classes using this function invoke the execute() method and cast the Object. That's it.
public class SomeSAPFunctionCall extends BaseSAPFunction{

    public SomeSAPFunctionCall(){
        super("ZBAPI_SOME_FUNCTION");
    }

    public void setInput(){
        input.setValue("fieldValue", fieldName);
        //more here
    }

    public void getData(){
        SomeDTO dto = new SomeDTO();
        JCO.table table = tables.getTable("TABLE_NAME");
        if(table != null) {
            do{
                dto.setAString(table.getString("A_STRING"));
                dto.setAnInt(table.getInt("AN_INTEGER"));
                //more here
            } while(table.nextRow());
        }
        return dto;
    }
}


usage
SomeDTO dto = (SomeDTO)new SomeSAPFunctionCall().execute();


resources

zondag 10 juni 2007

about collections, the basics

Let's talk about collections. You've got several options, only one is right.

First of all an overview of the Interfaces



Map: have key and a value. With the key the value can be looked up. These keys are unique so there is no duplication (at least not for the keys, you could insert to identical objects as long as they are stored with a different key).

You've got general Map which are not sorted, no garantee of any order. If order is needed you must look for a SortedMap implementation.

Remember that order is defined using the compareTo() method (Comparable). Custom objects need to implement this. The uniqueness is defined using the equals() method of java.lang.Object (which all objects extend). Good to know is that default implementation checks the actual instance of an object (=memory address). Override the equals() (and hashCode()) method to meet your needs. By example a user could be compared by email, etc...

When you add a custom object to a sorted collection while it doesn't implement Comparable you'll get the following error:
Exception in thread "main" java.lang.ClassCastException: NoComparable cannot be cast to java.lang.Comparable
at java.util.TreeMap.put(TreeMap.java:542)
at TestComparable.main(TestComparable.java:8)


Collection: only store values so no way to lookup. This means you would have to iterate the elements in order to find a specific one.

No keys here, uniqueness depends: Set and SortedSet can't contain duplicates, List can. The List is actually indexed, so the order is the one in which elements were added. The Set has no order what so ever, the SortedSet orders it's elements with the compareTo() method (or a given Comparator).

A note on sorting and performance: Use it only when really needed. A sorted collection has it elements sorted all the time. This means on every update (adding, removing, changing an element) the collection needs to resort and that takes some time and memory. Another solution is to use an unsorted collection and sort it only when presenting to the user.


This is only a quick start, you now only got the interfaces. You still need to find the right implementation. Look at the javadocs and don't forget that besides sun there is also the jakarta commons collections... More might follow.

interface vs abstract class

I'll keep it simple...

Interfaces should be seen as a contract, they define some method signatures which need to be implemented by any implementing class. Use Interfaces for code that can change easily.

A great example of how to use interfaces is the Strategy Pattern (PDF). Follow the link for a detailed description and example. In general the strategy pattern provides an easy way to implement different strategies (logics) for achieving your goal. On top there is an interface.

Another example of interfaces are the collections In fact it's a good practice to use these interfaces in your method signatures, this improves the flexibility of your code. You can then easily switch collection implementation. Example:

private List list = new ArrayList();

public List getList(){
return list;
}
public void setList(List list){
this.list = list;
}


Abstract classes can also oblige an extending class to implement some methods. The difference is that an abstract class can do more. You can add completed methods, fields, ... So an abstract class can provide general implementation, defaults and a contract for some other methods of which the logic will be defined in subclasses.

Don't forget!

zaterdag 9 juni 2007

jakarta commons

The jakarta commons project is a great example of reusability. It's a collection of utilities that can be used independently. The only problem is a lack of documentation. There are some books available. I'll look into these as soon as possible (just ordered a copy of the jakarta commons cookbook, ISBN:059600706X).

Some I used so far are:
commons.lang.StringUtils
commons.lang.builder.*
commons.collections.CollectionUtils
commons.collections.Transformer


...

For anyone who wants to get involved:
http://jakarta.apache.org/commons/volunteering.html

resources:
http://www.onjava.com/pub/a/onjava/2003/06/25/commons.html
http://jakarta.apache.org/commons/
http://www.javaworld.com/javaworld/jw-07-2005/jw-0725-chain.html
http://www.javaworld.com/javaworld/jw-10-2002/jw-1025-opensourceprofile.html

I recently wrote some code to convert time from the HH:mm notation towards decimal notation and vice versa, could it be done with commons and if not see for submitting code.


What about some tool to query javadoc in order to find commons code quickly?

donderdag 7 juni 2007

my java resources

The following is a list of my freguently used java resources, I might keep this up to date.

If anyone has more resources please let me know!

client side validation

I was looking for a good validation framework. Some options:

I eventually used jsVal. The inline form initialisation is very easy in use. Regex are supported and some specific validations can be done with callback functions.

Errorfields are marked by defining a css class. Besides that a popup shows a more informative message. These can be translated using javascript.

Custom validation messages can be defined using the err="your message" attribute. Only works in validateStandard() mode. The validateCompleteForm() mode in which all fields are validation in once seems to ignore these personal messages.

When using callback you need to set required="1".

I used a little trick to validate multiple fields (like compare a to be) by adding an onclick="return moreValidation()" event to the submit button.

To end this post an article about a more complex solution. Uses server side validation icw ajax to simulate (towards user) client side validation.

woensdag 6 juni 2007

fn:replace carriage return with br

So I have a String that needs to be passed through as a javascript method argument. Problem is this String is user input and therefore can contain newlines so code can be scattered over multiple lines resulting in js syntax errors, example:


functionName("a correct string argument","this one is
scattered over multiple lines and therefore generates js syntax errors");


Easy, lets replace these newlines with the fn:replace tag... Didn't turn out to be so simple at all, "\\\r\\\n" is not accepted with jstl. Read the following threads for some suggestions:

http://forum.java.sun.com/thread.jspa?threadID=614154&messageID=3427211

http://mail-archives.apache.org/mod_mbox/jakarta-taglibs-user/200404.mbox/%3c20040413170630.M35388@pdragon.net%3e

Important! In case of just formatting (not syntax problem like me) you can always use <pre> + css

Eventually I just created an extra getter in my model returning the corrected string, if you don't know how to do this see:

http://www.rgagnon.com/javadetails/java-0454.html


When always running on the same system you can also use System.getProperty("line.separator") in your replace.


about spring SimpleFormController

When extending the SimpleFormController you might need some referenceData to be available after submitting the form. For example usefull when formView and successView are equal. This can be achieved by overriding the


/**
* On form submission redisplay the form.
*/
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response,
Object command,
BindException errors) throws Exception {
//TODO handle your command here
//return to formView (so referenceData is still present)
return showForm(request, response, errors);
}


(my tiny thread on this: http://forum.springframework.org/showthread.php?p=123407)


And to finish this post, you might need a collection as command object. In that case you'll need a wrapper class because collections are not supported by default. Example for list:


/**
* Helper class to use a list as spring command object. By default this is not
* supported so need to use this wrapper class in order to have indexed access
* to list.
*
* @author Hans Cappelle
*
*/
public class ListWrapper {

/**
* The actual list to perform actions on
*/
List list = new ArrayList();

/**
* def ctor
*
*/
public ListWrapper() {

}

public ListWrapper(List list) {
this.list = list;
}

// setters & getters

public List getList() {
return list;
}

public void setList(List list) {
this.list = list;
}

}


review generics and see if this can be applied to this wrapper

yes I use firefox, my plugins

I use firefox for developping webclient frontends. That's why:

  • I can change my css file on the fly and see what happens in browser with EditCSS

  • Well the users will most likely use IE instead so make sure to test your desing in IE as well. Wouldn't it be extremely usefull if I could check this with firefox... check IETab.

  • HTML that looks the same in all browsers starts with valid HTML (and ends with IE :-)). So validate your pages with HTMLValidator.

  • What color is that, wait I have a colorpicker called ColorZilla.

  • You can even measure the dimensions of your elements in pixels (without looking at your source) with MeasureIt.

  • And while using firefox make sure to report any relevant bugs with the TalkBack plugin (that's installed by default I guess).

  • Don't forget performance, well that's not really frontend but I can check it in my firefox client with FasterFox.

  • Javascripts can be so annoying, I use the Javascript Debugger if I'm really lost.

  • Linkchecker, what's in a name?

  • The DOM Inspector I don't really use a lot but I can imagine this being very handy for some people among us (comes with firefox).

note 1 : For the lazy ones there's also a complete (much more than I need so I don't use it) plugin at http://chrispederick.com/work/webdeveloper/


note 2 : and I'm not the only one, so check this google result.


note 3 : I can't access the actual mozilla addons page here so links might be broken, let me know.


Some shortcuts I often use are:

  • CTRL + D : bookmark

  • CTRL + J : downloads

  • CTRL + TAB : travel tabs

  • CTRL + T : new tab

  • CTRL + N : new window

  • CTRL + U : page source

  • CTRL + L : addressbar
complete list:
firefox cheat sheet

GUI's should be simple, attractive and user friendly

Ok I'm a programmer and graphical design is just not my thing. But that doesn't mean my applications don't need an appealing frontend.

So let's see what I do to present my applications without shame. Any comments are more then welcome I'm here to log my solutions and to learn from people reading them.

I'm going to explain my methods for graphical design of web applications. Mostly HTML, CSS and a bit of javascripting. Swing is been to long to log any information on that.

technical


It's important to seperate your view (fronted) from the logic and backend. The same way you should seperate your styling from the presentation. Meaning you'll be writing plain HTML and add a reference to your external css file. This way you can simply change the look'n feel, make several themes, ...

usability


Don't forget about usability, make your applicatons available to everyone. Meaning you'll have to provide the alt attribute for your img tag, title for a tags, ...

More in general it's always good to know where you are so make a crumbtrail on your page. This is easily automated by letting a tokenizer play with your request url.

Read more about usability, I'm no expert.

html/css


div vs table


You'll need a gross layout first. Sketch some sections like header, menu, content, footer, crumbtrail, ... on your page and translate these to HTML using div elements with an id. Don't use tables for this. Tables are ment for listing data in... tables indeed. Not for positioning.

A simple position is the header on top, a menu on the left (and another on the right?), your content in the middle and a footer to end your page with.

By putting al these elements in a container div you can set a width for your website or some other general stuff (no need to change body for that).

You might want to refer to the strict doctype for better support on different browsers.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<div id="container">
    <div id="header">header</div>
    <div id="leftmenu">leftmenu</div>
    <div id="rightmenu">rightmenu</div>
    <div id="content">contentv/div>
    <div id="footer">footer</div>
</div>
</body>
</html>


For the css try the editCSS firefox plugin so you can give this website a rocking layout. Also read my blog about colors to get a cool colorscheme.

You can get some dummy text for visualising your pages at http://www.lipsum.com/.


Referring to the div elements is done with the id css selector shown below. I'll only give you some positioning css and borders so you can see you don't need any tables. Colors and an actual design is up to you. You might want some inspiration.

All I do is giving the leftmenu a width and float it to the left. Same for the right menu, only float to the right this time :-). Don't forget the clear property on your footer! This will make your footer appear at the bottom of these two vertical bars. Now the content div is still in the way of your menus. Give this one a left and right margin equal to the sizes of these menus to fix that (I actually added some more for some spacing).

#header{
    height:80px;
    border:solid 1px blue;
}
#leftmenu {
    width:200px;
    float:left;
    border:solid 1px red;
}
#rightmenu {
    width:200px;
    float:right;
    border:solid 1px green;
}
#content{
    margin:0px 210px 0px 210px;
}
#footer{
    clear:both;
    height:20px;
}


Read some css and maybe html tutorials when you don't understand this code.

sliding doors


Google on the sliding doors effect. It's way more advanced than this but I wanted to mention it anyway.

javascripting


Javascripting became very popular together with the rich web clients. Currently Java is even looking to include a javascript compiler with their jre.

nifty corners


When only using css and html you get a very rectangle design. You can always add background images and play with it using css, but that's not the simple way I'm looking for. It's easier to round some corners by using the nifty corners library.

Nifty("div#box","big");


prototype


Some common functions to ease javascripting can be found in the prototype library. More information here. Don't confuse this with the prototype object.

scriptaculuous


Scriptaculuous (note the uber url) takes prototype to the next level. You can add many dynamic effects to your website this way.

ajax


Google is all over it, check gmail, calendar and many more. For websites you always perform a get of your page, maybe a post of your form input and then again a get. Several requests are needed. And a request means a refresh of your page content. AJAX hides these requests for the user by posting data and updating the page with the requested content using javascripting on the background. While loading the data very typical ajax please wait images are shown.

The prototype has some very easy functions to perform these ajax submits. Read all about it here.

graphics


I use graphics for icons mostly.

JPG vs GIF


GIF images have an indexed, fixed number of colors. 16, 32, 64... maybe 256 colors but that's it. GIF images are used for small icons, backgrounds with little detail, ... Don't use a GIF for your self portrait. Pictures need a lot more colors so you'll need to make JPG pictures of it. For online take a good compression rate of about 65%. For archiving on your local computer (I don't recommend JPG but if you have to) take a higher rate like 85% (good balance). Make sure you leave a copy of the original picture. Anytime you save your JPG you will loose data, even when you save it with the same compression (or even higher) rate.

paint.net


Don't compare Paint.net with the cripple paint you get with windows. First of all Paint.net is free :-). It can work with layers, has gradient, ...