Test.java
package test;
import shape.twod.*;
import shape.threed.*;
import shape.*;
public class Test {
/**
* Creates a new instance of <code>Test</code>.
*/
int o;
public Test() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
ObjActions obj[] = new ObjActions[4];
obj[0] = new Line(1,2,3,4);
obj[1] = new Circle(1,2,3);
obj[2] = new Line3D(1,2,3,4,5,6);
obj[3] = new Sphere(1,2,3,4);
for(ObjActions x: obj)
x.draw();
ObjActions.Actions2D o =(Circle)obj[1];
//Actions2D o =(Circle)obj[1];
System.out.println("Area of circle "+o.area());
ObjActions.Actions3D op = (Sphere)obj[3];
System.out.println("Volume of sphere "+op.volume());
}
}
Its location is D:\Program\Javalearningprograms and the location of packages used is D:\Program\Javalearningprograms\PackageCheck
First I compiled it with
javac -classpath .\PackageCheck -d .\ Test.java
It compiled successfully and created Test.class in .\test, then I used this
java -classpath .\PackageCheck test.Test
and got Error: Could not find or load main class test.Test
so I tried with the full path:
java -classpath D:\Program\Javalearningprograms\PackageCheck\ test.Test
and
java -classpath D:\Program\Javalearningprograms\PackageCheck test.Test
still got Error: Could not find or load main class test.Test
So then to check weather the .class file has any errors I moved folder .\test to D:\Program\Javalearningprograms\PackageCheck and tried
java test.Test from D:\Program\Javalearningprograms\PackageCheck and the program ran successfully
then I set CLASSPATH environment variable to D:\Program\Javalearningprograms\PackageCheck and cleaned the .class files and then tried
javac -classpath .\PackageCheck -d .\ Test.java it created Test.class in .\test folder and the I used
java test.Test and the program ran successfully, I tried
java -classpath .\PackageCheck test.Test
java -classpath .\PackageCheck\ test.Test
java -classpath D:\Program\Javalearningprograms\PackageCheck test.Test
java -classpath D:\Program\Javalearningprograms\PackageCheck\ test.Test
and got Error: Could not find or load main class test.Test
I dont know why -classpath is not working with java command, what am I doing wrongly?
Directory: D:\Program\Javalearningprograms\PackageCheck
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 09-Dec-15 1:35 PM baseobj
d----- 09-Dec-15 1:35 PM shape
-a---- 09-Dec-15 1:33 PM 559 Circle.java
-a---- 09-Dec-15 1:33 PM 566 Line.java
-a---- 09-Dec-15 1:33 PM 627 Line3D.java
-a---- 09-Dec-15 1:32 PM 384 ObjActions.java
-a---- 08-Dec-15 9:58 PM 340 Point.java
-a---- 08-Dec-15 9:58 PM 302 Point3D.java
-a---- 08-Dec-15 10:05 PM 343 PointTest.java
-a---- 09-Dec-15 1:33 PM 547 Sphere.java
dir /s)