File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Importing the class file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Importing the class file " Watch "Importing the class file " New topic
Author

Importing the class file

humanoidi ufo
Greenhorn

Joined: Jan 31, 2006
Posts: 2
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

Joined: Aug 03, 2004
Posts: 245
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

Joined: Aug 16, 2005
Posts: 13869
    
  10

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 ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13869
    
  10

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

Joined: Nov 24, 2005
Posts: 14687
    
  16

I don't understand why his name is obviously fictitious
[ February 01, 2006: Message edited by: Satou kurinosuke ]

[My Blog]
All roads lead to JavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Importing the class file
 
Similar Threads
A question from Marcus Green's mock exam
error while compiling
compile problem
Not able to create package
call to JTextArea.getText() is not getting current text