Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

ActionScript for Java developers, Part 1

Learn how ActionScript 3 differs, and doesn't, from Java

  • Print
  • Feedback

Hybridizing Java sounds sexy but learning ActionScript ... not so much. In this two-part article, Chet Haase gets you started toward the Great Migration, with a Java developer's perspective on what's different about ActionScript 3 and its flashy, scripty syntax. In Part 1: An overview of ActionScript 3 and how its basic syntax and class behavior differs from Java's. In Part 2: An advanced look at how ActionScript handles properties, dynamic behavior, and functions. Level: Intermediate

About a year ago, I packed up my things and moved dimensions. I went from programming full-time in Java to working on the Flex team at Adobe, where I now program in ActionScript 3. I was looking forward to the change because I think that an occasional radical shakeup usually works out well, unless you're talking about babies or champagne bottles.

But I wasn't quite so sure about the language barrier.

I'm not an expert in programming languages -- at all. I'm just a graphics geek who learns enough about languages to get the job done. And I figure we can all do what we need to in any language as long as we understand the rules and constraints. But I did come to the new platform with a just a tad of supercilious Java bias, thinking "Isn't ActionScript that toy language that designers use for sprinkling code into animations in the Flash authoring tool?" I mean, any language with script in its name is obviously going to be a step down from the mighty Java. (Or, as Neil Young put it in his surreal cameo appearance at JavaOne 2008, "The Jay-va.") Right?

I was therefore pleasantly surprised to find that ActionScript 3 is actually quite a powerful language, and was syntactically similar to Java in many ways (see Figure 1). Yes, it's a scripting language with dynamic behavior and less type strictness than we have come to expect from Java. But it also has a lot of similar type behavior, object-oriented structure, and package/class/method/field organization that makes it look, well, almost Java-like.

A similar class written in Java and ActionScript 3.

Figure 1. A similar class written in Java and ActionScript 3. Differences are shown in bold. (Click to enlarge.)

So while I'm not a language expert (I'll keep emphasizing that, to make sure that nobody sends me questions about lambda expressions or BNF grammars or anything else I can't answer), I thought that it would be useful to take a step back from both languages and compare them from this programmer's point of view. I'll compare various aspects of the languages to see what ActionScript 3 looks like to a Java developer. In so doing, I hope to help you avoid some of the pitfalls and misconceptions I encountered in my own migration to the Flex SDK.

On the delicate art of comparison

The goal of this article is not to depict one language as better than the other. I think that all languages have their place (I could throw in an unkind jibe here about some older or untrendy languages, but I will pretend that I am above that). Instead, I just want to examine things that are similar and different about Java and ActionScript 3, and what these characteristics contribute to how we use each language.

  • Print
  • Feedback

Resources
  • "Java EE and Flex: A compelling combination" (Dustin Marx, JavaWorld, January and February 2009) introduces techniques for integrating Flex clients with a Java back end.
  • "Client-side Java's evolutionary leap" (Jeff Friesen, JavaWorld, January 2009) looks back on 2008 as a momentous year for Java desktop and RIA technologies, with commentary from many leaders and innovators in client-side development.
  • "The ABCs of RIA" (Paul Krill, Infoworld, August 2007) is a survey of tools and frameworks used in rich Internet application development.
  • ActionScript Developer Center is the Adobe developer site for the language.
  • The Flex SDK Open Source site is the open source repository for the Flex libraries. You can download the latest release of Flex and build applications with it, or download the source code and build Flex from scratch. Also check out learning resources such as the Flex Developer Center site and Flex.org.
  • Flex Builder is Adobe's IDE for building Flex applications. The Flex SDK is free to use, but tools can make development easier.
  • The Flash Development Center provides resources for developers writing programs for the Flash platform, which can be done either with Flex, or by using the Flash APIs directly, or with the Flash authoring tool.
  • Filthy Rich Clients (Chet Haase and Romain Guy; Addison-Wesley/Sun Microsystems Press, August 2007) is a definitive guide to client-side development in Java.
  • Chet Haase regularly posts graphics, animation, and tutorial articles and videos to his technical blog Codedependent, and irregularly posts comedy writings to his non-technical blog Enough About You.

More from JavaWorld