2017年7月21日 星期五

CS106A - Programming Methodology - Lecture 4

History of computing

4000 years? Advocates? (abacus?)

Charles Babbage
Difference engine
analytic engine

Ada Byron
First programmer

1930-40's
prototypes

1946
ENIAC

1971
microprocessor





CS computer science
science/study of problem solving of computers/computational devices(methods)

Programming is just one of the process

What Does The Computer Understand?

0s and 1s
on and off

machine language
high level language (people are bad at writing 0s and 1s)

how do you go from high level language to machine language

"compilation process"

"source code"(high level)

"object code"(low level/ machine)

ex. eclipse is a compiler

source code -> compiler -> object file ->
                                           linker -> executable file
                    other object file  ->
                        libraries
(The general situation in C or C++)


"The java interpreter"
                                        (some intermediate language)
source file > compiler -> class file ->
                                        linker -> JAR archive (java archive archive) (台北駅駅)
                     other class file ->
                                                  JVM(java virtual machines)
                                                  "really run the program on your computer"


why do the extra things?
To make all the different computers understands the same "code"
no matter PC, Mac or Linux

-------------------

Java is an object-oriented language

java program can have more than one class

class: behaviors and data

"hierarchies" multiple levels

superclass   Karel
subclass      SuperKarel

class hierarchy
a superclass could have different subclasses under it but all share the same characters

object is an instance of a class
template

"acm.program hierarchy"

Applet (run on webpage, like application but small)
JApplet (Java applet)
Program
ConsoleProgram  DialogProgram  GraphicsProgram

import acm.graphics.*;
import acm.program.*;

public class HelloProgram extends GraphicsProgram {
    public void run () {
        add( new GLabel( "hello, world", 100, 75) );
    }
}

looks similar to Karel!!

all java programs are collections of  java classes


Console program

import acm.program.*;
//no need of acm.graphic

public class Add2Integers extends ConsoleProgram {

    public void run (){
        println ("This program adds two numbers");
        int n1 = readInt ("Enter n1: ");
        int n2 = readInt ("Enter n2: ");
        int total = n1 + n2;
        println ("The total is " + total + ".");
    }

}

Graphics

collage model

blank canvas and put objects on the canvas

GLabel just text
GRect Rectangle
GOval
GLine

^they are classes




沒有留言:

張貼留言