Java Module 2
What is Unicode?
A code to represent all characters found in the human language
What is a String Literal in Java?
A set of characters enclosed by double quotes. For example, "this is a test"
What is scope?
What variable or variables are accessible to parts of a program
How many bits is a byte of data?
8 bits
What is the decimal value of Z? (according to the ASCII table)
90
What is the decimal value of a? (according to the ASCII table)
97
What Java character is used for an assignment?
=
What Java character is used to check if two items have the same value? (if two items match)
== (double equal)
Fill in the following truth table. Use 1 for true, 0 for false. (if table looks weird on here look at the actual review)
A B A&B A|B A^B !(A&B) !(A|B) !(A&B) | !(A|B) 0 0 0 0 0 1 1 1 0 1 0 1 1 1 0 1 1 0 0 1 1 1 0 1 1 1 1 1 0 0 0 0
Write a piece of Java code to see if a variable x is between 4 and 25
if(i > 4 && i < 25)
What does (int)(25/3) result in?
(int)(25/3) = 8
How can you find the numerical value of the character e if it is held in the variable data?
(int)data;
What are the arithmetic operators in Java?
(see pg. 60) + - * / ++ (increment) -- (decrement) % (modulus operator)
What is the decimal equivalent of 00010110?
1 * 2^4 + 1 * 2^2 + 1 * 2^1 = 16 + 4 + 2 = 22
What is the equivalent of 00101011?
1 * 2^5 + 1 * 2^3 + 1 * 2^1 + 1 * 2^0 = 32 +8 +2 +1 = 43
How would you represent the number 5 in binary?
101
How would you represent the number 3 in binary?
11
What is the decimal value of z? (according to the ASCII table)
122
If you are doing integer math, what is the value of 5 / 2?
2
What is the decimal value of A? (according to the ASCII table)
65
What is a short hand assignment?
A way to speed up the typing of a program
If x = 19 and y = 2, decide if the following are true, false, or invalid Java statements: a) if(x <= y) b) if(x*2 != y) c) if(x-1 == y*9) d) if(x => y) e) if( y < x < 25)
ANSWERS a) False b) True c) True d) Not a valid statement. Should be >= e) Not a valid statement. Should be if(y < x && x < 25)
What is ASCII?
ASCII is a subset of Unicode that handles the characters that are used in the English language
What are the four integer types and what size of numbers can each hold?
Byte: 127 to 128 Short: 32 thousand Int.: 2 billion Long: 9,223,372,036,854,755,807
How can you create an object called fourDecimal to format a number to four decimal places?
DecimalFormat fourDecimal = new DecimalFormat("0.0000");
What is casting?
Forcing an answer to be a certain type of variable
What is 10%3?
Gives a remainder of 1 (3 goes into 10 3 times with a remainder of 1)
What does short circuit logical operator mean?
It means the program stops checking an expression once an answer can be determined
Which integer type holds the biggest integers?
Long
How can you get the value of pi in java?
Math.PI
How can you get the sine of a number in java?
Math.sin(0.4) do not forget with trigonometric functions the value has to be in radians
How can you get the square root function in java?
Math.sqrt(7)
How can you find the square root of a number in Java?
Math.sqrt(x);
Suppose I define a variable called x within a block of code. Can the main program print out the value for x?
No. (see pg. 56) Scope determines what objects or variables are visible to other parts of your program.
If you are finding the cosine of an angle in java, does the angle have to be in radians or degrees?
Radians
If you are using an expression like y = Math.sin(x); what are the units for x?
Radians
Write a Java statement to define a string variable ans and set it equal to the value of Brown
String ans = 'Brown';
Use the object called fourDecimal in a print statement to format a variable called x
System,.out.println("The answer is " + fourDecimal.format(x));
How can you ring the bell on the computer?
System.out.println((char)7);
What values does the Boolean type of data represent in Java?
True or false
Suppose you have the x values in degrees and y in radians. How can you change the radians and y to degrees?
ans = Math.toRadians(x); ans = Math.toDegrees(y);
Which data type does Java use to define characters?
char
What are the two types of floating point or decimal types?
float and double
What size numbers can float and double hold?
float holds 7 digits double holds 16 digits.
Write a loop in short hand notation to print the numbers from 1 to 100
for(i > 1; i < 100; i++)
Write a Java statement to see if the variable ans matches Black
if(ans.equals("Black"));
Write a Java statement to define a character variable called data that matches the letter A
if(data == 'A') System.out.println("...");
What are Java's eight simple types of data?
pg. 43 Boolean (true or false), [byte, short, int, long] (different types of integers), char (characters), double or float (decimal or floating numbers)
What are data types and why are they important?
pg. 43 Boolean, char, double, int. This prevents errors and enhances reliability. String is not considered one of the basic data types because it's a whole set of characters enclosed by double quotes.
What is a Literal?
pg. 51 a fixed value. For example, 100, 0.5, etc. It's a constant
What number system uses base 16?
pg. 52 hexadecimal
What are the relational and logical operators in Java?
pg. 63 Relational: ==, !=, >, <, >=, <= Logical: &, |, &&, ||, ^, !
Order the follow operators in terms of precedence: ++. (), &&
see pg. 74 () ++ &&
If x = 3, what does x *= 10 do to the value of x?
x = 30
How do you use increment and decrement? pg. 62
x = x + 1 is the same as x++
If x = 20, what is y = x-- ?
y = 20, x is 19 after the fact. y = x++ y is still 20, x still goes up to 21
If x = 20, what is y = x++ ?
y = 21
If y = 5, what does y-= do to the value of y?
y = 5 - 2 = 3