Importing the java package.lang.*

Adding the studies in Java I came across a package so special, the java.lang, where the author of the book mentions that we do not need to carry out the 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 need to do it. "OCA: Oracle Certified Associate Java SE 8 Programmer I Study '

I would like to understand why only the package java.lang.* is the only one in which we do not need to import when we are developing in Java and what has a difference with the other packages in which we need to import?

Author: Maniero, 2018-12-25

1 answers

It has all the main functions of the framework of Java and you will probably need at least one function of what is in this package in applications that are not absolutely trivial and therefore would have to import it, it is almost impossible to do something useful without using something from it. Ali has what is most important and it was considered bad to have to make an almost mandatory import in all codes, would become a bureaucracy. All other packages already rely heavily on the type application, it is not any code that you do IO, or uses a collection of data, or utility functions, etc. The other ones imported automatically would increase the area of imported codes too much and increase the chance of conflicts and or having to turn off the automatic import.

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

 10
Author: Maniero, 2018-12-25 00:48:15