Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 18 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


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.