Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Slashdot Log In

Log In

Create Account  |  Retrieve Password

Ruby and Java Running in JavaScript

Posted by ScuttleMonkey on Mon Apr 28, 2008 02:11 PM
from the fun-new-toys dept.
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.
+ -
story
This discussion has been archived. No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More
Loading... please wait.
  • Awesome! (Score:4, Funny)

    by eln (21727) on Monday April 28 2008, @02:15PM (#23228366) Homepage
    Finally, a way to combine the feature-rich capabilities of Javascript with the speed of Java!
    • Re: (Score:3, Interesting)

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

      Cynicism was my initial response as well, but reading TFA shows a pretty cool demo [accelart.jp]. The fact that they are able to convert Java's user input events, GUI, and multithreading to Javascript is pretty cool. Probably has no practical use, but still cool.

      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 "basical
      • Re:Awesome! (Score:5, Funny)

        by omeomi (675045) on Monday April 28 2008, @03:29PM (#23229248) Homepage
        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.
          • Re:Awesome! (Score:4, Informative)

            by omeomi (675045) on Monday April 28 2008, @05:01PM (#23230398) Homepage
            : 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.
  • by techno-vampire (666512) on Monday April 28 2008, @02:16PM (#23228378) Homepage
    What this is, basically, is emulating the Java in Javascript, an interpreted language. I can't help but feel that anything written in this is going to be very slow, and I can't, personally, see why anybody would bother. Of course, I'd be very happy to be proven wrong!
    • Re: (Score:3, Interesting)

      What this is, basically, is emulating the Java in Javascript, an interpreted language. I can't help but feel that anything written in this is going to be very slow, and I can't, personally, see why anybody would bother

      I'm with you, I read the summary and almost choked on my coffee.

      This is like writing a Cray emulator for your TI 99/4a -- I don't know what it buys you.

      Of course, I'd be very happy to be proven wrong!

      I'm sure some clever person will put out a demo showing something completely amazing, and I'd

      • This is like writing a Cray emulator for your TI 99/4a -- I don't know what it buys you.


        Hey, I used to have a TI 99/4A. Great little machine, back then!

        • Hey, I used to have a TI 99/4A. Great little machine, back then!

          I'm not disparaging the TI 99/4a, I have very fond memories of that machine.

          But, let's face it, that's just as odd a scenario as running Java on a javascript interpreter. :-P

          It's like ... making a scale model of a dump truck from a Yugo. Sure, it kinda mostly looks like a dump truck. But, it can't do any of the things you'd actually want a dump truck for. :-P

          Cheers

            • alright, go ahead, get them out of your system.. I know you have a couple more analogies in there..

              Bah, give me enough monkeys and enough time, I'll give you all of the analogies you could ever want.

              I've made the computer analogy, the car analogy, and now I've alluded to monkeys ... what more could you want? ;-)

              Cheers
    • by Dekortage (697532) on Monday April 28 2008, @02:24PM (#23228466) Homepage

      The article suggests that the speed was not bad. (The sample Tetris [accelart.jp] 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.

      • by hanshotfirst (851936) on Monday April 28 2008, @02:29PM (#23228544)
        Anticipated application stack:

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

        Exciting New ways to be eaten by a grue!
      • Re: (Score:3, Informative)

        The game loaded faster than most Java apps do for me, but once it loaded the controls were laggy and the video was pretty choppy. Most of the time for me, the JVM takes a while to load but at least the app runs fairly smoothly once it does. I'd rather have that then a shorter load time on a laggy application.
      • by evanbd (210358) on Monday April 28 2008, @02:52PM (#23228772)

        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!

          • Re: (Score:3, Interesting)

            Why wouldn't I code in Java? For most things I code, I see about a 10-20% performance penalty vs C, plus a modest load time (that I don't care about usually). I also see a noticeably reduced development time; for me that's a trade worth making under most circumstances. Now, I'm not coding user interfaces, and I am paying attention to performance of my Java code (unlike many Java developers). I'm also emphatically not claiming it's a good environment for everything (but I'd say the same about any languag

            • Re: (Score:3, Insightful)

              Nah - the beef with java isn't that it's slow. Well, that too, but it's more in the interfacing; want to do something in C in between all your java - use the JNI if you dare ! Want to fire off a shell - see you thirty statements later ! Want to create a PDF ? Well, see, first we instantiate a worker-factory of this XML-class, and then we feed it through this parser-generator, and then we might end up with some PDF... on mondays. Want to stat a file, fork a process, set up a non-standard network communi
              • by asdfghjklqwertyuiop (649296) on Monday April 28 2008, @05:48PM (#23230814)

                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
      • Well, I always tell young programmers that the things that matter most are at the top and at the bottom of the stack of the abstractions you are using. The in between part is always negotiable and subject to clever alterations.

        Tetris is not apt to use a great deal of java's vast libraries, so if you're smart about loading just the parts you need, when you need them, why shouldn't Java on Javascript Tetris be fairly close to plain old Javascript Tetris, with a modest constant time hit. What I'd like to see
    • ``What this is, basically, is emulating the Java in Javascript, an interpreted language. I can't help but feel that anything written in this is going to be very slow, and I can't, personally, see why anybody would bother. Of course, I'd be very happy to be proven wrong!''

      Probably, it will be slow.

      But, in general, just because something is interpreted doesn't mean it has to be slow. There are various ways to implement an interpreter, and interpreters can have either very fast start-up time or very fast execu
      • But the controls are a little sluggish and the game was fairly simple, but over all it was really impressive for javascript.
        No, no it's not. [dnsalias.com]

        Is anyone here clear on the actual amount of processing power necessary to run a game of Tetris? Hint: It's not a lot. Especially if you're not using a fancy blitter with alpha-transparencies and pipelined transforms.
  • But... (Score:5, Interesting)

    by Oxy the moron (770724) on Monday April 28 2008, @02:17PM (#23228386)

    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.

      • Re: (Score:3, Informative)

        JDK6u10 solves this. It lets the applet run in a separate process from the browser, and bootstraps the download such that it starts up very quickly. See here [sun.com] for more information.

  • by kripkenstein (913150) on Monday April 28 2008, @02:19PM (#23228416) Homepage
    Also worth mentioning that PyPy allows you to run Python as Javascript [codespeak.net], inside a browser. Like all of these things, it isn't 100% mature, but pretty cool nonetheless.
  • Google Web Toolkit (Score:5, Interesting)

    by mysqlrocks (783488) on Monday April 28 2008, @02:20PM (#23228424) Homepage Journal
    While not exactly the same thing, the Google Web Toolkit [google.com] (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.
  • Strange (Score:5, Interesting)

    by graveyhead (210996) <fletch&nationofcriminals,com> on Monday April 28 2008, @02:22PM (#23228444) Homepage
    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 [jquery.com] 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.
    • Re:Strange (Score:4, Informative)

      by CastrTroy (595695) on Monday April 28 2008, @02:31PM (#23228570) Homepage
      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.
    • Re: (Score:2, Insightful)

      > Why does everyone hate Javascript so?

      Javascript is inherently multithreaded and embedded in a highly asynchronous environment, het has no threading API whatsoever. To me, this is mind-boggling. Every AJAX project I've been involved in has had to build in ugly workarounds or just drop features to prevent race conditions.
  • by Hoplite3 (671379) on Monday April 28 2008, @02:28PM (#23228528)
    This just reminds me of the "octoparrot" from The Simpsons. "Braawk! Polly shouldn't be!"
  • by Daishiman (698845) on Monday April 28 2008, @02:28PM (#23228536)
    'Orto' means 'ass' in Spanish.
    • 'Orto' means 'ass' in Spanish.
      Oh wow, initially I didn't understand the point of this project. Thanks for clearing that up for me.
  • No Perl? (Score:4, Informative)

    by SCHecklerX (229973) <slshdt@freefall.homeip.net> on Monday April 28 2008, @02:29PM (#23228538) Homepage
    Client side perl would kick ass. Then I could match my front end with the back.
    • Perl is so Web 1.0, though! Remember back in the day when all the Slashdot posters loved to talk about their awesome Perl skills? Kids these days use AJAX and such... back in my day we wrote web applications in COBOL and we were glad to have it!.
  • by trybywrench (584843) on Monday April 28 2008, @02:31PM (#23228576)
    writing a java VM in javascript? *head asplodes*

    that's pretty cool but man, talk about a daunting tedious task. I'd rather bail 600 acres with a weed wacker and twisty-ties.
  • by serviscope_minor (664417) on Monday April 28 2008, @02:37PM (#23228622)
    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!
    • Prolog in Javascript [ioctl.org] is available too. I first ran across an earlier version of this in a compressed form as an entry to the 5k competition: show off what you can do with 5k for your entire website.
  • * Urk * (Score:3, Funny)

    by Tarlus (1000874) on Monday April 28 2008, @02:47PM (#23228732)
    Anybody else twitch at the sight of that headline?
    • I know I twitched a little when I read the "Java in Javascript" part. A really neat hack, tho.

      Thing is Internet Explorer has supported lots of languages - even those not meant for a web browser! - for writing full-featured client-server code. They're called viruses.

  • by Decameron81 (628548) on Monday April 28 2008, @02:55PM (#23228814)
    As a side note: "orto" in argentina means ass. I don't think I'd want to run anything through it.
  • So how Orto different from Google's Web Toolkit? Does it accomplish it's goal without AJAX?
  • Why the hell would you use a JVM in Javascript when there are Java plugins for every major browser anyway? The only good use I could think of is if you want Java to run on some user hostile DRMd machine that doesn't let you do Java but lets you do javascript.
  • While Ruby and Java are nice and all, I give you Brainfuck and Ook! [virtuelvis.com].
  • by bigsexyjoe (581721) on Monday April 28 2008, @03:27PM (#23229220)
    Clearly the top application of this project is me playing that Tetris game and telling my boss that it's research for my job.
  • by Kryptikmo (1256514) on Monday April 28 2008, @03:30PM (#23229258)
    They don't know if it works properly yet - they're still waiting for it to finish running "Hello World"....
          • by Anonymous Coward on Monday April 28 2008, @03:07PM (#23228964)
            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.