views:

366

answers:

6

Since now javascript gets compiled to machine code by browsers. I was wondering which programming language gets better performance between java and javascript. I'm thinking of writing a 3d browser FPS or MMO and am trying to decide between the two.

Also what are thoughts on compatibility? It seems like with java and opengl I could reach a larger audience than using javascript and webgl since support hasn't been announced by IE.

+4  A: 

It is very difficult to give you a response. Java and Javascript are totally different languages :

  • Javascript is executed by your browser: performance depends of you browser javascript engine
  • Java (if executed on the client machine, by JNLP for example), run in a JVM environment: performance depends of your JVM

So there is no absolute response to your question.

Theses two languages have also very different functionnalities that can't be compared...

Benoit Courtine
I'd also add that accessing local resources from JavaScript is almost impossible - and rightly so.
Basiclife
It's not quite that simple. Starting with Java 6, you can actually embed other languages in it, and out of the box, it supports ECMAScript (JavaScript). It could be viable to implement part of a program in one language and part in another. Reference: http://java.sun.com/developer/technicalArticles/J2SE/Desktop/scripting/
John Gaughan
Does it need to be that difficult to give a response? When JavaScript performance depends on the particular browser JavaScript engine and Java performance depends on which JVM, can we simply ask how the best JavaScript performance compares to the best Java performance? How does the most widely available JavaScript performance compare to the most widely available Java performance?
igouy
+7  A: 

As @Benoit says, this is a difficult question:

  • Comparing (primarily) client-side and server-side languages is comparing apples and oranges.
  • Different languages perform better / worse depending on the application / task.
  • You can only benchmark language implementations not languages.

Having said that, here are a couple links to the "Computer Language Benchmarks Games" comparing Java and Javascript implementations:

Note that these are comparing Javascript with interpreted Java. You can fiddle around with the settings to get comparisons with (for example) server-mode Java.

Stephen C
igouy
@igouy - So really, the best Javascript implementation is significant slower except for one regex-centric benchmark.
Stephen C
igouy
+1  A: 

For browser-based games, I don't think you should be using either. Flash is the way to go.

Also, 3D games, even simple ones, are a pretty heavy-duty task. I suspect you don't know what you're getting into, but there's only one way to find out.

Mike Baranczak
-1 flash will get you nowhere in the long run
Lo'oris
I've hardly seen any 3D flash games. I knew full-blown Shockwave was the one plugin capable of 3d, while (Shockwave) Flash focused on 2D. I know a lot has changed, and now flash have as many APIs as one can imagine, but I still have to see one full-3d game made in flash. Do you know of one? Can you share it?
ZJR
+3  A: 

For what it's worth, JavaScript's performance has greatly improved since the emphasis on scripting speed in Browser Wars 2.0; Java has evolved less radically. Directly comparing such fundamentally different languages isn't really practical, though. And to be honest I don't think performance of the core language is usually going to be your main problem if you're doing something as ambitious as a 3D game in the browser.

To add another option, today you would typically do this Flash using one of the 3D libraries.

Java is what you'd use yesterday (its desktop/applet acceptance is on the wane IMO); WebGL is, hopefully, what we'll be using tomorrow. All three are currently very annoying to write 3D apps with. Get a bunch of practice writing some 2D games before going anywhere near 3D in the browser!

Bonus option for if you don't mind arbitrary closed plugins: Unity

Bonus option for if you're insane: JavaScript, doing the rendering itself, to a <canvas>.

bobince
I thought about this. I looked into ray tracing and different lighting techniques but it seems like a lot of work, and although IE9 will support canvas there is still IE8, 7, and 6 to worry about. I'm not sure I like the idea of not having hardware support for 3D rendering. All these compatibility issues have kind of led me to leans toward Java. I wasn't aware flash did 3D rendering though so I'll have to check that out.
Xavier
You can't practically ray-trace in real time. The Wolfenstein example is ray-casting (ray-tracing on only one axis), which is more practical but still slow for anything but a tiny viewport, and limits you to rendering straight 90-degree walls and floors. Incidentally, another plugin option you can look at is Silverlight. But yeah, this fragmentation of partial support amongst unpopular plugins is why you don't really see 3D browser games today.
bobince
**Unity** always had an enourmous price tag attached, now I see [it claims to have gone free](http://unity3d.com/unity/licenses) (with really pricy "pro" versions having pretty advanced features)One very good thing about it though, is it now supports **iPhone** and **Wii**, too.
ZJR
+3  A: 

As an avid FPS gamer, here's my biased two cents:

If you're going to write a 3D FPS, follow QuakeLive's example and create a browser extension that uses compiled code.

In FPS games, every extra frame and every few millisecond counts. So, a cross-browser solution like Flash, Silverlight, Java etc. may not cut it.

It's a different story if you're writing a turn-based game or a MMORPG where latency or low frame rates don't necessarily matter.

Ates Goral
Here's your upvote. @vlad003 : See also google earth and Bing! maps plug-ins.
Calvin1602
A: 

Depending on the level of detail you pretend from it, Java could cut it or not.

Take a look at Minecraft, a contemporary example of a Java 3d multiuser environment (alas, a very blocky one)

An yes, Javascript won't be able to give you any sensible 3D experience until WebGL (or what will take its place in the final HTML5 revision) takes afoot.

But until then I found out you may give a look into Google's O3D, an higher level interface to Javascript 3D that is available now as an installable plugin (for IE too) and has vague promises of being available later as a pure Javascript implementation, built over WebGL

Anyway, in general: Java on the browser is declining in usage, (Minecraft being an awkward exception) while HTML5 is the new g*dam buzzword.

ZJR