Home > OS >  How to use multiple java file, each file in each folder?
How to use multiple java file, each file in each folder?

Time:11-06

I am new in java and I coding on vscode. I create 2 .java file like picture below:

enter image description here

And these are each file:

main.java:

package program;
import sth.another_one;

public class main{

    public static void main(String args[]){
         another_one a = new another_one();
         a.func();
        System.out.println("main");
   }
}

And this is

another_one.java:

package sth;

public class another_one{
    public void func(){
        System.out.println("From another one");
    }
}

When I put both of them the same folder it run normally, but if I separate them like this and run on cmd -> it return like this:enter image description here

I try all command like:

javac -cp ".;C:\Users\Admin\Desktop\test\java\sth" main.java

javac main.java

javac -classpath main.java

I don't know why it did worked, please help me solve this.

CodePudding user response:

Even if you overcome this issue, you are sure to encounter another after having a big project.

Use an IDE (Integrated Development Environment). It will take care of many things for you and you don't have to worry about linking/building problems. Through IDEs, you focus on developing and not on the background of compiling and class files.

There are so many good ones out there

  1. enter image description here

  • Related