Fog Creek Software
Discussion Board




Java guide for C++ code jockeys?

Need one ASAP.  Printed book or online reference, I don't care as long as I can get my hands on one quickly.

Suggestions?

Mitch & Murray (from downtown)
Tuesday, August 26, 2003

Thinking in Java.

Online http://www.mindview.net/Books/TIJ/

shiggins
Tuesday, August 26, 2003

When I did some Java, the place I went was simply the Sun web site.  It is comprehensive, at least.

I don't know if there is anything specifically directed at C++ users, but I don't really see why that should matter.  If you know C++, Java is not going to a huge stretch language-wise.

Andy
Tuesday, August 26, 2003

Java in a Nutshell is good.  But what you'll need most is the API documentation, and that's freely downloadable from Sun.

Brian
Tuesday, August 26, 2003

Ditto "Thinking in Java".  Eckel is the author I understand the best...

Grumpy Old-Timer
Tuesday, August 26, 2003

My vote is Thinking in Java too.  Add it to your list of must reads and you make a smoother transition and a better developer.

I was also  a C++ code jockey which ties right into his Think In C book too.

Mike Gamerland
Tuesday, August 26, 2003

The first edition of "Java In Plain English" had a guide to Java for C++ programmers. The book had more than a few errors, and was by no means spectacular, but the C++ to Java parts were quite useful (and in an odd way the errors were helpful). I believe a 2nd edition has since been published, not sure if they kept the C++ features.

According to info on Amazon, they C++ stuff is still there:

http://www.amazon.com/exec/obidos/tg/detail/-/0764535390/qid=1061956794/sr=1-1/ref=sr_1_1/102-7362235-3537702?v=glance&s=books

Walter Rumsby
Wednesday, August 27, 2003

Crash course in java for the C++ programmer.

Java is dumbed down programming language compared to C++ which is often advantageous.

1) no templates

2) Object References are just referenced counted pointers...  If you are trying to remember the semantics of a Reference passed to a function, just think, this is the same as passing a pointer by value.  Most people say, "there are no pointers in Java."  I think it is easier to say everything is a reference counted pointer.

3) Threading model is virtually identical to POSIX.  If you know p threads you nearly done.

4) All casts are pretty much dynamic casts and fairly expensive.  Old C style cast syntax. 

5) you are required to specify which exceptions your functions throw, and catch them in calling code.

6) All code is in the header file which actually the Java file.

7) the compiler tries to figure out dependencies for you, but often fails.

8) CLASSPATH environment variable.  Most annoying practical thing about Java.  Must be set to point to all code you will be executing.  Seems like you are constantly modifying this.

9) Strings are a strange hybrid object.  The generally have the semantics as other objects, except syntax like: "mystring".length() is legal.  The compiler resolves "my string" to an object of type String.

10) everything inherits  from Object. 

11) Most collections contain Objects which means you are dynamic casting all the time, unlike the STL.

12) There are no stack based objects.  This simplifies things since there are no assignment operators or temporaries.  But also slows things down...

13) There are fundamental types such int and float to improve performance.

14) Many operations on fundamental types are provided by wrapper classes such as Integer.  If you want to pass a basic type by reference it must be wrapped in one of these classes.

15) Destruction is not deterministic, so while there is "finalize" which looks like a destructor you can not depend on it being called in a timely manner.

16) The run time supports reflection and you can query an object for the names of its methods and parameters.  In practice I don't use this very often.  Often used for marshalling data and is used by the beans spec.

17) The rest of it is libraries, libraries, libraries.

christopher baus
Wednesday, August 27, 2003

You can try this tutorial on the IBM DeveloperWorks site.
www-106.ibm.com/developerworks/edu/j-dw-ijcc++p-i.html
Worked for me :)

Andrea
Wednesday, August 27, 2003

When I first started out in Java, I got a hold of the aforementioned "Java in a Nutshell" and "Java Programming: Making the Move from C++" available here.

http://www.amazon.com/exec/obidos/ASIN/1850329222/102-2427913-7184137

Avrom Finkelstein
Wednesday, August 27, 2003

I've never liked any of the 'Thinking in..." books. But at least you can download them for free. That accounts for their popularity I think.

Clutch Cargo
Wednesday, August 27, 2003

Good overview, Christopher.  However one minor quibble -- no Java VM that I know of uses reference counting, due to the problems it has with circular references.  The Sun VM uses mark and sweep.

Also another difference between C++ and Java: there is no multiple *class* inheritence; everything is single-inheritence and inherits from Object.  However, Java has separate semantics for interface inheritence, and you CAN inherit multiple interfaces.

Alyosha`
Wednesday, August 27, 2003

Good point.  Thanks for correcting me on the GC.  I guess from a C++ programmer's perspective I think it is easier to think in terms of reference counting, but of course VM uses an async sweep procedure.

Other comments.

o All functions are virtual functions.

o Pure virtual base classes are implemented using interfaces and not = 0 type syntax.

o No enums

o No structs

christopher baus
Wednesday, August 27, 2003

"All functions are virtual functions" ... except if they are static.  =-)

Alyosha`
Wednesday, August 27, 2003

"... unless they are static"

Or final.

jeffh
Thursday, August 28, 2003

Of course from Java 1.5 there is a form of generic programming available.  I think this feature will take off quite quickly.

One thing not mentioned is that Java doesn't have operator overloading (although they fudged it for String concatenation).

For the C++ programmer, the obvious big differences are the use of a virtual machine vs native code, and garbage collection

Apart from those, I think the two 2 killer features that make Java stand out are interfaces and built in support for threading.

cheers,
Peter

Peter McKenzie
Thursday, August 28, 2003

I'm not sure if interfaces are a killer feature.  We've always had pure virtual base classes in C++.  Java is more restrictive, as far as inheritence is concerned which I personally like.

christopher baus
Thursday, August 28, 2003

*  Recent Topics

*  Fog Creek Home