The translation of a complete detailed design (algorithm and data descriptions) into a suitable programming language is called implementation. Pseudo-code is an intermediate notation between the modeling diagrams and the implementation programming language. In this book, KJP is used for writing the design and implementation, the translation to the Java programming language is carried out automatically by the KJP translator.
Programming languages, including Java and KJP, have well-defined syntax and semantic rules. The syntax is defined by a set of grammar rules and a vocabulary (a set of words). The legal sentences are constructed using words in the form of statements. The set of words is divided into two groups:
Reserved words have a predefined purpose in the language and are used in most statements with precise meaning, for example, class, inherits, variables, while, if, and others.
Identifiers are names for variables, constants, functions, and classes that the programmer chooses, for example, salary, age, and employee_name.
The attributes in a class are defined as variable declarations. The data definitions inside a function are written as local variable declarations. Object-oriented programs include the following kinds of statements:
Class definitions
Declaration of simple variables
Declaration of object references
Definition of functions
Creation of objects
Manipulation of the objects created by calling (or invoking) the functions that belong to these objects
Note | In Java and KJP, the functions or operations are known as methods. Objects do not directly have names, instead, object reference variables are used to reference objects when they are created. |
A class definition in KJP includes several sections. These must be written in the following order:
The description statement encloses a textual description of the purpose of the class, author, date, and any other relevant information. This section ends with a star-slash (*/).
The class statement defines the name of the class and other information related to the class.
The private section includes declarations of the private attributes of the class and definitions of the private operations.
The public section includes definitions of the public operations of the class.
The endclass statement ends the class definition.
The general syntactic definition of a class is:
description . . . class 〈 class_name 〉 is private constants . . . variables . . . objects . . . public . . . endclass 〈 class_name 〉