Skip to content

niharika2810/android-interview-questions

Repository files navigation

Android-Interview-Questions

interview

A repository containing interview questions on DS, Java & Android based on my experiences.

Note: I am not writing up the answers here for now as If I provide you the answers, what will you do? :-)

Also, you will restrict yourself to those answers only. Try and learn more deeply abut the concepts. For any particular questions, You can ask anytime.

DS

  1. https://www.geeksforgeeks.org/find-minimum-element-in-a-sorted-and-rotated-array/

  2. https://www.geeksforgeeks.org/largest-subarray-with-equal-number-of-0s-and-1s//

  3. https://www.geeksforgeeks.org/find-triplets-array-whose-sum-equal-zero/

  4. https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/

  5. https://www.geeksforgeeks.org/construct-tree-from-given-inorder-and-preorder-traversal/

  6. https://www.geeksforgeeks.org/write-an-efficient-c-function-to-convert-a-tree-into-its-mirror-tree/

  7. https://www.geeksforgeeks.org/maximum-sum-such-that-no-two-elements-are-adjacent/

  8. https://www.geeksforgeeks.org/longest-common-subarray-in-the-given-two-arrays/?ref=leftbar-rightbar

  9. https://www.geeksforgeeks.org/maximum-sum-path-across-two-arrays/

  10. https://www.geeksforgeeks.org/merge-two-sorted-arrays-o1-extra-space/

  11. https://www.geeksforgeeks.org/segregate-0s-and-1s-in-an-array-by-traversing-array-once/

  12. https://www.geeksforgeeks.org/construction-of-longest-monotonically-increasing-subsequence-n-log-n/

  13. https://www.geeksforgeeks.org/kth-smallestlargest-element-unsorted-array/

  14. https://www.geeksforgeeks.org/find-zeroes-to-be-flipped-so-that-number-of-consecutive-1s-is-maximized/

  15. https://www.geeksforgeeks.org/reverse-a-doubly-linked-list/

  16. https://www.geeksforgeeks.org/longest-common-increasing-subsequence-lcs-lis/

  17. https://www.geeksforgeeks.org/fix-two-swapped-nodes-of-bst/

  18. https://www.geeksforgeeks.org/backttracking-set-2-rat-in-a-maze/

  19. https://www.geeksforgeeks.org/detect-and-remove-loop-in-a-linked-list/

  20. https://www.geeksforgeeks.org/find-minimum-element-in-a-sorted-and-rotated-array/

  21. https://www.geeksforgeeks.org/maximum-product-subarray/

  22. https://www.geeksforgeeks.org/merge-k-sorted-arrays/

  23. https://www.geeksforgeeks.org/sort-an-array-of-0s-1s-and-2s/

  24. https://www.geeksforgeeks.org/a-product-array-puzzle/

  25. https://www.geeksforgeeks.org/count-frequencies-elements-array-o1-extra-space-time/

  26. https://www.geeksforgeeks.org/median-of-two-sorted-arrays-of-different-sizes/

  27. https://www.geeksforgeeks.org/find-maximum-path-sum-in-a-binary-tree/

  28. https://www.geeksforgeeks.org/lowest-common-ancestor-in-a-binary-search-tree/

  29. https://www.geeksforgeeks.org/lowest-common-ancestor-binary-tree-set-1

  30. https://www.geeksforgeeks.org/sorted-linked-list-to-balanced-bst/

  31. https://www.geeksforgeeks.org/given-an-array-a-and-a-number-x-check-for-pair-in-a-with-sum-as-x/

  32. https://www.educative.io/edpresso/how-to-find-the-most-frequent-word-in-an-array-of-strings

  33. Continuation Question to 32, What is the time complexity of your solution and how can you improve it?

  34. What is the time complexity of mergeSort, quickSort and Binary search?

  35. What is the time complexity for removing an element from LinkedList?

Java

  • Interfaces vs Abstract Classes.Why Interfaces if abstract classes are already there.

  • JAVA 8 new features

  • Hashmap implementation,ArrayList implementation

  • How to make a class immutable.

  • String pools,intern keyword,new() keyword

  • Linked list vs Array,Array vs ArrayList,Set vs List vs Map,Iterator vs Enumeration.

  • How to compare two objects in Set?(hint : equals() and hashcode() overriding)

  • How ClickListener implemented in Java?

  • Programs based on Inheritance and multithreading. (Most Important)

  • 1.) Add(String string) 2.) Add (Object object), you called Add(null) what will be the output here?

  • Why main Static?

  • Static vs Singleton? Which to prefer when?

  • Can a static method be overloaded/overridden?Can a constructor be made static? Can we override/overload constructor? Which type of error you get-Compile/Runtime.

  • Can we have final/static/default methods in interface/abstract classes?

  • Check for every keyword? Which type of error-Compile time or runtime(I remember it after I tried a sample in Android studio).

  • Stack vs Heap allocation in Java.

  • Why is String immutable?

  • Why reflection in Java?Introspection vs Reflection?

  • Anonymous vs Inner Classes.Static Inner Classes. Can we have Static inner classes on Top?

  • What is the naming structure for an inner class in java?

  • Default value for Access specifiers,primitie types.

  • Protected vs Default. Do static retain value if an application is removed from recent.

  • How is the Exception class implemented in java?Try/Catch with finally block.

  • Any situation when finally won’t get executed?

  • Is Java pass by value/reference?

  • What will be the result if StringBuffer value compared with String — strbuf.equals(str) /str.equals(strbuf)

  • Synchronization in Java.

  • Can one interface extend/implement other/Can one abstract class extend other? Can interface extend abstract classes?

  • Runtime vs compile time polymorphism with real-world scenarios. How do you define encapsulation?

  • this vs super() keyword

  • Implement own Garbage collection in java.

  • Why runnable interface if we have already had Thread class in Java?

  • Why thread pool in Java?

  • Order of call of constructors during Inheritance.

Kotlin

  • Why should we use Kotlin for Android Development?

  • Kotlin operators - apply, run, let, ?

  • How Kotlin is null-safe?

  • What is the difference between var and val?

  • How const is different from val?

  • What is the difference between ?. and !!

  • How to define static functions in Kotlin?

  • What are Data Classes in Kotlin?

  • What do you mean by Sealed classes in Kotlin?

  • Collections in Kotlin.

  • Difference between lateinit and lazy.

  • What is Kotlin synthetic binding?

  • Difference between Kotlin Synthetics, View binding and Butterknife?

  • What are extension functions in Kotlin?

  • What are lambda expressions?

  • What are Higher-Order functions in Kotlin?

  • Difference between let, run, with, also, apply in Kotlin.

  • What is the best way for performing tasks on a background thread in kotlin?

  • What are Coroutines in Kotlin?

  • What are the different Coroutines Scope?

  • Why use suspend function in Kotlin Coroutines?

  • Explain Coroutine LifecycleScope.

  • What is Kotlin Flow?

  • Kotlin Flow vs RxJava.

  • Room vs Realm? Why not Realm?

Android

(Also they ask for code not just theory things. Keep this in mind.)

  • Activity/Fragment/Broadcast/Application/Service Lifecycle (Explain with one line description)

  • Which lifecycle method gets called when A goes to B/come back to A?
Activity Launch Modes with examples

  • Let’s say 4 activities are there A->B->C->D. How to launch A from D finishing in between activities?

  • 4 Activities are there A->B->C->D.How to finish application from D if none of the activities opened earlier finished till now?

  • How CLEAR_TOP flag intent works in android?

  • Service vs IntentService?When to prefer which type of service?

  • Explain ways for Activity to activity communication/Activity to fragment communication/Fragment to fragment communication.

  • How to make a service persist even after Application killed?

  • How to achieve Interprocess communication in android?

  • How Async task internally works? Async task implementation?

  • Cons of using Async task? How to overcome this limitation?

  • Why Job Scheduler?

  • Notification related changes in Oreo?

  • How to handle Background service and execution limits with new Oreo Updates?

  • Have you seen Google I/O 2018? What were the updates for Android there?

  • Why do we use Headless fragments?

  • Memory Leakage, Causes, and preventions in Android? I have written a blog out here.You can refer this too

  • Ways to optimize an Android Application.

  • Proguard-Obfuscation/ Minification, Build Variants, Flavours.

  • How to achieve MultiThreading in Android?

  • Suppose you have 10 images to fetch from Server. What is the best way to fetch images? (Hint: Read about ThreadPool and Executor)

  • Builder vs Factory Pattern with an example

  • Why MVP not MVC? They will ask you to make a wireframe kind of thing on paper to demonstrate MVP pattern in android.

  • Why RXJAVA so popular nowadays?

  • Problems in RXJAVA? They can provide you with some scenarios to get to know if you can find out the problems with it.

  • Map vs Flat map? (Most commonly asked in RXJAVA)

  • Should we provide a context in presenter/Model? Answering yes/no is not enough. You have to provide a solution for it.

  • Why Schedulers and How Rxjava internally works with them?
SusbcribeOn vs ObserveOn, Schedulers on which both of these work?
.subscribe(new Subscriber…) vs .subscribe(new Observer…)

  • IOScheduler/new Thread Scheduler in RXJava

  • How dagger internally worksDagger vs Dagger2? Explain the purpose of every annotation taken in Dagger2.

  • How do you decide scope in Dagger? Why Qualifier annotation?

  • Why do we use Handlers? Do you know the Loopers? What’s the role of Message queue? With this, they will go for Main Thread working. They will also ask you about the exceptions we get as Looper.prepare() exceptions

  • Cause of Memory leak during the Async Task?

  • Explain Singleton pattern. Problems with it and Handling. (hint: Double checked locking/synchronization)

  • Why do you prefer Retrofit over Volley? Why Picasso? Now they will ask all the third party libraries you have used. Be honest with your answer. They may go deep in any of those.

  • Why ConstraintLayout?Barriers vs Guidelines, Why Group/Chains?

  • Why do we prefer Framelayout for Fragments?

  • Why ANR?How to prevent it?

  • Do async.execute make threads in parallel or serial?

  • How to make a custom view in android? Explain lifecycle methods. Difference between onLayout/onMeasure.

  • Have you ever faced any issue with SingleInstance launch mode or example if you have used it? Providing real-life examples are preferred more.

  • When 1 fragment added over another-Explain lifecycle methods. Another question would be if you replace instead of adding it. The 3rd question will be if you have back stack there.

  • Why fragment newInstance() is there (Best practice for instantiating a new Android Fragment)

  • Suppose you have to update location every minute even if you don’t get permission. But the tricky thing here is how will you notify the server-Through the same service you were sending updates using FusedLocationProvider/Will you use some other service or broadcast. Just design the whole thing.

  • Observable.just/Observable.from/Observable.create in RXJAVA?

  • Why Instant Apps? How do you achieve this?

  • How to load Large Bitmaps? Handle Memory leaks and Sample sizing

  • How parcelable internally works? Design it.

  • What happens if your serializable class contains a member which is not serializable? How to handle it?

  • Why do we use WeakReferences?

  • How to retain data on orientation change? Explain lifecycle during orientation changes.

  • How to make endless circular recyclerView?

  • Suppose you have given an array of array of custom Objects. Which data structure will you use to show these on UI?

  • How do you handle opening activity using notifications?

  • How to achieve Push notifications in android? Explain behavior during App in front/Background-How to handle both scenarios.

  • How to download files in parallel?

  • Why Realm?Realm Methods, Realm vs Sqlite.

  • How to handle different screen sizes/density/languages/orientation in android?

  • What the Fragment’s method setRetainInstance(boolean) does?

  • Keep yourself up to date with the latest library versions if using.

  • Why is there a need for JobIntentService?(hint:: Oreo update)

  • Basics for Testing in Android-They will ask some questions about Espresso,mockito,roboelectric(not in that deep).Stub vs mock. Also if you are following MVP pattern. Be prepared for the questions now.

  • How the OS handles process flow. When is the app killed or removed from recent memory? How OS decides this.

  • Which method gets called when home button pressed, back pressed etc.(Most commonly asked)

  • Manifest related attributes -allowBackup,intent-filters,process,taskAffinity,permission vs uses-permission etc.

  • Draw a simple basic design you follow to make an android application(folder structure, methods, variables)

  • Why services preferred over Broadcast receiver for background applications

  • Broadcast-related changes in Oreo and Handling them.

  • Accessibility services in android. How do you handle system apps(I mentioned this work too, so asked)

  • Thread.start() vs run method,submit vs Execute ,callable vs runnable

  • View Holder pattern.ListView vs RecyclerView.

  • Remote Views and How to use them?

  • Inner Classes vs Static Classes?

  • Volatile vs Transient

  • Internal Implementation of Picasso, Glide

  • Internal implementation of Recyclerview

  • Design Patterns and Practical Usage

  • Custom View and Lifecycle

  • Singleton vs Static and why we use them?

  • Deep vs Dynamic Linking

  • Livedata postValue vs set

  • Livedata vs ObservableField

  • ViewModelFactory

  • HashCode and Equals Implementation

  • Dagger - Component vs SubComponenets

  • TDD and frameworks - if using , tell the challenges faced

  • GSON vs Jackson vs Moshi

  • MultiModule Benfeits

  • Android Bundle - and Dynamic Feature usage

  • Proguard vs R8

  • What is Scoped Storage and how to implement?

  • Observable vs Completable vs Single

  • Rx vs Coroutines. Which one you prefer and when?

  • Difference between MVP and MVVM?

  • Explain SOLID principles?

  • Difference between const and val

  • When is onPause() called without onStop() being called?

  • Dagger vs Koin?

  • Any 5 RxJava operatrs. How subscribeOn and observeOn works?

  • Headless Fragments.

  • Workmanager, type of requests, methods, minimum interval before a job repeat itself.

  • Workmanager vs JobScheduler.

  • Why ConstraintLayout? Tell some properties which I find worth.

  • How SharedPreferences work internally?

You will be given assignments as your first/last round. They just want to know how you follow the standards. Some ask for UI thing, other ask for architectural patterns. Just check your methods and play well with the logic.That’s all.

System Design

  • Design Whatsapp/Chat application/Facebook messenger.

  • Implement search functionality with debounce operator (If user keeps on typing, then cancel the last network call and hit for the present one, How will you achieve that?)

  • Design a Location Tracking application

  • Design Uber/Ola.

  • Design Twitter.

  • Design Bookmyshow.

That’s all Guys. The moment I come out of the interview room, I always note down the questions on Google Keep. Blogs & Github links helped me so much in cracking these interviews. See Now I can help others too -:)

If you learn about the concepts for the above questions, I am sure you will get your basics strong and with the strong basics, you can easily crack any interview.

I have written an article on the same.

If you have more questions, I will be happy to learn, add & share. Please raise a PR and contribute. :-)