ANU The Australian National University



____________________________________________________

[ANU] [DCS] [COMP2100/2500] [Description] [Schedule] [Lectures] [Labs] [Homework] [Assignments] [COMP2500] [Assessment] [PSP] [Java] [Reading] [Help]

____________________________________________________

COMP2100/2500
Lecture 6: More about Java

Summary

Some more about programming in Java, including Javadoc documentation, finding information in the API docs, some of the new features in Java 1.5, exceptions and exception handling with try and catch, the meaning of static (and the trick of including a main() in components for self-testing).


Javadoc

Javadoc is a way to write internal documentation in your Java code. The javadoc tool

can then read through your code and build HTML documentation just like the documentation for the standard libraries.

Here's how you do it:


API documentation

Not much to say here. Follow the link to the Sun Java 1.5 API documentation. Notice that the whole site was created automatically from the code using Javadoc.


The meaning of “static

First a little about the usual (non-static) context.

OK, so now what does static mean?

I'm new to Java, and from an Eiffel programmer's point of view, static fields and methods seem a bit strange. At the moment I think of it as basically being a way to do procedural programming in Java. Grouping related static methods and fields into a class that never has any instances (like the Math class in Java) is a bit like procedural programming in a modular language. (See Lecture 29 for what this means.)

This procedural style can be very convenient for small programs. I ended up using it for several of the homework exercises. (But not the last two, where you need more than one class, and many instances.) For larger Java programs I think it has a danger of making things even more confusing than they need to be. Don't over-use this feature.

By the way, the use of the word “static” in this context is a carry-over from C++, where it is a carry-over from C.


Exceptions

Syntax of exception handling in Java.


New features in Java 1.5

Generic types, autoboxing and auto-unboxing of primitive types, enumerated types, formatted I/O... For more information see Programming with the New Language Features in J2SE 5.0 on the Sun website.


Acknowledgement: Much of this lecture is based on material in the book Big Java by Cay Horstmann (Wiley, 2002).

____________________________________________________

[ANU] [DCS] [COMP2100/2500] [Description] [Schedule] [Lectures] [Labs] [Homework] [Assignments] [COMP2500] [Assessment] [PSP] [Java] [Reading] [Help]

____________________________________________________

Copyright © 2005, Ian Barnes, The Australian National University
Version 2005.2, Friday, 4 March 2005, 12:20:35 +1100
Feedback & Queries to comp2100@cs.anu.edu.au