I think I probably failed.
It was only 45 minutes. The interviewer said they were hiring for just one opening.
- Questions about my projects. His wording was really vague; he did not ask clear questions, and he did not seem very interested in me either.
He asked about service communication protocols with the client side, and scalability.
- Coding
He gave me three code snippets.
public class Numeric {
public static void main(String[] args) {
double a = 0.9 - 0.8;
double b = 0.8 - 0.7;
System.out.println((float) a); // 0.1
System.out.println((float) b); // 0.1
System.out.println(a == b); // false
System.out.println(a == b);
}
}
What gets printed?
How would you fix it to make a equal b?
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Objects;
class Point {
int x, y;
Point(int x, int y) { this.x = x; this.y = y; }
@Override
public int hashCode() {
return Objects.hash(x, y);
}
@Override
public boolean equals(Object o) {
if (!(o instanceof Point)) return false;
Point p = (Point) o;
return x == p.x && y == p.y;
}
@Override
public String toString() {
return "(" + x + ", " + y + ")";
}
}
public class PointTest {
public static void main(String[] args) {
Collection<Point> set = new HashSet<>();
Collection<Point> list = new ArrayList<>();
Point p = new Point(1, 1);
set.add(p);
list.add(p);
System.out.println(set.contains(p)); // true
System.out.println(list.contains(p)); // true
p.x = 2;
Point p2 = new Point(2, 1);
System.out.println(set.contains(p2)); // true
System.out.println(set.contains(p)); // true
System.out.println(list.contains(p)); // true
set.remove(p);
System.out.println(set); // {}
}
}
What gets printed?
After changing a value and adding a new object, what gets printed?
import java.util.HashMap;
import java.util.Map;
public class SessionCache {
static boolean stopped;
static class Key {
Integer id;
Key(Integer id) { this.id = id; }
@Override public int hashCode() { return id.hashCode(); }
}
public static void main(String[] args) {
Map<Key, String> cache = new HashMap<>();
new Thread(() -> {
try {
Thread.sleep(24 * 60 * 60 * 1000);
stopped = true;
} catch (Exception e) {
} finally {
stopped = true;
}
}).start();;
int i = 1;
while (!stopped) {
cache.put(new Key(i % 5000), "DATA" + i);
i++;
}
}
// max / min value of key.id
// num elements in the cache
// how ling this program runs
}
Discussion
Loading comments…