Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6146483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:57:24+00:00 2026-05-23T18:57:24+00:00

I’m unclear on the rules for how types are converted between Javascript and Java

  • 0

I’m unclear on the rules for how types are converted between Javascript and Java when using (Mozilla) Rhino.

There’s some specifics in the documentation about String:

It’s important to keep in mind that Java strings and JavaScript
strings are not the same […]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

But what about others? If I pass a javascript Number to a Java method expecting int, double (or Integer or Double) will it get converted? What about long/Long? (which won’t fit in a Double and so won’t fit in a JS number?

What about Java methods returning these values?

Then there’s Boolean/boolean. Are the JS constants true and false converted to and from the appropriate Java value? I’ve seen code like

java.lang.Boolean.TRUE.booleanValue()

used from JS, so at least some people think it isn’t.

I have looked at the Mozilla Rhino documentation but do point out if I’ve missed something obvious.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:57:24+00:00Added an answer on May 23, 2026 at 6:57 pm

    Here’s how it converts JavaScript types to Java types: http://www-archive.mozilla.org/js/liveconnect/lc3_method_overloading.html#InvocationConversion.

    Try it:

    $ java -cp js.jar org.mozilla.javascript.tools.shell.Main
    
    js> new java.lang.Integer(12345)
    12345
    js> new java.lang.Integer(12345) == 12345
    true
    
    js> new java.lang.Double(12345.12345)
    12345.12345
    
    js> new java.lang.Long(9223372036854775807)                 
    js: Cannot convert 9223372036854776000 to java.lang.Long
    js> 9223372036854775807
    9223372036854776000
    js> new java.lang.Long("9223372036854775807")
    9223372036854775807
    js> new java.lang.Long("-9223372036854775808")
    -9223372036854775808
    
    js> new java.lang.Boolean(true)
    true
    js> new java.lang.Boolean(true) == true
    true
    js> new java.lang.Boolean(true) == false
    false
    js> java.lang.Boolean.TRUE.booleanValue() == true
    true
    js> java.lang.Boolean.FALSE.booleanValue() == false
    true
    

    UPD

    Unfortunately I can’t find any docs about JavaScript-from-Java type mapping either. But the tutorial shows that JavaScript objects are inserted into and retrieved from context as Java Objects that actually can be Doubles, Booleans, Functions (for JavaScript functions; also implements Scriptable) or Scriptables (for objects).

    Using this code snippet it’s possibly to get JavaScript-Java type mapping reference:

    https://gist.github.com/1089320#file_java_script_java_type_mapping.textile

    As for LiveConnect compatibility. If you are referring to this footnote:

    The ability to call Java from JavaScript was first implemented as
    part of a Netscape browser technology called LiveConnect. However,
    since that technology also encompassed communication with browser
    plugins, and since the way of calling JavaScript from Java in Rhino is
    entirely different, that term won’t be used in this paper.

    I think it’s about using JavaScript from Java is different from LiveConnect specification. Using Java from JavaScript should be the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.