Quantcast
Channel: Scratch Where It's Itching
Browsing latest articles
Browse All 73 View Live

Trivial Collection Pattern

We have a framework for handling server notifications, where listeners are responsible for producing one or several Events that will be forwarded to the UI part. Although it happens that one single...

View Article


Empty Integer

I just found this interesting piece of code: Integer oldGroupId = ... Integer groupId = (oldGroupId.toString().trim().equals(GUIConstants.EMPTY_STRING)) ? NumberConstants.ZERO_INTEGER : oldGroupId;At...

View Article


Legends of Code

For those of you who are french, student, and like programming, there will be a coding competition in November: Legends of Code Subscriptions are Open! Not a minute to loose...

View Article

Native Renderer Curiosity

The other day, a colleague showed me a window that was not working well. Scrolling a JTable was throwing lots of Exceptions and breaking the rendering. The strange thing was that this window worked...

View Article

EDT Freeze Detector

It is always the same scenario: the support team contacts us with a problem of a "frozen GUI". They send us the logs so that we can investigate, but of course the logs do not show anything. The user...

View Article


When is a SwingWorker really done?

Imagine you have a SwingWorker running, and you would like to know if it has terminated its job. You notice that it has a isDone() method, and say to yourself: "great! I can use it!". But are you sure...

View Article

ToString Overflow

A colleague of mine showed me this code from one of the libraries we are using:    @Override    public String toString()    {        final boolean reuse = false;        try        {...

View Article

Modal vs Always on Top

Here is an interesting piece of code:      public static void main(String[] args) throws Exception {          JFrame alwaysOnTopFrame = new JFrame(\"Always on top Frame\");...

View Article


InvokeDynamic for all?

I spent Tuesday evening at the Paris JUG listening to Remi Forax about his ideas of a new keyword for Java 9. It was an interesting presentation, followed by an even more interesting Q&A...

View Article


How to Align two Labels

Or rather how not to. This is a code a colleague found on our GUI. The developper probably did not know how to align two components, so he decided to do it his own way. There is no easy way to set the...

View Article

You Said Naming Conventions?

I remained speechless...public final class AbstractButtonList

View Article

Double Timeout

The other day, I needed to check if a configuration parameter giving a timeout in number of seconds was really used by our communication layer. I came to the point in the code where we are sending a...

View Article

Le Meilleur Dev de France

Yesterday I took part in the programming competition called The Best Developer in France. The place was the new hyped school 42, with its so-called “swimming pool”, two big rooms filled with Macs with...

View Article


Closure on "Le meilleur dev de France"

After all was said and done, here are the conclusions about this competition:Entry price: 50 euros. Quite expensive for a coding competition with so many sponsors. Especially since many places were...

View Article

Permutations

A simple piece of code for calculating all permutations of a given word:    public static List permutations(String s) {        List list = new ArrayList<>();        permutations(list, s, "");...

View Article


N Permutations and Combinations

Following my last entry, I would like to add the code for permutations of N elements out of a word, which is a simple modification of the previous program:    public static List permutationsN(String s,...

View Article

Java mini GUI Freezes on Windows 7

When migrating to Windows 7, a colleague of mine experienced small freezes in our application GUI when moving his mouse around. Thanks to the Freeze Detector (TM), we logged the following stack: FREEZE...

View Article


AutoCloseable when not available

On his blog, Brian Oxley shows a neat way in JDK 8 to use non AutoCloseable object having a close-like method in a try with resources construct, using the new method references. For those of us who are...

View Article

Get Simple Class Name

You probably heard of one method of Class that give the simple name of the class, without all the packages. Even if you hadn't, you probably know a simple way to get the sub-String following the last...

View Article

FIFO Stack and LIFO Queue

Recently, I found this class in one of our applications:publicclass FIFOStack extends Vector {publicsynchronized Object push(Object o) { add(o);return o; } publicsynchronized Object pop() {if...

View Article

Why don't I know my disk is full?

We had this interesting problem lately, that an application had a corrupted file after a disk got full. The strange thing was that the app did not know that the disk was full. We were expecting an...

View Article


Capital Date Mistake

Here is a small piece of code. Can you tell what it prints? SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2014);...

View Article


Java 8 Compilation Strangeness

A colleague of mine (thanks Clement) showed me some strange issues his team met when they decided to move their project to Java 8. These issues did not appear while compiling with Eclipse, but showed...

View Article

Autoclose Lock

I was just wondering if there is a difference between the classic: lock.lock();try { //I have the lock! } finally { lock.unlock(); } And the Autocloseable version: lock.lock();try (AutoCloseable auto =...

View Article

Thou Shall Close Thy Streams

You should always close your IO streams. Said like this, it sounds obvious. But in the light of some new Java 8 features, it took me some time to get around it.I needed to write a small method for...

View Article


Boolean Parsing Fest

A small gem I found the other day: String value = ...boolean booleanValue = Boolean.valueOf(value.toLowerCase()).booleanValue(); A lot of useless stuff: toLowerCase is useless because the Boolean class...

View Article

Lambda Before Switch

We had this method that was doing the same thing several times in a row. Here is a simplified version:void resolveAll() { a = resolveA();if (a == null) states.remove(State.A);else states.add(State.A);...

View Article

Collectors.toMap does not like null

Some map accept null values, some don't. How do you know? You usually take a look in the javadoc. But what about maps created by streams through the Collectors.toMap? The javadoc does not say. So I...

View Article

See you at Devoxx Paris

I'm in! The quickie I proposed to the Devoxx Paris comitee was accepted. It is called "The Thread Awakens". Maybe there were some Star Wars fan in the decision process?

View Article



Log content of SOAP message

It's probably all over StackOverflow, but lately I had to log the XML content of SOAP messages for debugging. I did it this way:publicvoid connect() { Service service = ... List<Handler>...

View Article

Java 8 might kill doclint

Since Java 8, javadoc doclint became a lot stricter. Up to now, we had some warnings here and there. But since we moved to Java 8, our Jenkins releases are failing because doclint would throw HTML...

View Article

Image may be NSFW.
Clik here to view.

Rocket Anti-Pattern

At my presentation at Devoxx Paris this year, The Thread Awakens, I introduced several Patterns related to multithreading. Since it was a quickie, I had only 15 minutes to talk about 15 Patterns. That...

View Article

Image may be NSFW.
Clik here to view.

Paratrooper Model

In my previous entry, I was describing the Rocket Anti-Pattern, where one thread would handle too much work across several application layers, leading to communication buffer overflow and message...

View Article


Image may be NSFW.
Clik here to view.

Marsupilami Pattern

In my previous entry, I described the Paratrooper Model, where each application layer would have its own thread pool for handling data. And the way to implement that is to use the Marsupilami...

View Article

Image may be NSFW.
Clik here to view.

Indian Train Anti-Pattern

Last time, I talked about the Marsupilami Pattern, where we introduced queues to transport data between application layers.Now you’ve been using these queues for some time, conveying all sorts of data,...

View Article

Image may be NSFW.
Clik here to view.

Indiana Jones Pattern

In my previous entry, I presented the Indian Train Anti-Pattern, where we added without discrimination data to be handled on our queues, leading to overcrowded queues.One possibility to alleviate the...

View Article


Image may be NSFW.
Clik here to view.

Hamburger Pattern

Last time, I introduced the Indiana Jones Pattern, where you would filter your messages in order to send less data on your overcrowded queue.Another way to reduce the number of messages is to use the...

View Article


Hamburger Queue

In my last entry, I presented the Hamburger Pattern and talked about how you can reduce the number of events on a queue by merging them. However, I feel that I should have presented at least one way to...

View Article

Image may be NSFW.
Clik here to view.

Water Drop Anti-Pattern

In my previous entries, I presented two patterns that allow you to limit the number of messages sent over a queue: the Indiana Jones Pattern and the Hamburger Pattern. The first one filters data while...

View Article

Negating a Predicate

Often, when using Java streams, I try to replace my lambdas with Method References. For instance, when I have this code: mystream.filter(mystring -> mystring.isEmpty()) ... I tend to replace it with...

View Article

Image may be NSFW.
Clik here to view.

Santa Claus Pattern

In a previous post, I talked about the Water Drop Anti-Pattern, where the ratio of payload to data was leading to poor performances.A way to alleviate this problem is to introduce the Santa Claus...

View Article


Image may be NSFW.
Clik here to view.

Godzilla Anti-Pattern

Last time, I presented the Santa Claus Pattern, where you would send several messages wrapped up in the same packet to lower payload and increase performance.However, if you create your packets without...

View Article

Create Temporary Files with NIO 2 on Linux

We have an application that had problems with memory consumption. One type of object that we were keeping in memory was kept there only in case a user would start an administration client and connect...

View Article


Image may be NSFW.
Clik here to view.

Opera Lift Pattern

In my last part, I presented the Godzilla Anti-Pattern, where you would merge so many messages that a monster size packet would be sent and have negative effects.In this part, I would like to present...

View Article

Queue Patterns

This is just a summary of all my Queue Patterns:PatternDescriptionRocket Anti PatternData cross layersParatrooper ModelSeparate threads for separate layersMarsupilami PatternIntroduce queuesIndian...

View Article


Image may be NSFW.
Clik here to view.

One Ring Pattern

Last time, I finished talking about all my Queue Patterns. Now I’ll start with my Thread Patterns. Once you have your queues filled with tasks, the question that arises is: how many Threads do I need...

View Article

Format Date with java time

An advantage of the DateTimeFormatter class from the java time package over the old DateFormat is that it is thread-safe. But if the only thing I have is a Date, how can I proceed? The...

View Article

Image may be NSFW.
Clik here to view.

Zebra Pattern

Last time I explained the One Ring Pattern, where only one thread handles data coming from a queue. I also explained the reasons why such a pattern might be preferred.One of those reasons is when...

View Article

TreeMap misuse

TreeMap is a very practical class when you want your Map to keep its keys ordered. Unless you don't know how it works. I noticed this code recently in one of our projects:private Map<Double,...

View Article


Image may be NSFW.
Clik here to view.

Star Trek Anti-Pattern

In previous installments, we tried to limit the number of Threads to the minimum, even to one. But what happens if you go the opposite way? Often, we try to parallelize some process, but do not want to...

View Article

Browsing latest articles
Browse All 73 View Live