• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic