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.

220 comments

  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 nmb3000 · · Score: 2, 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. 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 "basically the same thing" now!

      --
      "What do you despise? By this are you truly known." --Princess Irulan, Manual of Muad'Dib
      /)
    2. 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.

    3. Re:Awesome! by Vellmont · · Score: 1


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

      You joke, but I'm sure it's the other way around. The myth that Java is slow persists to this day, though it hasn't been true for many years.

      The ugly thing about this hack is going to be the slowness of javascript execution, especially when doing this bizzare translation. I'm all for replacing javascript with a less sucky language. But this doesn't seem like the solution.

      --
      AccountKiller
    4. Re:Awesome! by Anonymous Coward · · Score: 0

      people who dont know the diff between javascript and java are morons?

    5. Re:Awesome! by WoodstockJeff · · Score: 1

      In actuality, I can think of several applet-type projects that suffer significant problems in Java, which I'd like to try to "cross-compile" to Javascript... One that we've been trying to get to work for a long time works just fine in every browser we have tested it on. Unless, of course, you try to run it from a page loaded by HTTPS! If it is, the success of it running depends entirely upon the browser used, AND whether or not it was previously run from the same page, loaded via a non-TLS connection.

      Attempts to resolve the problem (with limited or no error messages given, it just doesn't work) point to several potential problems, and a number of "fixes"... None of which work in all instances, and most of which, at best, change which circumstances fail, or sometimes generate a more useful error message.

      If it were possible to turn it into strictly Javascript, it should lose the HTTP/HTTPS dependencies. Not to mention the load time to start the JVM.

    6. Re:Awesome! by FooAtWFU · · Score: 1
      Feature-rich? You mean it has things like introspection, closures, functions as first-class objects, and objects by aggregation as well as inheritance? Seriously, JavaScript is chock full of neat features.

      It's the two primary runtime environments' gross annoying differences, and weaknesses with little syntaxy things like variable declaration and adding strings - or did you mean integers? and how parseInt('08') blows up etc... things like THAT make it a pain.

      --
      The World Wide Web is dying. Soon, we shall have only the Internet.
    7. 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.

    8. Re:Awesome! by Red+Alastor · · Score: 1

      By features, he probably meant the Java's library which is pretty huge. The language itself has very few features and it was a design goal. I prefer Python for having the best of both worlds.

      --
      Slashdot anagrams to "Sad Sloth"
    9. Re:Awesome! by Anonymous Coward · · Score: 0

      Actually, Ecmascript is just a (worthless) standard that is based on Javascript.

    10. Re:Awesome! by Jesus_666 · · Score: 1

      What IS the diff between Java and JavaScript-really?
      $ echo "Java" > Java
      $ echo "JavaScript" > JavaScript
      $ diff Java JavaScript
      1c1
      < Java
      ---
      > JavaScript

      HTH
      --
      USE HOT GRITS WITH STATUE OF NATALIE PORTMAN (NAKED AND PETRIFIED)
    11. Re:Awesome! by HeroreV · · Score: 1

      I can say they really ARE "basically the same thing" now! That's like saying Python and C are basically the same thing, since the CPython interpreter is written in C. Writing an interpreter for language A in language B doesn't mean languages A and B are basically the same thing.

      Plus this isn't even the Java programming language we're talking about, it's Java bytecode, which could have been produced from something other than the Java programming language (like Groovy or Scala).
    12. Re:Awesome! by Anonymous Coward · · Score: 0

      and how parseInt('08') blows up etc... things like THAT make it a pain. parseInt('08',10)

      Problem solved.
    13. Re:Awesome! by rts008 · · Score: 0, Flamebait

      Well, I like hot grits, and would love to have Natalie Portman available...so I agree with your sig, but as for your posted reply I would have to respond (as a n00b)...WTF?

      I'm not trying to flame, but I don't get the relevance. What does this actually mean:"1c1
        JavaScript
      HTH"

      I get the first part($ echo "Java" > Java
      $ echo "JavaScript" > JavaScript
      $ diff Java JavaScript), but as a n00b, do not get the second part.

      It would be more 'informative' or more relevant if you could post links or man pages, but unless I try Google or Kubuntu forums this is just elitist hyperbole...try to be constructive in your RTFM attitude unless you're an elitist that can't be bothered outside of your mother's basement. (if this is the case, then you are somewhat responsible for the delay of 'this is the year for the Linux desktop' movement.

      BTW, as for your username: Jesus_666: that supposes that you are a fictional (debatable- can you prove otherwise? character in mythology, so where is your relevance?? It seems you set this up to be confrontation able to begin with, so I call your bluff!) *disclaimer:my opposition could be a massive Ad Hominem attack- if incorrect then, well, I take it all back.

      It's easy to be an asshat or ass-clown on teh interwebs...can you rise to the challenge of being a constructive and contributory participant in the discussion, or just an asshat?

      If I have taken this out of context, then I humbly apologize, and hope I will be enlightened on the subject matter, but skip the attitude, please...we don't need this kind of thinking to further 'Linux on the desktop'.

      Again, if I am making invalid assumptions and taking this wrongly, then please excuse me...but please correct me.

      If I am not misunderstanding you, then FSCK you and your ilk!

      If I mis-understood your point, then please excuse me, again, enlighten us n00bs!

      --
      Down With Slashdot BETA!!! I've been around the corner and seen the oliphant; you can only abuse me from your perspecti
    14. Re:Awesome! by larpon · · Score: 1

      This is seriously the first time I've ever seen diff piss someone this much off.

    15. Re:Awesome! by zoips · · Score: 1

      Javascript isn't functional; Lisp, Haskell, ML, etc are functional. Javascript is a prototype based object-oriented language, like SELF and Io.

    16. Re:Awesome! by FrangoAssado · · Score: 1

      Well, except from the prototyped-based OO, JavaScript is roughly Scheme minus macros plus C-like syntax.

      So, JavaScript at least supports some type of functional programming (much more than, say, Java). You can easily write in it all the "standard" higher-order-functions like map, fold, filter, etc.

      Exceedingly off-topic, I known: the thing that prevents me from really using it is its scoping brain damage. Local variables are local to the whole function, so when I find myself wanting to write (function(x){...})(1) to create a new "x", I give up and go back to Lua or Scheme.

    17. Re:Awesome! by porl · · Score: 1

      the parent was being a smartarse :) he was simulating running the 'diff' program on the two 'files' that contained the words Java and Javascript. diff is a program used mainly by coders to find the differences between two files. hence the difference between 'Java' and 'Javascript' is that one says 'Java' and the other 'Javascript' :)

      porl

    18. Re:Awesome! by FrangoAssado · · Score: 1

      Hey, lighten up, it was a joke. The part you didn't understand was the output of the "diff" command saying:

      • " 1c1 ": the difference was that the line 1 in the first file changed to the line 1 in the second file, and the difference is:
      • " < " [in the first file we had this:] " Java "
      • " > " [and in the second file it became this:] " JavaScript "

      See, now that it had to be explained, it's not funny. Well, it wasn't funny to begin with.

      And, since I just wasted 5 minutes writing and formatting this, here's the link so you don't have to use Google: man diff (feel free to ignore it if you don't really want to learn about diff). I always use "diff -u" myself (I find the output more readable).

    19. Re:Awesome! by rts008 · · Score: 1

      Thanks for the info.
      I suspected as much, but was not sure.

      *sigh* sometimes I can't help but to feed the trolls!

      Mom always said you could catch more flies with honey than you could with shit.

      I guess she was right.

      --
      Down With Slashdot BETA!!! I've been around the corner and seen the oliphant; you can only abuse me from your perspecti
    20. Re:Awesome! by Jesus_666 · · Score: 1

      Well, as others have pointed out, diff simply outputs the differences between two programs in a standardized way. Well, in one of several standardized ways. Sorry if I ticked you off; "is familiar with *nix to a certain degree" is one of the safer assumptions to make on Sashdot, so...


      As for my username: It was actally chosen for trolling, a long time ago in a far away chatroom. The concept was "controversial but actually meaningless". I stuck with it because I didn't yet have a proper nickname I'd stuck with and I kinda liked the sound of it.

      Generally, I avoid trolling nowadays, though. The name describes me more through none of the two extremes of it applying to me - and because I identify with it for the sake of identifying with it. Most people actually react rather well to it, although I can see how it might worsen a perceived troll or flame.


      Oh and say hi to Horrigan from me when you meet him. ;)

      --
      USE HOT GRITS WITH STATUE OF NATALIE PORTMAN (NAKED AND PETRIFIED)
    21. Re:Awesome! by BZ · · Score: 1

      > Local variables are local to the whole function

      That's being fixed. See http://developer.mozilla.org/en/docs/New_in_JavaScript_1.7#Block_scope_with_let for some documentation. With any luck, ECMA will standardize this as part of EcmaScript 4.

    22. Re:Awesome! by rikas · · Score: 1

      Yes they are! Complete morons! :

    23. Re:Awesome! by oliderid · · Score: 1

      I bought the book Pro Javascript Design patterns ISBN-13: 978-1-59059-908-2

      It is mainly about Object oriented technique with Javascript.

      Nice but it is still mainly hacks. They doesn't provide enough security (way too simple to override a singleton or setting strong typed variables in an interface is cumbersome).

      Otherwise there are really cool features, especially concerning classes (cloning, instance, and so on).

    24. Re:Awesome! by Ahruman · · Score: 1

      JavaScript is a functional scripting language originally derived from Ecmascript
      -1 Hogwash.
    25. Re:Awesome! by Anonymous Coward · · Score: 0

      JavaScript is a functional scripting language originally derived from Ecmascript.


      Backwards. Netscape created LiveScript, then called it JavaScript (as you noted, for marketing reasons), then submitted it to ECMA for standards development. ECMA created ECMAScript, with JavaScript being one implementation.

      Javascript is really more like Lisp with C-style syntax.
  2. Doing things the slow way by techno-vampire · · Score: 2, Insightful

    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!

    --
    Good, inexpensive web hosting
    1. Re:Doing things the slow way by gstoddart · · Score: 2, 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 love to see it. For now, it sounds like "because we can" sorta stuff (not that there's anything wrong with that).

      Cheers
      --
      Lost at C:>. Found at C.
    2. 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
    3. Re:Doing things the slow way by techno-vampire · · Score: 1
      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!

      --
      Good, inexpensive web hosting
    4. Re:Doing things the slow way by doombringerltx · · Score: 1

      They provide an example. They have a tetris game written in java then implemented in javascript. (I don't know if its in the article here. I first read about this somewhere else). But the controls are a little sluggish and the game was fairly simple, but over all it was really impressive for javascript. I can see plenty of uses for this. If you are a business you want to make your web site available and functional to as many people as people. Not everyone has an up to date java run time on their computer. If the site made use of a japplet it'd be possible to provide a javascript implementation of it as an alternitive for those without the java run time. It sounds like what they've come up with will make that easy and cost effective to do

    5. 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?
    6. Re:Doing things the slow way by gstoddart · · Score: 1

      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
      --
      Lost at C:>. Found at C.
    7. Re:Doing things the slow way by eln · · Score: 2, 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.

    8. Re:Doing things the slow way by sanimalp · · Score: 1

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

    9. Re:Doing things the slow way by Anonymous Coward · · Score: 0

      I'm not a huge expert or anything, but I can imagine people wanting to write in their preferred language instead of javascript. On the other hand, if it would be really beneficial to use these languages in a browser, can't people just work with browser developers to support these languages natively?

    10. Re:Doing things the slow way by gstoddart · · Score: 1

      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
      --
      Lost at C:>. Found at C.
    11. Re:Doing things the slow way by Anonymous Coward · · Score: 0

      You want an application, here you go:
      JSP form validation.
      Write Some semi-complex server-side validation of form entries being passed back in a java-bean. Run it through Orto, and voila, you have access to the same validation on the client too.
      One piece of code to maintain so that you know both ends are validating the same way. Validation on the front end so that there should be fewer round trips to the server and back, but if someone turns off javascript (or worse, starts screwing with your code with greasemonkey or firebug) then you still have the server side sanity check to fall back on.

      It's not sexy, but it's an issue I run into all the time.

    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:Doing things the slow way by AKAImBatman · · Score: 1

      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.

      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.
    14. Re:Doing things the slow way by hey! · · Score: 1

      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 is a non-trivial application that uses more than a few dozen Java classes load and run in a reasonable amount of time. You're either donwloading a significant portion of J2SE, encoded as javascript, or you're loading optimized javascript for some stack of method calls which works wonderfully for a small app but makes the problem worse for a large one.

      I've seen some mobile development platforms that essentially analyze an app and create custom deployments of themselves for resource constrained devices. It's clever, but I'm not sure it works in the "drive by user" world of the web.

      --
      Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
    15. Re:Doing things the slow way by jtolds · · Score: 1

      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.

      It is definitely playable on my OLPC, albeit a bit slowly. But Slashdot is just as slow with all its new Javascript stuff.
    16. Re:Doing things the slow way by Anonymous Coward · · Score: 0

      I was amazed to find that it runs almost OK in Firefox 2 on a 400MHz box. The controls are sluggish and there's a noticable delay when a new brick drops, but that's by orders of magnitude better than i expected.

    17. Re:Doing things the slow way by RAMMS+EIN · · Score: 1

      ``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 execution time, as well as various places in between.

      --
      Please correct me if I got my facts wrong.
    18. Re:Doing things the slow way by evanbd · · Score: 2, 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 language / platform). For what I do, it does a good job of balancing speed and ease of development and a number of other things.

      If you'd like to claim that Java is universally slow, I have a program spec you're welcome to implement in the language of your choice for comparison. I'll warn you, though, the last time someone implemented it in C++ it came out slower (though once I pointed out the subtle algorithmic difference between our implementations, the C++ won by 10-20%).

    19. Re:Doing things the slow way by morgan_greywolf · · Score: 1

      This is like writing a Cray emulator for your TI 99/4a -- I don't know what it buys you.
      Hey!!! I'm posting this from Firefox running under NetBSD running under a Cray emulator on a TI 99/4a, you insensitive clod!
    20. Re:Doing things the slow way by bytesex · · Score: 2, 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 communication, access shared memory ? Tough ! This java, man ! And it's in a world of its own. It's no miracle the java guys are always so evangelical - they're not *allowed* to see what's outside their world.

      --
      Religion is what happens when nature strikes and groupthink goes wrong.
    21. Re:Doing things the slow way by omeomi · · Score: 1

      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.

      I think the article was likely talking about web-based iPhone games, which presently is the only Apple-sanctioned way of playing a game on your iPhone. Unfortunately, the web-based games are pretty limited compared to what can be played on, say, a Jailbroken iPhone. Native iPhone applications aren't written in Javascript...I think the new SDK is based on Objective C, though I haven't actually done any iPhone development.

    22. Re:Doing things the slow way by poot_rootbeer · · Score: 1

      (The sample Tetris clone loaded very quickly for me.)

      Okay, but that's a pretty trivial example indeed -- Tetris was developed in the mid-'80s on a Soviet PDP-11 clone. Tetris has been implemented as simple state machines that run on wristwatches and keychains.

      While novel, I don't think JVM-implemented-in-Javascript is going to be a practical path for anything very complex. This isn't going to enable me to run Eclipse as a web app.

    23. Re:Doing things the slow way by poot_rootbeer · · Score: 1

      in general, just because something is interpreted doesn't mean it has to be slow.

      However, except in rare and unusual cases (e.g., using an interpreter that does realtime execution analysis and modifies code on the fly), interpreted code will always be at least a little bit slower than compiled code.

    24. Re:Doing things the slow way by Amouth · · Score: 1

      it isnt' a speed issue.. i mean every language has it's + and -'s i wouldn't want to dispute that..

      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

      oddly it isn't consitant from one CPU to the next but all the cpu's i have tested will have error's at and all have been with less than 1k amounts..

      it is odd as hell but it is the one reason i don't use java.. if i can't trust it to do basic math then i can't trust it at all

      --
      '...if only "Jumping to a Conclusion" was an event in the Olympics.'
    25. Re:Doing things the slow way by evanbd · · Score: 1

      Floating point numbers are expected to behave like that. It's an inherent limitation of the base conversion combined with finite precision and any exact equality test. 8.12 gets rounded off to a number slightly less than 8.12 when stored as a float; when multiplied and cast it gets rounded down to 811.

      #include <stdio.h>

      int main(int argc, char* argv) {
      double val;
      int upper;
      double newval;

      val = 8.12;
      upper = (int)(val * 100.0);
      newval = ((double)upper)/(100.0);

      printf("val: %e\nupper: %d\nnewval: %e\ndiff: %e\n", val, upper, newval, (val - newval));
      return 0;
      }

      evand@Desktop:~/test$ gcc --version
      gcc (GCC) 4.2.3 (Debian 4.2.3-3)
      Copyright (C) 2007 Free Software Foundation, Inc.
      This is free software; see the source for copying conditions. There is NO
      warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

      evand@Desktop:~/test$ gcc test.c
      evand@Desktop:~/test$ ./a.out
      val: 8.120000e+00
      upper: 811
      newval: 8.110000e+00
      diff: 1.000000e-02

      Java and C are both behaving exactly how they're supposed to. First rule of working with floating point numbers: never do an exact equality test on the results of calculations. That includes testing the edge case of rounding, which is what you're doing. If you're rounding off to an int, you had better be prepared to have very small errors get magnified on occasion.

      It's kinda silly to find a fault with one language, and then use that fault as basis to switch to another language without first checking whether it has the same fault. And in this case, the fault is not with the languages.

    26. Re:Doing things the slow way by evanbd · · Score: 1

      Replying twice, bad form I know, but I forgot to mention:

      If you really care about floating point precision, it's trivially easy to get in java: use the strictfp keyword on the relevant class or method, and java will generate code that *exactly* implements IEEE 754 arithmetic on all hardware. I don't know off hand how to do that in other languages; I imagine some make it easy and some make it hard to impossible. I can't see it being much easier than specifying a single keyword with the appropriate scope, though. (There will, obviously, be a performance penalty involved if the underlying hardware is not inherently IEEE 754 compliant.)

    27. 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
    28. Re:Doing things the slow way by cibyr · · Score: 1

      "i understand floating point errors"

      I don't think you do, because just before that you said "newValue does not alwasy equal value.. even though it should".

      Perhaps you read up on how floating point numbers work, and what you're asking the computer for when you use syntax like that. Unsurprisingly, it has the same behaviour in C, with gcc on my Athlon64 running linux:

      #include // Why does slashdot eat my less-than stdio.h greater-than when I'm in plain-old-text mode?

      int main() {
                      double value = 8.12;

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

                      printf("value: %g\n", value);
                      printf("upper: %d\n", upper);
                      printf("newVal: %g\n", newVal);

                      return 0;
      }

      cibyr@ciserv ~ $ gcc test.c
      cibyr@ciserv ~ $ ./a.out
      value: 8.12
      upper: 811
      newVal: 8.11

      But picking 8.12 * 100 as your test case makes me think you're maybe not such an idiot... anyone else see the interesting properties of that?

      --
      It's not exactly rocket surgery.
    29. Re:Doing things the slow way by Atario · · Score: 1

      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.
      I think your complaint here is with Java, not Javascript or Orto. I guarantee it would take longer for this Tetris to load up were it directly in Java if you didn't already have the Java runtime loaded up in memory -- and maybe even if you did.

      So, I'd grade Orto as "damn impressive".
      --
      "A great democracy must be progressive or it will soon cease to be a great democracy." --Theodore Roosevelt
    30. Re:Doing things the slow way by evanbd · · Score: 1

      Even after it loaded, it was sluggish with poor response to the controls. In native Java there'd be a load time, but if done well it would be quite snappy after that.

      Don't get me wrong, I'm quite impressed. But I'm impressed in the "damn that's neat" sense, not in the sense that I'd ever contemplate using it for anything.

    31. Re:Doing things the slow way by SanityInAnarchy · · Score: 1

      The Ruby-in-Javascript ended up being faster than Ruby 1.8 (the stable version) -- although it did use Ruby 1.9 on the server to compile it to bytecode.

      --
      Don't thank God, thank a doctor!
    32. Re:Doing things the slow way by Anonymous Coward · · Score: 1, Informative

      REM MS QuickBASIC 4.5

      DEFINT A
      DEFDBL B

      b1=8.12
      a=b1*100
      b2=a/100

      PRINT b2

      REM answer is 8.1199999999999 ;)

    33. Re:Doing things the slow way by Lisandro · · Score: 1

      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 lost. Are you talking about Javascript, Java, or both?

    34. Re:Doing things the slow way by Shadow-isoHunt · · Score: 1

      mIRC script. //echo Result: $calc((8.12 * 100.0) / 100.0)
      Result: 8.12

      Back in the day I wrote a quakeworld client that used pure mircscript & picture windows, and later expanded it so that it did a $dll call to do opengl rendering w/ software overlay(much better results).

      --
      www.isoHunt.com
    35. Re:Doing things the slow way by Anonymous Coward · · Score: 0
      What language can you stand, then?


      (...)

      % ruby
      print (8.12*100.0).to_i.to_f/100.0;
      8.11

      Here the to_f and especially the ';' at the end is redundant:

      % ruby
      print (8.12*100.0).to_i/100.0
      8.11
    36. Re:Doing things the slow way by techno-vampire · · Score: 1

      Both together.

      --
      Good, inexpensive web hosting
    37. Re:Doing things the slow way by Kegetys · · Score: 1

      Here's how to get a correct result with python:

      Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32
      Type "help", "copyright", "credits" or "license" for more information.
      >>> print float(int(round(8.12*100.0)))/100.0
      8.12

      The round is important to do proper rounding for the integer conversion.

    38. Re:Doing things the slow way by Anonymous Coward · · Score: 0

      Well, of course you're going to get that error when you do those things. The hint here is that if you truncate something in the middle of the calculation, you can't expect any correct results.

      Let's try the python example and see what we're really doing. Python is good because it'll show you what the values really are.
      >>> 8.12
      8.1199999999999992

      This is the closest thing to the original value you'll get. There's no way to represent 8.12 exactly with that datatype.
      Next step is this:
      >>> 8.12 * 100
      811.99999999999989

      Once again, this is as close as you'll get.

      Now's the interesting part. The OP decides to truncate this value to 811.
      >>> int(8.12 * 100)
      811

      Then divide by a hundred which will of course look like it's a big error. All because of truncating the vale before trying to get it back to the start value.

      If you'd do this instead, there wouldn't be anything to write about.
      >>> print (8.12 * 100)/100
      8.12

      No truncation, no spectacular error. And I didn't even have to throw in that sort of pointless cast to a floating point type. :)

    39. Re:Doing things the slow way by __aawavt7683 · · Score: 1

      *sigh* Please learn to understand computers. See this page: http://docs.python.org/tut/node16.html -- it seemed pretty good for explaining the basics.

      8.12 = 8 + 0/2 + 0/4 + 0/8 + 1/16 + 1/32 + ... the list goes on. The problem exists because 0.12 cannot be represented as a sum of 1/2^i for i = 0 to 32 (or probably 64, or probably at all).

      Further, this is why A GOOD ASSEMBLY COURSE should still be required in college. If you knew bitwise representations.. you'd know why you are NEVER supposed to take approx values and assume they're equal. As one person mentioned, rounding would give you the answer you wanted, but it's generally considered that two numbers are equal if the subtraction between them is 0.000000001 or so. After that, who cares?

      As an interesting assignment, take values nearly 32 bits in size (start with 4 294 967 295 or so) and multiply them by numbers very close to zero -- 0.0000000001, for example. I'm sure you won't get anything very near zero.

      And stop using int like that. You got rid of the 0.9999999999998234 extra that was attached to the number. Alternatively, knowing that 8 decimals is good-enough precision, another trick: int(double + 0.0000000001) should yield the true number.

      perl -e 'print ((8.12 * 100) / 100);'
      8.12
      perl -e 'print (int(8.12 * 100 + 0.0000000001) / 100);'
      8.12
      perl -e 'print ( (8.12 * 100) - (int(8.12 * 100) + 1));'
      -1.13686837721616e-13

      Huh. accurate to 12 decimals. That's good enough for me, I guess. I suspect Java is no different. Basic math... for anything else, use Mathematica ;-)

      -DrkShadow

    40. Re:Doing things the slow way by Anonymous Coward · · Score: 0

      If you want numerically accurate answers, use decimal math instead of floating point math.

      ex. in python:

      >>> from decimal import Decimal
      >>> value = Decimal("8.12")
      >>> upper = value * Decimal("100")
      >>> newVal = upper / Decimal("100")
      >>> newVal
      Decimal("8.12")

      ex. in java:

      import java.math.BigDecimal;

      public class Main {
          public static void main(String[] args) {
              BigDecimal fact = new BigDecimal("100.0");
              BigDecimal value = new BigDecimal("8.12");
              BigDecimal upper = value.multiply(fact);
              BigDecimal newVal = upper.divide(fact);

              System.out.print(newVal.toPlainString());
          }
      }

      Result: 8.12

    41. Re:Doing things the slow way by Anonymous Coward · · Score: 0

      Amouth, dude, you just got burnt. Severely.

    42. Re:Doing things the slow way by Anonymous Coward · · Score: 0

      (* (/ 8.12 100.0) 100.0)
      8.12

    43. Re:Doing things the slow way by Einmaliger · · Score: 1

      This is not a Java problem. The number 8.12 cannot be exactly represented as finite base-2 number.

      0.12 is 0.(000111101) in binary, with all fractional digits repeating. In a floating point representation only 23-52 significant digits are stored, so it can never store 8.12 exactly. Multiplying it by 100 will result in about 811.999..., so cutting of the fractional part of 8.12*100 yields 811. As pointed out in another posting, the better way would be rounding the result before casting it.

    44. Re:Doing things the slow way by Anonymous Coward · · Score: 0

      Erlang!!

      Erlang (BEAM) emulator version 5.6.1 [smp:8] [async-threads:0]
      Eshell V5.6.1 (abort with ^G)
      1> 8.12*100.0.
      812.000

    45. Re:Doing things the slow way by Anonymous Coward · · Score: 0

      that ISN'T an error, and has nothing to do with floating point inaccuracy.

      int upper = (int)( value * 100.0) ;
      is an INT. it has no exponential component, so for example:
      value = 3.0, upper = 300
      value = 4.12, upper = 400
      value = 52.52, upper = 5200

      when you cast upper to a double it does not and in fact SHOULD not retain the mantissa component of value. that would be an error, the whole point of the integer type is that it DOES NOT have a mantissa.

      this isn't even a math error, newVal is essentially the floor of value. floor values by definition also don't have exponential components.

      if you WANT to retain the mantissa, here's a clue, don't hold the upper as an int.

      the following code will work:
      double upper = value * 100.0 ;
      double newVal = upper / 100.0 ;

      in the above case, you may actually hit a floating point error, b/c depending on the contents of value, the exponent may be inaccurate.

    46. Re:Doing things the slow way by asdfghjklqwertyuiop · · Score: 1


      Of course, truncating was the point of the whole post. That's what the poster was doing.

    47. Re:Doing things the slow way by TheBigMacMan · · Score: 1

      Smalltalk (Cincom VisualWorks):
      (8.12 * 100) asInteger asFloat / 100.0
      8.12

    48. Re:Doing things the slow way by DragonWriter · · Score: 1

      it isnt' a speed issue.. i mean every language has it's + and -'s i wouldn't want to dispute that..

      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


      Yeah, so? Floating point errors on values that aren't positive or negative powers of two are rampant in any system using approximate binary floating point math, rather than exact math. That's the default for non-integer math for most programming languages (Java, C, C++, Javascript, Ruby, Python, and many more.) There are some languages that do exact arbitrary-precision decimal math by default unless a value used which has no exact representation (Scheme comes to mind), but they are rather the exception rather than the rule. And, if you need exact math, most major languages have exact math libraries available (for Java, look into BigDecimal.)

      oddly it isn't consitant from one CPU to the next but all the cpu's i have tested will have error's at and all have been with less than 1k amounts..


      Floating point errors are a result of conversion to and from binary representation, and have no connection to the size of the number.

      it is odd as hell but it is the one reason i don't use java.. if i can't trust it to do basic math then i can't trust it at all


      BigDecimal is in the standard library; otherwise, Java's floating point math behaves just like binary floating point in most languages, with the same kind of problems.
  3. 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.

    1. Re:But... by maxume · · Score: 1

      It depends on how much you prefer writing Java to writing javascript.

      Presumably the compiler/translator/whatchamahoosit can also smooth out the differences between various javascript platforms.

      --
      Nerd rage is the funniest rage.
    2. Re:But... by Ai+Olor-Wile · · Score: 1

      I, for one, would gladly call that problem "how long it takes a Java plug-in to load, and how unstable they are in Mozilla browsers." The Xetris sample posted elsewhere in these comments runs very quickly and with very little CPU usage, something which I cannot ever remember receiving from a browser plug-in from sun.java.com. In a similar stroke, I imagine it's probably nice in thin-client situations where the client machine doesn't have the system resources for a full JVM, also.

    3. Re:But... by morgan_greywolf · · Score: 2, Insightful

      I'm struggling to see how this is truly beneficial.


      If you can run it under JavaScript, you can run it on an iPhone.
    4. Re:But... by Profane+MuthaFucka · · Score: 2, Insightful

      Don't you see? Javascript is available on every hardware platform! You don't need to have a separate Java binary package from Sun to run Java programs. You can use the portable javascript implementation in your browser! It makes sense.

      --
      Fascism trolls keeping me up every night. When I starts a preachin', he HITS ME WITH HIS REICH!
    5. Re:But... by samkass · · Score: 2, 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 for more information.

      --
      E pluribus unum
    6. Re:But... by sootman · · Score: 1

      Does it run Linux?

      Screw that... does it run Javagator?

      --
      Dear Slashdot: next time you want to mess with the site, add a rich-text editor for comments.
    7. Re:But... by Seahawk · · Score: 1

      It's is practically impossible to unit test javascript code today - this is a problem, at least for me, in a world where more and more logic moves to the browser.

      With Java -> JavaScript translation I will be able to write my code in java, take advantage of the unit testing tools in java, and then "compile" and deploy my application as JavaScript.

    8. Re:But... by Anonymous Coward · · Score: 0

      this is extreamly benificial, it allows you to use java in your web app, on the browser, without loading an applet or requiring the user to download any kind of non-standard plugin.

      to put it in context:
      -- there is a lot more java code for a lot more things than there is javascript code.
      -- java, despite it's many flaws, is a much more powerful and flexible language than javascript, and it's a hell of a lot easier to read, comment, and structure
      -- most of the standard means of using java in web pages requires you to
        a) put it in an applet, which generally means your restricted to stand-alone graphical widgets
          b) use some kind of non-standard plugin, which the user must download, which in many cases they do not want or cannot download
        c) go back to the web server, which is subject to network delays

      as for interpreting ruby, it's even better, since we have all the above PLUS the fact that there isn't a standard way to run ruby in the browser at all at the moment.

    9. Re:But... by sohp · · Score: 1

      Never ask a geek, "Why?", just nod your head and back away slowly...

    10. Re:But... by Anonymous Coward · · Score: 0

      You might check out Crosscheck. It's fairly new, so it's probably got a ways to go when it comes to emulating any of the IE variants. But the ability to write unit tests for JavaScript and test them against multiple browser (even ones not installed on the system) could make it a really nice tool.

  4. Re:Java running under Javascript... by Anonymous Coward · · Score: 0

    Still with the "Java is slow" comments. Jeez.

  5. 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.

    1. Re:Ruby and Java, and also Python by Saija · · Score: 1

      hehehe
      Buddie "PyPy" in spanish sounds like "PeePee", you know the thing get out of your Pipi... hehehe

      --
      Slashdot ya no es que lo era! ;)
  6. 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.

    1. Re:Google Web Toolkit by Anonymous Coward · · Score: 0

      Actually, the GWT is quite a different thing, If I'm not mistaken. It's intended to simplify the construction of java based AJAX applications, where some bits run in the browser, and the rest on the server, and Interaction happens mostly by xmlhttprequests. I don't think you can get stand-alone applications with GWT, and even applications that just run in the browser and are loaded from a file appear unlikely, they'll always need a browser with javascript support and a webserver that can execute Java. Orto on the other hand doesn't bring any simplification to the browser<->Server communication, but the applet can theoretically run offline, and depending on how the application was designed, it's easy to convert it to a standalone (java) application.

    2. Re:Google Web Toolkit by quick2think · · Score: 1

      One big difference here is that the JavaScript created by the GWT Java->JavaScript translator is optimized. The optimized code is all that is sent to the browser. Imagine some well written, but verbose, Java code being sent to the browser, and then compiled. Sounds like a waste of time/resources to me. Interesting, I would like to see the debugger work too. If there is none, then it really is beneath what GWT already does.

    3. Re:Google Web Toolkit by H0p313ss · · Score: 1

      I don't think you can get stand-alone applications with GWT, and even applications that just run in the browser and are loaded from a file appear unlikely, they'll always need a browser with javascript support and a webserver that can execute Java.

      Actually no, you can build an application in Java with no client/server communications and have GWT generate the client javascript code and run it stand-alone or serve it as a standard web page. It really does generate (compile) a javascript version of the java code for the client.

      --
      XML is a known as a key material required to create SMD: Software of Mass Destruction
    4. Re:Google Web Toolkit by AngryLlama · · Score: 0

      I believe the article mentioned the Java code already being compiled to bytecode. This would imply that comments, long variable names, etc, are already stripped out. I do agree, this still seems rather wasteful compared to the GWT technique.

    5. Re:Google Web Toolkit by jesterzog · · Score: 1

      I'm not sure what practical advantage having a full JVM gives you.

      I don't think it'd be much use to me, but perhaps it could be useful if you're trying to port a closed source application or library, maybe? I'm only speculating and I haven't closely looked at either the GWT or at this project.

    6. Re:Google Web Toolkit by gedhrel · · Score: 1

      You aren't limited to Java. There are other languages that target the JVM.

    7. Re:Google Web Toolkit by Anonymous Coward · · Score: 0

      I've looked closely at the GWT before, it's output javascript is completely unreadable by humans, thus negating any chance of easily debugging errors that occur in that output but not the normal java version, or having a page that needs to have components written in java work with components written in javascript.

      this also avoids requiring you to work with the GWT framework.

      not that GWT isn't useful, GWT widgets would probably have a lower speed penalty than interpreting the thru a js jvm (run-time parsing takes TIME), but this method allows you to use browser-side java code in situations where GWT would be inappropriate.

  7. 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.
    2. Re:Strange by lcampagn · · 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.

    3. Re:Strange by xero314 · · Score: 1

      Javascript is inherently multithreaded and embedded in a highly asynchronous environment, het has no threading API whatsoever. This is because there is no reason to create custom threads. Multi-threaded functionality can be handled in a safe way through event handling. Implementing a semaphore is pretty simple if you need such a thing, but creating true asynchronous applications is actually a better approach.
    4. Re:Strange by emkman · · Score: 1

      Things have matured a lot lately, and you can almost get by without writing any browser specific hacks. Umm kinda. Tons of browser specific Javascript (and CSS!!!) hacks are still needed to write an app that plays nice across all platforms. The only difference is that developers of libraries such as JQuery, Prototype, and ExtJS have done an excellent job of encapsulating all the hacks into a library with a consistent API for you to use. They give you normalized event handling, keycode input, DOM element lookup etc. However if you tried to fly solo and develop without one of these libraries, Javascript would still suck as much as it ever did. BTW, my company wrote a fairly large web app using ExtJS and made extensive use of its templating system, giving a very snappy Ajax app. I highly recommend it.

      --
      Moderation Totals: Flamebait=2, Troll=1, Redundant=1, Insightful=6, Overrated=1, Underrated=1, Total=12. (not mine)
    5. Re:Strange by JCSoRocks · · Score: 1
      The hacks still continue depending upon what you want to do. If you're trying to seriously manipulate your interface using JavaScript you're still going to find yourself having to write browser hacks. Even with IE7 I've still run into plenty of things that don't work correctly in it versus FireFox.

      This doesn't make me hate JavaScript though... it just makes me hate browsers that don't work. If I tell you to update the contents of an object you should update it without me having to move the focus to that object to get you to repaint it. :-/

      The *only* thing I've hated about JavaScript is that I've never found a good JavaScript environment / debugging method. Even with FireFox and various developer programs debugging JavaScript is still a hassle (and of course that still doesn't help you when you've got an IE specific issue).

      --
      You are using English. Please learn the difference between loose and lose; they're, there, and their; your and you're.
    6. Re:Strange by jrumney · · Score: 1

      Getting Java or Ruby code to interact with the DOM seems like it would be a huge pain compared with JQuery.

      Not really, the netscape.javascript.* package for interacting with Javascript and the DOM has been a standard part of Java (even the notoriously incompatible MS JVM) since the early days. Perhaps it isn't as well known as it could be due to being outside the java.* namespace.

    7. Re:Strange by rhizome · · Score: 1

      Multi-threaded functionality can be handled in a safe way through event handling. Implementing a semaphore is pretty simple if you need such a thing, but creating true asynchronous applications is actually a better approach.

      Pointers to async JS would be nice, since my RSS reader pegs my CPU for minutes at a time while fetching updates to my 100+ feeds. When this happens every 20min you can see where this might become frustrating.

      --
      When I was a kid, we only had one Darth.
    8. Re:Strange by Anonymous Coward · · Score: 0

      I love JavaScript but theres a good reason people including me want to write in some other language: the lack of tools and methods for writing and collaborating on large JavaScript projects. GWT (and others) let you use Eclipse or the IDE and other language tools of your choice.

  8. Re:Java running under Javascript... by Anonymous Coward · · Score: 0, Troll

    It's especially amusing when it comes from people who predominately use Python or Ruby.

  9. 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!
  10. Safe and Secure I'm Sure by pdq332 · · Score: 1

    Congratulations! Sounds like a very secure platform. Maybe there's time to include it in IE8.

  11. I just need to get this out of my system by Daishiman · · Score: 5, Funny

    'Orto' means 'ass' in Spanish.

    1. Re:I just need to get this out of my system by kellyb9 · · Score: 2, Funny

      'Orto' means 'ass' in Spanish. Oh wow, initially I didn't understand the point of this project. Thanks for clearing that up for me.
    2. Re:I just need to get this out of my system by owlstead · · Score: 1

      Don't worry, I've already clicked the thumbs down button, it seems somebody was trolling there :)

    3. Re:I just need to get this out of my system by navarroj · · Score: 2, Informative

      No, it doesn't.

    4. Re:I just need to get this out of my system by baka_toroi · · Score: 2, Informative

      It does. Only (I believe) in Argentinian Spanish though, not in the rest of the Spanish speaking countries. http://www.elcastellano.org/miyara/dic_arg_esp.html (Site in Spanish)

    5. Re:I just need to get this out of my system by alx5000 · · Score: 1

      I think it's more of an impolite double entendre. Orto means right (as in "right angle", ángulo recto, or "right spelling", ortografía), but recto can also mean rectum.

      --
      My 0.02 cents
    6. Re:I just need to get this out of my system by Anonymous Coward · · Score: 0

      Although I did use an online dictionary, most of them states it means 'rising'. Unless it is some slang or something?

    7. Re:I just need to get this out of my system by Anonymous Coward · · Score: 0

      No, it doesn't. Except in Argentina, that is. Pretty much the whole World, I'm afraid.

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

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

    1. Re:No Perl? by Digi-John · · Score: 1

      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!.

      --
      Klingon programs don't timeshare, they battle for supremacy.
    2. Re:No Perl? by Anonymous Coward · · Score: 0

      Client side perl would kick ass. Then I could match my front end with the back. I think your front end has already met your back end.
    3. Re:No Perl? by Instine · · Score: 1

      COBOL? You were lucky!

      --
      Because you can - or because you should?
    4. Re:No Perl? by hal2814 · · Score: 0, Troll

      Wow, then you could screw yourself with Perl code instead of just screwing anyone who actually tries to read the code later.

    5. Re:No Perl? by Jesus_666 · · Score: 1

      That's a nice idea, but I think that client-side PHP is the wave of the future. getPHPScript('today')!

      No, wait. I think it was get_php_script('today'). Or was it get_today('script', _PHP_)...?

      --
      USE HOT GRITS WITH STATUE OF NATALIE PORTMAN (NAKED AND PETRIFIED)
    6. Re:No Perl? by SCHecklerX · · Score: 1

      Actually, I used to do mine in REXX :-). Ok, the first stab at it was on CERN HTTPD on windoze using C. Did I really do that, wow :-)

    7. Re:No Perl? by Anonymous Coward · · Score: 0

      You already can. It's called PerlScript. It just seems to be IE only, however, so not particularly useful, just like the host browser used to implement it:

      http://www.xav.com/perl/Components/Windows/PerlScript.html

    8. Re:No Perl? by XnR'rn · · Score: 0

      At my last place of work we still used REXX (and once I had to poke it to make it work, I was wow, cool scripting language). REXX scripts helped do some automation for making cartoons. :>

  13. crazy japanese by trybywrench · · Score: 2, Funny

    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.

    --
    I came to the datacenter drunk with a fake ID, don't you want to be just like me?
    1. Re:crazy japanese by TheRagingTowel · · Score: 1

      I looked at the tetris .js files (just replace Xetris-en.html in Xetris-en.js in their demo tetris url), and I must say I don't think they wrote a JVM is javascript. It looks more likely they disassembled the bytecode and "transformed" it into javascript code. Neat idea.

      --
      4Z5TX
    2. Re:crazy japanese by Anonymous Coward · · Score: 0

      Wait until someone links in Rhino - http://www.mozilla.org/rhino/

  14. ONE WORD by kellyb9 · · Score: 0, Troll

    One word - Slllllllllllllllloooooooooooooooooooooow!!!

  15. 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.
    1. Re:Language stacks galore! by mweather · · Score: 2, Funny

      We could run Linux in Firefox in Linux in Firefox!

    2. Re:Language stacks galore! by Anonymous Coward · · Score: 0

      The new version of javascript is going to be based on python. Things will be getting very interesting for python coders!

    3. Re:Language stacks galore! by Instine · · Score: 2, Interesting
      --
      Because you can - or because you should?
    4. Re:Language stacks galore! by omnipresentbob · · Score: 1

      in Windows! .... or not.

    5. Re:Language stacks galore! by g1zmo · · Score: 2, Funny

      It's Ice Weasels all the way down....

      --
      I have found there are just two ways to go.
      It all comes down to livin' fast or dyin' slow.
      -REK, Jr.
    6. Re:Language stacks galore! by HeroreV · · Score: 1

      IronPython targets the Common Language Infrastructure (e.g. Mono and .NET), not the JVM. Also, nowadays much of PyPy is written in C, so it's not going to run on IronPython (or any other Python implementation).

      Anybody seriously wanting to run Python in web browsers should look to IronMonkey.

  16. Re:Java running under Javascript... by spiffmastercow · · Score: 1, Informative

    The primary reason its okay for python to be slow, but not for java, is that python isn't a crippled version of C++ that runs at 1/10 the speed, whereas java is.

    That, and the fact that you can rewrite the performance-critical portions of python code in C if you need to.

  17. Re:Java running under Javascript... by Threni · · Score: 1

    > Because neither one is slow enough on its own?

    Yes, but this way you get the speed of Java, and the strongly typed, fun to develop world of Javascript.

  18. Haskell, too by Monkius · · Score: 1
    --
    Matt
    1. Re:Haskell, too by pjt33 · · Score: 1

      Prolog in Javascript 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.

  19. * Urk * by Tarlus · · Score: 2, Funny

    Anybody else twitch at the sight of that headline?

    --
    /* No Comment */
    1. Re:* Urk * by Z34107 · · Score: 1

      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.

      --
      DATABASE WOW WOW
  20. Re:Java running under Javascript... by Anonymous Coward · · Score: 0

    Java is still slow.

  21. All what is need now by quickbasicguru · · Score: 1

    All what is needed now is an implementation of Javascript in Java (and possibly have it be compiled).

    1. Re:All what is need now by skeevy · · Score: 1
  22. As a side note... by Decameron81 · · Score: 2, Funny

    As a side note: "orto" in argentina means ass. I don't think I'd want to run anything through it.

    --
    diegoT
  23. google Web Toolkit? by mweather · · Score: 1

    So how Orto different from Google's Web Toolkit? Does it accomplish it's goal without AJAX?

    1. Re:google Web Toolkit? by jrumney · · Score: 1

      GWT is an API. You write your server side java code to use the GWT library to do its display instead of one of the alternatives like AWT, SWT or Swing. GWT then takes care of sending the right Javascript to the client to do the display. The client never gets sent any Java.

      This is a byte code interpreter written in Javascript. You send it compiled Java, and it interprets it using Javascript. Presumably it has limited support for one of the aforementioned graphics APIs, probably AWT, and probably only enough of it to get their demos running.

  24. Naming by buchner.johannes · · Score: 0

    Finally the name JavaScript makes sense

    --
    NB: The message above might reflect my opinion right now, but not necessarily tomorrow or next year.
  25. Re:Java running under Javascript... by Instine · · Score: 1

    or GWT?

    --
    Because you can - or because you should?
  26. Re:Java running under Javascript... by Anonymous Coward · · Score: 0

    Python and Ruby have nice foreign function interfaces/or making C extensions for them is easy. Java makes it a pain (on purpose, Sun doesn't want anything that isn't portable across the JVMs) to write JNI stuff. So, when Python is too slow for a task, you write the part in C and be done with it. Try the same with Java and you will want to gouge your eyes. Fuck JNI.

    That and the fact that Python and Ruby are a lot more high level languages than Java. Java is just a crippled C++ with garbage collection and running on top of a virtual machine. It's nothing exciting.

  27. Wonderful by Anonymous Coward · · Score: 0

    Now all we have to do is compile that Javascript into bytecode with Rhino, and it will tear a hole in the fabric of space and time.

  28. 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.

  29. Why? by BlueParrot · · Score: 1

    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.

    1. Re:Why? by Anonymous Coward · · Score: 0

      Why the hell would you use a JVM in Javascript when there are Java plugins for every major browser anyway?
      Please show me the Java plugin for any browser whatsoever on x86_64. Or are you defining 64-bit platforms as not "major" enough?
    2. Re:Why? by mweather · · Score: 1

      Adobe and Sun seem to have that opinion.

    3. Re:Why? by HeroreV · · Score: 1

      some user hostile DRMd machine that doesn't let you do Java but lets you do javascript Like the iPhone?
  30. More important languages by zxSpectrum · · Score: 1

    While Ruby and Java are nice and all, I give you Brainfuck and Ook!.

  31. Bah by Xogede · · Score: 0

    Brainfuck has been available for JavaScript for years!

  32. Number #1 app by bigsexyjoe · · Score: 2, Funny

    Clearly the top application of this project is me playing that Tetris game and telling my boss that it's research for my job.

  33. 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"....

  34. You must be a Java adept by Anonymous Coward · · Score: 0

    There are people who love Java and those who hate it. You missed a chance to trash it, so you are not of a former variety :)

  35. Silverlight's been doing this for over a year by Anonymous Coward · · Score: 0

    DLR in Silverlight 1.1 and 2.0beta already has Ruby/Python/compiled Javascript and C# on the browser. F# for functional programming is coming soon.

    Under their VM, it's 1000x faster than interp JS.

    I know this will go under the "lalalalalalalalalalala I cant hear you lalallaallalal" camp, but someone needs to say it's already been done.

    1. Re:Silverlight's been doing this for over a year by PixelSlut · · Score: 1

      Yeah, but that still falls into the "extra software to install" category. You need to install Silverlight (or Moonlight on Linux or Mac) to get this to work. The interesting part of this Java and Ruby thing is that it runs directly in the browser. That said, I think the DLR approach is better and more interesting. It's actually kind of sad that Tamarin is duplicating all the effort of this when they could totally take the Mono VM right now and do a lot of this stuff. Mono's VM is actually -really- fast and very useful for exactly this purpose.

    2. Re:Silverlight's been doing this for over a year by Anonymous Coward · · Score: 0
      Mono from Novell? Including the Microsoft patent deal? In Firefox?

      How about if Mono and Novell provide it with something compatible with GPLv3 and its patent grants. Lets see them do that.

      Even then there could be submarine patents in the thing that Microsoft haven't licensed to Novell.

      For technical reasons Mono is much more bloated than Tamarin.

  36. I believe that you're missing the point by sleight · · Score: 1

    Previously, so-called RIA applications were limited to those with Flash and JavaScript expertise. These advances may open this field up further to Java and Ruby developers who don't know JavaScript. This puts less cognitive burden on the individual developer which, on the whole tends to be a good thing.

    1. Re:I believe that you're missing the point by jrumney · · Score: 1

      Java developers can already develop so called RIA applications using an old technology called applets. Some of the first RIA applications used it, because ten years ago there was no such thing as cross browser Javascript and Flash was only useful for making vector animation cartoons.

  37. Ruby in Javascript Speed. by Safiire+Arrowny · · Score: 1

    The most interesting part in the last link is that the following process:

    - Ruby code in tag sent to the server via XMLHttpRequest
    - Code recieved by a Ruby1.9 Cgi program.
    - Cgi script compiles the code with YARV to opcodes and sends it back formatted as JSON.
    - Browser takes the Ruby opcodes and translates it to javascript with HotRuby and runs it.

    ..is somehow 5x faster in their example than running the same ruby script on Ruby1.8 as a shell script on the commandline. Their example is incredibly simple, but I am still surprised that it wasn't 5x slower.

    In any case I can't wait to be able to have all my application code written in Ruby.

    1. Re:Ruby in Javascript Speed. by ORBAT · · Score: 1

      ..is somehow 5x faster in their example than running the same ruby script on Ruby1.8 as a shell script on the commandline. Their example is incredibly simple, but I am still surprised that it wasn't 5x slower. I boggled at that too, but I simply thought I misunderstood the article (English isn't my native language.) I keep hearing that Ruby's interpreter is rubbish, but I had no idea it could be beaten by a JavaScript implementation running a Ruby interpreter. That's like WINE running Windows programs faster than XP.
    2. Re:Ruby in Javascript Speed. by SanityInAnarchy · · Score: 1

      WINE does, in fact, run some programs faster than Windows 2000, at least. I haven't seen any comparisons to XP.

      --
      Don't thank God, thank a doctor!
    3. Re:Ruby in Javascript Speed. by Safiire+Arrowny · · Score: 1

      Yeah, Ruby1.8's interpreter is quite slow. I suppose it helps that this is done by compiling to opcode with the new Ruby1.9 YARV interpreter which is a lot faster.

      I for some reason still thought the bottleneck would be running those opcodes through Javascript. I always thought of Javascript on browsers as quite slow, I suppose I am really thinking of how browsers can be slow in updating the graphical parts of the DOM.

    4. Re:Ruby in Javascript Speed. by DragonWriter · · Score: 1

      I boggled at that too, but I simply thought I misunderstood the article (English isn't my native language.) I keep hearing that Ruby's interpreter is rubbish, but I had no idea it could be beaten by a JavaScript implementation running a Ruby interpreter.


      The JavaScript implementation isn't running a Ruby interpreter, its running a (not full featured, as I understand) Ruby 1.9 bytecode interpreter. Comparing Ruby 1.8.x, which isn't bytecode compiled vs. an JavaScript interpreter for Ruby 1.9 bytecodes operating on precompiled bytecodes generated by the stock Ruby 1.9 bytecode compiler, and mostly what you are learning is mostly that (1) Ruby 1.9 is much better on the tested task than Ruby 1.8.x, and (2) much of the speedup comes from using a bytecode approach.

      (I've seen tests on narrow tasks where Ruby 1.9 was something like 20x as fast as Ruby 1.8.x, so I'm not at all surprised that you get examples of things for which this approach is 5x as fast as Ruby 1.8.x.)

  38. PerlScript by gknoy · · Score: 1

    http://en.wikipedia.org/wiki/PerlScript

    Neat, in a way. I recall playing a very VERY small bit with this ~5ish years ago, I believe. Not sure how useful it is, but it still warms my perl-loving heart.

  39. oh, goodie by nguy · · Score: 1

    That means it's as cumbersome to program in as Java and even slower than JavaScript. What more could you ask for?

  40. Re:Java running under Javascript... by Toonol · · Score: 1

    That and the fact that Python and Ruby are a lot more high level languages than Java. Java is just a crippled C++ with garbage collection and running on top of a virtual machine. It's nothing exciting.

    Pardon my ignorance (I've never played with either Java OR virtual machines...) but has anybody ever created some sort of platform where each C++ app runs in its own VM? Wouldn't that give you nearly full c++ performance, while also giving nearly Java's security and memory protection?

  41. Too bad I'm crazy by Anonymous Coward · · Score: 0

    Too bad it's compiled to JavaScript rather than interpreted. That would have enabled secure execution of foreign code... and be the worst performance achievement in history.

  42. Development time-line... by amccaf1 · · Score: 1

    Month 1: Developer A writes a relatively complicated Java program. Developer A compiles it to bytecode, runs it through Orto and deploys resulting Javascript to company's webserver. Developer A writes no documentation.

    Months 2-6: Developer A continues to write no documentation concerning his work in Month 1.

    Month 7: Developer A quits, resigns, is fired, or otherwise disappears.

    Month 8: Developer B -- Developer A's replacement -- is asked to fix several bugs in the company's web pages. Developer B opens up the Javascript and freaks out while looking at auto-generated Javascript. Developer B slowly but surely makes his way through the Javascript and makes required non-trivial changes, updates and modifications.

    Month 9: Developer B flees the scene.

    Month 10: Developer C -- Developer B's replacement -- is asked to fix several more bugs in the company's web page. Developer C opens up the original Java program. Developer C opens up the company's deployed web pages with embedded Javascript. Developer C spends several hours looking from one to the other and then back again. Developer C submits the resulting mess to thedailywtf.com and then runs screaming from the building.

    To all potential Developer C's out there: Start running!

    --
    "Flag on the moon. How did it get there?"
  43. this kind of reminds me of ... by haupz · · Score: 1

    ... these.

    OMeta: http://www.cs.ucla.edu/~awarth/ometa/
    The more recent OMeta 2.0: http://jarrett.cs.ucla.edu/ometa-js/
    And, of course, COLA - http://piumarta.com/software/cola/

    Self-sustainment, anyone? ;-)
    One more link: http://www.swa.hpi.uni-potsdam.de/s3/

  44. Re:Java running under Javascript... by Sancho · · Score: 1

    I haven't kept up with Java--has its speed really improved, or is it just that hardware has caught up enough to make delays primarily the result of waiting for user input?

    When I first started messing around with Java (fairly shortly after it was released), it really was much, much slower than compiled code of just about any language. I wasn't a big Perl user at the time, so I really couldn't compare, and the joy of Python wasn't even a twinkle in my eye.

  45. Re:Java running under Javascript... by Galactic+Dominator · · Score: 2, Informative

    but has anybody ever created some sort of platform where each C++ app runs in its own VM? Yeah, it's called Java.

    Java is slow when done inefficiently, like any other programming language. In Java code that is implemented correctly, speed will be one your lesser worries. In fact, under certain conditions, Java can rival, and even surpass, native code for speed. The implemented correctly is a much bigger one.
    --
    brandelf -t FreeBSD /brain
  46. Re: by clint999 · · Score: 0

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

  47. Film at 11 by justleavealonemmmkay · · Score: 1

    What ? You mean a Turing complete language can be compiled to another one and still run on a Turing machine ? Oh noes, my world view collapses!

  48. Who wants to bet by lewp · · Score: 1

    The JavaScript Ruby interpreter is faster than the "real" one

    --
    Game... blouses.
    1. Re:Who wants to bet by SanityInAnarchy · · Score: 1

      It is faster than Ruby 1.8.

      However, it is running with the aid of Ruby 1.9 on the server, so I suspect that actual Ruby 1.9 is faster.

      --
      Don't thank God, thank a doctor!
  49. Re:Java running under Javascript... by jrumney · · Score: 1

    Yes, in the early days, the byte code interpreter was just that - an interpreter, and the garbage collection was naive and blocked all threads when it kicked in, leading to the notorious GC pauses at random times (great for all those Java games that sprung up in the early days).

    After Java 1.2 was released, Sun released a drop in replacement "Server VM" which had "hotspot" compilation, where programs were profiled at runtime and parts of the code that were frequently called were compiled to native code. In Java 1.3, this became the default VM on Unix platforms, and incremental garbage collection was introduced as an option. Both the hotspot compiler and the garbage collector have continued to be improved, to the point where there is no longer a distinction between server and client VMs and at some point generational garbage collection was introduced to speed up collection of short-lived objects. The focus now in 1.6 seems to be on improving startup time by loading only parts of the standard class library that are needed, instead of loading the whole lot at startup, and improving download time by downloading parts of the JVM on demand (the latter feature is currently in beta).

  50. A wordplay by Santana · · Score: 1

    After reading that page, I see that it's a wordplay. Orto is taken from Greek which means "recto" (straight) or "correcto" (right, as opposed to wrong). "Recto" also means "rectum".

    --
    The best way to predict the future is to invent it
  51. Re:Java running under Javascript... by setagllib · · Score: 1

    Yes, it's much faster now. Now JVMs perform on-the-fly optimisations much like the ones C compilers do at compile time, but since they're done at runtime, they can very specifically target the runtime context like your CPU model. Even though a specific optimisation set in a static compiler can do the same or even better, at runtime you get more information and more flexibility like being able to turn off synchronization when there's no chance of contention anyway.

    Version 6 of Sun's JVM now regularly outperforms even finely optimised C/C++ code for many tasks, and cuts through layers of abstraction and encapsulation so you don't have to clutter your code to speed it up. There are still many problems left for Java's performance, but they're going away, meanwhile C/C++ still have huge problems in language design and ease of development that are *not* going away.

    As an aside, the fact that Java has constantly-on features like garbage collection, bounds checks, null pointer checks, type safety checks, JNI call checks, etc. and STILL performs comparably with C/C++ code lacking these features, is a strong sign that the JVM itself optimizes code *very* well. If you turn all of these things off it goes even faster, but as a developer I like to have as much confidence in my code's correctness as possible, and doing formal proofs isn't fun.

    --
    Sam ty sig.
  52. Perl 2 JS by Anonymous Coward · · Score: 0

    The Perl 6 people were targeting javascript with KindaPerl6.

  53. The ability to run Java from within a browser.... by Anonymous Coward · · Score: 0

    has existed for ages...they are called Applets. Every browser supports them.

  54. Re:Java running under Javascript... by Sancho · · Score: 1

    Thanks to you and jrumney for the explanations.

    It seems like Java really has a bad case of "first impression syndrome." At the time, the only thing that it really seemed to have going for it was wide compatibility--and even that was not always true (I've had to deal with incompatibility issues between JVM versions in some applications that we support.) It sounds like Java is pretty nice now, so I may have to give it another look.

  55. Thanks for the info! by rts008 · · Score: 0, Offtopic

    I understood that Java was an OOL, but failed on the whole JS understanding.

    Thanks to your reply, I now know enough to differentiate the two: In other words: Java !=JS. I sort of get it and heartily thank you for the informative reply.

    I sincerely hope the /. moderators give you some 'informative +' love.
    I did not really get the diff, but see now I have more learning and research to do, as I do want to 'get it'.

    I guess the whole 'Java' vs. 'Javascript' is confusing to n00bs (or 'us morons') since they both contain the (unrelated) root word:java.

    Again thanks for a respectful and informative reply that can forward the conversation constructively...*can be a rare thing here on /.*... based on that, I feel compelled to add you to my 'Friend's' list here, so be forewarned if your pref's advise you on the change/message. (have not checked your user page,etc.)

    --
    Down With Slashdot BETA!!! I've been around the corner and seen the oliphant; you can only abuse me from your perspecti
    1. Re:Thanks for the info! by vsync64 · · Score: 1

      I guess the whole 'Java' vs. 'Javascript' is confusing to n00bs (or 'us morons') since they both contain the (unrelated) root word:java.
      Yes it is, and Sun decided to follow that resounding marketing success by renaming their GNOME/Linux and GNOME/Solaris distros to "Java Desktop System".
      --
      TO BUY A NEW CAR WOULD MAKE YOU SEXUALLY ATTRACTIVE.
  56. Re:Java running under Javascript... by evanbd · · Score: 1

    Exactly. JIT'ed code performs quite well.

    For anyone trying to make a Java program run faster, the first thing I always do is look at the profiler output (java -Xprof Foo) and see how much time is spent in the GC. If it's more than a couple %, you've got too many new's and too much garbage collection going on -- and 5% time in the GC represents far more than a 5% performance hit, thanks to thread switching overhead and thrashing the CPU caches. Basically, never ever have a new in an inner loop -- you wouldn't put a malloc there in C, so don't put a new there in Java.

    If you've taken care of that, and it still runs slow... Look to what API calls you're making. Are you adding single characters to Strings a lot (they're final; there's a hidden new and lots of copying in that operation)? Making lots of system calls that produce context switches? Basically, attack it like you would a C program, and you'll get good results. Why people manage to optimize C code well and not Java is beyond me, given that they use similar tools to do so...

  57. java on javascript by sentientbrendan · · Score: 1

    I'd like to point out that there are already two implementations of java on javascript aside from the one in the article:

    1. Google Web Toolkit compiles java to javascript.
    2. XML11 project actually implements the JVM in javascript. That's right, their script *interprets* and *executes* java bytecode. They let you do things like run existing AWT applications unmodified, by emulating AWT in HTML. Of course, this was pretty slow the last time I looked.

  58. Comment removed by account_deleted · · Score: 1

    Comment removed based on user account deletion

  59. Terrible Name by Anonymous Coward · · Score: 0

    Orto means "Anus" in spanish.

  60. Re:Java running under Javascript... by Jesus_666 · · Score: 1
    I just profiled the code my university project has produced for kicks. What does this tell me?

    Flat profile of 12.85 secs (993 total ticks): main

    Interpreted + native Method
    90.4% 0 + 613 java.lang.Object.wait<br>
    ...
    Okay, we do multi-threaded number cruching and that involves wait()ing, but is that high amount of waiting normal? Could it be an indicator of using too many worker threads (which would make sense as I tested with a small data set and thread-happy settings)?

    Oh, and we spendi upwards of 10% of all ticks with the GC, which is probably bad, as your post points out. Is there any way to determine where the GC spends the most time cleaning up without digging through the code? I'd love to make the app faster (as it needs to crunch absurdly large amounts of text), but a full-scale code evaluation would be too much effort and I have other things to do.
    --
    USE HOT GRITS WITH STATUE OF NATALIE PORTMAN (NAKED AND PETRIFIED)
  61. Re:Java running under Javascript... by evanbd · · Score: 1

    I don't know of an easy way to figure out what the GC is cleaning up. -Xloggc and such may help, or may not. I would say that much waiting is a bad thing -- you should likely be doing less of it, though how to accomplish that I can't say without seeing the code.

    You say you're doing text crunching; I'd look for string ops as possible culprits for the GC activity. Remember, for Strings, a = b + c involves a hidden new -- and therefore a GC operation if a has been initialized before (all string objects are constants). If you're doing any sort of modification of strings, ie not just reading numbers but breaking strings up into lines and such, you probably want to consider using a CharBuffer, or possibly a char[] array, depending on what you're doing.

    The dirty hack method of reducing GC time (only sometimes works) is to give the JVM too much memory at invocation (-XmxBIGNUM -XmsBIGNUM), and then call System.gc() occasionally and hope to do your garbage collecting in large chunks.

    Oh, almost forgot, and it's a big one -- assuming you're using Sun's JVM, are you running server or client mode (-server or -client)? It can make a big difference on some apps, and it's worth trying both ways. My guess is your app does better under the server JVM, and it defaults to client...

    Anyway, good luck. Java performance tuning isn't too hard; just watch out for hidden operations. There are much better tools available, but just running -Xprof is a pretty decent start.

  62. WOW!!! by Jane+Q.+Public · · Score: 1

    I bet it performs about as well as C++ programs running under a Visual Basic interpreter.

  63. You people are driving me nuts... by afabbro · · Score: 1

    More than half the comments so far are "why would you do this? it'd be slow!" or "I don't see the benefit of this" or "I would not recommend this enterprise architecture".

    Gaaaa!

    People, you're supposed to be nerds. Sometimes nerds do things just for the fun of it. Because they can. Look at the comments from a mere 8 years ago about the HTTPD server written in PostScript (and in shell, and in assembly). What's happened in the meantime? Did you all go get MBAs? Did you all start kissing girls or something?

    --
    Advice: on VPS providers
  64. amazing! but... by TheDeivix · · Score: 1

    This looks more like the kind of stuff that some programmer created just to amaze other programmers.

    If it's gonna end up being a js app it makes more sense to me to code it in js from start to finish, i don't see the point in coding it in java first.

    But anyway, amazing stuff!

  65. Hey, lighten up, it was a joke. by rts008 · · Score: 1

    Really sorry about harshing your mellow, man.

    Thanks for the extra time to reply. It just gets frustrating sometimes to be slapped with something you have not been informed about without any chance for ref's other than a Google search...which can yield many hairy results to wade through.

    I guess it's a matter of experience and perception.

    BTW, I consider myself a *nix n00b, but I am trying to soak it all up like a dry sponge....but there is a lot out there, and only so many hours in the day!

    Now I am going to take my frustrations out by playing Fallout2 and fscking up some stuff! (via WINE on Kubuntu 8.04--just finished Fallout1...again! then opened another beer!)

    --
    Down With Slashdot BETA!!! I've been around the corner and seen the oliphant; you can only abuse me from your perspecti
  66. Re:Java running under Javascript... by Jesus_666 · · Score: 1

    The problem with giving the JVM too much memory is that we will later spawn off a number of worker threads, each of which will potentially use several gigabytes of memory (the most labor-intensive things we do are cooccurrence analysis and clustering and those are memory hogs). If what I've ben told is correct, giving the JVM lots of memory means that any threads it later spawns get less, which would be undesirable.

    The -server tip worked well, however. On my minimal data set I cut processing time from 12 to 8 seconds with only 4% of all ticks spent with the GC. It now spends 11% of the ticks on compilation, but that number will likely decrease to nothing when tested with a real data set.

    Thanks for the tips. I'll bring your post up at the next project meeting.

    --
    USE HOT GRITS WITH STATUE OF NATALIE PORTMAN (NAKED AND PETRIFIED)
  67. Re:Java running under Javascript... by EsbenMoseHansen · · Score: 1

    The primary reason its okay for python to be slow, but not for java, is that python isn't a crippled version of C++ that runs at 1/10 the speed, whereas java is.

    Now you are being unfair. Java code runs often runs at almost half the speed of C++, and have a few features (such as better enums, reflection, simpler parse) which C++ doesn't.

    If you use the server VM, the java VM can actually inline code. Amazing!

    --
    Religion is regarded by the common people as true, by the wise as false, and by rulers as useful.
  68. See Also: Volta by Nurgled · · Score: 1

    Microsoft Live Labs is working on a similar project to translate CIL (.NET bytecode) to JavaScript as part of their Volta project. It's part of a larger effort to allow you to write both the client-side and the server-side code in the same project and then have a post-processor split the resulting assemblies and generate all of the boilerplate RPC code to make the client-side bits run on the client and the server-side bits run on the server.

  69. Nerds don't kiss girls! by woolio · · Score: 1

    Parent makes a good point...

    A true nerd would build a robot to kiss a girl...

  70. Charles Nutter on Ruby implementations by jilles · · Score: 1

    Related to this, here is a nice overview of the current state of various Ruby implementations (including a brief discussion of the javascript one) by Charles Nutter one of the lead developers of JRuby: http://headius.blogspot.com/2008/04/promise-and-peril-for-alternative-ruby.html

    --

    Jilles
  71. Re:Java running under Javascript... by Anonymous Coward · · Score: 0

    Version 6 of Sun's JVM now regularly outperforms even finely optimised C/C++ code for many tasks
    I've been hearing that for a long time, is it actually true now? It's possible that reality has caught up with fantasy and that JVM development has outpaced development on C and C++ compilers, but I am highly doubtful.

    Java has constantly-on features like garbage collection, bounds checks, null pointer checks, type safety checks, JNI call checks, etc. and STILL performs comparably with C/C++ code lacking these features
    Comparably? You just got finished saying that Sun's Java implementation "regularly outperforms even finely optimised C/C++ code". Now it only performs comparably? I am even more doubtful now.

    Ok, I just ran a few quick benchmarks of Sun's Java 6 vs. g++ from GCC 4.3 and I see 1.2 to 2.5 times slower performance for Java. Where are you getting your ideas about performance from?
  72. Re:Java running under Javascript... by Anonymous Coward · · Score: 0

    See the language benchmark shootout for all your implementation comparisons! ;-)

  73. Re:Java running under Javascript... by spiffmastercow · · Score: 1

    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. Spoken like a true fanboy. Java lacks pointers, and its slow. This means it loses two key benefits of a C-derived language. Yes, Java is truly portable. This is no real feat for an interpreted language, however. Yes, Java has reflection. So does every other interpreted language from the last 15 years. So what's so special about it?

    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. Okay, that's fair. But first off, I did not mention Ruby at all. I have no love for Ruby. Second, I see Python as a prototyping and scripting language, where these concerns are far outweighed by the expressiveness and readability of Python code. Java, on the other hand, has always been touted as a replacement for C, and it is there that it fails miserably. I think Java is mainly only valuable as the Pascal for OOP.
  74. Re:Java running under Javascript... by setagllib · · Score: 1

    Comparable can be better than or lesser than, as long as it's close enough to bother comparing. I think you're just trying to pick holes in my brief report of what many many Java developers have already benchmarked for their own purposes, including myself.

    What code did you compare? I said "regularly outperforms even finely optimised C/C++ code for many tasks", not *all* tasks. The plain fact is that runtime optimization can beat static optimization, and Java does it occasionally. It's safe to say that in Java 7 it will be even better, with more cases meeting or exceeding C/C++.

    And keep in mind, while C/C++ *can* be optimized manually with tedium like moving code to headers (so it can be inlined), declaring constants (so they, and their resulting code, can be inlined too), etc., at runtime in the JVM this kind of work is automatic. You generally don't have to sacrifice your cleanliness and abstraction to make Java optimize well, except in currently lacking cases like boxed primitives (which will remain boxed and therefore slow - yes, I benchmarked that too).

    --
    Sam ty sig.
  75. Critical parsing error by patio11 · · Score: 1

    I'm a little befuddled by lack of sleep, but the talk of ass and matching front ends with back made me think you were suggesting that Perl would be involuntarily sodomizing someone. In my defense, we are talking about Perl here -- its not like the comment would be terribly out of bounds.