Monday, December 04, 2006

How to force decimal separator char upon java region code?

Java application could be run on any compliant platform. And that's great. But, when you provide it to your customer, you don't know the region code of his server. For exemple, you don't know if is configured to work in english or french.

By the way, let's take the previous example. In franch, decimal separator char is ',' (comma). In english, it is '.' (dot). When prensenting data to end user, you probably want to ensure that the decimal separator char is the right. So, you can for it usiing DecimalFormat.

Let's see it in the following code :

public class AfficheurDecimal {

public AfficheurDecimal() {

private void testerReste(double reste) {
if (reste != 0) {
DecimalFormat formatEntier = new DecimalFormat("0.00");
DecimalFormatSymbols symbols = formatEntier.getDecimalFormatSymbols();
String msg = "Il reste " + formatEntier.format(reste) + " à ventiler";
if (reste == 0) {
System.out.println("Pas de reste");

* Auteur : a.depellegrin

* Définition :

* @param args
public static void main(String[] args) {
new AfficheurDecimal();


That's all!

Monday, November 13, 2006

Multibase application could be like in the song : it's just an illusion

Today, my friend and excellent architect Marc Godin told me something very interesting that sumarize an illusion that java introduced with its virtual machine. He said :

"L'adhérence a la base de donnée est à acter comme celle à la JVM"

Sorry, it's in french. BTW, the text tells that you had to choose your database as you chose you JVM.

Tuesday, October 31, 2006

Why primitive types are unprecises? the unacceptable explaination...

Another excellent article by Brian Goetz on numerical java data type storing. It's just a question of IEEE 754. So, don't expect to work with primitive types in Java for finacial applications. Such a pity! My old Casio FX-7000 is more powerfull than my computer.

Financial programs represents a major part of softwares all over the world. If you want my opinion, its unacceptable to have to work with wrapped types!!!

James Goslin, any solution? You're welcome if you have one.

Friday, October 27, 2006

Open ESB

Great news,

I just learnt that Sun launched an open source ESB project with a tool suite for NetBeans. This fact of having developped graphical tools to design processes and mappings is a very (VERY) important point in my point of view. Something tells me that, if the product is well done, the situation will be harder for webMethods in several months.

I will publish my Violet UML Editor as quickly as possible to investigate on it.

Thursday, October 12, 2006

Searching files on unix

Want to find files and perform massives operations on them, here are tws sample commands for unix platforms :

find -name "[filename]"

find -name "[filename]" -exec [command] '{}' \;

where [filename] and [command] should be replaced by real values. [command] is another unix command to execute on each file found. The file found is represented by '{}' in the command to execute. \; indicates to end of the command.

Ex : find -name "*.tmp" -exec rm '{}' \; -> deletes all tmp files.

Thursday, October 05, 2006

CVS activity : extract history for a user and from a date

cvs -d :pserver:[user]@[server]:/[repository] log -d ">2006-09-28" -w[user]

[user] is the username
[server] your server location
[repository] the CVS repositpry url

Of course, don't forget to change the date!

Monday, October 02, 2006

Hibernate 3 and Oracle 9i cursors : how does it work?

Here is a post I found on the hibernate forum. It explains why cursors opened are not released on session.close() :

OK. Here's the result of this thread:

For the environment, JDK1.4.2_01, Oracle 9i server, oracle 9i jdbc driver (ojdbc14.jar) and oci connection to the database (not thin driver);

There's no problem with hibernate's prep stmt cache nor with Oracle Jdbc driver with regard to cursors remaining open after Session.close().

Every Session.iterate() and Session.load() calls cause a prep stmt to be created on the server side. And after you close the session with Session.close(), hibernate explicitly calls appropriate driver methods to close the resultsets and prepared statements.

However, after you close the session, you won't see the cursors de-allocated (or closed) on the server side. While it seems to be a bug, it actually is not. The driver maintains a list of prep statements and open cursors in its memory and as soon as you re-use the same connection by opening a session on that very same connection, you'll see that the previous cursors and prep statements will go away.

To check this behaviour, open a session, run a few Sesson.load(), Session.iterate() methods and then call Session.close(). Run the below query and you'll see that the cursors are still there (in the statistic 'opened cursors current').

select n.*,s.* from v$sesstat s, v$statname n where s.statistic#=n.statistic# and sid=23 and like '%cursor%'

However, in the same program, after the above calls, if you
call SessionFactory.getSession() and grab the same jdbc connection from the pool;
as soon as you call Session.load() or Session.iterate(), you'll see that the number of open cursors will be 0 or decrease dramatically. This means that the jdbc driver is smart enough to track the status of the cursor and prep stmt and reports the closed cursors in the next round-trip to the database, hence reducing network round-trips, which is a good thing for performance.

Bulent Erdemir

Friday, September 29, 2006

Java primitive types

Just to remember... nothing more :

byte Short numerical from -128 to +127 1 byte
short Short numerical from -32768 to +32767 2 bytes
int Numerical from -2 147 483 648 to +2 147 483 647 4 bytes
long Long numerical from -263 to +263 -1 8 bytes
float Decimal from -1.4 * 10-45 to +3.4 * 1038 4 bytes
double Long decimal from 4.9 * 10-324 to +1.7 * 10308 8 bytes
char Unicode character (65536 possible characters) 2 bytes
boolean Boolean (true or false) 1 byte

Wednesday, September 27, 2006

Let's work in full screen mode

One of the greats features offered by Java is its capability to switch in full screen mode. The following article is a sun's tutorial on this subject :

To illustrate how it is benefit to use this mode, I want to opposite it to web based applications that impose the display of unusefull navigator toolbars (taking 25% of the screen workspace).

I will implement full screen mode in Violet UML Editor.

Tuesday, September 19, 2006

EAI, ESB and SOA news

when I was young, I developped on webMethods platform. Since this périod, I feel that writing java code is a prehistoric way of programming.

Friday, August 11, 2006

Monitoring the GC on JVM 1.4

As JConsole is provided with Java 1.5, Marco sent me a link to open source software that monitors the GC, using the jvm "verbosegc" option.

Understanding the garbage collector

Here is a good article (in french) by Romain Guy explaining how the Sun's JVM garbage collector works and how it is possible to set the GC mode

Thursday, August 10, 2006

Memory dumps are usefull

Here is a JVM option very interesting :
-XX:+HeapDumpOnOutOfMemoryError usefull to identify memory leak responsability

Sun's JVM options : the (big) list

I just put this link (thanks to Marco) :

I 'll make no comment about the difficulty to tune a virtual machine. Oh.. I would said just a few words : prefer design and don't hope you will tune your quick development that has been quickly deployed in production under preasure.

Inside the Sun's JVM memory

Yesterday, my manager asked me about a problem concerning the eden space memory. So, this is a summary of JVM's memory management.

Heap Size
The allocation of memory for the JVM is specified using -X options when starting ColdFusion

JVM option Meaning
-Xms initial java heap size
-Xmx maximum java heap size
-Xmn the size of the heap for the young generation

(extended options)
-XX:MaxPermSize maximum permanent generation size (for creating object instances)

For efficient garbage collection, the -Xmn value should be lower than the -Xmx value.

Heap size does not determine the amount of memory your process uses
If you monitor your java process with an OS tool like top or taskmanager, you may see the amount of memory you use exceed the amount you have specified for -Xmx. -Xmx limits the java heap size, java will allocate memory for other things, including a stack for each thread. It is not unusual for the total memory consumption of the VM to exceed the value of -Xmx.

Garbage collection
There are essentially two GC threads running. One is a very lightweight thread which does "little" collections primarily on the Eden (a.k.a. Young) generation of the heap. The other is the Full GC thread which traverses the entire heap when there is not enough memory left to allocate space for objects which get promoted from the Eden to the older generation(s).
If there is a memory leak or inadequate heap allocated, eventually the older generation will start to run out of room causing the Full GC thread to run (nearly) continuously. Since this process "stops the world", ColdFusion won't be able to respond to requests and they'll start to back up.
The amount allocated for the Eden generation is the value specified with -Xmn. The amount allocated for the older generation is the value of -Xmx minus the -Xmn. Generally, you don't want the Eden to be too big or it will take too long for the GC to look through it for space that can be reclaimed.

Stack size
Each thread in the VM get's a stack. The stack size will limit the number of threads that you can have, too big of a stack size and you will run out of memory as each thread is allocated more memory than it needs.
JVM option Meaning
-Xss the stack size for each thread
-Xss determines the size of the stack: -Xss1024k. If the stack space is too small, eventually you will see an exception class java.lang.StackOverflowError .

Wednesday, August 09, 2006

How to monitor your application

I just found an article about how to use the JConsole that is included in Java SE 1.5. The article also presents in a few words the JMX phylosophy.

SwingWeb 1.0 : a new swing to web bridge framework

Wooh! It's a great day. There's a new framework that allows to publish a swing application on the web. I just put the link here but I will write another message about it. This is really great.

Tuesday, August 08, 2006

Batch processing in Hibernate

I read this article that is very interesting (thank you very much Marco) :

Suppose you need to insert 200,000 records into a database in Hibernate. You'll need to adjust the following settings:

//set the JDBC batch size (it is fine somewhere between 20-50)
hibernate.jdbc.batch_size 30

//disable second-lavel cache
hibernate.cache.use_second_level_cache false

//and now do your job like this
Session S=SF.openSession(); //SF = SessionFactory object
Transaction T=S.beginTransaction();

for (int i=0;i<200000;i++)
record r=new record(...);;
if(i % 30==0)
{ //30, same as the JDBC batch size
//flush a batch and release memory

(Author : Anghel Leonard)

Monday, August 07, 2006

Debugging application servers

Today, I found a great article that explain how to debug remotly several application servers.

Follow this link

Java Look And Feel : a simple article

As I love simple articles, I found one interesting about how to male a Java Look And Feel. I think It's time for me to learn somthing different that rewriting the paint() method.

Link to the article

First Step

Humm... Well it's done! I don't want to spam Marco's blog (javacomptoir) anymore with dailly messages. On this blog, I will write about my readings, about articles I found on the web. In many cases, I will be about Java. But sometimes, It will be about related technologies such as databases, global software architecture and... my favorite activity during spare times : Violet, THE Very Intuitive Object modeling software that I develop behind Cay S. Horstmann.

Thus, this blog will be a sort of bookmark with some experience feedbacks