while loops check boolean condition, do-while loops perform the body once before checking the boolean condition
3
New cards
for loops
common example: we want to do something 1000 times for (int i = 0; i < 1000; i = i + 1) { } **everything in the parentheses after the "for" is a boolean condition
4
New cards
what is the boolean condition in loops called
the loop guard
5
New cards
what happens if the boolean condition evaluates to false in for loops
the code jumps out of the loop, no increments occur
6
New cards
Gaust's Formula
1 + 2 + 3 + 4 + ... + n = [n(n+1)/2]
7
New cards
nested loops (options for example w printing X's or O's)
- using a "formula" to compute # of Xs or Os on current row - maintaining variable(s) for # of Xs or Os on current row - using a comparison to decide whether to print X or O
8
New cards
what are the types of programming errors
syntax, semantic/logical (bugs)
9
New cards
what are syntax errors
- trivial, didn't follow the rules of the language - Eclipse will flag them w/ red marks
10
New cards
what are semantic/logical errors
- code compiles but doesn't work right when it's run - debug - finding mistake + fixing it
11
New cards
what is a piece of advice for dealing w bugs in your code
write code incrementally and test
12
New cards
types of conditional statements
if, if-else
13
New cards
if statement
if () { }
14
New cards
how do if-else statements work
they either execute one block or another (never both)
15
New cards
if-else statement
if () { } else { }
16
New cards
true or false: for conditional statements, braces are optional for blocks containing a single statement
true
17
New cards
what are the logical operators with boolean expressions
&& (and), || (or), ! (not)
18
New cards
what does the else correspond with when nesting if and if-else statements when there are no braces
the most recent if
19
New cards
statements end with
semicolons
20
New cards
what are identifiers
the name of something in java
21
New cards
what are some examples of identifiers
variable names, method names, class names, packages, interfaces, enumeration
22
New cards
what are the rules when creating identifiers
- can only use: A-Z, a-z, 0-9, _, $ - cannot begin w a digit - must avoid keywords
23
New cards
what are keywords
words that are part of the Java language
24
New cards
give an example of the importance of case differentiation
Else can be an identifier, else cannot
25
New cards
what is style for identifiers
- lower camel case for variables, methods, and packages - upper camel case for classes, interfaces, and enumerations
26
New cards
how to choose meaningful identifiers
- should be made of English word(s) describing the role of the entity - you can abbreviate, don't make it too long
27
New cards
when can you use single-letter identifiers
- in for-loops (when representing index numbers) - for coordinates with computer graphics
28
New cards
what is a named constant
a variable that is assigned a constant value (easy for maintenance)
29
New cards
what is the style for named constants
all caps, underscores between words
30
New cards
when should you use named constants
almost every time there is a literal in your program
31
New cards
why are named constants important
the value of a variable may change one day, also makes it easier for readability
32
New cards
what keyword should you use before a variable declaration of a named constant and what does it indicate
final - says the variable's value cannot be changed later
Is the following boolean expression true or false?((3 < 5) && !(1 > 14) && (-5 < -15)) || ((6 == 6) && !(2 == 2))
false
40
New cards
If s1 and s2 are variables representing Strings, what Java boolean expression is equivalent to "s1 is not the same as s2"?
!s1.equals(s2)
41
New cards
What statement must be included at the top of a file in order to use the Scanner in the file?
import java.util.Scanner;
42
New cards
What does IDE stand for?
Integrated Development Environment
43
New cards
What IDE will we use in class this semester?
Eclipse
44
New cards
What does CPU stand for?
Central Processing Unit
45
New cards
Define the term "bit".
A "binary digit" -- either 0 or 1.
46
New cards
Define the term "byte".
A sequence of 8 bits (not a set/collection)
47
New cards
What is "hardware"? Name some examples.
Physical components of the computer. (Things you can "touch"). Examples include: CPU, RAM chips, mother board, disk drives, monitor, mouse, keyboard, cables.
48
New cards
What is "software"? Name some examples.
These are the "programs" or "apps" that you can run on a computer. Examples: Internet browsers, games, word processors, spreadsheet programs, the operating system, etc.
49
New cards
Name several different operating systems
Windows, macOS, Android, ios, unix, linux, solaris
50
New cards
Give some examples of secondary memory devices.
Hard drives, flash memory devices, CD's , DVD's
51
New cards
What is the advantage of primary memory over secondary?
It is typically much faster.
52
New cards
What is the advantage of secondary memory over primary?
It is permanent. (Also usually there is more of it!)
53
New cards
What does I/O stand for? Give some examples of I/O devices.
Input/Output. These are devices that allow you to communicate with the computer: monitor, keyboard, mouse, printer, etc.
54
New cards
How many different combinations of 0's and 1's can be represented using 7 bits?
2^7 = 128
55
New cards
How many bytes are in a kilobyte?
2^10 = 1024 (1000)
56
New cards
How many bytes are in a megabyte?
2^20 (1 million)
57
New cards
How many bytes are in a gigabyte?
2^30 (1 billion)
58
New cards
Name four things that the operating system does for you.
- Process management - Memory management - Primitive I/O - Windowing - Primitive network control - Security management
59
New cards
What do you call the language that the CPU uses (0's and 1's represent instructions in this language)?
machine language (CPUs don't understand java)
60
New cards
How does "assembly language" relate to your answer to the previous question?
Assembly language is a mnemonic representation of machine language (assembly language is low-level, readable matching language)
61
New cards
Translate the number 123 into base 7 representation.
234 (base 7)
62
New cards
Translate the binary (base 2) number 1011010 into base 10 representation.
90
63
New cards
Translate the hexadecimal (base 16) number 7F into binary representation.
01111111
64
New cards
Translate the decimal (base 10) number -16 into 8 bit 2's complement representation.
11110000
65
New cards
what number base do we normally use for numbers
base 10 or decimal
66
New cards
what are important bases in CS
base 2 (binary), base 16 (hexadecimal)
67
New cards
how to convert from another base to base 10 (example with 1032 base 4)
starting from the right, take the digit and multiply it by the other base to the power of what position the number is in 1032 base 4: 2 x 4^0 = 2 3 x 4^1 = 12 0 x 4^2 = 0 1 x 4^3 = 64 2 + 12 + 64 = 78
68
New cards
digits in binary
0, 1
69
New cards
digits in hexadecimal
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A (10), B (11), C (12), D (13), E (14), F (15)
70
New cards
how to convert from base 10 to another base
divide the given number by the other base multiple times, take the remainders as digits starting from the ones place and going to the left
71
New cards
how to convert from base 10 to binary
write out the bits (128, 64, 32, 16...) and put 0s and 1s where necessary
72
New cards
converting hex to binary
for each character in hex, make a 4 digit binary equivalent and combine
73
New cards
converting from binary to hex
split the binary into sections of 4, add leading 0s, convert each section into the hex equivalent
74
New cards
what does the cpu do
process actual instructions, multiple cores like independent brains, often has 2 threads per core
75
New cards
what does ram stand for
random access memory (or primary memory)
76
New cards
what are i/o devices
input/output devices
77
New cards
what is an abstraction of RAM
a sequence of cells that each have an address and contain a byte of data
78
New cards
how many permutations of 0s and 1s can be stored in one cell
2^8 = 256
79
New cards
how many permutations of 0s and 1s can be represented by k bits
2^k
80
New cards
How many bytes are in a terabyte?
2^40 (1 trillion)
81
New cards
how are non-negative whole numbers stored
covert to binary, pad with leading 0s
82
New cards
how are negative whole numbers stored
two's complement (convert to binary, flop the digits, add 1) (more efficient)
83
New cards
any binary number that starts with 1 is...
negative
84
New cards
how are floating point numbers stored
as scientific notation (translate to binary, but into scientific notation)
85
New cards
how is 0 stored
as all 0s
86
New cards
what is the mantissa
the fractional part of a floating point number
87
New cards
how is text stored
old way: ascii (american standard code for information interchange), 1 byte per character
new way: unicode (more than 1 version), typically 2 bytes per character, each character is translated into code
88
New cards
how does java translate high level code to machine code
fast and portable: java program --> compiler ---> java bytecode program --> java interpreter for the operating systems (a combination of compiler and interpreter)
89
New cards
what is bytecode
close to assembly language, universal, used by java
90
New cards
what is a compiler
takes files and makes executable files that can be run on the CPU, runs faster, not portable, translates source code to machine code
91
New cards
what is an interpreter
takes source code, translates into machine code line-by-line while running, translation is completed live, takes CPU times, portable source code
92
New cards
what is an object
entities that interact with each other when the program is running
93
New cards
what is a class
a description/definition of an object (a blueprint)
94
New cards
what is a method
a chunk of code that has a name
95
New cards
what is the main method
where the program starts
96
New cards
what is a statement
an instruction, statements are sequential not "connected"
97
New cards
what are comments
not part of the program, in English to explain what's going on