PDA

View Full Version : Java and C++ are alike ?



black
06-16-2003, 10:04 PM
i know something about C++ but nearly nothing of Java, some friends told it is easy to understand and they are alike, most interesting is they said in Java you need not to face pointer directly, which is cool, but I think C++ has many advantages over Java, any opinions ? :rolleyes:

ygfperson
06-16-2003, 10:21 PM
If you know nothing of Java, how can you say that C++ has many advantages over it?

Mister C
06-16-2003, 10:21 PM
Well this is an open question you will receive many opinions from.

here are a few.

1. All have direct ancestor of C.

2. Java has no multiple inheritance (uses interface)

3. Java has no pointers (references)- can use pointers in C# but is considered unsafe

3. Java is platform independent. Unlike C/C++.

4. Java and C# are object oriented (C++ is technically hybrid)

I have taught both C++ and Java. I personally perfer Java and now C# over C++. My college and I still teach C as a structured non OOP language.

Just my thoughts...

ygfperson
06-16-2003, 10:41 PM
C++ is technically hybrid
AFAIK, the term 'object oriented' means that a language implements polymorphism. 'Object based' describes a language which deals with objects and isn't polymorphic. So C++ is totally object oriented. At least, that's my understanding.

Zach L.
06-16-2003, 11:08 PM
C++ is technically multi-paradigm. It isn't object oriented because you can write as large (or as small) a program you want without touching objects (at least nothing beyond a struct to hold some data). On the other side, you can write almost completely object-oriented code.

As for which has advantages over the other... as always, this depends on your application of it.

Try writing a high-performance matrix library in Java or an interactive web program in C++.

black
06-16-2003, 11:56 PM
Originally posted by Mister C
Well this is an open question you will receive many opinions from.

here are a few.

1. All have direct ancestor of C.

2. Java has no multiple inheritance (uses interface)

3. Java has no pointers (references)- can use pointers in C# but is considered unsafe

3. Java is platform independent. Unlike C/C++.

4. Java and C# are object oriented (C++ is technically hybrid)

I have taught both C++ and Java. I personally perfer Java and now C# over C++. My college and I still teach C as a structured non OOP language.

Just my thoughts...

from your opinion Java seems definitely beyond C++, i cant see something be advantages over Java (well, if you say pointers, but some go for it and others resists it)

Prelude
06-17-2003, 06:39 AM
>from your opinion Java seems definitely beyond C++, i cant see something be advantages over Java
This is a dangerous assumption if you don't have extensive experience with both languages. From my experience, Java is a diluted, "safe" C++. If you take C++, remove everything but the OO paradigm, remove everything you consider too complicated or too unsafe, add keywords up the wazoo to avoid the C/C++ "static" confusion, force arbitrary size decisions on the language, and throw a huge and useful collection of libraries into the mix, you pretty much have Java.

>AFAIK, the term 'object oriented' means that a language implements polymorphism.
There are four key concepts: Abstraction, Polymorphism, Inheritance, and Encapsulation.

>but I think C++ has many advantages over Java, any opinions ?
It depends on what you intend to use either language for. For many tasks C++ is too much language for the simple job you want done, so you choose a language more specialized (or slower, but simpler and more productive).

Zach L.
06-17-2003, 08:17 AM
>>> 3. Java is platform independent. Unlike C/C++.

Well, compiled binaries are not platform independent, but pure ANSI C/C++ code will work on any platform with a compliant compiler (which is most you'll deal with probably). Same way Java has to have a bytecode interpreter for its target platform.

Mister C
06-17-2003, 09:40 AM
OK, I knew I would

"platform independent": -an example here is that primatives in Java have the same size regardless of the compiler/platform.

"C++ is hybrid" : Well it is not totally OOP- this is known. Java and C# you have to use a class just to write a basic program. C++ you can write a program without using a class.

Prelude is right in stating the four hallmarks in OOP.

C++ does has some advantages :

1. I/O is much easier.
2. Formatting is easier.

those are a few.

Zach L.
06-17-2003, 10:42 AM
>>> "platform independent": -an example here is that primatives in Java have the same size regardless of the compiler/platform.

Okay, I see what your getting at. Java code will behave the same anywhere, C++ code might not, depending on how data is stored.

C++ has a few other strengths: generic programming through templates, and speed (while maintaining some semblance of OOPness) again, largely due to templates and lower-level memory access.

A lot of things you can do in C++ though, you can also do in Java. Which is 'better' depends on which you are more familiar with, and what the problem requires. There are some things for which C++ is simply overkill, or are difficult to accomplish in C++, but not in Java.

golfinguy4
06-17-2003, 10:49 AM
Yeah, I've heard rumors that templates might be added to Java. Not sure of the validity of the rumors though.

Shiro
06-17-2003, 11:06 AM
> but I think C++ has many advantages over Java, any opinions

Both have advantages over eachother, both have different fields of application. What may be an advantage of C++ in one field of application, may be a disadvantage in a different field of application.

codegirl
06-17-2003, 01:16 PM
If there's one thing that I learned from my Programming Languages class, it's that there is no "best" language -- it all depends on the application you're writing. If there was a "best" language for all types of applications, don't you think there wouldn't be very many other languages to choose from? :)

GuiltySpark343
06-19-2003, 02:05 PM
Java is no more portable than any other language. In fact, it's not even executable. No, it's a text file that has to be passed to a kernel that has already been compiled for the specific processor the Java is going to be "run" on, which in turn executes the java instructions in .obj.

Just another layer.

Get over it.

Unregd
06-19-2003, 03:56 PM
Originally posted by GuiltySpark343
Java is no more portable than any other language. In fact, it's not even executable. No, it's a text file that has to be passed to a kernel that has already been compiled for the specific processor the Java is going to be "run" on, which in turn executes the java instructions in .obj.

Just another layer.

Get over it.

That's the point. Joe Average doesn't know how to compile a relatively portable C++ application, but he'll have no problem going to www.dancing-baby-and-other-wastes-of-time.org to run a Java applet. It's such a good idea, in fact, that Microsoft took Sun's idea and made the .NET platform and C#.

And I wouldn't say Java is less portable than Visual Basic 6.0 or some obscure language. There are Java virtual machines for many, many platforms.

Zach L.
06-19-2003, 04:05 PM
Java has the portability of any other interpreted language (even though the Java itself isn't interpreted, the bytecode is). It'll work uniformly on any system for which a properly implemented virtual machine (which of course is written in a compiled language) without having to be recompiled.

GuiltySpark343
06-20-2003, 08:59 AM
"...That's the point. Joe Average doesn't know how to compile a relatively portable C++ application, but he'll have no problem going to www.dancing-baby-and-other-wastes-of-time.org to run a Java applet. "

True, but only if somebody has already ported the "virtual machine" to the processor in question.

Java is JAFL.

Remain here, Reclaimer. I must activate Security Protocol 2401 from a remote terminal. I will route Sentinels to your location to compliment your Class 2 armor until I return. The Flood is virulent, and must not be allowed to leave this installation.

golem
06-23-2003, 06:36 AM
Java is nothing compared to C++ speed, but take its simplicity and similarity to C++ and you would have the best educational programming language.

Just few days ago I was able to semi-complete nice Tetris game in Java (J2SE/AWT), all within one month and without any previous knowledge of this language. As I am occasionally stupid and lazy, this proved me that Java is not so bad.

As for other languages, all depends on what you try to gain with your particular language. For those "object oriented" with possible further step to C++ and some MFC/Windows programming, it is simply not bad, you won't loose.

Lurker
06-23-2003, 09:33 AM
Ahh.....something I FINALLY know about. First of all, Java is no better, or worse, than C, C++, or C#. But there are some big differences between the languages. The basics:

Java does not have(that C/C++ does):


Pointers
Templates
Structures or enumerations
Multiple inheritance


Java does have (that C/C++ doesn't):


Interfaces
Ability to compile into applets
Great Portability
Great Secuirty


The list could go on, but that's all I care to think about now :D !

Anyway, Java is compiled not into machine code, but bytecode. This bytecode is in turn interpreted by a Java interpreter. The interpreter ensures better security and portability (unfortunately, not speed). If compiled into an Applet, it can be run by a Java compatable web browser to have complete programs or games playable via internet. You may have seen Java chat rooms on the internet......another wonder performed by applets :) ! OK, I'll quietly crawl away and hide now........

beege31337
06-23-2003, 12:34 PM
I use java more often then C++.
I like it's style and it's libraries, and I don't have to recompile to move from my XP to Linux boxes or to use on Unix at my school.

Mister C
06-23-2003, 09:38 PM
Java does not have(that C/C++ does):




Pointers

Templates

Structures or enumerations

Multiple inheritance




Well in the newest version of Java to be out later this year- java will have enumerated types. Interfaces can simulate multiple inheritance