Letters to the Editor

This month: Readers cut HotSpot (and Java) down to size. Plus, more MessageBox app questions for Jack Harich; new columnist Bryan Morgan fields his first Distributed Objects inquiry; and Mark Johnson may just have to switch from instant -- "freeze-dried" -- JavaBeans to beans by the bag

1 2 Page 2
Page 2 of 2
                                       * Same as ask(String message) except adds an "Okay" button.
                                       */
                                       public void askOkay(String message) {
                                       addChoice("Okay");
                                       ask(message);
                                       }
                                       /**
                                       * Same as ask(String message) except adds "Yes" and "No"
                                       * buttons.
                                       */
                                       public void askYesNo(String message) {
                                       addChoice("Yes");
                                       addChoice("No");
                                       ask(message);
                                       }
                                       //---------- Private Methods -----------------------------
                                       // Prepares but does not show the dialog
                                       private void prepareDialog(String message) {
                                       if (frame == null) {
                                       frameNotProvided = true;
                                       } else {
                                       frameNotProvided = false;
                                       }
                                       dialog = WindowMgr.createDialog(true);
                                       dialog.addWindowListener(this);
                                       dialog.addKeyListener(this);
                                       dialog.setTitle(title);
                                       dialog.setLayout(new BorderLayout(5, 5));
                                       Panel messagePanel =
                                       WindowLib.createMultiLinePanel(message);
                                       if (imageCanvas == null) {
                                       dialog.add("Center", messagePanel);
                                       } else {
                                       Panel centerPanel = new Panel();
                                       centerPanel.add(imageCanvas);
                                       centerPanel.add(messagePanel);
                                       dialog.add("Center", centerPanel);
                                       }
                                       dialog.add("South", buttonPanel);
                                       dialog.pack();
                                       WindowLib.enforceMinimumSize(dialog, 200, 100);
                                       WindowLib.center(dialog);
                                       Toolkit.getDefaultToolkit().beep();
                                       }
                                       //--- Std
                                       private static void print(String text) {
                                       System.out.println("MessageBox" + text);
                                       }
                                       } // End class
                                      

Spooked about deadlocking

Jack,

Thanks for your tip. This is my understanding of the deadlock problem from your article:

  • The AWT thread calls actionPerformed()
  • My code tries to pop a modal dialog, thus blocking
  • AWT can't show the dialog because I'm blocking it
  • I can't stop blocking it until AWT shows the dialog

If I'm wrong here, please explain.

Also, when will I ever be able to use a modal dialog, other than with the main thread?

The JDK doc (http://java.sun.com/products/jdk/1.1/docs/api/java.awt.Dialog.html) has this to say about public void show():

It is permissible to show modal dialogs from the event dispatching thread because the toolkit will ensure that another dispatching thread will run while the one which invoked show is blocked.

Joe Walker

Joe, In Java 1.1, modal dialogs start a new thread to show themselves. Thus in 1.1 the deadlocking no longer occurs. In 1.0 you need to show a modal dialog in a new thread if the call is from an AWT thread. You should have no problems. Sorry if I spooked you about deadlocking. Jack Harich

Class evasion

Jack,

In your MessageBox app there are two packages. When I ran this application, I typed

java COM.jconsort.ui.MessageBoxTest
                                      

but the ImageCanvas class (used in MessageBoxTest) belongs to another package, org.jcon.ui, and cannot be found and invoked. Please advise.

Thank you very much for your help!

Judy

Judy, Try commenting out the package names, putting them all into the same directory, and running from that directory. Jack Harich

Distributed Objects: "Java 1.2 extends Java's distributed object capabilities" by Bryan Morgan

Read

Distributed Objects columnist offers advice on CORBA and Java

Bryan,

I am a final year student of computer science. As part of one of my projects I'm investigating and implementing a database to be viewed through a Web brower using CORBA. I was wondering whether or not you would advise me on using Java -- applets and all -- for commercial use at the moment.

Gareth Griffin

Gareth, First of all, as part of your university project, I would definitely recommend pursuing a three-tier project using Java, CORBA, and a commercial RDBMS. From an educational viewpoint, it will help you apply much of the in-class information you've been receiving and you will receive valuable training in technologies the industry is clamoring for. As far as the feasibility of a client/server project using Java, you should be aware that hundreds, perhaps thousands, of projects are underway now at nearly every major corporation using these technologies. When developing a client/server application, it is important to analyze your choice in tools by looking at the whole system instead of each individual part. Java is a great programming language and it offers you the ability to build a platform-independent solution, with a tradeoff in performance. The fact that CORBA is endorsed by so many vendors, is truly standardized, and is available on a wide range of operating systems means that your middle-tier (the object server) can be very flexible in terms of product choice and implementation. If you choose to use Java as your programming language, you'll need to decide between an applet or an application. Applets are dynamically downloaded and displayed within the Web browser and are subject to stringent security restrictions. Further, the major Web browsers have many problems with Java 1.1 functionality and a CORBA/Java applet requires a large number of class files to be downloaded before the applet can actually start. So for now I'd go with the Java application. Developing an application will ensure that the user has the latest version of the JDK and CORBA packages installed and will also open up the ability to print and save to a file. Good luck and keep me posted on your progress! Bryan Morgan

Java Step By Step: "Write your own threaded discussion forum" by Michael Shoffner

Read

Michael,

I am writing an application based loosely on your wonderful forum example. I use a file that I've created with DataOutput to keep track of different documents floating around on the server, as well as the corresponding senders, dates. I'm hoping for your input.

Billy Perez

Billy, You ought to just model the app with classes and use object serialization to serialize the message objects to the filesystem. Try something like this:

Message  
                                       _________________
                                       String sender 
                                       Vector recipients
                                       Date date 
                                       String subject 
                                       ...            
                                       MessageBody body 
                                      

Then

MessageBody

could be made to lay out and display text, images, etc. (You name it.) Then you could make a custom AWT component that knows how to lay out messages and put that in place of the text area that's in the display right now. Hope this helps, Michael Shoffner

Book Review: "Java virtual machine books -- a comparative review" by Laurence Vanhelsuwé

Read

Source code not always filler

Laurence,

I enjoyed your review of JVM books. It was useful and well-written, and probably saved me 30 minutes at Barnes & Noble.

You seem to take the position that printing source code is almost always a way for lazy authors to up page count.

I'd like to weigh in for the opposing view. When we were putting together our book Programming with Java IDL (Wiley 1997), this was the most contentious issue we had to resolve amongst our contributors.

Some felt as you did, that it was a page waster and that people would rather look at the code in electronic form. The other side of the argument -- that the inclusion of source code is vital to any discussion of a program -- is what eventually carried the day, largely because I insisted upon it.

I have seen books where the source code was presented in a page-wasting fashion, and I've felt cheated by it. One particularly egregious example actually presented each line of each program in the book at least three times.

But in books that teach programming or programming techniques, presenting the source code in full is very important. It's valuable to step people through the interesting parts of each program, often with surrounding text -- the "snippet" approach. It's equally valuable to present the whole enchilada, uninterrupted, for reasonably short programs. The author is not omniscient, and it's possible that the code the author thinks trivial is the part the reader is having trouble with, in which case the reader desperately needs to see a working example.

On the practical side, I ride the subway to work and this is where I do most of my reading. Given my busy life, having the source code squirrelled away on a CD-ROM would mean that I would be left with text. No thanks.

Sometimes I think that my views on this subject are idiosyncratic, because a lot of people do hold your view that source code is a waste of space. But then I notice that people like Don Knuth, who spent years developing the Web integrated text/code system, and Gerald Sussman, who once said in a lecture that programmers should study good source code listings as rabidly and as completely as English majors study Shakespeare, seem to agree with me, and I rest more easily.

Steve Barber

Java Tips Q&A with John D. Mitchell

Read

So, you want to make a Back button? See Tip 15

John,

I want to create a Back button in a Java applet using the JavaScript history.back() method, but I don't now how.

Can you help me?

Roberto Santiago

Roberto, Check out Java Tip 15, "How to make a 'Back' button in JavaScript." Note that Java and JavaScript are quite different, and you will not be able to use the same methods in both. John D. Mitchell

Why can't I view my applets?

John,

I'm a software developer in New Delhi. We are just starting to use Java. We have made a few applets using standard component toolbars of Visual Café 2.0, Web development edition. We are able to view them in appletviewer, but are not able to view them in Netscape 4.02. We don't know why.

The browser says: java.lang.NoSuchMethodError.

Murty

Murty, I suspect that you are making use of Java 1.1x constructs -- versions of Netscape 4.x before 4.04 aren't complete implementations of Java 1.1x. Try upgrading. It also wouldn't hurt to read the manuals on Visual Café. John D. Mitchell

Resources, resources, resources

Read

Do you know about JavaWorld's topical index?

To the editors:

I know you have an index page with all Java Tips listings.

I would like to see a similar chronological list of all your published Nuts & Bolts tutorial articles (and why not other articles too?)

It's rather cumbersome to load and browse through the back-issues one by one.

Thanks for listening.

Johannes

Johannes, Perhaps you are not aware of JavaWorld's topical index, which will help you navigate our rich archives by topic (for example, "How-Tos and Tutorials," "Security," and "Java Virtual Machine"). Just go to http://www.javaworld.com/common/jw-topicalindex.html Thanks for reading JavaWorld! Jenni Aloi

Associate Editor

Links for beginners

To Bill Day:

Can you send me some useful links for a Java programming beginner?

Roman g. Tchessov

Roman, Thank you for your interest in JavaWorld. I've included a few references below, all of which provide useful information in addition to the content available from JavaWorld magazine. A good place for any Java beginner to start is JavaSoft's Web site: http://www.javasoft.com This site contains tutorials to get you started and pointers to tools and programming environments. From there, you can click over to the Java Developer Connection. Though the JDC requires a login, it's free and has a lot of additional early and "inside" information on Java tech. Another decent source of Java information and tutorials is the Cafe au Lait site: http://sunsite.unc.edu/javafaq And here are a couple more sources for Java information, particularly books: http://www.oreilly.com/java; and http://java.miningco.com Bill Day

Related:
1 2 Page 2
Page 2 of 2