Java Coffee Break Newsletter Volume 2, Issue 7 http://www.davidreilly.com/jcb/ ISSN 1442-3790 ================================================================ In this issue * Java in the news * Book Review - "Java 2 Platform Unleashed" * Article : Java coming to a TV near you! * Q&A : Is Java Y2K compliant? Where can I find more information? * Q&A : What are exceptions, and when should I use them? * Q&A : How can I change the gray background of an applet? ================================================================ In the News Here are a selection of recent news items that may be of interest to Java developers. /*/ Sun makes significant announcements at JavaOne Conference During the annual JavaOne conference, Sun chose to make some very significant announcements on Java technologies. Included in this list are the release of the JavaTV API, three editions of the Java 2 Platform (standard, micro and enterprise), and many more. For a full wrap up this year's JavaOne announcements, check out : http://java.sun.com/features/1999/06/overview.html /*/ Palm V makes a big impression on developers at JavaOne Palm V, now with support for Java, was a hot selling item at this year's JavaOne conference. Palm V includes an early pre-release edition of a Java Virtual Machine (JVM). Not only for desktop machines, Java is now making inroads into PDAs, and with the release of the Java 2 Micro Edition of the Java platform, it won't be too long before we see mobile phones and embedded systems running Java. For coverage of the Palm V at JavaOne, check out Wired's read on it at http://www.wired.com/news/news/technology/story/20243.html ================================================================ Book Review - Java 2 Platform Unleashed Author : Jamie Jaworski Publisher : Sams ISBN : 0672316315 I've always been a big fan of the Java Unleashed series of books, not only for their ability to teach the Java programming language, but also for their comprehensive coverage of the Java language, its API, and advanced topics like multi-threading, networking, and Java extensions. This type of coverage means that they can be used afterwards as a programming reference. With the release of the Java 2 platform, however, there have been many changes including Swing, servlets, CORBA, and increased multimedia support (Java Media Framework, Java 2D, Java 3D). Some books might have adopted a superficial approach, covering only the most obvious of changes, and leaving out the new Java extensions. So it's with great surprise, and a little relief, that "Java 2 Unleashed" continues the fine tradition of its predecessors, by providing comprehensive coverage of all the new changes and features of Java 2. While many references give only superficial coverage of topics, "Java 2 Unleashed" takes a detailed look at the Java 2 Platform. Whether you're interested in upgrading your applications to use the rich range of new Swing components, want to create interactive applets to spice up a website, or even write client/server networking applications, this book covers it! But it goes further still. There are chapters on using the system clipboard, implementing drag and drop support, printing, and internationalization. Its coverage on networking and distributed systems covers remote method invocation (RMI), content handlers, JavaMail, CORBA and network programming (total of seven networking chapters). For those interested in Java's multimedia support, there are chapters covering the new Java 2D & Java 3D APIs, implementing animation in applets, and the new Java Media Framework (JMF). Even more impressive is the comprehensive look at developing and using JavaBeans (six chapters in total). This is the ultimate reference, and makes it easy to get a handle on the new changes in the Java 2 Platform. Nor is this title limited only to the new innovations which would interest existing Java developers. This book takes on the awesome challenge of introducing someone new to Java to the Java 2 platform, taking it slowly from applets to applications, through AWT & Swing, as well as the core Java packages (java.lang, java.util, java.net), database programming with JDBC, development tools, and all the practical information gathered from the author's experience. "Java 2 Platform Unleashed" is a fine addition to the library of any programmer, be they experienced in Java or still learning. For more information about this title, or to order it, visit http://www.davidreilly.com/goto.cgi?isbn=0672316315 ================================================================ Java coming to a TV near you! By David Reilly Imagine Java applications running on your television set. Sound far fetched? The new Java TV API promises to allow applications access to all the functionality of digital television sets, which will run the PersonalJava JVM. Okay. When I first read about the Java TV API last year, I thought the idea of Java running on set-top boxes was quite amusing. After all, we've all had the experience of slow loading applets running inside web-browsers, that amount to little more than eye-candy for the easily amused. Certainly, there are some serious Java applets out there, but they're few and far between, and with cross-browser compatibility issues, limited in their audience reach. Then the enormity of it hit me - while the number of computers in households is still small, and the number of Internet users even more so, the number of people with television sets is MASSIVE. This one concept has the potential to introduce the word "Java" to hundreds of millions of people world-wide. Digital TV may be slow to get a foothold, but it's almost a certainty. Now imagine all those people running Java applications (or applets) right from their television. High bandwidth HDTV or cable connections could be integrated with interactive Java content, ranging from simple games, stock tickers, and online shopping. The scope of the Java TV API is very big indeed. The Java TV API is designed to allow Java applications access to the functionality of the television host on which it runs. Through the Java TV API, which will provide access to television programming content (de-multiplexed on-the-fly), content selection (program guides), and control over the television screen appearance. Applications can run on a Java Virtual Machine (JVM) designed for set-top boxes, televisions, and real-time devices. The underlying hardware details are abstracted away, leaving developers free to concentrate on developing interactive content, not porting it from one system to another. Here's where Java technology comes into its own. Not only is it portable, not only is there an existing code base to work with and familiarity amongst developers, but it will be easy to move applications from one system to another. That means consumers (and cable companies) won't be left with antiquated systems that can only run a small range of software. Integrated with the Java TV API will be other related technologies. For example, Java already has support for decoding and processing multimedia content, through the Java Media Framework. New decoders for television content can be added, as well as existing mechanisms such as MPEG. Imagine a high speed cable network that allows audio playback of MP3 music! The Java TV API has the potential to revolutionize the Java landscape. Sure Java made inroads into browsers, and is having increasing success in the server-side market, but imagine the potential of set-top boxes all around the world running Java. That's a big market for Sun, for cable and television companies, and for software developers. For more information on the Java TV API, you can follow its progress at Sun, http://java.sun.com/products/javatv/ ================================================================ Q&A: Is Java Y2K compliant? Where can I find more information? I'd like to give a big unconditional yes, but its not quite that simple. Java is more than a language - its a platform. There are many different virtual machines, by many different vendors, running on many different hardware and software architectures. Does that present a Y2K threat? Yes. However, work is being done to prevent problems. Sun takes its commitments very seriously - for a comprehensive list of products and their Y2K status visit http://www.sun.com/y2000/cpl.html The problem is - will all Java Virtual Machines be ready in time? Remember that some are third party ports, or completely re-engineered versions. So there is still the potential for problems if you use non-Sun virtual machines. If you use third party class libraries, or code, you're also running some risk. Of course, a quick test to reassure you, might be to turn your computer's clock forward till after Jan 1 2000. ================================================================ Q&A : What are exceptions, and when should I use them? Exception handling is an important feature of C++ and Java. Exceptions indicate unusual error conditions that occur during the execution of an application or applet. When you call an object method, and an "exceptional" event occurs (such as being unable to access a file or network resource), the method can stop execution, and "throw" an exception. This means that it passes an object (the exception), back to the calling code. That code can then handle the event, and deal with unusual conditions. That's the theory of exception handling. Let's look at a practical example. Suppose my application had to read some data from a file. Most times, it will be able to read the data, and continue on without any problems - but what would happen if the file didn't exist? Our program might crash, without reporting any meaningful error message. Let's see how exception handling can help. The following code snippet shows our code for reading a line of text from a data file. Note the use the try / catch keywords. This indicates that code within this block can throw an exception, and how we will deal it. String line; try { // This line throws an IOException if file not present FileInputStream fin = new FileInputStream ("config.ini"); // Create a data input stream for reading a line of text DataInputStream din = new DataInputStream( fin ); // Read line of text line = din.readLine(); } catch (IOException ioe) { // Exit gracefully with an error message System.err.println ("An error occurred while reading config file"); System.exit(0); } Exception handling also has other benefits. In the past, programmers would check the return value for a null object, or a special numerical code that indicated failure. But, programmers being human, this value wouldn't always be checked. This lead to strange errors at run-time, and no meaningful error messages. When an exception is specified in the throws clause of an object method, it must be caught, or the compiler will generate an error message. This forces programmers to always provide some form of catch statement (though many choose to leave their catch statement blank). Finally, exception handling can also make code more legible. Its easy to see where error conditions are being handled, and which error conditions are explicitly being looked at. This also separates programming code for "normal" situations from that of handler code for unusual events. In small applications, the advantages of this are not noticeable, but when debugging large and complex systems, it helps to reduce complexity and track down problems. ================================================================ Q&A : How can I change the gray background of an applet? Applets use a default background of gray, which isn't very visually appealing, and very infrequently matches the background of the web page on which it is loaded. So unless you repaint the background yourself in the paint() method of your applet, you'll want to change its background as soon as the applet loads. The best place to do it will be in your init() method. This means the applet will change color once it has finished loading. To change background color, you need to invoke the setBackground(Color) method. It accepts as a parameter any valid Color. public void init() { setBackground ( Color.black ); } There are many predefined colors, or you can create your own. For more information, see the java.Color API documentation. ================================================================ The Java Coffee Break Newsletter is only sent out to email subscribers who have requested it, and to readers of the comp.lang.java.programmer and comp.lang.java.help newsgroups. If you'd like to receive our newsletter, and get the latest Java news, tips and articles from our site, then get your FREE subscription from http://www.davidreilly.com/jcb/newsletter/ If you are an email subscriber and no longer wish to receive the JCB Newsletter, please unsubscribe using the WWW form located at http://www.davidreilly.com/jcb/newsletter/unsubscribe.html