For our assignment we need to write code for a neural network. The way I planned to do it was to write a Node class, which is a node within the network; a Layer class, which is a layer of nodes and a NeuralNet class, which is a network of layers.
I’m having a lot of trouble understanding the way Java is designed to work for imports. To me it seems that it should be a simple matter to include my Node class in my Layer class, and my Layer class in my NeuralNet class, however Java doesn’t like importing from the default package.
What I have read suggests that anything you import needs to be in a package and packages have their own subdirectory. Because of the way I plan to structure my classes, this leaves me with what seems to me, an unwieldy and unnecessarily complex directory structure ie.
neuralpkg.layerpkg.nodepkg.Node
Can someone explain to me whether this is the only way to implement the structure that I want or whether there is some much, much simpler way that I’ve missed?
For what its worth I’d have no trouble writing this in C/C++, but attempting to import in a similar style has only given me heartache.
You don’t need to layer the package like
neuralpkg.layerpkg.nodepkg, where “neural”, “layer”, and “node” are subpackages for the respective classes.You can simply create a package named “ben” and put all of your classes in there. So within your source directory you’d have a layout like:
Each class definition should then start with the line
package ben;.Classes in the same package don’t need to import each other.