wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes java importing same packages . Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java importing same packages ." Watch "java importing same packages ." New topic
Author

java importing same packages .

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi , This is an Standard FAQ of Java .

Can I import same package/class twice? Will the JVM load the package twice at runtime?

A: One can import the same package or same class multiple times. Neither compiler nor JVM complains abt it. And the
JVM will internally load the class only once no matter how many times you import the same class.


But can we prove this ? Is there any Proof Of Concept for this .

Save India From Corruption - Anna Hazare.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11175
    
  16

What would you accept as proof? Documentation can easily say one thing, and the program do something else. Would you be satisfied with anything other than the source code for the JVM?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

fred rosenberger wrote:What would you accept as proof?

Please don't get angry . I am asking whether there i can see it in any way on to class files .
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11175
    
  16

i'm not angry at all. I'm just trying to understand what you would accept at 'proof'.

I don't know if the JVM source is available. There is probably some license agreement prohibiting decompiling the class files, so you can't do that...

heck the JVM does not even have to be written in Java - it could be a binary executable.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thank you .
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18553
    
  40

Well.... One option is to trace the JVM to see how many times it opens a particular class file.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
Might be using the -verbose flag helps while compiling or executing.

Regards


Experience and talent are independent of age
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It could be different across JVMs, too, although I'd be pretty surprised if anything was loaded twice.

I'm not really sure how meaningful the question is anyway--it's not like the byte code will change if something is imported twice.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java importing same packages .
 
Similar Threads
ClassLoader and Static variables
what will happen if we import a package twice
Package/Classpath problem with 1.4
what happens when i include a package more than once
package help