File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes import java.lang.*; Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "import java.lang.*;" Watch "import java.lang.*;" New topic

import java.lang.*;

Gary Ba
Ranch Hand

Joined: Oct 23, 2009
Posts: 161

I have a question about using an Array. I read somewhere that by default java.lang.* is already imported in any classes thus there is no need to add it on top. I am using static method Array.getLength() but how come I need to import java.lang.reflect.Array; ? Can anyone please explain a reason for this?

Thank you,

star chaser..
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
java.lang.* importst only java.lang package.
java.lang.reflect is a completely different package.
They only share part of their name, but they are completely different,
they could be even stored in other jar files in different directories on the disk.

Think about package names like a directories on the disc, and about import clause like a 'dir' command
- dir /java/lang/* lists content only only of /java/lang, to list content of /java/lang/reflect
you must run another dir command.
Gary Ba
Ranch Hand

Joined: Oct 23, 2009
Posts: 161

K. I looked at the API and saw on top that the two are from two different packages.

Thank you for the knowledge!
I agree. Here's the link:
subject: import java.lang.*;
It's not a secret anymore!