CS 112 Introduction to Programming - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

CS 112 Introduction to Programming

Description:

Teaching fellows will hold office hours M,Tue,Thur, from 3:00-5:00pm at Dunham ... involve multiple files, you need to generate a jar file for submission. ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 25
Provided by: Richar9
Category:

less

Transcript and Presenter's Notes

Title: CS 112 Introduction to Programming


1
CS 112 Introduction to Programming
  • Lecture 3
  • Computer Hardware/Software, and Sun SDK
  • Richard Yang

2
Outline
  • Admin. and review
  • Computer hardware/software
  • Write your first Java program

3
Admin.
  • Please finish reading Chap. 1.0-1.4
  • Assignment 1 is online due Sep. 18
  • Must run on Sun SDK
  • Can be either Unix or Windows
  • Teaching fellows will hold office hours
    M,Tue,Thur, from 300-500pm at Dunham Garage
    computer lab (Dunham 120) to help you get started
  • Only 18 computers, please schedule your time
  • TFs can meet with you at other time as well,
    please send email to make an appointment

4
Review
  • Different programming language levels
  • Machine code, assembly code, high level languages
  • A compiler translates a program in a high level
    language to machine code
  • Java compiler compiles a Java program to the
    machine code of Java virtual machine thus Java
    needs an interpreter for execution
  • Structure of a Java program
  • A program consists of one or more classes
  • A class consists of one or more methods
  • A method consists of one or more statements
  • Comments, identifiers, reserved words, and white
    space
  • Our first Java program

5
Outline
  • Admin. and review
  • Computer hardware/software
  • Write your first Java program

6
Computer Environment Hardware
  • Hardware
  • the physical, tangible parts of a computer
  • E.g., CPU, storage, keyboard, monitor

7
Storing Information
  • Computers store all information digitally
  • E.g. numbers, text, audio, video, program
    instructions
  • Information is stored in binary numbers
  • A single binary digit (0 or 1) is called a bit
  • A single bit can represent two possible states,
    like a light bulb that is either on (1) or off
    (0)
  • Combinations of bits are used to store values

8
Binary Bit Combinations
Each additional bit doubles the number of
possible combinations
9
Information is Stored in Memory
Each memory cell has a numeric address, which
uniquely identifies it
9278 9279 9280 9281 9282 9283 9284 9285 9286
10
The Central Processing Unit
  • A CPU is also called a microprocessor

11
The Central Processing Unit
  • A CPU continuously follows the fetch-decode-execut
    e cycle

Retrieve an instruction from main memory
a b c d
fetch
load b, r1 load c, r2 add r1, r2, r3 load d,
r4 add r3, r4, r5 store r5, a
decode
execute
Determine what the instruction is
Carry out the instruction
12
Computer Environment Software
  • Operating System
  • E.g., Windows 2000, Windows XP, Linux, Sun
    Solaris, Mac OS X
  • manages resources such as CPU, memory, and disk
  • controls all machine activities
  • Application program
  • generic term for any other kind of software
  • compiler, interpreter, word processors, missile
    control systems, games

13
Operating System
  • What does an OS do?
  • hides low level details of bare machine
  • arbitrates competing resource demands
  • Useful attributes
  • multi-user
  • multi-tasking

14
Example Operating Systems
  • Windows micro-kernel (make OS simple)
  • Unix monolithic kernel (make OS more capable)
  • Brief history
  • successor to Multics (65-70)
  • ambitious project at MIT
  • pioneered most of the innovations in modern OS
  • scaled down version by Thompson and Ritchie
    (1969)
  • ATT (70-80s)
  • Berkeley (BSD) produced a mature version (e.g.
    networking)
  • various flavors of commercial Unix
  • latest incarnation Linux
  • main features
  • processes
  • files

15
Unix File System
  • Hierarchical name space (directories, files)
  • same as folders and files on Windows
  • Permanent storage
  • Filename sequence of directory names ending with
    a file name (/usr/local/bin/foo)

/home/richter
Windows uses backslash C\cs112\lectures
16
Unix Commands
  • mkdir bar creates a directory bar)
  • cd /usr/local/bin changes current dir. to
    /usr/local/bin
  • pwd gives you the current
    directory
  • ls lists files in current
    directory
  • cp /usr/local/bin/foo /tmp/bar copies a
    file
  • cp /usr/local/bin/foo bar copies to the
    current directory
  • cat foo shows contents of file foo
  • rm foo, or rmdir bar remove a
    file/directory
  • chmod changes permissions
  • man ls gets help on command ls

17
Outline
  • Admin. and review
  • Computer hardware/software
  • Write your first Java program
  • Ultimately, you must test your program using Sun
    SDK
  • Sun SDK options
  • Pantheon Unix
  • Windows

18
Pantheon Environment
  • The "Pantheon" is a collection of computers
    named after Greek gods
  • Generally, you use ssh to login to eli.yale.edu
    eli.yale.edu will automatically direct you to
    one of the machineshttp//pantheon.yale.edu/help
    /ssh/
  • They run the Unix operating system
  • Linux
  • Sun Solaris
  • General help on pantheon is available at
  • http//pantheon.yale.edu/help/

19
Login, Edit, Compile, Run and Generate jar on a
Pantheon Machine
  • - Help
  • http//zoo.cs.yale.edu/classes/cs112/help/pantheon
    _java.html
  • - Login to a pantheon machine using sshif you
    want to know the OS ? typeuname a
  • Create a directory for your cs112 (only
    once)mkdir cs112
  • Change to the directory
  • cd cs112
  • Edit your Java program using pico, or another
    editor, e.g., emacspico HelloJava.javatype in
    your program, press control-X, type y, press
    return

20
Login, Edit, Compile, Run, and Generate .jar on a
Pantheon Machine (Cont.)
  • Due to a mis-configuration, javac and java are
    not defined on some pantheon machines. Find
    themlocate javac
  • Compile the Java program/usr/java/j2sdk1.4.0_01/
    bin/javac HelloJava.java
  • Take a look to see that HelloJava.class is
    generatedls
  • Run Java interpreter
  • /usr/java/j2sdk1.4.0_01/bin/java HelloJava
  • Since all homework assignments involve multiple
    files, you need to generate a jar file for
    submission. Suppose you also need to submit
    Errors.txt/usr/java/j2sdk1.4.0_01/bin/jar cvf
    RichardYang1.jar HelloJava.java Errors.txt
  • Take a look to see that RichardYang1.java is
    generatedls

21
Outline
  • Admin. and review
  • Computer hardware/software
  • Write your first Java program
  • Pantheon Unix
  • Windows

22
Edit, Compile, Run, and Generate .jar Using Sun
SDK without Forte
  • - Help
  • http//zoo.cs.yale.edu/classes/cs112/help/sunsdk.h
    tml
  • Install Sun SDK, make sure you set the
    PATHvariablehttp//java.sun.com/j2se/1.4/install
    -windows.html
  • Create a directory for your cs112 (only
    once)C\gtmkdir cs112
  • Change to the directory
  • C\gtcd cs112
  • Edit your Java program using a text
    editorC\cs112gtnotepad HelloJava.java

23
Edit, Compile, Run, and Generate .jar Using Sun
SDK without Forte (cont.)
  • Compile the Java programC\cs112gtjavac
    HelloJava.java
  • Take a look to see whether HelloJava.class is
    generatedC\cs112gtdir
  • Run Java interpreter
  • C\cs112gtjava HelloJava
  • Since all homework assignments involve multiple
    files, you need to generate a jar file for
    submission. Suppose you also need to submit
    Errors.txt.C\cs112gtjar cvf RichardYang1.jar
    HelloJava.java Errors.txt
  • Take a look to see that RichardYang1.java is
    generatedC\cs112gtdir

24
Edit, Compile, Run, and Generate .jar Using Sun
SDK with Forte for Java
  • Seehttp//zoo.cs.yale.edu/classes/cs112/help/fort
    e/index.html
Write a Comment
User Comments (0)
About PowerShow.com