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.









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 ForwardAction and IncludeAction
difference between == and === operators?
Difference between DispatchAction and LookupDispatchAction
difference between SessionState and ViewState
Difference between struts and JSF
difference between varchar & varchar2?
Difference between 3d and 4d
What is the difference between the >> and >>> operators?
Difference between Mysql and SQL
Difference between Timer and Thread?
what is the difference between extends and implements
what is the difference between extends and implements
Difference between SCJP Exams
Difference between JSP and Servlets
difference between lock and synchronization
Difference between request.getRequestDispatcher() and context.getRequestDispatcher()
Difference between forward and sendRedirect
Difference between ServletContext and ServletConfig
Difference between translate and replace
What is difference between Path and Classpath?
Difference between GET and POST
What is the difference between PHP4 and PHP5?
What is difference between a PROCEDURE & FUNCTION ?
Difference between XML and HTML - XML
difference between <%@ include ...> and <jsp:include>
What is the difference between $message and $$message?
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
Difference between http and https
What is the difference between a constructor and a method?
Difference between error and exception ????????
difference between applet and swings
Difference between jsonstring and json object
Difference between Struts and Spring
difference between $message and $$message
Variables
What is difference between the java and javascript?
Difference between getCurrentSession() and openSession() in Hibernate ?
What is difference between the java and javascript?
calculate difference between two dates
Difference between MVC1 And MVC2 - Struts
Difference between TRUNCATE and DELETE commands
Difference between and merge and update in hibernate
difference between prepared statement and statement

Ads