public class basicCounter_jsp extends HtpServlet
count = count*2;
int count=1; // It's java so no problem with forward-referencing(Declaring the variable AFTER you used it in a method)
My question here is Then why doesnt the below compile :
Christophe is correct and to elaborate a bit more on this you have to know that the page is first translated into a Java file before it is compiled. During the translation phase the declarations are moved outside the _jspService() method. So in this case both the method as the declaration of count do not end up in the _jspService() method. count becomes an instance variable and doubleCount() an instance method.
If you make them local to the _jspService() method, let's say like this (you can't have a method inside a method)
then the compiler will definitely complain that count isn't defined.