Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

for System.out.println() why we don't we import java.io.* package

 
vijaya saradhi
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Please apologise if this is very basic and simple question.But to me its not so easy.


normally by default java.lang package is imported .System class contains a public static final PrintStream object called out which belongs to another seperate package java.io.

using this call is made to println() method present in PrintStream class.


in a java program normally we import all necessary packages we refer in our code.


But how it's possible in this case...?

please help me out.Thanks in advance.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.System class contains a public static final PrintStream object called out which belongs to another seperate package java.io.

That's why the System class needs to import PrintStream. A class needs to import the classes that are used in its source code, but not the classes of which it merely uses objects. The compiler can figure out what class "out" belongs to by looking it up in the System class.
 
vijaya saradhi
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much.

I was searching for the clue using javap utility.But it lists out only the methods and instance variables present in a class it won't display any import statements.I think I must use jad(Java Decompiler )to know the implementation of a class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic