Why don't we use the JAVA import string?

505    Asked by CameronOliver in Java , Asked on Oct 11, 2022

 I asked myself why we didn't import a package while we use String functions such as toUpperCase()? How do they get in there without importing packages?

Answered by Colin Payne

Java tutorials > Learning the Java Language > Packages:


For convenience, the Java compiler automatically imports three entire packages for each source file: (1) the package with no name, (2) the java.lang package, and (3) the current package (the package for the current file)...

Class java import String is in java.lang package, hence it is imported automatically per above rule.



Your Answer

Interviews

Parent Categories