Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

1. super(); 2. debugging 1

Status
Not open for further replies.

ajuking001

Programmer
Mar 30, 2001
3
JP
Hi all,
1. why should the super(); statement be the first in the class that extends a superclass ? can it not be the second or placed after a method of that class ?
2. What is debugging of code ? If i am using notepad to type in my code , what is the best way to debug errors at runtime . How do using editors such as visual cafe or vj++ help ?

Thanks.
Archie
 
Actually, it's quite a pity the super() call has to be the first one in the constructor of a class.
The reason is that when a new class is constructed, the super()-Constructor is automatically called. IF you don't tell the JVM to do otherwise. This goes up the line with every class calling super() until it reaches java.lang.Object, the mother of all Java classes (as you sure know). :-X
The following is what I think is the reason for this - anybody correct me if I'm wrong: the Object class allocates memory and is actually platform-dependent in its implementation (providing the same functionality in the end). It is responsible for a class even to be able to exist, so its constructor has to be called before anything can happen.
If you create classes that don't have a constructor with no arguments, you'll even have to call a specific one of the existing constructors in its subclasses.

Hope I didn't shake up your mind to severely... X-)

Try the following for the command-line-debugger (just the first link i found when searching at

I never used the command line tools though, except a little compiling, JARing and JavaDoccing... :~/

For the debugging: IDEs (not just editors with a syntax highliting like - why not use this instead of good old notepad?) like Visual Cafe (do NOT use J++ - incompatible with every normal Java around, it's pure Microsoft >:):O>), Kawa or JBuilder (which I would recommend, see for a free version) normally provide a way to set breakpoints at which the program stops and you are able to check all variables that are currently valid (in scope) and instantiated.
You normally then are also able to follow the current Thread on a step-by-step basis, which shows you what the program you did is actually doing when it runs.

Debugging stands for "getting all bugs out of the program" - a noble goal. Maybe you'll reach it...

Hope this helps... allow thyself to be the spark that lights the fire
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top