Question: I'm trying to cast an object passed by my client application to an object of identical class in my server application.

The error I'm currently receiving in my server application is:

```
mei 02, 2012 11:44:43 PM server.UserThread process
SEVERE: null
java.lang.ClassNotFoundException: client.User

```

The object is being received by the server via Socket -> ObjectInputStream.

So I was wondering if you guys could help me cast the client.User class to my Server.User class. The only thing that works is placing the packages inside 1 project and then defining the exact location of the class.

Code can always be supplied.

Answer: 
> 
> cast the client.User class to my Server.User class
> 
> 
> 

You can't. They aren't the same class. They are in different packages. They are different. If you want to share a class between server and client, you have to share a single .class file. That might imply creating a third package for shared stuff.
The classes need to be the same, as some users suggest in reply to your question. It doesnt seem like a good choice to use the default serialization procces to flatten and inflate your objects.
You can define your own protocol if you use the [Externalizable](http://docs.oracle.com/javase/7/docs/api/java/io/Externalizable.html) interface, instead of Serializable,
you can use writeExternal and readExternal to customize the serialization procces.

If you are trying to send object from server to client, I really discourage the use of the object streams. May I suggest [Protobuff](http://code.google.com/p/protobuf/) to do this?

> 
> Protobuff:
> 
> 
> Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. Google uses Protocol Buffers for almost all of its internal RPC protocols and file formats.
> 
> 
>