I am pretty new to Java and Linux. I can't use an IDE but i have jdk installed (obviously). I have three .java files that i want to compile. One is the main code file and two small classes. how do i compile them using terminal? these files are called:
- main.java
- object.java (Object.class when compiled)
- living.java (Living.class when compiled)
object.java and living.java only have a constructor for now that i want to call
i've tried
javac main.java #this seems to be the right one
javac main.java object.java living.java
javac main.java Object.class Living.class
in terminal and
import object.java;
import living.java;
import Object.class;
import Living.class;
import object;
import living;
import Object;
import Living;
in the main.java file
but nothing seems to work
when i use
import Living;
in the code it tells me that it misses a ; or .
, when using precompiled
import Living.class
in the code i get
error: class, interface, or enum expected
import <Object.class>;
in the terminal and when i try
import living.java
in the code i get
error: package living does not exist
import living.java;
in terminal
so what am i doing wrong? do i have to import precompiled classes or java codefiles? do i have to tell javac all files i want to use or only the main.java file? main.java compiles without error when i don't try to import one of the classes. And if i have to use .jar files please explain and give an example
importthem in your code.