So I’m learning java, and I have a question. It seems that the types int, boolean and string will be good for just about everything I’ll ever need in terms of variables, except perhaps float could be used when decimal numbers are needed in a number.
My question is, are the other types such as long, double, byte, char etc ever used in normal, everyday programming? What are some practical things these could be used for? What do they exist for?
With the possible exception of ‘short’, which arguably is a bit of a waste of space– sometimes literally, they’re all horses for courses:
[*] For example, in Hotspot on Pentium architectures, float and double operations generally take exactly the same time, except for division.
Don’t get too bogged down in the memory usage of these types unless you really understand it. For example:
Obviously, there are certain API calls (e.g. various calls for non-CPU intensive tasks that for some reason take floats) where you just have to pass it the type that it asks for…!
Note that String isn’t a primitive type, so it doesn’t really belong in this list.