VHow does a HashMap work, and when would you not use one?
Sentido de la respuesta✓
Idioma2
Pregunta del entrevistadorDesarrollador Java
En las entrevistas para puestos de Java suelen empezar por el lenguaje base y las colecciones, y después pasan a la concurrencia, Spring y el diseño. Una explicación oral clara de lo básico suele valer más que un detalle exótico, porque demuestra que entiendes por qué funciona el código.
Practica cada respuesta en tres pasos: una definición corta, cómo funciona y cuándo importa en un proyecto real. Ese orden evita que te enrolles y le da al entrevistador un punto fácil para hacer una pregunta de seguimiento.
- ✓Palabras → expresiones → frases → conversación
- ✓Sentido de la respuesta
- ✓Idioma
Preguntas habituales y respuestas de ejemplo
How does a HashMap work, and when would you not use one?
¿Cómo funciona un HashMap y cuándo no lo usarías?
Qué quiere oír el entrevistador. El mecanismo (hash, bucket, colisiones, redimensionado), la complejidad y los límites: no mantiene el orden y no es seguro entre hilos.
Respuesta de ejemplo en inglés para practicar en voz altaA HashMap stores entries in an array of buckets. It calls hashCode on the key, turns that into an index and puts the entry in that bucket. If two keys land in the same bucket, they are kept in a list, and in modern Java a long list becomes a tree. When the map is more than 75 percent full, it doubles the array and redistributes the entries. Get and put are O(1) on average. I would not use it when I need ordering, so I choose LinkedHashMap or TreeMap, or when several threads write at the same time, where ConcurrentHashMap is the right choice.
What is the contract between equals and hashCode?
¿Cuál es el contrato entre equals y hashCode?
Qué quiere oír el entrevistador. La regla en sí y el error que aparece cuando se incumple.
Respuesta de ejemplo en inglés para practicar en voz altaIf two objects are equal according to equals, they must return the same hashCode. The opposite is not required: different objects may share a hash code. If I override equals but forget hashCode, hash-based collections stop working correctly. For example, I put an object in a HashSet, then create an equal object and call contains, and the result is false, because the second object looks in a different bucket. I also try to base both methods on immutable fields, so the hash code does not change while the object is inside a collection.
What is the difference between ArrayList and LinkedList?
¿Cuál es la diferencia entre ArrayList y LinkedList?
Qué quiere oír el entrevistador. La complejidad, el uso de memoria y una recomendación práctica, no solo la tabla del libro de texto.
Respuesta de ejemplo en inglés para practicar en voz altaArrayList is backed by an array, so reading by index is O(1), and adding to the end is O(1) amortised. Inserting in the middle is O(n), because elements must shift. LinkedList stores nodes with links, so inserting or removing at a known node is fast, but reading by index is O(n), and every element uses more memory. In practice I almost always use ArrayList, because arrays work well with the processor cache. If I need a queue or a stack, I choose ArrayDeque instead of LinkedList.
Why is String immutable in Java?
¿Por qué String es inmutable en Java?
Qué quiere oír el entrevistador. Varias ventajas y al menos una consecuencia práctica, como StringBuilder.
Respuesta de ejemplo en inglés para practicar en voz altaOnce a String is created, its content cannot change. This gives us a few benefits. Strings are thread-safe without any locks. They can be used safely as HashMap keys, and the hash code can be cached. The JVM can also reuse equal strings from the string pool to save memory, and values like file paths cannot be changed after they have been checked. The price is that concatenation in a loop creates many objects, so for that case I use StringBuilder.
What is the difference between checked and unchecked exceptions?
¿Cuál es la diferencia entre las excepciones comprobadas (checked) y las no comprobadas (unchecked)?
Qué quiere oír el entrevistador. Las reglas del compilador, cuándo usar cada tipo y qué prefiere tu equipo.
Respuesta de ejemplo en inglés para practicar en voz altaChecked exceptions extend Exception but not RuntimeException. The compiler forces you to catch them or declare them. Unchecked exceptions extend RuntimeException, and the compiler does not check them. Checked exceptions are meant for situations the caller can reasonably recover from, like a missing file. Unchecked ones usually mean a programming error, like a null pointer. In modern projects, especially with Spring, many teams prefer unchecked exceptions, because checked ones make method signatures noisy. What matters is to be consistent and never to swallow an exception silently.
Cómo pronunciar los términos clave
- Java
- dyá-va
- hashCode
- jásh-cod
- immutable
- i-miú-ta-bol
- queue
- kiu
- amortised
- ám-or-taisd
- iterator
- í-te-rei-ter
Frases útiles para responder
- Let me explain how it works step by step.Déjame explicar cómo funciona paso a paso.
- The main idea is…La idea principal es…
- In practice, I usually…En la práctica, normalmente…
- The trade-off here is…El trade-off aquí es…
- That depends on the use case.Eso depende del caso de uso.
- I haven't used that in production, but as far as I know…No lo he usado en producción, pero que yo sepa…
- Under the hood, it…Internamente, lo que hace es…
Errores habituales que debes evitar
- Decir «depende» y quedarte ahí. Explica de qué depende y da un ejemplo para cada lado.
- Recitar una definición sin ejemplo. Añade una frase del trabajo real: "In our service we used…"
- Pronunciar mal términos básicos como queue, cache o thread. Los entrevistadores perdonan el acento, pero una palabra clave poco clara hace que toda la respuesta sea difícil de seguir.
- Fingir que sabes. "I have not worked with that, but I would start by…" es una respuesta más sólida que una conjetura.
Preguntas frecuentes
¿Necesito conocer las novedades de Java 21 para una entrevista?
Para la mayoría de los puestos, a nivel básico, sí. Los records, las clases selladas (sealed classes), el pattern matching y los hilos virtuales son temas de seguimiento habituales. Prepárate para decir qué versión usó tu último proyecto y qué te gustó de las más nuevas.
¿Tendré que escribir código o solo hablar?
A menudo, las dos cosas. Di lo que haces mientras escribes: "First I will handle the empty input, then…" Hablar mientras programas es una habilidad que hay que practicar, porque la mayoría de los desarrolladores programan en silencio.
¿Cómo me preparo si mi inglés es más flojo que mi Java?
Elige entre 15 y 20 temas básicos y di cada uno en voz alta, en inglés, varias veces. Grábate, revisa los términos clave y concéntrate en la estructura más que en una gramática perfecta.
Leer una respuesta no es lo mismo que decirla. Practica cada pregunta en voz alta y después compara el sentido y el idioma de tu propia respuesta.
Probar SpeakRole ↗