Slashdot Mirror


Ruby and Java Running in JavaScript

John Resig is reporting on his blog that a recent trip to Tokyo opened up some very interesting JavaScript projects to him that haven't met with widespread popularity outside of Japan yet. "One project, in particular, really caught my eye. It's called Orto and is an implementation of the Java Virtual Machine (JVM) in JavaScript. This means that you can take an existing Java application, compile it to bytecode, run it through Orto (which produces the JavaScript, and embed it in a web page. While it doesn't provide the full capabilities of most Java code it does provide enough to make for some interesting demos." In a separate post he also detailed how the HotRuby project is allowing a Ruby VM to run in a browser using JavaScript or even indirectly using ActionScript in Flash.

18 of 220 comments (clear)

  1. Awesome! by eln · · Score: 4, Funny

    Finally, a way to combine the feature-rich capabilities of Javascript with the speed of Java!

    1. Re:Awesome! by omeomi · · Score: 5, Funny

      If nothing else it means that the next time (in about 3 minutes if today is a normal day) somebody gets Java and Javascript confused, I can say they really ARE "basically the same thing" now!

      Fantastic. Somebody's found a way to make the morons of the world slightly more correct without them even knowing it.

    2. Re:Awesome! by omeomi · · Score: 3, Informative

      : What IS the diff between Java and JavaScript-really?

      Java is an object-oriented programming language originally released by Sun Microsystems in 1995. JavaScript is a functional scripting language originally derived from Ecmascript. Java requires a Java Virtual Machine to be installed on your computer or some other device like a mobile phone. Javascript runs right in your web browser. Javascript was originally named LiveScript, but through a marketing deal between Netscape and Sun, became named JavaScript, even though the two languages are unrelated, thus dooming those in the know to have to constantly correct people who refer to JavaScript as Java, assuming that "Java" is just like a nickname or something. However, they are both based on syntax that looks a good deal like C.

  2. But... by Oxy+the+moron · · Score: 5, Interesting

    Does it run Linux? ;)

    In all seriousness, though... I'm struggling to see how this is truly beneficial. Aren't most pages already hopelessly clogged with mounds of JavaScript? Is it that difficult to expect a user to have a Java interpreter already installed when they visit the page such that having your Java "emulated" in JavsScript is the better solution?

    Just seems like a solution needing a problem to me.

    --

    Proudly supporting the Libertarian Party.

  3. Ruby and Java, and also Python by kripkenstein · · Score: 3, Informative

    Also worth mentioning that PyPy allows you to run Python as Javascript, inside a browser. Like all of these things, it isn't 100% mature, but pretty cool nonetheless.

  4. Google Web Toolkit by mysqlrocks · · Score: 4, Interesting

    While not exactly the same thing, the Google Web Toolkit (GWT) lets you write your code in Java and then run it in the browser. The difference is that the GWT translates the Java into JavaScript instead of giving you a full JVM. I'm not sure what practical advantage having a full JVM gives you.

  5. Strange by graveyhead · · Score: 4, Interesting

    Seems odd to use languages that weren't really designed to be embedded in a browser. One of the nice things about Javascript in the past couple of years has been the great DOM support. Add a library like JQuery and you have full cross platform goodness and a sane way to write code. Getting Java or Ruby code to interact with the DOM seems like it would be a huge pain compared with JQuery.

    Why does everyone hate Javascript so? If you're going of cut-n-paste examples from the web yes it looks like an ugly language. Check out how the OO stuff works, or some JQuery code, and you'll be pleasantly surprised.

    --
    std::disclaimer<std::legalese> sig=new std::disclaimer; sig->dump(); delete sig;
    1. Re:Strange by CastrTroy · · Score: 3, Informative

      I think that everybody just has memories from the Netscape 4 days, where every line had to be coded differently depending on which browser you were using. Things have matured a lot lately, and you can almost get by without writing any browser specific hacks. However, the history of Javascript has lead many people to dispise it.

      --

      Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
  6. Re:Doing things the slow way by Dekortage · · Score: 5, Informative

    The article suggests that the speed was not bad. (The sample Tetris clone loaded very quickly for me.) And the article's commenters note that this runs on an iPhone. In other words, Orto could be a route to port Java apps to be iPhone aps.

    --
    $nice = $webHosting + $domainNames + $sslCerts
  7. The Octoparrot of the programming world by Hoplite3 · · Score: 4, Funny

    This just reminds me of the "octoparrot" from The Simpsons. "Braawk! Polly shouldn't be!"

    --
    Use the Firehose to mod down Second Life stories!
  8. I just need to get this out of my system by Daishiman · · Score: 5, Funny

    'Orto' means 'ass' in Spanish.

  9. No Perl? by SCHecklerX · · Score: 3, Informative

    Client side perl would kick ass. Then I could match my front end with the back.

  10. Re:Doing things the slow way by hanshotfirst · · Score: 5, Funny

    Anticipated application stack:

    iPhone -> Orto -> Javascript -> Java -> C64 Emulator -> VIC-20 Emulator -> Zork I

    Exciting New ways to be eaten by a grue!

    --
    Why, oh why, didn't I take the Blue Pill?
  11. Language stacks galore! by serviscope_minor · · Score: 4, Funny

    Ok, so maybe we can run python in pypy in ironpython in java in javascript.

    Now all we need to get is a C compiler to output python code. If someone can then write an x86 VM in python we could then run Linux in Firefox!

    --
    SJW n. One who posts facts.
  12. Re:Doing things the slow way by evanbd · · Score: 3, Insightful

    Tetris performed better on my Gameboy (an 8-bit, 4.2MHz x80 CPU with 8KB RAM) than this clone does on my 32-bit 1.4GHz Athlon. And it had sound. Tetris shouldn't load "quickly" it should load instantly.

    This is a very clever hack, and I admire the work -- but it is in no way practical for anything. I find the idea of using it for "real work" apalling -- and I code in Java by choice!

  13. Re:Java running under Javascript... by Anonymous Coward · · Score: 4, Insightful

    Saying that Java is a crippled version of C++ that runs at 1/10 the speed is idiotic and only displays your ignorance. You're just parroting what you've heard from other ignorant retards. Java has a ton of significant problems but people like you continuously bring up points that are either wrong or completely irrelevant. Based on your posts I doubt you understand much about Java or the JVM.

    By the way, you can obviously rewrite critical portions of Java code in C as well... Being able to call out to C is not an excuse for the current Python and Ruby implementations being complete trash. There are lots of languages that provide a similar level of abstraction that have far better performance and a threading model that isn't a complete joke.

  14. This is just a prototype! by Kryptikmo · · Score: 4, Funny

    They don't know if it works properly yet - they're still waiting for it to finish running "Hello World"....

  15. Re:Doing things the slow way by asdfghjklqwertyuiop · · Score: 5, Informative

    what i can't stand is java's complete lack of accuracy in basic math such as

    int upper = (int) (value * 100.0);
    double newVal = ((double)upper) / 100.0;

    value can start as an int/double/float your choice.

    in the end newValue does not alwasy equal value.. even though it should.. i understand floating point errors but i first saw this cause a problem with value being a double 8.12


    What language can you stand, then?

    % perl
    print int(8.12*100.0)/100.0;
    8.11
     
    % python
    Python 2.4.4 (#2, Apr 5 2007, 20:11:18)
    [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> float(int(8.12*100.0))/100.0
    8.1099999999999994
     
    % php5
    <?= floor(8.12*100.0)/100.0; ?>
    8.11
     
    % cat > test.c
    #include <stdio.h>
    int main() {
        double val; int upper; double newval;
     
        val = 8.12;
        upper = (int)(val * 100.0);
        newval = ((double)upper)/(100.0);
     
        printf("%f\n", newval);
    }
    % make test
    % ./test
    8.110000
     
    % ruby
    print (8.12*100.0).to_i.to_f/100.0;
    8.11