Archived

This topic is now archived and is closed to further replies.

dmf_king

Java, C++... can't we all just get along!?

Recommended Posts

Hi, just wondering what the real differences are between java and C++ - in some ways I think Java is better because it is cross-platform well... in the sense that .jars can be opened on any platform. Anyway, are there any significant limitations with java - I''m going to stick with c++ but I''m just curious.

Share this post


Link to post
Share on other sites
Java and C++ are both good in their own domain.

The problem is that most people have serious problems determining the bounds of those domains.


Java has major strengths:
1) Complete ideal cross-platformed in the sense that code doesn''t even need to be recompiled in order to run on different OSes and architectures (unless the coder pulled some endian dependent BS).
2) Applets. You can''t find anything quite like em.

C++ has a couple strengths of its own:
1) Fast. Especially when written properly and without too many frills.
2) Far more powerful in terms of memory management, polymorphism, templates, etc. Of course you pay for that in complexity of code.
3) Native. Sometimes native just works better, for whatever reason. This is related to speed as well.

Share this post


Link to post
Share on other sites
Well programming languages are just a tool, so the best would be to be able to use as many as possible. Each programming language has its fields in which its top. Deciding which to use depends on your project, so ideally you decide which language based on the project.
-CProgrammer

Share this post


Link to post
Share on other sites
I use Java because my Java code tends to actually work the nth time I write/edit it, for much smaller values of n than when I work in C++. And I learned C first, then C++, then Java. :/

Share this post


Link to post
Share on other sites
quote:
Original post by DerAnged
cocoa on mac gcc on linux mingW or VC++ on windows C++ isnt cross platform eh? (c++ is faster to)(yet asm is faster than cpp)


if you now demonstrate how you compile ONE executable on any of those platforms that will run on every other platform.. then i believe you understood what people talk about when they say cross platform in combination with java (especially since he even explained it, just to be sure nobody is thinking about the strict meaning of it).

and i wont go into details about how much of a pain in the .. it is to actually write something that will compile on each platform (especially if you dont happen to have all of them for testing).

omg, im defending java and i dont even like it *lol*

Share this post


Link to post
Share on other sites
Yes. For me, C++ is the tool to use when I need to write something heavy on the processing/memory (like, say, a game). I''m also simply more familiar with C++.

Java is what I use when I need to write something and I need it done YESTERDAY. I find it easier (read: faster) to get working code with Java than with C++. No pointers to mess with, no playing with memory allocation, etc.

It all depends on what you need it to do, as has been stated previously in this thread.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Promit
C++
Far more powerful in terms of [...] polymorphism

Since you mentioned templates separately, how exactly does C++ have far more powerful polymorphism (counting out templates)? Java and C++ have the same kinds of polymorphism, i.e. inheritance based dynamic polymorphism and static polymorphism of functions with different parameters.

If you meant templates, then let me tell you Java has far easier memory management, dynamic garbage collection, elegant dead reference detection system, memory leak prevention mechanism and more

Share this post


Link to post
Share on other sites
quote:
Since you mentioned templates separately, how exactly does C++ have far more powerful polymorphism (counting out templates)?


Java doesn't have multiple inheritance as C++ has.

A class in Java can only inherit from one single class, but implement several interfaces. A class in C++ can inherit from multiple classes.

- Christoph

---
Teamwork Software - Stuff That Does Something

Edit: Quoted stuff.

[edited by - Captain Nuss on January 25, 2004 3:09:09 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
Since you mentioned templates separately, how exactly does C++ have far more powerful polymorphism (counting out templates)? Java and C++ have the same kinds of polymorphism, i.e. inheritance based dynamic polymorphism and static polymorphism of functions with different parameters.


Multiple inheritance as mentioned by the other guy (and as mentioned by the other other guy, not always that desirable), and also private inheritance (very rarely used and of dubious value, but there you have it).

quote:
far easier memory management, dynamic garbage collection, elegant dead reference detection system, memory leak prevention mechanism


You just basically said the same thing four times.

WTF, I''m attacking a Java defender and I prefer Java

Share this post


Link to post
Share on other sites
quote:
Original post by Promit
Java and C++ are both good in their own domain.

The problem is that most people have serious problems determining the bounds of those domains.


Java has major strengths:
1) Complete ideal cross-platformed in the sense that code doesn''t even need to be recompiled in order to run on different OSes and architectures (unless the coder pulled some endian dependent BS).
2) Applets. You can''t find anything quite like em.




You forgot multipass compiler, cleaner code, console like guarantions (like you''d more or less know what would be avilable and you are somewhat isolated from OS craziness. You just need to worry about bad graphic drivers and bugs in VM, not too much about the hardware problems.), and of course much less bugs in your code, easier testing, processor independence, easy maintainace of your programs.

ASM
in comparisson has this advantages
Modularity, possibility of ring 0 programming, acess to the memory ANYWHERE, speed (what you programmed that you''ll get), direct access to the Hardware, reassemblers (x86 to 64 bit)
~_^

Sometimes that difference is in programmers. Java programmers are less likely to think "just in the local optimum" >_<



Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
quote:
Original post by Promit
C++
Far more powerful in terms of [...] polymorphism

Since you mentioned templates separately, how exactly does C++ have far more powerful polymorphism (counting out templates)? Java and C++ have the same kinds of polymorphism, i.e. inheritance based dynamic polymorphism and static polymorphism of functions with different parameters.
In other words, counting everything out that is different between C++ and Java, C++ and Java are the same. Master of the obvious here...

quote:
If you meant templates, then let me tell you Java has far easier memory management, dynamic garbage collection, elegant dead reference detection system, memory leak prevention mechanism and more

He said "more powerful", not "easier". If you want easy, don''t use Java.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Raloth
That is not necessarily a good thing...


Oh, there are many times when muliple inheritance is handy.

... like default/common implementations of an interface, flatting out class hierarchies, and easily adding class functionality without screwing up every other class in the inheritance tree.

I think the main reason some people think multiple inheritance is bad is because people where trying to justify Java''s lack of MI when Jave first came out.

Share this post


Link to post
Share on other sites
For Java, the user of your app must have the JAVA RUNTIME. Most home users don't. And if your app is a small one (A couple megs or less) then it's a major pain in the butt. Should the users have to download many megabytes just to use your little app.

And, by default, java programs don't have an exe file to start them which is what most Windows users are used to.

DISCLAIMER: If any of the above statements are incorrect, feel free to give me a good hard slap

My game: Swift blocks

[edited by - JohanOfverstedt on January 25, 2004 4:58:06 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by antareus
quote:
of course much less bugs in your code, easier testing, easy maintainace of your programs

Exactly what constructs in Java gives me these things?

More readable guess what.

Multiple entry points and better debugers than C ones. gives you the second.

Class encapsulation that is guaranteed with tools that use Java structure to their advantage gives you third.

removed offtopic xxx

[edited by - raghar on January 26, 2004 5:21:02 PM]

Share this post


Link to post
Share on other sites
>>Something along the lines of multiple inheritance being not necessarily good...

So what? Allocating 2 gigs of memory to a single pointer isn''t necessarily a good thing. Being able to use pointers to anywhere isn''t necessarily a good thing. Having unchecked buffers isn''t necessarily a good thing.

That doesn''t mean they''re necessarily a bad thing. There are many cases where multiple inheritance is an elegant solution to a problem, and C++ provides reasonably powerful and complete facilities for dealing with multiple inheritance properly.

quote:

You forgot multipass compiler, cleaner code, console like guarantions (like you''d more or less know what would be avilable and you are somewhat isolated from OS craziness.



On the C++ side, I also left out the oh so useful preprocessor that does so much, enums, using more than one public class per file, much more powerful memory management abilities, and other things too. The point is they both have plus and minus sides.

Share this post


Link to post
Share on other sites
*vomits on thread*

oh look the stain blends right in with everyone''s comments...you cant even tell the difference...



dmf_king: sorry you had to be witness to this. to answer your question, for you i can almost guarantee there will be no significant limitations...basically the real difference is in the freedom the language gives you to interact with the hardware and lower levels...since java runs on a virtual machine you by definition cant do things like address memory directly. this can be great, it makes for a very stable and quick platform to develop on, but in very rare cases you have to bend over backward to do something that would have been pretty trivial with some pointer arithmetic. personally i think everyone should know both, they are both great languages.

everyone gets in such a tizzy about these conversations, i dont know why...especially now that many c++ developers are realizing that the C# paradigm isnt so bad...and, by extension, that java isnt where it was in 1998. JIT compilers have made a world of difference. ignorance, i suppose.



and to those talking about multiple inheritance...usually thats called a "hack"...using multiple interfaces is usually all you need, especially since you can cut out the conflicting data (vs the methods/functions) that was the reason anybody said anything bad about multiple inheritance in the first place. only very very rarely would you ever have to use them and a)you can figure out another way and b)you pay a price for a proper OOP implementation. *runs for cover*

Share this post


Link to post
Share on other sites
quote:
Original post by Raghar
More readable guess what.


Readability is subjective. Java has cleaner syntax. I can write confusing programs in either language.

quote:
Multiple entry points and better debugers than C ones. gives you the second.

Better debuggers? Again that is subjective. You''d be hard pressed to beat VS.net''s.

quote:
Class encapsulation that is guaranteed with tools that use Java structure to their advantage gives you third.

How is this any different from C++ classes?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Zahlman
You just basically said the same thing four times.
I see the joke was lost

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Russell
In other words, counting everything out that is different between C++ and Java, C++ and Java are the same. Master of the obvious here...
I see you didn''t quite understand the point . Try harder, you can do it!

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
If you meant templates, then let me tell you Java has far easier memory management, dynamic garbage collection, elegant dead reference detection system, memory leak prevention mechanism and more


I don''t really think it''s fair to compare templates to memory management. Why not compare templates to generics?

Java''s new generics system is both better and worse than C++''s template system.

In Java one can specify that a generic type parameter must be a subclass of a particular class (or implement a particular interface). This is handy if you want to define a generic class or method that operates on Collections, say.

Although C++ would still detect an attempt to use .begin() on a float, Java detects the error closer to where it actually occurs.

C++''s templates have features that are absent from Java (and, as it happens, C#). In C++, templates can have value parameters as well as type parameters. This allows the compiler to generate more efficient code for types such as matrix<4, 4>, in terms of both speed and space.

If Java supported this, it would allow some bounds-checking to be performed at compile-time: mat.get(5,9) would obviously be invalid if Java knew the size of the matrix at compile-time.

In addition, C++ allows for specialisation of templates. This allows for further optimisation. In the running example, the implementation of matrix<4,4> could be optimised to automatically use CPU extensions for multiplying 4x4 matrices, if any are available.

Java can specialise in as much as it could define a Matrix44<T> class that extends the Matrix<T> class. However, the advantage of C++ specialisation is that adding matrix<4,4> automatically applies that specialisation to all 4-by-4 matrices, whereas in Java one would need to replace references to Matrix with references to Matrix44 wherever a 4-by-4 matrix was being used.

Another significant advantage in C++ is that, unlike Java, it allows for generic parameter types to be value types. This would allow for efficient storage of value types in Vectors or Hashtables, amongst other things.

The reason Java doesn''t allow this is also the reason for one of the advantages it has over C++: Java''s generics are designed so that, unlike in C++, only one copy of a generic method or the methods of a generic class needs to be compiled.

That makes it easy to distribute generics in libraries without having to worry about what will happen if somebody tries to use your generic with a type you haven''t compiled in.

In summary:

C++: Value parameters, specialisation, type parameters may be value types
Java: Type parameter constraints, single-compilation

Type constraints could be added to C++ without issue.

The single-compilation feature is mutually incompatible with C++''s implementation of value parameters and the orthogonal type parameters.

You can redefine how value parameters and type parameters work -- value parameters act like ordinary parameters, and type parameters are always reference types (value types are boxed as necessary: requires the introduction of boxed types into C++). That would allow the single-compilation rule to be observed but would negate the efficiency benefits that C++ templates have over Java generics.

It seems to me that Java generics are more likely to be widely used than C++ templates because updates to Java generics can be distributed in binary libraries such that any program that used the old version of the generic will have no trouble using the new version. In C++, on the other hand, not only do you have to go out of your way to put your template code into seperate libraries, but a consumer of your library will only be able to use the template functions that you''ve compiled in, which defeats the purpose of templates.

CoV

Share this post


Link to post
Share on other sites