Java vs C++! How close are they really?

Started by
32 comments, last by Emonious 20 years, 3 months ago
Sadly, while I'm going into game design and development as a future career and that uses C++, it is Java that is used for my up coming computer science courses. I've taken a few peeks at Java, but nothing serious. Enough to know it is similar in many ways to C++. My question is this though: HOW close is it to C++? Some of the syntax and such seems almost dead on exact to C++. If I end up having to learn Java as my primary language and put C++ on hold till college ends, how much will transfer over and how much will be useless to me? Thanks for any comments (Edit: Comments on C# and J# comparisons to C++ wouldn't be useless either :D) [edited by - Emonious on January 3, 2004 12:30:02 AM]
-----------------------------Naze ga muzukashi desu ka...
Advertisement
I had no problems switching from Java to C++. The beginning hurt my head a little with headers and the different way of declaring classes and pointers, but it was worth the trouble. I am never going back! Yes I know that Java can do everything C++ can, but a lot of times it just doesn''t feel like it was made for it.
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
What are some examples of the code differences? IE how classes were different.
-----------------------------Naze ga muzukashi desu ka...
Apart from some things that are "missing" in Java (features that C++ has, but not Java, such as operator overloading), the biggest difference between them is in how they handle memory. Because of that, it can be a little confusing switching between them after coding in one of them exclusively for a longer period.

Edit: Do a search if you want to know the concrete differences. Java vs C++ questions are extremely common.

[edited by - eighty on January 3, 2004 12:51:51 AM]
I guess what I was hoping for was more of a few examples of the major differences that I''d find or run into.

Doing a search on such a large topic like this can take quite a while, when a question could be asked to the experts instead.
-----------------------------Naze ga muzukashi desu ka...
I assume the biggest thing that confuses people is that C++ doesn''t have a garbage collector, meaning it''s up to you to free/delete everything you malloc/new.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
I program in both C++ and Java fairly regularly, and the main differences that I can tell are that Java lacks generic functions(templates), 1.5 will fix that when it comes out. Java also lacks operator overloading, except they actually used it for the string class, which is stupid. Although I am sure calling a method for concatination would get painful after a while like String.equals("blah") is painful after a while. Although pointer syntax does gat some taking used to when going back and forth, the main differences is that both languages have their own application. And that is up to the programmer as which is easier for their particular project.
A big difference you''ll notice is that in java you declare a class in one file and everything must be in classes, including you''re main() function. In c++ you''ll usually have a header file (File.h) where you declare the variables and function prototypes and a File.cpp file where you implement everything. I hope this helps:

Java:
public class Example {
private int doggy;
private double cat;

public Example(int d, double c) { doggy = d; cat = c; }
public int getDog() { return doggy; }
public double getCat() { return cat; }
}

C++:
// File.h //
class Example {
private:
int doggy;
double cat;
public:
Example(int d, double c);
int getDog();
double getCat();
};

// File.cpp //
Example::Example(int d, double c) {
doggy = d;
cat = c;
}

int Example::getDog() {
return doggy;
}

double Example::getCat() {
return cat;
}

this was a silly example but i hope it gives some idea

Really you don''t have to worry about it. You''re sweating the details and you don''t need to. It doesn''t matter if you use Fortran, Basic or Java in school. Focus on the concepts and the principles they teach you. Once you become fluent with one language picking up another is a simple matter of learning the syntax and features specific to that language. By the time you get to that point, it will be easier than you think. So don''t stress over it.
Thanks for the explaination and examples guys, they are appreciated.

I''ll take Aldacron''s advice and just relax and learn what comes my way through the class. Nothing major it looks like difference wise.

Thanks again.
-----------------------------Naze ga muzukashi desu ka...

This topic is closed to new replies.

Advertisement