Difference between declaring variables before or in loop?

Difference between declaring variables before or in loop?

Difference between declaring variables before or in loop?

View Answers

December 23, 2013 at 6:07 PM

String str;
for (int i = 0; i < 10; i++) {
  str = "my String";
}

Java - Declaring variable before loop is a good practice. like as given in the above code. We have declared the Variable string before the for loop.

It will help you in reducing the memory usage.

Ads









Related Tutorials/Questions & Answers:
Difference between declaring variables before or in loop?
Java - Declaring variables in for loops
Advertisements
please tell me the difference between local variable, staitic variables, and instance variables....
Rules for Declaring Variables in PHP.
Difference between struts and JSF
difference between == and === operators?
Difference between 3d and 4d
What is the difference between the >> and >>> operators?
Difference between Timer and Thread?
what is the difference between extends and implements
what is the difference between extends and implements
difference between lock and synchronization
Difference between SCJP Exams
What is difference between Path and Classpath?
what is the Difference between weblogic and jboss?
what is the difference between pop and oop
difference between hashcode,reference in java
What is the difference between hibernate and spring
What is the difference between $message and $$message?
What is the difference between a constructor and a method?
Variables
Difference between http and https
Difference between error and exception ????????
Difference between Struts and Spring
difference between $message and $$message
calculate difference between two dates
difference between prepared statement and statement
mysql difference between two numbers
What is the difference between a JDK and a JVM?
difference between servletconfig and servletcontext in java
difference between wite and writeto in java

Ads