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 7565721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:13:37+00:00 2026-05-30T14:13:37+00:00

So right now, I have a server that is running with ObjectInputStream and ObjectOutputStream

  • 0

So right now, I have a server that is running with ObjectInputStream and ObjectOutputStream.

The problem I am having is that I have a custom (anonymous) class that extends java.lang.Date that I am trying to send to the client and then compile.

So nowhere do I ever define the class on the client side, but I want to compile the class programmatically. I have tried many different methods, but every time I get a ClassNotFoundException because the class isn’t on the client side initially.

Class<?> dateClass = (Class<?>) in.readObject(); //This is where the CNF Exception occurs
Compiler.compileClass(dateClass);
  • 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-05-30T14:13:39+00:00Added an answer on May 30, 2026 at 2:13 pm

    The Java Serialization mechanism assumes the classes are known to the deserializing JVM, it doesn’t send the class definitions. In particular, when you serialize a Class object, you don’t send the byte code for that class but only instruct the receiving VM to look up the Class object for a class with a particular name.

    Also note that a Class object represents a class defined in the JVM, i.e. the class’ bytecode has already been loaded. It makes little sense to try to compile to class to generate that bytecode after loading the class.

    So, we need to somehow get the class definition to the client. The easiest approach is to do this like any other class the client needs (by packing it in the client’s jar file, or whatever means you use to install the client programm). If that is not possible, you could load the class definition over the network, for instance by using a URLClassLoader, or you could send the classfile through the serialization stream, and upon receiving it on the client use ClassLoader.defineClass to load the class.

    PS: This issue is completely indepedent of whether the class is named or not. The following test code shows that objects of anonymous classes can be serialized and deserialized just fine (if the receiving VM has the class definition):

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
            Serializable payload = new Serializable() {
                @Override
                public String toString() {
                    return "hello from the anonymous class";
                }
            };
            oos.writeObject(payload);
            oos.writeObject(payload.getClass());
        }
    
        try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) {
            System.out.println(in.readObject());
            System.out.println(in.readObject());
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing Tomcat Installation that is running on production mode right now.
Here's my question. Right now I have a Linux server application (written using C++
Right now I have an SSIS package that runs every morning and gives me
Right now I have a JSP page that allows to sort some items, when
Right now I have a table called Campaigns that has many Hits, if I
I am building a Fedora server (on VirtualBox right now). It is running Fedora
I have a website that's running on a Windows server and I'd like to
I'm running Window XP and I have a java utility that accepts an input
I have a SQL Server that holds a lot of data. An application, running
Right now I have a database (about 2-3 GB) in PostgreSQL, which serves as

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.