I created a List.java
file in folder UtilityPack
which contains this code
package Utilities;
public class List
{
private class
Use the complete name of the class to lauch your program :
java Utilities.List
But the folder name should also match the package name.
Your directory structure needs to follow your Java package pathing. IOW, if the class List
is in the package Utilities
, you need to situate it in a directory called Utilities, which should be at the root level of your project, i.e. the path of the source file should be C:\UtilityPack\Utilities\List.java. When you are in C:\UtilityPack (project root), you compile and run List
by referencing it as Utilities.List
.
You might also consider using Eclipse, it will prevent this sort of things from happening, or any other Java IDE.
You need the fully qualified name e.g.
java -cp . Utilities.List
i.e. you're telling the JVM to look from the current direct (-cp .
) for a class Utilities.List
, which it will expect in the file Utilities\List.class
.
To be more consistent you should put the .java file under a Utilities
directory (yes - this is tautologous - the package specifies this, but it's consistent practise).
I would also avoid calling your class List
. At some stage you're going to import a java.util.List
and it'll all get very confusing!
Finally, as soon as you get more than a couple of classes, investigate ant or another build tool, and separate your source
and target
directories.