Delegates versus inner classes
August 14, 2006 on 8:35 pm | In Java | Add a commentThis whitepaper compares the use of delegates versus inner classes, and outlines the reasons why delegates are not implemented in the Java language.
Interestingly, the decision was largely influenced by Delphi Object Pascal.
Related Posts:
- How to identify and fix an anemic domain model
- How to Use JPOX in NetBeans 4.0
- How to Format Dates for SQL in Java
- Exception handling or result code
Choosing the Best Tool for the Job
August 2, 2006 on 10:41 am | In General, Java | Add a commentKathy Sierra wrote an interesting entry on her Creating Passionate Users blog about how the “right tool” is not always the “best tool” for the job. According to her, one factor that is not to be neglected is the level of enthusiasm for using the tool, which can sometimes be even more important than the perceived appropriateness of it. Of the three main considerations (appropriateness, expertise and enthusiasm), expertise remains essential nonetheless.
I mostly agree with her opinion that the urge to learn a tool often creates enthusiasm and drives productivity upward. However, this holds true only if the users are capable and learn efficiently. If that is not the case, there is a risk that projects get delayed as users struggle with the tool. In most cases, seasoned developers can apply their past experiences to quickly become efficient with new tools. And, driven by enthusiasm, they become highly productive.
Technorati Tags: software, development, project, tool, enthusiasm
Related Posts:
- Beagle Dynamic Desktop Search Tool
- Boot Camp for Mac OS X on Intel-based Macs
- Domain-Driven Design, the quest for software perfection
- Three weeks with a MacBook Pro laptop
How to Parse Dates from Strings
July 22, 2006 on 9:44 am | In Java | 5 commentsThis example shows how to parse dates from strings using the
SimpleDateFormat class.
The pattern is specified in the constructor, but could also be done with the applyPattern(String pattern) method.
import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class TestDate {
public static void main(String[] args) throws ParseException {
String s = "15-05-2005 5:55:55";
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
Date date = df.parse(s);
System.out.println(date);
}
}
This example should help ease the difficulty that all beginners seem to face when dealing with formatting
dates in Java.
Technorati Tags: Java, Programming
Related Posts:
- How to Format Dates for SQL in Java
- Validating a Date Field with RIFE
- Copy/paste command-line utilities
- Using Apache Axis in NetBeans 5.0
Robust Java Exception Handling
July 20, 2006 on 1:03 pm | In Java | 2 commentsHoa Dang Nguyen and Magnar Sveen published a very interesting paper on building robust Java applications by correctly applying exception handling. They explain how exceptions work in Java, when and how to use them, and provide sample source code to demonstrate their recommendations.
In the past, I have written about exception handling best practice and EJB exception handling.
Technorati Tags: Java
Related Posts:
- How to Handle Exceptions in EJB
- Exception handling or result code
- EJB Exception Handling
- BerkeleyDB database
Java Development on Mac OS X
July 20, 2006 on 10:30 am | In Java, Apple | Add a commentIf you are considering a move to the Mac for your Java development needs, then this comparison of Java development on different platforms is just for you.
Interestingly, it claims that Windows XP runs faster than Mac OS X on the new Intel-based Mac.
Technorati Tags: apple, mac+os+x, java, programming, benchmark
Related Posts:
- Three weeks with a MacBook Pro laptop
- Boot Camp for Mac OS X on Intel-based Macs
- Apple computers equipped with the Intel processor in 2006
- Linux will not displace Windows so soon
Using Decorator Pattern with Templates in RIFE
June 18, 2006 on 10:48 pm | In Java | Add a commentI have been playing with “RIFE”:http://www.rifers.org during my spare time a lot lately. I’m refactoring the code of one of my applications to use the “Decorator design pattern”:http://en.wikipedia.org/wiki/Decorator_pattern on RIFE templates. Watch this space for an example of how templates are decorated.
Technorati Tags: Java, RIFE, framework
Related Posts:
- Developing web applications with RIFE
- RIFE web framework
- Refactoring by Renaming in Visual Studio .NET 2005
- How to Parse Dates from Strings
Validating a Date Field with RIFE
June 7, 2006 on 9:28 pm | In Java | Add a commentHere is a quick way to validate a multi-part date field in RIFE. By “multi-part field”, I mean one that is made of several fields, in this particular case, a date field, a month field and a year field.
This is best done by creating a bean to hold the input data. Say, we are creating a form to schedule a task. The required input are:
* title
* description
* due date
The TaskBean will be as follows:
public class TaskBean extends Validation {
private String title;
private String description;
private int[] dueDate;
//... accessor methods
public void activateValidation() {
addConstraint(new ConstrainedProperty("title").notNull(true).notEmpty(true));
addRule(new AbstractValidationRule() {
public boolean validate() {
boolean validated = true;
int day = dueDate[0], month = dueDate[1], year = dueDate[2];
//... validate field components
return validated;
}
public ValidationError getError() {
return new ValidationError("INVALID_DATE", "dueDate");
}
});
}
}
The gist of the solution here is the addRule method of Validation subclass. It adds a new AbstractValidationRule that contains a method for validating a given input (in this case, the due date) and returning any found error.
Related Posts:
- How to Format Dates for SQL in Java
- Rapid web development
- How to use multiple triggers in RIFE
- Arbitrary sort of selection options
How to Activate the Contextual Menu in NetBeans for Mac OS X
May 30, 2006 on 9:24 pm | In Java | Add a commentIf you are like me, you probably enjoy writing Java code in NetBeans under Mac OS X on your Apple laptop but curse the lack of a second trackpad button. Thankfully, there is another way to call the contextual menu. Here is how it is done.
- Open NetBeans IDE
- Open Preferences…
- Select Keymap
- Expand Other
- Select Popup
- Click on Add…
- Specify a key combination (I find Cmd + Opt + / to be most appropriate)
Technorati Tags: NetBeans, Mac OS X, Programming, Java, Tip
Related Posts:
- How to Develop JSF Applications in NetBeans
- Spotlight search dialog fails to display
- Koders Code Search
- Essential Software for Mac OS X
How to use multiple triggers in RIFE
March 6, 2006 on 7:37 am | In Java | Add a commentRIFE has a concept of inheritance whereby an element (or controller) inherits the behaviour of another. This comes in handy when certain actions need to be performed before the requested element is executed, for example, password protected pages that are accessible only if the user is authenticated.
<element id="ProtectedPage" implementation="example.ProtectedPage" inherits="Login">
...
</element>
To support inheritance, RIFE provides child triggers, which are inputs or cookies. Those are checked by the engine to determine whether a child element can be executed or not based on some business logic. Child triggers are defined in the structure of the inherited element.
<element id="Login" implementation="example.Login">
<childtrigger name="authid" />
</element>
In the above example, authid is declared as the child trigger. The implementation, *example.Login*, needs to contain the childTriggered(String name, String[] values) method which is called automatically to determine the child element should be executed or not.
boolean childTriggered(String name, String[] values) {
if ("authid".equals(name) && values[0] != null) return true;
return false;
}
As can be seen, the developer is responsible for checking what child trigger is being passed. Also, raw access to the element context information is prohibited within this method since the developer could otherwise corrupt the execution flow along the inheritance path. Also, childTriggered is called separately for each child trigger.
Multiple child triggers can be declared for an inherited element. If the check depends on each one separately, it is straightforward to implement childTriggered. However, if the check involves a combination of those, for example, if a cookie value needs to be validated against a query string parameter, the task becomes slightly more complicated.
To cater cases such as the latter one, the order of declaration of child triggers in the element structure becomes important. Say, one has to implement the hypothetical scenario as above.
<element id="Login" implementation="example.Login">
<childtrigger name="username" />
<childtrigger name="authid" />
</element>
Here, the username cookie value needs to match that in the current session identified by authid. However, since the engine calls childTriggered separately for each child trigger, the outcome of processing username needs to be retained until authid has been processed.
The engine, by default, executes a child element if childTriggered returns true for at least one of the child triggers. The trick is to order the declarations of those in the same order as you wish them to be processed and NOT to return true until the last trigger is.
This is possible by using a field of the element class to store a value that is used by the two childTriggered calls. The code for given example could be like this:
boolean childTriggered(String name, String[] values) {
if ("username".equals(name)) {
this.username = values[0];
}
if ("authid".equals(name) && values[0] != null) {
if (getUsernameFor(values[0]).equals(this.username))
return true;
}
return false;
}
RIFE element inheritance removes the burden of implementing this kind of security checks from the developer. It also makes the code cleaner because one does not have to write the logic in each element, which would otherwise result in a complex [Java] inheritance hierarchy.
Related Posts:
Developing web applications with RIFE
February 19, 2006 on 2:41 am | In Java | 3 comments
I am using a little-known, yet very powerful, framework called RIFE. I discovered it when I came across a heated discussion between Geert Bevin, the author of the framework, and the Ruby on Rails camp.
What I like most about RIFE is the separation between presentation and logic, and the ease with which raw HTML code can be manipulated using Java code. This provides the foundation for creating visual components with little difficulty.
Templates are simple HTML files interspersed with RIFE tags. There are only four tags: the placeholder (or value) tag V marks a location on a page where content can be inserted; the block tag B marks a region of contents that can be manipulated as a unit; the directive tag I allows inclusion of templates; and, the default block tag BV identifies a block of content as the default one to be rendered at a placeholder location. Any HTML code enclosed within any of these tags can be manipulated by code, which allows for interesting effects. For example, a block of text can be marked as an error message and displayed at a specific location whenever that error occurs; similarly, one of several blocks of text in different languages can be displayed according to the user’s chosen locale. As would be expected, the RIFE framework already provides such pre-built components.
The ease of developing components in this way puts RIFE ahead of most other frameworks. In JSF, for example, visual elements are rendered by Java code, which is a rather un-natural way of developing web pages; in RIFE, visual elements are created with raw HTML code, and are interspersed with the template tags so that they can be manipulated by a backing Java class.
However, RIFE has much more to offer: a persistence subsystem, a CRUD rapid application development module, automatic validation, etc. But, perhaps even more important, RIFE has a dedicated community that is constantly growing as new users realise the productivity gains to be derived from the framewok. Geert Bevin is very active in the community, always taking time to listen to his users’ suggestions and help them. With so many web frameworks available nowadays, all following the same principles, RIFE comes as a breath of fresh air.
Related Posts:
- Using Decorator Pattern with Templates in RIFE
- wxPython on Panther
- RIFE web framework
- Validating a Date Field with RIFE
— Next Page »
Powered by blog.mu with Pool theme design by Borja Fernandez.

