Title: A Terminal Session
1A Terminal Session
- Log In Username and Password
- A window appears
- Check the prompt
- some computer name other stuff gt
- styx.cse.buffalo.edu is the computer, there are
many. - can be anything
- gt is where you type
- 4. set prompt / gt
2Creating Folders (or Subdirectories, or Work
Areas)
- You type
- set prompt/ gt
- eng/home/mikebgt mkdir Lab1
- eng/home/mikeb gt cd Lab1
- eng/home/mikeb /Lab1 gt
- What just happened?
- eng/home/mikeb /Lab1 gt cd
- eng/home/mikeb gt
3Work Areas on the main computer disk
mkdir Lab1 cd Lab1
/
Lab1/
/Lab1 Work Area is the location of edited
files
4What is a file?
- Dear John,
- I think we should just be
- friends
Created and Saved in an editor eng gt
/util/bin/jgrasp Dearjohn.txt Could be a Java
program eng /Lab1 gt /util/bin/jgrasp
myProgram.java
5so far
- We address the computer through a terminal window
in a primitive language called Unix - Unix allows us to set aside private areas of the
disk and go to them to do our work - Once there, we can open, edit, and save files
which will later become programs - Computer Scientists model some aspect of the real
world in the computer program - Computer programs make extensive use of changing
values called variables.
6Concatenation (Sequencing)
- Computers perform one small step at a time, in a
stated order. - z 0
- x 15
- y 12
- z x y
- print z
7Variables
- x, y, z
- i, j, k
- TotalCountOfNewEmployees
- Geekish_Designations_0123
- They Stand for Something
8The ESSENCE of a variable
- a 15
- b 12
- c ab What is C?
- b 1288
- c ab What is C now?
- b, and c, are both CHANGEABLE
9Variable Types (primitive, common)
- Integers meant to be a whole number (used for
counting) - Floating Pt. meant to be a detailed number
(used for measuring) called a DOUBLE - Character has no meaning other than to be read
by a human - Strings of Characters have no meaning other
than to be read by a human
10x 14
- Could mean 14 (not likely)
- Could mean 13.999995
- Could mean 14.000001
- Could mean 20 (honestly), might not be base-10,
more later - Could mean Fourteen, which has no meaning other
than to be read by humans
11Typing a variable
- Integer X
- X 14
- Therefore, 14 means 14
- Float X (or Real X, or Single X, or Double X)
- X 14.0000
- Therefore, X has meaning, 14 to 4 places
12More
- Char X, Y
- X 1
- Y 4
- X with Y 14 (Concatenation)
- String Z
- Z cat
13Legality
- Variable value and variable type must be the
same. - Deterministic behavior - All computers yield the
same result with the same variables
14Computers check our programs
- Called Compilation
- Must be successful before a program can run
15Illegality
- Compiler Errors however, some languages and
compilers allow mis-designations of variables - Indeterminate results
- Run-time Errors
16Compilation
will it work?
17Illegal
- Integer Y
- Y 14.001
- Char Q
- Q abcdef
- Double z
- z hello
18Why Type Variables
- Deterministic behavior of variables and the
numbers they represent. - New definition of Legality We will never
perform mathematical or logical operations on
variables of different types.
19Illegal, part 2
- Integer X
- Double Y
- Char Z
- X 12
- Y 16.001
- Z X Y
20Legal Operation
- String K
- Char I, J
- I H
- J i
- K I with J (what is K?)
21New Types
- Boolean TRUE or FALSE (really means presence or
absence), used to signify a condition, or
state of being. - Boolean X, Y, Z
- X TRUE (means X is present)
- Y FALSE (means Y is NOT present)
- Z X OR Y (what is Z?, i.e. does Z signify
some presence?) - Z X AND Y (what is Z?)
22floating point?
- 14.6567
- 128.1231
- 154367.001423
- 3.14159
- 987987465986543.
233 categories of ILLEGAL
- Variables set to a value wrong for its type
- Integer X
- X TRUE
- 2. Variables of different types used in the same
operation - Integer X, Y
- Char Z
- Z X Y ( multiply)
- 3. Operation wrong for variable type
- String Z cat
- Q X Z
-
24Constants
- constant integer X
- or
- final integer X
- X 16
-
- X 14 illegal!
25Algorithms
- Series of mathematical or variable manipulations
- Integer a,b,c
- a 12
- b 22
- c a b (what is c?)
26Complicated, Concatenated Algorithms
- integer Total, LoopCounter
- Total 0
- LoopCounter 0
- Start
- Add 2 to Total
- Add 1 to LoopCounter
- Go Back to Start Until Total 12
- What is LoopCounter?
two variables
a loop
done
27Written in Code
- int LoopCounter, Total
- LoopCounter 0
- Total 0
- while (Total lt 12)
-
- Total Total 2
- LoopCounter LoopCounter 1
-
semicolon
no semicolon (because brackets follow)
open bracket
odd-looking algebra
close bracket
28Real code
- public class Looper
-
- public static void main( String args
) - int LoopCounter, Total
- LoopCounter 0 Total 0 while
( Total lt 12 ) Total Total
2 LoopCounter LoopCounter 1
System.out.println( LoopCounter )
file
program
loop
Output!
29Summary
- Concatenation
- Typing
- Legality
- Algorithm
- Code
30Code summary
- public class filename
- public static void main( String arg )
- surround functional paragraphs
-
- semicolon