braju.com Java fprintf, printf, sprintf (fscanf, scanf, sscanf)

 

Home

Download
Purchase
History
Examples
Documentation
API/javadoc
FAQ
Feedback
About

Donate

Java scanf

About

In the end of 1996 I was doing a project in Java that included the display of matrices. I wanted to list the values in straight columns and that required some kind of string formatting. I realized quite soon, though, that Java did not support this very well, so I decided to search for a printf implementation on the web. But, I could not find a decent one. All of them where supporting only one parameter and only a subset of the format flags. I went through several news groups and mailing lists and everywhere I was told "it is impossible to do variable number of parameters because there is no varargs1 in Java". I accepted this limitation and forgot about it, but then when I woke up one morning a couple of weeks later, the simple workaround2 was just there.

The first version of the package did only supported a few format flags, mostly those that I needed in my project for printing out matrices. During the next couple of months I added more and more of the format flags as I needed them. In the summer 1997, I decided to assure that all format flags in C was also supported by my package. I also wanted the package to be compatible with Java 1.0.2. The latter was, and still is, important because several web browsers are only supporting "old" Java.

From the time I had a decent implementation of the printf package, I wanted to share it with the rest of the Java community. In October 1997, the first version was published. Since then the package has been going through code optimization, some bug fixes, and also some minor modifications in the API. It is my intention, though, to keep the API stable so you do not have change your old source code. Also, since the code is used and thereby tested by thousand of users, I can provide very high quality of the package.

In November 2000 I (finally) got a domain for the package; braju.com. Before you imported the package as "import hb.format.*", but that was against the naming conventions in Java. When you now write "import com.braju.*" you can be sure it is a unique package name.

My background is a Master's Degree in Computer Science & Engineering, a PhD in Mathematical Statistics and most recently a postdoc in Statistics at UC Berkeley..

Cordially,

Henrik Bengtsson
henrikb@braju.com

ruler
varargs is a feature in the C language that makes it possible to check the number of parameters at run-time.
The workaround is basically the Parameters class.