• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Active vs Passive usage of classes/Interfaces

 
Ranch Hand
Posts: 62
Netbeans IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This is referring to the class/interface loading by the class loader: What is active and passive usage of classes and interfaces? Could anyone please elaborate this concept a bit? Or at least refer me to some good material for the same.

Many thanks in advance.
 
Sheriff
Posts: 6914
1314
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This sounds not related to SCJP. Moving to JiG
 
Hrishikesh Yeshwant Alshi
Ranch Hand
Posts: 62
Netbeans IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Devaka,

I think there is some confusion. This is related with SCJP.

 
Devaka Cooray
Sheriff
Posts: 6914
1314
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hrishikesh Yeshwant Alshi wrote:This is related with SCJP.


What did you mean by active/passive usage? That's something I never heard before.
Since the underneath methodologies of ClassLoader are not bound to the scope of SCJP, I guess JiG is the best place to discuss this. If another moderator feels this is related to SCJP, this could be moved back to SCJP forum.
 
Sheriff
Posts: 22649
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with JiG being a better location.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've also never heard of "active" or "passive" usage of classes and interfaces. Where did you read this?
 
Hrishikesh Yeshwant Alshi
Ranch Hand
Posts: 62
Netbeans IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did I use the incorrect technical term - "Active/Passive usage of Classes/Interfaces"?

I found this in JLS - here

Apologies if that created confusion.

Thanks,
-Hrishikesh
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That page explains in a few places that classes or interfaces that are not actively used might not be initialized at all. There's this example:

And the text then says: "The class One is never initialized, because it not used actively and therefore is never linked to."

That means that when you run this program, the static initializer of class One will not be run, so you do not see the output "One". This is because there is no thread that needs class One, so the JVM will not load and initialize it. Classes are only loaded and initialized when they are actually needed.

There's no such thing as "passively" using a class.
 
Greenhorn
Posts: 2
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Page number 239
Java 2 Virtual Machine
by Bill Venners
 
Marshal
Posts: 75714
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please tell us briefly what page 239 says; I don't have that book.
 
Sid War
Greenhorn
Posts: 2
Netbeans IDE Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
following six situations qualify as active uses of a type
1. execution of 'new' instruction
2. Invocation of static method of a class.
3. Use or assignment of a static field declared by a class or interface, except for static final fields.
4. Invocation of certain reflective methods in Java API
5. Initialization of a subclass of a class
6. Designation of a class as the initial class(with main() method) when JVM starts

Example of passive use:
A use of a non-final field is an active use of only class that declares the field.
A static field declared in a class might be referred to via a subclass. This is a passive use of the subclass and active use of the super class.
This use will not trigger the initialization of the subclass.
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think we shouldn't think about this in a too complicated way. I guess that with "passive use", the book just means "the opposite of active use".

Note that the Java Language Specification (in the chapter that Hrishikesh mentioned) doesn't use the words "passive use" anywhere, so it's not official terminology from the specification.
 
Campbell Ritchie
Marshal
Posts: 75714
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think creating a new terminology which nobody else uses is potentially a cause of confusion.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as I know active use is

If you create new keyword to create an object from a class its considered as active use of that class.

If a class has a static method and if you call this static method this is active use of that class.

Also if you assign a value to a static variable that is also considered as active use of that class.

There's few more .

https://www.youtube.com/watch?v=CQQzYCjNdIw&list=PLD-mYtebG3X-rF1hU16AC3Rf9E-mAAkXJ&index=4

this video 15.00 you will find what I'm telling you. I hope this is what you were looking for at the time. Hope this will be useful for anyone else looking for the same.
 
Campbell Ritchie
Marshal
Posts: 75714
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Did you produce that video yourself?
 
Hasitha Subhashana
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch

Did you produce that video yourself?



Hey no. This is one of my mentor. Its his video
 
My pie came with a little toothpic holding up this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic