The Ragic Guide
Transforming the way your business works with IT software and cloud services
Follow us on Social Media!
Trending
Applications
Case Studies
What is Ragic
Talking Ragic
Facebook X YouTube
Product
Guide
About
Trending
Applications
Case Studies
What is Ragic
Talking Ragic

Javascript data types vs. Java data types

By Jeff Kuo

One of the most common problem Ragic developers encounter is the difference between Javascript data types and Java data types in workflow programs. Our workflow engine runs on Rhino java scripting engine, and here's some advice from Mozilla that may help developers:

https://developer.mozilla.org/en-US/docs/Scripting_Java

The difference between Java Strings and Javascript Strings is actually the most common problem:

Java Strings and JavaScript Strings

It's important to keep in mind that Java strings and JavaScript strings are not the same. Java strings are instances of the type java.lang.String and have all the methods defined by that class. JavaScript strings have methods defined by String.prototype. The most common stumbling block is length, which is a method of Java strings and a dynamic property of JavaScript strings:

js> javaString = new java.lang.String("Java")

Java

js> jsString = "JavaScript"

JavaScript

js> javaString.length()

4

js> jsString.length

10

Rhino provides some help in reducing the differences between the two types. First, you can pass a JavaScript string to a Java method that requires a Java string and Rhino will perform the conversion. We actually saw this feature in action on the call to the java.lang.String constructor in the preceding example.

Rhino also makes the JavaScript methods available to Java strings if the java.lang.String class doesn't already define them. For example:

js> javaString.match(/a.*/)

ava

Powered by Ragic! : #1 No Code tool for digitalizing your business processes
Keeping business data on Excel is not only a big productivity drain, it's error prone and provides no adequate trail of audit. As your team grows, managing data with spreadsheets become increasingly painful.
Create your first database now!

Start Ragic for Free

Sign up with Google