Fairly proficient in JAVA, must learn C++

YankeesWin

Senior member
Aug 3, 2001
642
0
0
I'm in college, and just transferred to a new school this Fall. My old school taught everything in JAVA, and I'm enrolled in a Data Structures course at my new school and the class uses C++.

From the brief gloss over I did on my own they seem to be pretty similar (obviously as they're both based on C), I just need to know the fundamental differences and I can take it from there. Any pointers on the most crucial differences or a link/book reference to some information on the basic differences that I'd need to get started would be greatly appreciated.
 
Sep 29, 2004
18,665
67
91
Originally posted by: YankeesWin
I'm in college, and just transferred to a new school this Fall. My old school taught everything in JAVA, and I'm enrolled in a Data Structures course at my new school and the class uses C++.

From the brief gloss over I did on my own they seem to be pretty similar (obviously as they're both based on C), I just need to know the fundamental differences and I can take it from there. Any pointers on the most crucial differences or a link/book reference to some information on the basic differences that I'd need to get started would be greatly appreciated.

The big difference is that C/C++ has no garbage collection. You need to manage your memory.

Strings are much harder (till you get the hang of things).

If you end up doing anything graphical in C/C++, it is 10 times harder than in Java. Java makes GUIs easy to do.

Unless you use something like MFC, you will not have any built in collection types. You will need to write your own linked lists, red-black trees, etc.

Since you are taking a data structures course, I'm assuming you are going to be writing trees, linked lists, etc in C/C++. If you want to learn, write an OO linked list class. Learn how to remove from the end, beginning and middle. Same for adding.

I'm surprised that a data structures course would be taught in C/C++ though. Alot of time is going to be spent coding and not learning the subject matter. Scheme would have been a much better choice.
 

Fallen Kell

Diamond Member
Oct 9, 1999
6,063
437
126
Lots of schools teach a data structures class in C/C++ mainly because you are forced to write the code and get your hands dirty, since that is what you will be doing in the real world anyway (well, more likely you will be reading someone else's code and adding/changing functionality, but the jist of it is that you need to get you hands dirty).

While I love java, it really has a high level of abstraction such that you don't have to dig into it as deep as you have to do with C/C++.

As for differences, well, there are lots because you don't have to code in an object oriented way with C++, however, your school will probably expect that, especially in a Data Structures class. That said, as others have mentioned, you need to remember that you need to deallocate your memory. That is something that you don't do in Java and you take it for granted. You need to pay attention that everything you do which uses memory deallocates the memory it used, especially in object oriented when you may make tons of things which use up lots of memory....
 

Cogman

Lifer
Sep 19, 2000
10,278
126
106
Originally posted by: YankeesWin
I'm in college, and just transferred to a new school this Fall. My old school taught everything in JAVA, and I'm enrolled in a Data Structures course at my new school and the class uses C++.

From the brief gloss over I did on my own they seem to be pretty similar (obviously as they're both based on C), I just need to know the fundamental differences and I can take it from there. Any pointers on the most crucial differences or a link/book reference to some information on the basic differences that I'd need to get started would be greatly appreciated.

long shot, but you aren't at BYUI are you? (The date you post this just doesn't seem like a normal schools fall starting date)

Anyways, as has been said, memory management is probably the biggest difference out there.

I disagree with strings being that much harder though. the string object is just as flexible as most other strings I have ever dealt with. Char arrays, on the other hand, aren't.

You should familiarize yourself with some of the standard libraries, like iostream, string, cstdlib, ect. cppreference.com has a good amount of examples for some of the most common libraries.
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
More specifically on memory management:
Learn pointers first, before you try memory management. Once you understand that pointers point to memory (sounds easy, I know, but its actually pretty subtle), you're reading to manage your own memory. In short: Anything you new you must delete exactly once, when you're done using it.

Learn to use valgrind... it is your friend.

As Cogman said, cppreference.com is very useful, for STL data structures (which you probably won't use, seeing as you're in a data structures course), and for I/O, etc.
 

XxPrOdiGyxX

Senior member
Dec 29, 2002
631
6
81
Originally posted by: aznium
memory management and c-style strings

What he said. You must be MUCH more careful because of pointers. Since there is no garbage collection you have to worry about memory leaks and such. Also, it's not a pure OO language so you will find it's a tad different when you try to develop using an OO paradigm. As far as things like syntax; you should pick it up fairly quickly since Java resembles it.
 

Cogman

Lifer
Sep 19, 2000
10,278
126
106
Originally posted by: XxPrOdiGyxX
Originally posted by: aznium
memory management and c-style strings

What he said. You must be MUCH more careful because of pointers. Since there is no garbage collection you have to worry about memory leaks and such. Also, it's not a pure OO language so you will find it's a tad different when you try to develop using an OO paradigm. As far as things like syntax; you should pick it up fairly quickly since Java resembles it.

I really don't know what you mean by "It isn't a pure OO language". Is it that it doesn't force you to use objects exclusively? I mean really, C++ has all the features that any other OO language uses, and very little forces you to do anything procedurally in it other then your desire to do things procedurally.

Ok, so you have a main function, but if you really wanted, that could easily be the only function in your entire program.

I guess if you mean that not all predefined functions for C++ are OO based, then yeah, I guess that could be different, but it really isn't THAT different from a "Pure" OO language.
 

XxPrOdiGyxX

Senior member
Dec 29, 2002
631
6
81
Originally posted by: Cogman
Originally posted by: XxPrOdiGyxX
Originally posted by: aznium
memory management and c-style strings

What he said. You must be MUCH more careful because of pointers. Since there is no garbage collection you have to worry about memory leaks and such. Also, it's not a pure OO language so you will find it's a tad different when you try to develop using an OO paradigm. As far as things like syntax; you should pick it up fairly quickly since Java resembles it.

I really don't know what you mean by "It isn't a pure OO language". Is it that it doesn't force you to use objects exclusively? I mean really, C++ has all the features that any other OO language uses, and very little forces you to do anything procedurally in it other then your desire to do things procedurally.

Ok, so you have a main function, but if you really wanted, that could easily be the only function in your entire program.

I guess if you mean that not all predefined functions for C++ are OO based, then yeah, I guess that could be different, but it really isn't THAT different from a "Pure" OO language.

Alright, it's not "completely" different, which is why I said it was a tad different. C++ is basically C with object oriented paradigm added. It doesn't strictly enforce OO paradigm and allows you to do things that would violate that paradigm. In contrast, Java and C# were created, from the ground up, to be an OO language and will not allow you to deviate from it. Bottom-line, yes you are correct, you can do a lot of the things in C++ that you can do in C# and it's really up to the programmer to keep the OO implementation consistent.
 

sao123

Lifer
May 27, 2002
12,648
201
106
Originally posted by: XxPrOdiGyxX
Originally posted by: Cogman
Originally posted by: XxPrOdiGyxX
Originally posted by: aznium
memory management and c-style strings

What he said. You must be MUCH more careful because of pointers. Since there is no garbage collection you have to worry about memory leaks and such. Also, it's not a pure OO language so you will find it's a tad different when you try to develop using an OO paradigm. As far as things like syntax; you should pick it up fairly quickly since Java resembles it.

I really don't know what you mean by "It isn't a pure OO language". Is it that it doesn't force you to use objects exclusively? I mean really, C++ has all the features that any other OO language uses, and very little forces you to do anything procedurally in it other then your desire to do things procedurally.

Ok, so you have a main function, but if you really wanted, that could easily be the only function in your entire program.

I guess if you mean that not all predefined functions for C++ are OO based, then yeah, I guess that could be different, but it really isn't THAT different from a "Pure" OO language.

Alright, it's not "completely" different, which is why I said it was a tad different. C++ is basically C with object oriented paradigm added. It doesn't strictly enforce OO paradigm and allows you to do things that would violate that paradigm. In contrast, Java and C# were created, from the ground up, to be an OO language and will not allow you to deviate from it. Bottom-line, yes you are correct, you can do a lot of the things in C++ that you can do in C# and it's really up to the programmer to keep the OO implementation consistent.


Its also worth noting that C# and java are both interpreted laguages requiring a runtime... IE a software layer running between your code and the hardware.
C++ compiles directly into binary code, running directly on hardware resources.
 

oog

Golden Member
Feb 14, 2002
1,721
0
0
Originally posted by: sao123
Its also worth noting that C# and java are both interpreted laguages requiring a runtime... IE a software layer running between your code and the hardware.
C++ compiles directly into binary code, running directly on hardware resources.

both .net and java compile to native code after an intermediate form (IL or byte code).
 

sao123

Lifer
May 27, 2002
12,648
201
106
Originally posted by: oog
Originally posted by: sao123
Its also worth noting that C# and java are both interpreted laguages requiring a runtime... IE a software layer running between your code and the hardware.
C++ compiles directly into binary code, running directly on hardware resources.

both .net and java compile to native code after an intermediate form (IL or byte code).

According to micrsoft it isnt. >net is JIT compiled by the framework, thus having a slight performance disadvantage over non .net c++.then why does java require the JVM? and why does .not require the .net run time?
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Originally posted by: sao123
Originally posted by: oog
Originally posted by: sao123
Its also worth noting that C# and java are both interpreted laguages requiring a runtime... IE a software layer running between your code and the hardware.
C++ compiles directly into binary code, running directly on hardware resources.

both .net and java compile to native code after an intermediate form (IL or byte code).

According to micrsoft it isnt. >net is JIT compiled by the framework, thus having a slight performance disadvantage over non .net c++.then why does java require the JVM? and why does .not require the .net run time?

C# and Java may optionally be compiled to native after translation and management. In the case of Java, that is a function of the JVM: JIT compilation. In simpler JVMs, the bytecode is merely interpreted. I would imagine .NET is in a similar boat, though I'm not entirely sure on .NET's architecture.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
13
81
www.markbetz.net
Originally posted by: degibson
Originally posted by: sao123
Originally posted by: oog
Originally posted by: sao123
Its also worth noting that C# and java are both interpreted laguages requiring a runtime... IE a software layer running between your code and the hardware.
C++ compiles directly into binary code, running directly on hardware resources.

both .net and java compile to native code after an intermediate form (IL or byte code).

According to micrsoft it isnt. >net is JIT compiled by the framework, thus having a slight performance disadvantage over non .net c++.then why does java require the JVM? and why does .not require the .net run time?

C# and Java may optionally be compiled to native after translation and management. In the case of Java, that is a function of the JVM: JIT compilation. In simpler JVMs, the bytecode is merely interpreted. I would imagine .NET is in a similar boat, though I'm not entirely sure on .NET's architecture.

It is similar. .Net code compiles to CIL (Common Intermediate Language), which is a sort of object-oriented pseudo-assembler. That is what gets stored in the assembly package. At runtime it is JIT precompiled to native and placed in an object cache, where it will stay as long as it is needed. You can also force direct compilation to native if you don't care about portability.

 

oog

Golden Member
Feb 14, 2002
1,721
0
0
Originally posted by: sao123
Originally posted by: oog
Originally posted by: sao123
Its also worth noting that C# and java are both interpreted laguages requiring a runtime... IE a software layer running between your code and the hardware.
C++ compiles directly into binary code, running directly on hardware resources.

both .net and java compile to native code after an intermediate form (IL or byte code).

According to micrsoft it isnt. >net is JIT compiled by the framework, thus having a slight performance disadvantage over non .net c++.then why does java require the JVM? and why does .not require the .net run time?

.net is always compiled down to native code by the JIT compiler. the runtime itself is responsible for things like code access security, JIT compilation, garbage collection, and other similar things, but the net result is that you're running native code. you are interacting with a memory manager, but that's one of the tradeoffs you're making.
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Originally posted by: Markbnj
Originally posted by: degibson
Originally posted by: sao123
Originally posted by: oog
Originally posted by: sao123
Its also worth noting that C# and java are both interpreted laguages requiring a runtime... IE a software layer running between your code and the hardware.
C++ compiles directly into binary code, running directly on hardware resources.

both .net and java compile to native code after an intermediate form (IL or byte code).

According to micrsoft it isnt. >net is JIT compiled by the framework, thus having a slight performance disadvantage over non .net c++.then why does java require the JVM? and why does .not require the .net run time?

C# and Java may optionally be compiled to native after translation and management. In the case of Java, that is a function of the JVM: JIT compilation. In simpler JVMs, the bytecode is merely interpreted. I would imagine .NET is in a similar boat, though I'm not entirely sure on .NET's architecture.

It is similar. .Net code compiles to CIL (Common Intermediate Language), which is a sort of object-oriented pseudo-assembler. That is what gets stored in the assembly package. At runtime it is JIT precompiled to native and placed in an object cache, where it will stay as long as it is needed. You can also force direct compilation to native if you don't care about portability.

So CIL ~= bytecode, eh?

Portability? Are there .NET environments for non-windows platforms?
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Originally posted by: degibson

So CIL ~= bytecode, eh?

Portability? Are there .NET environments for non-windows platforms?

Mono is a .NET platform for Linux.
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Originally posted by: Crusty
Originally posted by: degibson

So CIL ~= bytecode, eh?

Portability? Are there .NET environments for non-windows platforms?

Mono is a .NET platform for Linux.

Neat! I see its a Novell project. Thanks Crusty!
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |