user1869735
user1869735

Reputation:

How to import a java file into another java file in netbeans

I have 2 .java files I'm working with, one that is executable and the other one is a custom class.

I understand that during compilation, the custom class will be automatically imported since it's in the same folder on my machine. However, I'm using NetBeans and if I don't 'pretend' to import it in NetBeans, it would always show up with red lines indicating errors when I type the class object. Is there any way to 'import' the class .java file into NetBeans?

I'm a noob in java so I'm not sure how to questions like this one, sorry if my use of vocabulary isn't appropriate. Thank you very much!

Upvotes: 1

Views: 7491

Answers (1)

Ted Hopp
Ted Hopp

Reputation: 234857

If you have the two .class files in the same location, Java will always find the second one. The same location might be, for instance, a folder on your computer, a directory on a web server, or inside a .jar file. As long as Java can find one of them, it will find the other.

There are many tutorials on the web about Java packages and the Java classpath. These concepts are important to understand as you start to write larger programs. A good place to start is the Java Tutorial on Packages.

Upvotes: 1

Related Questions