go_away

Author Topic: JAVA -> C++  (Read 1264 times)

0 Members and 1 Guest are viewing this topic.

Offline robonerd137Topic starter

  • Jr. Member
  • **
  • Posts: 18
  • Helpful? 1
JAVA -> C++
« on: July 03, 2013, 11:12:53 AM »
I currently only know how to program in JAVA. How important is it that I learn how to program in C++. Is C++ very different from JAVA? Can someone give me a good resource to learn C++ after JAVA.

Offline newInRobotics

  • Supreme Robot
  • *****
  • Posts: 1,015
  • Helpful? 48
  • N.I.R.
Re: JAVA -> C++
« Reply #1 on: July 04, 2013, 02:23:53 AM »
How important is it that I learn how to program in C++.
For us it's not important at all  ;D However for whatver You want to do - it might be. What do You want to do? Why do You consider it?

Is C++ very different from JAVA?

Can someone give me a good resource to learn C++ after JAVA.
c++ tutorial (Google search)
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian W

Offline mviljamaa

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Re: JAVA -> C++
« Reply #2 on: July 04, 2013, 05:13:04 AM »
I currently only know how to program in JAVA. How important is it that I learn how to program in C++.

It depends on what you do. Some software undoubtedly requires C++, because it's written in C++. But apart from having to write C++, because the software is written in C++, I personally would try to avoid it, because of the unnecessary complexity of the language, and focus on using C and high-level languages that interface with C (e.g. Python, Objective-C, Haskell etc.). Why? Because you get the both worlds of simplicity (a higher level language that interfaces with C) and performance (C).

Is C++ very different from JAVA?

As both are primarily imperative and object-oriented, no it isn't. It's just considerably more complicated, because there are way more language constructs in C++ than in Java.

Offline jwatte

  • Supreme Robot
  • *****
  • Posts: 1,343
  • Helpful? 81
Re: JAVA -> C++
« Reply #3 on: July 04, 2013, 01:21:32 PM »
If the Java you know is J2EE style, with AbstractFactoryHelperBeans, then C++ is likely to be simpler :-)

The main difference is that, in C++, like in C, you have direct control over data structure layout in memory. This is great for when you need to fit in small spaces, but it's annoying when you end up using a pointer wrong and smashing some random piece of memory where some other part of your program lives.
Also, in C++, you have to call delete on each object exactly once. Forget it, and you leak memory. Do it more than once, and you crash.

Also, C++ (and C) has value objects/structs, which Java does not. In java, pretty much everything is a heap/reference object.

If you're doing embedded systems with small amounts of memory (Arduino, PIC, raw AVR, MSP430, etc) then C and a carefully chosen subset of C++ is likely your best bet; Java is too big to fit comfortably and will limit how much you can do on those devices. Also, don't use the heap ("new" or "malloc") at all in those small spaces; pre-allocate everything you need as static/global instances.

Offline robonerd137Topic starter

  • Jr. Member
  • **
  • Posts: 18
  • Helpful? 1
Re: JAVA -> C++
« Reply #4 on: July 15, 2013, 10:08:50 AM »
Thank you all for the excellent responses! :)

Offline hobbes

  • Jr. Member
  • **
  • Posts: 29
  • Helpful? 0
Re: JAVA -> C++
« Reply #5 on: November 23, 2013, 11:47:02 PM »
C++ is much faster compared to JAVA on the order of hundreds of times. It is much less forgiving but also much more powerful.



Offline Roman505

  • Jr. Member
  • **
  • Posts: 44
  • Helpful? 3
Re: JAVA -> C++
« Reply #6 on: November 24, 2013, 12:53:37 AM »
with great power comes great responsibility to delete()

Offline hobbes

  • Jr. Member
  • **
  • Posts: 29
  • Helpful? 0
Re: JAVA -> C++
« Reply #7 on: November 24, 2013, 02:08:22 AM »
yes, you have to delete what you create but at least the garbage collector does not hiccup and make your program pause.

Offline Roman505

  • Jr. Member
  • **
  • Posts: 44
  • Helpful? 3
Re: JAVA -> C++
« Reply #8 on: November 24, 2013, 03:18:37 AM »
with less power comes hiccoughs.






Are we all covered now? 8)

Offline jwatte

  • Supreme Robot
  • *****
  • Posts: 1,343
  • Helpful? 81
Re: JAVA -> C++
« Reply #9 on: November 24, 2013, 10:37:41 PM »
Quote
C++ is much faster compared to JAVA on the order of hundreds of times.

I can hate Java as much as the next guy, but this is simply not a true statement.

On modern servers and client machines, using modern Java VMs, Java is more like half the speed of native C++, when using the same level of tuning in implementation.

Even on very small form factors, where you can't afford to use JIT code generation or keep a code cache around, you can do better than 100:1, because many of the Java opcodes are more expressive than machine codes, and thus a "threaded interpreter" (nothing to do with threads of execution) can get to about 10:1 or so.

And when you are I/O bound, Java and C++ are equally I/O bound and thus equally slow :-)

 


Get Your Ad Here

data_list