• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How compiler works.

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
_______________________
class OUTTER{
void metohd(){
new INNER();
class INNER{ }
}
}
___________________
There's a compile time error "Class INNER not found".I guess the error is due to intializing an Object (the INNER class)
before creating it.But methods can be called before being created for example
class qaz{
qaz() {method();
}
void method(){}
}
Please explain me why does the compiler work differently with the two examples i've given above??
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The flow of execution in methods is from top to bottom in any condition so, if you declare a inner class at bottom and run it at top it will give error.
This is not the case with outside the methods.
 
Nasir Khan
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks asim ,
As you said outside the method the flow of execution is NOT from top to bottom then how it is?
Does the comiler jump to a required line? If it is so why this code gives error.

class abc{
int i=j;
int j=1;
}
 
Ranch Hand
Posts: 103
Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! Nasir,
Please read "Thinking in Java" polymorphism chapter and in that forward referencing.
------------------
Graaaasp the Concepts and Graaaab SCJP. :Anil Kollur:
 
Nasir Khan
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Govinda
I've been in java since june of this year.Prior to that I did
some Oracle stuff.I'm sorry if made no sense with my question
but I think this is the place where we come to clear our doubts
By the way how many years did you spent with java? just curious.
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats a good question Nasir, I didnot know that forward referencing doesnt work with Local Inner Class declarations.
Although it works with Inner Class declarations
class Forward{
Inner inner = new Inner();
class Inner{ }
void metohd(){
}
}
I think the reason it that the code of a method is compiled to be loaded in stack, where as class member variables are part of heap.So they are treated in different ways. If anybody can throw more light on this, kindly..

Also your logic of comparing it with method invocation is not valid, because there is no such thing as local methods, i.e. methods defined inside other methods.
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




[This message has been edited by Sahir Shah (edited November 25, 2000).]
 
mohit joshi
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well congrats, Govinda, for scoring such good marks in SCJP.
I am glad to see you back at this site. Do spread the good knowledge that you have.
 
Nasir Khan
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Govinda
I accept you as my teacher(just becaue of your SCJP 98% score) but i tell you sometimes i used to be rude to my teacher
specially if one is rude.
About my educational backgound I'm Bsc(Math ) and have been teaching A Levels classes for many years .
(subjects:Maths,Physics and statisctics) .Though I have only few years programing experience I'm ready for
your technical explaination.
thanks
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Nasir ,
because you didn't have technical background , so i don't think you understand that compilation process. and by the way i am one of the big bosse's of mathematics.

Originally posted by Nasir Khan:
Govinda
I accept you as my teacher(just becaue of your SCJP 98% score) but i tell you sometimes i used to be rude to my teacher
specially if one is rude.
About my educational backgound I'm Bsc(Math ) and have been teaching A Levels classes for many years .
(subjects:Maths,Physics and statisctics) .Though I have only few years programing experience I'm ready for
your technical explaination.
thanks


 
Nasir Khan
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sir Govinda,
It's ok.I'm working on it myself.but why did you delete your
old reply.
quote__________________________________________________
Dear Nasir
Here is Nothing to sorry
I just want to know because of your post Heading
-------how java compiler works-------------
for your information I am a SCJP(98%). and that one question
which is wrong accrding to sun is not wrong accrding to me. because they required three ans for that question and according to me only two of the given ans shall be correct. i write a mail in this concerns to Sun , let see what happens. And Now your problum , the reason for your problum is "forward referencing " . because of that your code didn't compile. and generally people
didn't understand properly what forward referencing means and how it cause impact on the code. have a look to the following code. this code also uses forward referencing but allowe by compiler. these kind of problums is almost occured because of not trying to get the "FEEL" of java by persons who code in java.
class amazed {
int getValue() {
System.out.println("trying to give value of variable which not yet declared");
return i; //this variable is not declared yet
}
//int j = i; // enabling this line made compiler barking.
int i;
}
actully forward referecing is allowed by compiler upto some extent . this extent is decided by compiler itself and vary from compiler to compiler. basiclly a compilation process
consist of a number of passes & phases, like Lexical analysis, tokenizing , parsing , generation of intermediate code etc.
but before i tell you what is the reason for barking compiler to your code i must know about your educational backgroung(from which stream or branch you are graduate or post graduate) . because explaination of compilation process involves some such kind of terms which cannot (possibely) be interprated by non technical person. so i must know about your educational background. then after i can easily decide from where & how to
start explaination.
One more thing i want to made in your knowledge that i am a very rude & proudy & arrogant & etc person , so if you want to communicate with me then some time it might possible that my words bite you. if you are agree to bear that then reply me the seeking information in the same thread otherwise don't. mind one thing as you say you are learning here and according to me i am teaching you. so you have to follow my agreement.
if you get me positively then reply......
waiting for reply .........
____________________________________________________
 
Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic