Midterm 1 Flashcards

(22 cards)

1
Q

Algorithm

A

a set of unambiguous and ordered steps to accomplish a task

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

3 control structures

A

Sequence (i.e. one line after the other)
Decision making (e.g. using if/else constructs)
Looping (e.g. using while loops)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Algorithm development should be independent of…

A

the final computer language used to implement the algorithm as an executable program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Java

A
  • an object-oriented programming language
  • portable between machines
    • > compiled into Java bytecode. This is a machine code for a “virtual computer” called the Java Virtual Machine (JVM).
    • > JVM interpreter reads bytecode and simulates its execution.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Object

A

The principal entities that are manipulated by a Java program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Class

A
  • A blueprint or template for the structure of an object.
  • The structure around which all Java programs are based.
  • combination of data units (variables) and computation units (methods)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Method

A
  • Java’s term for a procedure or subroutine. Every method belongs to some class, and a class may have any methods.
  • Each method has a name, a list of arguments enclosed in parentheses, and body, enclosed in curly braces.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Main Method

A

There must be exactly one method called main. This is where execution begins

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Statements (4 examples)

A

Individual instructions. Examples:

- Declarations -> declare (and initialize) variables
- Assignment -> compute and assign a new value to a variable    - Method invocation -> execute a method (which may return a result)    - Control flow -> alter the order in which statements are executed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Variables

A

Data items that the methods operate on. Variables can be of various types, integers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Expressions/ Operators

A

Java provides various operators, which allow you to manipulate the variables
x = (2 * y - z) / 32;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Types of errors

A

Compile time and Run time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Compile time error

A
  • caught by Eclipse / Java compiler
  • Syntax errors
  • Disobeys the rules of the language; violates language’s grammar
  • Type errors: misuse of variables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Run time error

A
  • appear during program execution
  • Obeys the rules of the language but does not express them meaning you intended;
  • Division by 0
  • Crash or hang or wrong outputs (b/c of mistakes in programming)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is variable? (4)

A
  • name of some location of memory used to hold a data value.
  • Different types of data require different amounts of memory. Compiler’s job is to reserve sufficient memory
  • Variables need to be declared once
  • Variables are assigned values, and these values may be changed later
  • Each variable has a type, and operations can only be performed between compatible types.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Variable Name (rule

A
  1. Starts with: a letter (a-z or A-Z), dollar sign ($), or underscore (_)
  2. Followed by: zero or more letters, dollar signs, underscores, or digits (0-9)
  3. Uppercase and lowercase are different (total =/= Total =/= TOTAL)
  4. Cannot be any of the reserved names (class, float, int, if, then, else, do, public, private, void,…)
17
Q

Primitive Data Types

A

Integer Types: byte, short, int, long
Floating-Point Types (real numbers): float, double
Other types: boolean, char

18
Q

Escape sequences

A

Allows us to include single/double quotes and other special characters:
" double quote
' single quote
\ backslash
\n new-line character (starts a new line)
\t tab character

19
Q

String Comparison

A

Strings should not be compared using operators (==, <=, returns true if s equals t
s.length() -> returns length
s.compareTo(t) -> compares strings lexicographically
result < 0 if s is less than t
result == 0 if s is equal to t
result > 0 if s is greater than t

20
Q

Scanner Class operations

A
nextBoolean()
nextByte()
nextDouble()
nextFloat()
nextInt()
nextLong()
nextShort()
next() - returns sequence of characters up to next whitespace (space, carriage return, tab, etc.)
nextLine() - returns sequence of characters up to next carriage return
21
Q

Control flow

A

The order in which statements are executed
General rule -> top to bottom
Several control structures that change that

22
Q

Conditional statements

A

permit control flow to be dependent on (true/false) conditions

  • if
  • if-else