Resources
Legal
Prepare for interviews with a database of questions from real interviews.
Showing 21–40 of 41
Fields address and phone are public. Why are public fields disliked in Java? What really changes when switching to private + getter/setter?
What is the difference between WHERE and HAVING?
Wildcard import (import java.io.*) — what do you think about this?
What is a lambda expression?
Is there a constructor in an abstract class?
Question to the interviewer: Is there a synchronization mechanism between the Lucene index and the main SQL storage? How is consistency addressed?
// ... some code here? private static List<DocumentProvider> getDocumentProviders() { Reflections reflections = new Reflections(Main.class.getProtectionDomain().getCodeSource().getLocation()); Set<Class<?>> subTypes = reflections.get(SubTypes.of(DocumentProvider.class).asClass()); return subTypes.stream().map(subType -> { try { return (DocumentProvider) subType.getConstructor().newInstance(); } catch (Exception ex) { throw new RuntimeException(ex); } }).collect(Collectors.toList()); }
How to get the only element from a List? How to get the only element from a Set if get(0) is not available?
What Stream API collectors do you know? What does groupingBy return? How does it differ from toMap? How does toMap behave with duplicate keys?
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlType; import java.io.*; @XmlAccessorType(XmlAccessType.PROPERTY) @XmlType(name = "Person", propOrder = { "name", "surname", "address", "phone", }) public class Person implements Serializable, Externalizable { private String name; private String surname; public String address; public String phone; public Person(String name, String surname) { this.name = name; this.surname = surname; } public String getName() { return name; } public String getSurname() { return surname; } @Override public int hashCode() { return 1; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Person person = (Person) o; if (name != null ? !name.equals(person.name) : person.name != null) { return false; } if (surname != null ? !surname.equals(person.surname) : person.surname != null) { return false; } return true; } @Override public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(name); out.writeObject(surname); out.writeObject(phone); out.writeObject(address); } @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { name = (String) in.readObject(); surname = (String) in.readObject(); address = (String) in.readObject(); phone = (String) in.readObject(); } }
Have you worked with the clone() method? Do you like handling CloneNotSupportedException through throw new Error()?
What is the complexity of the binary search algorithm O?
// ... call test code here? // ... some code here?
What collection framework interfaces do you know? What common parent do List, Set, Queue, Map have?
// ... some code here?
What is a predicate in Java?
What is findFirst() and a terminal operation in the Stream API?
How does Entity Graph differ from JOIN FETCH?
What integrations with Kafka have you worked on? How did you interact with the broker?
When should you use ArrayList and when LinkedList?