Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8763037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:41:18+00:00 2026-06-13T15:41:18+00:00

As part of an exercise I had to write a remote class loader. It

  • 0

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.

What I did was something like this:

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

And I got a java.lang.ClassFormatError: Incompatible magic value

But when I wrote this

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

It worked as expected.

Why is that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:41:19+00:00Added an answer on June 13, 2026 at 3:41 pm

    Object.toString() string returns you human readable form of Object So if you call toString on array object then it will return you default toString.

    Default toString implementation is

    public String toString() {
    return getClass().getName() + "@" + Integer.toHexString(hashCode());
    }
    

    You can clearly see this is not what you wanted.

    You can use String constructor with Charset or default charset to convert byte[]to string

    byte[] utf8Bytes = original.getBytes("UTF8");
    String roundTrip = new String(utf8Bytes, "UTF8");
    

    References:

    • Byte Encodings and Strings
    • String JavaDoc
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I did part of this code for a class exercise and the code is
Exercise: Write a program that converts 27° from degrees Fahrenheit (F) to degrees Celsius
I do an exercise to write an image gallery w/o using any libraries or
As part of an exercise, am implementing an ArrayList which will support Enumerations. Following
I've completed Chapter 5 and all the exercises. As part of the final exercise,
Part of the GUI I'm building using tkinter has a pop-up window that says
Part of my web application is a background script that polls from a beanstalkd
As part of a programming exercise I received the following: Simulator will receive orders
I am very new to Erlang and as part of my learning exercise, I
I have the following simple code from an exercise in Modern Javascript used to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.