Anyone using short and byte primitive types, in real apps?

后端 未结 15 3301
遥遥无期
遥遥无期 2021-02-20 08:09

I have been programming in Java since 2004, mostly enterprise and web applications. But I have never used short or byte, other than a toy program just to know

相关标签:
15条回答
  • 2021-02-20 08:09

    when we are programming for electronic devices like mobile phone we use byte and short.In this case we should take care on memory management.

    0 讨论(0)
  • 2021-02-20 08:09

    I found I was using byte variables when doing some low-level image processing. The .Net GDI+ draw routines were really slow so I hand-rolled my own.

    Most times, though, I stick with signed integers unless I am forced to use something larger, given the problem constraints. Any sort of physics modeling I do usually requires floats or doubles, even if I don't need the precision.

    0 讨论(0)
  • 2021-02-20 08:10

    Apache POI was using short quite a few times. Probably because of Excel's row/column number limitation.

    A few months ago they changed to int replacing

    createCell(short columnIndex)

    with

    createCell(int column).

    0 讨论(0)
  • 2021-02-20 08:11

    I used 'byte' a lot, in C/C++ code implementing functionality like image compression (i.e. running a compression algorithm over each byte of a black-and-white bitmap), and processing binary network messages (by interpreting the bytes in the message).

    However I have virtually never used 'float' or 'double'.

    0 讨论(0)
  • 2021-02-20 08:12

    On in-memory datagrids, it can be useful. The concept of a datagrid like Gemfire is to have a huge distributed map. When you don't have enough memory you can overflow to disk with LRU strategy, but the keys of all entries of your map remains in memory (at least with Gemfire).

    Thus it is very important to make your keys with a small footprint, particularly if you are handling very large datasets. For the entry value, when you can it's also better to use the appropriate type with a small memory footprint...

    0 讨论(0)
  • 2021-02-20 08:17

    The primary usage I've seen for them is while processing data with an unknown structure or even no real structure. Network programming is an example of the former (whoever is sending the data knows what it means but you might not), something like image compression of 256-color (or grayscale) images is an example of the latter.

    Off the top of my head grep comes to mind as another use, as does any sort of file copy. (Sure, the OS will do it--but sometimes that's not good enough.)

    0 讨论(0)
提交回复
热议问题