Java For RPG Programmers :Teaches Java By Comparing It To RPG

Java For RPG Programmers :Teaches Java By Comparing It To RPG

by Phil Coulthard
     
 

This book is the perfect solution for RPG Programmers who want to reach out and learn the Java language. The authors teach you the Java programming language by comparing it to the RPG IV programming language and include:
  • Java history and uses of Java, including the web
  • Java language syntax, including data types
  • Java objects and object oriented

Overview


This book is the perfect solution for RPG Programmers who want to reach out and learn the Java language. The authors teach you the Java programming language by comparing it to the RPG IV programming language and include:

  • Java history and uses of Java, including the web
  • Java language syntax, including data types
  • Java objects and object oriented programming
  • Accessing AS/400 data with Java
  • Writing user interfaces in Java
  • Java threads, exceptions and more

KEY FEATURES

  • Teaches you Java by comparing it to RPG
  • As a bonus, offers a good introduction to RPG IV
  • This book was developed in association with the IBM Center for Advanced Studies.

MINDQ JAVA TUTORIAL ON CD-ROM

Included on the CD-ROM is a complete licensed copy of the Introduction to Java Programming using VisualAge for Java Enterprise. This tutorial includes an introduction to VisualAge for Java. In addition covers all of the key Java language concepts.

Product Details

ISBN-13:
9781889671239
Publisher:
Advice Press
Publication date:
08/28/1998
Series:
IBM Centre for Advanced Studies
Pages:
523
Product dimensions:
7.08(w) x 9.01(h) x 1.31(d)

Read an Excerpt


Chapter 9: An Object Orientation

OO TERMINOLOGY

Java is an object-oriented language. That is a good thing, but what exactly does it mean? We'll define "OO" and describe how Java implements it. We'll point out the syntax, semantic, and capability considerations. But, to make this information useful, it Is important to begin to "think OO." That is quite different than "thinking procedural," as your RPG background has taught you. However, it is helpful to keep in mind that the AS/400 operating system is "object based," even if it is not object oriented. This will begin to make more sense as you gain more experience. Thinking OO when you are designing your code will feel more comfortable with time. We suggest you get in there and write some Java code right away. Don't be afraid to jump in and get your feet wet. Learning the syntax and capabilities of the language will take place as you are actually doing it. Pick a simple program you have always wanted to write to be your test case but, please, don't ship it immediately! As you write your initial code, pick up some reading material. We suggest reference manuals and two or three books on Java. After that, read a book about object oriented design. There are hundreds on the market. Having learned the Java language will make you more familiar with the terms you will find in the books and reference manuals. You will find answers in the books to questions that will inevitably accumulate as you write your initial code. If you can, hire someone to join your team who has object oriented skills. Keep in mind that not everyone on the team needs to be proficient in OO - the initial design could be done by a different set of persons than those who do the implementation. So don't get discouraged if everything doesn't make sense right away because, believe us, your second or third project with Java or any OO language will be great! OO has many important benefits - if applied correctly.

It is generally agreed that for a computer language to be considered object oriented, it must support the following concepts:

  • Encapsulation.
  • Inheritance.
  • Polymorphism.

What the heck are these? Read on...

Encapsulation Java classes, like RPG IV modules, offer code reuse and packaging options through the ability to have one compiled piece of code that does a self contained set of functions, such as managing a stack. This unit is reusable "as is" by many others, especially when it is packaged as part of a Java package or a RPG IV service program. Classes are the basic building blocks of all object oriented languages. Putting variables (data) and code together into a easily reused "black box" that others can access through specifically designated interfaces ("public" in Java, "export" in RPG) is called encapsulation. That is an appropriate term because you encapsulate the data and allow access only through related functions. Let's consider a stack example. Let's suppose that one day you decide to change the underlying data structure from an array to a dynamic linked list. No problem. You can make this change without affecting all users of the code if you have properly restricted access to the internal variables. You do this by restricting users to, say, the push and pop interfaces.

It is because of this ability to encapsulate the data (variables) from direct and unpredictable access that you often see graphics that show objects as a circle. The data or variables are in the middle, and the methods are around the outside. An example is shown in Figure 9-1:

Figure 9-1

This is a way of conveying that the variables (these are class level or instance variables) in the center are protected from direct access by the methods. That is, you must use one of the methods to access the variables. This helps to ensure data integrity, as well as gives the class designer control over future changes. Keep in mind that methods in Java are like procedures in RPG IV, and class level or instance variables in Java are like global variables in RPG. It's also useful to remember that classes in Java are like modules in ILE. Because exported procedures in ILE service programs are like public methods in Java, encapsulation is possible in RPG. The trick is to create service programs that export only procedures, not variables. That forces programmer users of the service program to go through your procedures to access your variables.

Encapsulation and the AS/400

Beyond ILE modules, another good example of this on the AS/400, is the database itself Data files on the AS/400 are typically created with very limited public access, and end users are forced to go through your programs to access the database. Typically these programs use adopted authority to gain entry to the data. It might be helpful to think of the database as being like your private variables. In contrast, your programs are like the public methods through which access to the variables is restricted.

Inheritance

Because it is possible to get encapsulation through ILE modules and service programs in RPG, why all the fuss in the industry about OO (Object Oriented)? The OO is getting so much hype because of another capability of classes - the ability to be extended (also known as subclassed). This ability that classes have is unique. There is no analogy to this in RPG, at least as this book is being written. As you will see, it can offer great rewards once you get the hang of it. The examples you have seen so far of Java classes have been defined from scratch. That is a common use for Java. However, you will also often find yourself in another situation. Let's say that you want a version of an existing class that is only slightly different. You don't want to copy and maintain a second slightly altered version. This can be done! You simply define your new class and specify that it I extends' (in Java) the original class. Your new class will inherit all the variables and methods of the base class. Well, not quite. It does inherit them all, but the new code in the new class is not allowed to access any variable marked as private, or to invoke any method marked as private. Unmarked ("package") and public variables and methods are accessible, however

// Class BaseClass public class BaseClass
{
private int a = 10;
public int getA ( )
{
return a;
}
public void setA (int newA)
{
a = newA;
}
}// end class Baseclass

// Class SubClass
public class SubClass extends BaseClass
{
}// end class SubClass

The example shows a new class, SubClass, that extends a base class called BaseClass. The important keyword here is extends. This syntax defines this new class as an extension, or subclass, of Baseclass. To users, this new class looks just like the base class.

Once you instantiate an object instance of SubClass you can invoke the methods getA ( ) and setA (...) on that object, as though you had instantiated an object of BaseClass. The new object has a variable 'a' in it, and has the same methods as the base class. . . .

Meet the Author


George N. Farr is currently the technical development manager for ILE RPG IV as well as VisualAge for RPG products. He has held many positions including a developer, team leader, development manager, and an AS/400 planner and architect since 1985. He is frequent speaker at COMMON conferences, AS/400 user groups, and other AS/400 conferences worldwide. He has authored many industry magazine articles and many books including ILE: A First Look and RPG IV By Example. George currently resides in Toronto, Ontario.

Phil Coulthard is currently the lead architect for AS/400 application development products at the IBM Toronto laboratory. He has worked as a developer, team leader, manager and general advocate of AS/400 application development since 1986. An author of many industry magazine articles and a frequent speaker at COMMON and other AS400 conferences, Phil currently resides in Aurora, Ontario.

Customer Reviews

Average Review:

Write a Review

and post it to your social network

     

Most Helpful Customer Reviews

See all customer reviews >