1.3. Programs

 
[Page 7 ( continued )]

Computer programs , known as software , are instructions to the computer. You tell a computer what to do through programs. Without programs, a computer is an empty machine. Computers do not understand human languages, so you need to use computer languages to communicate with them.

The language a computer speaks is the computer's native language or machine language. The machine language is a set of primitive instructions built into every computer. Machine languages are different for different type of computers. The instructions are in the form of binary code, so you have to enter binary codes for various instructions. Programming using a native machine language is a tedious process. Moreover, the programs are highly difficult to read and modify. For example, to add two numbers , you might have to write an instruction in binary like this:


[Page 8]
   1101101010011010   

Assembly language is a low-level programming language in which a mnemonic is used to represent each of the machine-language instructions. For example, to add two numbers, you might write an instruction in assembly code like this:

   ADDF3 R1, R2, R3   

Assembly languages were developed to make programming easy. Since the computer cannot understand assembly language, however, a program called assembler is used to convert assembly language programs into machine code, as shown in Figure 1.3.

Figure 1.3. Assembler translates assembly language instructions to machine code.

Since assembly language is machine-dependent , an assembly program can only be executed on a particular machine. Assembly programs are written in terms of machine instructions with easy-to-remember mnemonic names . The high-level languages were developed in order to overcome the platform-specific problem and make programming easier.

The high-level languages are English-like and easy to learn and program. Here, for example, is a high-level language statement that computes the area of a circle with radius 5:

   area = 5 * 5 * 3.1415;   

There are over one hundred high-level languages. The popular languages used today are:

  • COBOL (COmmon Business Oriented Language)

  • FORTRAN (FORmula TRANslation)

  • BASIC (Beginner All-purpose Symbolic Instructional Code)

  • Pascal (named for Blaise Pascal)

  • Ada (named for Ada Lovelace)

  • C (whose developer designed B first)

  • Visual Basic (Basic-like visual language developed by Microsoft)

  • Delphi (Pascal-like visual language developed by Borland)

  • C++ (an object-oriented language, based on C)

  • C# (a Java-like language developed by Microsoft)

  • Java


[Page 9]

Each of these languages was designed for a specific purpose. COBOL was designed for business applications and now is used primarily for business data processing. FORTRAN was designed for mathematical computations and is used mainly for numeric computations . BASIC, as its name suggests, was designed to be learned and used easily. Ada was developed for the Department of Defense and is mainly used in defense projects. C combines the power of an assembly language with the ease of use and portability of a high-level language. Visual Basic and Delphi are used in developing graphical user interfaces and in rapid application development. C++ is popular for system software projects like writing compilers and operating systems. The Microsoft Windows operating system was coded using C++.

A program written in a high-level language is called a source program . Since a computer cannot understand a source program, a program called a compiler is used to translate the source program into a machine-language program. The machine-language program is often then linked with other supporting library code to form an executable file. The executable file can be executed on the machine, as shown in Figure 1.4. On Windows, executable files have extension .exe.

Figure 1.4. A source program is compiled into a machine-language file, which is then linked with the system library to form an executable file.

You can port (i.e., move) a source program to any machine with appropriate compilers. The source program must be recompiled, however, because the machine-language program can only run on a specific machine. Nowadays computers are networked to work together. Java was designed to run on any platform. With Java, you write the program once and compile the source program into a special type of machine-language code known as bytecode . The bytecode can then run on any computer with a Java Virtual Machine ( JVM ), as shown in Figure 1.5. The Java Virtual Machine is software that interprets Java bytecode.

Figure 1.5. Java bytecode can be executed on any computer with a Java Virtual Machine.


Note

Java bytecode is interpreted. The difference between compiling and interpreting is as follows . Compiling translates the high-level code into a target language code as a single unit. Interpreting translates the individual steps in a high-level program one at a time rather than the whole program as a single unit. Each step is executed immediately after it is translated.


 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

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