views:

1120

answers:

14

I'm going to teach a Java course, and I want to show some interesting and impressive examples of simple Java programs at the first lecture to awaken student interest.

Except for the default examples which come with the JDK, what can you advise?

What possibilities of Java were you impressed by?

One more thing - students admittedly know C++ or C or (maybe even) Pascal.

A: 

This stockmarket visualization applet is pretty impressive. However, you might try explaining that a huge amount of dynamic content that they use on the web will be invisibly backed by Java servlet technology.

oxbow_lakes
+14  A: 

Are you after impressive-looking code, or impressive-looking programs?

When I've started classes with examples before, students always seem particularly fascinated with anything that uses the network. I've created some fairly trivial frameworks for network games (Hangman, BINGO, that sort of thing) that can let students start writing their own network applications very quickly — usually within a single two-hour lab period, or even a 90-minute lecture.

I've used this to generally show how logical and fun programming can be, so as not to scare off skeptical first-year programming students, but I can see the same thing working for first-time Java programmers just as well.

VoteyDisciple
I'm looking for both code and programs. Thank you for the idea with networking programming, I'll think about how to apply effectively it in my case.
Roman
This is a very good idea. Java's library is very, very good at accessing network resources, which C and Pascal are much worse at. A quick example of Java's pros vs. C's cons would be a 10 line program that loaded an image from the Internet and displayed it.
CaptainAwesomePants
Check out the last.fm API, maybe you can make a small simple client that reads the most popular bands or something like that, parse the XML and present it in a JTable on Swing or something like that... a simple twitter client, or something like that could get the students' attention, since it doesn't feel like something abstract, it's a program connecting to something they're familiar with.
Chochos
+1  A: 

I think that the most impressive things in Java is the ease and speed with which you can develop things, while at the same time not sliding into writing unstructured, disorganized code.

Among particular features, you can show them generics, reflection (warn them about its perils though), or the portability of Java code.

quant_dev
+1  A: 

IMHO, Make them understand OOP Concepts (encapsulation,Inheritance and Polymorphism).This is what Java gives me when compared to Pascal,C,C++ (ofcourse apart from the Hugh library).They are kind of weaved well in the language and the VM.

Then drive them through the process of building an application which when done in OOP-way would reap them multiple benefits.

+2  A: 

if you want to get some quick Ahh's and Oooh's write a trivial app - maybe swing - and show them how they can seamlessly start the same .jar file via java web start on 3-4 different operating systems - windows, linux, osx.

Andreas Petersson
I don't think showing them the same program 4 times is the answer here. They will loose focus quite fast.
Ula Krukar
This is only impressive after you've had to deal with porting code yourself.
windfinder
+3  A: 

While getting students excited is a good goal, be sure to do it in a way that isn't over-hyped. You say that many of your students know C or C++. Don't alienate them.

My first assignment in a java class was to read a short book written by one of the guys who created java. It was full of quasi-religious glorification of java, combined with rips on C++. It was a real turn off. Much of the glorification has turned out to be unfounded, and many of the criticisms of C++ were either unwarranted or have been improved upon as the language has evolved. Your students certainly don't believe C++ is a perfect language, but the fervored, competitive rhetoric between languages reaches silly proportions. In fact I'm expecting some of that rhetoric in comments to this post.

All I'm saying is to pick realistic examples, not rare wowsers that aren't reprentative of what they're likely to see in real world projects. Java has strengths compared to other languages, but also has weaknesses. Your students will see through an overly rosy view of the language. An overdone attempt to interest them may actually have the opposite affect.

Darryl
+2  A: 

Perhaps bring up how easy it is to unit-test your code with JUnit in Java. Boy do I wish my teachers would have mentioned that. I did'nt even know what unit-testing was. I'm a unit-test freak now, but it would have saved alot of lab-time for me knowing about unit-testing at school. Besides, any company with half a mind would want their programmers to test their code.

crunchdog
Don't you think that Unit-testing is kinda bored? And they don't even know anything about unit-testing yet. (but for all that I agree that u-tests are necessary and useful:)
Roman
Continually monkey testing your program and it still being full of bugs is really boring. Particularly if you have an algorithm problem (with a subtle bug slipped in), I think it could be the basis of a useful, mind-changing demo.
Tom Hawtin - tackline
Writing unit-test AFTER the code is finished is no fun, but writing it before in a true TDD manner is. Then you really have to think about how your code is going to be used, and what it is supposed to do before you implement it. But perhaps bringing in TDD is a little too much. How about showing them a piece of code with a not so obvious bug. Write a test to recreate that bug, and then fix the code so the test runs green? I often find this very rewarding when dealing with bugs.
crunchdog
A: 

Maybe you already need a bit of programming experience to appreciate it, but I'm pretty impressed with Jython.

CPython has a decent size codebase, and making a nearly equivalent port to yet another cross-platform system such as Java is impressive in my book. But, that probably isn't something early CS students would appreciate.

Mark Rushakoff
I'm only going to learn Jython by myself :)
Roman
+2  A: 

Try showing them open source examples of programs written in Java such as:

JNode, an OS in java: http://www.jnode.org/

Games or game libraries made with Java: http://bytonic.de/html/jake2.html http://fivedots.coe.psu.ac.th/~ad/jg/ (See the example files)

A multiplayer game can also be used to introduce the networking support in Java, http://arianne.sourceforge.net/

Just do a quick search on sourceforge.net for more programs.

Cobalt
+3  A: 

I think I'd search through C++ examples to find something that doesn't work well in that language, but works without problem in Java. Perhaps something that needs careful memory management. Perhaps something that requires a comprehensive library (although too often I see a language advocated on the basis of a specific, not actually that useful, library function).

Code that has, say, a buffer overflow which Java catches but (usually) C and C++ do not could also be enlightening.

Tom Hawtin - tackline
A: 

You can show them real-life websites created with GWT or Wicket, sites they're probably already familiar with.

"See? This is what Java can do! [with the right framework, under the right configuration, with the right wind speed and humidity condition, and provided nobody yawns next to it] " (it's important to mumble the last part, or some of your students will actually hear it and learn the awful truth...)

This page can give you some examples for GWT.

Yuval
A: 
Peter Mortensen
+3  A: 

Another possibility is to start by writing a tiny HTTP server in Java, along the lines of Tiny Java Web Server or Java Mini Web Server. There's nearly instant gratification in serving up static content from a directory, and that teaches Java file I/O and networking along with some HTTP basics. Then you can layer on more and more features as needed to expose other parts of the language, such as using Java collections to manage request and response headers. Such a project involves only a few hundred lines of code.

Update: I really like @weiji's example, especially for beginning programmers. My suggestion assumes experienced programmers who need something more apropos to their current jobs (assuming they're not working for an EA or Digital Chocolate!).

Jim Ferrans
Upvoted for pointing me to TJWS and JMWS. Both are good demonstrations of Java functionality.
Imagist
+11  A: 
weiji
Although I'm one of those responders you're probably referring to, I totally agree with your recommendations. Good suggestions.
Darryl
I'm likely another such responder, but I also agree with this. The key factor is the experience level and interests of the students. If they're relatively new to programming then small visual games are a great way to start. I helped organize a grad level J2ME-oriented games course at the USC GamePipe Lab a couple years ago and the results were extraordinary! On the other hand, if you're teaching experienced programmers you'll want an example that more closely matches their interests (especially if their companies pay for the course).
Jim Ferrans