-2

I can't run any java program with terminal:

Screen shot of the error

openjdk version "10.0.2" 2018-07-17 OpenJDK Runtime Environment (build
10.0.2+13-Ubuntu-1ubuntu0.18.04.2) OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.2, mixed mode)

Any ideas?

pomsky
  • 68,507

1 Answers1

1

To compile Java source code (usually with a file ending in .java) you need to enact the Java Compiler, a.k.a. javac. This compiles the source to a bytecode binary file ending in .class.

When running bytecode binaries, you refer to the full classname, not the file. Java will then look for the appropriate .class file relative to the current location, load the appropriate class, and call the function main(). This allows there to be many (even nested) callable starts to a program from the one compiled binary classfile.

Furthermore, Java classes can exist in packages which are organised by directory, and declared at the top of the file, e.g.

package Arrays;

So, once you have compiled your program, you need to be in the folder above the Arrays folder, and then remove the .java from your java command and prefix the classname with 'Arrays.'. e.g.

$ cd /path/to/src
$ java Arrays.Speeds