Android Interview Questions Series — Part I — Core Java, Multithreading and Kotlin

Abhishek Jain
Tech Insider
Published in
7 min readJul 22, 2020

I am sharing questions from my personal interview experiences for the Android dev role in this series.

Part II Link Android Interview Questions Series — Part II — Android, Dagger

Java Basics + Oops

  1. What is object-oriented programming? : It is a computer programming model that organizes software design around data, or objects, rather than functions and logic.OOP concepts in Java are the main ideas behind Java’s oop. They are an abstraction, encapsulation, inheritance, and polymorphism.
  2. SOLID Principles
  3. What is the purpose of the default constructor?: To initialize an object, The compiler implicitly adds a default constructor in the program if we have not declared or defined it.
  4. Restrictions on static methods, can we override static methods? link
  5. Static block vs init{} block (static, init & constructor calls order): The static block is only loaded when the class object is created by the JVM for the 1st time whereas init {} block is loaded every time class object is created. Also first the static block is loaded then the init block.
  6. Java Object class (Methods of Object class): Every class in Java is directly or indirectly derived from the Object class. If a class does not extend any other class then it is a direct child class of Object and if extends other class then it is indirectly derived.
  7. This keyword in java, Uses of this keyword, constructor chaining be done using this keyword: It is a reference variable that refers to the current object
  8. What is Inheritance and Why is multiple inheritance not supported in java? : Java supports multiple inheritance through interfaces only. A class can implement any number of interfaces but can extend only one class. Multiple inheritance is not supported because it leads to the deadly diamond problem
  9. Runtime and Compile time polymorphism, method overloading vs method overriding
  10. Static vs Dynamic Binding in java
  11. Class variable vs object variables
  12. Association, Aggregation & Composition
  13. Explain super in java and constructor chaining using super keyword
  14. this Vs super : super refers immediate parent class instance, this() — refers current class instance.
  15. Can we use this() and super() both in a constructor
  16. Final keyword and its restrictions (final variable cannot be overridden, final class cannot be inherited ): final variable — to create a constant variable, final method — to prevent override, final class to prevent inheritance
  17. Abstract class vs Interface in Java
  18. Write Immutable class in Java: make class final and all its member variable final
  19. *Write Singleton class in java (thread-safe, reflection proof, clone proof, serialization proof)*imp*
  20. what is object cloning?: The object cloning is a way to create an exact copy of an object. For this purpose, the clone() method of an object class is used to clone an object.
  21. Shallow copy Vs deep Copy in Java
  22. Marker Interface in java: It is an interface that has no abstract method eg — serializable, clonable)
  23. Functional Interface in Java: It is an interface that contains only one abstract method. They can have only one functionality to exhibit (eg — Runnable, comparable)
  24. Explain Java String Pool (equals and == operations on strings)
  25. String Builder vs String Buffer
  26. Explain some common Design patternsFactory pattern, Singleton pattern, Builder pattern, Observer pattern, etc.
  27. What is Exception Handling, Exception vs Error, a checked and unchecked exception?
  28. What is the base class for Error and Exception
  29. Explain final, finally and finalize in Java: Throwable
  30. What is the purpose of the finalize method? : It is a method that the Garbage Collector always calls just before the deletion/destroying the object which is eligible for Garbage Collection
  31. What is the difference between throw and throws
  32. What is Garbage Collector (GC)? how to invoke GC? System.gc(); Requesting JVM to call Garbage Collector method
  33. What is Serialization in java? : writing state of an object in bytes stream, We must have to implement the Serializable interface for serializing the object
  34. What is the transient keyword in serialization? : If you define any data member as transient, it will not be serialized.
  35. What is the reflection API? : Reflection is an API that is used to examine or modify the behavior of methods, classes, interfaces at runtime.

Multi-Threading

  1. What is a thread? Thread vs process? Thread lifecycle
  2. wait() vs sleep() method? Differentiate between the Thread class and Runnable interface for creating a thread?
  3. What does join() method do? : It will put the current thread on wait until the thread on which it is called is dead.
  4. Thread’s run() vs start() method
  5. Deamon threads? It is a low priority thread that runs in the background to perform tasks such as garbage collection.
  6. What is a synchronization block and concurrency in java? : synchronization is a good way to achieve mutual exclusion on shared resource
  7. Inter Thread communication in Java
  8. What is the difference between notify() & notifyAll()?: notify() and notifyAll() methods with wait() method are used for communication between the threads. We can use notify() method to give the notification for only one thread which is waiting for a particular object whereas by the help of notifyAll() methods we can give the notification to all waiting threads of a particular object
  9. Thread pool, volatile keyword and Thread safety in java: A thread pool reuses previously created threads to execute current tasks, volatile is yet another way (like synchronized, atomic wrapper) of making class thread-safe, volatile is used to mark a Java variable as “being stored in main memory”
  10. What are the Executor interface and Blocking queue
  11. Build Your own ExecutorService
  12. Implement producer-consumer problem in Java
  13. Callable and Future in Java, future task in java, Callable vs Runnable: for a Callable, the call() method needs to be implemented which returns a result on completion FutureTask implements Runnable and Future, combining both functionalities conveniently.

Collections in Java

  1. Array vs ArrayList in Java
  2. What is the difference between Comparable and Comparator
  3. HashMap vs HashSet, HashMap vs HashTree, HashMap vs HashTable
  4. null keys and null values in HashMap, LinkedHashMap, TreeMap
  5. Iterating a map in java : using keyset() and entryset()
  6. Internal Working of a HashMap

Kotlin

  1. Why use kotlin: Concise, null-safe, interoperable
  2. How does Kotlin work on Android? : Kotlin code is also compiled into the Java bytecode and is executed at runtime by the Java Virtual Machine
  3. Var vs Val: var are mutable variable and val are immutable
  4. Val vs const: Both are immutable but const value must be known at compile time
  5. How to ensure null safety in Kotlin? and what is safe call operator (?)
  6. Difference between safe call (?) and null check (!!)
  7. Elvis operator in Kotlin (?:): When we have a nullable reference b, we can say "if b is not null (val l = b?.length ?: -1)
  8. What is the use of @JvmStatic, @JvmOverloads, and @JvmFiled in Kotlin? : Kotlin code can be easily called from Java. For example, instances of a Kotlin class can be seamlessly created and operated in Java methods.Refer
  9. What is a data class in Kotlin?:A data class is a class that only contains state and does not perform any operation.When you declare a data class, the compiler automatically generates several functions such as toString(), equals(), hashcode() etc behind the scenes.
  10. What is lateinit keyword in kotlin: It is late initialization, it can be checked using isInitialized method
  11. Lateinit vs Lazy
  12. What are companion object in kotlin : A companion object is initialized when the class is loaded. If you need to write a function that can be called without having a class instance but needs access to the internals of a class, you can write it as a member of a companion object declaration inside that class. By declaring a companion object inside our class, you’ll be able to call its members with the same syntax as calling static methods in Java, using only the class name as a qualifier.
  13. What are init blocks in Kotlin?: The primary constructor cannot contain any code therefore init blocks allow adding code to the primary constructor.
  14. What is the open keyword in Kotlin used for?: the functions and the variables are final in nature by default i.e. they can’t be inherited from any other class. So, to make it inheritable from other classes, we use the open keyword with the class, function, and variable name
  15. What are extension functions in Kotlin?: Kotlin provides the ability to extend a class with new functionality without having to inherit from the class or use design patterns such as Decorator. This is done via special declarations called extensions.
  16. What is an inline function in Kotlin?: In Kotlin, the higher-order functions or lambda expressions, all stored as an object so memory allocation, for both function objects and classes, and virtual calls might introduce runtime overhead. In order to reduce the memory overhead of such higher-order functions or lambda expression, we can use the inline keyword which ultimately requests the compiler to not allocate memory and simply copy the inlined code of that function at the calling place.
  17. Explain Scoped Functions in Kotlin — let, run, with, also, apply
  18. Sealed Class: Sealed classes are used for representing restricted class hierarchies, when a value can have one of the types from a limited set, but cannot have any other type. They are, in a sense, an extension of enum classes
  19. Property Delegation in kotlin

Part II Link — Android Interview Questions Series — Part II — Android, Dagger

References: Geeks for Geeks, Tutorials Point and, StackOverflow, Wikipedia, Edureka,MindOrks

--

--

Abhishek Jain
Tech Insider

Android dev | Software developer at InMobi, Ex- MMT, Tokopedia