Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips,
by Chris Laffra

This page is a (revisited) mirror page published on August 4, 1997

last modified
(mm/dd/yy hh:mm:ss GMT+1)
published
(original author's agreement pending)
by marc.meurrens@acm.org (http://homepages.ulb.ac.be/~meurrens)

URL of the original document
http://members.aol.com/laffra/book.html
by Chris Laffra (laffra@aol.com)

URL of our page(s) on "Java OO Design & Coding Standards"
(where this document is referred as detailled below):
http://www.ulb.ac.be/esp/ip-Links/Java/joodcs/index.html
[back]

Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips
is a revisited mirror (published with the kind encouragements of the original author) of http://members.aol.com/laffra/book.html by Chris Laffra (laffra@aol.com)

Pre-prepared links (to this document)

A list of approx. 18 "pre-prepared" links to this page is available at URL http://www.ulb.ac.be/esp/ip-Links/Java/joodcs/laffra-LinksTo.html.
These links are (or will be) used in other pages related to "OO design and Coding Standards".

Revisions

"Advanced Java -- Idioms, Pitfalls, Styles, and Programming Tips"

Author: Chris Laffra
Publisher: Prentice Hall http://www.prenhall.com
pages: 256
Publishing date: September 12, 1996.
Includes a diskette (mirrored here 383kb --> 873 kb, 174 files)


Link to http://www.amazon.com where you may access reader's comments and order the book.
cover Advanced Java : Idioms, Pitfalls, Styles and Programming Tips
by Chris Laffra

Bk&Disk Edition
Paperback, 288 pages
Published by Prentice Hall Computer Books
Publication date: October 1, 1996
Dimensions (in inches): 9.24 x 7.04 x 1.01
ISBN: 0135343488
price: $35.95 - $28.76

Endorsements by panel of Java Experts

Important Warning

Contrary to one of the README files on the diskette that comes with this book, the enclosed visual debugger only works with JDK 1.0 (and with Symantec Cafe 1.0). It will not work with JDK 1.02 (nor with Symantec Cafe 1.2). To use the debugger, install JDK 1.0 somewhere on your PC (you can find JDK 1.0 on the CD of many Java books).

LTK (the toolkit enclosed with the book) should work fine with JDK 1.0 (it highlighted some problems in early beta versions of JDK1.0).

Abstract

The immensly popular Java programming language can be used to develop small applications that can be embedded into otherwise static WWW pages. Whenever a Java-enabled browser encounters a page with a reference to such an applet, it is automatically retrieved over the internet by the browser, and executed locally on the user's display. In this fashion, HTML pages can be host to a wide variety of interactive applications ranging from displaying a simple image, showing various animations, implementing a game like solitary or chess, performing client-based manipulation of data without needing a round-trip to a server, to retrieving live stock quotes from an external data source.

Java was initially designed as a language for programming embedded consumer electronics. Its syntax is inspired by C++, but it is simpler in quite a number of aspects. Removed from the language are pointer arithmetic, templates, multiple inheritance, and a lot of other things that were considered too complicated by the language designers. Added to the language are multi-threaded programming support, garbage collection, interfaces, and internet awareness. This makes the language a perfect vehicle for efficient compilation, distribution and execution of enhanced WWW pages.

This book does not give an introduction to Java for novices. Do not expect to find a description of how to set your class path on Windows 95, or what special relationships Jim Gosling has with oak trees, or how to make a simple applet run both with the appletviewer and with Netscape, or what a great programmer Arthur van Hoff is.

Those basic topics are dealt with enough in any of the dozens of Java books currently available on the shelves at your local book store. Instead, this book tries to concentrate on more advanced features, amongst which:

Diskette

On the accompanying diskette (mirrored here 383kb --> 873 kb, 174 files), the book gives access to full source code and description of:

Contents of this book

  • Preface
  • Acknowledgements
  • PART I, Idioms and Programming Tips

    PART II, LTK -- The Little Toolkit

    PART III, Visual Debugging of Java Programs

    PART IV, C2J -- A C++ to Java translator

    PART V, Index

    Author's Background

    After receiveing a Master's degree in Computer Science from the Free University of Amsterdam, the Netherlands, Chris has designed and implemented PROCOL, a parallel object oriented language as part of his PhD research at the Erasmus University of Rotterdam, the Netherlands. His interests during that time spanned OO languages, compiler techniques, and user interface development.

    During the two great years he spent at the IBM T.J. Watson Research, Chris worked on a compiler and development environment for the Oberon language and developed HotWire, a platform independent visual debugger for C++ and Smalltalk. Some of his ideas can now be found back in commercial versions of the IBM Smalltalk system, VisualAge.

    In the summer of 1994, Chris moved to the information technology department of Morgan Stanley in New York City, one of the ten best U.S. companies to work for, confirmed by a survey done by Money Magazine. At Morgan, he continued working with OO languages as a member of the MStk development team. MStk is a proprietary multi-platform C++ toolkit providing support for firm-wide infrastructure and user interface aspects of financial applications used by Morgan Stanley at Wall Street. Chris has also been actively involved in evaluation projects of the Java language inside Morgan Stanley, and ported major parts of MStk to Java.

    Chris has presented papers and organized various workshops at OO conferences such as OOPSLA, ECOOP, TOOLS, and Usenix-C++. He was demonstration chair and exhibition chair of ECOOP'92. He presented a tutorial at SIGGRAPH and co-chaired a Eurographics workshop on the topic of using OO techniques for graphics, leading to a publication by Springer Verlag.

    Click here for Chris' current coordinates.

    Data extracted from http://www.amazon.com where you may access reader's comments and order the book.

    Reviews and Commentary for Advanced Java : Idioms, Pitfalls, Styles and Programming Tips

    The publisher, Prentice-Hall ECS Professional:
    A guide to the more advanced features of Java. For advanced programmers, this may be the most sophisticated Java book on the market. This book covers a wide variety of advanced Java topics and techniques that are rarely discussed elsewhere. These include object-oriented analysis and design with Java, metaprogramming techniques, building Java debuggers, Java interprocess and inter-thread communications, 3D modeling, implementing generic data structures, and techniques for accessing third-party libraries. The author identifies inconsistencies and pitfalls in Java, helps identify ways to optimize Java code for faster performance, and provides well-reasoned answers for the questions that advanced Java programmers encounter. The CD-ROM includes C2j, software for automatically translating C++ code to Java; the Ltk toolkit, a lightweight alternative to AWT, and a visual debugger developed especially for this book.

    Synopsis:
    This is the next book for the Core Java market. The text concentrates on the more advanced features of the Java programming environment, such as O-O design and analysis of Java programs, implementing callbacks, enhancing the Java Toolkit, meta-programming in Java and more. This is not a book for novices! The CD-ROM includes extensive code examples, a visual debugger, an AWT alternative, and even a C++ to Java translator.

    Card catalog description
    If you're a sophisticated programmer who already has Java experience, Advanced Java: Idioms, Pitfalls, Styles and Programming Tips is the book you've been waiting for. This is a comprehensive compilation of advanced techniques you can use to move your Java programming to the next level. Nowhere else in print are all these topics covered with such expertise: object-oriented analysis and design with Java; Java metaprogramming techniques, including incremental compilation; tips on improving Java performance; Java pitfalls and "gotchas"; constructing Java debuggers; Java interprocess and inter-thread communications; implementing generic data structures; and Java coding styles. Java expert Chris Laffra identifies inconsistencies and pitfalls in Java, helps identify ways to optimize Java code for faster performance, and provides well-reasoned solutions for the challenges that advanced Java programmers encounter. Advanced Java is not for novices. But for expert developers who want tools and techniques to differentiate themselves from the "run-of-the-mill" Java programmer, it's an unprecedented, unparalleled resource.

    Computer Term:
    java: A programming language for Internet (World Wide Web) and intranet applications from the JavaSoft division of Sun. Java was modeled after C++, and Java programs can be called from within HTML documents or launched stand alone. The first Web browsers to run Java applications were Sun's HotJava and Netscape's Navigator 2.0. Java was designed to run in small amounts of memory and provides its own memory management.

    Customer comments

    Data extracted from http://www.amazon.com where you may access reader's comments and order the book.

    Customer Comments
    rags@tou.com, 05/27/97, rating=4:
    Not worth the money
    First, the book didn't cover Java 1.1, and many of its complaints about Java have been resolved in the later release. I noted several incorrect comparisons between Java and C++ which may mislead the reader. The first chapter was the only one that turned out to be interesting, as far as advanced Java is concerned. Almost the entire book was devoted to Chapter 2, the Toolkit, which, unless you're looking to write your own, wasn't worth much. There were many "advanced" features of Java that were not addressed at all. Overall, it didn't live up to expectations of being "advanced."

    Short table of contents

    Data extracted from http://www.amazon.com where you may access reader's comments and order the book.
    Click here for a detailled table of content!

    Table of Contents
    Foreword
    Preface
    Acknowledgments
    Ch. 1. Idioms, Pitfalls, and Programming Tips
    Ch. 2. LTK - The Little Toolkit
    Ch. 3. Java Debugging Techniques
    Ch. 4. Translating C++ to Java
    References
    Appendix A
    Index

    Click here to see the author's background.

    Chris wrote: "In May of 1997, after a great period at Morgan Stanley in New York City, I re-joined the IBM T.J. Watson Research Center in Hawthorne, New York, to work on Java Tools (compilers/IDEs/VMs/analyzers). My email there is laffra@watson.ibm.com. My IBM home page is: http://www.research.ibm.com/people/l/laffra>."

    The author maintains a professional email (fastest) at laffra@watson.ibm.com, and a private email (slower reaction) at laffra@aol.com.
    We suppose that this last address replaces laffra@ms.com (?).

    The authors' home pages are: his IBM home page http://www.research.ibm.com/people/l/laffra and a private one http://members.aol.com/laffra

    C2J, a C++ to Java translator
    written in C++

    This section is a mirror of URL
    http://members.aol.com/laffra/c2j.html
    C2J, a C++ to Java translator, written in C++

    c2j is a C++ to Java translator that translates C++ code to Java code. The parser is written in C++, because I wrote it before I ever heard of Java... The input to c2j must consist of:

    c2j is basically a shell-script that calls sed, a C++-to-Java translator, and the C pre-processor to do all the weaving of moving methods into one Java class definition.

    This parser currently uses a shell script and a Unix utility called "sed". When you have access to Unix utilities on a Windows PC (like the MKS toolkit), the parser could also be used.

    The zip file contains a couple of batch files to make it work fine on Win95 and WinNT. Assuming you have access to both VisualC++ 2.0 (or higher) and the MKS Unix utilities toolkit.

    Different problems that are tackled by this parser:

    c2j translates roughly about 85-95 percent of our code correctly. It saves me a lot of editing time (inlining all methods, translating simple types, removing &'s everywhere, changing -> into ., etc. Just run it and see what it does for you...

    A beta version of c2j can be downloaded here (or here, on our mirror site) for free.
    (approx. 18 kb --> 52 kb, 13 files including readme.txt)

    We have decided to put this parser in the public domain. Use it at your own risk, and if you make any changes (especially improvements), tell us! We hope that this utility is useful for you and the rest of the C++/Java community.

    Chris Laffra

    -------------------------------------------------------
    IBM T.J. Watson Research Center,  laffra@watson.ibm.com
    P.O. Box 704, Yorktown Heights, NY 10598 (914) 784 7525
    -------------------------------------------------------
    

    Old and new versions

    The following is extracted from URL
    http://members.aol.com/laffra

    C2J, automatically translating C++ to Java

    There are two versions of this very handy tool. There is an old version, based on UNIX, which is written in C++.

    And there is a 100% Pure Java version of C2J. (mirrored below) The latter has been written by Ilya Tilevich, and can be run as an applet. You can enter C++ code in one window, and see the resulting C++ code in another. All this without needing to leave your browser!

    Ilya Tilevich

    The following is extracted from Ilya Tilevich's Home Page
    http://pacevm.dac.pace.edu/~ny971734 (ny971734@pace.edu)

    C2J++ is a C++ to Java translator written completely in Java. C2J++ is a Java implementation of Chris Laffra's C2J. It translates C++ code to Java code.

    Look at URL http://pacevm.dac.pace.edu/~ny971734/c2j.html or below for more information on C2J++.

    C2J++
    a C++ to Java translator written completely in Java

    The following is extracted from
    http://pacevm.dac.pace.edu/~ny971734/c2j.html

    C2J++ is a C++ to Java translator that translates C++ code to Java code.

    C2J++ is based on Chris Laffra's C2J

    Read general disclaimer distributed with C2J++ before using this code

    For information about C2J++, send mail to ny971734@pace.edu or (?) Ilya_Tilevitch@ibi.com

    The input must consist of:

    - one .H file, containing one or more C++ class definitions.

    - one .C file, containing all method bodies referenced in the .H file.

    ******************************************************************

    * In order to use C2J++, copy .H and .CPP files that you want to translate into

    * the directory where you keep C2J++.

    * Then type:

    * java C2J yourHeaderFile.h yourCppFile.cpp

    *******************************************************************

    Different problems that are tackled by C2J++:

    * C++ can have a header file with a class declaration and a memberfunction given in another file (typically a .C or .cpp file), Java has all the methods "inlined" in the class definition.

    * Data types are incompatible (unsigned versus int, for instance)

    * Pointer references (->) need to be translated into refs (.)

    * Access (public,protected,private) is done by region in C++, and is per method in Java.

    * Print statements to cerr and cout, which are to be translated into calls to System.out.print, and System.err.print.

    * Statements with "delete object;" need to be translated into"object = null;" to render a similar effect. Note that these assignments are not necessary at all in a destructor, as we will lose the reference to the object automatically.

    * C++ has multiple inheritance. Java has single inheritance andinterfaces. In the case of multiple inheritance, we need to make a decision.

    Still to be done:

    * Variable declarations on the stack are not recognized and handled.

    * Overloaded operators in the code.

    * Templates.

    Note:

    All global variables and functions are collected and put into the first class found

    in the .H file. If you have a lot of global data, I would suggest putting

    an empty class definition at the beginning of your header file to force C2J++

    to put all the globals in that class.


    Click here to download C2J++ (mirrored here)
    (approx. 67kb --> 181 kb , 30 files including readme.txt)

    An applet demo of C2J++ is available here

    Brussels
    mirror of September 12, 1996 by Chris Laffra (laffra@aol.com)
    published by marc.meurrens@acm.org (http://homepages.ulb.ac.be/~meurrens)
    original URL: http://members.aol.com/laffra/book.html
    current URL: http://www.ulb.ac.be/esp/ip-Links/Java/joodcs/ChrisLaffra.html
    internet programming Links: http://www.ulb.ac.be/esp/ip-Links (ip-Links)
    Université Libre de Bruxelles: http://www.ulb.ac.be (ULB)
    La Cambre - Architecture: http://www.lacambre-archi.be
    Belgian JAVA User Group: http://www.bejug.org (BeJUG)
     
    Use this form to send your feedback and/or submit a link
    (please, replace sample texts by appropriate data before submitting!)
    From
    your e_mail :
    your URL :
    To laffra@watson.ibm.com ; laffra@aol.com ; laffra@ms.com ;
    ny971734@pace.edu ; Ilya_Tilevitch@ibi.com
    meurrens@ulb.ac.be ; sja@bejug.org
    Subject
    Link
    Comment
     
    Conventions used in these pages:
    html file, text file or java or CPP source located on our site
    download area (on our site) or file to be downloaded (use the right button of your mouse)
    document on a belgian academic or scientific site
    document (on another site) or link to be fixed or link we didn't visit/evaluate; documents indicated with their full URL will be displayed in their own "top" window.
    ftp download or file to be downloaded (use the right button of your mouse)
    indicates a "mailto" link.
    and indicate links added or updated within the last month.
    Click on the separator to reach a higher level in the page or site hierarchy.
     

    begin back previous home e_mail ULB ESP ip-Links La Cambre BeJUG next end