Docstoc

Introduction to Computers and Programming

Document Sample
Introduction to Computers and Programming Powered By Docstoc
					Algorithm
development
The invention of the computer
o Programming language developments:
   1.   Machine code
   2.   Assembler
        p   easier to write, debug, and update
   3.   High level languages
        p   strive to be machine independent
        p   easier to learn and use
        p   1954 – FORTRAN
        p   1961 – COBOL
        p   then ALGOL, LISP, BASIC
        p   1970 – Pascal
        p   1980’s – C
        p   1990’s – C++, Java (originally called ?)
        p   and many, many others
High level langauges (HLL)

o Not directly understood by the computer


o Humanly readable


o Requires the user of a compiler
  n   Compiler    = program
       p Input    = code written in a HLL
       p Output   = machine code
Pascal (an HLL)

o   1970’s
o   Support for “structured programming”
    n   Control constructs
        1. Linear sequence of commands/instructions
        2. Repetition
        3. Selection
p   Top-down programming
    p   Problem is broken down into a series of smaller
        problems which are solved.
    p   Divide-and-conquer technique.
Types of software

1. OS (operating system)


2. Programming environment/tools


3. Applications
Operating Systems (OS)

o Windows
o Linux
  n   Android (linux-based)
o Unix
o Mac OS
o many others
Programming
environments/tools
o Tools
  n   emacs (an editor – not a word processor)
  n   vi
  n   g++
  n   gdb
Programming
environments/tools
o IDE’s (Integrated Development
  Environment)
  n   consist of: editor, compiler or interpreter,
      debugger, linker

  n   examples: jGrasp, netbeans, Eclipse,
      Ready, Visual C++, Visual BASIC,
      JBuilder, and many others
Applications

o   Computer games
o   Word processors
o   Graphics packages
o   Virtual reality software
o   Web browsers
o   Presentation
o   Database
o   Spreadsheet
o   And many others.
Social issues

o Privacy/anonymity


o Quality of information
Program development

o Our programming language is Java.


o The IDE we will use is jGrasp.
  n   Editor is used to type in program text (it is
      not a word processor; don’t use a word
      processor).
  n   Compiler (syntax errors)
  n   Run/execute (semantic errors)
Program development

o Java is an object-oriented language.
   n (Note: Case sensitive.)


o Method
  n named operation
  n constructor (ctor)
      p special method w/ same name as class
      p performs initialization
      p class may have more than 1 ctor

o Class
  n named group of related methods
      Recall “What is a computer?”


   INPUT        PROCESSING    OUTPUT
(information)                (information)

                 MEMORY
Definitions         (from http://mathworld.wolfram.com/Algorithm.html)




o   An algorithm is a specific set of instructions for
    carrying out a procedure or solving a problem,
    usually with the requirement that the procedure
    terminate at some point.
Definitions          (from http://mathworld.wolfram.com/Algorithm.html)




o   Specific algorithms sometimes also go by the
    names:
    n   method
    n   procedure
    n   routine
    n   subroutine
    n   technique
Definitions       (from http://mathworld.wolfram.com/Algorithm.html)




The word “algorithm” is a distortion of al-Khwārizmī,
a Persian mathematician who wrote an influential
treatise about algebraic methods.
Definitions       (from http://mathworld.wolfram.com/Algorithm.html)




The process of applying an algorithm to an input
to obtain an output is called a computation.
      Recall “What is a computer?”


   INPUT          PROCESSING      OUTPUT
(information)                   (information)

                   MEMORY


      o How can a Java program perform
        output?
How can a program perform
output?


System.out.println( "hello world" );
blocks

{
    System.out.println( "Welcome!" );
    System.out.println( "Enjoy the show." );
}
Method/function/procedure

public static void main ( String param[] ) {

    System.out.println( "hi there" );

}
Defining our own objects

class MyFirstClass {

    public static void main ( String param[] ) {

        System.out.println( "hi there" );

    }

}
      Recall “What is a computer?”


   INPUT        PROCESSING        OUTPUT
(information)                    (information)

                  MEMORY


      o How can a Java program perform input?
How can a Java program
perform input?
…
Scanner s = new Scanner( System.in );
…
String str = s.nextLine();
…
We can mix input and output.

Scanner s = new Scanner( System.in );

System.out.print( "Enter your name: " );

String name = s.nextLine();

System.out.println( "Thanks." );

s.close();
Complete program that does
both input & output.
import java.util.Scanner;

class MySecondClass {

    public static void main ( String param[] ) {
           Scanner s = new Scanner( System.in );

          System.out.print( "Enter your name: " );

          String name = s.nextLine();

          System.out.println( "Thanks." );

          s.close();
    }
}

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:0
posted:4/10/2014
language:Unknown
pages:26