Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java importing same packages .

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
fred rosenberger
lowercase baba
Bartender
Posts: 12086
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12086
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you .
 
Henry Wong
author
Marshal
Pie
Posts: 20892
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well.... One option is to trace the JVM to see how many times it opens a particular class file.

Henry
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Might be using the -verbose flag helps while compiling or executing.

Regards
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic