There are 2 broad options:
You are trying to write an application in java
Then you need an IDE to develop it in, and a build system to produce the distributables, in the form of a jar file. There is no point or reason to trying to run this 'on the command line' the way you are. You need packages and a project definition.
You are just toying around for now, writing some basic code in a single source file.
Then just run the source file. This is a feature introduced in, I think, java11. Before that, this model of writing (stuff some lines in a source file and run it right away) is not what java itself is good at, only IDEs do that properly.
Starting with java11:
java Stemmer/Stemmer.java
works great, and no need to (re)compile anything. java
will take care of it.
Explanation
When you run a Java program, you specify the class name including the fully specified package, not the file path.
You read this answer before, and then proceeded to completely ignore it and try java Stemmer.Stemmer
which obviously doesn't work.
The class you have is named Stemmer
, and it is in the unnamed package. Thus, to run it, java Stemmer
is how to do this. It's not a file name. Stemmer.Stemmer
is not java-ese for 'run the class file Stemmer
in the subdirectory Stemmer
, and 'package' is not java-ese for 'directory on the filesystem'.
The classpath root for your Stemmer class is its own directory, as you are not using any packages. the default classpath is the current directory. It is not possible to run the Stemmer class file without having its root on the classpath, so if /Desktop/Lab 3/Stemmer
is not on the cp, you can't do it. So let's fix this:
java -cp '/Desktop/Lab 3/Stemmer' Stemmer
and that'll work fine.
More generally, using the unnamed package is a bad idea, and trying to run raw class files is similarly a bad idea - use an IDE for development, and a build system to build projects.
These rules and caveats all make perfect sense when writing a 'real' project (one you check into source control, and eventually deploy someplace or ship as a product to other users). But it's onerous and a tad ridiculous if just messing around. That's exactly why (these days) you can just specify a path to a java source file, which seems to be what you want to do. So, do that.