aspose file tools*
The moose likes Beginning Java and the fly likes Can't Understand the Exact Sequence of method Calling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can Watch "Can New topic
Author

Can't Understand the Exact Sequence of method Calling

Lavneet Sharma
Greenhorn

Joined: Dec 29, 2011
Posts: 10
I'm new to Java after having a good working experience of 5 years over C++.
Like C++, where the program starts its execution through main() function and proceeds further by calling other functions, I can't figure out this sequence in Java.

I covered most of the topic in Java, and when I came to AWT, I got the folowing problem:




I can't figure out the sequence in which the above programming code works. I means, starting from main(), constructor is invoked. then......!!!???
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Yes the Constructor is called but look what the constructor does:

Lavneet Sharma
Greenhorn

Joined: Dec 29, 2011
Posts: 10
Thanks for the reply James. But, what i can understand about this constructor is as follows:

super("MenuExample")
it is overRiding the super method to display window title

pack();
it is combining all elements of frame

is it the pack() method making some role over here?
Sorry, i'm transitioning from c++ to java. So, some doubts are...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
Code Mink wrote: . . . super("MenuExample")
it is overRiding the super method to display window title . . .
No. It is calling the constructor in the superclass which takes a String parameter. That String is used to set the title on the frame, so the text MenuExample is passed to the superclass constructor to display at the top of the frame.

You must have a very old book if you are learning AWT. I would recommend you put that book back on your bookshelf and buy something printed this century The show() method has been deprecated for 7 years.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
Code Mink wrote: . . . pack();
it is combining all elements of frame

is it the pack() method making some role over here? . . .
I can never seem to get pack() to work, myself. What it is supposed to do is to add up all the sizes of the child components in that frame, and set the size of the frame to match. It seems very peculiar that a sizing method call should immediately be followed by a different size!
Lavneet Sharma
Greenhorn

Joined: Dec 29, 2011
Posts: 10
Ohhh...!
Actually, i'm learning java from 'Peter Nortan's guide to Java Pragramming'
Well, thanks for the suggestion. Can you please suggest me a book instead of that?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
Earlier, I wrote: . . . It seems very peculiar that a sizing method call should immediately be followed by a different size!
Even more peculiar that the call to change size also uses a deprecated method. I would repeat my recommendation to get a different book. Which book are you using?
Lavneet Sharma
Greenhorn

Joined: Dec 29, 2011
Posts: 10
I'm currently refferencing 'Peter Nortan's Guide to Java Programming'
which book should i use instead of that.?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
Code Mink wrote:Ohhh...!
Actually, i'm learning java from 'Peter Nortan's guide to Java Pragramming' . . .
Looks quite a good book, although it uses “namespace”, a word not usually used about Java™, and it has the usual misunderstanding which C/C++ people have about what protected and static mean. Unfortunately it was written in 1996, and I would regard it as so out of date as to be useless.
If you search this forum, you will find lots of threads about books: here are a few. 1. 2. We also have a book review link.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't Understand the Exact Sequence of method Calling