This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
The statement is from Manish's notes - "If the compiler gives you the default no-args constructor for the class, its accessibility is same as the class. " How can we see accessibility of the constructor which is given by the compiler? I mean since it is not in the source file? Thanks, - Ria
You can't see it in the source file but you can see it in the class file. Compile this:
And then decompile it using javap: javap -c -l -s Test1 You are going to get this:
As you can see the default no-arg constructor is public. Now do the same with the following code:
Decompile it and you'll see this:
The constructor has a default accessibility just as the class Test2. This confirms Manish's notes. Learn how to use javap, you'd be amazed what you could discover with it. [ March 26, 2002: Message edited by: Valentin Crettaz ]
Val,Corey,Manish thanks I have learnt something new here by the question posted by Ria -> Thank U . Valentine decompiling with javap-c-|-s Test1 . Should this command be from the DOS command prompt. Is it possible from textpad. I am using Textpad & dos prompt for compiling and running codes. Is there anything better out there for a beginner like me.
Joined: Aug 26, 2001
javap is part of the J2SDK suite tools. it is located in $JAVA_HOME/bin and is a normal utility just like java and javac. Moreover, TextPad and a DOS console is the best you can hope for as a beginner. That's what I would recommend to any beginner: Your favorite text editor, the J2SE and a terminal. That way you really get a good idea of how Java works. When using IDEs all the dirty work is taken care of by the tool for you and you never know how that compilation/execution stuff works. Way to go
Besides, it is possible to configure your Textpad so that you can see the result of compiling, execution etc in the textpad window itself. That way you have all your learning, and you don't have to switch to dos prompt every now and then. I am sure that you would be able to configure textpad to run Javap as well. HTH, - Manish