0
Java question ?
Anyone could answer this question . How Java reads the text, bottom to top or top to bottom? I'll appreciate the answer. thanks
7 odpowiedzi
0
JuanRamoneMH
What do you mean by "reads the text"?
0
I meant when we write the code!!
0
JuanRamoneMH
Ok so tell me one thing if I print first after that declaring variable then what will happen?
public class Program
{
public static void main(String[] args) {
System.out.println (i);
int i = 0;
}
}
what will happen here?
0
I get it, but It comes to my attention when I wrote classes, because I put the class at the top and than I put at the bottom and I got the same result. so it looks like it does not matter in Java. I just wanted to make sure and find the answer what I thought.
0
JuanRamoneMH
See Java compiler reads from top to bottom even I think every programming language does the same thing.
You can create class or method anywhere but that would not work untill you don't call them.
Suppose I have a method written at bottom in the class but If I do not call that method then compiler will not read that method.
If you are calling that method then compiler will first read method then go inside method functionality.
0
Great. Now I am more clear than before.
Thank you very much for the info.
0
JuanRamoneMH
I hope this explanation will help you.
----------------
public class Program
{
public static void main(String[] args) {
readThisMethod();// compiler will first read this line then it will check this method is exist or not.
//If compiler found this method then it will go read that method functionality and will print value
}
//If I write this method on above the method then compiler will read it first and store in JVM for further action
static void readThisMethod() {
System.out.println ("Hi");
}
}