Java For ABAP Programmers 1 2
Java For ABAP Programmers 1 2
TM
Its a fully Object Orientated Language. This means that most people coming from an
ABAP environment will not have had any real exposure to OO concepts. (Hands up those
who have done the BC404). OO is very important to Java and some would say its
crucial.
Normally I wouldnt talk about Java at all for the first few lectures. I would talk about
Object Orientated principles. Inheritance, Polymorphism, Encapsulation and the like.
On the other hand its nice to see some Java to keep the excitement going.
What will this produce? A list dialog with Hello World of Abapers. OK, now lets look
at the same thing in Java.
class HelloAbapers
{
public static void main(String args[])
{
System.out.println(Hello World of Abapers);
}
}
Thats it! Thats your first program. Now we need to activate it, like we would activate
the ABAP program. In fact the process is somewhat similar. The Java program does not
compile to native code but rather to bytecode which is then interpreted by the Java
Virtual Machine. (More about the JVM later in the course). To do this we issue the
command javac HelloAbapers.java. The file weve just written must be saved with a
.java extension.
Lets see two separate examples on the same screen. One with errors and then one with
the errors corrected.
Lets have a look at the code weve just written. The first line defines the class. Notice I
havent defined a variable for my string in this example. Ill explain why when we cover
static variables.
Notice the curly brackets. This is how we define blocks in Java. They can be positioned
anywhere, but it looks a lot neater if they are lined up and indented. The first curly
bracket opens the class block.
Alistair C. Rooney 2002 All rights reserved
ABAP is the registered trademark of SAP AG.
Java is the registered trademark of Sun Microsystems Inc.
The next line defines the method we are using. In our case the main method. Every
Java class that can be called or run directly from the command line, must contain a main
method.
Lastly lets look at the line that does the work. We call a System object that contains a
method println. (More about the notation later). This accepts a single parameter and
prints it on the screen. The parameter is the string.
Dont worry at this early stage about the cryptic things like public or static or args[].
Well cover these things as we go along.
Finally we need to know how to run the jolly program. From a command line we merely
type in java HelloAbapers.
That was easy! Obviously there is a bit more to Java than this. Stay tuned for the next
lesson where well start to explore the benefits of Object Orientation and what the
concepts mean.
End of Lesson 1
Alistair Rooney is an SAP ABAP consultant who also lectures Java 2 and OOA/OOD. He has 20 years IT experience ranging from
operator to IT Manager. He is a member of the Institute of IT Management (London) and a member of the British Computer Society.
He currently lives in Durban, South Africa and is married with 2 children, a cat and several unwanted moles in the lawn.
Data
Methods()
FI:TR Consultant
We could say that the TR consultant is a more specialized FI consultant. We could also
say that the TR consultant Inherits all of the FI consultants Attributes and
Behaviours.
Lets take a more accurate analogy now. Lets look at a Shape. We dont know what kind
of shape it is, but it has some common attributes with all shapes. It has an area and it has
a colour. Now we can give it a behaviour. A good example is that a shape knows how to
calculate its area.
Again a diagram will illustrate this. Notice the two attributes and the one behaviour. This
is how we draw them in UML. (Unified Modelling Language).
-
Shape
Area
Colour
+ calcArea(x,y)
Now heres where it gets interesting. We can now create three more specialized shapes
that will inherit the attributes and behaviours from the Shape class. We call these subclasses. From their perspective we call Shape the super-class.
Square
+ calcArea(x,y)
Circle
+ calcArea(r)
Triangle
+ calcArea(x,y,z)
The variables defined inside the brackets loosely equate to exporting/importing functions
(depending where you look at them) for a function module. Bear in mind that these are
always the parameters being passed to a method. (Or the message in UML speak).
Notice that they are different in two of the classes (Circle, Triangle) and they are the
same for the Square. The Square class is said to have Overridden the calcArea method
from the superclass. The other two classes are said to have Overloaded the method.
Again, Ill go into greater detail on these later. Essentially the difference is that the
method signature is the same for the Square and different for the others. This is the
essence of polymorphism. In later lessons Ill explain the concept of late-binding which
makes this powerful in Java.
Handles >
0..1
Loan
dueDate
1
VideoStore
1
*
Borrows >
Records
0..1
*
< LendsVideoTo
< Employs
RecordsStorageOf >
< Maintains