Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there something like C's struct in Java?

Tags:

java

c

struct

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?

like image 667
lexer Avatar asked Mar 16 '26 21:03

lexer


2 Answers

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)

like image 170
Nivas Avatar answered Mar 19 '26 14:03

Nivas


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.

like image 31
stacker Avatar answered Mar 19 '26 13:03

stacker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!