IntroductionComputer programs are collections of instructions that tell a computer how to interact with the user, interact with the computer hardware and process data. The first programmable computers required the programmers to write explicit instructions to directly manipulate the hardware of the computer. This "machine language" was very tedious to write by hand since even simple tasks such as printing some output on the screen require 10 or 20 machine language commands. Machine language is often referred to as a "low level language" since the code directly manipulates the hardware of the computer.By contrast, higher level languages such as "C", C++, Pascal, Cobol, Fortran, ADA and Java are called "compiled languages". In a compiled language, the programmer writes more general instructions and a compiler (a special piece of software) automatically translates these high level instructions into machine language. The machine language is then executed by the computer. A large portion of software in use today is programmed in this fashion.We can contrast compiled programming languages with interpreted programming languages. In an interpreted programming language, the statements that the programmer writes are interpreted as the program is running. This means they are translated into machine language on the fly and then execute as the program is running. Some popular interpreted languages include Basic, Visual Basic, Perl and shell scripting languages such as those found in the UNIX environment.We can make another comparison between two different models of programming. In structured programming, blocks of programming statements (code) are executed one after another. Control statements change which blocks of code are executed next.In object oriented programming, data are contained in objects and are accessed using special methods (blocks of code) specific to the type of object. There is no single "flow" of the program as objects can freely interact with one another by passing messages.In this tutorial, we focus only on structured programming.Program StructureVirtually all structured programs share a similar overall structure:Statements to establish the start of the programVariable declarationProgram statements (blocks of code)The following is a simple example of a program written in several different programming languages. We call this the "Hello World" example since all the program does is print "Hello World" on the computer screen.LanguageExample program"C"#includevoid main() {printf("Hello World");}C++#includeint main(){coutPascalprogram helloworld (output);beginwriteln('Hello World');end.Oracle PL/SQLCREATE OR REPLACE PROCEDURE helloworld ASBEGINDBMS_OUTPUT.PUT_LINE('Hello World');END;Javaclass helloworld{public static void main (String args []){System.out.println ("Hello World");}}Perl#!/usr/local/bin/perl -wprint "Hello World";Basicprint "Hello World"
Selasa, 22 Jun 2010
Langgan:
Catat Ulasan (Atom)
0 ulasan:
Catat Ulasan