What def, val, and var fields in Scala traits look like after they’re compiled (including the classes that extend them)
I generally have a pretty good feel for how Scala traits work, and how they can be used for different needs. As one example, a few years ago I learned that it’s best to define abstract fields in traits using
def. But there are still a few things I wonder about.
Today I had a few free moments and I decided to look at what happens under the covers when you use
var fields in traits, and then mix-in or extend those traits with classes. So I created some examples, compiled them with
scalac -Xprint:all, and then decompiled them with JAD to see what everything looks like under the covers.
I was initially going to write a summary here, but if you want to know how things work under the hood, I think it helps to work through the examples, so for today I’ll leave that as an exercise for the reader.
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 14.6, “How to disassemble and decompile Scala code.”Back to top
In the process of learning Scala, or trying to understand a particular problem, you want to examine the bytecode the Scala compiler generates from your source code.Back to top
You can use several different approaches to see how your Scala source code is translated:Back to top
As a Scala newbie, I'm curious about how the process of converting a Scala class back to Java source code works. What I really want to see is how my Scala source code is converted to Java source code. Besides plain old curiosity, I think that understanding more about how Scala works can also be very important to my understanding of Scala (such as the apply() method, and so on).
One of the things that isn't immediately obvious when using the True License Java license key manager software library is how to use the ObfuscatedString string class. In short, you're supposed to use this class to help obfuscate Java String objects that you might ordinarily include directly in your Java source code. If you're trying to protect your Java class (your intellectual property, or "IP"), you want to obfuscate these strings, otherwise they can be easily found by people trying to hack your code so they can use it freely.
Java obfuscator/obfuscation FAQ: How can I obfuscate my Java class files so they can't easily be decompiled? (Or, how do I use ProGuard to obfuscate my Java class files?)
After taking a recent look at a Java decompiler, I decided to look again at the Java obfuscator market. I was going to put together a little list of Java obfuscators, but the people at ProGuard have already done that work for me.
So, here's a link to their list of Java obfuscators, which includes a simple tabular comparison of each obfuscator.
Wow -- I just looked at the state of the "Java obfuscator" market, and all I can say is, well, wow. If you've written some Java code as commercial software (where you don't want your Java class files turned back into Java source files), and you haven't obfuscated that code, it looks like a Java obfuscator can turn your Java class files back into source code very easily (once again).
This article is a little old now, so I've started a new series (as of April, 2010) on Java decompilers and obfuscators. Please follow that link for much more recent information. The content below is kept here only for legacy reasons.
This article is a little old now, so I've started a new series (as of April, 2010) on Java obfuscators and decompilers. Please follow that link for much more recent information. The content below is still valid, but mostly kept because it discusses how to download Java applets.
One of my favorite Java subjects is code optimization and performance. Here I'd like to show you a couple of neat things you can learn with the
javap -c command. This command lets you disassemble Java bytecode.
The first thing you need to have for this exercise is a little sample Java code. So in the examples below I create two test Java classes, appropriately named Test1.java and Test2.java. Although it's not explicitly stated below, the steps I'm going to follow are these: