Wednesday, February 29, 2012

Ivor Horton’s Beginning Java 2 JDK 5 Edition


Ivor Horton’s Beginning Java 2 JDK 5 Edition







Ivor Horton’s Beginning Java 2 JDK 5 Edition


Ivor Horton’s Beginning Java 2 JDK 5 Edition



Description




What is this book about?

This book is a comprehensive introduction to the Java programming language, updated thoroughly (more than 35% new and updated) for the latest SDK 1.5 release. This book shows readers how to build real-world Java applications using the Java SDK. No previous programming experience is required. The author uses numerous step-by-step programming examples to guide readers through the ins and outs of Java development. In addition to fully covering new features of SDK 1.5, such as generic types, the author has also added new chapters on Java database programming with JDBC and Java programming with XML.








Details




  • Paperback: 1512 pages

  • Publisher: Wrox; 1 edition (December 31, 2004)

  • Language: English

  • ISBN-10: 0764568744

  • ISBN-13: 978-0764568749

  • Product Dimensions: 9.3 x 7.4 x 2.2 inches

  • Shipping Weight: 5 pounds

  • See More About: Ivor Horton's Beginning Java 2, JDK 5 Edition











 Contents:
About the Author v
Foreword ix
Acknowledgments xi
Introduction xxxvii
Chapter 1: Introducing Java 1
What Is Java All About? 1
Features of the Java Language 2
Learning Java 3
Java Programs 3
Learning Java—The Road Ahead 3
The Java Environment 4
Java Program Development 5
Installing the JDK 6
Compiling a Java Program 8
Executing a Java Application 9
Executing an Applet 10
Object-Oriented Programming in Java 12
So What Are Objects? 13
What Defines a Class of Objects? 14
Operating on Objects 17
Java Program Statements 19
Encapsulation 20
Classes and Data Types 20
Classes and Subclasses 21
Advantages of Using Objects 21
Java Program Structure 21
Java’s Class Library 22
Java Applications 24
Java and Unicode 27
Summary 27
Resources 28
Chapter 2: Programs, Data, Variables, and Calculation 29
Data and Variables 29
Naming Your Variables 30
Variable Names and Unicode 31
Variables and Types 31
Integer Data Types 31
Integer Literals 33
Declaring Integer Variables 34
Floating-Point Data Types 36
Floating-Point Literals 36
Declaring Floating-Point Variables 37
Fixing the Value of a Variable 37
Arithmetic Calculations 38
Integer Calculations 39
Producing Output 44
Integer Division and Remainders 45
The Increment and Decrement Operators 46
Computation with Shorter Integer Types 48
Errors in Integer Arithmetic 49
Floating-Point Calculations 49
Other Floating-Point Arithmetic Operators 50
Error Conditions in Floating-Point Arithmetic 51
Mixed Arithmetic Expressions 51
Explicit Casting 52
Automatic Type Conversions in Assignments 52
The op= Operators 53
Mathematical Functions and Constants 54
Impoting the Math Class Methods 59
Storing Characters 60
Character Escape Sequences 60
Character Arithmetic 61
Bitwise Operations 63
Using the AND and OR Operators 65
Using the Exclusive OR Operator 68
Shift Operations 70
Methods for Bitwise Operations 74
Variables with a Fixed Set of Integer Values 77
Boolean Variables 79
Operator Precedence 80
Program Comments 81
Documentation Comments 82
Accessing Array Elements 138
Reusing Array Variables 138
Initializing Arrays 139
Using a Utility Method to Initialize an Array 140
Initializing an Array Variable 141
Using Arrays 142
Using the Collection-Based for Loop with an Array 143
Arrays of Arrays 145
Arrays of Arrays of Varying Length 149
Multidimensional Arrays 151
Arrays of Characters 152
Strings 152
String Literals 153
Creating String Objects 153
Arrays of Strings 155
Operations on Strings 157
Joining Strings 157
Comparing Strings 161
Comparing Strings for Equality 163
String Interning 166
Checking the Start and End of a String 167
Sequencing Strings 167
Accessing String Characters 169
Extracting String Characters 170
Searching Strings for Characters 172
Searching for Substrings 173
Extracting Substrings 177
Tokenizing a String 179
Modified Versions of String Objects 182
Creating Character Arrays from String Objects 182
Using the Collection-Based for Loop with a String 183
Obtaining the Characters in a String as an Array of Bytes 183
Creating String Objects from Character Arrays 184
Mutable Strings 184
Creating StringBuffer Objects 185
The Capacity of a StringBuffer Object 186
Changing the String Length for a StringBuffer Object 188
Adding to a StringBuffer Object 189
Appending a Substring 189
Appending Basic Types 190
Finding the Position of a Substring 191
Replacing a Substring in the Buffer 192
Inserting Strings 192
Summary 83
Exercises 84
Chapter 3: Loops and Logic 85
Making Decisions 85
Making Comparisons 86
The if Statement 87
Statement Blocks 88
The else Clause 90
Nested if Statements 91
Comparing Enumeration Values 94
Logical Operators 95
Logical AND Operations 95
&& versus & 97
Logical OR Operations 98
Boolean NOT Operations 98
Character Testing Using Standard Library Methods 99
The Conditional Operator 100
The switch Statement 102
The General Case of the switch Statement 104
Variable Scope 108
Loops 111
Varieties of Loop 112
Counting Using Floating-Point Values 117
Nested Loops 121
The continue Statement 123
The Labeled continue Statement 123
Using the break Statement in a Loop 124
Breaking Indefinite Loops 127
The Labeled break Statement 128
Assertions 130
More Complex Assertions 132
Summary 133
Exercises 134
Chapter 4: Arrays and Strings 135
Arrays 135
Array Variables 136
Defining an Array 136
The Length of an Array 137
Extracting Characters from a Mutable String 193
Other Mutable String Operations 193
Creating a String Object from a StringBuffer Object 194
Summary 196
Exercises 197
Chapter 5: Defining Classes 199
What Is a Class? 200
Fields in a Class Definition 200
Methods in a Class Definition 202
Accessing Variables and Methods 203
Defining Classes 204
Defining Methods 205
Returning from a Method 206
The Parameter List 206
How Argument Values Are Passed to a Method 208
Final Parameters 209
Defining Class Methods 209
Accessing Class Data Members in a Method 209
The Variable this 210
Initializing Data Members 211
Using Initialization Blocks 212
Constructors 215
The Default Constructor 216
Creating Objects of a Class 217
Passing Objects to a Method 218
The Lifetime of an Object 219
Defining and Using a Class 220
Method Overloading 222
Multiple Constructors 223
Calling a Constructor from a Constructor 225
Duplicating Objects Using a Constructor 226
Using Objects 227
Creating a Point from Two Lines 230
Recursion 233
Understanding Packages 236
Packaging Up Your Classes 237
Packages and the Directory Structure 237
Compiling a Package 238
Accessing a Package 239
Using Extensions 240
Adding Classes from a Package to Your Program 241
Packages and Names in Your Programs 241
Impoting Static Class Members 242
Standard Packages 243
Standard Classes Encapsulating the Primitive Data Types 244
Controlling Access to Class Members 246
Using Access Attributes 246
Specifying Access Attributes 248
Choosing Access Attributes 250
Using Package and Access Attributes 251
Nested Classes 256
Static Nested Classes 257
Using a Non-Static Nested Class 262
Using a Nested Class Outside the Top-Level Class 263
Local Nested Classes 264
The finalize() Method 265
Native Methods 266
Summary 266
Exercises 267
Chapter 6: Extending Classes and Inheritance 269
Using Existing Classes 269
Class Inheritance 271
Inheriting Data Members 272
Hidden Data Members 273
Inherited Methods 273
Objects of a Derived Class 274
Deriving a Class 275
Derived Class Constructors 275
Calling the Base Class Constructor 276
Overriding a Base Class Method 277
Choosing Base Class Access Attributes 279
Polymorphism 279
Using Polymorphism 282
Multiple Levels of Inheritance 286
Abstract Classes 287
The Universal Superclass 288
The toString() Method 289
Determining the Type of an Object 289
Copying Objects 291
Methods Accepting a Variable Number of Arguments 295
Limiting the Types in a Variable Argument List 297
Casting Objects 298
When to Cast Objects 300
Identifying Objects 301
More on Enumerations 302
Adding Members to an Enumeration Class 303
Designing Classes 307
A Classy Example 307
Designing the PolyLine Class 309
A General-Purpose Linked List 313
Using the final Modifier 317
Interfaces 318
Encapsulating Constants in a Program 319
Constants in an Interface 320
Constants Defined in a Class 321
Interfaces Declaring Methods 323
A Partial Interface Implementation 324
Extending Interfaces 325
Interfaces and Multiple Inheritance 326
Using Interfaces 326
Interfaces and Polymorphism 327
Using Multiple Interfaces 333
Method Parameters of Interface Types 333
Nesting Classes in an Interface Definition 334
Interfaces and the Real World 334
Anonymous Classes 335
Summary 335
Exercises 337
Chapter 7: Exceptions 339
The Idea Behind Exceptions 339
Types of Exceptions 340
Error Exceptions 341
RuntimeException Exceptions 342
Other Subclasses of Exception 343
Dealing with Exceptions 344
Specifying the Exceptions a Method Can Throw 344
Handling Exceptions 345
The try Block 345
The catch Block 345
try catch Bonding 347
Multiple catch Blocks 349
The finally Block 350
Chapter 9: Accessing Files and Directories 401
Working with File Objects 401
Creating File Objects 402
Portable Path Considerations 404
Absolute and Relative Paths 404
Accessing System Properties 405
Setting System Properties 407
Testing and Checking File Objects 408
Querying Files and Directories 409
Filtering a File List 414
Creating and Modifying Files and Directories 417
Creating File Output Streams 419
Ensuring a File Exists 421
Avoiding Overwriting a File 423
FileDescriptor Objects 424
Summary 425
Exercises 425
Chapter 10: Writing Files 427
File I/O Basics 427
File Input and Output 429
Channels 430
Channel Operations 431
File Channels 433
Buffers 434
Buffer Capacity 434
Buffer Position and Limit 435
Setting the Position and Limit 437
Creating Buffers 438
View Buffers 439
Duplicating and Slicing Buffers 441
Creating Buffers by Wrapping Arrays 443
Wrapping Strings 445
Marking a Buffer 446
Buffer Data Transfers 446
Transferring Data into a Buffer 447
Using View Buffers 449
Preparing a Buffer for Output to a File 449
Writing to a File 451
File Position 453
Using a View Buffer to Load Data into a Byte Buffer 458
Structuring a Method 351
Execution Sequence 352
Normal Execution of a Method 355
Execution When an Exception Is Thrown 356
Execution When an Exception Is Not Caught 357
Nested try Blocks 358
Rethrowing Exceptions 359
Exception Objects 359
The Throwable Class 359
Standard Exceptions 362
Defining Your Own Exceptions 362
Defining an Exception Class 363
Throwing Your Own Exception 363
An Exception Handling Strategy 364
An Example of an Exception Class 364
Summary 368
Exercises 368Chapter 8: Understanding Streams 371
Streams and the New I/O Capability 371
Understanding Streams 372
Input and Output Streams 373
Binary and Character Streams 374
The Classes for Input and Output 375
Basic Input Stream Operations 375
Basic Output Stream Operations 379
Stream Readers and Writers 379
Using Readers 381
Using Writers 382
The Standard Streams 384
Getting Data from the Keyboard 384
Tokenizing a Stream 385
Customizing a Stream Tokenizer 387
Writing to the Command Line 392
The printf() Method 392
Formatting Numerical Data 394
Specifying the Width and Precision 395
Formatting Characters and Strings 396
The Locale Class 397
Formatting Data into a String 398
Summary 399
Exercises 399
Writing Varying Length Strings to a File 460
Using a Formatter Object to Load a Buffer 462
Direct and Indirect Buffers 466
Writing Numerical Data to a File 467
Writing Mixed Data to a File 471
Gathering-Write Operations 477
Summary 481
Exercises 482
Chapter 11: Reading Files 483
File Read Operations 483
Creating File Input Streams 484
File Channel Read Operations 485
Reading a Text File 488
Getting Data from the Buffer 489
Reading Binary Data 491
Reading Mixed Data 496
Compacting a Buffer 499
Copying Files 502
Random Access to a File 507
Read/Write Operations with a Single File Channel 512
Memory-Mapped Files 513
Locking a File 517
Locking Part of a File 519
Practical File Locking Considerations 519
Summary 523
Exercises 524
Chapter 12: Serializing Objects 525
Storing Objects in a File 525
Writing an Object to a File 526
Writing Basic Data Types to an Object Stream 528
Implementing the Serializable Interface 529
Conditions for Serialization 532
Transient Data Members of a Class 533
Reading an Object from a File 533
Determining the Class of a Deserialized Object 537
Reading Basic Data from an Object Stream 538
Using Object Serialization 538
Serializing Classes Yourself 541
Serialization Problems and Complications 542
Resetting an Object Output Stream 544
Summary 545
Exercises 546
Chapter 13: Generic Class Types 547
What Are Generic Types? 547
Defining a Generic Class Type 548
Implementing a Generic Type 550
Instantiating a Generic Type 551
Using Primitive Type Wrapper Class Types as Arguments 555
The Runtime Type of Generic Type Instances 557
Relationships between Generic Type Instances 559
Multiple Type Parameters 559
Type Parameter Scope 560
Static Fields in a Generic Type 560
Type Parameter Bounds 561
Generic Types and Generic Interfaces 565
Enabling the Collection-Based for Loop 565
Implementing an Iterator Capability 567
A Parameterized Type for Binary Trees 569
Defining the Generic Type 571
Hidden Constraints in the BinaryTree<> Type 579
Variables of a Raw Type 580
Using Wildcards as Type Parameter Arguments 582
Constraints on a Wildcard 584
More on the Class Class 587
Arrays and Parameterized Types 588
Parameterized Methods 592
Generic Constructors 595
Parameterized Types and Inheritance 598
Summary 599
Exercises 600
Chapter 14: The Collections Framework 601
Understanding the Collections Framework 601
Collections of Objects 602
Sets 603
Sequences 604
Maps 605
Hashing 606
Iterators 606
List Iterators 608
Collection Classes 610
Collection Interfaces 614
Using Vectors 615
Creating a Vector 616
The Capacity and Size of a Vector 618
Storing Objects in a Vector 620
Retrieving Objects from a Vector 621
Accessing Elements in a Vector through a List Iterator 621
Extracting All the Elements from a Vector 622
Removing Objects from a Vector 623
Searching a Vector 625
Applying Vectors 626
Sorting a Collection 630
Stack Storage 632
Linked Lists 638
Using Maps 640
The Hashing Process 640
Using Your Own Class Objects as Keys 642
Generating Hashcodes 642
Creating a HashMap Container 643
Storing, Retrieving, and Removing Objects 644
Processing all the Elements in a Map 646
Summary 657
Exercises 658
Chapter 15: A Collection of Useful Classes 659
Utility Methods for Arrays 659
Filling an Array 660
Comparing Arrays 661
Sorting Arrays 662
Searching Arrays 666
Observable and Observer Objects 670
Defining Classes of Observable Objects 671
Observable Class Methods 671
Generating Random Numbers 675
Random Operations 676
Dates and Times 678
The Date Class 679
Interpreting Date Objects 679
Obtaining a Date Object from a String 684
Gregorian Calendars 684
Setting the Date and Time 686
Getting Date and Time Information 687
Modifying Dates and Times 688
Comparing Calendars 688
Regular Expressions 691
Defining Regular Expressions 691
Creating a Pattern 692
Creating a Matcher 693
Searching a String 694
Matching an Entire String 696
Defining Sets of Characters 697
Matching Boundaries 700
Using Quantifiers 701
Tokenizing a String 703
Search and Replace Operations 705
Using Capturing Groups 708
Juggling Captured Text 710
Using a Scanner 714
Creating Scanner Objects 714
Getting Input from a Scanner 715
Testing for Tokens 717
Defining Your Own Patterns for Tokens 718
Summary 720
Exercises 721
Chapter 16: Threads 723
Understanding Threads 723
Creating Threads 726
Stopping a Thread 731
Connecting Threads 733
Thread Scheduling 733
Implementing the Runnable Interface 734
Managing Threads 736
Synchronization 737
Synchronized Methods 737
Synchronizing Statement Blocks 749
Deadlocks 755
Communicating between Threads 756
Using wait() and notifyAll() in the Bank Program 758
Thread Priorities 761
Using Thread Priorities 762
Summary 765
Exercises 766
Chapter 17: Creating Windows 767
Graphical User Interfaces in Java 767
Model-View-Controller (MVC) Architecture 768
Creating a Window 770
Components and Containers 775
Window and Frame Components 776
Window Panes 777
Basics of Components 779
Component Attributes 779
The Size and Position of a Component 780
Points and Rectangles 784
Point Objects 784
Rectangle Objects 785
Visual Characteristics of a Component 788
Defining Color 789
System Colors 791
Creating Cursors 791
Selecting Fonts 792
Swing Components 797
Buttons 798
Menus 799
Text Components 800
Other Swing Components 800
Using Containers 801
Adding Components to a Container 802
Container Layout Managers 803
The Flow Layout Manager 805
Changing the Gap 807
Using a Border Layout Manager 811
Using a Card Layout Manager 813
Using a Grid Layout Manager 815
Using a BoxLayout Manager 817
Struts and Glue 820
Using a GridBagLayout Manager 825
GridBagConstraints Instance Variables 826
Using a SpringLayout Manager 834
Understanding Constraints 835
Defining Constraints 836
Setting Constraints for a Component 837
Adding a Menu to a Window 843
Creating JMenu and JMenuItem 843
Creating a Menu 844
Adding Menu Items to a Menu 847
Adding a Shortcut for a Menu Item 852
More on Applets 854
Converting an Application to an Applet 856
Summary 857
Exercises 858
Chapter 18: Handling Events 861
Window-Based Java Programs 861
Event-Driven Programs 862
The Event-Handling Process 863
Avoiding Deadlocks in GUI Code 865
Event Classes 867
Low-Level Event Classes 868
Making a Window Handle Its Own Events 870
Enabling Other Low-level Events 873
Low-Level Event Listeners 874
The WindowListener Interface 875
The WindowFocusListener Interface 875
The WindowStateListener Interface 875
The MouseListener Interface 876
The MouseMotionListener Interface 876
The MouseWheelListener Interface 876
The KeyListener Interface 876
The FocusListener Interface 877
Using Adapter Classes 879
Semantic Events 882
Semantic Event Listeners 883
Semantic Event Handling in Applets 884
Alternative Event-Handling Approaches 893
Handling Low-Level and Semantic Events 895
Semantic Event Listeners in an Application 896
Listening to Menu Items 896
Fixing the Color Menu Check Marks 902
Using Actions 902
The Action Interface 903
Using Actions as Menu Items 905
Defining Action Classes 906
Adding a Toolbar 911
Adding Buttons to a Toolbar 912
Adding Icons 914
Fixing the Menus 918
Adding Tooltips 920
Disabling Actions 922
Summary 924
Exercises 924
Chapter 19: Drawing in a Window 927
Using the Model/View Architecture 927
Coordinate Systems in Components 931
Drawing on a Component 933
Graphics Contexts 934
The Drawing Process 937
Rendering Operations 938
Shapes 939
Classes Defining Points 939
Lines and Rectangles 941
Combining Rectangles 943
Testing Rectangles 944
Arcs and Ellipses 947
Curves 950
Complex Paths 960
Filling Shapes 966
Gradient Fill 968
Managing Shapes 972
Storing Shapes in the Model 974
Drawing Shapes 975
Drawing Using the Mouse 976
Handling Mouse Events 977
Handling Mouse Button Press Events 979
Using XOR Mode 980
Handling Mouse Dragging Events 981
Handling Button Release Events 983
Locating the Mouse Cursor Using MouseInfo Class Methods 985
Defining Your Own Shape Classes 985
Defining Lines 986
Defining Rectangles 988
Defining Circles 990
Drawing Curves 993
Summary 996
Exercises 996
Chapter 20: Extending the GUI 997
Creating a Status Bar 997
Using Dialogs 1002
Modal and Non-Modal Dialogs 1003
A Simple Modal Dialog 1005
Instant Dialogs 1009
Input Dialogs 1011
Using a Dialog to Create Text Elements 1013
A Font Selection Dialog 1023
Creating the Font Dialog Buttons 1026
Adding the Data Pane 1027
Implementing the Font List 1028
Displaying the Selected Font 1031
Using a Split Pane 1031
Using a Spinner 1033
Using Radio Buttons to Select the Font Style 1035
Listening for Radio Buttons 1036
Pop-Up Menus 1039
Displaying a Pop-Up Menu 1040
Implementing a Context Menu 1044
Tracking Mouse Moves 1045
Defining the Other Context Menu 1048
Deleting Elements 1050
Implementing the Send-to-Back Operation 1051
Transforming the User Coordinate System 1052
The AffineTransform Class 1054
Modifying the Transformation for a Graphics Context 1056
Creating AffineTransform Objects 1058
Translating Lines 1060
Translating Rectangles 1062
Translating Circles 1063
Translating Curves 1063
Translating Text 1064
Moving an Element 1065
Rotating Elements 1070
Choosing Custom Colors 1074
Summary 1076
Exercises 1077
Chapter 21: Filing and Printing Documents 1079
Serializing the Sketch 1080
Implementing the Serializable Interface 1083
Serializing the List of Elements 1083
Serializing Lines 1084
Serializing Rectangles 1085
Serializing Circles 1086
Serializing Curves 1086
Serializing Text 1089
Supporting the File Menu 1089
Using a File Chooser 1090
File Save Operations 1091
Implementing the Save Operation 1093
Writing a Sketch to a File 1095
Creating a File Filter 1097
File Save As Operations 1099
File Open Operations 1100
Starting a New Sketch 1103
Preventing Data Loss on Close 1104
Printing in Java 1106
Creating and Using PrinterJob Objects 1109
Displaying a Print Dialog 1110
Starting the Printing Process 1111
Printing Pages 1112
The PageFormat Class 1114
Printing the Whole Sketch 1117
Scaling the Sketch to Fit 1120
Printing in Landscape Orientation 1123
Improving the Printing Facilities 1125
Implementing Page Setup 1126
Using the Java Print Dialog 1130
Setting Print Request Attributes Programmatically 1132
Multipage Document Printing 1134
Implementing the Pageable Interface 1134
Creating PageFormat Objects 1135
Dealing with Paper 1136
Printing Using a Book 1143
Printing Swing Components 1146
Summary 1149
Exercises 1150




Ivor Horton’s Beginning Java 2 JDK 5 Edition Book review

Operating Systems : Design and Implementation - Textbook Only [Student Edition]


Operating Systems : 

Design and Implementation - Textbook Only

 [Student Edition]



Description

The Second Edition of this best-selling introductory operating systems text is the only textbook that successfully balances theory and practice. The authors accomplish this important goal by first covering all the fundamental operating systems concepts such as processes, interprocess communication, input/output, virtual memory, file systems, and security. These principles are then illustrated through the use of a small, but real, UNIX-like operating system called MINIX that allows students to test their knowledge in hands-on system design projects. Each book includes a CD-ROM that contains the full MINIX source code and two simulators for running MINIX on various computers.


Details

  • Hardcover: 939 pages
  • Publisher: Prentice Hall, Inc.; 2nd Edition 1997 edition (1997)
  • Language: English
  • ISBN-10: 0003458903
  • ISBN-13: 978-0003458909
  • Shipping Weight: 4 pounds


Contents:
CHAPTER 1 INTRODUCTION 1

1.1 WHAT IS AN OPERATING SYSTEM? 3
1.1.1 The Operating System as an Extended Machine 3
1.1.2 The Operating System as a Resource Manager 4

1.2 HISTORY OF OPERATING SYSTEMS 5
1.2.1 The First Generation (1945-55) Vacuum Tubes and Plugboards 6
1.2.2 The Second Generation (1955-65) Transistors and Batch Systems 6
1.2.3 The Third Generation (1965-1980): ICs and Multiprogramming 8
1.2.4 The Fourth Generation (1980-Present): Personal Computers 12
1.2.5 History of MINIX 13

1.3 OPERATING SYSTEM CONCEPTS 15
1.3.1 Processes 15
1.3.2 Files 17
1.3.3 The Shell 20

1.4 SYSTEM CALLS 21
1.4.1 System Calls for Process Management 22
1.4.2 System Calls for Signaling 26
1.4.3 System Calls for File Management 28
1.4.4 System Calls for Directory Management 33
1.4.5 System Calls for Protection 35
1.4.6 System Calls for Time Management 36

1.5 OPERATING SYSTEM STRUCTURE 37
1.5.1 Monolithic Systems 37
1.5.2 Layered Systems 39
1.5.3 Virtual Machines 40
1.5.4 Client-Server Model 42

1.6 OUTLINE OF THE REST OF THIS BOOK 44

1.7 SUMMARY 44


CHAPTER 2 PROCESSES 47

2.1 INTRODUCTION TO PROCESSES 47
2.1.1 The Process Model 48
2.1.2 Implementation of Processes 52
2.1.3 Threads 53

2.2 INTERPROCESS COMMUNICATION 57
2.2.1 Race Conditions 57
2.2.2 Critical Sections 58
2.2.3 Mutual Exclusion with Busy Waiting 59
2.2.4 Sleep and Wakeup 63
2.2.5 Semaphores 66
2.2.6 Monitors 68
2.2.7 Message Passing 72

2.3 CLASSICAL IPC PROBLEMS 75
2.3.1 The Dining Philosophers Problem 75
2.3.2 The Readers and Writers Problem 77
2.3.3 The Sleeping Barber Problem 80

2.4 PROCESS SCHEDULING 82
2.4.1 Round Robin Scheduling 84
2.4.2 Priority Scheduling 85
2.4.3 Multiple Queues 86
2.4.4 Shortest Job First 87
2.4.5 Guaranteed Scheduling 89
2.4.6 Lottery Scheduling 89
2.4.7 Real-Time Scheduling 90
2.4.8 Two-level Scheduling 92
2.4.9 Policy versus Mechanism 93

2.5 OVERVIEW OF PROCESSES IN MINIX 93
2.5.1 The Internal Structure of MINIX 93
2.5.2 Process Management in MINIX 95
2.5.3 Interprocess Communication in MINIX 97
2.5.4 Process Scheduling in MINIX 98

2.6 IMPLEMENTATION OF PROCESSES IN MINIX 98
2.6.1 Organization of the MINIX Source Code 99
2.6.2 The Common Header Files 102
2.6.3 The MINIX Header Files 107
2.6.4 Process Data Structures and Header Files 112
2.6.5 Bootstrapping MINIX 120
2.6.6 System Initialization 122
2.6.7 Interrupt Handling in MINIX 128
2.6.8 Interprocess Communication in MINIX 137
2.6.9 Scheduling in MINIX 140
2.6.10 Hardware-Dependent Kernel Support 142
2.6.11 Utilities and the Kernel Library 145

2.7 SUMMARY 147


CHAPTER 3 INPUT/OUTPUT 153

3.1 PRINCIPLES OF I/O HARDWARE 154
3.1.1 I/O Devices 154
3.1.2 Device Controllers 155
3.1.3 Direct Memory Access (DMA) 157

3.2 PRINCIPLES OF I/O SOFTWARE 159
3.2.1 Goals of the I/O Software 159
3.2.2 Interrupt Handlers 161
3.2.3 Device Drivers 161
3.2.4 Device-Independent I/O Software 162
3.2.5 User-Space I/O Software 164

3.3 DEADLOCKS 166
3.3.1 Resources 167
3.3.2 Principles of Deadlock 168
3.3.3 The Ostrich Algorithm 170
3.3.4 Detection and Recovery 172
3.3.5 Deadlock Prevention 173
3.3.6 Deadlock Avoidance 175

3.4 OVERVIEW OF I/O IN MINIX 179
3.4.1 Interrupt Handlers in MINIX 180
3.4.2 Device Drivers in MINIX 181
3.4.3 Device-Independent I/O Software in MINIX 185
3.4.4 User-level I/O Software in MINIX 185
3.4.5 Deadlock Handling in MINIX 186

3.5 BLOCK DEVICES IN MINIX 187
3.5.1 Overview of Block Device Drivers in MINIX 187
3.5.2 Common Block Device Driver Software 190
3.5.3 The Driver Library 193

3.6 RAM DISKS 195
3.6.1 RAM Disk Hardware and Software 196
3.6.2 Overview of the RAM Disk Driver in MINIX 197
3.6.3 Implementation of the RAM Disk Driver in MINIX 198

3.7 DISKS 200
3.7.1 Disk Hardware 200
3.7.2 Disk Software 202
3.7.3 Overview of the Hard Disk Driver in MINIX 208
3.7.4 Implementation of the Hard Disk Driver in MINIX 211
3.7.5 Floppy Disk Handling 220

3.8 CLOCKS 222
3.8.1 Clock Hardware 223
3.8.2 Clock Software 224
3.8.3 Overview of the Clock Driver in MINIX 227
3.8.4 Implementation of the Clock Driver in MINIX 230

3.9 TERMINALS 235
3.9.1 Terminal Hardware 235
3.9.2 Terminal Software 240
3.9.3 Overview of the Terminal Driver in MINIX 249
3.9.4 Implementation of the Device-Independent Terminal Driver 264
3.9.5 Implementation of the Keyboard Driver 282
3.9.6 Implementation of the Display Driver 288

3.10 THE SYSTEM TASK IN MINIX 296

3.11 SUMMARY 304




CHAPTER 4 MEMORY MANAGEMENT 309

4.1 BASIC MEMORY MANAGEMENT 310
4.1.1 Monoprogramming without Swapping or Paging 310
4.1.2 Multiprogramming wiith Fixed Partitions 311

4.2 SWAPPING 313
4.2.1 Memory Management with Bit Maps 316
4.2.2 Memory Management with Linked Lists 317

4.3 VIRTUAL MEMORY 319
4.3.1 Paging 319
4.3.2 Page Tables 322
4.3.3 TLBs-Translation Lookaside Buffers 327
4.3.4 Inverted Page Tables 330

4.4 PAGE REPLACEMENT ALGORITHMS 331
4.4.1 The Optimal Page Replacement Algorithm 331
4.4.2 The Not-Recently-Used Page Replacement Algorithm 332
4.4.3 The First-In, First-Out (FIFO) Page Replacement Algorithm 333
4.4.4 The Second Chance Page Replacement Algorithm 333
4.4.5 The Clock Page Replacement Algorithm 334
4.4.6 The Least Recently Used (LRU) Page Replacement Algorithm 334
4.4.7 Simulating LRU in Software 336

4.5 DESIGN ISSUES FOR PAGING SYSTEMS 338
4.5.1 The Working Set Model 338
4.5.2 Local versus Global Allocation Policies 339
4.5.3 Page Size 341
4.5.4 Virtual Memory Interface 343

4.6 SEGMENTATION 343
4.6.1 Implementation of Pure Segmentation 347
4.6.2 Segmentation with Paging: MULTICS 348
4.6.3 Segmentation with Paging: The Intel Pentium 352

4.7 OVERVIEW OF MEMORY MANAGEMENT IN MINIX 356
4.7.1 Memory Layout 358
4.7.2 Message Handling 361
4.7.3 Memory Manager Data Structures and Algorithms 363
4.7.4 The FORK, EXIT, and WAIT System Calls 367
4.7.5 The EXEC System Call 368
4.7.6 The BRK System Call 371
4.7.7 Signal Handling 372
4.7.8 Other System Calls 378

4.8 IMPLEMENTATION OF MEMORY MANAGEMENT IN MINIX 379
4.8.1 The Header Files and Data Structures 379
4.8.2 The Main Program 382
4.8.3 Implementation of FORK, EXIT, and WAIT 382
4.8.4 Implementation of EXEC 385
4.8.5 Implementation of BRK 386
4.8.6 Implementation of Signal Handling 387
4.8.7 Implementation of the Other System Calls 393
4.8.8 Memory Manager Utilities 394

4.9 SUMMARY 396




CHAPTER 5 FILE SYSTEMS 401

5.1 FILES 402
5.1.1 File Naming 402
5.1.2 File Structure 404
5.1.3 File Types 405
5.1.4 File Access 407
5.1.5 File Attributes 408
5.1.6 File Operations 409

5.2 DIRECTORIES 410
5.2.1 Hierarchical Directory Systems 411
5.2.2 Path Names 412
5.2.3 Directory Operations 414

5.3 FILE SYSTEM IMPLEMENTATION 415
5.3.1 Implementing Files 415
5.3.2 Implementing Directories 419
5.3.3 Disk Space Management 422
5.3.4 File System Reliability 424
5.3.5 File System Performance 429
5.3.6 Log-Structured File Systems 432

5.4 SECURITY 434
5.4.1 The Security Environment 434
5.4.2 Famous Security Flaws 436
5.4.3 Generic Security Attacks 439
5.4.4 Design Principles for Security 441
5.4.5 User Authentication 442

5.5 PROTECTION MECHANISMS 446
5.5.1 Protection Domains 446
5.5.2 Access Control Lists 448
5.5.3 Capabilities 450
5.5.4 Covert Channels 451

5.6 OVERVIEW OF THE MINIX FILE SYSTEM 453
5.6.1 Messages 454
5.6.2 File System Layout 454
5.6.3 Bit Maps 458
5.6.4 I-nodes 460
5.6.5 The Block Cache 461
5.6.6 Directories and Paths 463
5.6.7 File Descriptors 465
5.6.8 File Locking 467
5.6.9 Pipes and Special Files 467
5.6.10 An Example: The READ System Call 469

5.7 IMPLEMENTATION OF THE MINIX FILE SYSTEM 470
5.7.1 Header Files and Global Data Structures 470
5.7.2 Table Management 474
5.7.3 The Main Program 482
5.7.4 Operations on Individual Files 485
5.7.5 Directories and Paths 493
5.7.6 Other System Calls 498
5.7.7 The I/O Device Interface 501
5.7.8 General Utilities 503

5.8 SUMMARY 503

CHAPTER 6 READING LIST AND BIBLIOGRAPHY 507

6.1 SUGGESTIONS FOR FURTHER READING 507
6.1.1 Introduction and General Works 507
6.1.2 Processes 509
6.1.3 Input/Output 510
6.1.4 Memory Management 511
6.1.5 File Systems 511

6.2 ALPHABETICAL BIBLIOGRAPHY 512

APPENDIX A MINIX SOURCE CODE LISTING 521

APPENDIX B INDEX TO FILES 905

APPENDIX C INDEX TO SYMBOLS 909

INDEX 925 


See More About: Operating Systems : Design And Implementation - Textbook Only


J2ME: The Complete Reference

J2ME: The Complete Reference




Description

J2ME allows developers to use Java and the J2ME wireless toolkit to create applications and programs for wireless and mobile devices. This is the most comprehensive resource for Java developers seeking to understand and utilise J2ME when building mobile applications and services. - Understand the core fundamentals of J2ME - Discover what makes J2ME unique with coverage on advanced topics like Mobile Information Device Profile (MIDP) and Connected Limited Device Configuration (CLDC) - Comprehend how to build robust mobile applications with examples on J2ME supported software development kits, databases, web services, and more - Learn from other people's mistakes with coverage on J2ME Best Practices and security

About the Author

James Keogh (New York, NY) is a faculty member of Columbia University where teaches a breadth of computer science courses in their CTA program. Keogh developed the Electronic Commerce track for Columbia University and was the first person to chair the track.


Product Details

  • James Keogh (New York, NY)
  • Paperback: 768 pages
  • Publisher: McGraw-Hill (February 27, 2003)
  • Language: English
  • ISBN-10: 0072227109
  • ISBN-13: 978-0072227109
  • Product Dimensions: 9.3 x 7.4 x 1.8 inches



Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Part I
J2ME Basics
1 J2ME Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Java 2 Micro Edition and the World of Java . . . . . . . . . . . . . . . . . . . . 4
Enter Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Java Virtual Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
J2EE and J2SE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
The Birth of J2EE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Back to the Future: J2ME . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Inside J2ME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
How J2ME Is Organized . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
J2ME and Wireless Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
What J2ME Isn’t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Other Java Platforms for Small Computing Devices . . . . . . . . . . . . 16
2 Small Computing Technology . . . . . . . . . . . . . . . . . . . . . 17
Wireless Technology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Radio Transmission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Limitations of Radio Transmissions . . . . . . . . . . . . . . . . . . . 20
Radio Data Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Data Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Microwave Technology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Satellite Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Mobile Radio Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Cellular Telephone Networks . . . . . . . . . . . . . . . . . . . . . . . . 26
Digital Wireless Transmissions . . . . . . . . . . . . . . . . . . . . . . . 28
Cell Phones and Text Input . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Messaging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Personal Digital Assistants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Mobile Power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Set-Top Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Inside Look at a Set-Top Box . . . . . . . . . . . . . . . . . . . . . . . . . 33
Smart Cards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3 J2ME Architecture and Development Environment . . . 35
J2ME Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Small Computing Device Requirements . . . . . . . . . . . . . . . . . . . . . . 37
Run-Time Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Inside the Java Archive File . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Inside the Java Application Descriptor File . . . . . . . . . . . . . 40
MIDlet Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Event Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
User Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Device Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Java Language for J2ME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
J2ME Software Development Kits . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Hello World J2ME Style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Compiling Hello World . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Running Hello World . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Deploying Hello World . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
What to Do When Your MIDlet Doesn’t
Work Properly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Multiple MIDlets in a MIDlet Suite . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
J2ME Wireless Toolkit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Building and Running a Project . . . . . . . . . . . . . . . . . . . . . . 61
Hello World Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
MIDlets on the Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
J2ME Best Practices and Patterns . . . . . . . . . . . . . . . . . . . 71
The Reality of Working in a J2ME World . . . . . . . . . . . . . . . . . . . . . . 72
Best Practices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Keep Applications Simple . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Keep Applications Small . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Limit the Use of Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Off-Load Computations to the Server . . . . . . . . . . . . . . . . . 76
Manage Your Application’s Use of a
Network Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Simplify the User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Use Local Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Don’t Concatenate Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Avoid Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Thread Group Class Workaround . . . . . . . . . . . . . . . . . . . . . 83
Upload Code from the Web Server . . . . . . . . . . . . . . . . . . . . 83
Reading Settings from JAD Files . . . . . . . . . . . . . . . . . . . . . . 84
Populating Drop-down Boxes . . . . . . . . . . . . . . . . . . . . . . . . 85
Minimize Network Traffic . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Dealing with Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Automatic Data Synchronization . . . . . . . . . . . . . . . . . . . . . 88
Updating Data that Has Changed . . . . . . . . . . . . . . . . . . . . . 89
Be Careful of the Content of the startApp() Method . . . . . 90
Part II
J2ME User Interface
5 Commands, Items, and Event Processing . . . . . . . . . . . . 95
J2ME User Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Display Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
The Palm OS Emulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Command Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
CommandListener . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Item Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Item Listener . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Throwing a MIDletStateChangeException . . . . . . . . . . . . . 120
Quick Reference Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
6 High-Level Display: Screens . . . . . . . . . . . . . . . . . . . . . . . 129
Screen Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Alert Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Alert Sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Form Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Item Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
ChoiceGroup Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
DateField Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Gauge Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
StringItem Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
TextField Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
ImageItem Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
List Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Creating an Instance of a List Class . . . . . . . . . . . . . . . . . . . 184
TextBox Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Creating an Instance of a TextBox Class . . . . . . . . . . . . . . . . 195
Ticker Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Quick Reference Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
7 Low-Level Display: Canvas . . . . . . . . . . . . . . . . . . . . . . . 213
The Canvas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
The Layout of a Canvas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Proportional Coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
The Pen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Painting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
showNotify() and hideNotify() . . . . . . . . . . . . . . . . . . . . . . . 219
User Interactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
Working with Key Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Working with Game Actions . . . . . . . . . . . . . . . . . . . . . . . . . 227
Working with Pointer Devices . . . . . . . . . . . . . . . . . . . . . . . . 233
Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Stroke Style and Color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Rectangles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Arcs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Repositioning Text and Images . . . . . . . . . . . . . . . . . . . . . . . 274
Clipping Regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Creating a Clipping Region . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
Quick Reference Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
Part III
J2ME Data Management
8 Record Management System . . . . . . . . . . . . . . . . . . . . . . 295
Record Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
The Record Store . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Record Store Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
Setting Up a Record Store . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Writing and Reading Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
Creating a New Record and Reading an
Existing Record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
Writing and Reading Mixed Data Types . . . . . . . . . . . . . . . 309
Record Enumeration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
Reading a Record of a Simple Data Type
into a RecordEnumeration . . . . . . . . . . . . . . . . . . . . . . . . . 319
Reading a Mixed Data Type Record into a
RecordEnumeration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
Sorting Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
Sorting Single Data Type Records in a
RecordEnumeration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
Sorting Mixed Data Type Records in a
RecordEnumeration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
Searching Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
Searching Single Data Type Records . . . . . . . . . . . . . . . . . . 345
Searching Mixed Data Type Records . . . . . . . . . . . . . . . . . . 352
RecordListener . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
Quick Reference Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
9 J2ME Database Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
Database Schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
Identifying Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Decomposing Attributes to Data . . . . . . . . . . . . . . . . . . . . . . 372
Defining Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
Normalizing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
Grouping Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
Creating Primary Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
Functional Dependency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
Transitive Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
Foreign Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
Referential Integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
The Art of Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
An Index in Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
Drawbacks of Using an Index . . . . . . . . . . . . . . . . . . . . . . . . 386
Clustered Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
Derived Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
Selective Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
Exact Matches and Partial Matches . . . . . . . . . . . . . . . . . . . . 389
Searching for Phonetic Matches . . . . . . . . . . . . . . . . . . . . . . 389
10 JDBC Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
The Concept of JDBC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392
JDBC Driver Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
Type 1 JDBC to ODBC Driver . . . . . . . . . . . . . . . . . . . . . . . . 393
Type 2 Java/Native Code Driver . . . . . . . . . . . . . . . . . . . . . 394
Type 3 JDBC Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
Type 4 JDBC Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
JDBC Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
Overview of the JDBC Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
Load the JDBC Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
Connect to the DBMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
Create and Execute an SQL Statement . . . . . . . . . . . . . . . . . 395
Process Data Returned by the DBMS . . . . . . . . . . . . . . . . . . 396
Terminate the Connection to the DBMS . . . . . . . . . . . . . . . . 397
Database Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
The Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
Timeout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
Connection Pool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
Statement Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
The Statement Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
PreparedStatement Object . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
CallableStatement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
ResultSet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
Reading the ResultSet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
Scrollable ResultSet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
Specify Number of Rows to Return . . . . . . . . . . . . . . . . . . . 414
Updatable ResultSet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
Transaction Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
Savepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
Batch Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422
Keeping ResultSet Objects Open . . . . . . . . . . . . . . . . . . . . . . 424
RowSet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
Autogenerated Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426
Metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426
ResultSet Metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426
Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Quick Reference Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
11 JDBC and Embedded SQL . . . . . . . . . . . . . . . . . . . . . . . . 453
Model Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
Model A Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455
Model B Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460
Create a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460
Drop a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462
Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
Create an Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
Drop an Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
Inserting Data into Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
Insert a Row . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466
Insert the System Date into a Column . . . . . . . . . . . . . . . . . 466
Insert the System Time into a Column . . . . . . . . . . . . . . . . . 467
Insert a Timestamp into a Column . . . . . . . . . . . . . . . . . . . . 467
Selecting Data from a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468
Select All Data from a Table . . . . . . . . . . . . . . . . . . . . . . . . . . 469
Request One Column . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470
Request Multiple Columns . . . . . . . . . . . . . . . . . . . . . . . . . . 471
Request Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
Request Rows and Columns . . . . . . . . . . . . . . . . . . . . . . . . . 472
AND, OR, and NOT Clauses . . . . . . . . . . . . . . . . . . . . . . . . . 473
Join Multiple Compound Expressions . . . . . . . . . . . . . . . . . 474
Equal and Not Equal Operators . . . . . . . . . . . . . . . . . . . . . . 475
Less Than and Greater Than Operators . . . . . . . . . . . . . . . . 477
Less Than or Equal to and Greater Than or Equal To . . . . 478
Between Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479
LIKE Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480
IS NULL Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480
DISTINCT Modifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
IN Modifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482
Metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
Number of Columns in ResultSet . . . . . . . . . . . . . . . . . . . . . 483
Data Type of Column . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484
Name of Column . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484
Column Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484
Updating Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
Update Row and Column . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
Update Multiple Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486
Deleting Data from a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
Delete a Row from a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
Joining Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
Join Two Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494
Parent-Child Join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495
Multiple Comparison Join . . . . . . . . . . . . . . . . . . . . . . . . . . . 496
Multitable Join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
Create a Column Name Qualifier . . . . . . . . . . . . . . . . . . . . . 498
Create a Table Alias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
Inner and Outer Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500
Calculating Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
SUM() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506
AVG() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
MIN() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
MAX() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508
COUNT() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508
Count All Rows in a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . 509
Retrieve Multiple Counts . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509
Calculate a Subset of Rows . . . . . . . . . . . . . . . . . . . . . . . . . . 510
NULLs and Duplicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511
Calculate Without Using Built-in Functions . . . . . . . . . . . . 511
Grouping and Ordering Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
GROUP BY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513
Group Multiple Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514
Conditional Grouping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515
Working with NULL Columns . . . . . . . . . . . . . . . . . . . . . . . 516
Sorting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516
Sorting on Derived Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518
Subqueries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519
Create a Subquery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520
Conditional Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521
VIEWs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525
Rules for Using VIEWs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525
Create a VIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527
Select Columns to Appear in the VIEW . . . . . . . . . . . . . . . . 528
Create a Horizontal VIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . 528
Create a Multitable VIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
Group and Sort VIEWs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
Modify a VIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 530
Part IV
J2ME Personal Information Manager Profile
12 Personal Information Manager . . . . . . . . . . . . . . . . . . . . 535
PIM Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536
The Contact Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538
The Event Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
The To Do Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
A Model PIM Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
Quick Reference Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557
Part V
J2ME Networking and Web Services
13 Generic Connection Framework . . . . . . . . . . . . . . . . . . . 575
The Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576
Connection and Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577
Hypertext Transfer Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580
Creating an HTTP Connection . . . . . . . . . . . . . . . . . . . . . . . . 580
Reading Data from an HTTP Connection . . . . . . . . . . . . . . 582
The File Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589
Socket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592
Communication Management Using HTTP Commands . . . . . . . . . 597
HttpConnection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 598
Session Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608
Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610
Transmit as a Background Process . . . . . . . . . . . . . . . . . . . . . . . . . . . 610
Quick Reference Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 614
14 Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617
Web Services Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618
The Tier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618
Clients, Resources, and Components . . . . . . . . . . . . . . . . . . 620
Accessing Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
J2EE Multi-Tier Web Services Architecture . . . . . . . . . . . . . . . . . . . . 621
Client Tier Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 624
Classification of Clients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 624
Web Tier Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625
Enterprise JavaBeans Tier Implementation . . . . . . . . . . . . . . . . . . . . 626
Enterprise Information Systems Tier Implementation . . . . . . . . . . . 627
Inside WSDL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629
The WSDL Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629
Types Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632
Message Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632
portType Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633
Binding Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634
Port Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 635
Service Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 635
J2ME MIDlets and Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636
JAX-RPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637
Holder Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637
Remote Method Invocation Concept . . . . . . . . . . . . . . . . . . . . . . . . . 639
Remote Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639
SOAP Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639
SOAP Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640
The SOAP Message and Delivery Structure . . . . . . . . . . . . 640
WSDL and SOAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 641
SOAP One-Way Transmission Primitive . . . . . . . . . . . . . . . 642
SOAP Request-Response Transmission Primitive . . . . . . . 643
SOAP Binding Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645
SOAP Operation Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645
SOAP Body Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 646
SOAP Fault Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 646
SOAP Header Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 646
SOAP Address Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 647
WSDL and HTTP Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 647
Quick Reference Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649
Appendix: Quick Reference Guide . . . . . . . . . . . . . . . . . 653
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 721