Posts Tagged ‘java’

Low-latency painting in AWT and Swing

Posted in Programming on December 20th, 2015 by Pavel – 7 Comments

00:00:00In this article I enumerate reasons why typical approach to painting in AWT / Swing can result in substantial visual lags, provide examples that demonstrate the problem and propose methods to significantly reduce the drawing latency.

Despite the focus on Java platform, the key ideas can be extended to most modern operation systems and GUI frameworks.

Contents:

  1. Problem statement
  2. Typical implementation
  3. Asynchronous painting
    3.1. Queue delay
    3.2. Request skip
    3.3. Region extension
    3.4. Component reordering
  4. Synchronous painting
    4.1. Component opacity
    4.2. Buffering overhead
    4.3. Showing delay
    4.4. Buffer reuse
  5. Active rendering
    5.1. Incremental painting
    5.2. Pipeline flush
  6. Summary

All key points are accompanied by short, shelf contained, compilable examples that clearly demonstrate the theoretical concepts in practice. The code is also accessible as a GitHub repository.
Continue reading →

Install IntelliJ IDEA on Raspberry Pi

Posted in Linux, Programming on June 11th, 2015 by Pavel – 15 Comments

Raspberry Pi and IntelliJThis article shows how to install IntelliJ IDEA on Raspberry Pi. The instructions are also applicable for other IDEA-based IDEs like PyCharm, RubyMine, PhpStorm, WebStorm, CLion, etc.

At first, the idea of installing a full-fledged, contemporary IDE on Raspberry Pi may seem unrealizable. Raspberry Pi boards are incredibly small, so it’s hard to believe that those devices are apt for such a task. Nevertheless, in reality, Rasperry Pi can do much, much more than blinking a LED.

After trying out Scala on Raspberry Pi for some time, I configured my Rasperry Pi to run IDEA & Scala plugin for the recent ScalaDays conference. While it was initially intended to be just a “proof of concept”, it turned out that we were able to open the Scala plugin project itself (which is pretty large, and includes all IDEA CE sources) and to comfortably use this setup for most feature demonstrations. Obviously, it’s unreasonable to expect desktop-like performance from such a device, however I happen to successfully use a similar environment on EEE PC which was hardly faster.

The instructions rely on the following keystones that make the undertaking possible (and even practical):

  • Raspberry Pi 2 Model B, which offers a 900MHz quad-core CPU and 1GB of RAM (this one is for the “practical” part, yet you may try to use Rasperry Pi 1 as well).
  • Oracle JDK 8 for ARM (with HardFP, JIT and server VM), which provides >10X performance boost (comparing to Zero VM from OpenJDK).

  • Small, but essential modifications that enable IntelliJ IDEA to run on ARM systems, like Raspberry Pi (you may use the same techniques for other ARM-based microcomputers).

Update: we’ve fixed the incompatibilities, so IDEA 15 (or later) should be able to run on ARM architecture (including RaspberryPi) out-of-the-box.

Contents:

  1. Installing Java
  2. Installing IDEA
  3. Tweaking Raspberry Pi
  4. Tweaking IDEA

Some of the commands will require root privileges, so either login as root user or use sudo to start an interactive shell via sudo -i.
Continue reading →

Install Scala on Raspberry Pi

Posted in Linux, Programming, Scala on June 4th, 2015 by Pavel – 3 Comments

Raspberry Pi loves ScalaThis article shows how to install and use Scala programming language on Raspberry Pi.

Traditionally, the programming language of choice for Raspberry Pi was Python, while JVM-based languages were set aside. That was reasonable, because JVM platform is rather resource-intensive, especially in interpreted mode, and the first version of Raspberry Pi was hardly apt for such a task.

However, things have changed: on the one hand, Raspberry Pi 2 now offers a 900MHz quad-core CPU and 1GB of RAM, on the other hand, Oracle released JDK 8 for ARM (with HardFP, JIT and server VM), which provides >10X performance boost (comparing to Zero VM from OpenJDK), so Scala runs nicely even on Raspberry Pi 1 (and, RPi 2 can run IntelliJ IDEA, if you wish).

Contents:

  1. Installing Java
  2. Installing Scala
  3. Using Scala
  4. Installing SBT
  5. Using SBT

Some of the commands will require root privileges, so either login as root user or use sudo to start an interactive shell via sudo -i.
Continue reading →

Ninety-nine

Posted in Programming on January 15th, 2012 by Pavel – 5 Comments

"99" in digital rainThe famous Ninety-Nine Prolog problems (by Werner Hett) transcended their original purpose and became a popular set of exercises for languages other than Prolog.

Solving these puzzles (and comparing your solutions with solutions of others) is a good way to “get a feel” for programing language and to explore idiomatic approaches to particular kind of problems.

Today we can easily find solutions to the problems in almost any wide-spread programming language. However most of the attempts use a single programing language and provide only one solution to each problem.

By providing multiple types of solutions we can enrich our programming “toolbox” and learn pros and cons of various methods. By using several programming languages simultaneously we can easily correlate different programming paradigms and explore limits of language expressive power.

Here goes my take on Ninety-Nine Problems in:

All the code is available as a GitHub repository.
Continue reading →