Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Can Java Programmer Learn C++ Quickly?

Reply
Thread Tools

Can Java Programmer Learn C++ Quickly?

 
 
Tim Ward
Guest
Posts: n/a
 
      12-07-2004
"Rhino" <> wrote in message
news:d83td.17928$. ..
> 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++.

--
Tim Ward
Brett Ward Limited - www.brettward.co.uk


 
Reply With Quote
 
 
 
 
John C. Bollinger
Guest
Posts: n/a
 
      12-07-2004
Chris Uppal wrote:

> 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

 
Reply With Quote
 
 
 
 
Andy Hill
Guest
Posts: n/a
 
      12-07-2004
"Rhino" <> wrote:
>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).
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      12-07-2004
Hal Rosser wrote:
> "Rhino" <> wrote in message
> news:d83td.17928$. ..


>>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.


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.

--
James Kanze home: www.gabi-soft.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 pl. Pierre Sémard, 78210 St.-Cyr-l'École, France +33 (0)1 30 23 00 34

 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      12-07-2004
Ian T wrote:
> Rhino wrote:


>> 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++.


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.

> >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.


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.

--
James Kanze home: www.gabi-soft.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 pl. Pierre Sémard, 78210 St.-Cyr-l'École, France +33 (0)1 30 23 00 34

 
Reply With Quote
 
Ian T
Guest
Posts: n/a
 
      12-07-2004
James Kanze wrote:
> 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.

>
> > 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.

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.

>
> > 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.


Yep, second the Meyer's book.

Ian
 
Reply With Quote
 
Rene
Guest
Posts: n/a
 
      12-07-2004
James Kanze <kanze@none> wrote:
> 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é

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
Chris Smith
Guest
Posts: n/a
 
      12-08-2004
Ian T <> wrote:
> > 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.


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.

> > 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.


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
 
Reply With Quote
 
Ian T
Guest
Posts: n/a
 
      12-08-2004
Chris Smith wrote:

> 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.

>
>>>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.

>
>
> 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

 
Reply With Quote
 
Sudsy
Guest
Posts: n/a
 
      12-08-2004
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.

--
Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need suggestions to learn Java to become an Freelance programmer Nikhil BS Java 14 05-10-2010 05:19 AM
Who gets higher salary a Java Programmer or a C++ Programmer? Sanny Java 391 01-06-2010 02:48 AM
Older Programmer Looking to Learn Java on his own. len Java 8 11-24-2008 03:10 AM
.NET Programmer Needs To Learn Java scorpion53061 Java 20 09-27-2004 07:59 PM
Experienced VB programmer trying to learn Java - Which IDE is best? Bill Java 7 07-23-2004 12:12 PM



Advertisments