aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes for  System.out.println()  why we don't we import  java.io.*  package  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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "for  System.out.println()  why we don Watch "for  System.out.println()  why we don New topic
Author

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

vijaya saradhi
Ranch Hand

Joined: Dec 31, 2007
Posts: 32
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
Marshal

Joined: Mar 22, 2005
Posts: 42280
    
  64
.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.


Ping & DNS - my free Android networking tools app
vijaya saradhi
Ranch Hand

Joined: Dec 31, 2007
Posts: 32
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: for System.out.println() why we don't we import java.io.* package