Java Bytecode Simplified: Journey to the Wonderland (Part 1)

There are two ways to see a thing. One, see it as it appears to us; two, see it and appreciate it. For example, we get light when we switch on a lightbulb. We press the button and then get busy with our life. Pretty simple, but boring. On the other hand, if we know how the light gets energy from an electrical power grid far from our home with wires, and while traveling through the wires and filament, the filament heats up and starts emitting photons, we get to see in the light; we can then appreciate the blessing.

In the same way, when we write a piece of code, and if we know the mechanism behind it, we can then appreciate it more, how excellent engineering effort went into it, making our life so amazing.

SKP’s Java/Java EE Gotchas: BCEL Issue on JiBX 1.2.5 (java.lang.CharSequence)

So, I spent some time on resolving this issue with a combination of the following:

1. JiBX 1.2.5 / JiBX 1.2.6
2. JDK 1.8

During the jibx-maven-plugin:bind phase of the Maven Build, you may get an error when you upgrade from JDK 1.x to JDK 1.8; The issue will manifest in the following most common form/error:
 
Failed to execute goal org.jibx:jibx-maven-plugin:1.2.5:bind (bind-compile) on project common: Error loading class java.lang.CharSequence: Error reading path java/lang/CharSequence.class for class java.lang.CharSequence
 

You can modify your pom.xml, to make these changes to fix this error.

1. Include the Repository for BCEL 6.0
Include the Repository for BCEL 6.0



2. Check the version of JiBX [Choose any of 1.2.5 or 1.2.6]
Check the version of JiBX [Choose any of 1.2.5 or 1.2.6]


3. Exclude default 'BCEL' from the Build
Exclude default 'BCEL' from the Build


4. See the modifications for the plugin 'jibx-maven-plugin'
See the modifications for the plugin 'jibx-maven-plugin'


5. Voila!
Build Success!

Serializable Java Lambdas

Recently I was presented with the following error when serializing a lambda with Kryo:

Java
 




x


 
1
com.esotericsoftware.kryo.KryoException: 
2
  java.lang.IllegalArgumentException: 
3
    Unable to serialize Java Lambda expression, unless explicitly declared e.g., 
4
    Runnable r = (Runnable & Serializable) () -> System.out.println("Hello world!");


If you do not recognize the (Runnable & Serializable) syntax, don’t worry, it is merely stating that the lambda must implement two types. This is called Type Intersection. Personally, I have never needed to use this myself, so have never really thought about it. Serializable is a bit of a unique interface in this regards, as there is nothing you actually need to implement.

Java Virtual Machine Internals, Part 1: Class Loader

The Java Virtual Machine is the heart of the Java ecosystem. Thanks to the JVM, when it comes to Java programs, we can 'write once, run everywhere.' Like other virtual machines, the JVM is also an abstract computer. The Java Virtual Machine's main job is to load class files and execute the bytecode they contain.

There are multiple components of the Java Virtual Machine like class loader, the garbage collector (automatic memory management), interpreter, JIT compiler, thread management. In this series,  I’ll be discussing how the Java Virtual Machine works. In this first installment, we are going to talk about the class loader. So let's get started!

Hibernate Bytecode Enhancement: Association Management

In the previous article, Hibernate Bytecode Enhancement. Dirty Tracking, I explained how to optimize Hibernate’s Dirty Tracking mechanism.

The bytecode enhancement, however, can be achieved via one more property: association management. When this feature is enabled, Hibernate will take care of automatically updating the “other side” of a bidirectional relation with a reverse mapping defined when one side changes. Similar to Dirty Tracking, this will as well result in additional changes made to the bytecode of the entities.