Você está na página 1de 11

CONTENTS

Chapter 1: THE WORLD OF JAVA 1


WHAT IS JAVA? 3
WHAT ABOUT THAT OO THING? 3
WHY THE HYPE? 4
The Name 4
The Internet 5
Portability 6
Accessibility 6
THE ROLES OF JAVA 6
THE HOUSE OF JAVA 7
JAVA BYTECODE 10
JAVA: THE LANGUAGE 11
THE INTERNET, HTML, AND JAVA APPLETS 13
HTML as an Internet user-interface language 17
Java as an Internet user-interface language 19
JAVA APPLICATIONS 20
JAVASCRIPT 21
JAVASERVER PAGES 22
ix

CONTENTS

ENTERPRISE JAVABEANS
JAVA VERSUS RPG
SUMMARY
References

23
23
24
25

Chapter 2: THE JAVA ONION 27


RPG IV VERSUS RPG III APPLICATIONS
THE OUTER SKIN: RPG VERSUS JAVA
RPGs outer skin
Javas outer skin
Compiling RPG
Compiling Java
About RPG IV procedures
RPG IV flow of control
About Java methods
Javas flow of control
COMPARING ANATOMIES
RPG syntax
Prototyping RPG procedures
Defining RPG procedures
Calling RPG procedures
JAVA SYNTAX
Java class syntax
Java variable syntax
Java method syntax
An example of a Java class
Getter and setter methods in Java
ALLOCATING MEMORY IN RPG IV
USING JAVA CLASSES
Accessing methods
Accessing variables
This is special
Java overload! Java overload!
STATIC MEMBERS
RPG static fields
Java static variables
Java static methods
CONSOLE-ATION
Calling a Java program: The main method
x

28
32
32
32
32
33
34
35
36
37
38
39
40
41
43
44
44
46
47
48
50
50
53
55
58
59
61
61
62
63
65
69
69

CONTENTS

Command-line parameters in RPG


Command-line parameters in Java
Writing to the command line in RPG
Writing to the command line in Java
Class constructors in Java
CODE REUSE AND DISTRIBUTION
Distributing reusable RPG code as service programs
Java code reuse through packages
JAVA ACCESSOR RIGHTS
SUMMARY

71
72
72
74
78
82
82
84
91
93

Chapter 3: JAVAS LANGUAGE AND SYNTAX 95


I WANT TO BE FREE! THE JAVA BASICS 95
COMMENTS 97
Java comments 98
JavaDoc comments 99
VARIABLE NAMING 105
The naming syntax for fields and variables 106
Keywords 106
COMPARING ANATOMIES 107
The anatomy of an RPG program 107
The anatomy of a Java Class 108
STATEMENTS 110
The expression statement 110
The block statement 111
The empty statement 113
The labeled statement 114
EXPRESSIONS AND OPERATORS 116
Computational expressions 117
Fetch expressions 136
OTHER MATHEMATICAL FUNCTIONS 137
SUMMARY 142

Chapter 4: STRUCTURED OPERATIONS AND STATEMENTS 143


ALTERNATE PATHS: DECISION STRUCTURES
If, then what? Else, of course
Too many IFs? Time to switch!
The conditional operator, ?:
Loop structuresThey get around

146
146
151
154
155
xi

CONTENTS

Going for a loopJust do it


A FOR loop in RPGYes, in RPG
Looping for a while
Looping until done
TRANSFER STRUCTURES
If you continue, I will need a break
Go to where?
Return to caller
SUMMARY

156
164
165
170
171
171
175
176
178

Chapter 5: DATA TYPES AND VARIABLES 181


A REVIEW OF RPG TYPES
AN INTRODUCTION TO JAVA TYPES
DATA DECLARATION
Defining fields in RPG
Defining variables in Java
VARIABLE SCOPE, LIFETIME, AND EXTERNAL ACCESS
Variable scope
Variable lifetime
Variable external access
Variables: An example
LITERALS BY DATA TYPE
NUMERIC DATA TYPE RANGES
FLOAT VERSUS PACKED
THE BOOLEAN DATA TYPE
CASTING AND NUMERIC CONVERSIONS
JAVA DATA-TYPE CLASS WRAPPERS
SUMMARY

182
186
189
190
195
199
199
200
201
202
205
207
209
214
215
220
223

Chapter 6: ARRAYS AND VECTORS 225


OBJECT REFERENCE OPERATORS
ARRAYS
Declaring arrays
Creating or instantiating arrays
Compile-time initialization of arrays
Runtime initialization of arrays
Initializing multi-dimensional arrays
Arrays are objects
Pre-runtime arrays in RPG
xii

227
228
230
232
233
236
238
241
243

CONTENTS

Unbalanced arrays
Arrays of objects
Helper methods for arrays
VECTORS
The Registration class
The AttendeeList Class
The Attendee class
Simulating vectors in RPG
HASHTABLES
PARAMETER PASSING
Parameter passing in RPG IV
Using arrays instead of primitives for simulated pass-by-reference
SUMMARY

248
249
252
256
260
261
263
264
271
278
278
281
283

Chapter 7: STRING MANIPULATION 285


JAVA STRING BASICS AND PITFALLS
STRINGS IN RPG
STRING MANIPULATION
Concatenation
Substrings
Searching for a substring
Trimming blanks
Determining string lengths
Translating characters
Translating case
Checking for characters
PERFORMANCE CONSIDERATIONS: THE STRINGBUFFER CLASS
IMPLEMENTING TRIMR AND TRIML IN JAVA
TOKENIZING STRINGS: THE STRINGTOKENIZER CLASS
THE STRING CLASS: MORE METHODS
SUMMARY

286
288
292

292
294
296
298
299
300
303
305
308
312
316
317
318

Chapter 8: DATE AND TIME MANIPULATION 321


RPG IV DATE AND TIME ENHANCEMENTS
JAVA DATE AND TIME SUPPORT
RAW TIME
GET ME A DATE, AND GIVE ME THE TIME!
DATE AND TIME MANIPULATION
Date/time math and duration

322
322
323
327
330
330
xiii

CONTENTS

Comparing dates
Extracting parts of a date or time
FORMATTING DATE FIELDS
FORMATTING TIME FIELDS
THE DEFAULT FORMATTER
TESTING DATE AND TIME
LOOK BEFORE YOU LEAP
TIME ZONES
SUMMARY

334
335
338
344
349
351
354
355
356

Chapter 9: AN OBJECT ORIENTATION 359


THE THREE TENETS OF OO
Encapsulation
Inheritance
Polymorphism
INHERITING MORE OR LESS
Preventing inheritance
Enforcing inheritance
THE FACTORY METHOD-DESIGN PATTERN
INTERFACES
Interfaces versus inheritance
Interfaces are callbacks
Interfaces and constants
Java-supplied interface examples
O2OOBJECT TO OBJECT: CASTING OBJECTS
COMMON METHODS TO OVERRIDE
THE OO WAY OF LIFE
In search of objects
OO design tips
SUMMARY
REFERENCES

361
361
362
372
379
379
380
382
387
398
400
401
401
409
411
412
412
415
418
419

Chapter 10: EXCEPTIONS 421


SYSTEM I EXCEPTION MODEL OVERVIEW
The OPM exception model
The ILE exception model
RPG III exception-handling
ILE RPG (RPG IV) exception-handling
New MONITOR operation in RPG V5R1
xiv

421
422
423
423
424
425

CONTENTS

EXCEPTIONS IN JAVA
The Java exception model at a glance
Exception objects in Java
Searching Java documentation for classes
Sending Java exceptions with the throw operator
Monitoring for Java exceptions with try/catch blocks
SUMMARY

426
427
428
431
433
437
443

Chapter 11: THREADS 445


SYNCHRONOUS VERSUS ASYNCHRONOUS
THREADS VERSUS JOBS
CALLING A METHOD ASYNCHRONOUSLY: SPAWNING THREADS
Calling without using threads
Using threads, option 1: The extends thread
Using threads, option 2: implements Runnable
STOPPING A THREAD
Stopping multiple threads: The ThreadGroups class
Ending programs with Java running threads
DAEMON THREADS
THINKING ASYNCHRONOUSDANGER LURKS...
The role of threads in a complex multi-user application
How single objects can have multiple threads of execution
Multithreaded danger: An inventory example
The solution: Synchronizing asynchronous execution
Fine-grained synchronization
Threaded application design alternatives
MORE ON THE SYNCHRONIZED KEYWORD
Synchronizing producer/consumer relationships with wait/notify
Deadly embrace
THREAD PRIORITIES
LOOSE THREADS
TIMING THREADED APPLICATIONS
SUMMARY

445
446
448
448
451
454
457
462
464
465
465
466
467
467
472
474
475
476
478
480
481
482
483
485

Chapter 12: USER INTERFACE 487


USER INTERFACES IN RPG IV
USER INTERFACES IN JAVA: OPTIONS, OPTIONS, OPTIONS
JAVA GUI
AN OVERVIEW OF JAVA SWING

487
488
490
491
xv

CONTENTS

BASIC GUI COMPONENTS IN JAVA


Common inherited methods
Common non-inherited methods
Model view controller
Events
CONTAINERS: JFRAMES, JDIALOGS, AND JPANELS
Adding components to containers: Layout managers
Nesting layout managers: The JPanel class
A simple form class
EFFECTIVE USE OF JTextFields
Component sizing and layout managers
Restricting input in a JTextField
MENU BARS AND POP-UPS
ADVANCED SWING FUNCTIONALITY
Default push button
Toolbars
Actions
Multiple-document interface
More components
More containers
Look and feel
Predefined dialogs
Message and simple input dialogs
APPLETS VERSUS APPLICATIONS
Applets and Swing
TRANSLATION-READY USING RESOURCE BUNDLES
Locales
Translated stringsResource bundles
SUMMARY

494
496
501
508
509
515
519
531
536
543
543
544
545
550
550
550
551
551
551
552
552
553
556
557
558
562
562
564
566

Chapter 13: DATABASE ACCESS 567


DATABASE ACCESS IN RPG IV
RPG DATABASE ACCESS UNDER COMMITMENT CONTROL
ACCESSING DATA WITH SQL
Interactive SQL versus embedded SQL
Static SQL versus dynamic SQL
Dynamic SQL versus CLI APIs
Local versus distributed SQL
SQL terminology
xvi

567
569
569
572
573
574
575
576

CONTENTS

SQL languages: DDL versus DML


What you need for SQL on the AS/400
WHY THE INTRODUCTION TO SQL?
ACCESSING DATA WITH JAVA
JDBC DRIVERS FOR DB2/400
JAVA JDBC PROGRAMMING
Steps 1 and 2: Registering and connecting
Step 3: Creating SQL statement objects
Step 4: Running the SQL statements
Step 5: Retrieving the information in result sets
Step 6: Close, close, close
More on data types
Null-value considerations in JDBC
Commitment control in JDBC
Retrieving database metadata in JDBC
THE GOOD STUFF: STORED PROCEDURES, TRIGGERS, AND RI
STORED PROCEDURE CALLS IN JDBC
WHATS NEW IN JDBC 2.0
Datatype enhancements
ResultSet enhancements
Something new: Batch updates
Optional JDBC 2.0 enhancements
WHATS NEW IN JDBC 3.0
EMBEDDED SQL IN JAVA: SQLJ
Writing embedded SQL in Java
Preparing and compiling embedded SQL in Java
SUMMARY
REFERENCES

577
579
579
579
582
583
585
595
597
599
617
617
619
620
621
624
625
627
627
628
630
630
631
631
633
636
637
637

Chapter 14: MORE JAVA 639


INNER CLASSES
ANONYMOUS INNER CLASSES
STATIC INITIALIZERS
JAVA NATIVE INTERFACE (JNI)
JAVA REMOTE METHOD INVOCATION (RMI)
JAVA OBJECT SERIALIZATION
J2SE 5.0 LANGUAGE CHANGES
Generics
Enhanced for Loop

640
642
644
645
647
652
656
656
657
xvii

CONTENTS

Autoboxing/Unboxing
Enumerations
Variable Arguments List
Static Import
Annotations
JAVA-SUPPLIED PACKAGES
COMMON HOW DO I? QUESTIONS
How do I determine the working directory?
How do I change the working directory?
How do I list files and directories?
How do I list drives?
How do I create a directory?
How do I create or open a flat file and write to it?
How do I read a flat file?
How do I call another program or command?
How do I save and restore user-profile information?
JAVABEANS
Properties
Bound properties
Events
Serializing beans
The BeanInfo class
Beans and tools
More beans
NEXT STEPS: OF SERVLETS, JSPS, EJBS, AND MORE
SUMMARY

657
658
659
659
659
660
664
664
665
667
669
670
670
672
673
676
678
678
681
684
687
689
690
692
692
692

APPENDIX A 695
INSTALLING THE COMPONENTS
THE ISERIES IBM DEVELOPER KIT FOR JAVA
Using the Integrated File System and QShell Interpreter
Working with Java on OS/400
Setting your classpath in QShell
Using CL commands for Java and the Java Transformer
ISERIES IBM TOOLBOX FOR JAVA
Getting the iSeries IBM Toolbox for Java classes
Using the iSeries IBM Toolbox for Java classes
The CommandCall class
The ProgramCall class
xviii

696
697
697
700
702
703
705
710
711
713
714

CONTENTS

PCML for easy calling of programs and service programs


The DataQueue class
Record-level database access
OTHER AS/400 TOOLBOX FOR JAVA FUNCTIONALITY

723
727
736
744

APPENDIX B 745
RPG CALLING JAVA
Mapping data types
Java exceptions when calling Java from RPG
Java Virtual Machine considerations
Classpath considerations
CALLING RPG PROCEDURES AS RPG NATIVE METHODS FROM JAVA
FINALLY

746
754
756
756
757
757
761

Appendix C: OBTAINING THE CODE SAMPLES 763


ABOUT THE AUTHORS 765
INDEX 767

xix

Você também pode gostar