Академический Документы
Профессиональный Документы
Культура Документы
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.
Alistair C. Rooney 2002 All rights reserved ABAP is the registered trademark of SAP AG. Java is the registered trademark of Sun Microsystems Inc.
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.
Alistair C. Rooney 2002 All rights reserved ABAP is the registered trademark of SAP AG. Java is the registered trademark of Sun Microsystems Inc.
Data
Methods()
Alistair C. Rooney 2002 All rights reserved ABAP is the registered trademark of SAP AG. Java is the registered trademark of Sun Microsystems Inc.
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.
Alistair C. Rooney 2002 All rights reserved ABAP is the registered trademark of SAP AG. Java is the registered trademark of Sun Microsystems Inc.
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.
There are a number of techniques used to extract these candidates, but we wont cover it 1 here. We can now start to build associations between our classes. This would start to give us an indication of the responsibilities of each class, which is a very important Assistant Customer Video aspect of OO. name VideoID The following diagram illustrates this more fully. 1..* * Loan dueDate
1 VideoStore 1
Handles >
0..1
Alistair C. Rooney 2002 All rights reserved Catalogue ABAP is the registered trademark of SAP AG. Java is the registered trademark of Sun Microsystems Inc.
Records
RecordsStorageOf >
< Maintains
Well thats a very brief introduction to the wonderful world of UML/OO. Ive heard people say that it takes 6 months to a year to convert a procedural programmer to an Object Oriented programmer. You can only benefit from learning and applying OO so stick with it! Personally I wouldnt put a time on it. It depends how keen you are. Thats the end of Lesson 2. Sometime in the future Ill put together a full UML course. If this is something youd be interested in email me at java@sapgenie.com so I can gauge the interest. In Lesson 3 well explore some Java Basics, such as the primitive data types.
Alistair C. Rooney 2002 All rights reserved ABAP is the registered trademark of SAP AG. Java is the registered trademark of Sun Microsystems Inc.