What is jPrime

It's rare, but people ask what is jPrime. Well here's the just of it:

jPrime is a community driven technology conference organized once a year by the Bulgarian JUG in Sofia, Bulgaria. Obviously it focuses on the world of Java.

jPrime is non-profit. What's that? The organizers (Gang of five) do this free of charge, and all monetary profit goes to the Bulgarian JUG, which uses it to fund sessions, events, workshops and jProfessionals (smaller one-day conference, organized 3-4 times/year by JUG.bg).
jPrime is organized by the community for the community and since there's no monetary incentive, the focus is on technology and there are no marketing talks. There's an effort to get the best speakers available - there have been many JavaOne Rockstars and Java Champions.
jPrime started 2015.
jPrime 2015: 1min video resume, slides, videos, pics (flickr, facebook) .
jPrime 2016: 1min video resume, slides, videos, pics (???).
jPrime 2017: May 30-31, 2017
jPrime in the media:
2015: softuni,

[jug.bg] Adopt a JSR (CDI 2.0 with Antoine Sabot-Durant) 

Antoine spent a while day with us explaining CDI 1.2 and the upcoming 2.0. We discussed CDI extensions and he wrote some live code.


These are the slides from the last session. The most interesting part.

JShell - Java 9 finally gets a REPL environment

I did a short presetation on JShell - Java9's new REPL environment.

Here's the video (in Bulgarian)

Here's the code for nashorn:

import java.net.http.*;
import java.util.stream.*
import javax.script.*
// URL to fetch JSON for weather data for Pravets, Bulgaria
String url = "http://api.openweathermap.org/data/2.5//forecast/daily?q=Pravets,BG&appid=27fc9aa7cc0af902105a9c4c2d97845c&mode=json&units=metric&cnt=7";
//java 9 http api
String json = HttpRequest.create(new URI(url)).GET().response().body(HttpResponse.asString()) 
// create nashorn engine
ScriptEngine e = new ScriptEngineManager().getEngineByName("js")
// expose weather data JSON as global variable to nashorn engine
e.put("str", json)
// massage JSON using nashorn and get the max. temp values
double[] values = (double[]) e.eval("Java.to(JSON.parse(str).list.map(function(val) val.temp.max), Java.type('double[]'))")
// stat on max. temp values

[jug.bg] jProfessionals 3.0 Venkat Subramaniam

Usually I do the review of what we do in our JUG, but Dmitry did quite a good job and he has the best pictures.

Some minor additions from me:

Venkat Subramaniam also known simply as Venkat was here. Venkat is a rockstar (JavaOne Rockstar is someone who did an amazing session at JavaOne. Venkat is 16 (sixteen!!!) times J1 Rockstar in just 4 years).


Venkat did two sessions and a workshop. The two sessions (one on lambdas and one soft-code session on bad code) were highly popular, probably 150-200 people came.

Then there was a workshop that turned into a discussion on lambdas and quality code in general. Which was awesome.

More info on the event page in facebook and on our jProfessionals social page. Photo album.

Some highlights:







Java, JDK, JRE locations on OSX

JRE for browsers (mine was 1.8.0_101, 160mb, was up to date):
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java

JDK, JRE installed with installer:

I had only:
$ du -d1 -h
312M ./jdk1.8.0_25.jdk

Was not up to date.

After installing U101, I had:
$ du -d1 -h
338M ./jdk1.8.0_101.jdk
312M ./jdk1.8.0_25.jdk

I removed the old one.

Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)

I did a talk on Jigsaw at BGOUG.

The talk is for a very important new feature in Java SE 9. Code named Jigsaw, this feature modularizes the Java SE platform.
The coolest thing I do at the talk is to create a custom JRE.

Of course the jug and jPrime were mentioned.

Code: https://bitbucket.org/stybz/jigsaw.sty/src/



[jug.bg] Speaking at Riga Dev Day

So I'll do a talk about Http/2.0 at Riga Dev Day Conference. I'll be there representing the jug.bg. I'm pretty psyched to check out Latvia.

My session is on the first day


Update: my talk didn't go too well, because of projector issues. 15 min gone, flickering screen and me nervous ... overshot my time.

And to top it all of they recorded it and said it will go to youtube in a couple of months. 🙁

Not that it matters, but all my demos worked, kind of a Pyrrhic victory.

Update2: Riga is awesome and very beautiful.

IMG_6612 IMG_6616 IMG_6641

[jug.bg] "Everything you need to know about Java Classloaders" by Oleg Shelajev


Today Oleg presented a very interesting session about how class loaders work. He even remotely loaded classes from images (I imagine steganography).

Oleg works for Zero Turnaround, the company behind jRebel. Code examples here. The presentation is here.

One of the most interesting sessions so far IMHO.

[jug.bg] Adopt OpenJDK is not for mere mortals


A bit of introduction - we as a jug (java user group) got more active at the end of 2013 in no small part thanks to Ivan. We managed to build openjdk, import it in 3 major IDEs (eclipse, intellij and netbeans) and contributed a Virtual Machine with buildable openjdk 9 (both in fedora and ubuntu) and organized a couple of events, we decided we were ready for the next part.

At the end of 2014 we started timidly to try to contribute in the Adopt OpenJDK program. Adopt OpenJDK allows everyone* to participate in building and writing the java platform itself (or at least that's how we understood it *back then*).

We knew that LJC (London Java Community - their most popular jug) heavily participated in the new Date/Time API and soujava (Brasil's most popular jug) also managed to include code in the OpenJDK. Elated by these guys' successes we decided we had enough free time and sheer energy to contribute to the OpenJDK and thus put ourselves on the OpenJDK map.

In December 2014 we asked for something to work on. Nobody answered.

We decided to work on a simple Throwable convenience method (JDK-5050783). We had a hackaton. We submitted our fix. We were given some feedback and we submitted another. And we were told not to play with grown up stuff. That was a bit discouraging. But we didn't give up.

In February 2015 we started working on jaxp warnings. We fixed 43 easy warnings and submitted a patch. Then we fixed more harder warnings and submitted another patch. The great Joe Darcy answered but unfortunately we got nowhere again. That sucks.

A bit before that (Dec 2014) jug.bg member Doychin Bonzhev found a bug in the NetworkInterface and submitted a solution. He even submitted to another mail-list. He got a response (saying it is reasonable solution) and answered, but that was it. Nothing AFAIK followed.

So that was it for us. We gave up. Probably we didn't know the right people, but I argue that shouldn't matter. From time to time we get mentioned as collaborators in the Adopt OpenJDK by our dear friend Mani. We don't feel like that at all.

* Now you understand why the asterisk, right?

[jug.bg] jProfessionals 2.0

Today was the second edition of the jProfessionals format we started 5 months ago.


jProfessionals is a one-day free conf. Smaller than jPrime (our star yearly event).

In the first version we invited Koshuke Kawaguchi. (the creator of Jenkins CI).


Today the first presenter was Richard Warburton.


The session was about java 8 lambdas and even though it started as a very introductory session it turned out to be quite interesting. We discussed currying, Optional and the elvis operator.

What I learned is that Optional with value types is going to be fast (all in stack, no heap). Elvis is going in another direction - just a simple !=null check. Optional is kind of an explicit contract (preferred despite the verbosity and the extra object).


The second speaker was Vlado Tsanev aka tsachev.


He talked about Spring REST Docs. The talk was one big live demo. REST Docs is a way to document a rest api automatically by extracting the info from the tests - it creates cURL commands, headers, params as so called snippets, and it allows the use of a adoc files with links to the REST Docs snippets.


After a tasty lunch it was time for "The Seven Deadly Sins of Microservices" by Daniel Bryant.


It was a soft session with a lot of links and cool ideas of what microservices are good for and what they are not. There was a discussion on where people fail mostly using them. Very interesting and engaging - I bookmarked a lot of books that I'm never going to read.


Doychin Bondzev talked about Firebird (an alternative to postgres) - free, has triggers and is embeddable with nice tools and binary backup that is fast enough on windows.


Richard Warburton was next with another session for the future of Generics which was really fun.


I finally understood why enums are defined recursively (Enum<E extends Enum<E>>).


Next was a talk about Jenkins Builds with Docker Containers by Petar Velikov from e-card.bg.


It was quite interesting especially the docker part (he even used dockviz).


Finally there were two lightning talks. Martin Toshev talked about RxJava and RxJS.

Another guy - Teodor Tunev talked about Activiti - a java BPM platform far better than jBPM in his words.



Finally some beer was due.


(has not arrived yet)

Fosdem 2016

My first fosdem this year. I found a lot of interesting things mostly on the opensource tracks. The "free java" track IMHO was a bit unpopular even though Stephen Chin and Mark Reinhold were there.

I guess I'm used to a better treatment on a conference (I go mostly as a speaker). Here it was rainy and cold and even though the french fries were awesome, I'm used to better food.

IMG_6498 IMG_6499 IMG_6500

[jug.bg] Dockerize Spring Boot Application

Antoan presented a session about Spring Boot running on Docker and how to use the docker maven plugin inside a Spring Boot application.

Actually we talked mostly about running Docker and application from the ecosystem. There was a statement that uninstalling Kitematic requires payment, which started a discussion about this model.


[jug.bg] The Jenkins' creator in Sofia thanks to @bgjug #jprofessionals

The first edition of jProfessionals is happening right now.


We managed to bring over Koshuke Kawaguchi. He's the creator of Hudson and after leaving Oracle, creator of the open source Jenkins. The topic was Jenkins 2.0.

The next speaker is Vladimir Tsanev. He'll talk about JMH with examples. Very interesting topic. He actually showed how to create a simple benchmark and to how to execute it.

Update: After the plentiful lunch Svetlin Nakov was awesome presenting HTTP/2. He was great at explaining the inner workings of the new protocol. Emil Doychev presented Groovy. There was a little bashing on JPA.

Some time for coffee and Doychin Bondzhev presented JavaFX in a very accessible way.


Trayan Iliev talked about high performance reactive programming with java 8. It was very interesting. Especially the demo at the end.

[jug.bg] Devoxx 2015



Writing this I'm listening to Alan Bateman and Mark Reinhold deliver a session on the new Jigsaw (their third attempt?). This time it might work.

There's a lot of beer, more than I can handle (it turns out that a teenage girl handles her liquor better than I can) . A lot of awesome sessions - even one on the history of the universe.

The JUG is represented by Ivan, Krasi, Vladi and a bunch more awesome folks that make my trip here awesome.

Explaining to young female students that an IT career doesn't suck (that much)


It was a surprise to me, but I got invited to a forum organized by HP to explain to young women that a career in IT is not scary, doesn't suck at all and why it might be something that they may enjoy.

There were around 50 guests.

I was invited as an example of a "young" "successful" person. It was an honor sitting next to the Iravan Hira (CEO of HP Bulgaria), Preslav Pavlov (Global Deliveries Director for HP), Rumyana Trencheva (CEO of SAP Bulgaria), Zornica Iankova (HP's HR Director), Kristina Stoitsova (R&D at VMware).

Modrator was webcafe.bg's owner Sibina Grigorova.


The event was highly entertaining for me. The public initially wasn't keen on asking too many questions. But the discussion afterwards proved interesting. I was happy to hear that female CEOs didn't feel male colleagues treated them differently. Still there are far more males than females in IT.


Of course I wore a @bgjug t-shirt.

[jug.bg] pi4j on RaspberryPi


Jug.mk's leader Pance Cavkovski is talking today about how to put java on a raspberry pi and then automate your home.

There is also a slide about NodeMCU that helps you distribute GPIO around your home and control different devices. NodeMCU is a wifi-to-GPIO for $5 basically, which is awesome:


Today was a busy day, the beer was over in seconds and that sucks because Ivan and I only had a beer.


I brought a Odroid C1. But pi4j doesn't work, so I used jOdro.

We have a new banner that we didn't forget to bring today, so there it is:


[jug.bg] A hackaton showcasing JSR 371 (MVC) 2015.09.30


On 30.09.2015 we did a workshop that showcased the very beta of MVC 1.0 implemented in ozark.

We had to use glassfish, which I somehow dislike, because I don't understand it and it didn't run very smooth, but in glassfish's defense I have to say that reloading the application without restarting worked like a charm. That is awesome.

MVC is promising and I like how simple it is.

The code is here: https://github.com/bgjug/mvc10-workshop.


[jug.bg] Hackaton to create a JBoss Forge plugin to create Spring Boot applications

So this weekend the Bulgarian Java User Group (jug.bg) organized a hackaton to try to create a JBoss Forge plugin to create Spring Boot applications.

JBoss Forge is a tool to ease development. Main traits are it can create JPA entities, It can create an example REST interface to those entities, a web interface to those entities and it integrates with Eclipse and IntelliJ IDEA:

Screen Shot 2015-08-12 at 11.51.02
Cmd+Option+4 in IDEA on OSX, Ctrl+4 in Eclipse on Windows

The code is here. Here are a couple of pictures from the event:

IMG_5514 IMG_5515IMG_5513


jdk1.8.0_25 internal compiler error

Screen Shot 2015-07-14 at 11.35.31

A bug report here: https://bugs.openjdk.java.net/browse/JDK-8065424

Information:Using javac 1.8.0_25 to compile java sources
Information:java: An exception has occurred in the compiler (1.8.0_25). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
Information:7/14/15, 11:22 - Compilation completed with 1 error and 0 warnings in 2s 319ms
Error:java: Compilation failed: internal java compiler error

[jug.bg] RabbitMQ session

Today we had a BGJUG event.

Martin presented RabbitMQ - Spring Framework's default message broker.
IMG_4964 IMG_4966


I followed the presentation and using Docker's GUI for OSX called Kitematic, easily created a rabbitmq server and a client in a maven project:

Screen Shot 2015-06-29 at 20.51.51Screen Shot 2015-06-29 at 21.07.04

Again there was a lot of beer, but since we have been accused of advertising beer brands, there will be no pics.


[jprime.io] Feedback

So, jprime.io is over, let's see how well we did:

Screen Shot 2015-05-28 at 17.15.33

Screen Shot 2015-05-28 at 17.18.33
Translation: A huge BRAVO. The organization was well done.
Screen Shot 2015-05-28 at 17.19.08
Translation: the event is exceptionally interesting. I learned a lot and I was inspired.
Screen Shot 2015-05-28 at 17.19.25
Translation: I liked it a lot. Please inform me if you plan to do anything again soon. The day was not wasted. Learned a lot.


Screen Shot 2015-05-28 at 17.23.25 Screen Shot 2015-05-28 at 17.25.20 Screen Shot 2015-05-28 at 17.25.33 Screen Shot 2015-05-28 at 17.25.48 Screen Shot 2015-05-28 at 17.26.02 Screen Shot 2015-05-28 at 17.29.57


Also in my inbox:

Tова което вчера казвах на Найден, че още от първата конференция бяхте много добри.


Translation: Basically Phillip is saying we are the best java conf here.


Another one:

Браво за конфа. Получи се доста добре.
Готиното беше, че хората наистина се събираха и си говореха.
Аз трябваше да тръгна по-рано, че имах малко лични ангажименти,
и изпуснах всичко след предпоследната лекция, но това на което бях,
наистина беше готино и се усещаше приятелската атмосфера 🙂


From: "Stefan Vartolomeev"

Translation: Stef is saying it was nice that people communicated and that the atmosphere was friendly and the feeling altogether was cool.


Screen Shot 2015-05-28 at 17.48.27Screen Shot 2015-05-28 at 18.02.35 Screen Shot 2015-05-28 at 18.03.31 Screen Shot 2015-05-28 at 18.03.43 Screen Shot 2015-05-28 at 18.04.03 Screen Shot 2015-05-28 at 18.04.22 Screen Shot 2015-05-28 at 18.05.49 Screen Shot 2015-05-28 at 18.06.09



I think we did well.

jprime: Why would someone organize a conference?

Every morning I wake up to this: Screen Shot 2015-05-20 at 23.09.29and this: Screen Shot 2015-05-20 at 22.21.30. Every day I wage a fruitless war to go down to zero on both fronts and I fail miserably. But I'm getting better.

Recently we managed to "inject" a company as a gold sponsor after all the deadlines have passed. We did it in 20 minutes after 6 phone calls.

The server firewall failed. Someone fixed it on a Saturday morning.

Our invoicing architecture after so many patches fails to follow all the complex branches of the process of issuing an invoice. We somehow manage to still use it fruitfully. And I have big plans for rewriting most of it.

ePay integration was a pain it the ass. Very bad documentation, different undocumented services, support could be better. But it was fun encrypting and decrypting a ton of messages until we stabilized it. We even "support" credit cards (in a way).

Our Turkish speaker delayed his visa application. I called the Bulgarian embassy in Ankara. They were nice, didn't forget to call me back. Actually they kept me updated the whole time. And they issued the visa in less than a day. So kudos to them.

We fight less, work more, plan better, became team players and learned a lot. Organizing a conference is fun.

Go buy a ticket at jprime.io.

[jug.bg] Simon Scholz presented Eclipse E4 in a bgjug event

Simon Scholz from Vogella presented Eclipse RCP development, the new Eclipse Mars (to be published in a month) and tips and tricks on migrating from eclipse 3 to eclipse 4.



There were also examples on Maven Tycho, SWTBot UI testing. Simon bragged about fixing issues on the dark theme of Eclipse, which I adore, so now it's even better.


Pretty funny, I had to pick Simon from the airport, so I had to have a sign:

Photo on 5-12-15 at 00.28


Sublime Text 3 with Javatar

So we in the Bulgarian Java User Group wanted to build Valhalla, and no IDE (Eclipse, Intellij Idea) supports it. We needed some simple text editor with some java support. And Sublime Text 3 (with Javatar) is the one we chose.

Sublime is a fancy editor written in C and Python. Javatar is a plugin that adds some Java support.

Installing Sublime Text 3 beta is straight forward. Installing Javatar is:

[openjdk@localhost valhalla]$ cd ~/.config/sublime-text-3/Packages/
[openjdk@localhost Packages]$ git clone git://github.com/spywhere/Javatar.git

Setting up the correct java is: Ctrl+Shift+P --> "javatar" --> Javatar Settings - Default

Then change the javac and java locations:

Creating projects is a bit uneasy - create new project is actually called "Project -> Save as".

And then we can run some code (fist compile, then run):

[jug.bg] Valhalla hackaton (29.01.2015)

Today we had a second bgjug hackaton for the month. Its topic was Valhalla.

Project Valhalla will probably be part of Java 10 (expected 2018). Among other things it allows using primitives as generic arguments.

Here's how you can build Valhalla yourself.

Here's a virtual machine with valhalla if you're lazy (virtual box).

This is the valhalla presentation by Ivan. And this is the video of the talk (in Bulgarian).


Here are some of the code we ran:

Ivan created a simple ArrayList

public class SpecialArrayList {
	private static int INITIAL_SIZE = 10;
	private T[] elements = null;
	private int length = 0;
	public SpecialArrayList() {
		elements = new T[INITIAL_SIZE];
	public T get(int position) {
		if(position &gt;= length) {
			throw new ArrayIndexOutOfBoundsException();
		return elements[position];
	public void add(T element) {
		// Check whether array is full
		elements[length] = element;
public class Main {
	public static void main(String[] args) {
		SpecialArrayList intList = new SpecialArrayList&lt;&gt;();
		SpecialArrayList stringList = new SpecialArrayList&lt;&gt;();

Nayden tested a bit of crazy code - which is supposed to fail (IA impl = new IAImpl();):

public class B  {
   protected T t;
   protected T[] ts;
   public B(){}
   public B(T t){
     this.t = t;
     this.ts = new T[100];
   //  System.out.println(this.t.getClass());
   public T[] getTs(){
     return this.ts;
   public T getT(){
     return this.t;
   public static void main(String[] args){
       B b = new B&lt;&gt;(100);
       System.out.println((new B("dada")).getClass());
       IAImpl ludnica = new IAImpl();
       System.out.println(ludnica.getT() instanceof Object);
       IABase base = new IAChild();
       IA impl = new IAImpl();
interface IA{
 public T getT();
 public void setT(T t);
class IABase{
 private T t;
 public T getT(){
   return this.t;
 public void setT(T t){
   this.t = t;
class IAChild extends IABase {
class IAImpl implements IA {
 private Object t;
 public Object getT(){
   return this.t;
 public void setT(Object t){
   this.t = t;

Building OpenJDK 9 on a OSX (or any linux)

This is a tiny tutorial on how to build your own copy of OpenJDK 9 from the current sources.


├─Install a package system
├─Install ccache
└─Command Line Tools
Download OpenJDK 9
Build OpenJDK 9
├─JTREG: The variables
└─Running tests


Install a package system

Install brew or macports. I prefer brew. Both are package systems for OS X.

Install ccache

ccache is a compiler cache - speeds up the build.

$ brew install ccache

Command Line Tools

We need them so we have a C compiler and other tools.

Install Xcode Command Line tools ( you don't need the whole Xcode, only the command line tools)

Download OpenJDK 9

Get the sources, in the console type:

$ mkdir jkd9
$ cd jdk9
$ hg clone http://hg.openjdk.java.net/jdk9/dev jdk9.hg

Takes 10-20 secs. This downloads basically a couple of scripts that we will execute to get the actual sources.

Now we execute the script we downloaded:

$ cd jdk9.hg
$ chmod u+x get_source.sh
$ ./get_source.sh

The last command can can take 10-20 minutes depending on the connection speed.

Build OpenJDK 9

$ chmod u+x configure
$ ./configure
$ make clean images

The second command took a bit less than 20 minutes. The first command is fast.

The result: we have this created:  build/macosx-x86_64-normal-server-release/images/jdk/ - this is the built OpenJDK 9 - SUCCESS.


jtreg is a "testing harness" (whatever that means) made specially for OpenJDK. We need it to run the tests written for the OpenJDK

Download from https://adopt-openjdk.ci.cloudbees.com/view/OpenJDK/job/jtreg/ (not the Snapshot version, the other one).

unzip in jdk9, so we have jdk9/jtreg.

JTREG: The variables

The official instructions suggest we edit ~/.bashrc. I don't like changing global (for your user) settings, so we can put these settings in jdk9/.bashrc

$ nano .bashrc

Add the following lines:

export SOURCE_CODE=/Users/steve/jdk9/
export PRODUCT_HOME=$SOURCE_CODE/jdk9.hg/build/macosx-x86_64-normal-server-release/images/jdk
export PATH=$PATH:$PRODUCT_HOME/bin:$JT_HOME/linux/bin/

NOTE: Change /Users/steve/jdk9/ with your folder on the top line.
NOTE: Check the correctness of PRODUCT_HOME too.

To execute this file, do:

$ source .bashrc

Running tests

$ cd jdk9.hg/test
$ make jdk_util


Webrev crawls over your changes to generate a set of web-based views of the differences in your code. The different views allow reviewers to easily look at your proposed changes, selecting the appropriate difference format based on the type of file, the type of change, and their own preferences.

webrev.ksh is a 70kb kshell script. Pretty weird.

Go to jdk9.hg and:

jdk9.hg# wget http://hg.openjdk.java.net/code-tools/webrev/raw-file/tip/webrev.ksh
jdk9.hg# chmod u+x webrev.ksh

To prepare a webrev, make some changes. For example in the jaxp folder. Then we commit locally in the mercurial repo.

jdk9.hg# cd jaxp
jaxp# hg commit -m "BGJUG: Fix compiler warnings in jaxp repository"
jaxp# ../webrev.ksh

It will prepare a webrev/ dir and webrev.zip. The folder is then uploaded somewhere and sent to the appropriate mail list inside openjdk. Example:

Note: execution times come are measured on a pretty recent Macbook Air.

Source: https://java.net/projects/adoptopenjdk/pages/AdoptOpenJDKBuildInstructions

[jug.bg] Building Valhalla and using primitives as generic arguments

Project Valhalla will probably be part of Java 10 (expected 2018). Among other things it allows using primitives as generic arguments.

Building Valhalla

On a linux/unix/osx box we start with:

hg clone http://hg.openjdk.java.net/valhalla/valhalla
cd valhalla
bash get_source.sh  #this one takes some time
bash configure
make clean images # this one takes some cpu


We can have a class like this:

public class Program  {
	public static void main(String[] args) {
		// this one still doesn't work, List not updated to List
//		List l = new ArrayList();
//		l.add(5);
//		System.out.println(l.get(0));
		Box b = new Box(6);
class Box {
    private final T t;
    public Box(T t) { this.t = t; }
    public T get() { return t; }


Running javap gives

$ javap -c Program.class gives:
[openjdk@localhost bin]$ ./javap -c Program.class 
Compiled from "Program.java"
public class Program {
  public Program();
       0: aload_0
       1: invokespecial #1                  // Method java/lang/Object."":()V
       4: return
  public static void main(java.lang.String[]);
       0: new           #2                  // class "Box${0=I}"
       3: dup
       4: bipush        6
       6: invokespecial #3                  // Method "Box${0=I}"."":(I)V
       9: astore_1
      10: getstatic     #4                  // Field java/lang/System.out:Ljava/io/PrintStream;
      13: aload_1
      14: invokevirtual #5                  // Method "Box${0=I}".get:()I
      17: invokevirtual #6                  // Method java/io/PrintStream.println:(I)V
      20: return

Running our pretty simple app gives:

[openjdk@localhost bin]$ ./java Program
Specializing Box${0=I}; searching for Box.class (not found)
Specializing Box${0=I}; searching for Box.class (found)
[openjdk@localhost bin]$

Notes: List is still not parameterized with because ... issues.

Building OpenJDK and submitting a solution on a feature request with the Bulgarian Java User Group

So yesterday was a memorable day.

We gathered the Bulgarian Java User Group and, as a hands-on-lab, in 3 hours we created a pretty complex patch on a open issue in the JDK Bug System. We plan to submit a webrev patch after we polish the code and supply better tests.

We've been playing with the OpenJDK code for quite some time. We have setup an easily distributable virtual machine (actually two virtual machines - fedora and ubuntu) that can be found here:
They have everything in there with clear instructions on how to build the code and start IntelliJ IDEA as the IDE.

The issue is this one:
That has been a request for quite some time. Apache Commons Lang even has an utility method.

Here are the slides of the hackaton:
And here are the instructions:

We even had some beer:

The patch included a pretty heated discussion on whether we should use the Apache's Commons Lang approach:

public static String getStackTrace(Throwable throwable) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw, true);
    return sw.getBuffer().toString();

or we should rewrite some private classes inside java.lang.Throwable.

Here's the updated Throwable code:
First we added a method:

 * Returns string representation of this throwable and it's backtrace.
 * @return string representation of this {@code Throwable} and it's backtrace
public String getStackTraceString() {
    final StringBuilder sb = new StringBuilder();
    printStackTrace(new WrappedStringBuilder(sb));
    return sb.toString();

We renamed the ill-named PrintStreamOrWriter to StackTraceFacade and added another implementation:

private static class WrappedStringBuilder extends  StackTraceFacade {
    private static final String NEW_LINE = System.getProperty("line.separator");
    private final StringBuilder builder;
    WrappedStringBuilder(StringBuilder builder) {
        this.builder = builder;
    Object lock() {
        return builder;
    void println(Object o) {

We decided to reimplement and change the private inner class, because the Commons Lang uses StringWriter that internally uses the StringBuffer which is synchronized and we don't want that, since we sync on an upper level.
Here's a small JTREG test we created:

import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;
import java.lang.Throwable;
 * @test
 * @bug 5050783
 * @summary Basic test of serialization of stack trace information
 * @author Bulgarian JUG
 * @run testng java.lang.Throwable.GetStackTraceString
public class GetStackTraceString {
    public void doTest() {
            double a =100/0;
        }catch (Throwable t){

Execute xpath queries on html downloaded from a url with java using eclipse luna

FYI: Eclipse Luna (4.4) is currently beta.

Create new Maven Project.

Open the pom.xml

Add the following dependencies:


The code is as follows:

package sty.qainjava.xpath.on.html;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.nio.charset.Charset;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.htmlcleaner.CleanerProperties;
import org.htmlcleaner.DomSerializer;
import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.SimpleHtmlSerializer;
import org.htmlcleaner.TagNode;
import org.w3c.dom.Document;
 * QAinJava: how to do an xpath on html in java.
 * We use <a href="http://htmlcleaner.sourceforge.net/">HtmlCleaner</a>
 * and <a href="https://hc.apache.org/">HttpClient</a>.
 * @author Mihail STY
public class Program {
	 * We're not using any methods so that the source code is as straight
	 * forward as possible.
	 * No exception handling at all for simplicity
	public static void main(String[] args) throws IOException,
	        ParserConfigurationException, XPathExpressionException,
	        TransformerException {
		String address = "https://www.google.com/";
		String html;
			// the httpclient part
			CloseableHttpClient httpclient = HttpClients.createDefault();
			HttpGet httpGet = new HttpGet(address);
			CloseableHttpResponse response = httpclient.execute(httpGet);
			HttpEntity entity = response.getEntity();
			ContentType contentType = ContentType.getOrDefault(entity);
			Charset charset = contentType.getCharset();
			BufferedReader r = new BufferedReader(new InputStreamReader(
			        entity.getContent(), charset));
			// we can directly plug the input to HtmlCleaner,
			// but we put it in a string so we can print it,
			// or save it to a file
			String line = null;
			StringBuilder builder = new StringBuilder();
			while ((line = r.readLine()) != null) {
			html = builder.toString();
		{// write html to a file
			BufferedWriter bf = new BufferedWriter(new OutputStreamWriter(
			        new FileOutputStream("google.html.xml")));
			// exception handling is not exceptionally good, but that's not our
			// focus here
		// HtmlCleaner part
		TagNode tagNode = new HtmlCleaner().clean(html);
		String cleanHtml = new SimpleHtmlSerializer(new CleanerProperties())
		// System.out.println(cleanHtml);
		{// write cleanHtml to a file
			BufferedWriter bf = new BufferedWriter(new OutputStreamWriter(
			        new FileOutputStream("clean.html.xml")));
			// exception handling is not exceptionally good, but that's not our
			// focus here
		// we need a DOM document to execute xpath, HtmlCleaner helps in creating one
		Document doc = new DomSerializer(new CleanerProperties())
		{// save dom to file with a transformer (just for testing purposes)
			TransformerFactory factory = TransformerFactory.newInstance();
			Transformer transformer = factory.newTransformer();
			transformer.transform(new DOMSource(doc), new StreamResult(
			        new File("dom.html.xml")));
		// the xpath part
		XPath xpath = XPathFactory.newInstance().newXPath();
		String imgURL = (String) xpath.evaluate("//img/@src", doc,
		//using two URLs we can make sure we get the absolute URL even if relative.
		System.out.println(new URL(new URL(address), imgURL).toString());

Two problems

  • Some people, when confronted with a problem, think, "I know, I'll use regular expressions." Now they have two problems.
  • Some people, when faced with a problem, think, "I know, I'll use #binary." Now they have 10 problems.
  • Some people, when confronted with a problem, think, "I know, I'll use #threads," and then two they hav erpoblesms.
  • Some people, when confronted with a problem, think "I know, I'll use #multithreading". Nothhw tpe yawrve o oblems.
  • Some people, when confronted with a problem, think, "I know, I'll use mutexes." Now they have
  • Some people, when confronted with a problem, think: "I know, I'll use caching." Now they have one problems.
  • Some people see a problem and think "I know, I'll use #Java!" Now they have a ProblemFactory.
  • Some programmers, when confronted with a problem, think "I know, I'll use floating point arithmetic." Now they have 1.999999999997 problems.
  • Some people, wanting an escape from their full-time job, think "I know, I'll contribute to open source." Now they have two full-time jobs.
  • Some people, when confronted with a problem, think: "I know, I'll think outside the box!" Now, they have 3.75 problems, an entirely new framework, and three dozen toll house cookies cooling in the kitchen.
  • Some people when confronted with a desire to use pithy quotes in their presentations think "I know, I'll use something from Star Wars". Now two problems they have.
  • Some people, when confronted with a problem, think, "I know, I'll use #UTF8." Now they à??????µ?ç°§ùÔ_¦Ñ?.
  • "I'll use #PHP!" Now they have ("1 apple" + "1 orange") problems.
  • "I'll use #Perl!" Now they have more than one way to have more than one problem....
  • Some people, when confronted with a problem, think, "I know, I'll use Shareware." Now they have two trials.
  • Some people, when confronted with a problem, think, "I know, I'll use delegations." Now their problem is a problem of their problem.
  • Some people when confronted with a problem think "I know, I'll quote jwz". Now everyone has a problem.

Source: http://nedbatchelder.com/blog/201204/two_problems.html

highlight code (xml, javascript, java, php, c#....) in html

Screen Shot 2013-08-19 at 2.39.59 AM

How can one highlight (use a code color scheme) for source code or xml or html and do the following and do it in any html page?
Like this:
Screen Shot 2013-08-19 at 2.38.24 AM

One can use a javascript library. Instead of explaining how it works, here's the trick:

  <pre name="code" class="xml:nogutter:nocontrols">
    <?xml version="1.0" encoding="UTF-8"?>
      <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
                      <news:name>Kenosha News</news:name>
                <news:title>On target: Archer sets county fair record</news:title>
  <link type="text/css" rel="stylesheet" href="http://syntaxhighlighter.googlecode.com/svn-history/tags/1.5.1/Styles/SyntaxHighlighter.css" />
  <script language="javascript" src="http://syntaxhighlighter.googlecode.com/svn-history/tags/1.5.1/Scripts/shCore.js"></script>
  <script language="javascript" src="http://syntaxhighlighter.googlecode.com/svn-history/tags/1.5.1/Scripts/shBrushXml.js"></script>
  <script language="javascript">

The important part is:


xml = the language
nogutter, nocontrols = options
http://syntaxhighlighter.googlecode.com/svn-history/tags/1.5.1/ = I don't want to include these in my project, so I use them remotely, you can download them locally, but download all.
Add the js libraries for the languages you use. For xml I added shBrushXml (see the code).

Supported languages: https://code.google.com/p/syntaxhighlighter/wiki/Languages
Configuration options: https://code.google.com/p/syntaxhighlighter/wiki/Configuration

Java allows a trailing comma when enumerating arrays and enum values?

public class Peshev {
    public static void main(String... args) {
        String[] fff = new String[]{"a", "b",};

Do you see the trailing comma after "b"? That's allowed. Unexpected from a strongly-typed lang as Java.

Can I watch 1080p torrents while they are still downloading on OS X? — YES (ver.2)

This is ver1 of this manual. Ver2 is updated with a better torrent client.

A 1080p movie is around 4 -8GB in size. Downloading this takes a while even on 50mbit connection.

What if it is possible to watch while downloading? So watching starts right away.

  • We need a torrent client that can download the movie file parts in order, not randomly.
  • We need a player that supports playing incomplete files.
  • We need a connection that is faster than the movie's bitrate.

The torrent client

Previously I used BitThief. It is developed by a technology institute in Zurich. It didn't have a polished GUI and took a little bit too much CPU while downloading.

The new client I found thanks to diimdeep. It is called qbittorrent and it is awesome.

Screen Shot 2013-03-17 at 9.24.31 PM

You can see that while downloading it downloads as a normal torrent client - the parts are downloaded randomly:

Screen Shot 2013-03-17 at 9.27.38 PM

But there is an option:

After that we can see that the rest of the file is being downloaded sequentially (blue - downloaded, green - requested):

The connection speed

How can we tell if the speed is good enough? By the estimated time of arrival (ETA):

If the movie is 1.5 hours and the ETA is 17 minutes, then the speed is sufficient.

The player

The player is and always has been mplayer. I use MplayerX because it comes with a nice OSX gui. Download and associate movie files with mplayer (avi, mkg):

Screen Shot 2013-03-17 at 9.45.59 PM

The final step is to to play the file after the downloading started:

That's it.

Screen Shot 2013-03-17 at 9.41.25 PM

Happy watching.

Longstanding Eclipse issues - fix them finally, please

Eclipse is the best IDE ever. It's the most stable, most popular, most- a lot of things. The developers that write the Eclipse code have T-shirts that say that - they are that proud. The code-base is said to be awesome - I don't have time to check. But, there are some longstanding issues.

First, SVN client. There's a CVS client that comes with Eclipse. SVN is way more popular. Put the client inside finally. I'm sick of solving numerous JavaHL issues. Fix it. I don't care how, just do it.

Second, Tomcat is the best web container ever and most popular in development. Integrate it better. There are numerous issues with debugging, redeployment and so on. These problems are so old. Fix 'em NOW.

Third, installing plugins is soooo slow. So very slow.

Fourth, web development is not that well integrated. WTP is still buggy, there are issues with configurations, deployment and so on.

Update: Fifth, autocomplete should put jdk classes/interfaces first!!! This is so important. Screenshot:

WTF is antlr.collections?! Are you kidding me?

Now, I'm trying to launch a main method without the "String... args" parameters and Eclipse cannot find it. This is also a longstanding problem.

This works:

public static void main(String... args)

This does not (eclipse cannot find the method):

public static void main()

I'm pretty sure there's a solution, but I'm not going to waste time searching for it.

I've wasted time with compilation, memory, various configurations with xml and whitespace also.

There are always solutions, but this is wasted time. What are the developers working on? Stupid pointless features? Fix these please. Please.

Installing PostgreSQL 8.4.x (8.4.8-1) and 9.x (9.0.4-1) on OS X Lion with EnterpriseDB installer (fix)

Postgres for Mac OS X has three install options:

  1. Using a package management system. Fink, MacPorts and Homebrew all have it. I've tried only MacPorts and it works fine.
  2. Manually downloading and compiling it.
  3. Using EntrepriseDB's installer. It can be found here.
Options 1) and 2) require Xcode. Xcode is a large development package for OS X. It installs an IDE, compilers and unix tools. Options 1) and 2) use the unix tools.
I don't want to install Xcode, even though there is a way to limit it's memory footprint. Here's how (the question was with negative rating when I found it, but the answer is useful).
Anyway I don't want to install Xcode, and on my last OS X I only installed a couple of databases. That made the whole ports thing a bit useless.
So I tried the EnterpriseDB's installer. It failed with
Problem running post-install step. Installation may not complete correctly
The database cluster initialisation failed.
The official sites said: Lion is not yet supported: link. I didn't want to install some package management solution so I wanted a solution.
I found one here. On a poker site - kill me now. It seems to be the easiest one. Just create a postgres user using the Users & Groups preference tab. Don't create a Sharing only user, it doesn't work with it - I tried. Create a normal user. Everything works like a charm:
I tried the new postgres 9.0.4, but it failed with "invalid stream header: BB656430" when serving binary data from an import from 8.4.x. I went back to 8.4.x.
EntrepriseDB's installer creates an uninstaller, installs pgAdmin, works nice. User-friendly.