This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes importing java.lang Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "importing java.lang" Watch "importing java.lang" New topic

importing java.lang

Omkar Shetkar
Ranch Hand

Joined: Jun 22, 2006
Posts: 41

Hi All,

I have got a doubt regarding very basic fact of Java i.e., why we need not import java.lang package? What is the mechanism in Java which makes any program to have access to the default package?

Omkar V S
Ian Edwards
Ranch Hand

Joined: Aug 14, 2006
Posts: 107
There's nothing stopping you importing the java.lang package yourself - its just not required as the compiler will automatically do it for you.

This package provides classes that are fundamental to the language. You won't get far without it.
Swapnil Sonawane
Ranch Hand

Joined: Jan 02, 2008
Posts: 190
Yes. You need not import java.lang as Java does it automatically for you. There is no harm even if you import that explicitly.

Swapnil S. Sonawane<br /> <br />B.Tech (Expected May 2009)<br />Computer Science, NIT Durgapur, India<br />SCJA 1.0
Omkar Shetkar
Ranch Hand

Joined: Jun 22, 2006
Posts: 41

But I want to know how Java do that?
Paul Clapham

Joined: Oct 14, 2005
Posts: 18150

It's done by special-case programming in the compiler.
I agree. Here's the link:
subject: importing java.lang
Similar Threads
Thread question
important package
Name the mutable and immutable Classes
can we create object of the interface and what is the base package of java ?