Writing JVM bytecode by hand using GroovyJVM bytecode looks similar to Assembly code. It maps to it closely enough that translating it into machine code shouldn't be too much of a challenge.
Writing it can be quite challenging, but it can be quite useful to understand the inner workings of the JVM.But before we see how to use the Groovy compiler to let us write bytecode by hand (and create pure JVM bytecode that does not require Groovy at runtime!), let's have a quick crash-course on JVM bytecode.
A short introduction to JVM bytecode
Instructions operate on a frame consisting of an operand stack and an array of local variables (amongst other things).
For example, to load the value of an object ...
Posted Jan 30, 2017, 2:24 PM by Renato Athaydes
4 free ways to hot-swap code on the JVMThe JVM is a wonderful piece of engineering with a lot of great features. One feature that many developers don't seem to realize exists is that the JVM (I am referring to Oracle's HotSpot, but this applies to others as well) is capable of hot-swapping code. In plain English, you can load changed code into a running JVM and immediately see the effects of your changes.
In this blog post, I will present 4 different ways of doing this, none of which requires paying for a product or license, starting from the rawest, but simplest one, and moving towards more complex (but not necessarily harder-to-use) alternatives.
Unfortunately the simplest way is also the least powerful ...
Posted Feb 18, 2017, 8:06 AM by Renato Athaydes
OSGiaaS-CLI - A CLI to run JVM-languages REPL and commandsEvery now and then, like most technical people, I feel the need to run some CLI (command-line-interface) commands to perform a quick, usually repetitive task. The operating system provides a lot of commands (ls, cat, cp, rm, grep...) that can be wired together to perform certain kinds of tasks (like deploying your application to Amazon, or even finding the cheapest flight somewhere!). There's even a venerable name for this: the Unix philosophy, though this approach can be used in any OS.
The Unix-way can make you very productive, so much so that some folks even think that Unix is an IDE because of that.
However, a lot of times you will find yourself trying to do ...
Posted Feb 6, 2017, 11:28 AM by Renato Athaydes
Solutions to multiple inheritance in KotlinI have recently come across a little problem that recurs from time to time as I write new code.I had a base class with some really useful methods that I wanted to make another class extend, but the ditto class already extended some other, equally useful, base class.If this were Java, I would just add a field to the class, using composition rather than inheritance and be done with it, even if that felt a little clunky, after all that's the best you can do in Java.However, these days I'm using Kotlin more often than not. Moving on with the times, I guess!Anyway, Kotlin has a really interesting feature called class delegation, which allows ...
Posted Nov 29, 2016, 2:23 PM by Renato Athaydes
Using Java annotations as pure data valuesAnnotations were introduced to the Java programming language in the 1.5 version, circa 2004. Since then, Java annotations have been adopted with gusto by framework developers, to the point where today, a Java application class might look like little more than scaffold for the annotations themselves, leaving all the actual work to be done by the framework itself.It was not always that way. Initially they were used just to provide additional information to the programmer (@Override, @Deprecated) or the compiler (@SuppressWarnings), but new uses for them have been devised and now include ORMs, serialization, execution control (JUnit), bytecode instrumentation (metaprogramming via annotation processors), Dependency Injection, stricter type-checking and, finally, configuration. Arguably, configuration is the most contested use ...
Posted Oct 19, 2016, 2:37 AM by Renato Athaydes
osgi-run Tutorial - run your Java/Kotlin/Frege code in OSGiWhat you'll learn in this tutorial:Introductionosgi-run is a Gradle plugin that makes using OSGi as easy as using Gradle.To get started with this tutorial, you need to have Java and Gradle installed. It is assumed you have basic knowledge of both.Some very basic OSGi knowledge is also assumed.To make it easy for you to follow along, a GitHub project was created to back this tutorial.Instead of creating the files described below, you can simply checkout the appropriate git branch and run and modify the code as you wish.The git branch at each stage of the tutorial is shown in bold, blue font, as in the following example where master is the ...
Posted Sep 4, 2016, 7:41 AM by Renato Athaydes
Efforts to get Ceylon running on the Dart VM are well under way.
However, my main interest in using Ceylon has been to run code on the JVM, and I noticed that to use Java libraries in Ceylon was not as straightforward as in Java itself using Maven or Gradle.
The problem is that, even though Ceylon has its own module dependency resolution engine which works great for Ceylon modules sourced from Herd or local repositories, and which theoretically supports also Maven dependencies ...
Posted Feb 8, 2016, 8:54 AM by Renato Athaydes
Using Swing-Selectors to split up layout-style-logic in UIs with GroovyIntroducing Swing-SelectorsSwing-Selectors is a project I've been working on that takes some pretty nice code from the Automaton testing framework (don't worry, it's not stealing, I wrote most of it) and makes it available as a separate library, which makes it easy to, as the name says, select items from a Swing UI.This code is at the core of Automaton's Swinger and lets its users do things like click on something that has the text "click me", or drag the component with name "foo" to "bar", for example.Making it a separate library is a good idea, I think, because Swing developers might want to use the selection mechanisms outside of the ...
Posted Jun 9, 2016, 10:42 AM by Renato Athaydes
Evaluating a programmer's efficiency with realistic programming tasksMy wife is an operations management researcher and she is currently working on a thesis about the productivity of information workers at the individual level.It is a difficult issue, of course, but that's why it merits being the subject of a PhD thesis, after all! One of the studies that will serve as a basis for her thesis is called IT-enabled Productivity and its aim is to find out "how information and communication technologies may be used in organizations to contribute to productivity gains".Software developers fall under the category of information workers, and measuring the productivity of software developers is a notoriously difficult problem, even more so, I'd imagine, than for other information workers such ...
Posted Sep 27, 2015, 1:34 PM by Renato Athaydes
A Groovy Webserver running on Raspberry Pi in minutesI have just bought a Raspberry Pi to have some fun with code first and, hopefully, hardware later.After setting it up (with the Raspian OS, a Linux distro for the Pi), making sure it could connect to the internet and I could ssh into it from my laptop, the first thing I wanted to do was to get it to run a little webserver.I have recently attended a Java meetup (in fact, the very first one in Stockholm) where one of the speakers demoed the Spark-Java micro-framework, and it really caught my attention. Starting up a webserver and providing a simple REST API or just plain HTML with it is as easy as it gets so ...
Posted Jan 2, 2015, 5:06 PM by Renato Athaydes
Creating a simple JavaFX 8 app and testing it with AutomatonI have finally given Automaton 1.1 the last touches and released it, making it publicly available at Bintray's JCenter. I believe that with the newest features and bug fixes (see the release notes for a full list) Automaton has really become an awesome framework to allow anyone to thoroughly test their UIs (JavaFX, Swing or mix of both) in a very similar manner to some great UI-testing frameworks such as Selenium and Geb.
In this blog post, I would like to show how to create and test a JavaFX application using pure Java code and, alternatively, using FXML (a UI-layout markup language similar to HTML) and the Scene Builder, a free designer tool which greatly eases ...
Posted Jul 29, 2014, 2:01 PM by Renato Athaydes
Give your code some space!
I have seen recently quite a few different coding conventions regarding the use of white spaces being used by different development teams. This has intrigued me as I have always thought that there ought to be a "best convention" for white spaces, and code format in general. In practice, this seems not to be the case. But this begs the question: why does every team, if given the option, seems to come up with different rules (or lack of rules) for what they consider to be the best use of white spaces?
To start with, I would like to discuss the Java code convention used by default in most Java IDEs.
Here's an example:
publicclass Example ...
Posted Jun 1, 2014, 10:11 AM by Renato Athaydes
A Groovy Web Server to serve static and Groovlet-generated contentGroovy makes creating a lot of things extremely easy! For example, you can create a GUI application or a library to "talk" to your DB with just a few lines of Groovy code.
Another thing that is really easy to do with Groovy is create your own HTTP server to provide both static content (mapping URLs to files in your file system) or code-generated pages using Groovlets.
But unfortunately, most tutorials you'll find on the Internet to show you how to do this are quite out of date.
So, unless you're reading this much later than May 2014, here's how you achieve that with Groovy and one of the latest versions of Jetty:
Posted May 24, 2014, 5:28 AM by Renato Athaydes
Java 8, Haskell, FP and MonoidsI've been writing some code using Java 8 to get familiar with it. As any Java developer should know, Java 8 is just about to be released (if there's no more delays, it will come out in March 2014), so there's no more time to wait to get our hands dirty!Java 8 brings a volume of changes when compared to Java 7 never before seen between single major releases. Lambda expressions, mixins, streams and its rich, fluent API, a new Date Time API, to mention but a few novelties.Clearly, Java 8 focuses on bringing Functional Programming (FP) to Java programmers. But what exactly is FP, why does everyone seem to be so excited about it ...
Posted Mar 1, 2014, 2:02 PM by Renato Athaydes
Strange String issues in JVM languagesI always trusted that I could safely use Strings in Java, after all String is one of Java's core classes and, probably, THE most used class.
That's why I was quite surprised with a few blatant String fails demonstrated in this blog post (in the Musing Mortoray blog) which simply claims, and actually shows, that the String type is broken. Not only in the JVM world, by the way!
I will not repeat what that blog says here, please read that. I just wanted to show here the results I got with my favourite languages.
I used the following test Strings:
"😸😾", "noël", "baffle", "abc"
The first one should look like a happy cat followed by a ...
Posted Dec 6, 2013, 1:08 PM by Renato Athaydes