CMSC131 Midterm #1

0.0(0)
studied byStudied by 3 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/181

flashcard set

Earn XP

Last updated 2:08 PM on 3/1/23
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

182 Terms

1
New cards
Object
The principal entities that are manipulated by a Java program
2
New cards
Class
A blueprint or template for the structure of an object. The structure around which all Java programs are based. A typical program has many classes.
3
New cards
Method
Java's term for a procedure or subroutine. Every method belongs to some class, and a class may have many methods
4
New cards
Main Method
There must be exactly one method called main. This is where execution begins.
5
New cards
public static void main(String args[]){

6
New cards
//body

7
New cards
}

8
New cards
Statements
Individual instructions. There are many different types of statements. Each method consists of some number of statements.
9
New cards
Declarations
(Ex of statement) Declare (and initialize) variables
10
New cards
Assignment
(Ex of statement) Compute and assign a new value to a variable
11
New cards
Method invocation
(Ex of statement) Execute a method (which may return a result)
12
New cards
Control flow
The order in which statements are executed. General rule is top to bottom.
13
New cards
What is Java compiled into?
Java bytecode
14
New cards
What do you need to run Java bytecode?
A bytecode interpreter ("Java Virtual Machine")
15
New cards
Why is Java more portable than C or C++?
C/C++ programs are compiled into machine code (rather than Java bytecode) and executed directly by CPU.
16
New cards
A class consists of a combination of data units, called \___________, and computation units, called \___________.
variables,
17
New cards
methods

18
New cards
Methods
Where all the computation takes place. Each method has a name, a list of arguments enclosed in parentheses, and body, enclosed in curly braces.
19
New cards
Ex:

20
New cards
public static void main (String[]args){

21
New cards
//body

22
New cards
}

23
New cards
Variables
Data items that the methods operate on. Can be of various types.
24
New cards
List all primitive variable types
8 types: byte, short, int, long, float, double, boolean, and char
25
New cards
What do expressions/operators do?
Manipulate variables
26
New cards
Ex:

27
New cards
x \= (2*y-z)/32

28
New cards
Comments
Used to indicate programmer's intent. Do not affect program's execution. There are line comments ( using // ) and block comments ( using /star ... star/ )
29
New cards
Debugging
Process of finding and fixing problems
30
New cards
"Compile time" errors
Caught by compiler.
31
New cards
Ex:

32
New cards
Syntax errors

33
New cards
Variable type errors

34
New cards
"Run time" errors
appears during program execution
35
New cards
Ex:

36
New cards
division by zero

37
New cards
semantic errors

38
New cards
Different types of data require \_________ \__________ of memory.
different amounts. The compiler's job is to reserve sufficient memory
39
New cards
Operations can only be performed between variables with \_____________ types.
compatible
40
New cards
Valid Variables Names
-Starts with: a letter (a-z or A-Z), or dollar sign ($), or underscore ( _ )
41
New cards
-Followed by: zero or more letter, dollar signs, underscores, or integers

42
New cards
-Cannot be any of reserved names (class, float, int, if, etc.)

43
New cards
Camel case
A capitalization style
44
New cards
Ex:

45
New cards
dataList

46
New cards
myFavoriteMartian

47
New cards
Variables start with \_______ case. Classes start with \_______ case.
lower,
48
New cards
upper

49
New cards
JTM (Java Virtual Machine)
A interpreter that reads bytecode and simulates its execution
50
New cards
Numeric Constants (Literals)

51
New cards
-What are the integer types?
byte, short, int, long
52
New cards
Numeric Constants (Literals)

53
New cards
-What are the floating-point types?
double, float
54
New cards
Character Constants
-letters and digits: 'A', 'B', 'C', ....
55
New cards
-punctuation symbols: '*', '\#', '$',..

56
New cards
-escape sequences

57
New cards
Escape Sequences
Allows us to include single/double quotes and other special characters
58
New cards
\" double quote

59
New cards
\' single quote

60
New cards
\\ backlash

61
New cards
\n start new line

62
New cards
\t tab character

63
New cards
int x \= 7;

64
New cards
int y \= 2;

65
New cards
x \= x/y;

66
New cards
System.out.print(x);

67
New cards
//What prints?
3 because 7/2 \= 3.5, however, x and y are integers, therefore the answer must also be an integer. Round the answer down to the nearest integer.
68
New cards
int x \= 7;

69
New cards
int y \= 2;

70
New cards
x \= x%y;

71
New cards
System.out.print(x);

72
New cards
//What prints?
1 because modulo (%) finds the remainder
73
New cards
Comparison Operators
-Equality/Inequality: \== or !\=
74
New cards
-Less than/Greater than: < or \>

75
New cards
-Less than or equal/Greater than or equal:

76
New cards


77
New cards
These return a boolean value true or false

78
New cards
String Concatenation
The '+' operator concatenates (joins) two strings
79
New cards
What happens when a string is concatenated with another type?
The other type is first evaluated and converted into its string representation and then joined
80
New cards
How do you compare strings?
string1.equals(string2)
81
New cards
string1.length()

82
New cards
string1.compareTo(string2)

83
New cards
What do you import if you want to use Scanner?
import java.util.Scanner;
84
New cards
How do you create a scanner object?
Scanner sc \= new Scanner(System.in);
85
New cards
int x;

86
New cards
//How do you set x to the user's inputted integer?
x \= sc.nextInt();
87
New cards
String x;

88
New cards
//How do you set x to the user's inputted string?
x \= sc.next();
89
New cards
Conditional Statements
if,
90
New cards
if-else

91
New cards
Logical Operator "and"
&&
92
New cards
Logical Operator "or"
||
93
New cards
Logical Operator "not"
!
94
New cards
What is the difference between Global variables and Local variables?
Global: scope is entire program
95
New cards
Local: scope is the block in which they are declared in

96
New cards
What does adding the special term "final" before a variable declaration do to the variable?
It makes the variable constant. If the variable value is attempted to be changed anywhere in the code it will result in an error.
97
New cards
What are the three loop types in Java?
while
98
New cards
do-while

99
New cards
for

100
New cards
What is one run through a loop called?
An iteration