I am new to this forum thing so please let me know if I am doing anything wrong.
My question involves debugging classes for java. I am wondering if anyone could start me off on which way to go for the following:
"Create a debugging class that can be utilized in future assignments. The class will encapsulate exceptions, and offer the ability to output debugging information about any class, or a simple textual message."
I am doing an online course with no specified book or software. I have no idea where to start with this. Could someone help me out?
First, a bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. Initials aren't enough for a last name. You can change your display name here. Thanks!
Now, as to your assignment: wow. No idea, really. Does the assignment build in some way on something the instructor covered in lecture? This really doesn't sound like any standard programming practice -- it really sounds like something the lecturer would have specifically come up with in some context. Can you ask for clarification?
I can tell you that, for example, the technical programming term "encapsulate" as it's used in a Java context has absolutely nothing to do with exceptions; and debugging information is something that you get in context from a particular object, not from a class in general. So this really makes very little sense as-is.
This is really hard to answer not knowing where you are in the course -- i.e., what you already know, or not. My best guesses -- but these are just guesses:
1) For the exceptions part, perhaps what you're building is a driver program that can invoke some other code while catching all exceptions and reporting them? This actually isn't needed at all in Java -- it's entirely redundant -- but maybe something like
Or maybe this is a class about some particular API, and your general debugging program is supposed to serve as a harness for programs that use some specific API? What's the course about?
2) For the debugging info class, again, this isn't needed at all because it's redundant, but something like
Does any of this ring any bells?
author and iconoclast
Hmmm - I am wondering if something similar to the Logger APIs would achieve the required effect. Logger's need to be able to output whatever sort of information is provided in the method, whether it is plain text, debuging information, or an exception - pretty much the same as what you seem to need.
If your instructor was planning on having a class / application that could be used to attach to a running program, then you might be looking at the Java Platform Debugger Architecture (JPDA). Personally I suspect that this is too advanced though.
I'm wondering the same thing. Krista, is it possible for you to post the actual requirements?
It sounds like the old pre-log4j Debugging classes:
Note: this is ugly. You should always use log4j rather than this, but you may even be able to merge the two by getting the Debugger Class to call Log4J
You enable logging by setting debugging=true and recomiling, you stop debugging by setting it to false and recompiling. Or you can use Log4J.
You call it in code like this:
I haven't included all of the correct code as well as being able to log at particular levels (like Log4J) and logging Objects, primitives, etc, and logging to different locations (System.out, File, both, other) but I hope this helps.