23. dec. 2004

ONJava.com: The Hidden Gems of Jakarta Commons

The Hidden Gems of Jakarta Commons
If you are not familiar with the Jakarta Commons, you have likely reinvented a few wheels.

Before you write any more generic frameworks or utilities, grok the Commons. It will save you serious time. Too many people write a StringUtils class that duplicates methods available in.
This article gives some examples and tips.

21. dec. 2004

TheServerSide.com - Struts Live Chapter: Nested POJOs

The new chapter will include a solution to one of the most frequently heard complaints about Struts: that it doesn't provide a simple way to meaningfully nest POJO graphs in ActionForms. The provided example code solves this problem and includes an integrated solution for automating conversion, formatting, and validation.

Read the article in PDF here:Struts Live Chapter: Nested POJOs.

20. dec. 2004

Yet Another Servlet Filter You Can't Live Without - Cache control

The Cubicle Jockey: Yet Another Servlet Filter You Can't Live Without
At work, we were looking for ways to reduce bandwidth usage on our secure applications. We already have the compression filter, various object caches, etc-- everything you read about. Then we started looking into caveats with using SSL and found something surprising-- HTTP 1.1 SSL usage prevents ANY content from being cached on the user's drive. "So you mean those massive JavaScript and Stylesheet files are getting pulled down with each secure page?" Yes, images too-- multiple times on a single page even.

The solution? Yet another Servlet Filter you can't live without that will be bound to your static content such as Javascript, CSS, and image files. The code for the filter is only a couple lines, but the goal is to write out the 'Cache-Control' header and the 'Expires' header.

long durationSeconds = 28800; // 8 hours
response.setDateHeader("Expires",
System.currentTimeMillis()
+ (duractionSeconds * 1000));
response.setHeader("Cache-Control",
"public, max-age="
+ durationSeconds);
chain.doFilter(request, response);


I couldn't believe how much bandwidth we are now saving with our SSL applications.

Read more here.

Write custom appenders for log4j

Write custom appenders for log4j.
Extend log4j to support lightweight over-the-network logging.

The Apache Software Foundation's log4j logging library is one of the better logging systems around. It's both easier to use and more flexible than Java's built-in logging system. This article shows you how to extend log4j with a custom "appender," the part of the system that actually writes the logging messages. This article also provides a simple example of Java's socket APIs and multithreading capabilities.

1. dec. 2004

Unit Testing with Mock Objects : What are Mock Objects?

Unit Testing with Mock Objects : Shine Technologies.
This page and its children talk about unit testing with the Mock Objects pattern. In particular, it covers what Mock Objects are, what tools the author (Ben Teese) have used, and important lessons he has learnt along the way.


The pages is about:

  • What Are Mock Objects?
  • DynaMock - A Mock Object Testing Framework
  • Experiences With Mock Objects
  • Conclusions on Unit Testing with Mock Objects

26. nov. 2004

Usable GUI Design: A Quick Guide

In Usable GUI Design: A Quick Guide, the author has 5 points in writing good GUI's.
It's supplemented with good examples.

The points:

  1. The user is not using your application

  2. The most basic point in all computer UI design is that the user does not want to use your application. They want to get their work done as quickly and easily as possible, and the application is simply a tool aiding that.

  3. Fitt's Law

  4. This is the most basic and well known of UI design laws. It states that the larger and nearer to the mouse pointer an on-screen object is, the easier it is to click on. That's common sense, yet it is often completely ignored in UI design.

  5. Unnecessary interference

  6. When a user is working, their attention is on the work they are doing. Every time they have to move their attention away from their work to the application, it takes time for them to get back to where they were in their work. Therefore, you should minimise the amount of distraction and interference your application gives the user. Every application has an item that is its key focus ? in a text editor, it's the text; in a web browser, it's the web page ? so make that central to your interface.

  7. Use the power of the computer

  8. Computers are powerful things these days, with billions of processor cycles per second and hundreds of gigabytes of storage available. Humans, however, haven't changed that much in hundreds of years. We still get tired, bored or distracted and have a limited amount of mental energy available at any one time. It would seem a good idea, therefore, to shift as much work as possible off the poor, worn out human and on to the untiring, super fast computer in front of them.

  9. Make items easy to distinguish and find

  10. This point is pretty simple: items on the screen that do different things should be easy to see and differentiate from each other.

New Community: community.java.net - Portlet

New Community: community.java.net - Portlet.
If J2EE based portals, JSR 168 or WSRP mean anything to you, you have come to the right place. This is a gathering of developers and technical experts working on Portals and related technologies. Here you will find open source projects, articles, tips, news, product announcements, blogs and FAQs. This community is also dedicated to creating a repository of open source and free JSR 168 compliant portlets that can be used on any J2EE portal server available in the market today. This is a great place to obtain portlets, learn, discuss, share knowledge and publicize your work.

25. nov. 2004

AOP: Aspect Oriented Programming - Introduction

AOP (Aspect oriented Programming) enables clean modularization of crosscutting concerns, such as error checking and handling, synchronization, context-sensitive behavior, performance optimizations, monitoring and logging, debugging support, and multi-object protocols


When Object-Oriented (OO) programming entered the mainstream of software development, it had a dramatic effect on how software was developed. Developers could visualize systems as groups of entities and the interaction between those entities, which allowed them to tackle larger, more complicated systems and develop them in less time than ever before. The only problem with OO programming is that it is essentially static, and a change in requirements can have a profound impact on development timelines.

Aspect-Oriented Programming (AOP) complements OO programming by allowing the developer to dynamically modify the static OO model to create a system that can grow to meet new requirements. Just as objects in the real world can change their states during their lifecycles, an application can adopt new characteristics as it develops.

References:

24. nov. 2004

Animation: Totally Gridbag - Fun animation about java gridbags

madbean.com: Totally Gridbag
A fun day of coding with gridbags.

This is a funny animation about a man coding gridbaglayout.

Windows Tips & tricks: Defragmenting Your Pagefile

WindowsDevCenter.com: Defragmenting Your Pagefile: "Defragmenting your hard drive regularly is an important part of general system maintenance for Windows XP machines, and the Disk Defragmenter tool in Computer Management lets you do this easily. (You can also get to the Disk Defragmenter tool by choosing Control Panel-->Performance and Maintenance-->Rearrange items on your hard disk to make programs run faster.) But what about defragmenting your pagefile?"
This article tells you how.

The way to do it, is by removing your pagefile, defragment your hardisk, and then add the pagefile again.

Link: Effective Java - Tips & tricks - What about equals()?

Effective Java: "Joshua Bloch's book Effective Java Programming Language Guide" is about tips and tricks about java.


This book i really recommend.

The only thing is, that the implementation of equals should be made different.

In stead of:

public boolean equals(Object o) {
if (! (o instanceof MyObject)) {
return false;
}
MyObject other = (MyObject) o;
return (value == null ? other.value == null :
value.equals(other.value));
}


Use:

public boolean equals(Object o) {
if ((o == null) || (this.getClass() != o.getClass())) {
return false;
}
MyObject other = (MyObject) o;
return (value == null ? other.value == null :
value.equals(other.value));
}


The reason to use getClass() instead of instanceof, is the problem when you have inheritance.
The equals must be symmetric, which means if a.equals(b) then b.equals(c) must be true.

Example:

... Class A...
public boolean equalsFalse(Object o) {
if (! (o instanceof A)) {
return false;
}
...
}
}


... Class B extends A...
public boolean equalsFalse(Object o) {
if (! (o instanceof B)) {
return false;
}
...
}
}


In this case this would happen:

A a = new A();
B b = new B();

a.equals(b); <- would return true
b.equals(a); <- would return false


If you use getClass() you will instead get:

a.equals(b); <- would return false
b.equals(a); <- would return false.
Which means the symmetric isn't broke!



I've made some tests that shows that getClass() takes about 7% longer time to evaluate than instanceof.
But this is a price I would like to pay to be sure that I don't have any problems with inheritance.

Link: Sikkerhedsforum.dk :: Security debate (danish website)

Security debate in danish.
Sikkerhedsforum.dk :: Seriøs debat om sikkerhed.

Download: Check your computer for security-leaks (remote-exploit.org)

At remote-exploit.org you can download a Cd with an Auditor security collection which contains a bootable Linux distribution and has many programs to test Foot-printing, analysis, scanning, wireless, brute-forcing and cracking.

Download the CD here: http://www.remote-exploit.org/content/mirrors.html

22. nov. 2004

Trace SQL: SQL Logging and tracing.

IronGrid - home_page: "IronEye SQL is the first step in troubleshooting JDBC performance problems. An ideal introduction to performance testing, this intuitive tool monitors the time it takes for SQL queries to pass between a Java application and the database without changing any source code."

MacDevCenter.com: Write a Webserver in 100 Lines of Code or Less

Write a Webserver in 100 Lines of Code or Less by Jonathan Johnson -- REAL Software programmer and tester, Jonathan Johnson, shows you the power and simplicity of developing with REALbasic by walking you through the building of a working webserver. After this tutorial, you'll not only have a pratical knowledge or REALbasic, but you'll have a cool little server too.


(The Response header: HTTP_VERSION + Space + STATUS + Space + MESSAGE + CRLF + CRLF.
Ex.: Write "HTTP/1.1 " + format( statusCode, "000" ) + " " + _
response + chr(13) + chr(10) + chr(13) + chr(10))

18. nov. 2004

Blog of Anders Holmbech Brandt

My blogs: "Blog of Anders Holmbech Brandt".

Anders is freelance consultant and are currently hired though ProData to work for TDC Kabel TV.

xHTML/stylesheet generation slideshow like powerpoint

S5: An Introduction.
xHTML/stylesheet generation slideshow like powerpoint.

Works with all browsers.

16. nov. 2004

Techworld.com - What is encryption?

Techworld.com - What is encryption?: "What is encryption?
What's the difference between a cipher and a code? Encryption schemes explained."