Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-06-20
6
Medium Priority
?
198 Views
Last Modified: 2010-03-31
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#.)
0
Comment
Question by:stockblocks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16943546
Use log4j. It will report the class and package which logged the message
0
 
LVL 14

Accepted Solution

by:
StillUnAware earned 800 total points
ID: 16943557
You simply do that:

String name = someObject.getClass().getName();
String pack = someObject.getClass().getPackage().toString();
0
 

Author Comment

by:stockblocks
ID: 16944209
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 14

Expert Comment

by:StillUnAware
ID: 16944286
glad to help
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16944452
Log4j is the de facto standard for logging - i'd use it if i were you ;-)
0
 

Author Comment

by:stockblocks
ID: 16944591
CEHJ,  sorry -- thanks for the tip! I'll google it to learn more.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question