Can Java Programmer Learn C++ Quickly?

R

Rhino

I realize that this is not entirely a Java question but I am hoping that
some of the people reading this newsgroup are Java programmers who went on
to learn C++.

I am giving some thought to applying for some jobs that want people with
Java and C++ experience. I have been writing Java for several years and am
fluent enough that I don't have to post questions here very often. I have no
real C++ experience and not much C experience for that matter.

However, the core Java statements are "borrowed" from C and C++ has often
been called "C with classes". It seems to me that it shouldn't take very
long to get up to speed on C++ if I am already fluent with Java and have at
least some knowledge of C. Then again, I understand that Java and C++ use
classes a bit differently; for instance C++ allows multiple inheritance
while Java allows only single inheritance but allows for multiple interfaces
as compensation. I'm not sure how long it would take to get fluent with
multiple inheritance after several years with Java.

I'd be very curious to know how long it took people here who were fluent in
Java to get fairly fluent in C++ if they started with approximately the same
skills I have today.

--
Rhino
---
rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to make it
so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies." - C.A.R.
Hoare
 
F

FunkyKarma

I programmed in C++ 10+ years before programming in Java now for 5+ years.

While I think the transition from being a good object oriented C++
programmer to Java was relatively easy, I don't think that going the other
way will be quite as easy.

What working with Java will hopefully bring to the table is practice in
applying sound OO principles, and to some degree syntax. C++ and C provide
a much bigger opportunity to hang yourself especially with pointer / direct
memory manipulation.

Also, you need to be very familiar with your machine architecture to be
really good a debugger on a given platform.
 
S

Sudsy

Rhino wrote:
I'd be very curious to know how long it took people here who were fluent in
Java to get fairly fluent in C++ if they started with approximately the same
skills I have today.

I taught myself the fundamentals in a weekend. Weird stuff like templates
took a bit longer. Granted, I had seen C++ many years ago but didn't like
it as it didn't FORCE you to use object orientation. I wasn't surprised
when Forester Research suggested that some 85% of "C++" was actually
procedural C.
 
M

Martin Demberger

Hi,
I think you would be able to program in C++ in a few days. But I a C++
programer sees this code you would say: Thats not C++ thats Java.
C++-Programer have another pholosophy (don't know how to write this in
english).
You will even be able to write a simple C++ program before you can read a
difficult one. An writing a good and real C++ program would take a very lot
of time if it's not impossible.
The problem of you wouldn't be the HOW, this can be read by any book, but
the WHY NOT.
Java has a lot of good (and also a little bad) contructs in the library.
And the STL (Thats the JDK of C++) is a awfull in my opinion.
The other problem is the memory concept. But if you can handle C you will
be able to learn that very fast. It's easier than in C but you can also use
more hacks.

cu Martin

P.S. I came from Pascal over C over C++ to Java. I wrote my diploma about
C++ and Java, so I think I can write a little about those two languages.
 
R

Ryan Stewart

Rhino said:
I realize that this is not entirely a Java question but I am hoping that
some of the people reading this newsgroup are Java programmers who went on
to learn C++. [...]
I'd be very curious to know how long it took people here who were fluent
in
Java to get fairly fluent in C++ if they started with approximately the
same
skills I have today.

I've been using Java constantly for about a year and a half. I feel that I
could pass the SCJP at any time without studying in advance (an opinion
supported by some coworkers who have taken the exam). That said, a couple
months ago I picked up a good sized C++ book and read it through in a week
(with some hands-on interspersed throughout, of course). After that I felt
comfortable reading some simple and not so simple C and C++ source code and
writing my own simple little things.

If you want an eyeful, download the Quake 2 source code (C only, I believe).
If you can even begin to untangle that I'd say you're doing fairly well.

For a quick start IDE, check out Dev-C++:
<http://www.bloodshed.net/devcpp.html>

Granted I'm biased as that's the only one I've used :)
 
H

Hal Rosser

Rhino said:
I realize that this is not entirely a Java question but I am hoping that
some of the people reading this newsgroup are Java programmers who went on
to learn C++.

I am giving some thought to applying for some jobs that want people with
Java and C++ experience. I have been writing Java for several years and am
fluent enough that I don't have to post questions here very often. I have no
real C++ experience and not much C experience for that matter.

However, the core Java statements are "borrowed" from C and C++ has often
been called "C with classes". It seems to me that it shouldn't take very
long to get up to speed on C++ if I am already fluent with Java and have at
least some knowledge of C. Then again, I understand that Java and C++ use
classes a bit differently; for instance C++ allows multiple inheritance
while Java allows only single inheritance but allows for multiple interfaces
as compensation. I'm not sure how long it would take to get fluent with
multiple inheritance after several years with Java.

I'd be very curious to know how long it took people here who were fluent in
Java to get fairly fluent in C++ if they started with approximately the same
skills I have today.

I had a couple of years of Java behind me (and no C++), then went back to
school for a MS degree, and had to take a 'Data Structures' class to qualify
for the Masters program. The instructor chose C++ for the course. My Java
background saved me. The syntax is similar and OO concepts are the same (for
the most part). Watch out for pointer arithmetic and templates.
 
P

Phil Staite

In a word, no... not quickly.

That is, while you may be able to pick up on what existing C++ programs
are doing fairly quickly, authoring your own OO programs from scratch in
C++ is, well, different.

Some of it is just different syntax, from minor to maddening... Like
where you put [] in array declarations. Or the notion of separate
header and source files. Or C++'s automatic (stack) based objects
without new...

Some of it is just fundamental differences in tool sets. Someone used
to a nice slick GUI based IDE in Java will struggle with command line
gcc ;-) Similarly someone coming from say a Borland or MS C++ IDE to a
raw javac command line would struggle...

You'll miss many of the things that are built in to Java such as GUI
support, network IO, threading, and synchronization. To do those in C++
you'll have to learn platform specific APIs. (posix standards help some,
where supported of course)

You'll struggle with STL, while whole books have been written on C++ the
language, whole other books are devoted just to the STL portion.

As others have noted, you'll struggle with the power and peril of C++ -
it not only makes it possible to shoot yourself in the foot, it loads
and cocks the gun for you too. :-( Seriously though, some of the
automatic conversions and conventions in C++ will drive you nuts, little
things like integer types auto-converting to bool (oh yeah, boolean in
java!) Or C++'s rather casual attitude about catching exceptions. Or
that you get a choice in how to catch exceptions...

If you're really adventureous you'll try fun things like multiple
inheritence...and begin to appreciate Java's interface idiom...

Speaking of idioms... There's a whole different universe of C++ idioms
(at least 99% different from Java idioms)

Then there's the wonderful world of debugging...memory leaks, stray
pointers, uninitialized pointers... Oh, and the funny little thing that
in C++ base class constructors get called first, always... And the
whole virtual/non-virtual function call thing...

Wait till you first bump into trying to make a virtual function call
from a constructor or destructor...

Or when you first learn about overloaded functions, and the dreaded "xxx
hides function xxx declared in ..." warning...



So while you may be able to start reading/writing C++ fairly quickly, it
generally will take a long time to become well versed in it. By long
time I mean a year to three would not be unusual. I've been doing C++
since the dark ages, about 15 years. Thanks to the ongoing efforts of
the standardization committee and the slow pace of the tools catching up
to said standard... even us long time veterans still bump into new/odd
things. Of course, that's nothing new to Java programmers, you (we, I
do Java too) have been dealing with a much more rapidly evolving and
changing language.

I'm not trying to discourage you. In fact, I'd encourage you or anyone
else to learn at least a couple of languages. I believe it gives you a
much better perspective on the overall process of programming. I just
want you to go into this with an appreciation of what you're getting in
to. That way you're less likely to get frustrated and give up. There
is light/hope!
 
C

Chris Smith

Rhino said:
I'd be very curious to know how long it took people here who were fluent in
Java to get fairly fluent in C++ if they started with approximately the same
skills I have today.

I don't have that particular experience (I had been working in C++ for
some time before Java existed), but I can offer a comment. Learning the
basics of any new language, for a competent developer who's already got
a few behind them, ought to take something on the order of days. What
takes a lot longer (meaning months) is becoming effective in that
language and surrounding environments. Unfortunately, the latter task
is difficult to even approach unless you've got some kind of non-trivial
project to work on, and that comes from using the language for real
work.

So yeah, I don't doubt you can learn the C++ language fairly quickly,
but how productive will you be once the Java standard API is nowhere in
sight and you're working with something called Qt or MFC instead? And
will you write good code, or code that reads like the transliteration of
Java into C++ that it is? That's the main difficulty here. You may
want to obtain more information from this perspective employer on what
level of C++ experience they are looking for.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
C

Chris Uppal

Rhino said:
I'd be very curious to know how long it took people here who were fluent
in Java to get fairly fluent in C++ if they started with approximately
the same skills I have today.

I haven't gone from Java to C++ (I went the other way) but I think I can add
something useful to this thread. The following is only personal opinion, of
course, but it is backed by quite a bit of experience of working with C++
programmers of various grades.

C++ is large, complicated, and /DIFFICULT/. There is no way that you can learn
it quickly, no matter what your background. If you are intelligent, a good
programmer, and are interested in understanding the details of programming
languages, then you can probably become a very good C++ programmer in as little
as three years. If not then it'll take a little longer...

I would say that its a rare programmer who can (or should !) write C++ code
without supervision with less than a year's (fulltime) practise.

Obviously, people don't /really/ take that long to become "productive" -- what
happens is that they learn a cut-down approximation to C++, and then use that.
If they are well-taught (or lucky) then the various misconceptions and
misunderstanding they have will not be /too/ serious, and they'll be able
(usually) to write code that works, and modify existing code without (usually)
introducing subtle bugs.

The difference from languages like, say, Java is that misunderstand C++ is
often dangerous. A "fairly fluent" C++ programmer is quite likely to be
introducing bugs without knowing it (even when using features that they think
they understand), whereas a "fairly fluent" Java programmer is quite likely to
be writing reasonable Java, even if there are things about the language that
they haven't yet learned.

But what you are /really/ asking isn't about learning to write good C++, its
more about knowing C++ well enough to claim that you know the language at
interview ;-) How long that will take will depend on how honest you want to
be, and on what you think /their/ requirements are. It's certainly possible to
learn enough in a week or so (fulltime) that you can easily pass simple
programming tests.

BTW, I know this post sounds like a criticism of C++, and indeed it /is/ a
criticism of C++, but I wouldn't want to give the impression that I dislike the
language. It's a lot of fun to program in C++, there are so /many/
intellectual challenges. I just don't think its a particularly good choice for
writing programs in...

-- chris
 
I

Ian T

Rhino said:
I realize that this is not entirely a Java question but I am hoping that
some of the people reading this newsgroup are Java programmers who went on
to learn C++.

I am giving some thought to applying for some jobs that want people with
Java and C++ experience. I have been writing Java for several years and am
fluent enough that I don't have to post questions here very often. I have no
real C++ experience and not much C experience for that matter.

However, the core Java statements are "borrowed" from C and C++ has often
been called "C with classes".

Having programmed C++ for ~3years and now learning Java, I can say that
C++ (and C ) has some nasties that takes years to completely get your
head around.

First of all: memory management. You've got to follow that object
reference (and mallocs) everywhere it goes and anticipate every
situation where it might be stranded. A good bounds checker will help,
but still, it's something that you never think about with Java (garbage
collector), but you should always be thinking about in C++.

Second: Pointers. References (&), de-references(->), points(*().),
pointer(*), pointer arithmetic, char arrarys, memory buffers, and so on.
Learning pointers is the hardest part of C++, and once you have a good
handle on that, some of the other things come easier too.

Third: Null terminated character arrays. Useful, but often dangerous as
you can kill the null terminator and have string functions wander off
into other parts of the stack or the heap. Also, C style string
functions are the source of many buffer overflow exploits. For most
string handling <basic string> is your friend, but null terminated
character arrays have enormous flexibility.

Fourth: Learn the containers in STL as soon as practically possible,
especially said:
It seems to me that it shouldn't take very
long to get up to speed on C++ if I am already fluent with Java and have at
least some knowledge of C.

Good luck with that ;). Probably *the* best book (IMNSHO) for starting
out with C++ is Dietel & Deitel C++ How to Program. It's as dense as a
chocolate pudding, but it has all the bits.

Ian
 
T

Tim Ward

Rhino said:
I realize that this is not entirely a Java question but I am hoping that
some of the people reading this newsgroup are Java programmers who went on
to learn C++.

The other way round is easier, as others have said, because C++ is a vastly
more complex language than Java. (This was deliberate; many of the nasties
in C++ come from retaining backwards compatibility with C, without which C++
would have been just-another-OO-language-that-nobody-used, whereas Java was
designed from scratch with all the difficult bits deliberately omitted.)

Yeah, sure, learning the syntax differences is trivial and should take an
afternoon (apart from templates, and of course the various obscurities that
nobody uses such as pointer-to-member and stuff like that).

If you've never done any real programming and have no idea what a computer
is (ie if you've never done any machine code or assembler programming) then
you may have trouble getting your head round pointers and references and
suchlike; I've never seen why people find this difficult, but it's a fact
that some do.

On the memory management ... C++ is one of the languages that thinks "memory
management is far too important to leave to the compiler" in contast to Java
which thinks that "memory management is far too important to leave to the
programmer". But once you've realised what you can do with proper
destructors ...

Anyway, the language is the smaller part of the problem, you'll have entire
sets of basic C libraries, STL, GUI class libraries etc to learn, depending
on the platform and toolkit. Some of these are harder and/or bigger and/or
weirder than others.

Virtual function calls in constructors ... oh yes, this is one that is
definitely wrong in Java, whatever you think of the C++ interpretation. If
you're going to end up using both languages on a daily basis it may be best
to ensure that you never call a virtual function in a constructor! On the
other hand throwing exceptions from constructors is not a problem in Java
but is well worth avoiding in C++.
 
J

John C. Bollinger

Chris said:
It's a lot of fun to program in C++, there are so /many/
intellectual challenges. I just don't think its a particularly good choice for
writing programs in...

Now there's one for the quote file. :)


John Bollinger
(e-mail address removed)
 
A

Andy Hill

Rhino said:
I realize that this is not entirely a Java question but I am hoping that
some of the people reading this newsgroup are Java programmers who went on
to learn C++.

I am giving some thought to applying for some jobs that want people with
Java and C++ experience. I have been writing Java for several years and am
fluent enough that I don't have to post questions here very often. I have no
real C++ experience and not much C experience for that matter.

However, the core Java statements are "borrowed" from C and C++ has often
been called "C with classes". It seems to me that it shouldn't take very
long to get up to speed on C++ if I am already fluent with Java and have at
least some knowledge of C. Then again, I understand that Java and C++ use
classes a bit differently; for instance C++ allows multiple inheritance
while Java allows only single inheritance but allows for multiple interfaces
as compensation. I'm not sure how long it would take to get fluent with
multiple inheritance after several years with Java.

I'd be very curious to know how long it took people here who were fluent in
Java to get fairly fluent in C++ if they started with approximately the same
skills I have today.
The basic languages are quite similar -- you shouldn't have any real trouble
*reading* c++ code from the get-go. The multiple-inheritance thing isn't much
of a bugaboo... it's not used all that much anyhow. The big problems are that
(1) The libraries are very different between java and c++, and learning to
"think" in terms of the STL takes time (2) The garbage collector in java lets
you get sloppy with memory management...no such luck in c++

At a rough guess, it'd take you about 6 months, working with c++ every day, to
become what I'd consider "fluent" in c++ (i.e., when confronted with a design
problem, be able to sketch out the system design and bang out the code without
having to consult the manual every fifteen minutes). If the job is mostly
maintenance programming, then that's a horse of a different color -- you should
be able to do useful work almost immediately (i.e., you can figure out c++ while
you're figuring out the existing system and the existing set of development
tools).
 
J

James Kanze

Hal said:
interfaces
I had a couple of years of Java behind me (and no C++), then went back to
school for a MS degree, and had to take a 'Data Structures' class to qualify
for the Masters program. The instructor chose C++ for the course. My Java
background saved me. The syntax is similar and OO concepts are the same (for
the most part). Watch out for pointer arithmetic and templates.

I'd say that the most important thing he will have to learn is to feel
comfortable with value semantics. You can write an awful lot of C++
without pointer arithmetic, and the most essential templates are
provided for you. But you start declaring everything as a pointer, and
using new even when the actual scope is local, and you'll stick out as
someone who doesn't understand the C++ idiom.

Note too that writing a good, robust value oriented class is something
that a Java programmer will not be familiar with either (for the obvious
reason). Once you get beyond the really basics, read Scott Meyers.

Well written C++ isn't necessarily difficult, but it is different from
Java. And while poorly written code is poorly written code in any
language, C++ does seem to have a particular gift for encouraging it.
 
J

James Kanze

Ian said:
Rhino wrote:
Having programmed C++ for ~3years and now learning Java, I can say that
C++ (and C ) has some nasties that takes years to completely get your
head around.
First of all: memory management. You've got to follow that object
reference (and mallocs) everywhere it goes and anticipate every
situation where it might be stranded. A good bounds checker will help,
but still, it's something that you never think about with Java (garbage
collector), but you should always be thinking about in C++.

I've never found memory management to be a great problem in C++. And in
the doubtful cases, you use some sort of smart pointer. It's a far cry
from having garbage collection, and it IS one more thing you have to
think about, but since at the conceptual level, you have to be concerned
with lifetime of object issues anyway, it usually ends up to be just one
more implementation detail. A bit of extra work, but not something
difficult to get your head around.
Second: Pointers. References (&), de-references(->), points(*().),
pointer(*), pointer arithmetic, char arrarys, memory buffers, and so on.
Learning pointers is the hardest part of C++, and once you have a good
handle on that, some of the other things come easier too.

Pratically, except for the absence of garbage collection, I don't seem
much difference between C++ pointers and Java references. You can do
more things with C++ pointers, and if you do, it can become difficult,
but you don't normally worry about things like pointer arithmetic unless
you are writing low level software, like a garbage collector.
Third: Null terminated character arrays. Useful, but often dangerous as
you can kill the null terminator and have string functions wander off
into other parts of the stack or the heap. Also, C style string
functions are the source of many buffer overflow exploits. For most
string handling <basic string> is your friend, but null terminated
character arrays have enormous flexibility.

It's been ages (something like fifteen years) since I've used a null
terminated character string in C++ other than at a C interface. In
fact, if someone starts talking about null terminated character strings
in C++, I pretty much take it as a sign that he doesn't know C++.
Fourth: Learn the containers in STL as soon as practically possible,
especially <map> and <list>.

Regretfully, I'll agree. IMHO, the library is a disaster in C++, but it
is very *in* to vault the STL. In practice, I'd say that you do have to
know the tradeoffs with regards to the containers (vector, deque and map
are the ones I use most often -- almost never list). On the other hand,
I've found very little use for most of the algorithms in practical code.
Good luck with that ;). Probably *the* best book (IMNSHO) for starting
out with C++ is Dietel & Deitel C++ How to Program. It's as dense as a
chocolate pudding, but it has all the bits.

Once the basic syntax is mastered, I'd strongly recommend Scott Meyers'
three books. The first one ("Effective C++"), particularly, addresses a
number of classical issues that you just have to know.

Don't forget that C++ makes intensive use of value semantics. Which
means that you have to decide whether your class should have value
semantics or not, up front. And a class implemented with value
semantics doesn't look like one with reference semantics -- one with
reference semantics often ends up looking very much like a class in Java
(except that we generally declare the copy constructor and the
assignment operator private, so that it doesn't accidentally get used as
if it has value semantics); a class with reference semantics is a horse
of a different color -- you have to understand the difference between
initialization and assignment, for example.
 
I

Ian T

James said:
I've never found memory management to be a great problem in C++. And in
the doubtful cases, you use some sort of smart pointer.

Right, but it's not something a Java (or VB) programmer would have
thought about. So for you it's no problem, but the OP asked the question
from the point of view of someone learning the language.
It's a far cry
from having garbage collection, and it IS one more thing you have to
think about, but since at the conceptual level, you have to be concerned
with lifetime of object issues anyway, it usually ends up to be just one
more implementation detail. A bit of extra work, but not something
difficult to get your head around.

No so much difficult as unforgiving.
Pratically, except for the absence of garbage collection, I don't seem
much difference between C++ pointers and Java references. You can do
more things with C++ pointers, and if you do, it can become difficult,
but you don't normally worry about things like pointer arithmetic unless
you are writing low level software, like a garbage collector.

IIRC, the containers use pointer arithmetic for iterators.
It's been ages (something like fifteen years) since I've used a null
terminated character string in C++ other than at a C interface. In
fact, if someone starts talking about null terminated character strings
in C++, I pretty much take it as a sign that he doesn't know C++.

As you don't offer up your alternative, I'll just take that as a
personal slur.
Regretfully, I'll agree. IMHO, the library is a disaster in C++, but it
is very *in* to vault the STL.
The OP mentioned jobs that ask for C++ experience. Often that means that
they have an existing code base, and often the programmer who proceeded
you used STL.
In practice, I'd say that you do have to
know the tradeoffs with regards to the containers (vector, deque and map
are the ones I use most often -- almost never list). On the other hand,
I've found very little use for most of the algorithms in practical code.
I like the associative containers for parsing lvalue,rvalue pairs into.
Once the basic syntax is mastered, I'd strongly recommend Scott Meyers'
three books. The first one ("Effective C++"), particularly, addresses a
number of classical issues that you just have to know.

Yep, second the Meyer's book.

Ian
 
R

Rene

James Kanze said:
Well written C++ isn't necessarily difficult, but it is different from
Java. And while poorly written code is poorly written code in any
language, C++ does seem to have a particular gift for encouraging it.

Ever seen perl code ? :)

CU

René
 
C

Chris Smith

Ian T said:
IIRC, the containers use pointer arithmetic for iterators.

You're half right; it's not pointer arithmetic, but operator overloading
is used to make it look the same as pointer arithmetic looks in typical
C code. IMHO, this is far more confusing than pointer arithmetic ever
was, but it's still not prohibitive to understand. Devoting months to
getting it is, frankly, ludicrous.
As you don't offer up your alternative, I'll just take that as a
personal slur.

I think it pretty much goes without saying. C++ has a std::string class
(actually a template specialization rather than a class per se, but
that's immaterial). You should use it if you're writing C++.

#include <string>

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
I

Ian T

Chris said:
IMHO, this is far more confusing than pointer arithmetic ever
was, but it's still not prohibitive to understand. Devoting months to
getting it is, frankly, ludicrous.
Please point out where I said it would take months to 'get' pointer
arithmetic.
I think it pretty much goes without saying. C++ has a std::string class
(actually a template specialization rather than a class per se, but
that's immaterial). You should use it if you're writing C++.

#include <string>
So if an (for example) Winapi call required that you pass a reference to
a char array you would use

string a;
HANDLE = AnExampleAPI(a.c_str());
??
It's been a while but a seem to recall a problem with using 'string'
that way. I will go back and see if I can find the specific example.

Ian
 
S

Sudsy

Rhino wrote:
<snip>

You've received some well-considered opinions from some of the heavy-
weights on this ng. I must admit to being impressed at the care with
which their responses were crafted.
I'd just like to add to my earlier posting. While other have confirmed
the difficulty of templates and the JSTL, there were many mentions
made of the pitfalls of pointers.
I was trying out C++ coming from a C background, down to the kernel
layer, so I was already intimately familiar with the language elements
which make C so powerful. It's a double-edged sword, but single and
double indirection were second nature to me when I approached C++ for
the second time.
So I'll clarify and suggest that, if you already have a background in
C and have learned Java, "merging" the two and picking up C++ is still
something which can be done in a weekend.
You won't be an experienced practitioner, but you'll probably do better
than many who skipped Java and went directly from C to C++. As to
whether you should apply for jobs requiring C++ expertise...
It's my opinion that a good programmer can pick up what they need in
short order. It's the thought process behind the coding which makes
the difference. Just hope you can find a potential employer who agrees!
As always, YMMV.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top