Pages
Friday, September 9, 2011
JavaZone 2011: Bytecode for discriminating developers
Saturday, September 3, 2011
Destination: JavaZone, Oslo, Norway
There's plenty of interesting sessions on the schedule that I'm tempted to attend myself.
Wednesday, August 31, 2011
Tuesday, August 30, 2011
GeeCON 2011: Java Bytecode For Discriminating Developers
The related blog posts:
Monday, August 29, 2011
What’s Cool In IntelliJIDEA. Part III: External Tools
What’s Cool In IntelliJIDEA. Part I
What’s Cool In IntelliJIDEA. Part II: Live Templates
Although there is almost any kind of functionality available in IntelliJIDEA, either as a base functionality or via plugins, there's still a fraction of probability involved that you might want to do something that goes beyond the power of the IDE. For such rare cases you might want to take a look at External Tools in IntelliJ.
Just recently I've encountered such a case myself - I wanted to use an utility from JDK, but in a more flexible way than just switching to command line and navigating to the correct location. My idea was that I should just press an arbitrary shortcut and get the result. So I decided to give External Tools a try.
The utility I use a lot when studying Java is javap - the java class file disassembler. This is due I study the bytecode sometimes. And although there's ASM plugin available for IntelliJ that basically can provide me the result I needed, I still prefer to read the raw javap output.
To setup javap in Intellij as an External Tool go to Settings >> External Tools and press Add... . You can then define the location of the tool, the working directory, and the parameters.
The nice part of it is that IntelliJ provides some basic macros in order to dynamically resolve the parameters for the tool. So for javap it was enough to set $FileClass$ for the parameter, and $OutputPath$ as the working directory. And that's it - the tool is now ready for use.
You can also define a "group" which is then used to group the external tools in the popup menu. I use "jdk" as a group name for javap so here's what it looks after:
So that's cool but you might have noticed that it is not that comfortable to use - have to right-click the file, navigate to "jdk" group, expand it, and only then can execute javap. Well, shortcuts to the rescue! Browse to Settings >> Keymap, and there you can define any sortcut for the tool. The nice part of it is that IntelliJ detects if you select a conflicting shortcut and notifies you.
One more tweak left to do. Once I press the shortcut that I've assigned to javap, the result of decompilation is printed out to the IDE console, which is just below the source code. But it would be more convenient to see it side by side. For that, it is possible to drag-and-drop the Run window to the side panel in IntelliJ so the result can be observed right next to the source I'm currently working with.
The only thing that is probably missing is the syntax highlight for the javap output, but that is probably too much to wish.
Tuesday, August 2, 2011
Code Snippet: Redirecting Standard Output to File
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
public class SystemOutRedirect {
public static void main(String[] args) throws FileNotFoundException {
System.setOut(new PrintStream(new FileOutputStream("stdout.txt")));
System.setErr(new PrintStream(new FileOutputStream("error.txt")));
System.out.println("hello"); //goes to stdout.txt
System.err.println("error"); //goes to error.txt
}
}
Wednesday, July 27, 2011
Using JRebel with MyEclipse Blue and WebSphere
JRebel 4.0.x
See the press release.
Monday, July 25, 2011
JVM Language Summit 2011
Back from Santa Clara, CA where I've attended an awesome event - JVM Language Summit. Before the event I thought I know some Java, but it seems I was too self-confident :) The 3 days of technical sessions revealed to me a lot of new things in Java world, including the new features coming in the next versions of Java as well as some JVM-based languages that I didn't pay attention to previously.
Day 1
The event started with a short intro by Brian Goetz followed by a keynote speech by Cameron Purdy. Cameron presented an awesome wishlist for the upcoming versions of Java/JVM. Some of the features I liked the most on that list:
Immutability. The main concern was pretty much about how could Java get so far without immutability natively supported by the language?
Obvious Intrinsic Types are just missing from Java. And this is the major pain for the developers dealing with financial calculations whereas the rule of thumb is - never use double for operations on monetary values. Indeed, every Java programmer should see this presentation - How Java's Floating-Point Hurts Everyone Everywhere. The good news is, IEEE 754-2008 a.k.a. IEEE 754r – defines decimal types, the bad news, it is not yet implemented.
Alternative class format is something that tool implementers would definitely love - why inner classes aren't inner classes? why anonymous classes are not properties of a method where they are defined?. In fact, I was carrying the idea around with myself on why not to try to implement the class nesting into the VM? I was actually thinking it is a crazy idea of mine but it turns out other people do have same crazy ideas! :)
Tail Recursion / Tail Call Optimization is something that every developer, who tried some FP language, misses from Java. I've tried Erlang a while ago, and after a few weeks I really could live without this feature.
Cameron had plenty of other stuff on the list but I'd rather skip mentioning all the points. The presentation slides are available here.
Async .NET
It was quite an interesting presentation by Mads Torgersen. It is nice to know, what are the people working on the other major managed runtime come up with in a while. The main feature that Mads was talking about was the asynchronous task execution coming in C# 5. Basically it is similar to what Java has with Futures. The presentation slides are available here, and actually I've found a video on the same subject at Channel 9 - recommended!.
Indy FTW!
Now it was all about invokedynamic, method handles, call sites, etc. First, John Rose talked about Method Handles. And after that, Dan Heidinga talked about the method handles implementation in IBM J9.
These followed by the language implementers - demonstrating how invokedynamic and method handles can be used: Charles Nutter on JRuby, and Remi Forax on JSR-292 Cookbook. JRuby folks take a great advantage of the invokedynamic which allows a lot of optimizations hence improving the performance. Remi Forax presented a number of Method Handle usage tips. The collection can be found at https://code.google.com/p/jsr292-cookbook. One really cool thing I've got to know is the ClassValue which can serve as a metadata carrier that might be required for dynamic method invocation.
Day 2
The first half of day 2 was mostly related to all the same JSR-292 features: porting Smalltalk to JVM, new implementation of JavaScript on JVM, Jython&Indy.
Dynalink, presented by Attila Szegedi, is an interesting project for dynamic linking in Java - as far as I understand Dynalink could be used to implement invokedynamic behavior on JVM.
After all the dynamic fluff-and-stuff the statically typed languages came on stage.
Gosu. Honestly, I underestimated the language when I learned about it the first time. This time I was actually surprised by the features presented in Gosu, accompanied with compiler support and the open type system. A couple of years ago I used Drools and Groovy to implement the rules-based system. If I knew about Gosu at that time it would probably be my language of choice. Especially neat is that one can basically connect some XML or properties file to the type system and tell that this is a new type in Gosu, and get all the type-checking backed by the compiler. Just awesome!
Gosu doesn't seem to tackle any of the general-purpose language but it definitely has its niche - a statically-typed language for writing business rules.
Project Kotlin, presented by JetBrains developers, Andrey Breslav and Dmitry Jemerov, has definitely created a lot of buzz by now. According to the creators, Kotlin is designed to be nicier than Java, and simpler than Scala. Here're the slides from the presentation & the workshop. At first sight, the language is definitely nice to read and the syntax seems to be more friendly than in Scala, but going deeper into more advanced features, the claim tends to diminish. I noticed a lot of similarities with Scala, Groovy and C#, whereas C# features (i.e. non-virtual methods) do not seem as coherent with the other two languages. I do not have any strong opinion on the project yet - need to study it a bit and compare to other languages (read Scala) but one thing I quite sure about is that the IDE support should be top class. There are a lot of opinions currently, whether JetBrains should rather have contributed to Scala tooling, or Ceylon project.. don't know what is best - time will show. I do understand the scepsis of Scala fanboys regarding Kotlin, but it is quite stupid to underestimate this effort. IMHO, nothing replaces Java any time soon - it rather benefits of all the language experiments.
Day 3
On the day 3 there have been a few talks related to Java language itself.
Interface injection by Tobias Ivarsson, Extension Methods & Lambda Bytecode by Brian Goetz - awesome content and ideas presented. IMO, properly combined autoboxing, interface injection and extesion methods with lambdas could enable ruby-like syntax in Java, e.g.
5.times({ int x -> println(x); }. Neat, huh? A very interesting project Graal, presented by Thomas Wuerthinger (one of the core developers on DCEVM. Graal includes a mechanism to execute the compiler outside of the HotSpot JVM which leads to "distributed compilation".
At the end Prashant Deva talked about the Chronon debugger. In fact, it turns out that Chronon isn't really a debugger but you can rather record the dataflow of your program execution and do "post-debugging" using the data recorded at runtime. It really looks as if you're debugging in the IDE, stepping through the lines of code and observing the values of variables. But technically, the plugin doesn't even connect via JVMTI - it rather emulates the program under inspection - executing queries to the recorded data set and jumping to the correct line of code in the IDE.
Summary
I think this was the most advanced and interesting Java-related event I've attended so far. I really feel myself being so dumb now - very motivating to finally take a look at some textbook on the compiler construction :)





