Course Content
Keywords
Operators
Loops
String
Array
Object Oriented Principle
Memory Management
Collection Framework
Exception Handling
Reflection API
Multi Threading
File Handling
Java Version wise Questions
Java Scenario Based Interview Questions
About Lesson
Scenario: You are working on a legacy codebase that uses a mix of primitive types and wrapper classes. How would you decide when to use a primitive type versus a wrapper class? Provide examples.

 

Expected Answer:

  • Use primitive types for performance-critical applications where memory and speed are important (e.g., intdouble).
  • Use wrapper classes (e.g., IntegerDouble) when you need to use collections (e.g., ArrayList), handle null values, or leverage object-oriented features like polymorphism.

 

Example:

int primitiveInt = 10; // Primitive type
Integer wrapperInt = 10; // Wrapper class