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?
 
StillUnAwareConnect With a Mentor Commented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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
All Courses

From novice to tech pro — start learning today.