Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am creating a web application. I have primarily used Javascript specifically jQuery. Because of some very specific functionality, I am running into practical limitations of Javascript--they're not hard limitations but stuff that I would find easy in Java, like making an equation editor where you can edit directly as opposed to entering TeX, is difficult in JS even using MathJax as a base.

I'm going to have to build even more complex functionality that involves 3D and physics engines.

For a large scale application like this--specifically one that involves 3D and physics engines--would Java be slower or faster than Javascript when one is run within a browser? (Assume that code is written well in both cases.) Or is it completely uncertain--i.e. dependent on far too many specific variables?

Thanks.

share|improve this question
    
It's not Java or JavaScript that's going to be a bottleneck, it's going to be your rendering and GPU that's the bottleneck –  Raynos Oct 13 '11 at 9:32

3 Answers 3

up vote 1 down vote accepted

Java will typically perform considerably perform better than Javascript - the JIT compiler for Java is extremely good and gets you to near-native performance in most cases.

I think if you want to build a 3D engine though you are best advised to go with Java - you're ultimately going to want full OpenGL capabilities and the performance of Java's JIT compiler.

You should note that Java is a bit "heavyweight" to start up compared to Javascript (overhead of loading .jar files and warming up the JVM etc). Also there are some security controls that you may have to work around, especially if you do something that requires native libraries. Typically this means signing your .jar files and/or having a user agree to trust your application. Alternatively, you may decide that it is best to offer a downloadable Java application.

I've personally have good experiences with LWJGL as a toolkit for building 3D browser applications using Java. You could also look at jMonkeyEngine if you want a more complete 3D engine with physics etc.

share|improve this answer
    
By "considerably better performance" you mean roughly a factor of 2. Which can help but doesn't help that much –  Raynos Oct 13 '11 at 9:32
    
Well benchmarks are always somewhat open to interpretation :-). shootout.alioth.debian.org/u64/javascript.php shows JavaScript taking 2x as long on some tasks, 10x as long on others. I think the fundamental issue is that JavaScript objects are very dynamic, which is nice but results in overhead when reading many property values from a large numbers of objects - which is unfortunately a common use case in many games. Of course if the game/simulation is simple it won't make much difference, but when you start modelling a lot of physics it can start to be an issue. –  mikera Oct 13 '11 at 10:25
    
I was indeed being vague, The Firefox JavaScript engine guys claim performance within a factor of 2 of C for a sensible subset of JavaScript. Of course performance is a factor of 10^7 in IE6 –  Raynos Oct 13 '11 at 11:16

Assuming you mean client side java so that the hardware and network behavior are the same, it depends on the browser. The Internet explorer JavaScript engine is a couple orders of magnitude slower than chrome for example. Java or other plugins like flash should be fairly constant across browserson the same hardware.

share|improve this answer

It depends on many variables, I will say that the Java VM is more consistent. You can also look at Silverlight, Flash/Flex and something else I'm probably missing :-).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.