Java optimal performance?

I have learned so far that Java works faster with BufferedReader and PrintWriter, but I would like to improve my coding a bit further.

Considering all the loops, I guess there is no real difference except while loop may require one less variable, therefore being slightly faster.

I am wondering, is program behaving any differently in terms of speed if I put my code outside the main method, but still in the same class, which is then called within main method?

Thanks

I highly doubt that it will make a difference. In general moving code and variable declarations around in Java is discouraged because it’s unlikely that it will make a difference and it reduces the readability. If you’re desperate for performance, you might be better off using C++.