Importing the java.lang package. *

9

Adding Java studies I came across a special package, java.lang , where the author of the book mentions that we do not need to import of this package.

  

There is a package   special in the Java world called java.lang. This package is special   because it is imported automatically. You can still type this   package in an import declaration, but you do not have to do   that. "OCA: Oracle Certified Associate Java SE 8 Programmer I Study"

I would like to understand why only the java.lang.* package is the only one in which we do not need to import when we are developing in Java and what does it differ from other packages we need to import?

    
asked by anonymous 25.12.2018 / 01:35

1 answer

10

It has all the major Java framework functions, and you'll probably need at least one function of what's in that package in applications that are not trivial and therefore have to import it, it is almost impossible to do something useful without using something from it. There is what is most important and it was considered bad to have to make an import almost mandatory in all codes, would turn out to be a bureaucracy. All other packages already depend heavily on the type of application, it is not any code that you do IO, or uses a collection of data, or utilities functions, etc. The other imported ones would automatically overestimate the surface of imported codes and increase the chance of conflicts and of having to turn off automatic import.

It is quite curious that Java is considered verbose to adopt this stance. C # preferred to put a lot of names used in the same language and let you import everything manually, for example almost every application needs to have using System; .

    
25.12.2018 / 01:48