Chapter 12 - Type Details Flashcards
What are the two basic categories of values in Java?
Primitive values and objects
How are primitivie values categorized?
- Byte, short, int, long
- float, double
- char
- boolean
What are the primitive value integer types?
byte, short, int, long
How do you access a data type’s minimum and maximum values?
Use the MIN_VALUE and MAX_VALUE named constants.
Example: To print the maximum int value type:
System.out.println(“Largest int = “ + Integer.MAX_VALUE);
What is the default integer constant type?
int
What does using a 1 or L suffix do?
Explicility forces an integer constant to be long.
Example:
long ageOfPlanet = 4_540_000_000; (causes a compilation error)
long ageOfPlanet = 4_540_000_000L; (will compile, notice the L at the end)
What are the floating-point types?
float, double
Why is the double type preferred over the float type?
Because it provides more accuracy.
Meaning that for the doubles type the number of significant digits is 15, while only 6 for the float type.
What commands access a floating-point data type’s minimum and maximum values?
MIN_NORMAL and MAX_VALUE
How does the floating point MIN_NORMAL differ from the integer MIN_VALUE?
Instead of being the largest-magnitude negative value, it’s the smallest-magnitude positive value.
For floating-point numbers, how do you access the largest-magnitude negative value?
By using the negation operator (-) with the MAX_VALUE named constant.
Example:
To print the largest-magnitude negative float value type:
System.out.println(
“Largest-magnitude negative float = “ + -Float.MAX_VALUE);
What is the default floating-point constant type?
double
What are you required to do if you declare a variable a float?
Append an f or F suffix to all floating-point constants that go into it.
Examples:
float gpa1 = 3.22f;
float gpa2 = 2.75F;
float gpa3 = 4.0; (this will cause a compilation error)
What data types are normally used for numbers with large magnitude?
long and double
What data types should be used if you require greater magnitude or higher precision than long or double offer?
BigInteger and BigDecimal where magntiude and precision are only limited by the computer’s memory
How do you create BigInteger and BigDecimal objects?
Call their constructors with string arguments
Example:
BigInteger num = new BigInteger(“12345678”);
BigDecimal x = new BigDecimal (“12.34567890123456e400”);
When using the BigInteger and BigDecimal classes what must you import?
The java.util package
API Headings and example for the more common BigInteger methods:
What method does the BigDecimal class not implement?
The mod method
What is the encryption and decryption of a message called?
Cryptography
What is the purpose of Cryptography?
To ensure that only the intended recipient(s) can read the message, while others cannot.
What is a popular cryptography algoritm that relies on the difficulty of factoring large integers?
The RSA algorithm
What do character values have in most programming languages?
An underlying numeric value
For example the letter “A” has the underlying value of 65
What specifies the underlying numeric values of characters?
The ASCII table
What is having underlying numeric values important?
So characters can be ordered. Ordering is necessary so that characters and strings can be sorted.
Example: ‘A’ comes before ‘B’ because A’s 65 is less than B’s 66
ASCII Table
How can you concatenate a char value to a string?
Using the + operator.
Example:
char first = ‘J’;
char last = ‘D’;
System.out.println(“Hello, “ + first + last + ‘!’);
What happens with the JVM sees a string next ot a + sign?
It converts the operand on the other side of the + sign to a string.
What happens if you apply the + operator to two chars?
It doesn’t perform concatenation, it instead does mathmatical addition using the characters’ underlying ASCII values.
Example:
char first = ‘J’;
char last = ‘D’;
System.out.println(first + last + “, What’s up?’);
Outputs 142, What’s up?
You must have a string on each side of the chars
What is a problem with the ASCII character set?
It specifies only 128 characters and there are way more than 128 character in the world. (Think foreign alphabets)