article

C++/Java

Email
Submitted on: 1/3/2015 2:52:00 AM
By: D/D++ (from psc cd)  
Level: Intermediate
User Rating: By 3 Users
Compatibility: C, C++ (general), Microsoft Visual C++, Borland C++, UNIX C++
Views: 1658
 
     The differences between C++ and Java

 
				

C++ Vs Java(Ham vs Chicken)

C++ is one of the most powerful language and will be used for a long time in the future inspite of emergence of Java. C++ runs extremely fast and is in fact 10 to 20 times FASTER than Java. Java runs very slow because it is a byte-code-interpreted language running on top of "virtual machine". Java runs faster with JIT (Just-In-Time) compiler, but it is still slower than C++. And optimized C++ program is about 3 to 4 times faster than Java (with JIT compiler).

Then, why do people use Java? Because it is pure object oriented and is easier to program in Java, as Java automates memory management, and programmers do not directly deal with memory allocations. Because of manual memory allocations, debugging the C++ programs consumes a major portion of time.

Since C++ programmers are abundant, it is recommended you do programming in object-oriented "C++" for all your application programming or general purpose programming. You can take full advantage of object oriented facilities of C++. The C++ compiler is lot more complex than "C" compiler and C++ programs may run bit slower than "C" programs. But speed difference between "C" and "C++" is very minute - it could be few milli-seconds which may have little impact for real-time programming.

Since computer hardware is becoming cheaper and faster and memory 'RAM' is getting faster and cheaper, it is worth doing code in C++ rather than "C" as time saved in clarity and re-usability of C++ code offsets the slow speed. Compiler optimizer options like -O or -O3 can speed up C++/C which is not available in Java. Nowadays, "C" language is primarily used for "systems programming" to develop operating systems, device drivers etc..

Prefer to use web-server-side programing "Fast-CGI" with C++ and HTML, DHTML, XML to get better performance. Hence, the golden rule is "Web-server side programming use C++ and web-client side (browser) programming use Java applets". The reason is - the server-side OS (Linux) is under your control and never changes, but you will never know what the client side web-browser OS is. It can be Internet appliance device (embedded linux+netscape) or computers running Windows 95/98/NT/2000 or Linux, Apple Mac, OS/2, Netware, Solaris etc.. The advantage of Java language is that you can create "Applets (GUI)" which can run on any client OS platform.

Java was created to replace the Microsoft Windows 95/NT GUI APIs like MS Visual Basic or MS Visual C++. In other words - "Java is the cross-platform Windows-GUI Api language of next century". Many web-browsers like Netscape supports Java applets and web-browser like Hot Java is written in java itself. But the price you pay for cross-platform portability is the performance, applications written in Java run very slow.

Hence, java runs on "client" and c++ runs on servers.

Some facts: The usage of char * and strcpy causes horrible memory problems due to "overflow", "fence past errors", "memory corruption", "step-on-others-toe" (hurting other variable's memory locations) or "memory leaks". The memory problems are extremely hard to debug and are very time consuming to fix and trouble-shoot.

Memory problems bring down the productivity of programers. Memory related bugs are very tough to crack, and even experienced programmers take several days or weeks to debug memory related problems. Memory bogs may be hide inside the code for several months and can cause unexpected program crashes.

The memory bugs due to usage of char * and pointers in c/c++ is costing $2 billion every year in time lost due to debugging and downtime of programs. If you use char * and pointers in c++ then it is a very costly affair, especially if your program size is greater than 10,000 lines of code.


Other 7 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.