• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Importing the class file

 
humanoidi ufo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been given a prepared class file that I should use in my program. I have tried to use the following code:

import java.util.Scanner;
import class1;

public class Program {
...

It does give me the following error messages:
Program.java:2: �.� expected
import Juoma;


I have been said that "Class1 should be in a package. Since Java 1.4, you have been unable to import a class from the default package." So, how do I create a package? Or how do I use the file class1 in other way?
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no need to import a class from default package.

Import allows to use simple name (without package) of the imported class instead of fully qualified name (with package).
Classes in defulat package have same simple and fully qualified name so importing such class would do nothing.

What should class1 do?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If class1 is not in a package, and your own class is not in a package (i.e., they are both in the default package), just put both *.class files in the same directory and it will work.

Just remove the "import class1" statement. You don't need to import classes that are in the same package.

Vlado: it is not even possible to import packages in the default package since Java 1.4. So if class1 is in the default package but your own class is not, you wouldn't be able to use class1 at all in your own class.
[ January 31, 2006: Message edited by: Jesper de Jong ]
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java 1.2 did not allow importing classes from the default package, either. As stated above, it is not necessary since you can use them directly.

Layne
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way "Humanoidi UFO", will you please change your name according to the JavaRanch naming policy?

All JavaRanch users are asked to use a real name as their display name, with a first and last name, and maybe more, separated by spaces. Obviously fictitious names may be locked out. By "real name", we mean either your own actual, personal name, or a name that at least looks like it could belong to a real person. No names of celebrities or fictional characters. No cute nicknames like "javarulz" or "Hacker King". No joke names like "Adam Baum" (atom bomb) or "Justin Case" (just in case). No names with embedded numbers or other unorthodox punctuation like "Mike505" or "John_Smith". No names of companies - just people.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand why his name is obviously fictitious
[ February 01, 2006: Message edited by: Satou kurinosuke ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic