Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't Understand the Exact Sequence of method Calling

 
Lavneet Sharma
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes the Constructor is called but look what the constructor does:

 
Lavneet Sharma
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm currently refferencing 'Peter Nortan's Guide to Java Programming'
which book should i use instead of that.?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic