Title: COMP 14: Intro. to Intro. to Programming
1COMP 14 Intro. to Intro. to Programming
- May 23, 2000
- Nick Vallidis
2What well talk about today...
- Brief overview of computers
- Hardware and Software
- What is programming?
- Java
- Algorithms
3Computers
- Basically information processors
- Take info, do something to it, spit it out again
- Digital
- Store the information as numbers (digits)
- Use the binary number system
4Computers are made of 2 things
- Hardware
- The part you can see and touch
- CPU, monitor, mouse, keyboard
- Software
- Information to tell the computer HOW to process
information - OS, compiler, word processor, games, etc.
5Hardware
- CPU Pentium (II/III), Alpha, Athlon
- Memory RAM, floppy disk, hard drive, CD
- Input Devices keyboard, mouse, data tablet
- Output Devices monitor, printer
6Our view of the hardware
Central Processing Unit
Secondary Memory
Main Memory
7CPU
- Central Processing Unit
- Continuously does fetch-decode-execute
8Memory
- An address is the name of a specific location in
memory - Main Memory
- run programs from here
- fast, volatile
- Secondary Memory
- slow
- permanent
9This class is about Software
- Operating System (OS)
- Understands the hardware
- Simplifies your interaction with the hardware
- Controls starting/stopping applications
- Applications
- any software that isnt the OS
- what you will learn to write
10Computer Languages
- Machine Language
- the form the CPU understands
- strings of 1s and 0s
- Assembly Language
- people-friendly version of machine language
- High-level languages
- Java, C, FORTRAN, COBOL, BASIC
11Compilers and Interpreters
- Both are ways to turn high-level languages into
something the computer can execute - Compilers turn a source code file into an
executable - Interpreters let you type the program into it and
run it directly
12Java is compiled and interpreted
Java source code
Java bytecode
Java compiler
Java interpreter
Bytecode compiler
Machine code
13So what is programming?
- Programming IS problem solving
- Takes multiple steps
- understand what the problem is
- find a solution (algorithm) for the problem
- determine if the solution is correct
- implement the solution
- test the solution implementation
14Implementation
- Not any more important than other steps, but
probably the one you know the least about - We are using Java
15Simple Java Program
public class Simple public static void
main(String args) System.out.println(Hello
!)
16Simple Java Program
All programs have to be part of a class
public class Simple public static void
main(String args) System.out.println(Hello
!)
17Simple Java Program
Tells the computer where to start running the
program
public class Simple public static void
main(String args) System.out.println(Hello
!)
18Simple Java Program
public class Simple public static void
main(String args) System.out.println(Hello
!)
Braces indicate where different sections of the
program begin and end
19Simple Java Program
public class Simple public static void
main(String args) System.out.println(Hello
!)
This tells the computer to print out Hello!
(without quotes)
20Simple Java Program
public class Simple public static void
main(String args) System.out.println(Hello
!)
This indicates the end of a statement (one step
in the program)
21Simple Java Program
public class Simple public static void
main(String args) System.out.println(Hello
!)
These are reserved words in Java. This means that
Java uses them for a special purpose
22Java Reserved Words
abstract boolean break byte byvalue case cast catc
h char class const continue
default do double else extends false final finally
float for future generic
goto if implements import inner instanceof int int
erface long native new null
operator outer package private protected public re
st return short static super switch
synchronized this throw throws transient true try
var void volatile while
23Simple Java Program
public class Simple public static void
main(String args) System.out.println(Hello
!)
These are identifiers. These are words chosen by
a programmer as names for things.
24Java Identifiers
- Can include letters, digits, , and _
- Must not start with a digit
- They are case sensitive
25Simple Java Program
Red identifiers were chosen by the author of this
program
public class Simple public static void
main(String args) System.out.println(Hello
!)
Blue identifiers were chosen by another
programmer.
26Identifier guidelines
- You want to choose descriptive identifiers
- things like a, b, dm, tu are bad
- things like lastValue, cost are good
- If multiple words, start each new word with a
capital letter
27Comments
- You can insert comments in the code that are
completely ignored by the compiler - two styles
- / everything in here is a comment /
- // everything to the end of line is a comment
- I was very bad and didnt comment the program I
showed before. Lets fix that...
28Simple Java Program
/ a very simple Java program / public class
Simple // prints a message to the user public
static void main(String args) System.out.pr
intln(Hello!)
29Algorithms
- A step-by-step description of a solution to a
problem - In some sense the computer is stupid and needs
very explicit instructions
30Homework
- Read Ch. 1 (there are more specific instructions
on the web page, but its ok if you just read the
whole thing) - Write an algorithm for making a peanut butter and
jelly sandwich