Posts in the “java” category

JSF error - Why your JSF error message might not be displayed

Using JavaServer Faces (JSF), if you can't see the error message (FacesError) you're creating in your controller/handler when you forward to a new JSP (JavaServer Page), the problem may be that you have a "redirect" tag in your faces-config.xml file.

For example, the following JSF faces-config.xml example shows the problem, where I do have a redirect tag when I bounce control back to the login.jsp page:

Spring Dao - a Spring JDBC update example

Spring JDBC FAQ: Can you provide an example of a SQL UPDATE query used with Spring JDBC, i.e., Spring Dao class and methods?

Here's some example Java code from a Spring Dao class where I use Spring JDBC and the JDBCTemplate update method to run a SQL UPDATE statement. In short, if you can get access to the Spring JDBCTemplate, this code shows a simple example of how to execute a SQL UPDATE statement.

Free Java and OOP training material (pdf)

Several years ago I taught classes on Java programming and Object-Oriented Analysis and Design (OOA/OOD). After using Java training material from other companies for a little while (and being unhappy with their quality and high fees), I decided to write my own Java course material.

Today I'm glad to announce that I'm giving this Java and OOA/OOD training material (150+ pages) away for free -- no registration required. (I always hate it when I have to "register" to get something free, so you'll find no registration forms here.)

Java Store update

After seeing some ads for the Java Store on this website, I just read up on it again, and it sounds pretty interesting. The Java Store is currently in a beta program state ... hmm, I just finished poking around, and I can't find any information on when they intend to go from a Beta to a Live state, but after seeing the ads here, I'm wondering how close they are to going live.

A Log4J format example

Log4J formatting FAQ: Can you share a Log4J output/logging format example?

Sure. I'll share a Java Log4J format example that I'm pretty happy with.

I've used the following Log4J logging format quite a bit lately, as I've been working on a headless Java app that can be deployed on thousands of computers, and I was looking for a good Log4J format that was easily readable by humans, and also easy to parse by computers. Here's what my Log4J output format look like these days:

Java int - How do I add two integers?

Java integer FAQ: How do I add two Java integers (Java int fields)?

Answer: Just use the Java addition operator, the plus sign (+), to add two integers together.

Here's a quick example: If you have to drive 23 miles east, then 14 miles north, what is the total distance you had to drive?

Java int FAQ - How to multiply two integers

Java FAQ: How do I multiple two integers (int) in Java?

Here's a quick example:

int i = 3;
int j = 4;
int k = i * j;
System.out.println("k = " + k);

The value of k here will be 12.

Java String to float conversion example

Java String to float FAQ: How do I convert a Java String to a Java float?

Answer: Here's an example that demonstrates how to convert a Java String to a float value. This example code segment converts the String "100.00" to a Java float:

Java number formatting - how to format Java numbers

Java number formatting FAQ: How do I format numbers for output on reports in Java programs?

Generally speaking you want to use the Java NumberFormat class and its descendants, such as the Java DecimalFormat class.

Quoting the API documentation, the Java DecimalFormat class "also supports different kinds of numbers, including integers (123), fixed-point numbers (123.4), scientific notation (1.23E4), percentages (12%), and currency amounts ($123). All of these can be localized."

Enable Java assertions (public service reminder)

Enable Java assertions tip: The main thing to remember is that assertions -- new to Java 1.4 -- are not enabled by default. That's true when compiling, and also when running your program.

When compiling your code with javac, you need to compile your source code using the "-source 1.4" option. Then, when running your program you need to specify the "-ea" of the java or javaw command to enable assertions.

Java URL example - A Java class to download and parse URL contents

Java URL download FAQ: Can you share some source code for a Java URL example, specifically a Java class to download and parse the contents of a URL?

This example is a little weak, but it's a program that downloads and parses the contents of a given URL. The purpose has nothing to do with URLs ... it has a lot more to do with the parsing that I am trying to achieve. The parsing code is actually going to be used in an anti-spam program that I am working on.

Java spell checking with Jazzy (test #1)

Java spell checking FAQ: Can you share some source code for a Java spell checking example?

Here is the source code for my first test program with Jazzy, a Java spell checking tool. This is taken straight from one of the example programs distributed with Jazzy.

Java spell checking with Jazzy

Here's the source code for this first Jazzy Java spell checking example:

Java performance-related URLs

Just cleaning off an old PC that I used to use, and I find these URLs that some of our developers put together for an old "Java Performance Tuning" seminar: