Source Code. Projects. Nerd Stuff. Art Stuff.

Lesson 1: Introduction

Introduction to Computers and Programming

Hardware and Software

  • Hardware – physical machines
  • Program – set of instructions to run on those machines
  • Software – the collection of such programs

5 Main Components of Computer Hardware

  1. Central Processing Unit (CPU) – Fetches and follows instructions, and does simple arithmetic calculations. (Following simple instructions given to it.)
  2. Main Memory (RAM)- A silicon-wired card inside the computer box containing huge numbers of numbered memory locations (bits organized into bytes). High speed, low capacity. Volatile (memory is lost when power shuts down).
    • bit – a binary number; either 0 or 1. Stored electronically with 0 meaning off (no power flowing through a circuit) and 1 meaning on (power flowing).
    • Because computer memory is based upon this principle of 2 possible states, it’s useful to work with powers of 2 for computer memory.
    • byte – 8 bits, giving 28 (256) possible values – a more useful unit of measure
    • memory address – The location of the first byte of memory used for a variable. Stored numerically, often in hexidecimal (base 16) format.
  3. Secondary Memory – Hard drive, floppy drive, CD-ROM, etc. Low speed, high capacity. Non- volatile (nothing lost when power is cut.)
  4. Input Device – Keyboard Mouse, etc. (input stream)
  5. Output Device – Screen, Printer, etc. (output stream)

Making Software Work

  • Operating System – UNIX, Windows, Linux, etc. intermediary between hardware and software. Coordinates operation of tasks, allocates resources. The OS is a program itself.
  • High-level language – Java, C, C++, Pascal, Basic, etc. Platform-independent (commands are the same for all kinds of computers). Designed to be understandable by people, and usually compiled to work on computers.
  • Low-level language – Very simple computer instructions given one small step at a time. True Machine Language is made up of binary numeric codes for these instructions. We generally deal with its equivalent Assembly Language, which uses short abbreviations for commands, such as “add” for an addition calculation, or “sub” for subtraction. Platform-dependent (commands are different for different kinds of computers)
  • Compiler – Converts a high level language to assembly language, saving it in a new file. Source code to Object code. A compiler is a program, generally written in a high level language itself. Compilers are generally platform-dependent. They produce assembly language that works only on the machine they are running on.
  • There are two general categories of modern high-level programming languages: Scripting Languages and Compiled Languages. Compiled languages generally produce programs that run faster than scripting language programs.
  • C, C++, and Java are examples of Compiled Languages. With them, you write your complete program, compile it to an executable file, and then run that executable file. To make any changes, you have to change your program, re-compile, and run again from the beginning. Compiled languages are generally strongly-typed. (You have to declare variables and specify their data types before using them.)
  • Perl, PHP, Python and JavaScript are examples of Scripting Languages (Interpreted Languages). With them, you write your program, then run it through an interpreter that executes it immediately. You can make changes to the program as it’s running and see the results immediately. Scripting languages are generally loosely-typed. (You can use variables as needed without declaring them first.)
  • Open-Source Software (OSS) is computer software that is available in complete source code form for which the source code and certain other rights normally reserved for copyright holders are provided under a software license that permits users to study, change, and improve the software. Some open source software is available within the public domain. Open source software is very often developed in a public, collaborative manner.
  • Interpreter – a program which inputs a source code program (such as Perl or PHP) and executes it directly, converting each line of code to machine language as it goes. This is like compiling and running a program all in one step.

A Brief History of Programming Languages:

  • 1943: Colossus: the world’s first programmable, digital, electronic, computing device. Used by British codebreakers including Alan Turing to help read encrypted German messages during World War II.
  • 1946: ENIAC: the first American computer. Filled a large room, and required about 18,000 vacuum tubes. Designed by J. Presper Eckert and John Mauchly at the University of Pennsylvania.
  • 1957: FORTRAN: the first modern programming language, suited to numeric computation and scientific computing. Developed by John W. Backus at IBM. Still being used today.
  • 1964: BASIC: an acronym for Beginner’s All-purpose Symbolic Instruction Code. Designed by John George Kemeny and Thomas Eugene Kurtz at Dartmouth College in New Hampshire to provide computer access to non-science students. At the time, nearly all use of computers required writing custom software, which was something only scientists and mathematicians tended to be able to do.
  • 1972: C: Developed by Dennis Ritchie at the Bell Telephone Laboratories (now AT&T) for use with the Unix operating system. Allows easy manipulation of low-level memory, more so than most high-level languages.. Still one of the world’s most popular programming languages.
  • 1974: SQL: often pronounced like “Sequel”, stands for Structured Query Language., A database language designed for managing data in relational database management systems. Developed by Donald D. Chamberlin and Raymond F. Boyce at IBM. Still the most widely used language for relational databases.
  • 1983: C++: Originally an extension of C, but with object-oriented features added. Developed by Bjarne Stroustrup at Bell Labs (Now AT&T). Still one of the world’s most popular programming languages.
  • 1986: Objective-C: Developed by Brad Cox, licensed by NeXT Software, which was acquired by Apple Computer. Similar to C++, Objective-C is a reflective, object-oriented programming language which adds Smalltalk-style messaging to the C programming language. Objective-C is still widely used with Apple platforms such as the iPhone and iPad.
  • 1987: Perl: A high-level, general-purpose, interpreted, dynamic scripting language. The language provides powerful text processing facilities without the arbitrary data length limits of many contemporary Unix tools, facilitating easy manipulation of text files. It is also used for graphics programming, system administration, network programming, applications that require database access and CGI programming on the Web. Perl is nicknamed “the Swiss Army chainsaw of programming languages” due to its flexibility and adaptability. Developed by Larry Wall, and still widely used. It is open source.
  • 1991: HTML: stands for HyperText Markup Language. HTML is not a programming language. It is the predominant markup language for web pages. It provides a means to create structured documents by denoting structural semantics for text such as headings, paragraphs, lists, links, quotes and other items. It allows images and objects to be embedded and can be used to create interactive forms. It is written in the form of HTML elements consisting of “tags” surrounded by angle brackets within the web page content. It can embed scripts in languages such as JavaScript which affect the behavior of HTML webpages. HTML can also be used to include Cascading Style Sheets (CSS) to define the appearance and layout of text and other material. HTML was originally developed by Tim Berners-Lee at CERN (European Organization for Nuclear Research).
  • 1991: Visual Basic: Event-driven programming language and integrated development environment (IDE). VB is considered a relatively easy to learn and use programming language, because of its graphical development features and BASIC heritage. Developed by Alan Cooper, sold to Microsoft.
  • 1991: Python: a general-purpose high-level programming language whose design philosophy emphasizes code readability. Python aims to combine “remarkable power with very clear syntax”. Its use of indentation for block delimiters is unusual among popular programming languages. Python is often used as a scripting language. Developed by Guido van Rossum at CWI in the Netherlands. Python is open source.
  • 1995: Java: Similar syntax to C++, but built for imbedded devices and the internet, fully object-oriented. Has a simpler object model and fewer low-level facilities. Developed by James Gosling at Sun Microsystems (now Oracle). Competes with C++ for the world’s most popular programming language. It is somewhat open source.
  • 1995: PHP: (Stands for Hypertext Preprocessor). A widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document. As a general-purpose programming language, PHP code is processed by an interpreter application in command-line mode performing desired operating system operations and producing program output on its standard output channel. It may also function as a graphical application. PHP is available as a processor for most modern web servers and as standalone interpreter on most operating systems and computing platforms. PHP was designed by Rasmus Lerdorf, and is open source.
  • 1995: Ruby: a dynamic, reflective, general purpose object-oriented programming language that combines syntax inspired by Perl. Ruby was developed in Japan by Yukihiro “Matz” Matsumoto. Around 2005, interest in the Ruby language surged in tandem with Ruby on Rails, a popular web application framework written in Ruby. Rails is frequently credited with making Ruby “famous”. Ruby is open source.
  • 1996: Flash: Adobe Flash is a multimedia platform used to add animation, video, and interactivity to Web pages. Flash is frequently used for advertisements and games. Flash contains an Object- oriented language called ActionScript. Developed Adobe Systems (formerly Macromedia).
  • 1996: JavaScript: Very different from Java. A scripting language (not compiled) that is primarily used in the form of client-side JavaScript, implemented as part of a web browser in order to provide enhanced user interfaces and dynamic websites. JavaScript and Java have similar syntax, and JavaScript copies many Java names and naming conventions; but the two languages are otherwise unrelated and have very different semantics. Developed by Brendan Eich at Netscape (now AOL).
  • 1998: XML: Extensible Markup Language is not a programming language. It is a set of rules for encoding documents in machine-readable form. It is similar to HTML, but much more general and flexible. Developed by a working group of the World Wide Web Consortium (W3C).
  • 2000: C#: Developed by Anders Hejlsberg at Microsoft, within the .NET initiative. Combines ideas from Java and C++, along with the capability to easily interoperate with programs written in other languages.

C++ Code and Compilers

  • Examples of C++ compilers are aCC, g++, Eclipse, Bloodshed Dev C++, Microsoft Visual C++, and Borland Turbo C++. Compilers are platform-dependent. They produce assembly language that works only on the kind of machine they are running on.
  • Steps in making a program work:
    1. Use a text editor to create file containing the C++ program (source file)
    2. Run preprocessor to convert source file directives to source code program statements
    3. Run compiler to convert source program into machine instructions
    4. Run linker to connect hardware-specific code to machine instructions, producing an executable file
    5. Steps 2-4 are often performed by a single command or button click (such as aCC on hills)
    6. Errors detected at any step will prevent execution of following steps.
  • Here is a simple C++ program:

        /* Craig Persiko
           Simple Hello World program
        #include <iostream>
        using namespace std;
        int main()
          cout << "Hello, World!\n"; //Display the string.
          return 0;

  • The above program will compile correctly, but if you make one small change, it probably will produce a compiler error.
  • The formatting of the above program is largely for human readability. Programs are written for 2 audiences: they must make sense to both the computer and to other programmers.
  • For example, the semicolon is used to mark the end of a line of code. Hitting return after each line is just us to be able to read it better.
  • The first line, which begins with “/*” is the beginning of a comment. Everything from /* to */ is ignored by the compiler; it’s just there for us to read. Another way to specify a comment is to begin it with “//”, then the comment ends at the end of the line (like “//Display the string.” above)
  • Lines beginning with “#” are Preprocessor Directives, which specify a library of C++ code to be imported and used by this program. The line:
    #include <iostream>
    loads the code to make “cout” work for output.
  • Every stand-alone C++ program must have a main function, which begins with the header:
    int main()
  • Key Words such as “using”, “namespace”, “int”, and “return” are words that have a special meaning in C++. Also called Reserved Words
  • Operators are symbols that have special meaning in C++ (common examples are: + – * / ). In this program, the Insertion Operator “<<” is used
  • Punctuation such as the semi-colon “;” the curly-braces “{” and “}” and parentheses “(” and “)” is needed in C++ to mark boundaries between statements, etc.
  • Literals are explicit values in a program, such as the string “Hello, World!”

Software Development

  • Software Development Life Cycle – Analysis, Design, Implementation, Testing, Maintenance/Evolution, Obsolescence. Implementation (writing code in Java or other languages) occupies only 20% of the total development time for a project.
  • Testing and Debugging – 3 kinds of errors: Syntax/Compile-time, Run-time, and Logic. Syntax errors often confuse the compiler, so attack the first error, then try compiling again.
  • Algorithm – a sequence of precise instructions. May be conveyed using flowchart, logic diagram, pseudo-code, or such. Planning saves time! Think in terms of what you want, how you can do it, before you dive in.
  • Here’s an example of a pseudo-code algorithm to buy the textbooks for a class, using parameters for the course number and section number:To buy the books for CS 110A Section 001, you would write:
    BuyTextBooks(CourseNumber=”CS 110A”, SectionNumber=”001″);To buy the books for English 1A Section 581, you would write:
    BuyTextBooks(CourseNumber=”ENGL 1A”, SectionNumber=”581″);Here is the generic algorithm to buy textbooks:BuyTextBooks(CourseNumber, SectionNumber):

    1. Go to the college bookstore.
    2. Pick up a shopping basket.
    3. Find the section for textbooks.
    4. Locate the shelf labeled for CourseNumber and SectionNumber.
    5. Repeatfor each required book for this course section:
      1. Determine the required book�s title and author.
      2. Pick up a copy of the required book and put it in your shopping basket.
    6. Repeatfor each optional book for this course section:
      1. Determine the optional book�s title and author.
      2. Pick up a copy of the optional book.
      3. Look at optional book to decide if you want to buy it:
      4. Ifyou want to buy the optional book:
        1. Put the optional book in your shopping basket.
      5. If you do notwant to buy the optional book:
        1. Put the optional book back on the shelf where you found it.
    7. Go to the cash register.
    8. Pay for the book(s) in your shopping basket.
    9. Exit the bookstore with your books.