Hi every one, Can any one tell me the major difference between JAVA and C++...
nancy10001 0 Newbie Poster
Slavi 94 Master Poster Featured Poster
Pointers! :D I would say syntax. In c++ you also don't have garbige collection and with inheritance you have to play with the keyword virtual to satisfy the compiler.To me java is indeed much easier when with GUI's (at least to me)
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster
Edited by peter_budo
albertjohns1 0 Newbie Poster
It's simple:
1: C++ uses pointers and have memory leaks , where java doesn't have pointers and there are no memory leaks (although there are logic memory leaks,I think) ..
2: C++ compiles to machine language , when Java compiles to byte code .
Java has no virtual , since everything in java is virtual (please correct me if I'm wrong) .
3: In C++ the programmer needs to worry about freeing the allocated memory , where in Java the Garbage Collector (with all its algorithms , I can think of at least 3 algorithms) takes care of the the unneeded / unused variables .
Sandra_4 commented: Nice meeting you, My name is Maryam and I am a woman seeking for an honest friend and partner.so if you are interested please send an email to me for us to know ourselves better and I will send more of my pictures to you. Here is my email address...( mary +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
C++ uses pointers and have memory leaks
Just because C++ uses pointers doesn't mean it has to leak memory. It's just that you have to be careful with allocations, sharing and ownership. Modern pointer types like unique_ptr
and shared_ptr
provide a limited form of garbage collection if used correctly.
In C++ the programmer needs to worry about freeing the allocated memory , where in Java the Garbage Collector (with all its algorithms , I can think of at least 3 algorithms) takes care of the the unneeded / unused variables .
Java still has the problem wherein you can create unncessary garbage which never gets collected. The classic example of this is the naive implmenetation of an array backed linked/array list.
Hiroshe 499 Posting Whiz in Training
I think the community is one of the largest factors for most languages IMO. Though the C++ and Java communities are both very vast and it's harder to distinguish the two.
The C++ community is accociated with the C camp more. The general feel is that they are more aware (and more willing to account for) the underlaying system. I feel that this community is less forgiving to new programmers. Also, I feel like the community is less "seperated" then Java. IE, a scientific programmer would have no problem helping a mobile developer, because the developers understand the common ground. I think that the number of people who properly use the language is large. There are a few smaller groups (some schools seem to teach C++ like it's C with added cin/cout commands, and teach students things like system("pause")
, conio.h
, void main
and other horrid things).
The Java community is more disjoint from other camps. Also I feel that it is more "seperated" then C++. For example, you have a group of professionals that use the language properly, and understand fundamental computer science. This is a smaller relative to C++ I think. You also have the group of people that learned Java in high school that don't have any care for learning funadmental computer science, and only care about "getting there tic tak tow game working." You also have a few catagories of mobile developers. Also, there is a game development community (which contains groups of people who know what there doing, and groups that have never programmed before). In this community, I feel it would be more difficult for a scientific developer to help a mobile developer, because java programmers are often more "ad-hoc" and don't bother learning the common ground as much.
These are definatly not the "rules" for either communities. They have more in common then whats different, and what is different is only by a little bit.
Constrast these two with FORTRAN for example, in which the community is mostly for numerical and scientific computation. It would be a little strange to hear someone say "I wrote this awesome new android app in FORTRAN" for example. Or contrat these with the Scheme community, which is more focused on academic use and learning proper programming and computer science before "ad-hoc" use.
When I need to pick a language, this is often the first thing I look at to be honest.
Edited by Hiroshe
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster
- Java is C++ with training wheels.
- Java doesn't support multiple inheritance, other than via interface types, which in my opinion are really useless. Every concrete class that inherents an interface class has to separately implement each function in the interface! Gah!
- C++ doesn't leak memory. Only badly written applications do. I wrote a smart-pointer implementation for C++ that handled recursive object references (in deterministic time suitable for real-time applications) without leaking. No deletes and no leaks in 10M lines of application code! That code is still in use today (has to run 24x365) to run most semiconductor, flat-panel display, and disc drive manufacturing plants. I have seen major Java applications leak like a sieve because of unintended references. Also, the default Java garbage collection tools suck! When you server "stops" for minutes at a time while cleaning up the heap, you are well and totally fubar'd!
And yes, I have written, debugged, and fixed a LOT of major Java code (including standard Java libraries such as Jetty/Netty) in my career, and I once had a (now broken) Java mug given me by none other than James Gosling (the author of Java) himself! Smart guy, but nothing (in my opinion) compared to Stroustrup.
Edited by rubberman
~s.o.s~ commented: Interesting :) +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
C++ is a language with a standard librray that covers a decent range of common requirements. You are expected to use it with the native facilities of your OS and whatever other third-party libraries you need to build your application.
Java is a language plus a vast API of over 4,000 public classes that provide standard methods for pretty much everything you can think of, all in a single Windows/Linux/Mac consistent portable package.
Yes, C++ language is technically more capable than Java language, and more dangerous in the wrong hands. But that's only a small part of the whole story...
Java is also still evolving major features - in the last few months we gained multiple inheritance of methods, closures/lambdas, parallel-processing support for functional programming Stream operations, Optional values, a major multi-media library (JavaFX is now integrated and standard)... (see http://www.oracle.com/technetwork/java/javase/8-whats-new-2157071.html )
Edited by JamesCherrill
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster
C++ uses pointers and have memory leaks , where java doesn't have pointers
I've been writing C++ code for years, and I don't remember the last time I had a real memory leak problem. The idea that C++ code has memory leak is a complete myth. Beginners might have such problems for maybe a few months at the beginning, until they understand the basic tricks (RAII, smart-pointers, value objects, etc.), that's been my experience, at least. In the C++ community, people generally characterize memory management in C++ as "automatic scope-based resource management", emphasis on the "automatic", because in decently written C++ code, resources manage themselves.
Also, Java does have pointers, they are simply hidden from the programmer. In fact, by any measure, Java has exponentially more pointers than C++ has. Java is a reference-semantics language, which means that every object you see in the code is, in reality, a hidden pointer to where the real object is (i.e., "reference-semantics" means that all variables must be understood as being pointers / references to something). This means that there is an extra layer of indirection on top of everything, everywhere. C++ is a value-semantics language, which means that every object you see is the object itself, i.e., variables must be understood directly as variables. The only indirections there are are the ones that you create, by using pointers or references explicitly. This crucial difference between the languages is, IMHO, the most important one, by far.
Reference-semantics in Java is what enables garbage collection, and makes garbage collection a requirement for correctness.
Value-semantics in C++ is what makes automatic resource management possible, and what makes C++ much more powerful, efficient and suitable at lower levels.
[In Java] there are no memory leaks (although there are logic memory leaks,I think) ..
As others have pointed out, there can be memory leaks in Java, and from what rubberman seems to say, they are much more of a problem then you might suspect. I don't have enough real-world experience with Java to know how much of a problem it is though. But from what I understand, there are naturally occurring corner-cases in Java that will cause small leaks, and can even be crippling to the whole system / software. The problem is that figuring out whether your code can / could / will give rise to leaks is a very difficult thing, and you cannot, in general, diagnose or solve such problems very easily (since you can't access those gizillion pointers that the VM hides from you).
C++ compiles to machine language , when Java compiles to byte code .
C++ can, in general, compile to almost anything you want, but, AFAIK, there are only C++ compilers that compile either to C code (usually to be compiled further by a C compiler) or to native machine code directly. Java has to compile to something that a virtual machine, designed to run Java code, can understand, i.e., "bytecode". The main reason for that is because the Java language is built on this abstraction (or "idea") of a fictional computer that does not work like any actual computer can or would ever work, and therefore, this computer has to be simulated on top of a real one. Native languages like C or C++ are also based on an abstract model of a computer, but that model actually corresponds to a real computer, and therefore, the code can be mapped directly onto real CPU instructions (machine code). That is also a very important difference.
In C++ the programmer needs to worry about freeing the allocated memory
Uhmm.. I have yet to meet this mythical C++ programmer who worries so much about freeing allocated memory. I've seen lots of Java programmers whining about the lack of garbage collection in C++, but I've never heard of a C++ programmer making the same complaint. With this reputation that C++ has about having all its programmers loosing sleep over the fear of having forgotten to free some memory, you would think that meeting such C++ programmers would be a more common occurrence, yet, I've never heard of one that I can remember, in nearly 10 years. And I have certainly never lost any sleep over this "burden", and, in fact, I don't think I ever really even give it any thought, because, as I said, in C++, resource management is automatic, guaranteed by basic language mechanisms (deterministic destruction, value-semantics, stack unwinding on exceptions, etc.).
Java doesn't support multiple inheritance, other than via interface types, which in my opinion are really useless. Every concrete class that inherents an interface class has to separately implement each function in the interface! Gah!
I'm not 100% sure I get this correctly. But I think I agree. One might say that the C++ style of OOP mechanism is too permissive or not "pure" enough, but the flip side of that is that the Java style of OOP mechanism is often tedious, restrictive and repetitive, and for no good technical reason, only an ideological one.
Just today, I was optimizing some code in C++, and I implemented an OOP-style abstract base class, without using any virtual functions at all. This is something that probably sounds like some kind of dark / black magic to a Java programmer or an OOP purist, but it's just another day at the office for a C++ programmer.
I wrote a smart-pointer implementation for C++ that handled recursive object references
@rubberman, it's not the first time you mention that fine piece of engineering. Everytime you mention it, my mouth waters.. I would love to see that code, but I know I can't.
Can any one tell me the major difference between JAVA and C++...
Well, besides what I already mentioned, I would have to mention a few other major ones:
- C++ has a Turing-complete meta-programming language built into it via its template mechanisms, which allow for general compile-time calculations, type manufacturing and code verifications.
- Java has generics which only support a very basic form of parametric polymorphism, while C++ has templates which allow for a nearly complete support for generic programming.
- Java supports run-time reflection, which C++ does not support (mainly due to lack of implicit indirections, from what I understand).
- Java has a much larger standard library, including GUI, networking, and many other features. C++ aims for a minimalistic standard library such that it can work on a wider array of environments.
- Java is a language that evolves more rapidly, which also implies some amount of version compatibility headaches (e.g., writing code that can work on several versions of the JVM). C++ tends to evolve more slowly, meaning that it lags behind in state-of-the-art features, but it is also more stable and nearly never breaks any backward compatibility.
These are definatly not the "rules" for either communities. They have more in common then whats different, and what is different is only by a little bit.
I largely agree with those "rules" about the two communities. I often find that the Java community has a large population of people who are either academics or RADs (Rapid App. Developers). C++ is too much of a free-form language to suite the needs of the by-the-book computer science academics, and it's too close to the metal for doing RAD. I guess the C++ community is doomed to be only populated by hard-core professional developers who write highly-efficient industrial-strength infrastructure code... oh well. ;)
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
This means that there is an extra layer of indirection on top of everything
Almost everything; this doesn't apply to method scoped primitives which are allocated on the stack.
which also implies some amount of version compatibility headaches
Do you have examples for this? Code written for JDK 1.1 works on the JDK 8 with pretty much no changes.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.