Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

up vote 14 down vote accepted

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 String is in java.lang package, hence it is imported automatically per above rule.

share|improve this answer

The java.lang package is imported by default. If you take a look at the classes in the package, you'll see that they are very common classes that you end up using frequently, independent of what your program is actually trying to do. Rather than essentially requiring every file to have import statements for these classes, the creators decided to include it for you behind the scenes.

share|improve this answer

the String object is part of java.lang which is considered core and is always included (like for example Object)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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