1.3 Programming Languages


1.3 Programming Languages

A programming language is a formal notation that is used to write the data description and the instructions of a program. The language has a well-defined set of syntax and semantic rules. The programming language's syntax rules describe how to write sentences. The semantic rules describe the meaning of the sentences. These two types of rules must be consistent.

1.3.1 Machine Languages

Historically, the first group of programming languages that were developed were the machine languages for the various computers. Until the early fifties, this was the only category of programming languages available. The human representation of a program was a sequence of ones and zeros (or bits). Program development was extremely difficult, tedious, and error prone. These programming languages were very low-level because they consisted of symbolic machine instructions used to express very detailed manipulation at the hardware level and consequently, were hardware dependent.

1.3.2 Assembly Languages

The next group of programming languages includes the symbolic machine languages (also called assembly languages). These languages were developed to ease and improve the construction of programs. In these languages, various mnemonic symbols represent operations and addresses in memory. These languages are also low-level and hardware dependent; there is a different assembly language for every computer type. Assembly language is still used today for detailed control of hardware devices; it is also used when extremely efficient execution is required.

1.3.3 High-Level Programming Languages

The purpose of a programming language is to allow a human to write instructions to the computer in the form of a program. A programming language must be expressive enough to help the human in the writing of programs for a large family of problems.

High-level programming languages are so called because they are hardware independent and closer to the problem (or family of problems) to be solved.

Note

High-level languages allow more readable programs, and are easier to write and maintain. Examples of these languages are Pascal, C, Cobol, FORTRAN, Algol, Ada, Smalltalk, C++, Eiffel, and Java.

These last four high-level programming languages are object-oriented programming languages. These are considered slightly higher level than the other high-level languages.

The first object-oriented language, Simula, was developed in the mid-sixties. It was used mainly to write simulation models. The language is an extension of Algol. In a similar manner, C++ was developed as an extension to C in the early eighties.

Java was developed by Sun Microsystems in the mid-nineties, as an improved object-oriented programming language compared to C++. Java has far more capabilities than any other object-oriented programming language to date.

Languages like C++ and Java can require considerable effort to learn and master. There are several experimental, higher-level, object-oriented programming languages. Each one has a particular goal. One such language is KJP (Kennesaw Java Preprocessor); its main purpose is to make it easier to learn object-oriented programming principles and help students transition to Java.

1.3.4 Compilation

The solution to a problem is implemented in an appropriate programming language. This becomes the source program written in a high-level programming language, such as C++, Eiffel, Java, or others.

After a source program is written, it is translated to an equivalent program in machine language, which is the only programming language that the computer can understand. The computer can only execute instructions that are in machine language.

The translation of the source program to machine language is called compilation. The step after compilation is called linking and it generates an executable program in machine language. For some other languages, like Java, the user carries out two steps: compilation and interpretation. This last step involves direct execution of the compiled program.

Figure 1.5 shows what is involved in compilation of a source program in Java. The Java compiler checks for syntax errors in the source program and then translates it into a program in bytecode, which is the program in an intermediate form.

click to expand
Figure 1.5: Compiling a Java source program.

Note

The Java bytecode is not dependent on any particular platform or computer system. This makes the bytecode very portable from one machine to another.

Figure 1.6 shows how to execute a program in bytecode. The Java virtual machine (JVM), which is another software tool from Sun Microsystems, carries out the interpretation of the program in bytecode.

click to expand
Figure 1.6: Executing a Java program.

1.3.5 Converting from KJP to Java

For programs written in KJP (an object-oriented language that is higher level than Java), the KJP language translator is needed for the conversion from KJP to Java. This translator software is freely available from the KJP Web page:

  • http://science.kennesaw.edu/~jgarrido/kpl.html

The conversion is illustrated in Figure 1.7. Appendix A explains in further detail how to use the KJP translator.

click to expand
Figure 1.7: Conversion from pseudo-code to Java.

1.3.6 Program Execution

Note

Before a program starts to execute in the computer, it must be loaded into the memory of the computer. The program executing in the computer usually reads input data from the input device and after carrying out some computations, it writes results to the output device(s).

When executing in a computer, a program reads data from the input device (the keyboard), then carries out some transformation on the data, and writes the results on the output device (the video screen). The transformation also produces intermediate results.

In a personal computer system, the input data typically originates from the user keyboard. Similarly, the output data list is directed to the computer screen. A program reads data from the input list, carries out some transformation on this data, and writes output data (results) to the output list.

The instructions in a program define a set of transformations on the input data. These transformations together with the data description represent the program, which implements the solution. Figure 1.8 shows a typical application program in execution; reading input data and producing output data (results).

click to expand
Figure 1.8: An executing program.




Object-Oriented Programming(c) From Problem Solving to Java
Object-Oriented Programming (From Problem Solving to JAVA) (Charles River Media Programming)
ISBN: 1584502878
EAN: 2147483647
Year: 2005
Pages: 184

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net