About 351,000 results
Open links in new tab
  1. What is the difference between local and instance variables in Java ...

    Jan 18, 2010 · Existence time: Local variables are created when a method is called and destroyed when the method exits whereas instance variables are created using new and destroyed by the garbage …

  2. Why must local variables, including primitives, always be initialized ...

    Oct 13, 2009 · 11 In Java, class and instance variables assume a default value (null, 0, false) if they are not initialized manually. However, local variables don't have a default value. Unless a local variable …

  3. Variable default value in Java - Stack Overflow

    9 From the Java Language Specification, Java SE 8 Edition, 4.12.5 Initial Values of Variables: A local variable (§14.4, §14.14) must be explicitly given a value before it is used, by either initialization …

  4. Why are local variables not initialized in Java? - Stack Overflow

    Before Java 7, instance variables are stored on the heap and local variables are found on the stack. However, any object that a local variable references will be found in the heap.

  5. Java error "Value of local variable is not used" - Stack Overflow

    Jun 16, 2012 · 1) "value of local variable p is not used" is a compile time warning. 2) A Launch Error is a run-time error rather than a compile time error. 3) Someone who is "really new to java" should try …

  6. What happen when a method returns a local variable in java? Does the ...

    May 29, 2021 · Local variables' lifetime does NOT extend after the method has returned. Java methods are not closures. BUT: the objects created within a method have a completely different lifetime. The …

  7. java - Local variable defined in an enclosing scope must be final or ...

    Apr 5, 2017 · In order to use a method's local variable inside a nested class, the variable must either be either final or "effectively final", where the latter means that the compiler can prove that that the …

  8. How do I create a static local variable in Java? - Stack Overflow

    Jan 17, 2010 · Although Java doesn't support static local variables, it's fairly easy to emulate in recent versions of Java. From Java 16 onwards, it is possible to create a local class with a mutable static …

  9. java - Difference between final and effectively final - Stack Overflow

    Jan 6, 2014 · A local variable initialized with a constant is not a constant expression to the compiler. You cannot use such a variable for a case in a switch/case until you explicitly add the final keyword.

  10. java - What is the difference between a local variable, an instance ...

    Dec 18, 2013 · What is the difference between a local variable, an instance field, an input parameter, and a class field with respect to a simple Java program?