O'Reilly logo

Java RMI by William Grosso

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Conventions Used in This Book

Italic is used for:

  • Pathnames, filenames, directories, and program names

  • New terms where they are defined

  • Internet addresses, such as domain names and URLs

Constant Width is used for:

  • Anything that appears literally in a Java program, including keywords, datatypes, constants, method names, variables, classnames, and interface names

  • Command lines and options that should be typed verbatim on the screen

  • All JSP and Java code listings

  • HTML documents, tags, and attributes

Constant Width Italic is used for:

  • General placeholders that indicate that an item should be replaced by some actual value in your own program

Constant width bold is used for:

  • Text that is typed in code examples by the user

Tip

This icon designates a note, which is an important aside to the nearby text.

Warning

This icon designates a warning relating to the nearby text.

Coding Conventions

For the most part, the examples are written in a fairly generic coding style. I follow standard Java conventions with respect to capitalization. Instance variables are preceded by an underscore (_), while locally scoped variables simply begin with a lowercase letter.

Variable and method names are longer, and more descriptive, than is customary.[2] References to methods within the body of a paragraph almost always omit arguments—instead of readFromStream(InputStream inputStream), we usually write readFromStream( ).

Occasionally, an ellipsis will show up in the source code listings. Lines such as:

catch (PrinterException printerException){
....
}

simply indicate that some uninteresting or irrelevant code has been omitted from the listings in the book.

The class definitions all belong to subpackages of com.ora.rmibook. Each chapter of this book has its own package—the examples for Chapter 1 are contained in subpackages of com.ora.rmibook.chapter1; the examples for Chapter 2 are contained in subpackages of com.ora.rmibook.chapter2, and so on. I have tried to make the code for each chapter complete in and of itself. That is, the code for Chapter 4 does not reference the code for Chapter 3. This makes it a little easier to browse the source code and to try out the individual projects. But, as a result of this, there is a large amount of duplication in the example code (many of the classes appear in more than one chapter).

I have also avoided the use of anonymous or local inner classes (while useful, they tend to make code more difficult to read). In short, if you can easily read, and understand, the following snippet:

private void buildGUI(  ) {
	JPanel mainPanel = new JPanel(new BorderLayout(  ));
	_messageBox = new JTextArea(  );
	mainPanel.add(new JScrollPane(_messageBox), BorderLayout.CENTER);
	createButtons(  );
}

you should have no problem following along with the example code for this book.

Applications

The source code for this book is organized as a set of example applications. In order to make it easier to browse the code base, I’ve tried to follow a consistent naming convention for classes that contain a main( ) method. If a class Foo contains a main( ) method, then there will be a companion class FooFrame in the same package as Foo. Thus, for example, the ViewFile application from Chapter 1 has a companion class ViewFileFrame. In fact, ViewFile consists entirely of the following code:

package com.ora.rmibook.section1.chapter1;

public class ViewFile {
	public static void main(String[] arguments) {
		(new ViewFileFrame()).show(  );
	}
}

Having top-level GUI classes end in Frame makes it a little easier to browse the code in an IDE. For example, Figure P-1 shows a screenshot of JBuilder 3.0, displaying the source files related to Chapter 2.

Screenshot of JBuilder 3.0

Figure 1. Screenshot of JBuilder 3.0

Compiling and Building

The example code in the book compiles and runs on a wide variety of systems. However, while the code is generic, the batch files for the example applications are not. Instead of attempting to create generic scripts, I opted for very simple and easily edited batch files located in chapter-specific directories. Here, for example, is the NamingService.batbatch file from Chapter 15:

start java -cp d:\classes-Djava.security.policy=c:\java.policy com.ora.rmibook.
chapter15.basicapps.NamingService.

This makes a number of assumptions, all of which are typical to the batch files included with the example code (and all of which may change depending on how your system is configured):

  • start is used as a system command to launch a background process. This works on Windows NT and Windows 2000. Other operating systems launch background processes in different ways.

  • The d:\classes directory exists and contains the .class files.

  • There is a valid security policy named javapolicy located in the c:\ directory.

In addition, the source code often assumes the c:\temp directory exists when writing temporary files.

Downloading the Source Examples

The source files for the examples in this book can be downloaded from the O’Reilly web site at:

http://www.oreilly.com/catalog/javarmi


[2] We will occasionally discuss automatically generated code such as that produced by the RMI compiler. This code is harder to read and often contains variables with names like $param_DocumentDescription_1.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required