Technical interview questions for software engineer

Index


Java

  1. Please explain about HashMap and how it works. 2~3min
    • definition
      • HashMap is Java Collections Framework API and also implemented Map interface.
      • Basically it is key value map. And value is saved on bucket.
      • Compare with list, HashMap performance is faster as O(1) for searching.
      • We need to provide an implementation for equals() and hashCode() method to work properly.
    • hashCode
      • HashMap uses hashCode method to determine the bucket which the value will be stored.
      • pros : whatever key types(Integer, String, Object), hashCode provides standard results.
      • cons : hashCode return type is int. If number of keys is more than int range, collision occur
    • collision
      • collision happens when differen keys have same hashCode result
      • HashMap uses ‘separate chaining’ structure as linked list to resolve collision.
  2. Please explain why equals and hashCode method override is required.
    • It is necessary to do override because equals method return false when same value but different object case. Same for hashCode method.
  3. Please explain what is difference between ‘==’(equality operator) and ‘equals method’
    • ’==’(equality operator) is only check referencing same memory address.
    • But we can override ‘equals method’ that checking referencing same memory address, on top of that checking internal value if referring different memory address case.
    • And also when we override ‘equals method’, we need to override hashCode as well for same reason. Because hashCode generates different value each by memory address.
  4. TBD

Spring

  1. Please explain about Dependency injection. 3~5min
    • Definition
      • Dependency injection is a design pattern that an object receives other objects dependency.
      • By using depdendency injection, we can achieve that separate constructing objects and using them.
    • Role
      • Dependency injection involves 4 roles : services, clients, interfaces and injectors.
      • Services and clients
        • A service is any class which contains functionality.
        • In turn, a client is any class which uses services.
    • Advantage
      1. First, a basic benefit of dependency injection is separate constructing objects and using objects. By this, it is decreased coupling between classes and their dependencies. So that programs become more reusable, testable and maintainable.
      2. Second, dependency injection reduces boilerplate code, since all dependency creation is handled by a single component.
    • Disadvantage
      • First, makes code difficult to trace because it separates behavior from construction.
    • Types of dependency injection
      1. Constructor injection - where dependencies are provided through a client’s class constructor
      2. Setter injection - where the client exposes a setter method which accepts the dependency.
      3. Interface injection - where the dependency’s interface provides an injector method that will inject the dependency into any client passed to it.