top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

If we import same package/class twice. Will the JVM load the package twice at runtime?

+5 votes
681 views
If we import same package/class twice. Will the JVM load the package twice at runtime?
posted Feb 16, 2014 by Prachi Agarwal

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

In JAVA each class is loaded by the class loader subsystem only once......
Though u can import it multiple times but with no benefit.
When a class is loaded is much complex....Refer cathy serra book for details. This book gives all the details on when the class is loaded refering to static and nonstatic scopes and other related issues on class loading.

answer Feb 22, 2014 by Prakash
0 votes

No, it will run one time only.

answer Feb 16, 2014 by Neeraj Pandey
Similar Questions
+2 votes

I was playing around some static inner class.

    package com.tutorial; 
    public class MyUpperClass {
        private MyUpperClass () {

        }
        private static class MyStaticInnerClass{
                    private static final MyUpperClass muc = new MyUpperClass ();
        }
        public static MyUpperClass getInstance() {
            return MyStaticInnerClass.muc;
        }
    }

Now, My question is, when does MystaticInnerClass get loaded into the JVM memory?
At the time of, when MyUpperClass get loaded or getInstance() get called?

+1 vote

For example -

Case A - It consumes less signalling load:

Cell X - Band1 - PCI 22
Cell X - Band2 - PCI 22

Case B - It consume more signalling load:

Cell X - Band1 - PCI 22
Cell X - Band2 - PCI 222

+1 vote

DataStream classes such as DataInputStream and DataOutputStream class. why DataStream classes needed for input data. while we have others stream classes in java through which we can input the data.

...