Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm tasked with teaching an accelerated university special topics course in Java for programmers with many years of experience in C/C++.

What sort of medium-length (1-2 hours max) assignments would you give, that would exercise the student's basic Java skills without seeming like an assignment one would give to someone learning Java as a first language? (The idea is to provoke thought about the difference between Java vs. C++ rather than insult the student with ridiculously simple programming in general.)

To clarify, the entire course is not 1-2 hours -- it will be 4 hours on the first day and 7 hours on the second and third day, for two weeks, for a total number of contact hours of 36 hours. This is comparable to a standard college course's number of hours, just dramatically compressed.

share|improve this question
24  
WHY?!!! Why would anyone want to take STRONG C++ developers and turn them into Java developers? They are already at home with tough concepts like pointers, indirection, efficient memory management, OOP, interfaces, developing cross platform and thousand other things, they can write anything. Java is not going to make them any better, no good can come out of it! –  Coder Jul 29 '12 at 21:50
5  
Do you have a syllabus? It's hard to suggest problems without knowing which topics you intend to cover. Are you covering the class loader? C++ RAII and Java try/finalize? Reflection? Java constructors and overridden methods vs. C++ constructors and virtual methods? –  kevin cline Jul 29 '12 at 21:55
2  
@gjbbaanb: GC does make many things much easier, but not all things. –  kevin cline Jul 30 '12 at 1:02
2  
@TomAnderson: C++ Templates generate code. Generics don't. It's hard to think of something that can be done with Java generics that isn't trivial with C++ templates. –  kevin cline Jul 30 '12 at 1:03
2  
+1 for a real homework question with meaningful value! –  GlenH7 Jul 30 '12 at 2:05

6 Answers 6

Throughout the course you could create a Java compiler in Java that outputs C/C++ code and creates a working executable.

You can give them a framework that handles all the basic stuff like:

  • Reading the files
  • Interfacing with GCC
  • Testing framework (could be an assignment)
share|improve this answer
1  
This would be an interesting problem in general, but well outside of the scope of 1-2 hours as per the original question. Thanks though! –  David Pfeffer Jul 29 '12 at 21:34
1  
As well, it seems like the provided framework would contain much of the core language differences. Building the compiler itself wouldn't differ all that much between Java and C++, at least algorithmically. –  David Harkness Jul 29 '12 at 23:02

I suggest you choose an assignment where one will need some dynamic sized arrays/vectors, since this will demonstrate one of the most important differences between C/C++ and Java: memory management. Things like

Another idea is to let them implement something like a linked list, which will show them the differences between the way pointers work in C/C++ on one hand, and object references in Java on the other hand.

However, you probably do not just want to focus only on the language differences, but also on the standard library differences. A text file parsing assignment, which forces one to use file stream and string operations and something like regular expressions would surely show a lot of differences between Java and C/C++.

If you have more time, and you are going to teach some GUI programming basics, you could also add some simple GUI programming task, like programming a small visualization for one of the suggested problems above. It should be obvious that they will learn here things from the Java world which are different from the C++ world.

share|improve this answer
    
Game of Life is a great way to learn high level OOP languages. And if you want them to learn some GUI rogramming too it's a really fun challenge (and causes some good competition). –  Ziv Aug 3 '12 at 11:53
    
+1 for Linked List. I think it's a good way to really demonstrate how Java handles references where C++ relies on more explicit pointer arithmetic (for better or worse). Also shouldn't take more than an hour or two to implement and test. –  KChaloux Sep 5 '12 at 14:59

Main point is to concentrate on differences.

I would advise to look at several resources where "Java programming for C/C++ developers" is a topic.

The Java programming for C/C++ developers is a quick reference guide to developers who have experience with C/C++ programming language and would like to learn Java programming concepts by comparison.

To me Java is a nice, friendly and relaxing sandboxed version of C++. In Java I don't have to worry about GPFs, memory leaks or messing with pointers. However, don't let that confuse you, there are still plenty of opportunities to screw up royally, and they're sometimes even nastier to detect.

Just take the leap and if you have the instinct, it shouldn't be a problem. There is a book Thinking in Java 4th edition that has chapters on concurrency and generics that you will want to read. It explains why Java generics are different from C++ templates for instance.

Effective Java is another good book. It is written by the guy who designed, implemented, and maintained many of the Java platform libraries.

Java Concurrency in Practice is also a very good book to read once you get a chance.

share|improve this answer
    
The first link (Java ... for C/C++ ...) appears to be wrong. –  kevin cline Jul 29 '12 at 21:56
    
@kevincline, thanks for pointing out, it should be fine now –  Yusubov Jul 29 '12 at 22:08
    
nastier to detect.... so C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off; ... and Java lets you spray bullets in the general direction of all your users :) –  gbjbaanb Jul 30 '12 at 1:01
2  
@gbjbaanb: Actually, no, because in modern Java, you just automatically download forty-seven jars from Maven Central which spray bullets in the general direction of all your users for you. Or use Spring. –  Tom Anderson Jul 30 '12 at 8:02

Given that they are seasoned C++ developers, throw some real world problems at them like building a webpage scraper, a spellchecking program, a flashcard GUI with options to input and display various cards with quizzes, a course scheduling system that accounts for prerequisites, a summary statistics program perhaps with a polling system. These are mostly well understood programs with clear cut requirements but require programming ability beyond that of a beginner. You could incorporate JEE if you wanted to provide some Java web experience.

Finally you could utilize a few project euler problems as a quick start to the language.

share|improve this answer
    
+1 - It is ridiculous to teach a language at the university level. Give them an assignment, tell them to use Java and any specific libraries you want them to use. University students should be able to learn the language on their own. –  Dunk Aug 1 '12 at 17:30

I'd suggest implementing a data structure with a few associated algorithms.

Reasons:

  • It's mostly pure Java coding, so your C++ guys won't waste too much time having to look up APIs or additional libraries
  • The algorithms can be fairly fun / challenging even for quite experienced programmers. Maybe give a prize for the fastest implementation....
  • You can pick something with cyclic references so that your C++ developers get some experience relying on the garbage collector / seeing the benefits of the same
  • You can optionally get them to implement one of the Java collections interfaces (e.g. java.util.Collection) or extend from an abstract base class. This will be a good introduction to Java-style interfaces and OOP.
  • There are plenty of good extensions, e.g. creating an immutable verson, adding concurrency safety, etc.
share|improve this answer

I'll add that the JVM is a very different beast. It focuses on:

  • Runtime optimisations/behaviour (Hotspot) leading to...
  • Runtime compilation (JIT)

and of course

  • Runtime memory management (GC)

A C/C++ programmer will greatly benefit rom understanding how those mechanisms work (and in fact will understand them all the better given their backgrounds).

So exercises that get them to explore those characteristics will make them far better Java programmers.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.