Java developers can dish out tastier Web apps with JSweet

The transpiler adds Java syntax to TypeScript so developers can use Java skills to build JavaScript Web apps

Java developers can dish out tastier Web apps with Jsweet
Credit: Oregon State University

With JSweet, which recently became available via open source, developers can leverage their Java skills to build Web apps in JavaScript.

The technology transpiles from Java to TypeScript and, in turn, JavaScript. TypeScript is a Microsoft-built superset that compiles to JavaScript. In building JSweet, developer Renaud Pawlak, CEO of Paris-based software engineering company Cincheo, cited a desire to help Java programmers build Web apps.

"In the past couple years, TypeScript has been proving that transpiling to JavaScript to add typing actually works and is efficient," he said in an email. "In parallel, some Java developers have been desperately seeking a light and simple approach to program Web applications in Java. Some are frustrated with the idea that everything in Java should run on a JRE. Some are frustrated by these complex, heavy, and limited Java Web frameworks one can find out there. On the other hand, some are very impressed with what can be achieved with TypeScript/JavaScript on the front end."

JSweet, he said, is a light solution adding bits of Java syntax to TypeScript. "If you want to compare JSweet to TypeScript in a few words, you can say that JSweet is the same as TypeScript, but for Java. It offers an alternative to Java programmers wanting to program real Web applications. The good news is: they don't have to drop Java anymore."

Pawlak still believes Java is a good, safe language for programmers, despite what he describes as a verbose syntax and functions and generics looking "like hacks" to preserve backward compatibility. Java tooling remains efficient and scales better than other languages to program complex applications, he said.

JSweet also makes accommodations for Node.js, the popular server-side JavaScript platform. "JSweet does to Node.js the exact same thing as TypeScript does: it adds types (but in Java)," said Pawlak. "A small but quite interesting difference is that it handles commonjs modules in a more transparent way for the Java programmers. We have defined a @Module annotation so that requires' can be generated automatically when using the APIs. Java programmers just need to import the right packages, as they usually do, without having to know at all about JavaScript modules."

JSweet cross-validates the Java programs and the Java API with TypeScript, and the JSweet API Translator Tool makes JavaScript APIs available in Java. But Pawlak cautioned there are issues with his technology.

"The main difficulty for JSweet is that Java programmers will have to be open-minded and break with some Java logic when programming with JSweet," he said. "For instance, on contrary to Java, in JSweet the hashCode function does not exist and interfaces do not exist at runtime -- only at compile time. Programmers will have to understand that JSweet is not GWT (Google Web Toolkit) at all, because when you program with JSweet you have to think JavaScript, not Java." Also, legacy Java code cannot be used with JSweet. "The Java and JavaScript APIs and semantics are too different."

From CIO: 8 Free Online Courses to Grow Your Tech Skills
Notice to our Readers
We're now using social media to take your comments and feedback. Learn more about this here.