VHow does a HashMap work, and when would you not use one?
سؤال المقابلمطوّر Java
يبدأ المحاورون في وظائف Java عادةً بأساسيات اللغة والمجموعات (collections)، ثم ينتقلون إلى التزامن (concurrency) وإطار Spring والتصميم. والشرح الشفهي الواضح للأساسيات يهم في الغالب أكثر من تفصيلة غريبة، لأنه يدل على أنك تفهم لماذا يعمل الكود.
تدرّب على شرح كل إجابة في ثلاث خطوات: تعريف قصير، ثم كيف يعمل الشيء، ثم متى يهم في مشروع حقيقي. هذا الترتيب يمنعك من الاسترسال، ويمنح المحاور موضعًا سهلًا لطرح سؤال متابعة.
- ✓كلمات → عبارات → جمل → تحدث
- ✓معنى الإجابة
- ✓اللغة
أكثر الأسئلة تكرارًا ونماذج الإجابات
How does a HashMap work, and when would you not use one?
كيف تعمل HashMap، ومتى لا تستخدمها؟
ما الذي يريد المحاور سماعه. الآلية (التجزئة، والسلة، والتصادمات، وتوسيع الحجم)، والتعقيد الزمني، والحدود: لا ترتيب ولا أمان في بيئة تعدد الخيوط.
نموذج إجابة بالإنجليزية للتدرّب عليه بصوت عالٍA 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?
ما العقد بين equals وhashCode؟
ما الذي يريد المحاور سماعه. القاعدة نفسها، والخطأ الذي يظهر في البرنامج عند مخالفتها.
نموذج إجابة بالإنجليزية للتدرّب عليه بصوت عالٍIf 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?
ما الفرق بين ArrayList وLinkedList؟
ما الذي يريد المحاور سماعه. تعقيد العمليات واستهلاك الذاكرة وتوصية عملية، لا الجدول الدراسي وحده.
نموذج إجابة بالإنجليزية للتدرّب عليه بصوت عالٍArrayList 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?
لماذا يكون String في Java غير قابل للتغيير (immutable)؟
ما الذي يريد المحاور سماعه. عدة فوائد ونتيجة عملية واحدة على الأقل، مثل استخدام StringBuilder.
نموذج إجابة بالإنجليزية للتدرّب عليه بصوت عالٍOnce 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?
ما الفرق بين الاستثناءات المفحوصة (checked) وغير المفحوصة (unchecked)؟
ما الذي يريد المحاور سماعه. قواعد المترجم (compiler)، ومتى تستخدم كل نوع، وما الذي يفضّله فريقك.
نموذج إجابة بالإنجليزية للتدرّب عليه بصوت عالٍChecked 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.
كيف تنطق المصطلحات الأساسية
- Java
- جَافَا
- hashCode
- هَاشْ كُود
- immutable
- إِمْيُوتَبِل
- queue
- كْيُو
- amortised
- أَمُرْتَايزْد
- iterator
- إِتِرَيْتِر
عبارات مفيدة للإجابة
- Let me explain how it works step by step.دعني أشرح كيف يعمل ذلك خطوة بخطوة.
- The main idea is…الفكرة الأساسية هي…
- In practice, I usually…من الناحية العملية، أقوم عادةً بـ…
- The trade-off here is…المفاضلة هنا هي…
- That depends on the use case.هذا يعتمد على حالة الاستخدام.
- I haven't used that in production, but as far as I know…لم أستخدم ذلك في بيئة الإنتاج، لكن بحسب علمي…
- Under the hood, it…خلف الكواليس، يقوم ذلك بـ…
أخطاء شائعة
- قول «هذا يعتمد» ثم التوقف. وضّح على ماذا يعتمد، وأعطِ مثالًا لكل حالة.
- ترديد التعريف من دون مثال. أضف جملة واحدة من العمل الحقيقي: "In our service we used…"
- نطق المصطلحات الأساسية بشكل خاطئ، مثل queue أو cache أو thread. يتسامح المحاورون مع اللكنة، لكن كلمة مفتاحية غير واضحة تجعل الإجابة كلها صعبة المتابعة.
- التظاهر بالمعرفة. عبارة "I have not worked with that, but I would start by…" إجابة أقوى من التخمين.
الأسئلة الشائعة
هل أحتاج إلى معرفة ميزات Java 21 في المقابلة؟
في معظم الوظائف نعم، على مستوى أساسي. تُطرح كثيرًا في أسئلة المتابعة مواضيع مثل السجلات (records) والفئات المختومة (sealed classes) ومطابقة الأنماط (pattern matching) والخيوط الافتراضية (virtual threads). كن مستعدًا لتقول أي إصدار استخدمه مشروعك الأخير وما أعجبك في الإصدارات الأحدث.
هل سأكتب كودًا أم سأتحدث فقط؟
غالبًا الأمران معًا. قل ما تفعله أثناء الكتابة: "First I will handle the empty input, then…" الحديث أثناء البرمجة مهارة تحتاج إلى تدريب، لأن معظم المطورين يبرمجون بصمت.
كيف أستعد إذا كانت إنجليزيتي أضعف من Java؟
اختر من 15 إلى 20 موضوعًا أساسيًا وانطق كل واحد منها بصوت عالٍ بالإنجليزية عدة مرات. سجّل صوتك وراجع المصطلحات الأساسية، وركّز على البنية لا على القواعد النحوية المثالية.
قراءة الإجابة ليست مثل قولها. تدرّب على كل سؤال بصوت عالٍ، ثم قارن معنى إجابتك ولغتها بالنموذج.
جرّب SpeakRole ↗موضوعات أخرى في هذا المجال