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

  • SEARCH
  • Home
  • 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 8496433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:51:15+00:00 2026-06-10T23:51:15+00:00

I’m trying to understand how the Java class loader works, specifically the defineClass(String,byte[],int,int) method.

  • 0

I’m trying to understand how the Java class loader works, specifically the defineClass(String,byte[],int,int) method. Let’s say I want to load the class definition for NonIntrinsicType. I know I can find the *.class file for NonIntrinsicType, serialize its contents into a byte[] called bytes, and then call defineClass(null,bytes,0,bytes.length).

The weird situation I’m having trouble understanding is, how can I get a byte[] for the class definition of something like [LNonIntrinsicType – in other words, if my application requests the class definition for an instance of NonIntrinsicType[], I don’t have a *.class file that corresponds to this class type. How would I obtain a byte[] for this type’s definition?

You’re probably wondering why I want to do this. I’m basically trying to create a network class loader, with a “Local” JVM that has class definitions on its class path, and a “Remote” JVM that does not have the aforementioned class definitions on its class path. “Remote” is encountering an instance of NonIntrinsicType[] and requests a definition from “Local” for that class type, but my “Local” JVM can’t find a class file for NonIntrinsicType[], so it fails to provde a class definition byte[] to “Remote”.

Added 9/7/2010

One thing I should have mentioned… I am using Socket and ObjectInputStream to receive messages sent to “Remote” by “Local”. I’ve created a custom extension of ObjectInputStream on the “Remote” side and overrode protected Class<?> resolveClass(ObjectStreamClass). This is the first notification my “Remote” JVM gets when an incoming message contains instances of classes that have yet to be loaded. I have another socket that I use to pass class definitions around with, so when the first socket receives an instance of a class that hasn’t been loaded, it requests a definition for that class from the “Local” JVM via the second socket.

The problem happens when my custom ObjectInputStream.resolveClass(ObjectStreamClass) gets passed an ObjectStreamClass that returns a class name for an array type (the name looks like [Lsome.ClassName;). I can easily parse out the base-level type some.ClassName and load it first – this is done in the call to NetworkClassLoader.getInstance.loadClass(), where I get a byte[] for the base-level class and then use it to call defineClass() inside that method call.

I understand now that you probably can’t get a byte[] for an array type’s class definition, so that leaves me trying to figure out how to find the Class<?> instance for the array type and return it. Here’s the code for my resolveClass method in my custom ObjectInputStream on the “Remote” JVM’s message-receiving Socket:

@Override
protected Class<?> resolveClass(ObjectStreamClass osc) 
        throws IOException, ClassNotFoundException{
    try {
        return super.resolveClass(osc);
    } catch (Exception e){}

    String name = osc.getName();
    boolean array = name.contains("[L");

    if(array) name = name.replace("[L","").
            replace("[","").replace(";","");

    Class<?> c = NetworkClassLoader.getInstance().loadClass(name);
    if(!array) return c;

    //If it's an array type, how do I obtain its corresponding
    //Class<?> and return it here?

    throw new ClassNotFoundException();
}
  • 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-10T23:51:16+00:00Added an answer on June 10, 2026 at 11:51 pm

    You shouldn’t need to create a definition for [LType. If you have a Class, you can create an array of that class with reflection:

    Object array = Array.newInstance(yourClass, dimensions);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace

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.