Java Magazine, September/October 2016
ORACLE COM JAVAMAGAZINE SEPTEMBER OCTOBER 2016 53 jvm languages Fantom is a programming language derived from mainstream languages such as Java and C The primary design goal from its start in 2005 was portability between heterogeneous runtime environments specifically the JVM and browser JavaScript VMs The Fantom compiler and extensive standard library ensure that code written in Fantom works exactly the same on a Java server and in a browser client Although many JVM languages now have eforts around providing a JavaScript port few were designed from the ground up to solve this challenging problem You will find the goal for seamless portability woven into every aspect of the Fantom platform Fantom also supports a novel approach to immutability and concurrency The type system and runtime work in concert to provide guaranteed immutability An actor model for concurrency leverages the type system to ensure that mutable state is never shared between threads Fantom is designed to be a single language for writing both server side and browser client side code On the client side it has a new library called domkit for building rich HTML5 user experiences This article provides an in depth look into several of these prominent features portability immutability actor concurrency and Fantoms HTML5 toolkit domkit Portability True portability requires both compiler support and library support If your language is portable but all the libraries you use are not then you havent really solved the problem For this reason Fantom has its own standard library which is equally important as the language itself Fantom was conceived to provide both compiler support and a standard library to port between three diferent runtime environments Java NET and JavaScript VMs Although we prototyped a Fantom runtime for NET it isnt currently supported Today all development is done only for the Java and JavaScript runtimes These two runtimes have been used in production for commercial software for more than six years making them very mature and robust The Fantom compiler supports a pluggable architecture A single pass of the compiler is used to simultaneously generate bytecode for the Java VM and transpiled JavaScript source for browser environments Once a Fantom module is built a single module file can be deployed with everything required to use the code on a Java server and in a browser The compiler also provides a mechanism for classes and methods to be implemented natively Native code is implemented in Java and or JavaScript to create the low level APIs that access functionality from the underlying VM These lowlevel APIs include core types Str Int DateTime collections I O networking concurrency and Document Object Model DOM access With these APIs in place most Fantom modules are written in 100 percent Fantom and have guaranteed portability between Java and JavaScript Immutability One of Fantoms guiding principles has been to have a type BRIAN FRANK Fantom Programming Language A language that runs on the JVM and JavaScript VMs and delivers excellent UI building capabilities
You must have JavaScript enabled to view digital editions.