Chapter 2 - In person Class Flashcards
What’s the object in System.out.println (“Whatever”)?
What’s the method?
What’s the parameter?
system.out
println is the method.
What’s the difference between Primitive data (for python and java).
Python figures it out for you, in java you have to be specific.
How many types of primitive data are there? (can they be negative)
There are four integers. Two of them float, double. One of them are char, and the other boolean (yes).
Why do computers approximate? How can that be a problem.
Because computers are limited. This can cause an issue when you are calculating total cost that need decimals.
What happens when you add 1 to an integer type of 2147483647?
It rolls over and gives you -2147483648. So you went from billionaire to owing 2 billion. This is why it’s so important to know the type of data the integer is saved in. Compare that the cost of using more bits with type long.
What is the difference between using ‘ and “ in Java? What language did Java come from?
You use single quotation mark for characters, where the uppercase and lowercase are different. Strings in Java use double quotation marks.
Java came from C.
When creating a variable in java do you have to specify the data type (different than python)?
Yes.
What’s a literal? Give an example of a string literal.
It’s simply a value. “Hello” is a string literal.
Is an expression a program statement?
No, they cannot exist by themselves. They are part of statements that end with a semi-colon ( ; ).
“Hello” + “World” is an expression but not a statement. String s = “Hello” + “World”; is a statement.
What is the %, a modulus (mod) operator? Why is it important?
It calculates the remainder. It’s important when we’re counting lists and telling the program to go back to the beginning after Remainder hits 0.
What part of this is the expression?
result = total + count / max - offset;
Everything to the right of result is the expression of the statement.
How do you create a constant in Java? What is the style used for a CONSTANT?
add a final in front of it. final int var1 = 1;
The style is to capitalize it.
What do you need to know about data conversion? For example in one we may want to treat an integer as a floating point. (Java is a strongly typed language).
The data conversions do not change the type of variable. They do not affect the original variable or the original data value. You must be careful not to lose data value when going from wider to narrower type.
What are the decrement operators ++ or –? Where will you see this all the time? It’s very common to use i for the outer loop, j for the next inner, and k for the next… and so forth.
count = 4. count++; is not the same thing as count = count +1; Count ++; is faster and adds only 1.
count++ is not the same as ++count.
total = count ++; Total becomes 4 first and then count++ becomes 5 after.
total = ++count; both Total and Count become 5.
We see ++ in loops all the time. for (int i = 0; i< 10 , i++)
What are some assignment operators like +=? i.e. num += count;
Why is it important to learn this?
num += count; is equivalent to num = num + count.
This is because most of your job will not to start from scracth; but most likely fix other’s “crappy” coding.