C++ & Java

Posts 1–8 of 8 · Page 1 of 1
C++ & Java
I am currently learning java this year and i was looking at c++ coding today and is it just me or are some of the commands the same like
int x;

and stuff like that.
Also i was thinking of learning c++ during the summer after i finish learning java. Is this a good idea?
I was just wondering since i already know visual basic and java.
Well, you will need some time to adjust to alternate features. For example in java there is no # for including headers, or a define function at all.

And in java, every class comes from an object. In C++ you can define your own class trees and they don't have to connect to each other in any way.

In C++, you also can't have dual pointers for the same object like in Java (in dynamic memory).

I would definitely recommend you switch to C++, but you will have a lot of re-learning to do, despite the two languages having some common features together. I very seldom use java personally.
Quote Originally Posted by Silentknife View Post
Well, you will need some time to adjust to alternate features. For example in java there is no # for including headers, or a define function at all.
#define is a macro, processed be the preprocessor, I'm positive java has an equivalent. If not, I'm pretty sure there are addons to the compiler.

In C++, you also can't have dual pointers for the same object like in Java (in dynamic memory).
Not sure what you mean by this, if you mean, two pointers pointing to the same location, then yes, of course you can do it in C++

I would definitely recommend you switch to C++, but you will have a lot of re-learning to do, despite the two languages having some common features together. I very seldom use java personally.
I agree, the syntax is fairly similar but they are both completely different, consider one runs in a VM, the other doesn't. One has garbage collection, the other doesn't. There are a lot of major differences in the languages. They're just not noticeable until you get more advanced with the.
Quote Originally Posted by radnomguywfq3 View Post
#define is a macro, processed be the preprocessor, I'm positive java has an equivalent. If not, I'm pretty sure there are addons to the compiler.
I think he was talking more specifically about #include. Where as Java uses import to load headers.

I agree, the syntax is fairly similar but they are both completely different, consider one runs in a VM, the other doesn't. One has garbage collection, the other doesn't. There are a lot of major differences in the languages. They're just not noticeable until you get more advanced with the.
Let me speak from experience, from switching over from Java to C++, that the similarities in style and syntax outweigh the differences. Technically speaking in the way the two languages compile and run they are much different, but the syntax for most every HLL is pretty similar, and I found the transition very easy. Haha even though I did have some trouble getting used to the way C++ does strings, and not having garbage collection...
Quote Originally Posted by radnomguywfq3 View Post
Not sure what you mean by this, if you mean, two pointers pointing to the same location, then yes, of course you can do it in C++
Though on some (slightly older) compilers it can give you "non-static reference member" issue and refuse to compile if two pointers go to 1 location, for example, a program which otherwise works fine, but if you point:


int main(int argc, char* argv[]){
string a = "0000f48";
string b="0000f49";
hack a(a);
hack b(b);
b = a;
}
Refuses to compile with assignment error in Borland C++ 4.9 "non-static reference member"
Quote Originally Posted by Silentknife View Post
Though on some (slightly older) compilers it can give you "non-static reference member" issue and refuse to compile if two pointers go to 1 location, for example, a program which otherwise works fine, but if you point:



Refuses to compile with assignment error in Borland C++ 4.9 "non-static reference member"
Those aren't pointers. They're classes. And they can't be initialized by using that method, you have to call their constructor(provided it's not static).

Any type declaration with the * suffix makes it a pointer. Consider:
char* ptr1 = "pointer 1";
char* ptr2 = ptr1;


Both pointers point to the same location.
or
char* ptr1 = "a";
char* ptr2 = "a";
Both pointers point to different locations with similar data(unless the code goes through optimization, there is a chance they may point to the same location.)
string myString = new string(some constructor arguments);
string* stringPtr = &myString;

stringPtr points to myString.

Quote Originally Posted by why06 View Post
Let me speak from experience, from switching over from Java to C++, that the similarities in style and syntax outweigh the differences. Technically speaking in the way the two languages compile and run they are much different, but the syntax for most every HLL is pretty similar, and I found the transition very easy. Haha even though I did have some trouble getting used to the way C++ does strings, and not having garbage collection...
I beg to differ. Just the fact that java runs in a VM vs C++ which is directly executed is a huge difference. Also consider that most java programmers don't communicate with the operating system directly, AT ALL. C and C++ the programmer is generally always communicating with the operating, regardless if it is small or large. If you work with any large scale projects you will find a considerably MASSIVE difference. Another big one, you have so little control over memory in java you don't even have the ability to use pointers(real pointers, that point to actual locations in memory), where as in C and C++, you have to be aware of everything that is happening in memory.
Quote Originally Posted by radnomguywfq3 View Post
I beg to differ. Just the fact that java runs in a VM vs C++ which is directly executed is a huge difference. Also consider that most java programmers don't communicate with the operating system directly, AT ALL. C and C++ the programmer is generally always communicating with the operating, regardless if it is small or large. If you work with any large scale projects you will find a considerably MASSIVE difference. Another big one, you have so little control over memory in java you don't even have the ability to use pointers(real pointers, that point to actual locations in memory), where as in C and C++, you have to be aware of everything that is happening in memory.
Yeh I know. I'm just saying I didn't think it was that hard. In fact I would say its a lot easier to learn another HLL once your already comfortable with another HLL. Im not saying there aren't major differences I was merely saying that switching over from Java to C++ was fairly easy. Hell didn't you learn C++ after Java... wouldn't you say it was a pretty smooth transition.

I mean dude... what's he name there... kratos is trying to learn C++. I'm just trying to give him some encouragement. I mean that what this thread was about. No need to discourage him. I don't think I was be unrealistic when I said that the similarities between Java and C++ outweigh the differences; atleast from a coding stand, you know actually writing the programs.
Quote Originally Posted by why06 View Post
Yeh I know. I'm just saying I didn't think it was that hard. In fact I would say its a lot easier to learn another HLL once your already comfortable with another HLL. Im not saying there aren't major differences I was merely saying that switching over from Java to C++ was fairly easy. Hell didn't you learn C++ after Java... wouldn't you say it was a pretty smooth transition.

I mean dude... what's he name there... kratos is trying to learn C++. I'm just trying to give him some encouragement. I mean that what this thread was about. No need to discourage him. I don't think I was be unrealistic when I said that the similarities between Java and C++ outweigh the differences; atleast from a coding stand, you know actually writing the programs.
Your point is valid for a large majority of projects but the more advanced ones, it is much different. That's all I meant to say. I learned C++ first, I think a transition form C++ to Java is much smoother then the other way around. When java was first created it targeted many existing C++ and C programmers.

I didn't mean to completely disagree with you, or discourage the poster. I was just stating some things he needs to be aware of.
Posts 1–8 of 8 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

Talk with us