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.