JavaRush /Java Blog /Random EN /15 technical interview questions for a Java programmer wi...
dio
Level 16
Москва

15 technical interview questions for a Java programmer with 5-6 years of experience

Published in the Random EN group
With the growth of a programmer's experience from the level of a novice developer (from 2 to 4 years of work experience) to the level of a senior developer (from 5 to 7 years), the interview questions on Core Java also change. 15 technical interview questions for a Java programmer with 5-6 years of experience - 1Of course, basics such as data structures, algorithms and object-oriented programmingremain, but the questions and answers become more detailed. I often get questions about what Core Java questions are asked to senior developers, or what questions to expect in an interview for a senior Java developer position. This puzzles me for a while, as once you become a senior developer you will automatically start taking part in interviews and you need to have an idea of ​​what to expect from an interview, but at the same time, I understand that knowing the interview questions, it will be easier for you to prepare for it. Of course, you won't get questions that are asked of programmers with 2-3 years of Java experience, although this is not excluded at the beginning of the interview. I don't see the difference between phone interviews and face to face interviews. Some questions remain the same some questions require more detailed answers. In this article, I will share15 Core Java Technical Questions Asked in Senior Developer Interviews During Phone Interviews. I don't post all the answers, but you can find them on the current blog or the Javarevisited blog .

15 questions on Core Java for programmers with 5-6 development experience

All questions were received from working senior developers with over 5 years of experience. The developers faced these questions at various stages of the hiring process, including phone interviews and face-to-face interviews.
  1. How does a getclass method work HashMapin Java?

    Yes, this is still one of the most popular questions for a senior developer, you should expect it on a phone interview, after it there will probably be many related questions, see the answers to them here .

  2. What 2 methods should the key object implement HashMap?

    equalsAndhashcode

  3. Why do objects used as a key need to be immutable?

    So that the hash code always returns the same value.

  4. What makes it possible to ConcurrentHashMapachieve scalability?

    Sometimes this interview question sounds like: the difference between ConcurrentHashMapand Hashtablein Java, look for answers here .

  5. How to make an object shared between different threads? Or how to pass an object from one thread to another?

    There are many ways to implement this, such as queues, exchangers, but blocking queues with the Producer/Consumer design pattern are the easiest way to pass an object from one thread to another.

  6. How do you know if your program has a deadlock?

    (By getting a thread dump using kill -3 using JConsole or VisualVM). I suggest preparing for this interview question very carefully, because interviewers love details, they ask if there were similar problems in your project and how you managed to solve them.

  7. How to avoid deadlocks while coding?

    To understand blocking and get full information about the topic, read this .

  8. What is Busy spinning? Why should you use it?

    One of the most interesting topics in multithreading for a senior Java developer, Busy spinning is a waiting strategy, where a thread performs a wait in a loop, while not using processor resources and, as it were, falling asleep . This strategy is used when the waiting time is very short, while the processor is not loaded and the thread is not stopped, all data that can be lost when the thread starts on another processor core is saved. This question is popular among programmers who create high-load projects, where programmers achieve extremely low latency in work, in the range of micro- and milli-seconds.

  9. What is a Read/Write ( ReadWriteLock) lock? Does it use ConcurrentHashMap ReadWritelocks?

    A Read/Write lock is an implementation of a lock where multiple threads attempt to perform a read/write operation on the same object. the read operation itself does not modify the object, which allows multi-threaded read operations without locks. Java provides an implementation ReadWriteLockworth reading. For example , ConcurrentHashMapit does not apply ReadWriteLock, instead it divides Hashinto separate parts and blocks them separately, so at any given time only part of the hash is blocked, and not all of it. This question is popular with experienced developers, usually asking for more details, asking for different implementations of ReadWriteLock for different cases.

  10. How to make an object immutable (not mutable) in Java? Why make an object immutable?

    Immutability offers several benefits including thread safety, cacheability, and makes multithreaded code more readable.

    Watch this and learn how to make objects immutable. At the interview on this issue, additional clarifications are possible, depending on the completeness of your answer. For example, when you say that Spring is immutable, be prepared to answer why strings are also immutable in Java.

  11. What design patterns do you use?

    Always expect a question about design patterns in a senior developer job interview. It is better to mark any GOF pattern, and not Singleton or MVC which is used by every second Java programmer. A better answer might be the Decorator pattern or the Dependency Injection pattern , which are quite popular in the Spring Framework. It is also good if you actually used the design patterns you call and know what compromise their application leads to. As soon as you say the name of the design pattern, for example: "Factory", the interviewer will immediately ask: "Have you used this in your projects?" Therefore, be prepared to give examples and tell why you chose this particular template in your project.

  12. Do you know about the Open/Closed Principle or Barbara Liskov's Substitution Principle ?

    Design patterns are based on the principles of object-oriented design.

    I highly recommend checking out my article 10 Object Oriented Design Principles that a Java programmer should know, at least to have an idea of ​​how these principles will help you write object oriented code. If you don't have an answer to this question, you can politely answer "no", no one expects you to know the answers to all questions. However, knowing the answer to a question that most developers struggle with makes you a very strong candidate for an interview.

  13. What design pattern will you use to protect your code from a third party library that will be replaced in a couple of years?

    This is just one of the possible variations of the question about design patterns that you may be asked depending on what you are talking about now in the interview. One way to shield your code from a third party library is to depend on the interface rather than the implementation and use dependencies to provide a concrete implementation. Similar questions are often asked to senior developers with 5-7 years of experience.

  14. How to prevent SQL injection in Java code?

    This question is asked more often by Java EE developers than by regular Java programmers, but it's still a great way to learn about PreparedStatement. PreparedStatement is an object that represents a precompiled SQL statement. PreparedStatement not only provides better performance, but also protects against SQL injection. If you work mostly with Java EE or J2EE, you should be familiar with some security issues, including the "Session Fixation attack" or "cross-site scripting", and you should be able to avoid these attacks.

  15. Can you tell us about the difference between reference types in Java such as WeakReference, SoftReference and PhantomReference? And why should you use them?

    In fact, there is only one difference between all types of links - the behavior of the Java Garbage Collector with the objects they refer to. In Java, objects created with the new operator are created with a strong reference. The garbage collector (garbage collector) destroys such objects only when there are no more strong references to them. The java.lang.ref package has 3 classes that describe 3 types of links, respectively SoftReference, WeakReference, PhantomReference. Objects created via SoftReference will be collected in case the JVM needs memory. That is, there is a guarantee that all SoftReference objects will be collected before the JVM throws an OutOfMemoryError exception. SoftReference is often used for caches that consume a lot of memory. WeakReference does not save object from finalization, even if there is enough free memory. As soon as there are no strong and soft references left on the object, it can be finalized. Used for caches and for creating chains of related objects. Objects created via PhantomReference are destroyed when the GC determines that the referenced objects can be freed. This link type is used as an alternative to finalization (for more flexible release of resources).

    This is the entire list of interview questions for a senior Java developer. I didn't include many important questions about exception handling, garbage collector, JVM tuning that are very popular with senior developers, maybe I will include them in the next part. But if you don't find answers to any of the questions, let me know and I'll update this post for my regular readers.

Original article: 15 Technical Core Java Interview Questions Answers for Experienced Developers
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION