Java for Programmers

 

 

by

Douglas Lyon, Ph.D.


Table of Contents

 

If you wish to make an apple pie

truly from scratch,

you must first invent the universe.

 

– Carl Sagan, (1934-1996)

 

Java for Programmers.......................................................... i

Dedication........................................................................... ii

FOREWORD....................................................................... ii

Preface................................................................................ iv

Who should read this book?........................................................................... vi

Teaching Approach....................................................................................... vii

Deferred API coverage.............................................................................. vii

About the Icons............................................................................................ viii

Acknowledgments............................................................. viii

Table of Contents................................................................ ix

Illustrations.................................................................... xxvii

About the Contributors..................................................... xlii

1. Java, the Basic Idea.......................................................... 1

1.1. The History of Java.................................................................................. 1

1.2. What is Java?........................................................................................... 3

1.3. The HTTP model versus the Java model.................................................. 5

1.4. Summary.................................................................................................. 7

1.5. Exercises.................................................................................................. 7

2. Primitive Data Types........................................................ 9

2.1 The 8 primitive data types in Java........................................................... 10

2.2 Signed fixed point Data Types................................................................ 12

2.3 Simple Arithmetic Expressions............................................................... 13

2.4 Elementary Examples of Primitive Data Types....................................... 14

2.5 Casting Primitive Data Types.................................................................. 17

2.6 Some Math Methods............................................................................... 18

2.7 Summary................................................................................................ 18

2.8 Exercises................................................................................................. 19

3. Operators....................................................................... 21

3.1 Precedence, Associativity, and Unary/Binary Classification................... 22

3.2 Highest Order of Precedence Operators.................................................. 29

3.3 Increment and Decrement Operators....................................................... 31

3.4 Arithmetic Operators............................................................................... 33

3.5 Assignment Operators............................................................................ 33

3.6 The Syntax of Operators......................................................................... 34

3.7 Self-test................................................................................................... 36

3.8 Exercises................................................................................................. 42

4. Base Conversion.............................................................. 45

4.1 Numbering Systems................................................................................ 45

4.2 Common Computer Numbering Systems............................................... 47

4.3 Converting from Binary, Octal, and Hexadecimal to Decimal................. 48

4.4 Converting from Binary to Octal and Hexadecimal................................. 49

4.5 Converting from Decimal to Binary, Octal, and Hexadecimal................. 50

4.6 Summary................................................................................................. 52

4.7 Exercises................................................................................................. 53

5. Control Structures.......................................................... 55

5.1 Relational Operators................................................................................ 56

5.2 Equality Operators.................................................................................. 57

5.3 Boolean Operators.................................................................................. 57

5.4 Conditional Operator............................................................................... 59

5.5 The if statement....................................................................................... 59

5.6 The while and do statements................................................................... 63

5.7 The for statement..................................................................................... 65

5.8 The continue statement............................................................................ 67

5.9 The break statement................................................................................. 69

5.10 The switch statement............................................................................. 70

5.11 The return statement.............................................................................. 73

5.12 Exercises............................................................................................... 75

6. Reference Data Types...................................................... 77

6.1 Class Concepts........................................................................................ 78

6.2 Constructors............................................................................................ 82

6.3 Getter and Setter Methods....................................................................... 85

6.4 Null......................................................................................................... 87

6.5 Subclassing and Super............................................................................ 88

6.6 Casting.................................................................................................... 93

6.7 The instanceof keyword......................................................................... 95

6.8 Interfaces................................................................................................. 96

6.9 Data-centered Object-Oriented Design.................................................. 103

6.10 The Fragile Base Class Problem......................................................... 106

6.11 Summary............................................................................................. 107

6.12 Exercises............................................................................................. 108

7. Static, Abstract and Final Modifiers.............................. 112

7.1 Static Methods...................................................................................... 112

7.2 Static Variables..................................................................................... 113

7.3 Abstract Classes and Methods.............................................................. 120

7.4 The final Modifier and Named Constants............................................. 124

7.5 Final Classes and Methods................................................................... 125

7.6 The Singleton Pattern............................................................................ 126

7.7 Summary............................................................................................... 128

7.8 Exercises............................................................................................... 129

8. Arrays and Vectors....................................................... 131

8.1 Arrays................................................................................................... 131

8.2 Vectors.................................................................................................. 142

8.3 Building A Shopping Cart.................................................................... 145

8.4 A Stack................................................................................................. 149

8.5 A List.................................................................................................... 150

8.6 A Queue................................................................................................ 150

8.6 Summary............................................................................................... 151

8.7 Exercises............................................................................................... 152

9. Wrapper Classes and Strings......................................... 155

9.1 Wrapper classes.................................................................................... 155

9.1.1 Boolean........................................................................................... 156

9.1.2 Character......................................................................................... 157

9.1.3 The numeric wrapper classes.......................................................... 159

9.2 Strings................................................................................................... 160

9.3 ReplaceString........................................................................................ 164

9.4 StringTokenizers................................................................................... 165

9.5 The CsvParser....................................................................................... 166

9.6 The Maze Solver................................................................................... 169

9.7 Summary............................................................................................... 172

9.8 Exercises............................................................................................... 173

10. Exceptions................................................................... 176

10.1 Generating your first exception........................................................... 177

10.2 Guard the Input or Catch the Error...................................................... 178

10.3 Defining your own Exception............................................................. 180

10.4 Checked and Unchecked Exceptions................................................... 181

10.5 The Syntax of the try statement........................................................... 183

10.6 Throw................................................................................................. 187

10.7 Throws................................................................................................ 188

10.8 System.err........................................................................................... 189

10.9 Public safety and Exceptions............................................................... 189

10.10 Summary........................................................................................... 191

10.11 Exercises........................................................................................... 192

11. Packages, Imports and Visibility.................................. 195

11.1 Packages............................................................................................. 196

11.2 Imports................................................................................................ 199

11.3 Visibility Modifiers............................................................................. 201

11.4 Summary............................................................................................. 204

11.5 Exercises............................................................................................. 205

12. Nested Classes and Interfaces....................................... 207

12.1 The Member Inner Class..................................................................... 209

12.2 The Local Inner Class......................................................................... 212

12.3 The Anonymous Inner Class.............................................................. 214

12.4 The Nested Static Class....................................................................... 218

12.5 The Nested Interface........................................................................... 220

12.6 TheThis Keyword............................................................................... 222

12.7 Summary............................................................................................. 224

12.8 Exercises............................................................................................. 225

13. Threads....................................................................... 227

13.1 Concurrency, Multi-tasking, and Multi-Threading.............................. 227

13.2 Making a new Thread........................................................................ 233

13.3 Thread States...................................................................................... 234

13.4 Synchronized and Too Much Beer...................................................... 237

13.5 Thread Groups.................................................................................... 240

13.6 The Thread Manager........................................................................... 241

13.7 ThreadUtil........................................................................................... 242

13.8 The Thread Queue............................................................................... 249

13.9 Running Thousands of threads........................................................... 251

13.10 The Job Thread................................................................................. 252

13.11 Summary........................................................................................... 253

13.13 Exercises........................................................................................... 254

14. Files............................................................................ 256

14.1. What are files?.................................................................................... 256

14.2. Getting a file from the user................................................................. 257

14.2.2.3. Futil.getDirFile......................................................................... 257

14.2.3.1. Futil.getReadFile...................................................................... 258

14.2.3.2. Futil.getWriteFile..................................................................... 258

14.3. The File Class................................................................................... 259

14.3.1. Class Summary........................................................................... 259

14.3.2. Class Usage................................................................................ 260

14.4. The java.io.FilenameFilter interface................................................... 262

14.4.1. Class Summary........................................................................... 262

14.4.2. Class Usage................................................................................ 262

14.4.3. DirFilter...................................................................................... 262

14.4.4. The FileFilter Class..................................................................... 263

14.4.5. The WildFilter Class................................................................... 265

14.5. The Ls Class...................................................................................... 265

14.5.1. Ls.getWildNames........................................................................ 266

14.5.2. Ls.wildToConsole....................................................................... 267

14.5.3. Ls.getDirName............................................................................ 267

14.5.4. Ls.deleteWildFiles....................................................................... 267

14.5.5. Ls.WordPrintMerge.................................................................... 268

14.6. Dir Lister............................................................................................ 269

14.7. Summary............................................................................................ 272

14.8. Exercises............................................................................................ 272

15. Streams....................................................................... 274

15.1. The FileInputStream Class................................................................ 276

15.1.1. Class Summary........................................................................... 277

15.1.2. Class Usage................................................................................ 277

15.1.3. Futil.getFileInputStream.............................................................. 279

15.1.4. Futil.available.............................................................................. 280

15.2. The FileOutputStream Class............................................................. 281

15.2.1. Class Summary........................................................................... 281

15.2.2. Class Usage................................................................................ 281

15.2.3. Futil.getFileOutputStream........................................................... 285

15.2.4. Futil.close(OutputStream)........................................................... 285

15.3. The DataInputStream Class............................................................... 286

15.3.1. Class Summary........................................................................... 287

15.3.2. Class Usage................................................................................ 288

15.4. The DataOutputStream Class............................................................ 290

15.4.1. Class Summary........................................................................... 290

15.4.2. Class Usage................................................................................ 291

15.5. The StreamSniffer Class.................................................................... 293

15.5.1. The StreamSniffer Class.............................................................. 302

15.5.2. Class Summary............................................................................ 302

15.5.3. Class Usage................................................................................. 303

15.6. Serialization....................................................................................... 305

15.7. Reading and Writing GZIPed Files of Floats.................................... 309

15.8. Exercises............................................................................................ 311

16. Readers...................................................................... 314

16.1 ReaderUtils......................................................................................... 316

16.2 Reading in a CSV File........................................................................ 318

16.3 The Cat.toConsole method.................................................................. 321

16.4 The Dos Class..................................................................................... 322

16.5 Dial D for Dos.................................................................................... 324

16.6 The StreamTokenizer......................................................................... 324

16.6.1. Class Summary........................................................................... 325

16.6.2. Class Usage................................................................................ 325

16.6.3. Futil.readDataFile........................................................................ 327

16.6.4. Futil.writeFilteredHrefFile.......................................................... 328

16.7 The futils.PolymorphicProcessor........................................................ 330

16.8 Summary............................................................................................. 332

16.9 Exercises............................................................................................. 332

17. Writers....................................................................... 336

17.1. Getting a File Name for Output.......................................................... 337

17.2. The SimpleWriter............................................................................... 340

17.3. HTML2Links..................................................................................... 341

17.4. The Cat class...................................................................................... 345

17.5. Futil.makeTocHtml........................................................................... 347

17.6. Summary............................................................................................ 349

17.7. Exercises............................................................................................ 349

18. Intro to Swing............................................................. 352

18.1. The Historical View........................................................................... 352

18.2. The Swing/AWT Relationship........................................................... 354

18.3. The Screen Class................................................................................ 355

18.4. Heavy Weight vs. Light Weight......................................................... 356

18.5. Simple Input and Ouput..................................................................... 358

18.6. An Introduction to Layouts................................................................ 362

18.6.1 FlowLayout................................................................................... 363

18.6.2 GridLayout.................................................................................... 366

18.6.3 BorderLayout................................................................................ 367

18.6.4 Mixing Layouts............................................................................. 369

18.6.5 Panels and Frames and Flow Layout............................................ 371

18.6.6 Custom Layouts............................................................................ 373

18.7. Getting a file from the user................................................................. 381

18.7.1 The Dialog Class........................................................................... 381

18.7.1.1. Class Summary......................................................................... 381

18.7.1.2. Class Usage    382

18.7.2 The FileDialog Class.................................................................... 383

18.7.2.1. Class Summary........................................................................ 383

18.7.2.2. Class Usage   383

18.7.2.3. Futil.getDirFile......................................................................... 384

18.7.2.4. Futil.getReadFile...................................................................... 385

18.7.2.5. Futil.getWriteFile..................................................................... 385

18.7.3 Using Swing to get a File.............................................................. 387

18.8. Summary............................................................................................ 388

18.9. Exercises............................................................................................ 389

19. Introducing Events...................................................... 393

19.1. ClosableJFrame.................................................................................. 396

19.2. The actionPerformed method............................................................. 402

19.3. The RunButton................................................................................... 403

19.4. Historical Perspective......................................................................... 406

19.4.1. The Observer Interface................................................................. 406

19.4.2. The Observer and Observable Summary..................................... 408

19.5. The NamedObservable....................................................................... 409

19.6. The ObservableDouble...................................................................... 410

19.7. ObserverOfPoint3d............................................................................ 411

19.8. Summary............................................................................................ 413

19.9. Exercises............................................................................................ 414

20. Design Patterns and Events......................................... 415

20.1 The Adapter Pattern and the Command Pattern................................... 416

20.2 A Command Pattern and the TouchTone Keypad............................... 418

20.3 The RunTextField............................................................................... 420

20.4 BorderLayout and RunTextField........................................................ 422

20.5 The RunCheckBox.............................................................................. 423

20.6 The RunPasswordField....................................................................... 426

20.7 The RunList........................................................................................ 427

20.8 The Scrollbar and the Slider................................................................ 429

20.8.1 The RunScroll............................................................................... 430

20.8.2 The RunSlider............................................................................... 431

20.9 The RunRadio..................................................................................... 433

20.10 The RunRadioButton........................................................................ 435

20.11 The MainMenuBar and RunCheckBoxMenuItems........................... 436

20.12 RunRadioButtonMenuItem Groups.................................................. 438

20.13 The Controller Design Pattern........................................................... 441

20.14 The Mediator Design Pattern............................................................ 445

20.15 A Word about the Design Process And the JTabbedPane................ 448

20.16 Summary........................................................................................... 455

20.17 Exercises........................................................................................... 456

21. Viewing HTML in Swing............................................. 462

21.1 The HtmlViewer................................................................................. 462

21.2 The HtmlSynthesizer........................................................................... 464

21.3 Summary............................................................................................. 474

21.4 Exercises............................................................................................. 474

22. Using the Keyboard..................................................... 477

22.1 Geting the key-event information........................................................ 477

22.2 Programming key modifiers............................................................... 479

22.3 Adding key-events to TouchTone....................................................... 481

22.4 Mnemonics and the RunMenuItem..................................................... 482

22.5 MnemonicMenus................................................................................ 484

22.6 Summary............................................................................................. 486

22.7 Exercises............................................................................................. 487

23. Mouse Input................................................................ 490

23.1. The MouseController......................................................................... 490

23.2. Combining Keyboard and Mouse Events.......................................... 493

23.3. Moving and Scaling Components with the MouseComponentMover 497

23.4. The MoveLabel.................................................................................. 500

23.5. Summary............................................................................................ 502

23.6 Exercises............................................................................................. 502

24. Reflection.................................................................... 504

24.1. ReflectUtil gets Information about an Instance................................... 505

24.2. Printing the Name of a Class.............................................................. 507

24.3. Printing an Array of Objects println(Object o[])............................... 507

24.4. Methods with N args?........................................................................ 508

24.5. Accessor Methods............................................................................ 509

24.6. Mutator Methods.............................................................................. 511

24.7. Converting a String into a Method..................................................... 512

24.8. Invoking a method from a String....................................................... 513

24.9. A Command Line Interpreter Using Reflection.................................. 514

24.10. ReflectUtil.java................................................................................. 515

24.11. Summary.......................................................................................... 520

24.12 Exercises........................................................................................... 521

25 Automatic Message Forwarding.................................... 524

25.1. Introduction........................................................................................ 525

25.2. Delegation vs. Multiple Inheritance.................................................... 531

25.3. Related work...................................................................................... 540

25.4. A Real-example.................................................................................. 543

25.5. The Delegate Synthesizer................................................................... 544

25.5.1. Implementation of the DelegationSynthesizer.............................. 546

25.5.2. The DelegateSynthesizer.............................................................. 550

25.6. Conclusions....................................................................................... 558

25.7. Exercises............................................................................................ 561

26. Introduction to Drawing Shapes.................................. 563

26.1. The Graphics Class............................................................................ 565

26.1.1. Class Summary............................................................................ 566

26.1.2. Class Methods............................................................................. 567

26.1.3. The Radar Class.......................................................................... 571

26.2. Spiral Components............................................................................. 574

26.2.1. The Spiral Class........................................................................... 575

26.2.2. ArchimedesÕ Spiral...................................................................... 576

26.2.3. FermatsÕ Spiral Component Class................................................ 578

26.3 The Poor ManÕs Thread and Damage Control.................................... 581

26.4. Exercises............................................................................................ 581

27. Business Graphics with Color and Images.................... 583

27.1. The Color Class................................................................................. 583

27.1.1. Class Summary............................................................................ 584

27.1.2. Class Usage................................................................................. 585

27.1.3. Adding Color to the Radar........................................................... 588

27.1.4. Building a Color Map.................................................................. 589

27.1.5. The Color Grid............................................................................. 591

27.2. The FontMetrics................................................................................. 594

27.2.1. Class Summary............................................................................ 595

27.2.2. Class Usage................................................................................. 595

27.2.3. How to Draw a String with a Background................................... 596

27.2.4. How to Draw a Vertical String.................................................... 597

27.3. Charts................................................................................................. 598

27.3.1. The LineGraph............................................................................. 598

27.3.2. The BarGraph.............................................................................. 600

27.3.3. The PieGraph............................................................................... 601

27.4. Images................................................................................................ 602

27.4.1. The ImageUtils class.................................................................... 604

27.4.2. The ImageFrame class.................................................................. 606

27.4.3. The WriteGIF class...................................................................... 609

27.5 The ImagePlanel.................................................................................. 610

27.6. Summary............................................................................................ 612

27.7. Exercises............................................................................................ 612

28. JDBC.......................................................................... 615

28.1. JDBC – What is it?............................................................................ 615

28.2. Multi-tier models of computation....................................................... 616

28.3. The Javasoft Framework.................................................................... 618

28.4. Opening a connection to a RDBMS................................................... 619

28.5. Making an instance of the SQL statement.......................................... 621

28.5.1 DatabaseWriter.............................................................................. 622

28.6. ResultSetMetaData............................................................................. 624

28.7. DataBaseMetaData............................................................................. 627

28.8. Code for the SQLBean....................................................................... 628

28.9 Summary............................................................................................. 633

28.10 Exercises........................................................................................... 635

29. Network Programming................................................ 636

29.1 The OSI Reference Model.................................................................. 637

29.2 The Client-Server Paradigm................................................................ 639

29.3 Mapping your first Domain Name...................................................... 640

29.4 Sockets and Ports............................................................................... 643

29.4.1. Reading your first socket, by building an Atomic Clock.............. 645

29.4.2. Serving your first socket, by building a Web Server................... 647

29.4.3. Using Sockets to send E-mail via SMTP..................................... 650

29.4.4. Sockets send Instances................................................................ 654

29.4.5. The Compute Server.................................................................... 657

29.4.6. Solving the Class Configuration Problem.................................... 660

29.5 Reading your first URL, by building a Quote Client........................... 663

29.6 Reading a URL, by building a Browser.............................................. 665

29.7 Help, I am behind a Firewall............................................................... 667

29.8 Summary............................................................................................. 669

29.9 Exercises............................................................................................. 670

30. Servlets....................................................................... 674

30.2 Your first servlet................................................................................. 675

30.3 Decoding the EchoEnvironmentServlet............................................... 678

30.4 The GuestBook................................................................................... 680

30.5 SQL and the Execute class.................................................................. 687

30.6 Server-side graphics............................................................................ 688

30.7 Get vs. Post and the RequestUtil........................................................ 692

30.8 Cookies and Sessions......................................................................... 694

30.8.1. Cookies and the Servlet API........................................................ 695

30.8.2. Session Management................................................................... 697

30.9 Exercises............................................................................................. 698

31. JSP............................................................................. 701

31.1. What is JSP?...................................................................................... 702

31.2. Why JSP?.......................................................................................... 703

31.3. How do you use JSP?........................................................................ 704

31.4. The Cookie Counter........................................................................... 706

31.5. Sniffing out the header in JSP............................................................ 709

31.6. Sending Mail from JSP...................................................................... 712

31.7. Multi-media Server Pages.................................................................. 714

31.8. Charts in MSP................................................................................... 716

31.9. Building a Meta-Search Engine.......................................................... 718

31.10. Building a fast off-line Meta-Search Engine.................................... 722

31.11. Building a Shopping Cart with Session Beans................................. 727

31.12 Summary........................................................................................... 730

31.13. Exercises.......................................................................................... 731

32. XML........................................................................... 733

32.1 What is XML?.................................................................................... 733

32.2 Why use XML?.................................................................................. 735

32.3 How do I install XML libraries?......................................................... 735

32.4 How do I define my own XML?........................................................ 736

32.5 Xml2Cart............................................................................................ 739

32.6 Csv2XML........................................................................................... 746

32.7 Displaying XML................................................................................. 754

32.8 Should I convert my RDBMS to XML?............................................. 755

32.9 The Problems and Limitations of XML.............................................. 756

32.10 Exercises........................................................................................... 756

33. More XML Techniques................................................ 759

33.1 Evolving XML.................................................................................... 759

33.2 The SAX and DOM Models.............................................................. 759

33.3 Where JAXP Fits In........................................................................... 761

33.4 Building a DOM Level 2 Application Using JAXP........................... 761

33.5 XML Namespaces.............................................................................. 767

33.6 XML Schemas.................................................................................... 769

33.7 Summary............................................................................................. 787

33.8 Exercises............................................................................................. 788

34. Bean Properties........................................................... 791

34.1 History of the problem........................................................................ 791

</note>........................................................................................................ 791

34.2 The Component................................................................................... 791

34.3 The Bean............................................................................................. 792

34.4 The Event............................................................................................ 793

34.5 Properties............................................................................................ 793

34.6 The InverterGate................................................................................. 794

34.7 The InverterGate Class........................................................................ 797

34.8 Code for the InverterGate Class.......................................................... 798

34.9 The console window output................................................................ 799

34.10 Summary........................................................................................... 800

34.11 Exercises........................................................................................... 800

35. Introspection............................................................... 801

35.1 History of Introspection...................................................................... 801

35.2 What is introspection?......................................................................... 801

35.3 BeanInfo............................................................................................. 802

35.4 SimpleBeanInfo.................................................................................. 803

35.5 Naming convention............................................................................. 803

35.6 IntrospectionException........................................................................ 804

35.7 Summary:............................................................................................ 805

35.8 Exercises:............................................................................................ 805

36. FeatureDescriptors...................................................... 807

36.1 What are FeatureDescriptors?............................................................. 807

36.2 FeatureDescriptor................................................................................ 809

36.3 BeanDescriptor................................................................................... 810

36.4 EventSetDescriptor............................................................................. 812

36.5 MethodDescriptor............................................................................... 816

36.6 ParameterDescriptor Methods............................................................. 818

36.7 PropertyDescriptor.............................................................................. 818

36.8 IndexedPropertyDescriptor................................................................. 821

36.9 BeanInfo Example............................................................................... 821

36.10 Summary........................................................................................... 822

36.11 Exercise............................................................................................. 823

37. Introduction to Enterprise Java Beans......................... 824

37.1. EJBs and Server-side architecture...................................................... 825

37.2. Requirements for an Enterprise Server-side architecture.................... 826

37.2.1. Support for component development........................................... 826

37.2.2. Scalability..................................................................................... 827

37.2.3. Portability..................................................................................... 827

37.3. Multi-tier applications........................................................................ 828

37.4. Competing architectures..................................................................... 830

37.5. Resources........................................................................................... 831

37.6. Summary............................................................................................ 831

37.7. Exercises............................................................................................ 831

38 EJB Container............................................................. 832

38.1 Introduction......................................................................................... 832

38.2 Requirements for J2EE-compliant EJB Containers............................. 833

38.2 Programming Restrictions for Enterprise Beans................................. 838

38.3 Four components of an EJB application.............................................. 840

38.3.1 Business logic: the EJB class........................................................ 840

38.3.2 Deployment descriptor.................................................................. 841

38.4 How interfaces are used...................................................................... 841

38.4.1 EJB Function call sequence.............................................................. 842

38.4.2 EJB Application Servers.................................................................. 844

38.5 Summary............................................................................................. 845

38.6 Exercises............................................................................................. 845

39 Session Beans............................................................... 846

39.1 Introduction......................................................................................... 846

39.2 Stateless session beans........................................................................ 848

39.3 Stateful session beans......................................................................... 849

39.4 How to write session beans................................................................ 849

39.4.3 How to connect to an EJB from a client........................................ 851

39.4.4 Example........................................................................................ 851

39.4.5 Java Naming and Directory Services (JNDI)................................ 857

39.4.6 Local Interfaces............................................................................. 859

39.5 Summary............................................................................................. 860

39.6 Exercises............................................................................................. 860

40. Session Bean Deployment............................................ 862

40.1 Introduction......................................................................................... 862

40.2 Deploying the EJB.............................................................................. 863

40.3 Start server.......................................................................................... 864

40.4 Create the Application......................................................................... 865

40.5 Add the Application Client.................................................................. 872

40.6 Deploy the Application....................................................................... 874

40.7 Run the client...................................................................................... 877

40.8 Run the EJB in a JSP.......................................................................... 878

40.8.1. Code the JSP................................................................................ 879

40.8.2. Deploy the JSP............................................................................ 880

40.9 Summary............................................................................................. 882

40.10 Exercises........................................................................................... 882

41 Entity Beans................................................................. 883

41.1 Introduction......................................................................................... 883

41.2 Design Considerations........................................................................ 883

41.3 Structure Of An Entity Bean............................................................... 884

41.4 Home Interface................................................................................... 885

41.4.1 Container Managed Persistence.................................................... 888

41.4.2 Bean Managed Persistence............................................................ 888

41.5 Summary............................................................................................. 892

41.6 Exercises............................................................................................. 892

42. EJB Security............................................................... 893

42.1. Introduction........................................................................................ 893

42.2. Security guidelines............................................................................. 896

42.3. Security for an enterprise application................................................. 897

42.4. The EJB security API........................................................................ 900

42.5. Summary............................................................................................ 901

42.6. Excercises.......................................................................................... 901

43. RMI............................................................................ 902

43.1. Introduction........................................................................................ 902

43.2. RMI Architecture............................................................................... 903

43.3. RMI................................................................................................... 904

43.4. Wrapping........................................................................................... 909

43.5. EJB and RMI/IIOP............................................................................ 911

43.6. Summary............................................................................................ 912

43.7. Excercises.......................................................................................... 913

44. Literature Cited.......................................................... 915

A.   Syntax...................................................................... 932

A.1 Introduction to Grammar...................................................................... 932

A.2 Reserved Words................................................................................... 940

A.3 Summary.............................................................................................. 942

B.    Java: The Good, The Bad and The Ugly..................... 944

B.1. Introduction......................................................................................... 945

B.2. The Java Language.............................................................................. 945

B.2.1. Java is Object-Oriented................................................................. 946

B.2.2. Java has Simula-like classes.......................................................... 948

B.2.3. Overloaded operators.................................................................... 949

B.3. Multiple inheritance............................................................................. 950

B.4. Arrays can be C-style or Java style..................................................... 952

B.5. Platform Independence: Compile Constantly....................................... 952

B.6. New APIs support Multimedia........................................................... 953

B.7. The Virtual Machine............................................................................ 954

B.8. Javadoc................................................................................................ 955

B.9. Performance........................................................................................ 955

B.10. Deployment....................................................................................... 956

B.11. Other languages................................................................................. 958

B.12. Conclusion........................................................................................ 958

B.13. Acknowledgements........................................................................... 959

C. How to Set-up your System for Java............................. 960

C.1. Running Java under Unix.................................................................... 961

C.2. Running Java Under Windows........................................................... 964

C.2.1 Setting the Class Path..................................................................... 964

C.2.2 Out of environment space............................................................... 964

C.3. Metrowerks IDE Usage...................................................................... 965

C.3.1 Making a new project..................................................................... 966

C.3.2 Changing the target class................................................................ 969

C.3.3 How to add a file in Java................................................................ 971

C.3.4 How to edit XML, XSD, etc.......................................................... 973

C.4. IntelliJ.................................................................................................. 974

C.5. Summary............................................................................................. 980

C.6. Exercises............................................................................................. 981

D. Coding Style................................................................ 983

D.1. Naming Conventions.......................................................................... 984

D.1.1. Method, Package and Variable Names.......................................... 984

D.1.2. Constant Names............................................................................ 985

D.1.3. Class and Interface Names............................................................ 985

D.1.4. Visibility....................................................................................... 986

D.2. Avoid ambiguous variable names....................................................... 986

D.3. Avoid shadowed variables.................................................................. 987

D.4. Formatting........................................................................................... 988

D.5. Organization........................................................................................ 989

D.6. Summary............................................................................................. 992

E. Learning to use Javadoc............................................... 993

E.1 Introduction to Javadoc......................................................................... 993

E.2 The tags of JavaDoc............................................................................. 994

E.2.1. @author......................................................................................... 995

E.2.2. {@docRoot.................................................................................... 995

E.2.2. @deprecated.................................................................................. 995

E.2.3. @exception.................................................................................... 996

E.2.4. @param......................................................................................... 996

E.2.5. @return.......................................................................................... 996

E.2.6. @see.............................................................................................. 996

E.2.7. @since........................................................................................... 997

E.2.8. @throws........................................................................................ 997

E.2.9. @version....................................................................................... 998

E.2.10. {@link......................................................................................... 998

E.3 Common HTML tags........................................................................... 998

E.4 How to Run JavaDoc........................................................................... 999

E.5 How to Run Javadoc using JDK........................................................ 1003

E.6 Summary............................................................................................ 1004

E.7 Exercises............................................................................................. 1005

F. Object-Oriented Design and Documentation............... 1008

F.1 The Three kinds of Documentation..................................................... 1009

F.2 The Software Architect....................................................................... 1010

F.3 Object-oriented Design....................................................................... 1011

F.4 Procedural Design.............................................................................. 1017

F.5 Flow Charts........................................................................................ 1020

F.6 Combining Procedural and Object-Oriented Design........................... 1023

F.7 Software Life-Cycle Models............................................................... 1025

F.8 Summary............................................................................................ 1029

F.9 Exercises............................................................................................. 1029

G. UML: Lingua Franca for Object-Oriented Design....... 1033

G.1 Introduction to UML.......................................................................... 1033

G.2 Static and Dynamic Characteristics.................................................... 1034

G.3 User Requirements............................................................................. 1035

G.4 Use Case Diagram............................................................................. 1035

G.5 Object Diagram.................................................................................. 1036

G.6 Class Diagram.................................................................................... 1039

G.7 Collaboration Diagram....................................................................... 1040

G.8 Sequence Diagram............................................................................. 1042

G.9 Statechart Diagram............................................................................. 1043

G.10 Summary.......................................................................................... 1044

G.11 Exercises.......................................................................................... 1046

H. Setting up JDBC........................................................ 1048

H.1. Opening a connection to a RDBMS.................................................. 1048

H.2. Setting a Data Source Name in Windows......................................... 1049

H.3. Using MySql.................................................................................... 1061

H.4. Using Oracle..................................................................................... 1066

H.4.1. Installation of Oracle JDBC Driver on Windows 98/NT............ 1066

H.4.2. Setting up CodeWarrior.............................................................. 1067

H.5 Summary............................................................................................ 1068

I. Setting up Servlets....................................................... 1070

I.1 Setting up a Servlet Engine.................................................................. 1070

I.1.1 Setting up Tomcat.......................................................................... 1071

I.1.2 Setting up JSWDK........................................................................ 1076

J. Bitwise Operators........................................................ 1083

J.1 Complement Operator........................................................................ 1085

J.2 AND, OR, XOR Operators................................................................ 1086

J.3 Shift Operators.................................................................................... 1087

J.4 Summary............................................................................................. 1092

J.5 Exercises............................................................................................. 1092

K. Collections................................................................. 1096

K.1. The Collections Framework.............................................................. 1096

K.2. The Collection Interface.................................................................... 1097

K.2.1 The Set Interface.......................................................................... 1098

K.2.2 The List Interface......................................................................... 1099

K.2.3 The Map Interface........................................................................ 1100

K.2.4 The Iterator................................................................................... 1101

K.3. Collection Implementations............................................................... 1103

K.3.1 The HashSet class........................................................................ 1104

K.3.2 Uniqueness means overriding the hashCode and equals methods 1105

K.3.3 Using getClass............................................................................. 1109

K.3.4 The TreeSet.................................................................................. 1110

K.3.5 Natural ordering by making your classes comparable.................. 1111

K.3.6 Total ordering by providing an explicit Comparator:.................... 1113

K.3.7 The ArrayList class...................................................................... 1116

K.3.8 The LinkList class........................................................................ 1120

K.3.9 The HashMap class...................................................................... 1122

K.3.10 About Hashing........................................................................... 1125

K.3.11 The TreeMap class..................................................................... 1131

K.3.12 The Collections class.................................................................. 1134

K.4. Conclusion........................................................................................ 1135

K.5. Excercises......................................................................................... 1136

K.6. References......................................................................................... 1137

L. Glossary..................................................................... 1139

M. Index......................................................................... 1153

Colophon........................................................................ 1189

Back Cover..................................................................... 1193

Reviews........................................................................... 1193

 

Illustrations

Figure 1.2-1 The Java model....................................................................................... 4

Figure 1.3-1 The Internet............................................................................................ 6

Figure 2-0. The Primitive Data Types......................................................................... 9

Figure 2.1-1. The Taxonomy of data types............................................................... 10

Figure 2.1-2. Primitive Data Type Summary............................................................ 11

Figure 2.2-1. Signed Integer Data Types.................................................................. 12

Figure 2.2-2. Constants in varying Radix................................................................. 13

Figure 3.1-1 Operators Precedence Hierarchy.......................................................... 23

Figure 3.2-1 Highest Order of Precedence Operators............................................... 30

Figure 3.3-1 Increment and Decrement Operators.................................................... 32

Figure 3.4-1 Arithmetic Operators............................................................................ 33

Figure 3.5-1 Assignment Operators.......................................................................... 34

Figure 3.7-1. A Truth-table....................................................................................... 43

Figure 4.2-1. Symbols in Various Numbering Systems........................................... 48

Figure 4.5-1. Successive Division converts decimal................................................. 50

Figure 4.5-2. Successive Division converts decimal to octal in Excel....................... 51

Figure 4.5-3. Successive Division converts decimal to hexadecimal......................... 51

Figure 4.5-4. A Demonstration of Repeated Division for Radix 2............................ 52

Figure 4.5.-5. Operations that Transform From One Base to Another...................... 52

Figure 5-0. Keyword Words in Control.................................................................... 56

Figure 5.1-1 Relational Operators............................................................................. 56

Figure 5.2-1 Equality Operators................................................................................ 57

Figure 5.3-1 Logical Operators................................................................................. 58

Figure 6-0. The Reference Data types of Chapter 6.................................................. 78

Figure 6.1-1 Variables and Methods in a Class....................................................... 80

Figure 6.5-1. The Hierarchy in the Mammal class................................................... 92

Figure 6.8-1. Interface Example showing A.K.O Hierarchy................................... 101

Figure 7-0. The modifiers in this Chapter............................................................... 112

Figure 7.2-1. Static Cannot Make Direct Reference to Dynamic............................. 119

Figure 8.1-1   Row Major vs. Column Major......................................................... 137

Figure 9.5-1. A Number Letter Map....................................................................... 174

Figure 10.0 The Exception Keywords.................................................................... 176

Figure 10.4-1. An overview of the java.lang exception classes............................... 182

Figure 10.4-2. An overview of the java.lang.RuntimeException classes................. 182

Figure 11.1-1. The Strict Java Filenames settings................................................... 198

Figure 11.3-1. Visibility.......................................................................................... 203

Figure 12-1. The Taxonomy of Nested Reference Data Types............................... 208

Figure 12.1-1. Only the Purchasing Department can make a P.O........................... 211

Figure 12.4-1. Access of an Outer class from an Inner class.................................. 219

Figure 13.1-1. A Multi-tasking Operating System.................................................. 228

Figure 13.1-2. True concurrency............................................................................. 230

Figure 13.1-3. Typical Speed-up versus Ideal Speed-up......................................... 232

Figure 13.3-1 The Finite State Machine Table for threads...................................... 235

Figure 13.3-2. The Life Cycle of a Thread.............................................................. 235

Figure 13.4.-1 The Thread class hierarchy.............................................................. 237

Figure 13.5-1. Default Threads and Groups........................................................... 240

Figure 13.7-1. Threads Found on Windows version of JDK 1.2.2........................ 245

Figure 13.7-2. Changing Thread Priorities.............................................................. 246

Figure 13.7-3. Setting Thread Names and Priorities............................................... 247

Figure 13.7-4. Launching Several Threads from the Main Group.......................... 248

Figure 13.7-5. Job Thread Output........................................................................... 249

Figure 14.2.4-1 The Swing Dialog......................................................................... 259

Figure 15.-1.  Sketch Depicting the Relationship Between the Streams.................. 275

Figure 15.-2.  Application for a Buffered Stream.................................................... 276

Figure 15.6-1. Compressed Serialization................................................................ 306

Figure 16.9-1. CSV Dialog in Excel....................................................................... 318

Figure 17.1-1 An image of the output File Dialog box........................................... 338

Figure 17.3-1. An Image Showing the Favorites.................................................... 341

Figure 17.3-2.......................................................................................................... 342

Figure 17.4-1 The Standard File Dialog Input........................................................ 345

Figure 17.4-2. Standard File Dialog for Output...................................................... 346

Figure 17.7-1. Digit-Symbol Map.......................................................................... 350

Figure 18.1-1 The Component Hierarchy............................................................... 353

Figure 18.2-1 The Basic Swing JComponent Hierarchy......................................... 354

Figure 18.2-2. The Swing/AWT Relationship........................................................ 355

Figure 18.5-1. A Message Dialog........................................................................... 358

Figure 18.5-2. A Sample Input Dialog.................................................................... 360

Figure 18.5-3. Sample Hi-Lo Output...................................................................... 361

Figure 18.6.1-1. Two buttons in FlowLayout......................................................... 364

Figure 18.6.1-2. Ten buttons in FlowLayout.......................................................... 364

Figure 18.6.1-3. Ten buttons in FlowLayout.......................................................... 365

Figure 18.6.2-1. GridLayout with ten buttons......................................................... 366

Figure 18.6.3-1. Some examples of BorderLayout................................................. 368

Figure 18.6.4-1 Mixing Layouts............................................................................. 370

Figure 18.6.5-1. Two Stacked Touch Tone Pads.................................................... 371

Figure 18.6.5-2. Two Unstacked Touch Tone Pads in Flow Layout...................... 372

Figure 18.6.6-1. Buttons will not expand to fill available space.............................. 374

Figure 18.6.6-2. Buttons will shrink if container gets small.................................... 374

Figure 18.6.6-3. Keeping the Aspect Ratio in the Grid........................................... 379

Figure 18.7.3-1 The Swing Dialog......................................................................... 387

Figure 18.8-1. The AddressBookPanel................................................................... 390

Figure 19.0-1 Model-View-Controller.................................................................... 395

Figure 19.0-2 Common Events............................................................................... 395

Figure 19.1-1. The ClosableJFrame........................................................................ 397

Figure 19.1-2 Listeners and Observables................................................................ 401

Figure 19.3-1. The RunButton................................................................................ 404

Figure 19.4.1-1. The Observable and Observer..................................................... 408

Figure 20.2-1. A Touch Tone Keypad.................................................................... 418

Figure 20.3. The RunTextField............................................................................... 420

Figure 20.4-1. BorderLayout and The TouchTones................................................ 422

Figure 20.5-1. An Image of the RunCheckBox...................................................... 424

Figure 20.6-1. An image of the RunTextField Frame............................................. 426

Figure 20.7-1 The RunList...................................................................................... 428

Figure 20.8.1-1 The RunScroll............................................................................... 430

Figure 20.8.2.-1 The RunSlider.............................................................................. 432

Figure 20.9-1 The RunRadio Button....................................................................... 433

Figure 20.10-1 Button Groups................................................................................ 435

Figure 20.11-1. Main Menus and the RunCheckBoxMenuItem............................. 437

Figure 20.12-1. RunRadioButtonMenuItem Groups.............................................. 439

Figure 20.15-1. The RunTab................................................................................... 449

Figure 20.15-2. The MenuBarPanel........................................................................ 451

Figure 20.15-3. The LabelPanel.............................................................................. 452

Figure 20.15-4 The CheckBoxPanel....................................................................... 453

Figure 20.15-5 The RunButtonPanel...................................................................... 454

Figure 20.17-1. The AddressBookPanel................................................................. 457

Figure 20.7-3. Label GUI....................................................................................... 460

Figure 20.7-4. Setting the Label Dimensions.......................................................... 461

Figure 21.1-1 The HtmlViewer............................................................................... 463

Figure 21.2-1 An Image of the Selector.................................................................. 472

Figure 21.4-1. The Guest Book Form..................................................................... 474

Figure 22.3-1 The Keypad...................................................................................... 482

Figure 22.4-1 The RunMenuItem Frame................................................................ 483

Figure 23.3-1. An Image of the MoveLabel............................................................ 497

Figure 23.3-2. After the Mouse Moved The Label................................................. 498

Figure 23.3-3. Scaling in the Horizontal Direction.................................................. 498

Figure 23.3-4. Scaling in the Vertical Direction...................................................... 498

Figure 23.4-1. String Query Dialog Box................................................................ 500

Figure 23.4-2. The new Label................................................................................. 501

Figure 24.9-1. The command Dialog Box............................................................... 515

Figure 24.12-1. The GUI Building Tool................................................................. 522

Figure 24.12-2. The component property display................................................... 523

Figure 25.5.1-1. The Disambiguation Dialog.......................................................... 547

Figure 26-1. Relationship between Drawing Methods............................................ 564

Figure 26.1-1 The Default Coordinate System of the Graphics Class..................... 565

Figure 26.1.3-1. The Radar..................................................................................... 571

Figure 26.1.3-2. Sketch of the Circle...................................................................... 572

Figure 26.2-1 Polar Coordinates............................................................................. 575

Figure 26.2.1-1. The Archimedes Spiral................................................................. 576

Figure 26.2.2-1. ArchimedesÕ Components............................................................ 578

Figure 26.2.3-1. FermatsÕ Spiral............................................................................. 579

Figure 27.1.2-1. A Packed Pixel............................................................................. 586

Figure 27.1.5-1 A Color Grid................................................................................. 591

Figure 27.1.5-2. JColorChooser Options................................................................ 593

Figure 27.2-1 Font Metrics..................................................................................... 594

Figure 27.2.4-1. A Target on the Radar.................................................................. 598

Figure 27.3.1-1. Sample Output from the LineGraph............................................. 599

Figure 27.3.2-1 Sample Bar Graph......................................................................... 600

Figure 27.3.2-2 A Thin Bar Graph......................................................................... 601

Figure 27.3.3-1. A Pie Chart................................................................................... 602

Figure 27.4-1. A Packed Pixel................................................................................ 602

Figure 27.4.2-1 The File Open Dialog.................................................................... 608

Figure 27.4.2-2. An Opened Image........................................................................ 608

Figure 27.4.2-3. The Result of a Grab.................................................................... 609

Figure 27.6-1. A sample plot.................................................................................. 613

Figure 27.6-2. The Tangent function....................................................................... 614

Figure 28.2-1 The Two-tier model of Computation................................................ 617

Figure 28.2-2 The Three-tier model of Computation............................................... 617

Figure 28.3-1. JDBC Drivers................................................................................. 619

Figure 29.1-2. An Internetworking System............................................................ 638

Figure 29.3-1. Top-level domains........................................................................... 640

Figure 29.4-1. The Socket Connection.................................................................... 643

Figure 29.4.2-1. The Socket and the ServerSocket................................................. 647

Figure 29.6-1. The HtmlViewer.............................................................................. 667

Figure 29.7-1. The Proxy Dialog in Netscape......................................................... 668

Figure 29.7-2. The Internet Explorer Proxy Setup.................................................. 668

Figure 30-1 Presentation Layer Programming........................................................ 675

Figure 30.2-1. The Servlet Examples Page............................................................. 676

Figure 30.2-2. Output from the TestWebServlet..................................................... 676

Figure 30.3-1. The Table of Variable for the Request............................................. 678

Figure 30.4-1. A Three Tier System....................................................................... 681

Figure 30.4-2. The Guest Book interface................................................................ 682

Figure 30.6-1. The Server Side Chart..................................................................... 689

Figure 30.9-1. A sample file listing......................................................................... 699

Figure 31.1-1. Stop and Wait Protocol.................................................................... 703

Figure 31.4.-1 The Cookie Counter........................................................................ 707

Figure 31.6-1. A Form for submitting comments................................................... 713

Figure 31.6-2. A Sample Constructive Comment................................................... 714

Figure 31.7-1 MSP Output..................................................................................... 715

Figure 31.8-1. A Server Size Chart......................................................................... 717

Figure 31.9-1. The Meta Search Engine Page......................................................... 719

Figure 31.10-1. The Off-line Meta Search.............................................................. 722

Figure 31.10-2. The Meta Search Confirmation...................................................... 723

Figure 31.11-1. The Current State of the Shopping Cart......................................... 727

Figure 31.11-2. The Cart after Removal of an Item................................................. 728

Figure 33.6-1. Browser Display............................................................................. 787

Figure 34.2-1. Component diagram........................................................................ 792

Figure 34.6-2. Inverter logic table........................................................................... 794

Figure 34.6-3. PropertyChangeEvent diagram........................................................ 795

Figure 36.9-1. A diagram showing the re............................................................... 821

Figure 38.1-1. Basic EJB container architecture...................................................... 838

Figure 38.4.1-1. Step 1: Get a Reference to the EJB Home Interface...................... 842

Figure 38.4.1-2. Step 2. The xyzBean creates the xyzBeanRemote......................... 843

Figure 38.4.1-3 Step 3. xyzBean andxyzBeanRemote........................................... 843

Figure 38.4.1-4. Step 4: The outside process and xyzBeanremote.......................... 844

Figure 39.4.4-1. J2ee -verbose output..................................................................... 853

Figure 40.3-1. J2EE -verbose Output..................................................................... 864

Figure 40.4-1 New Application Dialog box............................................................ 865

Figure 40.4-2. Application Deployment Tool Dialog Box...................................... 866

Figure 40.4-3 Edit Contents of DemoJAR dialog................................................... 868

Figure 40.4-4 The Enterprise Bean Wizard Dialog................................................. 869

Figure 40.4-5 The Security Dialog Box.................................................................. 871

Figure 40.4-6. Setting JNDI Names....................................................................... 872

Figure 40.5-1 Edit Contents of <Application Client> Dialog.................................. 873

Figure 40.5-2. Altering the Application Deployment Dialog.................................. 874

Figure 40.6-1. Pop-down Tools Menu................................................................... 875

Figure 40.6-2 Deployment Progress Dialog........................................................... 876

Figure 40.7-1. The testClient.bat output.................................................................. 877

Figure 40.7-2. The testClient.bat output After Password Entry.............................. 878

Figure 42.1-1. Flow of information in a J2EE architecture..................................... 894

Figure 43.1-1. The Role of RMI Protocol............................................................... 903

Figure 43.2-1. RMI architecture.............................................................................. 903

Figure 43.4-1 Inheritance from Remote interface.................................................... 910

Figure 43.5-1 Allowable and impermissible overloading in RMI/IIOP.................. 912

Figure A.2-1. Reserved words of Java................................................................... 940

Figure A.2-2. The Primitive Data types of Chapter 5.............................................. 940

Figure A.2-3. The Control Structures of Chapter 7................................................. 941

Figure A.2-4. The Reference Data types of Chapter 8............................................ 941

Figure A.2-5. The Static.......................................................................................... 941

Figure A.2-6. The Exception Keywords of Chapter 13.......................................... 942

Figure A.2-7. The Reference Related Keywords of Chapter 14.............................. 942

Figure A.2-8. Miscellaneous Keywords................................................................. 942

Figure C.3-1. The Installation Window................................................................... 966

Figure C.3.1-1 Selecting a New Project.................................................................. 967

Figure C.3.1-2 Project stationary, name selection................................................... 967

Figure C.3.1-3. Mac Users Must use JDK 1.1....................................................... 968

Figure C.3.1-4. The Project Messages Window..................................................... 968

Figure C.3.1-5. Project Window............................................................................. 969

Figure C.3.1-6. Java Console.................................................................................. 969

Figure C.3.2-1 Alter the main class......................................................................... 970

Figure C.3.2-2. The Project Window Showing the Source File.............................. 971

Figure C.3.2-3. The Altered Code........................................................................... 971

Figure C.3.3-1 Java Language Settings................................................................... 972

Figure C.3.3-2. Select File>New............................................................................ 973

Figure C.3.3-3. Select File>Text File...................................................................... 973

Figure C.3.3-1. The File Mappings Dialog............................................................. 974

Figure C.4-1. Initial Set-up Screen.......................................................................... 975

Figure C.4-2. The New Project Wizard Screen....................................................... 976

Figure C.4-3. Setting up the Jar Paths..................................................................... 977

Figure C.4-4. The ClassPath Panel......................................................................... 978

Figure C.4-5. The Run Dialog Box......................................................................... 979

Figure C.4-6. The Run Setup.................................................................................. 980

Figure D.5-1. Java Application Release Settings Dialog......................................... 990

Figure E.3-1. Summary of Common HTML Tags................................................. 999

Figure E.4-1. Selecting the Application Settings................................................... 1000

Figure E.4-2. Select the Target Settings................................................................ 1000

Figure E.4-3. Select the JavaDoc Pre Linker......................................................... 1001

Figure E.4-4. Set the JavaDoc output settings....................................................... 1001

Figure E.4-5. The Docs Output folder.................................................................. 1001

Figure E.4-6. Missing links to the gif images....................................................... 1002

Figure E.4-7. Standard gif images......................................................................... 1002

Figure F.2-1. Inputs are on the Left, Outputs on the Right................................... 1010

Figure F.3-1. Sample Action Diagram.................................................................. 1013

Figure F.3-2. The Cart.......................................................................................... 1013

Figure F.3-3. The Cart and the Goodie................................................................. 1014

Figure F.3-4. The Customer and the Book............................................................ 1015

Figure F.3-5. The Customer and the Book............................................................ 1016

Figure F.3-6. A is owned by B............................................................................. 1016

Figure F.4-1 A Finite State Machine Diagram for a Gum Machine..................... 1017

Figure F.4-2. Petri Net Primitives......................................................................... 1018

Figure F.4-3 Petri Diagram for a Gum Machine.................................................. 1019

Figure F.4-4 Petri-Table for a Gum Machine........................................................ 1020

Figure F.4-1. A Sample Flow Chart..................................................................... 1021

Figure F.4-2. A flow chart of a program that counts to 10.................................... 1022

Figure F.5-1. MUML + Flowcharts..................................................................... 1024

Figure F.7-1. 1031

Figure G.4-1 Use Case Diagram........................................................................... 1036

Figure G.5-1 Object Diagram............................................................................... 1038

Figure G.6-1 Class Diagram................................................................................. 1039

Figure G.7-1 Collaboration Diagram.................................................................... 1041

Figure G.8-1 Sequence Diagram........................................................................... 1043

Figure G.9-1 Statechart Diagram.......................................................................... 1044

Figure H.2-1. An Image of the ODBC Data Sources control panel...................... 1050

Figure H.2-3. Create New Data Source Dialog..................................................... 1052

Figure H.2-4 Microsoft Access Setup.................................................................. 1053

Figure H.2-5 The Selection of an MDB file.......................................................... 1054

Figure H.2-6. The addresses.mdb file................................................................... 1055

Figure H.2-7. The File Mapped to the DSN......................................................... 1056

Figure H.2-8. Using MyODBC............................................................................ 1057

Figure H.2-9. Accessing an ODBC Database....................................................... 1058

Figure H.2-11. The Machine Data Source Name.................................................. 1059

Figure H.2-12. Selecting the Tables of Interest..................................................... 1060

Figure H.2-13. The Tables are available in the database window.......................... 1060

Figure H.4.2-1. An image of the CodeWarrior Project Window........................... 1068

Figure I.1.1-1. Alter the Output Type................................................................... 1072

Figure I.1.1-2. Alter the Output Directory............................................................ 1073

Figure I.1.1-3. After the Output Directory is altered............................................. 1073

Figure I.1.1-4. The Location of the Classes for output.......................................... 1074

Figure I.1.1-5. Alter the Server.xml file................................................................ 1075

Figure I.1.1-6. Make sure reloadable=ÒtrueÓ......................................................... 1075

Figure I.1.1-7. Alter the Browser settings............................................................. 1076

Figure I.1.2-1. The Jar Files that Come with this Book........................................ 1077

Figure I.1.2-2. After the Jars are Added............................................................... 1078

Figure I.1.2-3. Setting the Target in CodeWarrior................................................. 1080

Figure I.1.2-4. The JSWDK Start Scripts............................................................. 1080

Figure I.1.2-5. The Servlet Home Page................................................................. 1081

Figure J.0-1 Bitwise Operators............................................................................. 1084

Figure J.2-1. Truth-table for the Inclusive OR...................................................... 1086

Figure J.2-2. Truth-table for the exclusive OR...................................................... 1087

Figure J.3-1.  A Packed Pixel............................................................................... 1091

Figure J.5-1. A Truth-table................................................................................... 1095

Figure K.1-1. The Collections Interfaces.............................................................. 1097

Figure K.2.1-1 Set A............................................................................................ 1099

Figure K.2.2-1. List B........................................................................................... 1100

Figure K.2.3-1. Map C......................................................................................... 1100




 


Honest criticism is hard to take,

particularly from a relative,

a friend,

an acquaintance,

or a stranger.

 

– Franklin P. Jones,

businessman (1887-1929)


 


 

 


 

About the Contributors

 

Douglas Lyon, Ph.D., is Chair of the Computer Engineering department at Fairfield University and President of DocJava, Inc. He has authored 3 books on Java and worked at the Jet Propulsion LaboratoryÕs Artificial Intelligence R&D department, AT&T Bell Laboratories, and was Chief Scientist for RAYTEL, Inc. He has been doing object-oriented programming since 1984. Dr. Lyon may be reached at the Computer Engineering Department, Fairfield University, North Benson Rd., Fairfield, CT 06430-5195, USA, Email: lyon@docjava.com, web: <http://www.docjava.com>.

Diane Asmus, Worked at Executone, and NOTARA as a Software Engineer in Visual Basic and Java since 1994. Diane can be reached at Fairfield University, North Benson Road., Fairfield, CT 06430-5195, Email: DianeJava@Yahoo.com.

Dr. Frances Grodzinsky is a Professor of Computer Science and Information Technology at Sacred Heart University in Fairfield, CT. She has co-authored The Anatomy of Programming Languages, is the editor of The Networking and Data Communications Laboratory Manual and author of several articles on Computer Ethics. Email: grodzinskyf@sacredheart.edu.

James Linn, M.S. Worked at Executone, IPC Inc., NeuVis and Hartford Technology Service Co. He has been an object-oriented architect and developer in C++ and Java since 1997. James can be reached at the Computer Engineering Department, Fairfield University, North Benson Rd., Fairfield, CT 06430-5195, USA, Email: jim@raptureart.com.

Maynard L. Marquis, M.S. (Yale University), teaches graduate Java courses in the School of Engineering at Fairfield University, and provides training to commercial companies for DocJava, Inc. He has many years of engineering experience in the aerospace industry. Maynard may be reached at the Computer Engineering Department, Fairfield University, North Benson Rd., Fairfield, CT 06430-5195, USA, Email: maynard_marquis@juno.com.

Allison McHenry has an MS degree in Software Engineering from Fairfield University. She is also a developer at INT Media Group and has been working with internet-related technologies since 1996. Allison may be reached at the Computer Engineering Department, Fairfield University, North Benson Rd., Fairfield, CT 06430-5195, USA, Email: amchenry_fagan@techie.com

Rodrigo A. Obando, Ph.D., is an Assistant Professor in the Information Systems and Operations Management at the Charles F. Dolan School of Business at Fairfield University. He has worked for the NASA Langley Research Center and the Jet Propulsion Laboratory as well as for several consulting companies and corporations. He currently works in the areas of Information Visualization and Data Mining. He started in Object-Oriented Programming in 1988. Rodrigo can be reached at: Assistant Professor of Information Systems and Operations Management, Charles F. Dolan School of Business, Fairfield University, North Benson Rd., Fairfield, CT 06430, Phone: (203)254-4000 Ext 2830, Email: RObando@fair1.fairfield.edu.

Thomas F. Rowland has a an MS degree in Software Engineering from Fairfield University, and holds a B.S. in Electrical Engineering. He has been involved in both hardware and software development since 1987, and has been developing object-oriented software for the past five years. Thomas works for DocJava, Inc. as a Member of Technical Staff. He may be reached at the Computer Engineering Department, Fairfield University, North Benson Rd., Fairfield, CT 06430-5195, USA, Email: tomorrwland@yahoo.com.