Sunday, March 10, 2013

Localization in Java can be easy

It’s being a while since my last post. Recently I wrote small localization library for Java. It’s still in development but I wanted to share main ideas.

JDK localization capabilities are comprehensive enough but not easy to use and it misses very important concept of Plural Rules. IMHO GWT is the only Java framework I know which did localication right. I decided to bring these ideas to server side and created ginger. Here is the list of it’s core ideas:

  • Ease of use
  • Compatibility with JDK localization features
  • Type safety
  • Plural rules support
  • Popular libraries and frameworks support
Read More »

Thursday, March 31, 2011

Lost Stack Trace

Last week our team faced another NullPointerException in our development environment. As usual I started investigate log files to get full stack trace and find out reason of exception. Surprisingly, but the message I saw in log file was like:

ERROR: MyClass - java.lang.NullPointerException

I realized that there was something wrong in logging code, hence we are loosing stack trace. I checked code which produces this log and didn’t find anything unusual. Then I asked my colleague to double check it may be I miss something. He reproduced the same exception on his desktop and showed me nice log statement with full stack trace. We started to feel that there is some magic behind that. Whole team started googling and finally we found the answer.

Read More »

Saturday, March 26, 2011

Java Formatters Best Practices

Java API has set of classes for formatting and parsing dates and numbers. Mostly used are: java.text.DateFormat and java.text.NumberFormat. Often when interviewing candidates I ask them whether JDK date and number formatters are thread-safe. Surprisingly most of them don’t know the right answer, hence I decided to describe common pitfalls with formatters usage.

Read More »

Tuesday, March 22, 2011

Java Generics and Reflection

“Officially” Java does not have information about generic types in runtime. But it’s not absolutely true. There are some cases, which are utilized by smart frameworks like Spring and Google Guice. Let’s explore these cases!

Read More »

Monday, March 07, 2011

Logging JDBC calls

Today I found some my drafts of JDBC logger library. And finally decided to upload it on Google code. The main idea of the library is to transparently intercept JDBC calls and log queries (even for PreparedStatement).

Read More »

Sunday, March 22, 2009

Фабричный метод

В этот раз речь пойдет о паттернах проектирования. Если быть точнее — Статическом фабричном методе (Static Factory Method). Вкратце, он призван для того, чтобы инкапсулировать процесс создания объекта.

Допустим, у нас есть метод, который возвращает определенный набор (список) данных. Этот метод должен иметь возможность вернуть для каждой единицы фактический результат или ошибку. Естественно, что в таком случае исключения бросать нельзя, иначе мы не получим “хорошие” данные. Обычно, в таких целях используется объект-контейнер, который хранит или данные или ошибку или просто пустой.

Read More »

Sunday, February 15, 2009

Чем опасно логирование

Большинство современных приложений не обходится без логирования. Почти каждый разработчик, так или иначе, знаком с тем как это делается. Для Java существует довольно обширный набор библиотек для удобного логирования: Log4J, Jakarta Commons Logging, SLF4J, Logback и Java Logging API и т.д.

Существующие библиотеки позволяют очень удобно разграничить вывод информации об ошибках, предупреждений, информационных сообщений и отладочной информации. Так же, позволяют настроить предпочитаемую степень логирование непосредственно перед запуском приложения.

Но, к своему удивлению, я недавно заметил, что большинство разработчиков пользуются логированием неправильно. “Что значит неправильно?”, - удивитесь Вы.

Read More »

Tuesday, December 16, 2008

Подмена Синглтонов

Недавно мне в очередной раз пришлось работать с кодом, полученным в наследство. И я, как честный преверженец TDD, решил предже всего написать тесты на уже существующий класс. К своему огорчению сразу же обнаружил в коде вызов следующего вида: IdGenerator.getInstance(). Да, это он самый, “любимый” нами синглтон.

Read More »