tags:

views:

844

answers:

10

What is the difference between Java and C++? Are both object-oriented?

+1  A: 

Both are object oriented but they are very different languages. This probably isn't the best forum to ask for the differences... I would suggest you look both up on Wikipedia and review the descriptions there. You will be able to see the differences very quickly for yourself.

Jason Coco
+14  A: 

This is far too general a question to be answered here.

Java is an explicitly object-oriented language, with the harder-to-use bits snipped off.

C++ is a multi-paradigm language with the safety off. You can do object-oriented programming in it, as well as procedural and generic.

If you had a more specific question, we could be of more help. Why did you ask? If you want recommendations for a particular platform, or project, or whatever, we could be more responsive.

David Thornley
"Any language will let you shoot yourself in the foot. C++ will provide the gun, load the bullets, give you a drink to steady your hand, mount telescopic sights, and paint a large target on your foot"
Paul Tomblin
Sure will, but it will also gives you a gun with a big enough bang to drop a dinosaur. All in perspective.
WolfmanDragon
+1  A: 

I love c++ but unless you absolutely need to use c++ then use something else. When you need to use c++ then you will know the difference, Grasshopper.

(hint do not write device drivers, video decoders, encryption libraries, 3-d graphics engines or language run-time engines in java).

Dipstick
+1  A: 

Yes, both are object oriented programming languages.

C++ is an evolution to C. Which was a system programming language. C++ Added many features to the language to make it object oriented. It became the mainstream programming language for that reason.

Java is an evolution of C++, with different goals ( cross platform for instance ). It remove some of the features that make C++ so hard to learn. Simplify others and remove others.

The main difference is C++ programs are compiled directly to machine code ( understood by the CPU ) while Java programs are compiled to be run in a "Virtual Machine" the JVM most of the cases. For these reasons java programs were interpreted by another program and at the beginning were veeeery slow programs. Nowadays the VM may optimize this code and make it run very very fast.

OscarRyz
+1  A: 

One of the most important differences hasn't been mentioned yet - one is compiled to machine code, the other is compiled to bytecode which is interpreted by a virtual machine.

Michael Sharek
unless the bytecode gets compiled to machine code by a JIT compiler
Ferruccio
+1  A: 

See this link.http://www.javacoffeebreak.com/articles/thinkinginjava/comparingc++andjava.html

Jared
It's good, but some places are really old
Yoni Roit
A: 

Gross but accurate oversimplification: Java is easier. C++ is faster.

With the state of compilers at the moment, C++ is only faster than java if it is optimized. Not the languages fault though.
WolfmanDragon
A: 

Just a quick addition to what David Thornley posted. C++ is a procedural language that supports Objects and OO design. Java is pure OO. Java does less but on more.

WolfmanDragon
Hence a multi-paradigm langauge. I personally think "procedural" langauge capabilities are far less important than C++'s template metaprogramming capabilities. Not only can C++ drop a dinosaur, but you can do it in an infinite number of ways.
James Schek
touche'.You have me there.
WolfmanDragon
+1  A: 

Each language designed with different purposes in mind, so IMO it's not fair to compare the two from one perspective, and ignore the other.

Generally speaking, C++ is an open standard, designed for implementing high performance systems where speed and performance and critical, there are lots of impressing projects designed using this language like Phoenix Lander, Adobe Acrobat Reader and others. C++ gives the developer the ability to program using a very high level abstraction -using generics for example, and, when needed, go down deep to the bare metal of the machine -to handle an interrupt for instance.

Java was designed with other purposes in mind, when Sun was planning Oak (later called Java), it focused on web applications so it supported the language with a bunch of heavy libraries of easy-to-use interfaces considering that. and portability (Compile once, run anywhere) using JVM, which prevents the programmer from coding to specific machine, but instead coding to a sandbox which in turn runs the code on the hosting machine, and this has obviously negative reflections on performance/speed.

Comparison of those two language is a popular cause of debate between programmers, and this is due to their different working demands and nature, IMO every language has made mistakes in order to mature, for example, C++'s exported templates, and Java's lack of procedural programming (Big Mistake). plus, each one has its pros and cons regarding different aspects, hence the one that balance productivity/performance issue IS the right language.

For more information Wikipedia's comprehensive article on Comparison of Java and C++

It might be interesting to take a look at what languages are used (and being used) to create major systems (like Google) from here.

Josef
+2  A: 

A C++ programmer will tell you that Java is rubbish. A Java programmer will tell you that C++ is rubbish. Therefore I conclude that they are indeed the same thing.

Daniel Paull
Besides, everyone knows that Erlang is better than both. Or is that Scheme? Or Clojure? Or Ruby? I can never remember.
James Schek
An Erlang programmer will tell you that Scheme is rubbish and a Scheme programmer will tell you that Erlang is rubbish. Therefore I conclude that they are indeed the same thing.
Daniel Paull