TEST 1 Flashcards
What are the parts of software development?
Requirements, Design, Implementation, Testing and Debugging, Maintenance
What two things shape what design needs to meet
functional requirements and software quality metrics
What are design choices
ALGORITHM- what sequence operations is preformed DATA STRUCTURE- how information is represented COMPONENT DESIGN - how software is designed
Application Software
Software designed to solve specific tasks for users, typically written in a high level language
system software
software that interfaces between the application software and hardware (or lower layers of system software) ie runtime, operating, virtualization
hardware
physical resources such as memory (RAM), processing power (CPU), storage (disk), and I/O devices
What are the key components of programming languages
grammar, semantics, libraries
interpreter
a program that executes programs written in a language
complier
program that translates program language into another language (typically a binary)
what are the primary programming paradigms
Imperative, object- oriented, functional, declarative
imperative
series of statements that mutate programs state, these statements detail how to preform each operation – outputs can depend on combo of inputs and external states, side effects are allowed
functional
immutability, all functions are pure (no side effects, output soley depends on inputs)
cons of imperative
Behavior can be harder to understand
● Debugging can be more challenging
● Order is more crucial
Pros of imperative:
Efficient
● Familiar
● Parallels how computers actually work
Pros of functional
Proofs and analysis are easier
● Can be easier to test and debug
● Order of execution is less important
(easier to parallelize)
Cons of functional
Can sometimes be less efficient
Can’t use familiar constructs such as
loops
declarative
express logic of what without detailing its control flow how
Pros of more declarative:
Abstracts away the low-level details
● Equivalent code is typically shorter
● Self-documenting (goal is explicit)
Cons of more declarative:
Can sometimes be less efficient
● Gives the programmer less control
Is OOP imperative or functional, in terms of mutation
Can be either! Imperative is more common
Is OOP imperative or declarative, in terms of abstraction
Some argue declarative: once objects are defined, you can use
them abstractly without knowing how they work under the hood
I disagree; someone still has to define how they operate before
using them!
pros of OOP
High level of abstraction & encapsulation
● High level of modularity
● High level of extensibility & reusability
Static type system
type-checking happens at compile-time
○ Variables have types; type system checks that assigned values
match declared variable types
Dynamic type system
type-checking happens at runtime
○ Values have types; variable types are inferred from their values
Pros of static
Guarantees that type errors will not occur at runtime;
effectively free,
automatic testing by the compiler
Cons of static
Code is a bit bulkier
can feel slow and onerous to write code that will pass static type checks
Cons of dynamic
May encounter runtime type errors (potentially after code has been running for a long time)
Pros of dynamic
● Code is sleeker
● Writing code is faster
strong typed
Variables have a
shallow fixed type
Variables have a
deep fixed type
weak typed
No notion of types
(e.g. assembly code,
machine code)
Values have
a fixed type
stronger typing leads to greater type safety(the extent to which type errors are disallowed)
type safe
can be used to describe languages or programs
If a language is type safe, programs written in it are type safe
examples of type safe languages
Java is a type-safe language
while JavaScript and C++ is not a type-safe language
evolution of programming languages
machine-independent, higher-level abstractions (functions), support for OOP, programming languages created , built in libraries
Java Compilation & Execution
source code, complier, bytecode, class loader, execution engine, result
type system of java
strong and statically typed- means you must declare things explicitly ot implicitly
primitive types
numeric types, boolean, char
strings
object type but behavior like primitive- cant be mutated and can be created without constructor- surrounded by double quotes
literal
a symbolic representation of a value ie x = 5 assignment of literal 5 to variable x
variable
a name associated with memory location ie int x a declaration that variable x is of type int
Declaration
a statement associating a variable with a type
Assignment or definition
a statement that places a value in
the memory location associated with a variable
Rules of Assignment
The defined value of a variable must match the declared type
The defined value of a variable must match the declared type
Primitive Type numeric definitions
long literals can optionally
include a trailing “L” float literals must include
a trailing “F”; without it java assumes its a double
double literals can optionally
include a trailing “D”
Primitive Type boolean definitions
boolean literals must be lowercase
Primitive type char definitions
char literals must be designated with
single quotes; String literals must be
designated with double quotes
initial values
For numeric types: 0 (or 0.0, or 0.0F)
For booleans: false
For chars: the null character (‘\u0000’)
For Strings, arrays, and objects: null
final keyword
final keyword tells the compiler that a variable will never
be re-defined ie final int x = 5
operator
a symbol that is built into a programming
language and has a specific, well-defined behavior, takes arguments (amount of arguments it takes it fixed)
Arithmetic operators:
take numeric expressions yield 1 numeric values
addition (can preform a cantaonation between string and int) plus operaters automatically takes care of any conversions
subtraction
multiplication
divison (overloaded 3/2 = 1 but 3/2.0 = 1.5)
modulus
logical
yeild a boolean value
relational operators
used for comparison used for any types
ternary
<boolean> ? <expr> : <expr> --> if <boolean> is true, yield <expr>;
otherwise, yield <expr>
String a = (b > c) ? “b is greater” : “c is greater or eq”
</expr></expr></boolean></expr></expr></boolean>
augmented assignment operations
with exceptions of += a and b need to be numeric a = b
a += b a = a + b
a -= b a = a - b
a *= b a = a * b
a /= b a = a / b
a %= b a = a % b
Control flow
the sequence of statements executed in a program
“straight-line”
sequences of statements excuted one after the next
“branches” to the control flow
conditionals and loops, multiple paths, ○ Which path is taken depends on the current program state
Blocks
group together a series of statements to be executed
In Java, blocks are generally denoted using curly braces { }
Scope
the set of blocks in which a variable is valid/usable– , a variable’s scope is the block in which it was declared
+ any blocks nested inside that block
two rules of scope
Can’t reference a variable outside of its scope
Can’t re-declare a variable within its scope
Conditionals
Control flow depends on the value of a boolean expression
if (<boolean>) {
// do something
...
} else if (<boolean>) {
// do something else
...
} else {
// do something different entirely
}
Exactly one if block per conditional,
followed by zero or more else if blocks
only first if block whos condition is true gets executed even if others are true
At most one else block per conditional - only executed if everything else was false</boolean></boolean>
Switch Statements
Control flow depends on the value of a single variable
switch (<variable>) {
case <value>:
// do thing 1
break;
case <value>:
// do thing 2
break;
default:
// do thing 3
}</value></value></variable>
these values must be constant, cannot be arrtibuary involving variables
default case
executes everything from the match case to the default statement if there is no break statement or if it does not meet any of the cases
pure function in java
“procedure” or “subroutine” = a
sequence of statements packaged together into a callable unit
parameters
variables that are defined in the function
header and can be referenced within the function
function header
public void addTwoInts(int num1, int num2) structure is privacy, return type (void if nothing is returned), name of function in camel case, the parameter list a list of <type> <name> pairs</name></type>
arguments
the specific values that get “bound” (assigned)
to the parameters (variables) when the function is called
local variables
Their scope is the function in which they’re declared
If you want your compiled program to be a standalone executable, you
must define a function with this exact header to serve as the “entry point
public class Main {
public static void main (String[] args) {
System.out.println(“hello world!”);
}
}
What are array limitation?
An array is declared with a type; all elements must be of that type
An array is defined with a size and cannot exceed that size
Why cant array sizes change?
ordered sequence of fixed-size storage locations
○ Each slot typically fits one byte (8 bits)
○ At runtime, all of the data that your program creates is stored in memory
If we fix an array’s size, we can place it in a contiguous chunk of memory,
making it easy to find the ith element
how to declare an array in java?
int[] myArray; int myArray[];
primitive types
values associated with variables stored directly in the chunk of memory associated with variable name (no arrows or pointers)