Blog

by Marbel Tamm

Migrating from ActionScript 3 to Java (personal experience)

A few months ago I decided to try out new things and switched my programming language from ActionScript 3 to Java. I have heard that these kind of radical shakeups work out pretty well at last and I hope that with each day I feel a bit less of a newbie. Knowing OOP and having a real working experience as a developer has been helpful, but what I really need is TIME. Eventually (I hope) the whole system will come together like a huge and almost completed jigsaw puzzle.

The goal of this blog-post is not to shape an idea that one language is better than the other. It is more about what kind of things I have so far encountered and discovered on my path.

Let’s start from the basics – syntax. AS3 looks syntactically almost like Java. It also has OO structure, organization for packages, classes, methods and fields. A small comparison is highlighted in the picture below – declaring variables and methods.

as3_vs_java_example

Those two languages are so alike that it takes only few days to get to know what the main differences are. They even share similar features like having a garbage collector. A little bit more time is required to get rid of the brain muscle memory and the mental desire of automatically writing a „var“ when declaring a variable. Also getting to familiar with Java API takes weeks, depending on what exact features are required (I/O, JDBC etc.).

Still, there are some small quirks I missed for a while from the AS3 times as I was used to these and expected those to work in Java as well:

  1. Possibility of declaring a non-typed variable (var abc:*;). You may store whatever value you want: a boolean, int etc.
  2. More flexibility when calling a super’s constructor (in Java it has to be the first statement in the subclass constructor). In Flash you are allowed to do more:
    • Controlling the order of constructor execution – nice.
      flash1
    • Dubious but still a valid way for skipping a parent constructor. Here, no default constructor is added by Flash. This is dangerous!
      flash2
  3. Calling a method more than 1 level up: super.myMasterMethod();
  4. “private protected”. AS3 has the same access modifiers as in Java: public, protected, default (package/internal) and private. However, the protected access has a different meaning:
    • AS3 – available within the same class and subclasses.
    • Java – same as AS3 + available to everyone within the same package.
  5. Namespaces. This allows to declare your own custom access modifiers to control the visibility of properties and methods.
  6. Dynamic behavior. You can create a lot on a fly.

Is it good that I don’t have these features anymore? Probably yes. Now I have to create a stricter design and less likely shoot my leg with the code being too loose and dynamic. Yes, at first it was a little bit frustrating to find out that I cannot declare a method in Java to be overridden by child classes but being hidden to others. Creating a sub-package for one file seems an overkill. This all taught me that not everything has to be strongly concealed – it is your package, your files. You control it, so just don’t call those methods 🙂

On the other hand, Java is not poor of having features I like:

  1. Abstract classes and enums. I still don’t get it why those were not included into AS3. I have seen a lot of workarounds for achieving the similar functionality but those were quite a mess.
  2. Method overloading. AS3 tries to solve this by allowing to define a default value for each parameter that is not actually passed into the function.
    function defaultValues(x:int, y:int = 3, z:int = 5):void{}
    Overloading is much more flexible when compared to this.
  3. Lambdas. Isn’t it nice to read a code and immediately understand what it does because those unreadable lines of braces and parentheses of an anonymous class are gone?

When grasping the Java language was really easy, then getting to know Java EE world is completely a different story. It is not like opening a small door/window and peeking inside like you would do first when trying out a new thing. There are too many technologies and frameworks tangled together – servlets, AOP, Spring, Hibernate, OSGi and the list goes on and on. If you don’t know anything about those then absorbing all these seems quite impossible. I recommend starting from servlets. After that at least the Spring MVC makes better sense.

What else has changed? Even though I can continue on using Eclipse or IntelliJ (what a relief), the debugging of live projects has come more painful. Before I just had to switch one small swf file with Fiddler and saw the impact. Now I have to build and deploy bigger file packets and this takes much more time. The major time saver has been developing against unit tests.

Java EE has already expanded my mind and I have taken only few steps on this very long path. So, I already have great expectations what things and approaches are there waiting for me. I strongly suggest you to take some time and look into other languages and their frameworks. It doesn’t matter what language to choose. They all teach you a different perspective on solving problems. And the result is good – more creativity. I bet you will find at least one interesting thought, for example from Scala. BTW, every next language will be easier to master.

Related content

Blog

  • Data and AI
  • Technology and Engineering

Solution Specialist experience: low-coding and AI in IT

In this blog, our Solution Specialist Semi discusses the benefits of today’s game-changers – low-code development and AI – and what they offer for both our customers and our developers.

Blog

#d human cell with code in it
  • Data and AI
  • Technology and Engineering

Blog

Stairs in a triangle

The Iron Triangle as Forcing Function

The Iron Triangle of project management asserts that Scope, Cost, and Time represent dimensions fundamentally and irrevocably bound together such […]

Get in touch

Let us offer you a new perspective.