JavaIntermediate#spring

What are Spring bean scopes?

Singleton (default, one instance per container), prototype (new instance every request), request/session/application (web-aware scopes tied to HTTP lifecycle). Choosing the right scope avoids state leakage between requests.

Example
@Component
@Scope("prototype")
class ShoppingCart {} // new instance created each time it's requested

Related Questions

1
JavaIntermediate#puzzle#operators

What does this print? int x = 5; System.out.println(x++ + ++x);

Open
2
JavaBeginner#puzzle#strings

What is the output of this code? String s1 = "abc"; String s2 = "abc"; String s3 = new String("abc"); System.out.println(s1 == s2); System.out.println(s1 == s3);

Open
3
JavaAdvanced#puzzle#exceptions

What does this code output and why? try { return 1; } finally { return 2; }

Open