byte
Java's smallest integer primitive type: 8 bits, holding values from -128 to 127.
In more detail
Arithmetic on byte values promotes them to int first, so b = b + 1 does not compile without a cast. Compound assignment such as b += 1 includes an implicit cast back to byte. Overflow wraps around silently.
Example
byte b = 10;
b += 5; // compiles
// b = b + 5; // does not compileRelated terms
- int — The common integer type in many languages, holding whole numbers within a fixed range set by its size in bits.
- primitive type — A basic built-in type, such as a whole number or true-or-false, whose values are held directly rather than as objects.
Taught in
- Fifty Items, Five Traps — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- A Hundred And Twenty Minutes, Fifty Items — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Promotion, Wrappers And The Math API — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Switch, Loops And Labels — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Overloading And Varargs — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Console And File I/O With Streams — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Final Review And Exam Day — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep