0% found this document useful (0 votes)
59 views

Java For ABAP Programmers 4-5

Comments in Java are just about the same as ordinary old comments in any other language including ABAP. They have one important distinction, however, and that is the use of the javadoc utility. To use javadoc comments you start the comments with a double slash.

Uploaded by

Aarón Villar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Java For ABAP Programmers 4-5

Comments in Java are just about the same as ordinary old comments in any other language including ABAP. They have one important distinction, however, and that is the use of the javadoc utility. To use javadoc comments you start the comments with a double slash.

Uploaded by

Aarón Villar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Alistair C.

Rooney 2002 All rights reserved

Java for ABAP programmers Lesson 4 & 5


TM

In these two lectures Im going to talk about commenting in Java and naming conventions and standards. Im not only going to talk about the Sun conventions but also the conventions I use to make a program easier to read. This is also known as good programming style.

Lesson 4 Comments in Java


Comments in Java are just about the same as ordinary old comments in any other language including ABAP. They have one important distinction, however, and that is the use of the Javadoc utility. This is an extremely powerful tool which will scan your Java program for certain comments, method names etc. and produce very nice documentation from it. Lets have a look then at the three different types of commenting in Java: Block comments Line comments Javadoc comments

Block Comments
Java provides a way of commenting out an entire block of code. The following example illustrates this: /* This is a block Comment in Java. You may not nest block comments in Java. You can only have one start and one end comment. */ Notice the use of /* to start the comment and */ to end the comment. You can use this form of commenting for a single line, but Java does provide for this with:

Alistair C. Rooney 2002 All rights reserved ABAP is the registered trademark of SAP AG. Java is the registered trademark of Sun Microsystems Inc.

Alistair C. Rooney 2002 All rights reserved

Line Comments
Line comments allow you to comment a line, or part of a line. This is very similar to the double quote symbol used in ABAP. Lets have a quick look at an example of this: int myVariable = 0; // Initialize myVariable to zero. // Now initialize the other variable. float myFloat = 3.45f; The two different methods are shown above. The double slash // can start at the beginning of a line or half way through a line, telling the compiler that anything after it is to be ignored.

Javadoc Comments
I intend to touch on this briefly here. If you want to find out more about the Javadoc utility and how to comment for it specifically, then have a look at the following url: http://java.sun.com/products/jdk/1.1/docs/tooldocs/win32/javadoc.html To use javadoc comments you start the comments with /** and end them with */. The other benefits of using the javadoc comment method is that you can now use tags within your comment block. For example: /** Start of comment block. @author Alistair Rooney @version 1.1 */ For a list of the standard tags, have a look at the url above. In conclusion I should add that contemporary wisdom dictates that all programs should be fully documented as this is where you will find developers looking for clues about the programs functionality. Document your programs as much as possible.
Alistair C. Rooney 2002 All rights reserved ABAP is the registered trademark of SAP AG. Java is the registered trademark of Sun Microsystems Inc.

Alistair C. Rooney 2002 All rights reserved

Lesson 5 Naming Standards and Conventions


There are two distinct areas in Java that we can discuss when talking about naming standards. The first is the Legality of the name, i.e. will the compiler allow the name. The second is popular convention. The latter will not give you a compiler problem, it will earn you a sharp smack upside the head from your team leader and/or fellow developers. Ill let you decide which is worse!

Legal and Illegal names.


Firstly we need to cover the types of things that we name. We will name variables, methods and labels. Collectively we call these things identifiers . You can start an identifier with any letter, an underscore or a dollar sign. The identifier can then have any combination of letters or numbers. It can also contain certain special characters, like the underscore. Legal MYVARIABLE myVariable my_Variable MyVariable9988 $myVariable Illegal %myVariable My-Variable 9988variable 5variable THE-FIRST-METHOD

See if you can work out why the above names are Legal or Illegal. While were on the subject of variable names, lets look at the Java syntax for declaring a variable. In ABAP we would say DATA MYVARIABLE TYPE I. In Java we would declare the variable like this: int myVariable; We can also initialise the variable at the same time like so: (We would add the VALUE addition in ABAP) int myVariable = 76; To use the equivalent chain command in ABAP (DATA:) we would simply use a comma to separate the different variables, but they must be of the same type. This is illustrated thus:
Alistair C. Rooney 2002 All rights reserved ABAP is the registered trademark of SAP AG. Java is the registered trademark of Sun Microsystems Inc.

Alistair C. Rooney 2002 All rights reserved

int myInt1, myInt2, myInt3; In the next section well discuss recognised conventions that we use in Java.

Java Conventions
There are many good sites on the Internet, which discuss Java style. More than one book has been written on this subject alone! (Elements of Java Style ISBN 0-52177768-2) (A good site to look at is : http://www.javaranch.com/style.jsp and Suns site is http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html ). What I intend doing here is going over the basics of naming conventions. 1. All identifiers should start with a lower case letter. 2. Class names should start with an upper case letter. 3. If there are two words in the name the second word should always start with an upper case letter. E.g. myGreatVariableName 4. Names should always be meaningful. Do not call your identifiers $a or $b! 5. Constants should be All upper case like PI or MYCONSTANT. Constants are defined using the final keyword. Heres a quick example. final double PI = 3.14159; Remember that a constant cannot be changed in any way. Attempting to do so would throw a compiler error. Constants are also usually prefixed with the static keyword, but this is something we will cover later. There are other suggestions like prefixing a working variable with an underscore, but these are largely personal preference. In the next lesson we will have a look at the operators that are provided with Java and something new to Abapers called block scope.

Java for Abapers is soon to be available in book form!

Alistair C. Rooney 2002 All rights reserved ABAP is the registered trademark of SAP AG. Java is the registered trademark of Sun Microsystems Inc.

You might also like