aspose file tools*
The moose likes Beginning Java and the fly likes import   java.question 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   java.question" Watch "import   java.question" New topic
Author

import java.question

Justin Beattie
Greenhorn

Joined: Nov 28, 2001
Posts: 9
Hello everyone, first time beginner Java programmer with a question here (everyone says: BOO, lol). I am having a bit of trouble importing a math package into my class so i can perform simple math operation (sqrt, etc.). I am not too sure about the whole "import" thing either, i`m more of an #include kinda guy..
I tried: import java.lang.Math;
and a few other combinations including my trusty kleene star *, but i keep seem to be getting a "Method sqrt(double) not found in class JustCalculator...".
Anybody mind helping a poor lost Java kid find his way?
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

have a code snippet of what your problem is?
... and seeing as though you're a greenhorn on the JR, I'll give you a free hint: wrap your code snippets in the UBB [CODE] tags, it will preserve the whitespace and make it much easier to read .
Justin Beattie
Greenhorn

Joined: Nov 28, 2001
Posts: 9
yep, thanks!
Here`s some snippet of my JustCalculator class. It`s basically, just a calculator, lol.

now the problem i am having is an error that says specifically:

and i know it has something to do with my import:

and finally, i don`t fully understand the concept of what the importing does...
Thank you at least for reading!
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
In Java you import classes and packages, not methods. Your class has no method called sqrt - the Math class does. So, tell the compiler to use the Math class's method like this:
Math.sqrt(...)
Making sense?
[ June 07, 2002: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Justin Beattie
Greenhorn

Joined: Nov 28, 2001
Posts: 9
Heeeyy, yeah that`s working for me, and it makes sense too, thanks!!
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

Originally posted by Justin Beattie:
and finally, i don`t fully understand the concept of what the importing does...

Importing classes lets you use short names for classes rather than the FULL class name.
Try it out, you can remove the import statement and change your line to:
java.lang.Math.sqrt(...)
and it will work just the same.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: import java.question