-2

In java we import packages to the classes.when we accessing some thing from a different package we have to import that package to our working package.like,

  • java util.*;
  • java io.*;

But we never import java lang package.Why is that?what is the specialty in java lang package.

2
  • It is auto imported stackoverflow.com/questions/2073680/…
    – Thiyagu
    Commented Jul 10, 2018 at 4:25
  • 2
    @ThilanRavindu your question is entirely reasonable: it is non-obvious why it should be so. It has just been asked many times before. Commented Jul 10, 2018 at 5:46

2 Answers 2

8

Because:

Code in a compilation unit ... automatically imports all of the public types declared in the predefined package java.lang.

Source: Java Language Specification #7

2
  • 2
    Translation: "just because". Hmmm ....
    – Rick
    Commented Jul 10, 2018 at 5:02
  • 1
    @Rick Translation: because that's the way they designed it, and here is the JLS citation to prove it. What else were you expecting exactly?
    – user207421
    Commented Oct 12, 2019 at 10:34
-1

Java.lang package is imported by default. If you check the documentation, then you'd see you use mostly half of it blindly.

Documentation: https://www.cs.mun.ca/java-api-1.5/api/java/lang/package-summary.html

Source: http://www.cafeaulait.org/course/week4/31.html

1
  • Elliotte Rusty Harold's text is not a normative reference.
    – user207421
    Commented Jul 10, 2018 at 4:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.