I have a question regarding byte code and serialization.
bytecode - every java class is converted to bytecode for compilation and stored on the memory (disk) as stream of bytes / bytecode.
Serialization - Serialization is the process of saving an object's state to a sequence of bytes.
can't this bytecode itself be used to send through network ?
So what is the exact difference between the two ??
Thanks in advance.
The concepts are completely unrelated.
every java class is converted to bytecode for compilation
No, it isn't converted for compilation. Bytecode is the result of compilation. It is, well, code which is run by a virtual machine (JVM in Java's case) like machine code is run directly by the CPU. It is binary (a sequence of bytes instead of characters) simply because it's a more compact representation. It doesn't contain state of any objects (except for constants).
Serialization stores the state of an object (default Java serialization is binary, but other libraries/languages can use text). The serialized object doesn't contain bytecode: you can't run it or in JVM.
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