It's not a secret anymore!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Import doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Import doubt" Watch "Import doubt" New topic
Author

Import doubt

saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

When i use IOException in my program, it doesn't work but when i do import java.io.IOException; then it works, so why i have to write this line in my program ,whereas other java functions are working without importing anything ? thanks in advance.

Tell the difficulties that i am difficult.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2854
    
  11

All classes in the java.lang package are automatically imported, so that may be what's confusing you. You can use other classes without importing them by just writing the fully qualified name, i.e. java.io.IOException, instead of IOException. Importing a class can just save you some typing.
saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

Greg Charles wrote:All classes in the java.lang package are automatically imported, so that may be what's confusing you. You can use other classes without importing them by just writing the fully qualified name, i.e. java.io.IOException, instead of IOException. Importing a class can just save you some typing.


Thanks Greg, Is there any way to automatically import classes like java.lang ?
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2854
    
  11

No, what I meant is you don't have to import anything in the java.lang package, like String, for example. You don't have to write import java.lang.String or use the fully qualified name. For classes in every other package, you do.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Import doubt