Хуудсууд

2012-09-13

Java annotations example

I've done some small-scale presenting about annotations in Java based on a simple use case in my company. I thought I would post it here for a greater audience.

Annotations in Java is a very powerful enhancement that can save a lot of time for developers and programmers. Basically, it enables programmers to avoid creating bunch of configurations based on XML, database records, etc. Instead they can annotate certain classes or fields to achieve different configurations. That is how now we don't declare our servlets in web.xml with its class and URL pattern; instead we annotate them by typing @WebServlet in the Java file.

OK, the use case: Let's assume that we are developing a tax processing program. We have an entity class called Citizen.java which looks something like following:


Let's also assume that our program shall be a pretty generic one where we can define our processing formulas. Let's say we define formulas and set its variables to Citizen class' fields. Say we have if (A < (new Date()).getTime()) { B; } else { 0-B/2; }.

Obviously, some of the fields are irrelevant for formula designing. So, we define an annotation and annotate those fields which are relevant.


and
We have also defined an attribute called name for the annotation so that it can be more readable.

Finally, what and why are doing it is that we are building drop-down menus for setting variables in each formula we define. We are not able to fetch those fields annotated with @Calculated to fill those drop-down menus.

The ways to using these kind of functionality are left for your imaginations.

Of course, using reflections in run-time may make your program run slower. However, you can always cache the annotated fields list in your favorite embedded key-value store database.

2012-08-07

Embedded key-store store database wrapping-up

In my last post, I have mentioned about what a key-value store database and little about Sleepycat. While Sleepycat is great, it needs some configuration before actually using it. For this reason, I have written an wrapper which stores only unicode-based strings as key and value. The code is given in the following Gist. The usage example has been given in the comment.

2012-06-30

Embedded, persistent key-store

One often needs an embedded, persistent, key-store database solution if he/she is developing a software which relies on configurations made upon deployment. I was that one yesterday, so I looked up on the Internet for a solution. The solution was, with no convincing reason, Berkeley DB Java Edition, Sleepy Cat to be specific.

So here is the code chunk that did the trick! For a developer of modern languages like Python, it seemed like a lot of work for simple tasks. However, if you wrap it with your own code it can be helpful in many ways.


2012-01-09

The Friendship of the Music: A review for Genghis Blues


The world as we know is full of inspirations, surprises and other amazing things with all its diversity. This diversity is its people who vary from the highlanders in the Andes, to the arctic Eskimos, from city dwellers of enormous metropolitan areas to Tuareg people in the Saharan desert. The greatest inspiration that is maybe music, a common thing that all different cultures in the world share. The inspiration for Paul Pena, a renowned jazz musician from the United States, was a practice of music from the nomadic people in the Central Asian Altai mountains. Called khoomei locally, this is a style of throat-singing in which the performer produces multiple tones simultaneously making a unique melody. As interesting as how it sounds is the journey and friendship formed when Paul Pena wanted to know better about what he heard on radio.

Khoomei, otherwise called overtone singing, is practiced by the nomadic people in Mongolia, Chinese Inner Mongolia and Russian Siberian republics like Tuva and Khakassia. It’s believed that khoomei was originated from nomadic herdsmen trying to emulate sounds of mountains, rivers, sand and wild animals. Mongolian nomads have a very different lifestyle which have great impact on khoomei. Mongolian plateau consists of steppes and Gobi desert that last thousands of kilometers where one may not find people for days. Altai ranges have steep mountains raising over the clouds. Herding domestic animals in the arid steppes and hunting games in enormous mountains can last days and sometimes months without seeing home. In such geography and condition, wilderness can be friend of people. Culturally tied to Mongolia, Tuva is a republic in Russian Federation. Tuva was an independent country in the first half of the 20-th century [1]. Afterwards it was incorporated into Russia. The people in Tuva share  lots of cultural elements with Mongolians.

Paul Pena, an American jazz singer accidentally catches khoomei on the radio, when he was surprised by what he was hearing. Excited, he goes to a local music store to look up what he has just listened where he finds out about khoomei performed by Tuvan artists. He wants to go further and make some studies. Apparently he gets along with an organization called Friends of Tuva which is a friendly community that gathers information about Tuva. Friends of Tuva was formed by Nobel laureate physicist Richard Feynman and friends [2]. After performing khoomei unofficially in a Tuvan event in America, Paul Pena was invited to Tuva by Kongar-Ool Ondar who is a throat-singing master in Tuva. After informing with letters, just after the USSR was split, the group of friends travel to Tuva in a very long trip. They get there to be welcomed very friendly by the Tuvan people and meet Kongar-Ool Ondar. The group get along very nicely with local people thus establishing friendships with the people. Furthermore, having learnt khoomei before going to Tuva, Paul Pena wins Tuvan national throat-singing competition called Kargyrgaa [3]. Paul Pena and Kongar-Ool Ondar perform famous jazz music and Tuvan music together with big smiles on both of their faces. The friendship was there to grow and last rest of the following years.

The world is a big... big place. There are thousands of different ethnic groups and hundreds of different cultures which can not be easily percieved by each other. But inspirations are always there to be found by some medium. In “Genghis Blues”, the music was the medium and it connected different cultures to create friendships among them.  It can be best summarized by Paul Pena in his letter which states, “Kongar-Ool and I have been working in the hope of promoting better understanding between people of different nationalities, races, beliefs, languages, and cultural and economic systems. I believe that in this work there can be found evidence that such understanding and cooperation can be realized.” [3]

References
  1. World at War timelines. http://www.schudak.de/timelines/tannutuva1911-1944.html retrieved Jan 03, 2012
  2. Friends of Tuva website. Frequently asked questions: http://www.fotuva.org/faq/part_1.html retrieved Jan 03, 2012
  3. A personal letter by Paul Pena in 1994. http://www.fotuva.org/gb/paul.html retrieved Jan 03, 2012