About 157,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 …

  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 …

  3. Variable default value in Java - Stack Overflow

    Jan 7, 2021 · 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 …

  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 - 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 …

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

    Apr 5, 2017 · 2 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 …

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

    Jan 17, 2010 · From Java 16 onwards, it is possible to create a local class with a mutable static field in a method. Subsequently, you mutate the local class's static field just like you would in …

  8. What happens to a declared, uninitialized variable in Java?

    Aug 22, 2016 · Local variables are slightly different; the compiler never assigns a default value to an uninitialized local variable. If you cannot initialize your local variable where it is declared, …

  9. java - Default values of local variables - Stack Overflow

    Aug 18, 2013 · The local variables are not initialized to default values, as in the case of class variables. The same applies to primitives and object references. JavaDoc (Section 4.12.5. …

  10. java - Variable used in lambda expression should be final or ...

    Jan 19, 2016 · Hence to the need to make local variable final if it’s not changed once it is initialized as lambda in itself is nothing but an anonymous class. Java 8 realized the pain of …