0

I have the following directory, let's call it program/, housing the following items:

Circle.java 
Point.java 
Shape.java
Triangle.java
Main.java
Geometry/` 

All of the .java files are part of the same geometry package, so I use this command to compile them together:

javac -d Geometry/ Main.java Triangle.java Shape.java Point.java  

This puts a .class file for each of the above files into the directory program/Geometry/geometry. It also puts those same files into the /program directory, so I guess my first question is why does it put those .class files in both locations? There doesn't seem to be a point in putting them with the .java files if they are contained by themselves in the geometry package directory.

Regardless of the answer to that, my main problem is that I can't seem to get my program to run. Inside Main.java, there is the Main class with a main() function that is supposed to work its magic. I have run the following command in both the program/ and program/Geometry/geometry with the same error, both listed below:

java Main 
Error: Could not find or load main class Main

Can someone explain what I am doing wrong here, and give me an answer to my first question as well? Thank you for any help you can provide!

user207421
  • 298,294
  • 41
  • 291
  • 462
UnworthyToast
  • 805
  • 5
  • 11
  • 19

2 Answers2

0

Specify a classpath. In the same folder that you ran your compilation above, something like

java -cp Geometry Main 
Elliott Frisch
  • 191,680
  • 20
  • 149
  • 239
0

Your Main.java file must have main() method.

Something like this:

public static void main(String[] args) {
    ...
}
Ghost4Man
  • 945
  • 1
  • 12
  • 18
Jude Niroshan
  • 4,081
  • 7
  • 39
  • 58