I am trying to learn how to compile classes in Linux using javac and running them using java commands.
If I create a class and its main method is simply System.out.println(1); then I have no issues compiling.
However, when I start to reference other classes in the main method of a class, such as
package com.example
public class Main {
public static void main(String[] args) {
Class1 class = new Class1();
class.printX();
}
}
It will not let me compile even though Class1 is already compiled.
I literally just type in javac Main.java in the terminal and it replies with a few errors about how iv written the class eg. Class1 class = new Class1(); is not a statement ect.
Through some simple google searches, I have come across terms such as CLASSPATH that I don't fully understand. I have literally just downloaded the JDK and tried to compile away lol.
I am completely new to Java without using an IDE and I've only just started to use the Linux OS as of yesterday (Linux Mint) so do assume I know absolutely nothing. I am also new to posting on stackoverflow so please go easy on me if I'v done something wrong, I'v tried to supply enough information without rambling on. Thanks!
lsshould list thecomfolder of your package, then compilejavac -cp . com/example/Main.java. The-cp(or-classpath) flag tojavactells it option to specify the base directory of the package com.example, in order to locateMain.java