I am a software developer with about three year experience (mostly JVM languages) and currently reading Code Complete 2.<p>Because of that I wondered why I never had a chance to use short or byte - or at least I never saw one.
Of course I have learned about those, but during my professional time (circa 3.5 years and 4 projects) as a developer I believe to never have stumbled upon any usage.<p>I am just wondering whether they are or are not obsolete by now, because the performance gain seems to be not too extraordinary.
I am not a Java developer by trade, but I do a lot of C# stuff and the languages are somewhat similar.<p>So with that in mind I imagine a byte type being useful for reading / writing binary formats [0] (e.g. for sending small amounts of data over a network). A byte or short type can also be useful for using bitfields [1]. In some use cases you might want to use a small type to store the flags (e.g. if you don't need 32 flags, it seems a waste to use a Int32 type).<p>---<p>[0]: <a href="https://www.codejava.net/java-se/file-io/how-to-read-and-write-binary-files-in-java" rel="nofollow">https://www.codejava.net/java-se/file-io/how-to-read-and-wri...</a><p>[1]: <a href="https://en.wikipedia.org/wiki/Bit_field" rel="nofollow">https://en.wikipedia.org/wiki/Bit_field</a>
I use byte in the context of Input/OutputStreams, which operate on bytes. Ideally this will be wrapped in something that determines the encoding -- preferably one maintained by somebody other than me -- but I'm aware that serialization to disk or network ends up being a stream of bytes.<p>I've occasionally used short in similar contexts. I wrote a JVM library, and the JVM specification uses a bunch of short values -- though ironically, a lot of them are really unsigned values, so a short is inappropriate.<p>But for the most part, use of short or byte to save memory is very rare for me. I write Java knowing that it's pretty flagrant with machine cycles and memory, and also knowing that computers have lots of memory and users care more about the difference between 10 vs 20 days to write a feature than about the difference between 10 vs 20 msec to reply to a click. I write Java because it lets me work faster, rather than for economy.
Primitive types in general are planned for deprecation in future releases of Java. The 8-bit / 16-bit data structures have been obsolete for quite some time. If you haven't used them in your career yet as a software developer it's a good sign of progress that our industry is evolving beyond legacy technologies onto more enlightened thinking.