Exercises

To extend your knowledge of the subjects covered today, try the following exercises:

  • Use reflection to write a Java program that takes a class name as a command-line argument and checks whether it is an application—all applications have a main() method with public static as modifiers, void as a return type, and String[] as the only argument.

  • Write a program that creates a new object using Class objects and the newInstance() method that serializes the object to disk.

Where applicable, exercise solutions are offered on the book's Web site at http://www.java21days.com.

Get Sams Teach Yourself Java 2 in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.