Hardcore Java: Quine and Backward quine

Browsing through old university folders I found interesting pieces of code that I wrote some time ago for a contest at IBM. Have you ever heard of a quine? If not, here’s the definition by Wikipedia:

In computing, a quine is a computer program which produces a copy of its own source code as its only output. (…). For amusement, programmers sometimes attempt to develop the shortest possible quine in any given programming language.

Now, when everything is clear – let’s amuse ourselves and write a shortest possibile quine in Java :)
After some experimenting, I ended up with a Java code which consisted of 135 characters (the code is wrapped for better readability):

enum f{f;System z;String s="enum f{f;System z;String s=%c%s%1$c;{z.out.printf(s,34,s);z.exit(0);}}";{z.out.printf(s,34,s);z.exit(0);}}

That’s all you think? – no class, no main method? Yes, but let’s make some test in order to prove the correctness of the presented approach (note: you won’t run it in eclipse – you have to use command line) :

C:\WORKSPACES\BLOG\quine>javac f.java
 
C:\WORKSPACES\BLOG\quine>java f
enum f{f;System z;String s="enum f{f;System z;String s=%c%s%1$c;{z.out.printf(s,34,s);z.exit(0);}}";{z.out.printf(s,34,s);z.exit(0);}}

OK, but grouches may say that it is an old trick – and that’s actually true. You can google much stuff concerning that problem. So, let’s raise the bar and write a shortest backward quine – a program which will output its content backwardly. I haven’t found a word about it on the Internet. My version contains 191 characters:

enum b{b;System z;String s="}};)0(tixe.z;))(esrever.)s(reffuBgnirtS wen,43,s(ftnirp.tuo.z{;%c%s%1$c=s gnirtS;z metsyS;b{b mune";{z.out.printf(s,34,new StringBuffer(s).reverse());z.exit(0);}}

Is your version shorter :) ? Groovy version is gonna be much briefer – I will code it and post soon…

Tags:

View Comments

E-point prize for the best thesis is mine :)

I am really excited to inform that the master thesis written by Marek and me was awarded for the second time! Today, our dissertation titled “Generic ESB Monitoring Architecture Compliant with JBI” has received the e-point prize for the best thesis on JEE Internet solutions. The official results are published on the e-point site (in Polish). See the screenshot attached below:

Few months earlier it had been also awarded by the Polish Information Processing Society – I blogged about it HERE. On that occasion, I would like to thank Marek for great and successful cooperation! As far as I know it was the last contest to which we submitted our dissertation so in the nearest future I will publish its content in the Internet. Stay tunned :)

Tags: , ,

View Comments

Mission Impossible with Kirk Pepperdine

Last Tuesday Kirk Pepperdine gave a talk at Warszawa Java User Group. Kirk is a Real Guru in the Java world so I was truly excited to meet him. He has been working in high performance and distributed computing for nearly 20 years. What is more, in 2006 Kirk was recognized by Sun Microsystems as a Java Champion recipient for his contributions to the Java community.

“Performance Tuning with Cheap Drink and Poor Tools” was the topic of the session. At the beginning participants got a cheap food (pizza) and a cheap drink (coke) – so everybody was in high spirits :) You can expect everything when you attend a JUG meeting. Sometimes people present something you actually got acquainted with very well, sometimes you don’t know the subject, but Wikipedia, Google and Eclipse would give you the same answers without leaving your home. Some sessions are, however, sensational – and Kirk’s talk was really that case!

At first, Kirk put emphasis on the fact that there is no taxonomy regarding performance tuning. The main problem is that very often developers do not realize that the process of giving a performance boost to an application is much different than the development itself. Kirk made a joke that many companies tune their application in accordance with the following rule:

“We don’t know where we are going, but we are having a great time” .

According to the speaker, issues concerning performance should be take into consideration at every stage of the project life-cycle. Could we disagree with that? I don’t think so, but why it is neglected most of the time…?

Later, Kirk presented a sample application which encompassed the most common performance bottlenecks. The audience was supposed to tune it on the spot. It was really funny as this simple exercise showed the main problem right away! Developers are used to work with the code – we can even say that we love the code :) So, what do we actually do to solve potential performance problems? – we look into the code! According to Kirk it is the last thing that should be done. However, to cut the long story short, here are some general rules presented by Kirk:

  • When is the performance bad? – When users do complain!
  • Everything matters – tune application in exactly the same hardware/software environment as the production environment.
  • DON’T LOOK INTO THE CODE unless you really know where you wanna look.
  • Find the DC (dominating consumer): application, jvm, os, hardware.
  • If CPU kernel time is higher than 10% – application is the DC.
  • Use poor tools – such as: jps, jstack, jvisualvm – to locate the piece of code that is responsible for the degradation of performance. THEN look into the code to modify it.
  • Using a profiler is the last step
  • Don’t shoot wild – don’t do anything blindfold – making your code look beautiful won’t help!

Do you agree with that? YES, YES, YES ;)

View Comments

Spring integration in jBPM 4

When I was supposed to use the fourth version of jBPM for the first time I couldn’t find a sufficient documentation concerning the integration with Spring. I have also seen that there are many questions regarding that issue on forums or discussion lists. Despite the fact that there are some entries on Andries Inzé Blog or in jBPM official documentation which actually outline that problem I felt a lack of a sample project archetype. Something that I could download, build and take the first shot right away!

After few months I found some time to make this dream come true :) as I have created a sample Spring+jBPM+Maven2 project. All details of the integration are described in my developers notebook under the entry: Spring integration in jBPM 4. The article briefly shows how to set up:

  • Maven Project Configuration [pom.xml]
  • Logging configuration [log4j.xml]
  • jBPM Configuration [jbpm.cfg.xml]
  • and Spring Configuration [applicationContext.xml]

It also outlines how to write and execute a sample test case.

That is all what you need to start playing with jPBM in your favorite IDE(A)! More on this is comming soon! Stay tunned!

Tags: , ,

View Comments

JavaCamp #1 in Krakow

Last weekend I returned to Krakow to take part in the Java Camp meeting. I decided to travel by car, which was actually an unfortunate decision. 300km, 2 traffic jams, 6 hours of driving – all these facts perfectly summarize my journey :(   The meeting was organized by PJUG (Polish Java User Group). It took place at AGH University of Science and Technology which I have graduated from, thus it was really nice to return there. The agenda was interesting, especially when you consider the fact that I was one of the speakers :)

The meeting began with the session called “Developing Rich Web Applications in JBoss RichFaces” led by Marcin Nowrot. Marcin presented the overview of the newest RichFaces (3.3) components by showing a sample demo application. I have to admit that this session wasn’t really beneficial for me since it was more like a RichFaces advert. I expected an objective review which would summarize all the pros and cons of the library, so all in all, I was disappointed. I also didn’t like the fact that hardly no code was shown. What is more, Marcin’s application was similar to the Exadel Demo so everybody could do the same test at home. The last thing I would like to mention is the speech code used by Marcin. Addressing people by sir or madame is not a common behavior on JUG meetings – it built a wall between Marcin and the audience. But I would like to emphasize the fact that it is only my humble opinion – I am sure that there were many people that enjoyed the session.

Afterwards, I presented jBPM in action! The main goal of my session was to present the most important advantages of leveraging jBPM capabilities in an ordinary JEE application. I also wanted to popularize it a bit since in Poland it is rather unknown. It was confirmed by the fact that only two people raised their hands after I asked how many of them had used any of BPM frameworks before (there was about 60-80 people present). After outlining the basic concepts of BPM I went into the details of jBPM. I presented the wide variety of jBPM tools: ant installer, web console, eclipse plugin and signavio editor. Later, I showed two examples which explained how to integrate jBPM with EJB and Spring. In my opinion people were a little bit surprised that it can be done so easily. Yeah, jBPM is lightweight! Finally, I presented a sample business application implemented in… Grails. It was supposed to automate the process regarding JUG meeting’s organization. Some methods were implemented in two ways: with and without jBPM. First of all I showed the version which didn’t use jBPM – business rules and the logic of the process were hard-coded. Later I showed the version which was implemented with the usage of jBPM. Then I explained all the advantages and disadvantages of such approach. According to the feedback that I received my presentation wasn’t so bad but I don’t want to rate myself… :)

Later, we had the possibility to get acquainted with JavaFX. Andrzej Grzesik introduced the concept of RIA. It is the acronym of Rich Internet Application, but you can also find different kind of RIAs on the Internet :) The presentation was cool. Andrzej shared his experience concerning JavaFX giving an objective view of it’s current status and stability. JavaFX and RIA do not belong to my current area of interest, but it was cool to deepen my knowledge in that field.

Next, there was a long awaited pizza break! It was a great opportunity to chat with other developers and to exchange opinions concerning the sessions which were already held. Pizza was a little bit to spicy :D so we have drunk all the coke left to stay alive, but who cares – it was great!

The last session that I attended was the “Matlab Java Injection” presented by Miroslav Kopecky from Prague. It was a really good presentation! Mirek showed how to leverage Matlab’s capabilities directly in Java applications. He explained step-by-step how to set up the environment, write Matlab functions encompassed by “m” files, import them to Java application and finally use as Java classes. Mirek also presented a wide variety of examples which enabled us to deeply understand all the covered aspects. My favorite example was the JSP servlet showing a javascript plot generated by Matlab. I was really amazed by the fact that Matlab provides such sophisticated Java integration mechanisms. I have even promised myself to write a sample Java-Matlab application, if I will find enough time…

Summing up, it was really great to visit Krakow for the second time this autumn. I met new people, learned new things and gained a priceless practical experience as a speaker. What more could I ask for?

Tags: , , ,

View Comments