1/105
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
What are Identifiers?
Names you chose for variables, methods, and classes
What rules must identifiers follow?
-Start with a letter
-Can include digits, letters, or $
-Can't be reserved words
Examples of identifiers
name, count, totalAmount, isHeads
What are reserved words?
Built in java words used for its language structure.
Examples of reserved words
class, public, static, int, if, return, new
What is a compile time error?
A error that prevents the program from running successfully.
What is a runtime error?
An error that occurs while the code is running, so the code crashes.
What is a logical error code?
Code works, answer is wrong.
What does println do?
Prints info and moves cursor to next line.
What does print do?
Prints info and keeps cursor on that line
What are parameters?
variables listed in a methods definition that receive information when the method is called
Example:
public static void greet(String name) {
System.out.println("Hello " + name); }
String name = parameter
How many arguments can print and println take?
One argument per method call
What does braces look like?
{ }
What do brackets look like?
[ ]
What do parenthesis look like?
( )
How to get newline?
\n
How to get double quote?
\"
How to get backslash?
\
How to tab?
\t
What are the primitive data types?
int (integers)
double (decimals)
boolean (true or false)
What is a variable?
A named storage location that holds one value at a time. Its value can be changed unless it is declared final.
the double variable is for…
decimals
the int variable is for…
integers
the boolean variable is for…
true or false
In double height; what is a double?
The data type
In double height; what is the height?
variable name (identifier)
What is int sides = 10
A declaration and initialization. It declares sides as an int and gives it its initial value of 10.
What is sides = 10?
An assignment statement. It assigns/stores the value 10 in the variable sides.
How many values can a variable store one it is declared?
1
int legs = 4
How to print "My dog has 4 legs"
System.out.println("My dog has " + legs + " legs");
What is a constant?
A variable whos value cannot be changed after it is initialized. It is declared using the final.
Example
final int LEGS = 4;
Example of how to make a constant?
final int legs = 4
Multiplication symbol
*
Division symbol
/
Modular division symbol
%
What happens when you perform arithmetic using two int values?
The result is an int. For division, the decimal portion is discarded.
10/4 =
2
2*4 =
8
1/4 =
0
What happens when an arithmetic operation includes a double?
The result is a double.
2*4.0 =
8.0
10/4.0 =
2.5
What does System.out.println(1/3*90); print.
0
What does the Modulus operator % do?
It gives the remainder after division.
40 % 11 =
7
17 % 2
1
4 % 5
4
What is widening?
Converting a value from a smaller numeric type to a larger numeric type, such as int > double.
What is narrowing?
Converting a value from a larger numeric type to a smaller numeric type, such as double > int.
What is the one way to convert and int to a double?
Assign the int to a double variable.
int num1 = 1
double num2 = num1
Can you automatically assign a double to an int?
No
How can arithmetic with an int produce a double.
Include a double in the arithmetic operation
int num = 5
System.out.println(num/4.0); yields 1.25
What is casting?
Explicitly converting a value to another data type by putting the desired type in parentheses before the value/expression.
Does casting a double to an int round the number?
No, it removes/discards the decimal portion.
What is the result of this code
double a + 4.4, b = 7.5;
int c = (int)(a + b);
C = 11
How to assign "11d" to an int?
11*d
What is an argument?
The actual value or expression passed to a method when it is called. Arguments go inside the parentheses.
System.out.println("Hello");
Hello is the argument
What is double height?
A variable declaration. It tells Java to create a variable named height that can store a double.
What does System.out.println(1/3*90.0); print?
0.0
What does = mean in Java?
Assignment. It stores the value on the right on the right in the variable on the left.
What does == mean in java?
Equality comparison. It checks whether two values are equal and produces a Boolean.
What is a string?
A sequence of characters/text enclosed in double quotation marks.
Example: "Hello"
What does + do when used with strings?
It concatenates, or joins, Strings and other values together
Example "Age: " + age
What is initialization?
Giving a variable its first value when it is declared?
Int age = 16;
What is an escape sequence?
A combination with \ that represents a special character or action inside a String,
Examples: \n \t \
How can % be used to determine whether an integer is even?
Check whether number % 2 is even.
How can % be used to determine whether an integer is odd?
Check whether number % 2 is odd.