What are Binary Operands
-Must have two operands
-Must have a left and a right operand
-Cannot divide numbers by 0
What is integer division
-When both numbers are integers, Java drops any decimal part
-eg: 1/2= 0.5, then drops .5 so =0
-If you want a decimal, at least one number must be a decimal (double)
What is a combined assignment operator
-Lets you do math operation and assignment at the same time instead of two steps
Example:
x=x+5; is the same as x +=5;
Example:
int x =10;
x+=5;
y was 20, divide by 4, y=5
Rank the Primitive Data types
Highest to lowest:
Double
float
long
int
short
byte
What are widening conversions
-When a value of a lower ranked data type is assigned to a variable of a higher ranked data type
example:
double x;
int y =10;
x=y;
What are narrowing conversions
When a value of a higher ranked data type is assigned to a variable of a lower ranked data type
example:
int x;
double y=2.5;
x=y;
doesn’t work
What are cast openers
-Cast opener tells Java to do the narrowing conversion anyways even if it loses data
-To do this you use parentheses with the type name before the value you want to convert
Example:
int x;
double y=2.5;
x=(int) y;
x=2; (the 0.5 is gone because it cuts off)
What are constants
-Allow the programmer to use a name rather than a value throughout the program
-Constants are identifiers that hold only a single value
-They are declared using the keyword final
-Constants are all uppercase and words are separated by the underscore character
What are the three types of comments
1.Single line comments: place // where you want comment to begin and the compiler ignores everything from that point to the end of the line
2.Multiline Comments: Start with /* end with */ and everything between these markers is ignored. Can span multiple lines
3.Documentation comments: Comments that start with /** and ends with */. documentation comments are used before a class header, giving a brief description of the method or each method header, giving a brief description of the method
What is Scope
-Scope means the part of a program where a variable exists and can be accessed
-In java, a variables scope begins where it is declared and it ends when the block ({}) it belongs to ends