Core Java Technologies Tech Tips Tips, Techniques, and Sample Code Welcome to the Core Java Technologies Tech Tips for February 17, 2004. Here you'll get tips on using core Java technologies and APIs, such as those in Java 2 Platform, Standard Edition (J2SE). This issue covers: * Loading and Saving Images with the Image I/O Library * Reflecting JavaBeans Components These tips were developed using Java 2 SDK, Standard Edition, v 1.4.2. This issue of the Core Java Technologies Tech Tips is written by John Zukowski, president of JZ Ventures, Inc. (http://www.jzventures.com). You can view this issue of the Tech Tips on the Web at http://java.sun.com/developer/JDCTechTips/2004/tt0217.html See the Subscribe/Unsubscribe note at the end of this newsletter to subscribe to Tech Tips that focus on technologies and products in other Java platforms. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - LOADING AND SAVING IMAGES WITH THE IMAGE I/O LIBRARY Introduced in J2SE 1.4, the javax.imageio package is the primary package for the Java Image I/O API. As its name implies, this package helps you read and write image files. You might wonder what's so important about this package. The fact is that you could read images with the getImage method of various classes like Toolkit and Applet since the initial release of the Java platform. But there is more to the javax.imageio package than simply reading images. One important point is that there was no writeImage or putImage previous to the Image I/O library. Now there is a way to write images. Also, you can now set properties such as compression level when you save images. The first question many people ask when working with the Image I/O libraries is what formats are supported? With Sun's reference implementation, you get a specific set. However, the API is flexible enough so that you can install your own formats by extending the necessary classes in the javax.imageio.spi library. For the moment, let's put that aspect of the library aside. To discover the installed set of readers and writers, you simply ask the ImageIO class through its getReaderFormatNames() and getWriterFormatNames() methods (or getReaderMIMETypes() and getWriterMIMETypes() if you want to work directly with MIME types). Here's an example: import javax.imageio.*; public class GetList { public static void main(String args[]) { String readerNames[] = ImageIO.getReaderFormatNames(); printlist(readerNames, "Reader names:"); String readerMimes[] = ImageIO.getReaderMIMETypes(); printlist(readerMimes, "Reader MIME types:"); String writerNames[] = ImageIO.getWriterFormatNames(); printlist(writerNames, "Writer names:"); String writerMimes[] = ImageIO.getWriterMIMETypes(); printlist(writerMimes, "Writer MIME types:"); } private static void printlist(String names[], String title) { System.out.println(title); for (int i=0, n=names.length; i