• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Marcus Exam No2 #57

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the following statements are true?
1) Adding more classes via import statements will cause a performance overhead, only import classes you actually use.
2) Under no circumstances can a class be defined with the private modifier
3) A inner class may under some circumstances be defined with the protected modifier
4) An interface cannot be instantiated
The answer is 3) and 4), but why not 1) ?
I think if we import all the classes, but we only use one or two classes within them, it will definitely affect the performance.
Need your help !
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I had the same impression, till I asked my java guru.
He did explain something, which I never got.
But the bottom line is, importing more classes than needed
doesnot effect. It is involved with the way the compiler
works. This stmt however, is a true for C++.
Try the Performance discussions, may be someone else has
a better insight into this...
Regds.
- satya
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Importing classes via the import keyword does not cause a performance overhead when your program is run.
First of all, the import keyword is just a short-cut for referring to classes by their full name.
For example you can write fully working programs without even using the import keyword. For eg:
java.util.Vector v = new java.util.Vector();
Now instead when you say:
import java.util.*;
Vector v = new Vector();
The compiler goes and searches in the java.util package to see if there is any class Vector. When it finds it, it replaces your code with the fully-qualified name of the class. Thus your byte-code will only contain the classes which you actually used in your program and not the entire bulk of classes in the package which you are importing.
The byte-code generated will be the same whether you import one single class or you import the entire package. What this means is that there is no performance overhead when running your programs. However there may be a slight increase in the compilation time of your program since the compiler has to look in the various packages to find your class.
Hope this helps!

[This message has been edited by Junaid Bhatra (edited July 24, 2000).]
 
kevin jia
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your help.
 
Ranch Hand
Posts: 477
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kevin jia:
3) A inner class may under some circumstances be defined with the protected modifier


Is this true? I think you can inherit an inner class, so I don�t find the meaning for the protected keyword in an inner class.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic