Developing Mainframe Java Applications 1st Edition Lou Marco all chapter instant download
Developing Mainframe Java Applications 1st Edition Lou Marco all chapter instant download
https://ebookultra.com/download/ejb-jsp-java-on-the-edge-lou-marco/
https://ebookultra.com/download/enterprise-j2me-developing-mobile-
java-applications-8th-print-edition-yuan/
https://ebookultra.com/download/java-internationalization-creating-
international-applications-java-series-first-edition-david-czarnecki/
https://ebookultra.com/download/developing-backbone-js-applications-
addy-osmani/
Developing applications with enterprise SOA 1st Edition
Martin Huvar
https://ebookultra.com/download/developing-applications-with-
enterprise-soa-1st-edition-martin-huvar/
https://ebookultra.com/download/expert-oracle-and-java-security-
programming-secure-oracle-database-applications-with-java-1st-edition-
david-coffin/
https://ebookultra.com/download/running-mainframe-z-on-distributed-
platforms-1st-edition-kenneth-barrett/
https://ebookultra.com/download/metagenomics-of-the-microbial-
nitrogen-cycle-theory-methods-and-applications-1st-edition-diana-
marco/
https://ebookultra.com/download/digital-food-photography-1st-edition-
lou-manna/
Developing Mainframe Java Applications 1st Edition Lou
Marco Digital Instant Download
Author(s): Lou Marco
ISBN(s): 9780471415282, 0471415286
Edition: 1
File Details: PDF, 2.74 MB
Year: 2001
Language: english
Cover
Y
FL
AM
TE
Team-Fly®
Page i
Lou Marco
Page iv
Designations used by companies to distinguish their products are often claimed as trademarks. In all
instances where John Wiley & Sons, Inc., is aware of a claim, the product names appear in initial
capital or ALL CAPITAL LETTERS. Readers, however, should contact the appropriate companies
for more complete information regarding trademarks and registration.
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form
or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as
permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the
prior written permission of the Publisher, or authorization through payment of the appropriate per-
copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-
8400, fax (978) 750-4744. Requests to the Publisher for permission should be addressed to the
Permissions Department, John Wiley & Sons, Inc., 605 Third Avenue, New York, NY 10158-0012,
(212) 850-6011, fax (212) 850-6008, E-Mail: PERMREQ@WILEY.COM.
This publication is designed to provide accurate and authoritative information in regard to the subject
matter covered. It is sold with the understanding that the publisher is not engaged in professional
services. If professional advice or other expert assistance is required, the services of a competent
professional person should be sought.
For more information about Wiley products, visit our web site at www.Wiley.com
Page v
Contents
Preface xiii
Acknowledgments xvii
Part 1 Java Fundamentals 1
Chapter 1 Introduction 3
Java Trek 3
A New World of Objects 3
Reusability 4
Inheritance 4
Encapsulation 4
Stack Class 5
Polymorphism 6
Java and C++ 6
C++ 7
Java 8
A PL/I Version of the Bubble Sort 17
In Summary 20
Chapter 2 What Is Java? 23
A Brief History of Java 23
The World of Java Today 25
Java: The Programming Language 25
Java: The Object-Oriented Programming Language 25
Java: The Portable Programming Language 26
Page vi
Preface
Developing Mainframe Java Applications provides big iron data processors with a reference and
learning tool they can use to write Java programs that run under OS/390. The thrust of the book is to
describe Java in the language of the mainframe professional and to show how such professionals
would develop Java applications for the IBM mainframe.
This is a "how-to" book, meant to impart rules and general techniques by drawing analogies between
the familiar and the new. Scant mention is made of the technical intricacies of the Java Virtual
Machine, garbage collection algorithms, "the taming of the threads," or other topics that deal with
Java internals.
The book helps programmers learn Java programming, but the book has a wider audience than
AM
mainframe programmers. Systems analysts need to understand what Java is all about as well as
programmers. Management, especially first and second line managers, needs an understanding of
Java and a way of relating Java to their technical background.
TE
As an aside, the book assumes that the reader has no C or C++ programming experience, which
means that Java syntax, down to using curly braces, may be unfamiliar to the reader.
Team-Fly®
Page xiv
Part 1 contains chapters that discuss loops, decision constructs, declaring data, and
subroutine/function (methods, really) invocation–the language of procedural programming
languages. Other chapters discuss Class/Object representation, Inheritance, and Encapsulation–the
language of object-oriented programming languages. After the reader completes Part 1, he or she will
have a good grasp of how to use Java and how Java stacks up against familiar mainframe
programming languages.
To introduce the Sun Java JDK so the reader can create and execute simple Java programs on
his or her PC
Part 2, "Java in the Mainframe Environment," describes IBM's "Java Everywhere" strategy by
examining Java in the OS/390 environment. Each chapter covers how Java works with a particular
brand of IBM technology, such as CICS, DB2, or VSAM. Java code exploiting IBM-specific
technologies is included. The section concludes with Java code that accesses DB2 tables.
Part 2 explains shows how IBM has provided the Java programmer access to tried and true
technologies. After the reader completes this section, he or she will have a good grasp of how to
exploit Java in the OS/390 environment. The reader will be quite comfortable with Java; he or she
knows the syntax, how Java implements the object-oriented world view (from Part 1), and how to
use Java with familiar IBM technologies (Part 1).
CICS
IMS
Batch
VSAM
DB2
To compare and contrast Java code with COBOL and PL/I code when using the previous list
of technologies
Page xv
To describe IBM's JRIO classes and how the Java programmer on OS/390 uses these classes to
perform record I/O
In the first two parts, the book shows COBOL and PL/I code that functions like the Java code in the
snippets and applications. However, this approach can only take the reader so far into the world of
Java. Simply put, Java is far more capable than COBOL and PL/I put together. Hence, the last
section of the book describes several key features of Java that are found only in Java.
Part 3, "Java: Above and Beyond Other Programming Languages," lightly touches on several Java
features and capabilities, such as applet creation, the Swing user interface classes, Java 2, Enterprise
Edition (J2EE), and Remote Method Invocation (RMI).
The goals of Part 3 are to describe some of Java's unique features, including
Applet coding
The Remote Method Invocation (RMI) classes, which enable a Java programmer to execute
Java programs on other machines over a network
The first time a term is used in a chapter, the term is printed in italics.
Throughout the book, you'll find sidebar information that contains relevant information that doesn't
fit into the current context. Here's what a sidebar may look like:
You'll also encounter notes that augment the material preceding the note. Here's
This text may explain the material immediately preceding the note.
You'll also encounter tips that offer a shortcut or a solution to a common problem that relates to the
material you've just read.
This text may provide a shortcut or solution to a common problem.
Page xvi
Acknowledgments
This work would not have been possible without the nearly infinite patience of the hard-working folk
at John Wiley & Sons. Of course, kudos go to my wife who had to witness and endure some strange
behaviors on my part during the completion of this work.
Page xviii
PART One
Java Fundamentals
Page 2
CHAPTER 1
Introduction
Java Trek
You are a mainframe programmer neck deep in COBOL programming. You cannot escape the siren
song of object-oriented programming (OOP). Every trade publication you peruse has articles from
industry pundits chanting the object mantra. In an evangelical manner, these new disciples of the
object faith quote chapter and verse from the missiles of Saint Booch and Saint Jacobsen. The
message is clear— you must adopt the Object Tao and righteously cast out the old demons of
procedural programming and structured design.
Okay, you got the calling. As a highly evolved mammal, your survival instinct kicks in. You sense
that you'd better find out what this object stuff is all about. If these harbingers of the object path are
correct, you could become obsolete before you become vested in your pension plan. Duly motivated,
you begin your quest for the truth about object technology.
Y
A New World of Objects
FL
The oceans of literature and the galaxy of Web pages contain many new terms and concepts. On your
AM
own, the brave new world of object technology can be quite daunting. In this exploration, you will
have an experienced guide to help you sort through the differences between mainframe programming
concepts and object technology— specifically Java programming.
TE
Team-Fly®
Page 4
Object applications are not related sets of procedures acting on external data sources, but sets of
communicating objects. These objects contain all their needed data and procedures. The object view
of modeling software systems is based on the properties and behaviors of actual application entities.
Comparatively, the old software design model of creating separate data models and structure charts
seems archaic.
Reusability .
The object prophets make strong claims about software reusability. On the reusability issue, the
prophets speak with a single voice. They say that only by using object technology can you, the
programmer, create truly reusable code.
We all know that software reusability is not a new issue. Actually, software reusability has always
been the platonic ideal of programming. You've probably been very close to this ideal at times. It is
possible to write reusable code with a procedural language, but the reusability is achieved in spite of,
rather than because of, your programming tools and environment.
Is there really a programming environment out there somewhere that enables you to create reusable
code as a rule, not as an exception? Any culture advanced enough to produce cholesterol-free eggs
and breastfeeding devices for males must be advanced enough to produce this programming
environment. But do object environments truly assist the programmer in writing reusable code?
Inheritance
You may have read about that wonderful property of objects called inheritance. With inheritance,
you write code that implements some behavior for a group of similar objects, or a class. You create
subclasses based on some relationship— subclass A ISA superclass of B, for example. Once done,
the code that implements behaviors for the superclass is automatically known to the subclass. Yes, I
said automatically known to the subclass.
Well, this certainly sounds like a feature that would help me write reusable code. Think of a bank
account superclass with checking and savings account subclasses. You write code to implement the
withdrawal behavior for the bank account class. This code automatically becomes known to the
checking and savings account superclass. One routine, three classes. This beats the pants out of
reusability in the COBOL world-copying code in a separate member of your PDS and changing a
few lines. Do you see the real value in this inheritance stuff?
Encapsulation
You are likely to encounter the term encapsulation in any exploration of object technology. With
encapsulation, the data and code that implement behaviors in application objects are hidden from
other objects. The big idea is that, because other objects do not know about an object's internal data
and behavior representations, these other objects cannot change these representations. In short,
encapsulation provides a safety mechanism that prevents unwanted changes in an object's data.
Page 5
How does this encapsulation stuff really help prevent unwanted changes? Think about the last set of
COBOL modules you wrote. Let's say you coded a list of parameters in the CALL/USING statement
of the calling module. Remember the unexpected behavior of the calling program? Remember trying
to debug the calling program? Remember how the called program changed one of the parameters
supplied in the LINKAGE section? Remember how difficult this problem was to locate? Suddenly,
like the light bulb flashing over the coyote's head in those silly roadrunner cartoons, you see the
beauty, majesty, and practicality of encapsulation.
The problem with the COBOL modules is that both the calling and called modules needed to know
the data representation of the parameters. Because the called module knew the data representation,
the module contained code that changed the parameter. At times, you count on the ability of the
called COBOL module to change the parameter's value and write code to make wanted changes.
Sadly, you can slip and write code that inadvertently changes passed parameters. The calling module
has no knowledge of these changes and does not execute correctly.
Owing to encapsulation, an object application can never suffer this fate. What an object doesn't
know, an object cannot change. Data contained on objects is safe from unwanted tampering from
other objects.
Stack Class
Let's say Joe Programmer wrote a PL/I program a while back. Being a wise guy, he implemented a
stack as a controlled data structure (a controlled data structure in PL/I— declared with the storage
class CONTROLLED— means the PL/I program can dynamically allocate memory for the structure
with the ALLOCATE statement). All routines that used the stack had this controlled structure
declaration. Joe's code worked; he was immensely pleased with himself. When the team lead
scheduled the code walk-through, he couldn't wait to demonstrate his superior knowledge of the PL/I
language.
Well, it turns out that Joe should have known that the project lead is not nearly as well versed in PL/I
as he is. When she saw the stack and its controlled allocation, she barked, "What is this?" With pride,
Joe described the intricacies of PL/I's controlled storage class. A scowl slowly spread over the
project lead's face. She was clearly not impressed with Joe's code and asked him to rewrite the stack
code, using a more conventional data structure. When Joe meekly asked for a suggestion, she
whipped out an array representation on a white board. Joe slinked back to his cube to make the
required changes.
Joe hunted down every module that accessed the stack because he had to change every one. He had
to change the POP, PUSH, and ISEMPTY routines, too. What a pain. Maybe Joe should have
conferred with Hagatha, the team lead, before he embarked on his coding journey.
If this application were done in an object language, Joe would need to change only the stack class.
All objects communicating with the stack, being ignorant of the stack's data representation, would
not have to be changed.
Another bonus— because of inheritance, all subclasses of a changed class automatically know of the
change. Joe need do nothing to implement a new data representation or a behavior in the subclasses.
Page 6
By now, you should be firmly convinced that this object stuff is definitely worth the admission price.
This class/object representation, combined with inheritance and encapsulation, makes for powerful
code. Many more object technology wonders are there to unearth— let's keep digging.
Polymorphism
What if you could send the same message to different objects and each object would invoke the
appropriate behavior in response to the message? Remember that object applications are
communicating objects, not separate function/module calls acting on external data sources. The term
message makes sense in object-speak. Objects communicate by issuing messages to each other. The
message invokes some behavior that you have implemented in code. The thrust of polymorphism is
that each object responds to a message according to its understanding of that message.
There is practical, everyday truth in this. How do people respond to messages? Do we not respond in
our own way? Don't different people (and dogs, for that matter) respond differently to the same
message? When you become accustomed and attuned to this concept, the object world-view of
polymorphism seems as natural and proper as wearing underwear.
You may think that object technology is recent, say 1990s, technology. However, object technology
has been around since the 1970s. It may be strange to realize that object technology is older than
your dog. It may be older than your significant other. It is certainly older than some of the big iron
technology like DB2 and REXX that you've been using for the past 15 years.
Your first impulse may be to rush off to a bookstore and purchase some of the uncounted number of
books about these languages. Because most programming books are 40-plus dollars, a few books
equate to big bucks. After all, you're a programmer, not a drug dealer or a dentist. Three books are
the equivalent of food for two weeks. By now, the at-home crowd must be weary of eating beanie-
weenies. Maybe you can make do without the books for now.
Internet searches reveal a wealth of links on C++ and Java. There are lots of C++ and Java source
code, lots of terminology and acronyms, and lots of talk about UNIX on the net. There's little on how
object technology is used by companies in certain industries— notably yours. To find out how this
object–C++–Java technology is used by your industry and your company will take more research.
Page 7
Perhaps a direct approach is in order. Why not talk to folks in your organization to learn if anyone in
the same building is using object technology? You may meet a few object converts under your
corporate roof. Perhaps some of these object practitioners can shed some interesting light on C++
and Java usage within the company.
C++
Joe, the first object practitioner you meet, uses the C++ programming language. This programmer
swears with the fervor of a recent ex-smoker that any object programmer worth his salt uses C++. He
gleefully takes the time to explain his ardor for C++.
Joe tells you in a pompous and annoying manner that C++ supports all the features of object
programming: class/object representation, encapsulation, inheritance, and polymorphism. He
explains that C++ is a hybrid object language— a language built upon an existing procedural
programming language (C, in this case). He boasts that his C experience and knowledge of object
concepts enabled him to start coding almost immediately.
He continues by explaining that C++ supports multiple inheritance. Multiple inheritance enables a
subclass to inherit data attributes or behaviors from more than one superclass. Of course, he grins,
multiple inheritance is more flexible than, and superior to, single inheritance.
Because of your hard work and research, you understand what Joe is talking about. You wax with
glee as you realize that you can talk the object talk. You can't wait to walk the object walk.
Impatiently, you ask him to show you some C++ code.
As your eyes scan the C++ code, your shiny, gleeful face quickly sours to a dull, woeful puss. You
can't understand any of this stuff. This code could be Babylonian cuneiform writing as far as you're
concerned. You can't believe that under this mess is essentially code in a procedural language.
You recall the first time you saw PL/I. You didn't understand the nuts and bolts, but you had a good
understanding of what the code did. Your COBOL background was good preparation for
understanding PL/I. Unfortunately, this C++ stuff looks pretty cryptic.
The C++ programmer senses your state of overall confusion and asks you how much C experience
you have under your belt. There may be lots under your belt these days, but none of it is C
programming experience. You're a COBOL and PL/I programmer. Remember when you had to learn
pointer use in PL/I? You finally grasped that a pointer is merely a four-byte address. Joe shows you
pointers to character strings, pointers to integers, and (gasp!) pointers to pointers, explaining that,
although these pointers are addresses, they are all different data types. You thank the Joe for his time
and mosey on to your cubie. Alone with your thoughts, the horror of learning C++ seeps in. You
thought object programming would be easier than conventional procedural programming. This C++
stuff seems to be procedural programming at its worst.
At lunch, you mention to a chum that you're looking into C++ programming. This chum happens to
know a thing or two about C++. He has some C++ information obtained from a vendor of Macintosh
software development tools. He believes that this information is Mac-specific. But the C++
information from the Mac vendor made the
Page 8
stuff you gleaned from the pointer-happy programmer earlier today read like a nursery rhyme. Here's
what you read:
When you call the function "MYSTREAM.read()", it normally returns a reference to the stream object
itself, that is, . MYSTREAM. This is so you can chain these functions together, like this:
MyStream.read (MyVar1).read(MyVar2).read(MyVar3)
But when you call "MYSTREAM.read()" from a function that expects an integer, the compiler performs
some "sleight-of-hand" and actually returns MYSTREAM.good()" as the function result.
Desperately, you rifle through your notes. You recall hearing through the mill that your corporate
training department may be developing courses on Internet technologies. You recall the instructor of
the last class you took, oh so many moons ago. Why not give her a call?
Java
Jane, a corporate instructor, is developing a course on the Java programming language. Java, she
excitedly explains, is part of a suite of technologies that enable a programmer to write a program
once and run it on any platform— even on the Internet. Great— you have to deal with a suite of
technologies to learn and use Java. This is just what you need, right? Before you get all steamed up
over technology suites and the like, your Java guide says that Java has use and value as a
programming language aside and apart from Internet; Java is much more than the "Applet language
of the Internet." Upon hearing this, you regain your composure.
Jane starts to talk about Java's inheritance mechanism. When you comment on C++ and its support
for multiple inheritance, she audibly snickers. Jane mentions that with multiple inheritance, you have
no straightforward way of knowing the origin of some inherited behavior. Her point is that an
application developed with multiple inheritance may ease initial class creation and application
development but could make application maintenance a nightmare. By now, you assume that Java
supports single inheritance only.
However, when you point out the textbook advantages of multiple inheritance, she audibly snickers
again. Your Java guide points out that she never got to explain Java's inheritance mechanism to you.
She tells you that Java supports single inheritance inas-much as every object is created from a class
that has one and only one superclass. However, the Java designers were well aware of the limitations
of single inheritance as well as the pitfalls of multiple inheritance. She explains that Java's
inheritance mechanism is unique; a Java class has the ability to inherit behaviors from several classes
but only one of these classes is the superclass. The inherited behaviors that do not belong to the
superclass are defined to the class by an interface.
You are puzzled because this sounds like multiple inheritance. Jane explains that Java supports two
separate hierarchies: a Class hierarchy, which defines the
Page 9
Well, this still sounds like multiple inheritance but you get her gist: A Java class has one bonafide
superclass but can implement behaviors from other classes. When you comment that a Java class can
inherit method implementations from only the superclass, and the class must provide
implementations for all methods used by an interface, your guide approvingly nods. She suggests
that you not get hung up on the differences between a superclass and an interface yet.
Jane explains that the lazy C++ programmer could write code that doesn't do the cool object stuff,
like encapsulation or inheritance. The lazy C++ programmer could write C++ code to be completely
procedural. At first, you might be tempted to believe that this ability of C++ to wear two hats, so to
speak, is a good thing. Yeah, but you saw C++ code, remember? C++ is not your idea of procedural
programming.
Actually, she says, a common view of C++ is that C++ is a better version of C; C++ was developed
to overcome the deficiencies of the C programming language (of which many exist). Now, you don't
know C, and don't care to learn, but you see the wisdom of her words. You get the drift that C++ was
developed from C as opposed to being developed from the ground up. C++ is a better C, not a
language necessarily engineered to support object orientation.
The Java guru continues. She states that you could do procedural programming in Java, but anything
of substance, like file or database I/O, requires classes and objects and inheritance— the stuff of
objects. Although you could force a Java program to be procedural and not use object-oriented
features, your program probably could not do anything useful.
Java is a modern language, she says. Java designers at Sun Microsystems had definite ideas in mind
when Java went to the drawing board. Considering that Java was released in late 1995, you can tell
that this technology is hot.
Perhaps you should look at some Java code before she waxes into a Java frenzy. Jane presents an
implementation of the bubble sort in Java as shown in Listing 1.1.
Looks like that C++ stuff you saw before. You see those ++, --and the braces {}. At least there's a
use for those braces now. For the moment, you're not impressed with the syntax of this "modern"
language.
My friendly Java instructor explains that syntax is syntax; after all, isn't it all a matter of what you're
used to? Of course, as a programmer, you take the time to explain that programming language syntax
parallels written language inasmuch as both need to be read, written, and understandable. You take
the time to explain that language replete with punctuation is more difficult to digest than language
without excess punctuation. However, you are a gracious and classy person and you readily yield to
your Java Guide's point about syntax.
Life, and programming, is too intense to sweat the small stuff. Jane says her time is short and she'd
rather not go over too many syntax details right now; she'd rather stick to explaining Java concepts
that may be daunting to a Java wannabe like you.
Page 10
} //5
}
if (!swapped)
return ;
}
} //7
} //8
Listing 1.1 The infamous bubble sort.
She first explains that the double slashes denote a single line comment; the slash-asterisk
combination denote a multi-line comment. She mentions that Java is case sensitive. That is, the
variable names myPay and MYPAY are different variables. Like a chanteuse breaking into song, she
starts to explain pieces of the program by the numbers. She says that even this small example
contains many Java features; she has time to cover only a few points. You express your gratitude and
ask her to proceed.
She explains the big picture by stating that the program has a main method that declares and
initializes an array of numbers, calls a sort method, and prints out the sorted array. The sort() method
implements our friend, old Mr. Bubble. Both the main()
Page 11
and sort() methods are part of a class called BubSort. You may understand her reasoning; it is the
way you might code an example to illustrate a sort or features of a programming language.
class BubSort {
Every Java file containing Java source code has a class declaration. The class declaration should
match the name of the dataset. In this case, the dataset name would be BubSort.java.
Every Java application has a main() method. Now, she continues, this doesn't mean that every dataset
with Java source code has a main() method. Some Java source files have support datasets. And, she
adds, Java applets do not have a main() method.
Yes, applets. You recall reading about Java applets— small programs that execute within a Web
page. But you withhold your questions because you're in the middle of dissecting this bubble sort.
Speaking of which, Jane returns to the explanation of line //(2). Well, those words public static void
have meaning. She says it has to do with the visibility of the method (that's the public keyword)— the
method does not belong to any particular object (that's the static keyword) and what the method
does, or does not return (that's the void keyword).
Yes, she says— Java has keywords, or reserved words, like most programming languages.
The first keyword, int, is the data type of the elements of the array. You gather that the keyword int
is short for integer. She tells you that you may be right, you may be wrong— it depends on what you
think an integer is.
You say that the definition of an integer is operating-system dependent. On some platforms an
integer is four bytes, type binary, unsigned. On other platforms, an integer is four bytes, type packed,
signed. You say the int declaration depends on the platform you are writing Java on.
Well, your long-suffering and humble Java instructor certainly has a thing or two to say now. She
asks you if you've read anything about Java. If so, she claims, you'd know
Page 12
that Java doesn't care for operating system particulars such as primitive data type byte sizes and
formats. The beauty of Java is that Java was designed to be source code compatible across multiple
platforms. The same Java that executes on a Wintel box will run without modification on a
Macintosh, an IBM RS6000 running AIX, or on an IBM mainframe running OS/390.
You chortle under your breath. Seems you've heard this one before. You recall how C was the
ultimate cross platform software development tool. C was the "be all, end all" of programming
languages. Now, you never became proficient in C, but you work in data processing, right? If C lived
up to one-tenth of its promise, you would have heard about it, right? Well, you still spent your time
coding EVALUATE statements and looking at Abend-Aid dumps, right?
Apparently sensing your disbelief over her words, she explains that Java achieves this cross platform
execution boast by compiling into a platform-neutral format called bytecodes. A platform-specific
piece of software called a Java Virtual Machine translates the bytecodes into platform-specific
machine code. Hence, the Java compiler does not have to care about operating system details; the
Java Virtual Machine takes care of that. And the Java Virtual Machine is platform-specific.
You see the beauty in this approach. The Java programmer really does not have to know how big
integers are or how booleans are represented on a particular platform. All the Java programmer needs
to know is how big Java integers are or how Java represents booleans. The Java Virtual Machine
takes care of the mundane platform-specific details.
Oh, back to the question, how large are int data types? She says that Java uses four byte signed
binary integers.
A typical Java declaration is the data type or class name followed by the variable or object name. In
line // 3, the identifier anarray is the name of the declared array. My guide says that Java variables or
objects can have other attributes attached to them, but for now let's keep things straightforward.
You are a bit puzzled over this "variable or object" thing. Isn't Java object-oriented? Isn't everything
you use in Java an object instantiated from a class? Isn't that how this object-oriented stuff works?
She reminds you that Java is a new language. Over the years, computer scientists have learned a
thing or two about programming languages. For example, a "pure object" language like Smalltalk
would never, never, ever, ever permit you to use anything but objects. In Smalltalk, even the number
2 is considered an object. Some computer scientist types have concluded that this "everything is an
object" approach doesn't work for some applications. A programming language runtime must keep
track of memory allocated for objects (among other things). Most object languages need custom
routines to compare objects for equality and to read and write objects. In short, using objects is a lot
of work for a computer.
An example of an application type that is not well suited to object technology is the "number
crunching" type of applications used in science labs. Remember those old Fortran programs with five
nested loops? To use an object-oriented system to perform
Page 13
numeric calculations seems a bit wasteful of computing resources considering what the system may
require to keep track of all the objects used. Of course, this is not to say that you couldn't code
application of this type in object languages.
Java enables a programmer to use primitive data types instead of objects. For example, this example
uses few objects. The array elements, the array indices, and the boolean flag are not objects; these
program elements are variables. The array declared on line //3 is what she calls a reference data type.
As an aside, Java arrays are very object-like. Arrays may be assigned to variables of type Object
(Object is the root class in Java, the class at the top of the hierarchy). But, she continues, Java
practitioners do not consider an array an object.
You mull this over. You sort of understand that the array declaration does not declare an object.
Objects use methods and there's been no talk of methods attached to this array. This array is pretty
much like an array used in COBOL or PL/I.
You believe that some of this object stuff looks really good "on paper" but often fails the real world
test. You've read that this object stuff is decades old. Let's face it— if this technology were so great, it
would be more widespread. A mixture of old-fashioned, procedural programming and this object
stuff could be just what we need in data processing, perhaps.
Possibly, says your Java guide. She continues to discuss the sort example.
Y
FL
Back to the Java Bubble Sort
AM
Back to line //3. Note that this statement initializes the array. In Java, arrays start with index 0, not 1
like some programming languages. Just something to keep in mind, she quips.
TE
Jane comments that she has to wrap this up soon; she has meetings to attend and memos to write. She
starts to discuss line //4:
sort( anarray ) ;
Here's where you invoke the sort() method and pass the array argument. This is not tough, new, or
strange. This is programming!
Where are the objects? Where are the classes? Java is object-oriented, right? Of course, Jane says,
but we don't need object stuff to do a bubble sort. Java lets you do some things procedurally.
The sort method has a special keyword, static, which means that you need not attach this method to
an object. Sometimes you just need a piece of code that does not depend on any particular object's
data. The bubble sort is like that; the sort is entirely parameter driven. What we need is a way of
telling Java that we want this method but don't want to create objects and attach the method to the
object. The static keyword does just that.
She explains that if she (or anyone) needed a bubble sort, she could use the sort method in the
BubSort class. First, the programmer would remove the main() method from BubSort.java; Listing
Team-Fly®
1.2 shows the new BubSort.java.
Page 14
class BubSort {
}
if (!swapped) return ;
}
Listing 1.2 Bubble sort in its own class.
As you can see, the sort() method is unchanged but the class does not have a main() method.
Presumably, the class that will use the sort() method has a main() method, and only one main()
method per Java application is allowed.
Assuming the BubSort class is on the same directory as the UseBub class or in what Java mavens
call the classpath, when you execute UseBub, the Java runtime will pull what UseBub needs from
BubSort. In particular, UseBub needs the sort() routine. Check out the lines marked with //*** in
Listing 1.3.
BubSort.sort( anarray ) ;
BubSort.sort( anarray2 ) ;
The sort() method is qualified with the class that contains the method.
You ask about the other statements in the original bubble sort program— the one from Listing 1.1. In
particular, you ask about these curly braces. The rest of the numbered statements are braces that
close off blocks. She explains that Java uses the curly braces as block constructs. The block construct
helps to define variable visibility. Also, the block construct is required when more than one
statement follows an if statement or a loop construct. Even a small Java program can contain
numerous braces, she says.
The visibility of these variables may be defined by curly braces; variables declared within a pair of
braces are known within those braces. Some cases exist where a variable is declared within a
statement. In this case, that variable is visible only in that statement. She directs you to the following
statement:
Page 15
class UseBub {
printResults( anarray ) ;
printResults( anarray2 ) ;
}
Listing 1.3 Invoking the bubble sort from a class.
This is a single statement. The variable idx is visible in this statement only.
She catches you staring at this statement. She catches you in mid-thought and explains that this is a
looping construct that prints an array value to the default output stream. She also says that she is
quickly running out of time and has to pick up the pace.
After a pregnant pause, you meekly ask her where the pointer references are. You figure that
"modern" languages like C++ and Java are replete with pointers. You cite your discussion with the
C++ programmer and what he told you about pointers in C++. What about pointer use in Java, you
ask?
With an impish grin, she tells me that Java does not use pointers. No pointers? None, she answers.
Java is able to do what every programming language does, and more, without the use of explicitly
declared and manipulated pointers. A Java programmer cannot declare a pointer or access the
starting address of a data structure in any way.
Well, well— no pointers in Java! That one statement alone is music to your codeweary ears. You start
to believe that these Java engineers at Sun really know their stuff.
Page 16
You ask her how she compiles and links this program. She reminds you that Java compiles into a
platform-neutral data format called bytecodes. You knowingly nod in agreement. She is using a
WinTel box to compile her Java source. She tells you that the marketplace is rife with Java tools and
serious Java folk have an arsenal of tools to help with Java development. For now, she explains,
she'll use the standard tool suite, or Java Development Kit, available from Sun Microsystems (the
developers of Java). She opens up a DOS window and compiles the program. Next, she executes the
program. Figure 1.1 shows the DOS window after compiling and running the bubble sort.
The javac command invokes the Java compiler. In truly sparse computer geek fashion, a successful
compile provides no diagnostics. A successful Java compile produces a class file— in this case,
BubSort.class. Next, the java command executes the program. The java command passes the
previously created class file, in Bytecode format, to the Java Virtual Machine for execution. The
result of the execution is seen in the DOS window previously.
Well, well, you think. This certainly beats the pants off of submitting batch compiles and links. You
enter source code in an appropriately named dataset, switch to a DOS window where you do your
compiles, and repeat until you get a clean compile. Next, you execute your program in the very same
window.
You note that you need a program to execute your Java program. You ask her where the executable
file is produced by the linker. Actually, you ask her where and how she did the link. Your Java guide
tells you that she did not link the Java code; she did not produce an executable. The java compiler,
javac, produced a class file composed of bytecodes. The bytecodes are interpreted by the java
command.
You ask her how much these Java tools cost— the compiler (javac), the program that executes the
bytecodes (java), and the Java Virtual Machine. You would like to get a copy on your machine.
When she replies that these tools are free, you slip off your chair. Free? How can this be? Our shop is
used to paying a fortune for any software tool.
Figure 1.1 DOS window after compiling and running the sort.
Another Random Scribd Document
with Unrelated Content
have him. I could see that Jacqueline liked him and that was enough
for me. He never tired of thanking me for what I had done for him,
and his face would light with pleasure whenever he saw me.
"How was I to suspect anything? As his visits became more frequent
and my work grew more absorbing, I encouraged him to escort
Jacqueline to the races and the other places of amusement of which
she was always so fond. I seldom had time to go with her. But in
spite of this friendship Jacqueline grew more affectionate to me
every day and pleaded with me constantly to go about with her and
let my work take care of itself. I showed her time and again how
impossible this was, and then she would pout until Lescelles came,
and I would tell him to take her somewhere.
"What a blind fool I was!" he cried with a harsh laugh. "I can see it
all now. And what an actress she was! The more guilty she grew
with Lescelles the more affection she displayed for me to prevent
any hint of suspicion.
"One day I told her that I would be unusually busy—would dine at a
café and would not be home until very late. But, as it happened,
when I returned to my office after dinner, I found there was nothing
of importance and so I went home."
He stopped again and the other could see that he was fighting to
retain his composure as he reached the climax of the story. Noel did
not speak or stir, but the hand that had but rested on the arm of the
chair gripped it tightly.
"Noel!" There was unspeakable anguish in his voice. "Noel! In the
blackness of these two years I've suffered so that I've sometimes
wished that I had not gone home that night until I was expected! It
was raining a little and when I reached the front door I let myself in
without making any noise. I wanted to surprise Jacqueline and——
Oh, God! I did—I did—I did!" And with a sobbing groan he sank into
a chair and bowed his head on his arms.
It was a long time before he could continue, and when he began
again his voice was hoarse with the effort he made to speak calmly.
"My friend, God grant that you may never know what I felt when I
opened the door of the room where they were and found them—
together! For you will never know till you have been—as I was! I
think the shock must have unbalanced my mind in the moment that
I saw them as I opened the door, for I leaned against the door-post
and stared at them as if paralyzed. They leaped up and were staring
back at me, and their faces—! They probably thought that I was
enjoying a moment of bitter joy before I killed them both, and do
you know what was passing in my mind? I was thinking that a chair
just behind her was too close to the divan, and that if she leaned
back in it, it would probably strike and scar the furniture. My mind
refused to grasp the horror that my eyes had seen.
"And then in some dim, vague way the idea worked into my
benumbed brain—I must shock them! I turned away from the door
and stumble down the hall toward my study. I didn't have any desire
to kill them in any way—at that moment I didn't even think that I
ought to do it. But it seemed to me that I must kill them, and with a
revolver—in the same way that a man would go through a
distasteful social function.
"I was some little time finding my revolver, but that did not seem at
the time to make any difference. I came back with it in my hand,
fully expecting to find them there, waiting to be shot—but the room
was empty!
"And then the paralysis passed from my brain and I went mad with
fury. I rushed through every room in the house, cursing them at the
top of my voice. Fortunately, none of the servants was at home.
"Then I ran bareheaded out into the rain and dashed down the
street aimlessly, in the hope that I had taken the right direction and
might come up with them. Before I had gone a hundred feet I ran
into someone and nearly shot him accidentally. He yelled with fright
and ran. I had just sense enough to put the revolver in my outside
coat pocket, and with my hand still gripping it, I hurried on."
He paused again to mop his brow, but his voice I grew firmer and
higher as the story of his wrongs worked him from grief to rage.
"I don't remember much of the rest of that night. I was only
conscious of the rain on my face and that I was walking always at
top speed without any goal. Now I was along the quays, then I
remember peering into a few cafés. It seems to me that I was
stopped several times by gendarmes, who released me when I
showed them my card, but I never heard of it afterward. I think I
passed through the Bois once, but when dawn came I was in some
vile street in Montmartre. And with the daylight came some sort of
calm.
"I started back toward my house, and after a short walk found a
cab. In that drive I became, as I thought, complete master of myself
again. I know now that I was practically a somnambulist. I thought
the whole thing over in an almost impersonal way, and decided I
would devote the rest of my life to vengeance. I would hunt both of
them down and kill them, and I would begin the hunt systematically
that day.
"When I reached home my clothes were soaking wet and my collar
and necktie were gone. I had probably tom them off and thrown
them away. Rose met me in the hall, and it did not strike me as
being at all strange that she asked no questions. I went up to my
room, took a bath and dressed in the most faultless style that my
wardrobe would permit. With the pistol in my pocket I started, out
again, first sending word that I would not, probably, be in my office
for several days.
"All that day I haunted the cafés and clubs that I knew Lescelles
frequented. I did not intend to kill him there unless he saw me. My
plan was to follow him to whatever place he had taken Jacqueline,
and kill them together.
"No one had seen him and I went home early in the morning,
bitterly disappointed. I sat in my study most of the day planning,
imagining, devising the most delightful ways in which to commit the
double murder, as I did not intend to use the revolver unless it
became necessary. The way that struck me as being best would be
to find them asleep and waken them with one hand on the throat of
each. Those throats haunted me. A dozen times that night I felt the
joy of sinking my fingers into them, slowly squeezing out their lives
as they stared up at me with eyes pleading for mercy.
"I was setting out again that evening when I met Rose a few steps
outside my door. I think she was waiting for me—and she had the
baby in her arms." His voice wavered and sank as if the rest were
too terrible to tell.
"Noel," he went on at last in a strained, uncertain voice, "up to that
moment I had not felt the slightest grief. I was apparently rational,
but I was as insane as any man that ever lived. Fury and the lust of
vengeance left no room for any other emotion. And," the voice
dropped with horror until it was barely more than a hoarse whisper,
"for a fraction of a moment I felt an impulse to kill the baby because
it was hers!" Again he stopped, unable to go on. Noel could not
repress a shudder but his hand shaded his features and he made no
other sign that he had heard. Then Floriot spoke again.
"Noel! Noel!" he half-sobbed. "I thought the next moment that I was
dying and—if it had only been true! For then for the first time came
the realization of what I had lost. I must have staggered into my
room and locked the door before I fainted, for light was coming in
the window when I recovered consciousness and I was lying across
my bed. With consciousness came the suffering hat has not ceased
for two years!...
"I will not try to tell you what the next few days were. I lost track of
time. I could not eat or drink or sleep. My revolver lay on the table
and a dozen times I picked it up to blow out my brains, but the
thought of the baby stopped me. I wept because I couldn't do it.
She was so completely part of me that I did not see how I could live
any longer.
"Finally, I made up my mind that no matter how dreary and empty
my life might be, I must; live for the boy's sake, and with that
resolution I locked up the revolver, burned every letter and
photograph of her that I had, I held them in the fire, one by one,
until the flames burned my fingers! Then I came into the world
again.
"I fled to work like a man running away from something and the
work brought—success! Success!"—And he ended with a grating
laugh.
Then he turned his white, drawn face and feverish eyes on the still
figure in the chair.
"Now," he demanded, "my friend, which of us deserves the most
pity?"
CHAPTER VI
CHAPTER VII
THE WANDERERS
"CONFIDENTIAL MISSIONS"
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com