Home
Explore
Exams
Search for anything
Login
Get started
Home
Primitive Types
Primitive Types
0.0
(0)
Rate it
Studied by 1 person
Learn
Practice Test
Spaced Repetition
Match
Flashcards
Card Sorting
1/4
There's no tags or description
Looks like no tags are added yet.
Study Analytics
All
Learn
Practice Test
Matching
Spaced Repetition
Name
Mastery
Learn
Test
Matching
Spaced
No study sessions yet.
5 Terms
View all (5)
Star these 5
1
New cards
What is widening or automatic type conversion? (up casting) What is narrowing or explicit conversion? (down casting) During expressions?
This means you can convert from smaller data types to larger ones. It’s automatic because it can easily fit in the data type.
\
Ex. int y = 5;
double x = y; (X is bigger than y)
\
Downcasting means you convert larger data types to smaller ones. It’s explicit because you must be able to fit a larger one into a smaller one.
Ex. double x = 15432432;
int y = (int) x; (you must shrink x to fit into y)
\
Sometimes, an expression will result in a number larger than the data type can sustain. You will need to typecast it then
`Â Â Â Â Â Â Â Â // Declaring byte array`
`Â Â Â Â Â Â Â Â byte` `b = 50;`
Â
`Â Â Â Â Â Â Â Â // Type casting int to byte`
`Â Â Â Â Â Â Â Â b = (byte)(b * 2);`
\
2
New cards
What is type promotion and why is it important?
It’s when a data type is unable to perform an operation in it’s current so it must promote itself to a different type to perform it.
\
Java automatically promotes each byte, short, or char operand to int when evaluating an expression.
3
New cards
How do you convert from binary to hexadecimal?
Split up the binary number into sets of 4 and write it that way.
\
You can also convert each letter in hexadecimal to binary by converting each letter in hexadecimal to a set of 4 binary number and combining it.
4
New cards
What is a final
A variable that won’t change.
5
New cards