Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Import doubt

 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic