aspose file tools*
The moose likes Beginning Java and the fly likes import statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "import statement" Watch "import statement" New topic
Author

import statement

kap kumar
Greenhorn

Joined: Jan 13, 2005
Posts: 7
Hi there.

I am trying to make a program work which uses javabook. I have installed JDK 1.4.2. The program is not working as it does not recognise javabook.

What do i do and how.

Sorry about the stupid qu but im a beginer.

Thanks
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Hi,

Welcome to JavaRanch!

For the "import" statement to work, of course, the classes you're importing have to be available somewhere, and the compiler has to be able to find them. This page from the JavaRanch FAQ talks about the "class path", which is Java's solution to this problem. Head over there and read it and see if that helps!


[Jess in Action][AskingGoodQuestions]
kap kumar
Greenhorn

Joined: Jan 13, 2005
Posts: 7
I have the following classpath. (All else is working fine.)

.;C:\j2sdk1.4.2_04\lib\tools.jar

It is still not working.
[ January 31, 2005: Message edited by: kap kumar ]
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1821

We need a little bit more information in order to assist:

1). What is the error message that you are getting? (Copy-and-pasting it here would be preferable).

2). Is the javabook package in the classpath? From your posting, I would say not. Make sure that the Classpath includes and entry pointing to the javabook jar (or zip) file.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
kap kumar
Greenhorn

Joined: Jan 13, 2005
Posts: 7
The error message is:

Cast.java:1: package javabook does not exist
import javabook.*;
^
1 error

Where are the packages, i have a folder 'j2sdk1.4.2_04'.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Note that "javabook.*" isn't something that comes with Java -- it must be a third-party thing you read about somewhere. Based on the name, it's probably be the sample code from a book, yes? You need to download that sample code onto your machine, and arrange to have it on the class path, before you can use it from your own code. The book probably includes details about where to download the code.
kap kumar
Greenhorn

Joined: Jan 13, 2005
Posts: 7
thats rite, it is from a book.

Can you tell me some standard package that i can try?

thanks
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by kap kumar:
thats rite, it is from a book.

Can you tell me some standard package that i can try?

thanks


Well, that depends on what you want to do. There are several hundred standard packages. Here are some of the most common, at least from the Java coding I do:

java.lang - contains classes that Java uses under the hood (e.g. ClassLoader, Class, etc.) and some that are considered part of the language (e.g. String); you don't need to import this package
java.util - contains the Collections Framework; this includes classes like Vector, ArrayList, HashMap, and TreeMap, to name a few
javax.swing - classes for developing GUI applications with Swing
java.awt - classes for developing GUI applications with the Abstract Windowing Toolkit (AWT)

There are so many more that I don't dare even try to list them here. However sun has documented them very well. As you learn how to program in Java, you should familiarize yourself with the Java API documentation. Use this link to find the docs for the version of Java that you are using. When you click on the link to the docs for the appropriate version, the available packages are listed in the frame in the top left corner.

Layne


Java API Documentation
The Java Tutorial
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

I see you've been posting new threads on this same topic. I've closed them and redirected discussion to this thread.

Have you tried what I suggested in my very first reply? Have you read the FAQ about the CLASSPATH and added the .jar file you downloaded to your CLASSPATH?

Note that "tools.jar" almost certainly doesn't belong on your CLASSPATH; it contains the implementations of tools like javac, javah, anmd javap, and you shouldn't be using those classes in your own applications.
Lionel Badiou
Ranch Hand

Joined: Jan 06, 2005
Posts: 140
Hi Kap,

Understanding the java class search mechanism is strongly recommanded. You may teach yourself in few minutes here

Best regards,


Lionel Badiou
CodeFutures Software
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: import statement