Subj : Re: Java vs. C++ To : comp.programming.threads From : dayton Date : Sat May 28 2005 09:04 am hzs202@gmail.com wrote: > ...I am looking to > focus my studies on either C++ or Java and I am looking for a little > bit of advice in this area. Given this is a threads newsgroup, and a lot of people use threads in Java, I guess its okay to offer my assessment of Java here. Java has a more developed library than C++ so its generally faster to develop applications in Java, but consider the following: -- Java is interpreted. If you want performance use a compiled language. Have you ever noticed how slow Java IDEs are? -- Java does not have multiple inheritance. Wars have been fought in the OO world over whether multiple inheritance is needed, but I find MI useful. I have yet to see an amphibious truck as car with a boat interface. -- Java manages your memory. This costs something in performance and robs you of precise control over resources. C++ with its constructors and destructors, and use of techniques such as resource acquisition is initialization (RAII), and Boost shared pointers you get much more precise and efficient control of any resource. Resources include memory, threads, files, database connections. Java doesn't have destructors so you really can't wrap external resources in Java objects. Using modern C++ techniques, I find multi-threaded programming easier in C++. (I can't recommend the Boost threads library, though -- you might as well just call the POSIX C functions directly). -- The Java synchronization model is rather broken. If one object with synchronized methods contains another object with synchronized methods, you become subject to deadlock because you haven't acquired all the required locks at once -- and you have no control of the level of the locks. -- the real heavy lifting in the Java library is done in C routines. The Java command line program that instantiates the Java virtual machine is written in C. C++ has its own basket of faults, but if you want to implement systems that are more closely tied to hardware, or have high performance requirements, use C++. If you want to develop sophisticated but possible slow applications, use Java. .