Jump to content
  • Advertisement

Archived

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

Emonious

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

This topic is 5302 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!