0
0
Javaprogramming~15 mins

Autoboxing in Java - Practice Problems & Coding Challenges

Choose your learning style8 modes available
trophyChallenge - 5 Problems
🎖️
Autoboxing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 code output
intermediate
2:00remaining
What is the output of autoboxing with == operator?
Consider the following Java code snippet. What will be printed when it runs?
Java
Integer a = 1000;
Integer b = 1000;
System.out.println(a == b);
ARuntime exception
Btrue
CCompilation error
Dfalse
Attempts:
2 left
💻 code output
intermediate
2:00remaining
What is the output when adding Integer and int?
What will the following Java code print?
Java
Integer x = 5;
int y = 10;
System.out.println(x + y);
A15.0
B15
CCompilation error
DNullPointerException
Attempts:
2 left
🔧 debug
advanced
2:00remaining
Why does this code throw NullPointerException?
Examine the code below. Why does it throw a NullPointerException at runtime?
Java
Integer a = null;
int b = a;
System.out.println(b);
ABecause Integer cannot be assigned to int
BBecause variable a is not initialized
CBecause unboxing null Integer to int causes NullPointerException
DBecause printing int b is invalid
Attempts:
2 left
🧠 conceptual
advanced
2:00remaining
How does autoboxing affect performance?
Which statement best describes the performance impact of autoboxing in Java?
AAutoboxing can cause performance overhead due to object creation and garbage collection
BAutoboxing always improves performance by caching objects
CAutoboxing has no impact on performance
DAutoboxing reduces memory usage by using primitives only
Attempts:
2 left
💻 code output
expert
2:00remaining
What is the output of this tricky autoboxing and caching code?
Analyze the code below and select the output it produces.
Java
Integer i1 = 127;
Integer i2 = 127;
Integer i3 = 128;
Integer i4 = 128;
System.out.println(i1 == i2);
System.out.println(i3 == i4);
A
true
false
B
false
false
C
true
true
D
false
true
Attempts:
2 left