days
1
3
hours
0
4
minutes
0
4
seconds
4
7
search
Sugary goodness

Add some candy to your code: JSweet transpiles from Java to JavaScript

Sarah Schlothauer
javascript
© Shutterstock / Veronika Vankova

JSweet is a transpiler that takes code from Java to JavaScript with over 1,000 available JavaScript libraries. See what it can do and unwrap something sweet with its Maven repository.

From Java to JavaScript, it might be easier than you thought. The dream of translation is innate. We all wish to be able to speak to people from across the globe without having to learn a new, complex language, and this is true even with programming. Are we at the “click a button and go” level of transcription yet? Well, no. But JSweet is a helpful tool that’s almost just as good as being multilingual.

JSweet is a Java to JavaScript transpiler. Time to see what it can do!

Let’s unwrap

JSweet uses source-to-source compiles code to TypeScript and JavaScript for availability in browsers, mobile web, or Node.js. All you need is Maven, Git, and Node.js and you can get started with cloning the project from GitHub.

From GitHub, here’s the reasons why JSweet should be on our radar:

  • JSweet is safe and reliable. It provides web applications with type-checking and generates fully type-checked JavaScript programs. It stands on Oracle’s Java Compiler (javac) and on Microsoft’s TypeScript (tsc).
  • JSweet allows you to use your favorite JS library (JSweet+Angular2JSweet+threejsIONIC/Cordova, …).
  • JSweet enables code sharing between server-side Java and client-side JavaScript. JSweet provides implementations for the core Java libraries for code sharing and legacy Java migration purpose.
  • JSweet is fast, lightweight and fully JavaScript-interoperable. The generated code is regular JavaScript code, which implies no overhead compared to JavaScript, and can directly interoperate with existing JavaScript programs and libraries.

There is also a helpful debug mode to prevent any mistakes from going live. And for those wondering, JSweet is not just an emulator. You can use the newly generated code as your source code. It works like JavaScript because it is JavaScript, no secret Java to be found underneath.

SEE ALSO: TypeScript: Everyone’s type of JavaScript

    iJS Cheat Sheet 2018

    Free: The iJS React Cheat Sheet

    You want to get started with React?
    Our Cheat Sheet includes all the most important snippets.
    Get the sheet for free!

 

Not just a sugary treat

Candies aren’t just an impulse buy in the grocery store line. In JSweet, candies are how the transcription works.

Let’s take a look at the Getting Started guide and find out what these snacks are: “A JSweet candy is a Maven artifact that corresponds to a Java/JavaScript library/framework/API, which you can use in your JSweet application simply by adding a dependency to it in your pom.xml.”

A candy is a Maven artifact with three ingredients:

  1. Java API and/or implementation,
  2. the corresponding TypeScript definitions (necessary for the TypeScript to JavaScript compilation),
  3. and, optionally, the compiled JavaScript implementation, to be used for running the library/framework/API.

SEE ALSO: Freelancer Fast 50: Blockchain, JavaScript and AI skills on the rise

There are already available candy libraries and if those aren’t enough, get cooking and build your own candy and add it to the library. There are several repos on GitHub of JSweet candies as well ready to deploy.

Of course, there are some limitations to JSweet. After transcription, some parts of the code may have to be rewritten and some Java libraries are not supported.

Getting started

Try JSweet live sandbox and view how it works, such as transcribing a 3-D logo rotate, quick start, or basic jQuery. There are also many examples you can run on your browser to see more of JSweet’s capabilities, including canvas drawing, form input, Angular example, and Backbone todos.

Have you used JSweet? What do you think of this transpiler?

 

 

 

Author
Sarah Schlothauer

Sarah Schlothauer

All Posts by Sarah Schlothauer

Sarah Schlothauer is an assistant editor for JAXenter.com. She received her Bachelor's degree from Monmouth University in Long Branch, New Jersey and is currently enrolled at Goethe University in Frankfurt, Germany where she is working on her Masters. She lives in Frankfurt with her husband and cat.

Leave a Reply

1 Comment on "Add some candy to your code: JSweet transpiles from Java to JavaScript"

avatar
400
  Subscribe  
Notify of
Anna Martinez
Guest

Thank you for sharing an amazing article @Sarah Schlothauer.

I was not aware of this Jsweet Candy. Again thanks Sarah for sharing this article, Nowadays Node.js is also a trending JS for a programmer you should also add in this in the article.