Can Java source code know it's parent file and package names without explicitly defining static String's?

I'm beginning to use JBuilder 2005 for servlet programming.

I often embed references to the source filename (and associated package it belongs to) when reporting error exceptions.  Currently, I have private static String vars named -- appropriately -- CLASS_NAME and PACKAGE_NAME.

Is there a better way?  I was wondering if there was some magical code call that automatically identifies their names.  If not a JDK call, but perhaps a JBuilder macro-like call that can be embedded in my .java files (for example -- and I'm making this up --  #CLASSNAME#.)
stockblocksAsked:
Who is Participating?
 
StillUnAwareCommented:
You simply do that:

String name = someObject.getClass().getName();
String pack = someObject.getClass().getPackage().toString();
0
 
CEHJCommented:
Use log4j. It will report the class and package which logged the message
0
 
stockblocksAuthor Commented:
Excellent.  I see that getClass().getName() reports both package and class names together, which is perfect!

Should have known this all along. Thanks!

SB
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
StillUnAwareCommented:
glad to help
0
 
CEHJCommented:
Log4j is the de facto standard for logging - i'd use it if i were you ;-)
0
 
stockblocksAuthor Commented:
CEHJ,  sorry -- thanks for the tip! I'll google it to learn more.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.