struct is necessary when you try to parse some file format like ELF, etc...
Is there something like C's struct in Java?
Or can Java be used to parse ELF/binary format directly in the first place?
If you need a struct for grouping different data of the same type, Java has a class, and a class is better in logically grouping data than a struct because it includes operations on the data as well.
If you want to format ELF, then you may have to look at the "The ELF Parser" section in http://www.icsa.inf.ed.ac.uk/research/groups/hase/manuals/design/javahase.html. See also LibElf and GElf - A Library to Manipulate ELf Files (an old article)
Unfortunatly there is no decent support to read binary structured data in java.
This example reads image header into a byte array and assembles the required information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With