- You want to interview with a new company.
- You are working in a company but want to know which questions are typically mentioned in interviews.
- You are an interviewer and need some useful questions or want to challenge the interviewee
- You just want to improve your knowledge about android problems and basics.
| IMPORTANT NOTICE: There is no need to know and read all the questions will be mentioned later. According to the field, size, products and requirements of the company, select and read the appropriate questions. |
|---|
- Object-oriented
- Java
- Kotlin
- Android
- Architecture and coding
- Tools and libraries
- Gradle
- Design patterns
- Data structure and algoritms
-
What is and Object?
-
What is the main feature of OOP ?
Encapsulation,Polymorphism,Inheritance,Abstraction -
What is encapsulation?
-
What is Polymorphism?
-
Difference between abstract and interface?
-
What is the difference between static and dynamic Polymorphism?
-
Can Interfaces to be extended?
-
What is the difference between overriding and overloading?
| Method Overloading | Method Overriding |
|---|---|
| Method overloading is a compile time polymorphism. | Method overriding is a run time polymorphism. |
| It help to rise the readability of the program. | While it is used to grant the specific implementation of the method which is already provided by its parent class or super class. |
| It is occur within the class. | While it is performed in two classes with inheritance relationship. |
| Method overloading may or may not require inheritance. | While method overriding always needs inheritance. |
| In this, methods must have same name and different signature. | While in this, methods must have same name and same signature. |
| In method overloading, return type can or can not be be same, but we must have to change the parameter. | While in this, return type must be same or co-variant. |
-
What is the difference between Abstraction and Encapsulation?
Even though both Abstraction and Encapsulation looks similar because both hide complexity and make the external interface simpler there is a subtle difference between them. Abstraction hides logical complexity while Encapsulation hides Physical Complexity.
| Abstraction | Encapsulation |
|---|---|
| Abstraction solves the problems in the design level | Encapsulation solves the problems in the implementation level |
| Abstraction is used for hiding the unwanted data and giving relevant data | Encapsulation means hiding the code and data into a single unit to protect the data from outside of the world |
| Abstraction let you focus on what the object does instead of how it does it | Encapsulation means hiding the internal details mechanisms of how an objects does something |
| Outer layout, used in terms of design: Outer look of mobile phone, like it has display screen and keypad buttons to a number | Inner layout, used in terms of implementation: For example: Inner implementations detail of a mobile phone, how keypad button and display screen are connect with each other using circuits. |
-
How to prevent a class to be extended?
-
What is the use of the finalize method?
-
Overriding for static method, possible?
-
What is an abstract class? Benefits?
-
What is an object cloning? Is it enable for all objects?
-
Multiple inheritances? Possible? How can we do that?
-
Object scopes?
-
Override private methods, possible?
-
why access to the non-static variable is not allowed from static method in Java?
because non-static variable are associated with a specific instance of an object while static is not associated with any instance.
-
What is a static variable in Java?
-
Java reference types?
-
What is Generic in Java?
-
How String class is implemented? Is it mutable or immutable? Why was it made immutable?
-
What is the difference between int and Integer?
-
What are Autoboxing and unboxing?
-
What is the difference between initialization and instantiation?
-
How does a static block work?
-
What does the keyword
synchronizedmean? -
What is the memory leak? How to handle it?
-
What is
transientmodifier? -
What is the difference between
==and.equal? -
What is
reflection? -
What is the
volatilemodifier? -
What is the
hashCode()used for? -
What are "annotations"?
-
When we use thread-safe , what does it mean?
-
what is the difference between
throwandthrows?Keyword
throwis used to explicitly throw as an exception in the body of function, whilethrowsis utilized to handle checked exceptions for re-intimating the compiler that exceptions are being handled. The throws need to be used in the function’s signature and also while invoking the method that raises checked exceptions.
-
What are the benefits of Kotlin?
-
What does "Null safety" meaning?
-
Why Kotlin does not support primitive type?
-
What is Lazy initialization?
-
What is the data class?
-
Is it possible to inherit a class/method/property by default?
-
Difference between apply, also?
-
What
==exactly do in Kotlin in comparison to Java? -
What is the difference between parameter and argument?
-
What is the difference between function and method?
-
What is the "receiver" in the extension function?
-
What is operator overloading?
-
Is it possible to write a static method as java as has?
-
What is a sealed class?
-
How does an extension function work?
-
What is
reifiedkeyword? -
What is an inline function?
-
What are the cons of using an inline function?
-
What is the best practice of using an inline function?
-
How does the
companion objectblock work? -
Is it possible to create an extension function on the
companion objectof a class? -
Extension function as a member, possible? What are the benefits of declaring an extension function as a member?
-
What is a spread operator? What is the recommended place to use it?
-
What is the producer’s function? how to demonstrate it in Kotlin?
-
What is the consumer’s function? how to demonstrate it in Kotlin?
-
What is the higher-order function?
-
How to compare two Strings in Kotlin?
-
What is the difference between
==and===?
-
What is
Applicationclass? -
Difference between
ActivityandService? -
Why do android apps need to ask permission like
INTERNETorLOCATION? -
Differences between
serializableandParcalable? -
Why
serializablebody is empty? How is it doing? -
Which method in
fragmentruns only once? -
How does the activity respond when orientation is changed?
-
How to know
configChangehappens inonDestroy()function? -
How to prevent the data from reloading when orientation is changed?
The most basic approach would be to use a combination of
ViewModelsandonSaveInstanceState(). AViewModelis LifeCycle-Aware. In other words, aViewModelwill not be destroyed if its owner is destroyed for a configuration change (e.g. rotation). The new instance of the owner will just re-connected to the existingViewModel. So if you rotate anActivitythree times, you have just created three differentActivityinstances, but you only have oneViewModel. So the common practice is to store data in theViewModelclass (since it persists data during configuration changes) and useOnSaveInstanceState()to store small amounts of UI data. -
How to handle multiple screen sizes?
-
What is the difference between margin and padding?
-
Padding will be space added inside the container, for instance, if it is a button, padding will be added inside the button.
-
Margin will be space added outside the container.
-
-
What is
swkeyword inlayout-sw600folder meaning? -
What is the difference between
swandwandhas postfix in order to define the resources folder? -
What are the major differences between
ListViewandRecyclerView?-
ViewHolder Pattern:
Recyclerviewimplements the ViewHolders pattern whereas it is not mandatory in a ListView. AViewHolderobject stores each of the component views inside the tag field of the Layout, so you can immediately access them without the need to look them up repeatedly. InListView, the code might callfindViewById()frequently during the scrolling ofListView, which can slow down performance. Even when theAdapterreturns an inflated view for recycling, you still need to look up the elements and update them. A way around repeated use offindViewById()is to use the "view holder" design pattern. -
LayoutManager: In a
ListView, the only type of view available is theverticalListView. ARecyclerViewdecouples list from its container so we can put list items easily at run time in the different containers (linearLayout, gridLayout) by setting LayoutManager. -
Item Animator:
ListViewsare lacking in support of good animations, but theRecyclerViewbrings a whole new dimension to it.
-
-
Difference between
IntentandIntentService?-
Serviceis the base class for Android services that can be extended to create any service. A class that directly extendsServiceruns on the main thread so it will block the UI (if there is one) and should therefore either be used only for short tasks or should make use of other threads for longer tasks. -
IntentServiceis a subclass ofServicethat handles asynchronous requests (expressed asIntents) on demand. Clients send requests throughstartService(Intent)calls. The service is started as needed, handles eachIntentin turn using a worker thread, and stops itself when it runs out of work. Read More on Mindorks's blog
-
-
How to pass items to
fragment? -
What is
Fragment? -
How would you communicate between two
fragments? -
Difference between adding/replacing
fragmentinbackstack?-
replaceremoves the existingfragmentand adds a newfragment. This means when you press back button the fragment that got replaced will be created with its onCreateView being invoked. -
addretains the existing fragments and adds a newfragmentthat means existing fragment will be active and they wont be in 'paused' state hence when a back button is pressed onCreateView is not called for the existing fragment(the fragment which was there before new fragment was added).In terms of fragment’s life cycle events
onPause(),onResume(),onCreateView()and other life cycle events will be invoked in case ofreplacebut they wont be invoked in case ofadd.
-
-
What is the difference between
dialoganddialogFragment? -
What is the difference between
ThreadandAsyncTask? -
What is the relationship between the life cycle of an
AsyncTaskand anActivity? What problems can this result in? How can these problems be avoided?An AsyncTask is not tied to the life cycle of the Activity that contains it. So, for example, if you start an AsyncTask inside an Activity and the user rotates the device, the Activity will be destroyed (and a new Activity instance will be created) but the AsyncTask will not die but instead goes on living until it completes.
Then, when the AsyncTask does complete, rather than updating the UI of the new Activity, it updates the former instance of the Activity (i.e., the one in which it was created but that is not displayed anymore!). This can lead to an Exception (of the type java.lang.IllegalArgumentException: View not attached to window manager if you use, for instance, findViewById to retrieve a view inside the Activity).
There’s also the potential for this to result in a memory leak since the AsyncTask maintains a reference to the Activity, which prevents the Activity from being garbage collected as long as the AsyncTask remains alive.
For these reasons, using AsyncTasks for long-running background tasks is generally a bad idea . Rather, for long-running background tasks, a different mechanism (such as a service) should be employed.
-
What is
Lopperand how it works? -
What are Handlers?
Handlers are objects for managing threads. It receives messages and writes code on how to handle the message. They run outside of the activity’s lifecycle, so they need to be cleaned up properly or else you will have thread leaks. Handlers allow communicating between the background thread and the main thread. -
What is the difference between
ForegroundandBackgroundandBoundedservice?-
Foreground Service: A foreground
serviceperforms some operation that is noticeable to the user. For example, we can use a foreground service to play an audio track. ANotificationmust be displayed to the user. -
Background Service: A background
serviceperforms an operation that isn’t directly noticed by the user. In Android API level 26 and above, there are restrictions to using background services and it is recommended to use WorkManager in these cases -
Bound Service: A
serviceis bound when an application component binds to it by callingbindService(). A bound service offers a client-server interface that allows components to interact with theservice, send requests, receive results. A bound service runs only as long as another application component is bound to it. Read More
-
-
What are the limitations of using
Servicesin android 8 and higher? -
What is
JobScheduling? -
What is
contentProviderand what is typically used for?A
ContentProviderprovides data from one application to another, when requested. It manages access to a structured set of data. It provides mechanisms for defining data security. Learn more. For further reading see the official android documentation -
What is the difference between
apply()andcommit()insharedPreferences?-
commit()writes the data synchronously and returns a boolean value of success or failure depending on the result immediately. -
apply()is asynchronous and it won’t return any boolean response. Also if there is anapply()outstanding and we perform anothercommit(), Thecommit()will be blocked until theapply()is not completed.
-
-
How you load your
Bitmaps? What do you do for loading large bitmaps? Loading Large Bitmaps Efficiently in Android -
How Android apps compiled and run?
-
First step involves compiling the resources folder (/res) using the aapt (android asset packaging tool) tool. These are compiled to a single class file called R.java. This is a class that just contains constants.
-
Second step involves the java source code being compiled to .class files by javac, and then the class files are converted to Dalvik bytecode by the “dx” tool, which is included in the sdk ‘tools’. The output is classes.dex.
-
The final step involves the android apkbuilder which takes all the input and builds the apk (android packaging key) file.
-
-
Do you know any about how
Dalvikis working? -
What are the benefits of
ARTin comparison toDalvik? -
What is
AAPT? -
What is Doze mode?
According to a report by codespaghetti, The most design patterns that you must to know are Singleton, Factory, and Builder. I didn't bring the typical questions like what is a singleton, factory, and... . I imagine you fluent on these patterns and instead, I will focus on the other side of questions that may asked in the interview meeting.
-
When to use Adapter pattern? (Not for RecyclerView or ListView)
Use Adapter pattern when you need to make two class work with incompatible interfaces. Adapter pattern can also be used to encapsulate third party code so that your application only depends upon Adapter, which can adapt itself when third party code changes or you moved to a different third party library.
-
In singleton pattern whether it is better to make the whole
getInstance()method synchronized or just critical section is enough? Which one is preferable?Synchronization of whole
getInstance()method is costly and is only needed during the initialization on singleton instance, to stop creating another instance of Singleton. Therefore it is better to only synchronize critical section and not the whole method. -
How many ways can you write singleton class in Java?
One can write singleton class in Java in five ways
- Classic Java Singleton pattern
Public class Singleton{ private static Singleton instance; private Singleton(){ } public static Singleton getInstance(){ if(instance == null) instance = new Singleton(); return instance; } }
- A thread-safe singleton pattern in java using Synchronization
public class Singleton{ private static final Singleton instance = null; private Singleton(){} public synchronized static Singleton getInstance(){ if(instance == null) instance = new Singleton(); return instance; } }
- Double-checked locking with volatile keyword
public class Singleton { private volatile static Singleton instance; private Singleton (){} public static Singleton getSingleton() { if (instance == null) { synchronized (Singleton.class) { if (instance == null) instance = new Singleton(); } } return instance; } }
- Initialization-on-demand with singleton holder
// Correct lazy initialization in Java @ThreadSafe class Singleton { private Singleton() {} private static class SingletonHolder { public static Singleton instance = new Singleton(); } public static Singleton getInstance() { return SingletonHolder.instance; } }
- Using Enum
enum Color { RED(1), GREEN(2), YELLOW(3); private int nCode ; private Color( int _nCode) { this.nCode = _nCode; } @Override public String toString() { return String.valueOf ( this . nCode ); } } public class ColorTest { public static void main(String[] args) { Color red = Color.RED; Color red2 = Color.RED; System.out.println(red == red2); // return true } }
-
What are the drawbacks of using singleton design pattern?
-
Testability issue: The bad thing with singletons is that the
getInstance()method is globally accessible. That means that you usually call it from within a class, instead of depending on an interface you can later mock. That's why it's impossible to replace it when you want to test the method or the class. -
Tight Coupling: The singleton object is exposed globally and is available to a whole application. Thus, classes using this object become tightly coupled. So any change in the global object will impact all other classes using it.
-
Violation issues: Singleton principle can be violated by techniques such as cloning. If an application is running on multiple JVM’s, then, in this case, Singleton might be broken.
-
-
How can you prevent creating another instance of singleton using
clone()method?The preferred way to prevent creating another instance of a singleton is by not implementing Cloneable interface and if you do just throw an exception from
clone()method "not to create a clone of singleton class". -
When will you prefer to use a Factory Pattern?
The factory pattern is preferred in the following cases:
-
A class does not know which class of objects it must create
-
Factory pattern can be used where we need to create an object of any one of sub-classes depending on the data provided
-
you can use factory pattern where you have to create an object of any one of sub-classes depending on the given data
-
-
Why use a factory class to instantiate a class when we can use new operator?
Factory classes provide flexibility in terms of design. Below are some of the benefits of factory class:
- Factory design pattern results in more decoupled code as it allows us to hide creational logic from dependent code
- It allows us to introduce an Inversion of Control container
- It gives you a lot more flexibility when it comes time to change the application as our creational logic is hidden from dependant code
-
What is the difference between factory and abstract factory design pattern?
Both factory and abstract factory are creational design patterns. The major difference between these two is, a factory pattern creates an object through inheritance and produces only one Product. On the other hand, an abstract factory pattern creates the object through composition and produce families of products. In other word an abstract factory is "factory of factories". You can find an example here.
-
(My Favorite question!) Suppose we are building an application for a pizza store and we need to model their pizza classes. Assume they offer four types of pizzas namely Peppy Paneer, Farmhouse, Margherita and Chicken Fiesta. Each pizza has a different cost. We have overridden the getCost() in the subclasses to find the appropriate cost. Now let's become it more interesting! suppose a new requirement, in addition to a pizza, customer can also ask for several toppings such as Fresh Tomato, Paneer, Jalapeno, Capsicum, Barbeque, etc. Toppings may be redundant and it's OK. (It means a customer may choose double jalapeno or three-time barbeque). Each topping has its price and by adding each one the total cost of the pizza will be increased. If you have to suggest only one design pattern to solve this problem, choose which one? why? and How you implement it?
-
If you couldn't find a solution to the previous question, don't worry and follow this one. It can help you to find out how to solve it. The question is, Which design pattern allows you to implement the inheritance approach at the runtime?
-
which pattern is used when we need to decouple an abstraction from its implementation?
When we want to decouple an abstraction from its implementation in order that two can vary independently we use bridge pattern.
NOTICE: For D.S. questions will not add any response! :(
-
What are the differences between Array and linkedList?
-
What are the differences between Array and ArrayList?
-
Find duplicate an item in a non-sorted list?
-
How to implement a stack using queue?
-
How do you find the largest and smallest number in an unsorted integer array?
-
Given an array of size n with range of numbers from 1 to n+1. The array doesn’t contain any duplicate, one number is missing, find the missing number.
-
A sorted array is rotated at some unknown point, how to efficiently search an element in it.
-
How to find if two given rectangles overlap?
-
How to swap two integers without swapping the temporary variable in Java?
-
How do you check if a string contains only digits?
-
How to sort a list?

