I have a client and server which use serialization to send an array of
why should I create [the class] in the same package?
Shape is not the name of the class, only a part of it. Java identifies classes by their full name, which includes package.
If you define
Shape on the server as
com.myserver.Shape and on the client as
com.myclient.Shape, JVM would correctly treat the two classes as unrelated.
A common approach is to make a special package for your data exchange objects, e.g.
com.shared.dto.Shape, and use it on both sides of communication.
If you need to share your project with someone else, make a separate jar with your DTOs, and another jar with the client library. Build the client code using the client library and the DTO jar. This will ensure that the client would be able to communicate with the server built against the same DTO jar.