converting to byte[] and String.getBytes
<p>As part of an exercise I had to write a remote class loader. It downloads a class from a server and then loads it using defineClass.</p>

<p>What I did was something like this:</p>

<pre><code>in=new ObjectInputStream(s.getInputStream());
Object o = in.readObject();
return defineClass(className,o.toString().getBytes(), 0, o.toString().length());
</code></pre>

<p>And I got a <code>java.lang.ClassFormatError: Incompatible magic value</code></p>

<p>But when I wrote this</p>

<pre><code>in=new ObjectInputStream(s.getInputStream());
byte[] classData=(byte[])in.readObject();
return defineClass(className,classData, 0, classData.length);
</code></pre>

<p>It worked as expected.</p>

<p>Why is that?</p>
