The short answer is "never".
The longer answer is almost never.
Primitives that can hold int values but are smaller than int
are invented to save memory. This reason is irrelevant for most applications. Memory usage optimization (almost) passed away since computers became very strong and memory very cheap.
Sometimes it is convenient to use byte
type. However due to java does not have unsigned
modifier (like C) byte can be confusing: you values greater than 127 become negative. Even method read()
declared in InputStream returns int
instead of byte
.
Sometimes however memory usage optimization becomes relevant again. For example in case of "big data" near real time applications that have to operate with huge in-memory caches and store on disk terabytes of data.