Each primitive data type has a fixed size. Literals are often interpreted and stored in primitive types.
- [Instructor] I really enjoy looking at examples…that can help understand and solidify the concepts.…Let's take a look at some primitive types examples…that show differences in different data types.…So what do you think this code would output?…It looks very simple.…The first line defines a variable,…and the second line prints its value.…The type of the variable is int,…and the value on the right-hand side…is a hard coded integer value.…What could go wrong?…Well, unfortunately the code doesn't compile.…
Let's look at the error.…It says the int value is too large.…Java compiler will attempt to interpret…the literal number as an int type,…since the literal value is hard coded,…the compiler can check its size requirements…versus what's available.…The int value that we inputted manually is simply too large.…An int in Java uses 32 bits…and this quantity is roughly two to the 47th power,…which requires at least 47 bits to store.…
Let's try to fix the problem.…We're intentionally making the data type bigger.…In fact, a long integer type uses twice as many bits…
Released
2/8/2019- Data types
- Allowable operations
- Literals and primitives
- Prefixes and suffixes
- Reference types
- Identifier rules
- Conversions
- Casting
Share this video
Embed this video
Video: Examples of primitives