Click here to Skip to main content
15,896,408 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone!

I am a mobile robot designer in autonomous space robotics. there is a great dilemma in front of me to opt a programming language for the robots between C++ and Java.
the most important factor for me is performance of the language when i want to use it for applying very complicated navigation algorithms and very sophisticated localization strategies, for example.
I have experience in working both of them. I got Java more interesting but because of the special compiling process which it has, I feel that it could be run on the PC slower than C++!
I've tried to investigate about them collected the opinions of the other and find somethings but they couldn't help me deciding.
for example:

many of the programmers think that java is faster and have better performance whereas I found it slower...!!! of course, there is a very important thing. I finally want to program my on a ARM microprocessor or a DSP and I'm not sure that java is slow on them too or not!!!

but the others think that C++ is more powerful than all languages such as java and its operation is better than Java noticeably. furthermore, descendent of the C++ in design of different robotic packages is undeniable.

All in all, what is your opinion??? which one could be the best choice for me???

Thank you!
Posted
Comments
matinking 21-Feb-12 9:07am    
Do you know about performance of the Java programs within execution in DSP chips?
is their performance better than on PCs?

If performance really matters, then there is no choice: C++ is faster than Java (provided the algorithm is the same, C++ is faster than almost everything else).
 
Share this answer
 
// I have experience in working both of them

Try both of them by your own stopwatch,
it could be your first move :)
 
Share this answer
 
v2
Java runs nearly as fast as C++ for many applications.

One feature that programmers love about it, is that it does garbage collection in the background. This means that discarded memory can build up, and occasionally you may see large performance hits, as that memory gets cleaned up.

This isn't a big deal for web apps, but it can be a problem for applications that will run continuously over long periods of time.

And of course, as an application developer, Java does give you facilities for managing the garbage collection, but then, you lose the benefit of not having to worry over it. You're back in the C/C++ paradigm of managing memory.

There is a reason that operating systems and many server systems are still written in C/C++. You can finely tune your application for size and performance, and you have better control over memory management.

My vote is for C/C++. It will provide every feature you will need, and give you the capacity to draw from a huge code base, while minimizing your code footprint.

I'm sure other folks will provide excellent arguments for Java. Both languages have advantages and disadvantages.
 
Share this answer
 
I agree with Jack: if nothing else, if the garbage collection can happen at any time, that can be a major problem in any system that works in real time: If your sensors notice at the last moment there is an obstacle in the path your arm is swinging, then a garbage collection at the wrong time could be fatal.

Note that there are very good free physics engines available. E. g. check out Open Dynamics Engine (ODE)[^] by Russell Smith, or maybe Newton Game Dynamics[^], by Julio Jerez and Alain Suero. These Engines are written in C++.

P.S.: While I have only little experience with Java myself, most SW development I know of in Java deals with Web programming, databases, distributed systems, or any combinations of these. Robotics requires neither. I'll leave the conclusions to you ;)
 
Share this answer
 
v3
No wonder you found Java slow. It IS slow. It's bound to be slow. This is because Java applications run on an extra layer called the Java Virtual Machine. That certainly adds an overhead.

You should choose C++ over Java if your utmost goal is performance. And even that is not enough, you can consider assembly language, which is even faster (if coded correctly). But of course assembly language is a bit tricky and I don't know if there's a good programming platforms for robots for assembly.

Adding a tip: Pardon me if you know this already. But many C++ compilers have tiny little switches that can tell the compiler to optimize code for high performance. You can use them too. With Java you'll only get one level of optimization.
 
Share this answer
 
v2
Few nice points related to performance of these are available here:

http://scribblethink.org/Computer/javaCbenchmarkFAQ.html[^]

http://sprout.stanford.edu/uli/java_cpp.[^]
 
Share this answer
 
Comments
krumia 22-Feb-12 4:16am    
Your stanford link is broken :(
Thank you everyone for your suggestions!!!

finally I found C++ as the better choice...!!! so did I!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900