Reputation: 115
I have PhotosScanner.java
and PhotosScanner.class
in same folder with Main.java
.
And now I want to use PhotosScanner
in the class Main
with this code:
import PhotosScanner;
public class Main {
public static void main(String[] args) {
PhotosScanner ps = new PhotosScanner();
}
}
When I try to compile Main.java
, then I get this error:
d:\space\NewPhotos>javac Main.java
Main.java:1: error: '.' expected
import PhotosScanner;
^
Main.java:1: error: ';' expected
import PhotosScanner;
^
2 errors
In Java 7 it compiles without errors (I'm using Java 8 now).
How can I import my PhotosScanner
class?
Upvotes: 3
Views: 1125
Reputation: 37023
I have PhotosScanner.java and PhotosScanner.class in same folder with Main.java
You dont need to import as they reside in same folder (i.e. same package).
You need to import when you try to use class from other package.
Upvotes: 1
Reputation: 9677
Imports in Java are used for importing Classes from outside the current package.
You don't need to import the class from the same package.
Upvotes: 1