• 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

classloader program

 
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[code]
public class Test{
public static void main(String args[])
{
System.out.println(Class.getClassLoader().getClass().getName());
}
}[\code]

here i got an error msg saying thatnon-static method getClassLoader() cannot be referenced from a static context
System.out.println(Class.getClassLoader().getClass().getName());
how can i resolve this error
pleas give some suggestions
thanking u
cinux
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need an actual object for this, because it's not a static method. Instead of

Class.getClassLoader()

use

(new Test()).getClass().getClassLoader()

For your purposes (where you are not using any classloaders of your own) it's probably equivalent to use

ClassLoader.getSystemClassLoader()

if you want to avoid the creation of a Test object.
 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey i have used ur piece of code.. but unfortunately i got sonme strange output..
it has given the hashcode of the class...:-(
what can do with ath hashcode ...
is there any advantages,applications by knowing the classloader??
please tell me soon
thanx
cinux
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

it has given the hashcode of the class


What do you mean by that? What has given you the hashcode? Are you passing the classloader to println? Then you most likely got its in-memory reference, with which you can do nothing.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic