C++ and Java
Author |
Message |
Raknarg
|
Posted: Wed May 18, 2011 7:31 pm Post subject: C++ and Java |
|
|
This is probs a noobish question, but are Java and C++ mostly the same? I've seen a lot of code for both of them and they seem to use basically the same syntax. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
mirhagk
|
Posted: Wed May 18, 2011 10:44 pm Post subject: RE:C++ and Java |
|
|
very similar in syntax, yes, in execution and the way code is compiled/run no.
Java runs on a virtual machine, meaning one java program can be run on any computer, while C++ is compiled for a specific computer, meaning you'll recompile for each computer, but it also gives it a performance boost.
Also how they deal with errors and things are different.
But yes, the syntax is much the same. |
|
|
|
|
|
DemonWasp
|
Posted: Thu May 19, 2011 12:37 am Post subject: RE:C++ and Java |
|
|
The syntax is largely similar. However, everything else is different.
In Java, you have automatically-managed memory, with manual allocation and automated freeing. In C++, you must manually allocate and free memory.
Java is compiled against the JVM, a specification of a virtual machine. In C++, you compile against a given description of a machine + operating system combination. Compiling C++ programs on Linux is different from compiling them for Windows or OSX or BSD or AIX or HP/UX or...
Java has native libraries for an awful lot of things that C++ has a...variety...of libraries for. Java has language-level support for multithreading and concurrent programming...C++ has pthreads and whatever the library on the Windows side is. Java has Sockets, C++ has either the UNIX sockets library or WinSOCK, depending on OS.
C++ is typically slightly faster. However, the gap is definitely closing and there are cases where Java is faster. The comparison depends largely on which C++ compiler is used, which JRE is used, and the skill of the programmer for each language.
There's actually a fair bit of syntax that's very different between the two languages, but you need to have a little experience with both to know what they are. |
|
|
|
|
|
|
|