├── Android ├── -nodpi, -anydpi qualifiers for resources.md ├── Activity Lifecycle.md ├── Build Type, Product Flavor, Build Variant.md ├── Describe Fragment lifecycle.md ├── Describe android modularization in general.md ├── Describe jetpack compose phases.md ├── Difference between Room and SQLite.md ├── Difference between raw and assets folders.md ├── Different between @id and @+id.md ├── How does RecyclerView differ from ListView.md ├── How to communicate with fragments.md ├── How to support different screen size in android.md ├── Main components of Android application.md ├── Service vs IntentService.md ├── View lifecycle.md ├── What are Sticky Intent.md ├── What are the permission protection levels.md ├── What do you know about Activity Result APIs.md ├── What do you know about App Bundles.md ├── What do you know about App Shortcuts.md ├── What do you know about App Startup library.md ├── What do you know about ArrayMap.md ├── What do you know about Auto Backup.md ├── What do you know about Chrome custom tabs.md ├── What do you know about CompositionLocal.md ├── What do you know about Converters in Room.md ├── What do you know about DiffUtil.md ├── What do you know about FileProvider.md ├── What do you know about Foreground Services.md ├── What do you know about Handler, MessageQueue, Looper.md ├── What do you know about Intent Filter.md ├── What do you know about Intents.md ├── What do you know about Lint.md ├── What do you know about Parcelable.md ├── What do you know about PendingIntent.md ├── What do you know about Play Feature Delivery.md ├── What do you know about RecyclerView ItemDecoration.md ├── What do you know about SparseArray.md ├── What do you know about Splash screen and SplashScreen library.md ├── What do you know about Version catalog.md ├── What do you know about View Binding.md ├── What do you know about ViewCompositionStrategy.md ├── What do you know about accessibility.md ├── What do you know about app startup time.md ├── What do you know about downloadable fonts.md ├── What do you know about lifecycle from architecture component.md ├── What do you know about notification.md ├── What do you know about paging library.md ├── What do you know about side effects in jetpack compose.md ├── What do you know about slices.md ├── What do you know about taskAffinity.md ├── What do you know about tasks and the back stack.md ├── What is ANR.md ├── What is AndroidManifest.md ├── What is Context.md ├── What is Fragment.md ├── What is Jetpack Compose.md ├── What is Overdraw.md ├── What is Spannable.md ├── What is StrictMode.md ├── What is SurfaceView.md ├── What is background task and how it should be performed.md ├── What is gradle.md ├── What is installLocation tag in AndroidManifest.md ├── What is savedInstanceState bundle.md ├── What is the difference between Activity and Fragment.md ├── What is the difference between Dialog & DialogFragment.md ├── What is the difference between Serializable and Parcelable.md ├── What is the difference between view binding and data binding.md ├── What launch modes do you know.md ├── What modularization patterns do you know.md ├── What security best practices you know.md ├── What tools for multithreading do you know.md ├── What types of modules do you know.md ├── What ways do you know to reduce the size of an application.md ├── What you know about DataStore.md ├── What's Activity.md ├── What's BroadcastReceiver.md ├── What's ContentProvider.md ├── What's Jetpack.md ├── What's LiveData.md ├── What's Navigation component.md ├── What's Play App Signing.md ├── What's Proguard.md ├── What's RecyclerView.md ├── What's Room.md ├── What's Service.md ├── What's View.md ├── What's ViewGroup How are they different from Views.md ├── What's ViewModel.md ├── What's ViewStub.md ├── What's Widget.md ├── What's WorkManager.md ├── What's dark theme.md ├── What's data binding.md └── res │ ├── activity_lifecycle.png │ ├── anr_example_framed.png │ ├── app_modules.png │ ├── app_signing.png │ ├── appearance_affecting_spans.png │ ├── build_type.png │ ├── cold_start.png │ ├── compose_1.png │ ├── compose_phases.svg │ ├── compose_phases_state_read_draw.svg │ ├── content_provider.jpg │ ├── context.png │ ├── context_table.png │ ├── data_modules.png │ ├── debug_broadcast_receiver_timeout.png │ ├── debug_content_provider_anr.png │ ├── debug_execute_service_anr.png │ ├── debug_input_dispatch_anr.png │ ├── diagram_backstack.png │ ├── diagram_multitasking.png │ ├── downloadable_fonts_process.png │ ├── event_tasks_flowchart.svg │ ├── feature_modules.png │ ├── fragment-a-to-b.png │ ├── fragment_add_replace.png │ ├── fragment_lifecycle.png │ ├── fragment_stop_save_order.png │ ├── fragments.png │ ├── handler_looper_message.jpeg │ ├── hot_start.png │ ├── layout-editor_2x.png │ ├── lifecycle_states.svg │ ├── lint_tool.png │ ├── metric_affecting_spans.png │ ├── modularization_dependency_graph.png │ ├── module_mediator.png │ ├── modules_di_concept.png │ ├── modules_shared_data.png │ ├── ninepatch_raw.png │ ├── nodpi_anydpi_source.png │ ├── notification.png │ ├── paging_library_architecture.webp │ ├── paragraph_affecting_spans.png │ ├── pass-parent-child.png │ ├── pinned_shortcuts.png │ ├── product_flavor.png │ ├── room.png │ ├── service_lifecycle.png │ ├── singleInstance_scenario_1.png │ ├── singleTask_scenario_1.png │ ├── singleTask_scenario_1_2.png │ ├── singleTask_scenario_2.png │ ├── singleTop_scenario_1.png │ ├── singleTop_scenario_2.png │ ├── sizes-phone-tablet_2x.png │ ├── slices_image_1.png │ ├── slices_image_2.png │ ├── slices_image_3.png │ ├── slices_image_4.png │ ├── slices_image_5.png │ ├── slices_image_6.png │ ├── slices_image_7.png │ ├── spannable_table.png │ ├── test_modules.png │ ├── user_task_flowchart.svg │ ├── view_hierarchy.png │ ├── view_lifecycle.png │ ├── viewbinding_vs_databinding.png │ ├── viewmodel_lifecycle.png │ ├── wear_dep_graph.png │ └── work_manager_criteria.png ├── General ├── Composition vs Inheritance.md ├── Concurrency vs Parallelism.md ├── Describe Scrum and Kanban.md ├── Difference between git rebase and git merge.md ├── OOP principles.md ├── SOAP vs REST.md ├── SOLID principles.md ├── What do you know about CI.md ├── What do you know about DI.md ├── What do you know about GraphQL.md ├── What do you know about OSI model.md ├── What do you know about Protocol Buffers.md ├── What do you know about SOAP.md ├── What do you know about Symmetric Key Encryption.md ├── What do you know about TCP.md ├── What do you know about UDP.md ├── What do you know about URI.md ├── What do you know about URL.md ├── What do you know about YAGNI, KISS, DRY.md ├── What do you know about asymmetric key encryption.md ├── What do you know about certificate pinning.md ├── What do you know about certificate transparency.md ├── What do you know about ssl certificates.md ├── What do you know about waterfall methodology.md ├── What is Agile.md ├── What is Extreme Programming (XP).md ├── What is Feature Driven Development (FDD).md ├── What is Kanban.md ├── What is Man-in-the-middle attack.md ├── What is REST.md ├── What is Scrum.md ├── What is cohesion.md ├── What is coupling.md ├── What is deadlock.md ├── What is encryption. What types of encryption keys do you know.md ├── What is livelock.md ├── What is the difference between Aggregation and Composition.md ├── What is the difference between DI and Service Locator.md ├── What is the difference between GET and POST request.md ├── What is the difference between HTTP and HTTPS.md ├── What is the difference between PUT and POST request.md ├── What is the difference between TCP and UDP.md ├── What is the difference between abstraction and encapsulation.md ├── What is the difference between git pull and git fetch.md ├── What is the difference between symmetric and asymmetric encryption.md └── res │ ├── aggregation.jpg │ ├── agile.png │ ├── asymmetric-encryption.png │ ├── asymmetric_base.png │ ├── ci_basics.svg │ ├── cohesion.png │ ├── composition.jpg │ ├── concurrency.png │ ├── coupling.png │ ├── ct_components.jpeg │ ├── ct_works.jpeg │ ├── encryption_base.png │ ├── fdd.png │ ├── graphql_general.png │ ├── man_in_the_middle_attack.png │ ├── osi_model.png │ ├── parallelism.png │ ├── proto_buffers_types.png │ ├── soap_message.png │ ├── soap_protocol.png │ ├── ssl_certificate_work.png │ ├── symmetric_base.png │ ├── symmetric_encryption.png │ ├── tcp_header.jpg │ ├── udp_datagram.png │ ├── uri_syntax.png │ ├── waterfall_model.png │ ├── xp_lifycycle.webp │ └── yagni_image.webp ├── Java ├── ArrayList vs LinkedList.md ├── Can a constructor be inherited.md ├── Can a static method be overridden.md ├── Comparable interface in java.md ├── Describe Deque interface from java collection.md ├── Describe List interface.md ├── Describe Queue interface from java collection.md ├── Describe map interface from java collection.md ├── Describe set interface from java collection.md ├── Difference between Semaphore and Monitor.md ├── Difference between int and Integer.md ├── Difference between static and regular nested classes.md ├── Different between Array and ArrayList.md ├── Do objects get passed by reference or value.md ├── Exception. Checked and Unchecked..md ├── Generics.md ├── HashSet vs TreeSet.md ├── Hashtable vs ConcurrentHashMap.md ├── How HashMap works.md ├── Memory model.md ├── Method signature.md ├── References types.md ├── What are anonymous classes.md ├── What are lambda expressions.md ├── What are the basic interfaces of Java Collections Framework.md ├── What are the methods of Object class.md ├── What do you know about ArrayList.md ├── What do you know about Comparator interface.md ├── What do you know about ConcurrentHashMap.md ├── What do you know about EnumMap.md ├── What do you know about EnumSet.md ├── What do you know about HashSet.md ├── What do you know about Hashtable.md ├── What do you know about Iterator interface.md ├── What do you know about LinkedHashMap.md ├── What do you know about LinkedHashSet.md ├── What do you know about LinkedList.md ├── What do you know about Serializable interface.md ├── What do you know about Stack.md ├── What do you know about Stream interface.md ├── What do you know about TreeMap.md ├── What do you know about TreeSet.md ├── What do you know about Vector.md ├── What do you know about access modifiers.md ├── What do you know about default method in interface.md ├── What do you know about double check pattern singleton.md ├── What do you know about java record.md ├── What do you know about try-catch-finally.md ├── What do you know about wildcard.md ├── What does the keyword synchronized mean.md ├── What is Java's Garbage Collection.md ├── What is String Pool.md ├── What is casting.md ├── What is enum.md ├── What is immutable object.md ├── What is memory leak.md ├── What is object monitor.md ├── What is the difference between JDK, JRE and JVM.md ├── What is the difference between String, StringBuilder and StringBuffer.md ├── What is the difference between a Stream and an Iterator.md ├── What is the difference between final, finally and finalize.md ├── What is the difference between overriding and overloading.md ├── What is transient keyword.md ├── What is volatile keyword.md ├── What's Clonaeble interface.md ├── What's Comparable and Comparator interface.md ├── What's Executor interface.md ├── What's Semaphore.md ├── What's interface.md └── res │ ├── access_modifier.png │ ├── collection.jpeg │ ├── deque_interface_java.jpeg │ ├── exception_hierarchy.jpg │ ├── garbage_collection_generations.png │ ├── garbage_collection_step_1.png │ ├── garbage_collection_step_2.png │ ├── garbage_collection_step_3.png │ ├── iterators.png │ ├── java_list_class_diagram.png │ ├── java_map.png │ ├── java_memory.jpg │ ├── java_memory_leak.png │ ├── java_set_implementation.png │ ├── jdk.png │ ├── jre.png │ ├── linkedlist-node.png │ ├── linkedlist_implemenation.png │ ├── metaspace.png │ ├── queue_interface_java.png │ ├── semaphore.jpeg │ ├── serialize_deserialize_java.png │ ├── stack_and_heap.png │ ├── stack_vs_heap.png │ ├── string_pool.png │ └── volatile.png ├── Kotlin ├── Crossinline keyword.md ├── Default method in kotlin interface.md ├── Describe constructors invocation order.md ├── Describe nullability and null safety.md ├── Difference between fold and reduce in Kotlin.md ├── Enum.md ├── Generics.md ├── Inline keyword.md ├── Kotlin collections.md ├── Scope functions.md ├── Visibility modifiers.md ├── What are coroutines.md ├── What do you know about Any, Nothing, Unit types.md ├── What do you know about Channels.md ├── What do you know about Coroutine Job.md ├── What do you know about Flow.md ├── What do you know about JvmOverloads annotation.md ├── What do you know about JvmStatic and JvmField annotations.md ├── What do you know about StateFlow and SharedFlow.md ├── What do you know about companion object.md ├── What do you know about data classes.md ├── What do you know about data objects.md ├── What do you know about delegated properties.md ├── What do you know about extensions?.md ├── What do you know about functional interfaces.md ├── What do you know about lateinit.md ├── What do you know about object keyword.md ├── What do you know about operator overloading.md ├── What do you know about property references.md ├── What do you know about reified keyword.md ├── What do you know about sealed classes and interfaces.md ├── What do you know about type aliases.md ├── What is Coroutine Scope and how is that different from Coroutine Context?.md ├── What is destructuring declarations.md ├── What is the difference between * and Any in generics.md ├── What is the difference between abstract class and interface.md ├── What is the difference between functional interfaces and type aliases.md ├── What is the difference between lazy and lateinit.md ├── What is the difference between nested class and inner class.md ├── What is the difference between suspending vs. blocking.md ├── What's Ranges.md ├── What's Sequence.md ├── What's a const.md ├── What's difference between == and ===.md ├── What's difference between launch and async.md ├── What's infix function.md ├── What's init block.md ├── What's inline class.md ├── code │ └── Questions.md ├── map vs flatMap in collections.md ├── res │ ├── collections-diagram.png │ ├── coroutine_context.png │ ├── coroutine_scope.png │ ├── crossinline.png │ ├── flow_entities.png │ ├── nullability_compile_time_error.png │ ├── scope_function.png │ └── visibility_modifiers.png └── val mutableList vs var immutableList. When to use which.md ├── LICENSE ├── Libraries ├── Main annotations in Dagger 2.md ├── Popular libraries for image loading on Android.md ├── What JSON serialization & deserialization libraries do you know.md ├── What do you know about Kodein.md ├── What do you know about Koin.md ├── What do you know about OkHttp interceptors.md ├── What do you know about OkHttp.md ├── What do you know about Realm.md ├── What do you know about Retrofit.md ├── What do you know about hilt.md ├── What the difference between @Bind and @Provides in Dagger 2.md ├── What's Dagger 2.md ├── Which libraries for dependency injection you know.md └── res │ ├── hilt_hierarchy.png │ └── interceptors.png ├── Patterns ├── Abstract factory pattern.md ├── Adapter pattern.md ├── Bridge pattern.md ├── Builder pattern.md ├── Chain of Responsibility pattern.md ├── Command pattern.md ├── Composite pattern.md ├── Decorator pattern.md ├── Facade pattern.md ├── Factory method pattern.md ├── Flyweight pattern.md ├── Interpreter pattern.md ├── Iterator pattern.md ├── MVI pattern.md ├── MVP pattern.md ├── MVVM pattern.md ├── Mediator pattern.md ├── Memento pattern.md ├── Observer pattern.md ├── Prototype pattern.md ├── Proxy pattern.md ├── Service locator pattern.md ├── Singleton pattern.md ├── State pattern.md ├── Strategy pattern.md ├── Template method pattern.md ├── Types of Design Patterns.md ├── Visitor pattern.md └── res │ ├── facade.jpg │ ├── mvi.png │ ├── mvp_android.png │ ├── mvvm_android.png │ └── state_pattern.jpeg ├── README.md ├── Rx ├── Give example of combining operators.md ├── Give example of conditional operators.md ├── Give example of creating operators.md ├── Give example of error handling operators.md ├── Give example of filtering operators.md ├── Give example of mathematical and aggregate operators.md ├── Give example of transforming operators.md ├── Give example of utility operators.md ├── Observable types.md ├── RepeatWhen vs RetryWhen.md ├── Schedulers types.md ├── Subjects types.md ├── What do you know about observeOn operator.md ├── What do you know about subscribeOn operator.md ├── What is the difference between cold and hot observables.md ├── What's backpressure.md ├── What's the difference between Concat Vs Merge.md ├── What's the difference between map and flatMap.md ├── What's the difference between observeOn and subscribeOn.md ├── What’s the difference between flatMap(), concatMap() and switchMap().md ├── code │ └── subscribeOn.md └── res │ ├── async_subject_error.png │ ├── async_subject_success.png │ ├── behavior_subject_error.png │ ├── behavior_subject_success.png │ ├── combining_combineLatest.png │ ├── combining_join.png │ ├── combining_merge.png │ ├── combining_startWith.png │ ├── combining_switch.png │ ├── combining_zip.png │ ├── concat.png │ ├── concatMap.png │ ├── conditional_all.png │ ├── conditional_amb.png │ ├── conditional_contains.png │ ├── conditional_defaultIfEmpty.png │ ├── conditional_sequenceEqual.png │ ├── conditional_skipUntil.png │ ├── conditional_skipWhile.png │ ├── conditional_takeUntil.png │ ├── conditional_takeWhile.png │ ├── creating_create.png │ ├── creating_defer.png │ ├── creating_empty.png │ ├── creating_from.png │ ├── creating_interval.png │ ├── creating_just.png │ ├── creating_never.png │ ├── creating_range.png │ ├── creating_repeat.png │ ├── creating_start.png │ ├── creating_throw.png │ ├── creating_timer.png │ ├── error_handling_catch.png │ ├── error_handling_onErrorResumeNext.png │ ├── error_handling_onErrorReturn.png │ ├── error_handling_onExceptionResumeNext.png │ ├── error_handling_retry.png │ ├── error_handling_retryMain.png │ ├── error_handling_retryWhen.png │ ├── filtering_debounce.png │ ├── filtering_distinct.png │ ├── filtering_elementAt.png │ ├── filtering_filter.png │ ├── filtering_first.png │ ├── filtering_ignoreElements.png │ ├── filtering_last.png │ ├── filtering_sample.png │ ├── filtering_skip.png │ ├── filtering_skipLast.png │ ├── filtering_take.png │ ├── filtering_takeLast.png │ ├── flatMap.png │ ├── math_concat.png │ ├── math_count.png │ ├── math_reduce.png │ ├── merge.png │ ├── observeOn.png │ ├── observeOn_flow.png │ ├── publish_subject_error.png │ ├── publish_subject_success.png │ ├── replay_subject_success.png │ ├── schedulers.png │ ├── serialize.png │ ├── switchMap.png │ ├── transforming_buffer.png │ ├── transforming_flatMap.png │ ├── transforming_groupBy.png │ ├── transforming_map.png │ ├── transforming_scan.png │ ├── transforming_window.png │ ├── utility_delay.png │ ├── utility_dematerialize.png │ ├── utility_do.png │ ├── utility_materialize.png │ ├── utility_schedulers.png │ ├── utility_subscribeon.png │ ├── utility_timeInterval.png │ ├── utility_timeout.png │ └── utility_timestamp.png ├── Test Assignments └── Google image search.md └── Testing ├── Describe Test Driven Development.md ├── Difference between JUnit 4 and JUnit 5.md ├── Difference between mock, fake and stub.md ├── Test pyramid.md ├── Unit testing vs Functional testing.md ├── What do you know about BDD.md ├── What do you know about Mockito library.md ├── What do you know about espresso.md ├── What is A_B testing.md ├── What is JUnit.md ├── What is functional testing.md ├── What is robolectric.md ├── What is unit test.md └── res ├── ab_testing.png ├── tdd.png └── test_pyramid.png /Android/-nodpi, -anydpi qualifiers for resources.md: -------------------------------------------------------------------------------- 1 | From the Google-android source code 2 | 3 | ![NoDPInAnyDPI](https://raw.githubusercontent.com/swayangjit/Android-Interview-Questions/master/Android/res/nodpi_anydpi_source.png) 4 | 5 | ## nodpi: Fallback 6 | 7 | - A drawable inside the `res/drawable-nodpi/` folder is valid for any 8 | screen density. 9 | Eg. 10 | **drawable-nodpi/ic_icon.png** 11 | The above icon will will look small on `xxxhdpi` devices and big on `ldpi` devices. 12 | 13 | **drawable-hdpi/ic_icon.png** 14 | **drawable-nodpi-21/ic_icon.xml** 15 | In android 21 hdpi devices `ic_icon.png` will be used and in android 21 xhdpi devices `ic_icon.xml` will be used. 16 | 17 | 18 | 19 | ## anydpi: Takeover 20 | 21 | - A drawable inside `drawable-anydpi` is also valid for any screen 22 | density but anydpi variant has more priority over any density 23 | specific variant. 24 | 25 | Eg. 26 | If we have **res/drawable-anydpi/ic_icon.xml** and **res/drawable-xxxhdpi/ic_icon.png** then `ic_icon.xml` will be used even in xxxhdpi devices. 27 | 28 | -Most of the times `-anydpi` used in conjunction with other qualifiers. A good example is `anydpi-v21` as vector drawables were introduced in android 21 , so after that we usually have `res/drawable-anydpi-v21/ic_icon.xml` (Vector drawable) and `res/drawable-xxhdpi/ic_icon.png`. The vector drawable (`ic_icon.xml`) will be used in all android 21+ devices and `ic_icon.png` will be used in xxhdpi devices runing in android 4.4 or older 29 | -------------------------------------------------------------------------------- /Android/Build Type, Product Flavor, Build Variant.md: -------------------------------------------------------------------------------- 1 | # Build Type, Product Flavor, Build Variant 2 | 3 | ## Build Type 4 | **Build Types** controls how to build and package your app, for example whether or not ProGuard is run, how the resulting application package is signed and whether debug symbols are to be included. By default, the build system defines two build types: `debug` and `release`. 5 | 6 | ![](./res/build_type.png "Build Type") 7 | 8 | ## Product Flavor 9 | **Product Flavor** configuration defines a customized version of the application build. It can be used to specify custom features, minimum and target API levels, device and API requirements like layout, drawable and custom code. This can help create different label apps as well. Flavours can vary in adding different features or customizing exisitng features, different icons and resources, different styles and strings etc. 10 | 11 | ![](./res/product_flavor.png "Product Flavor") 12 | 13 | ## Build Variant 14 | The combination of **Build Type** and **Product Flavor** is known as **Build Variant**. For example, for above build types (debug and release) and product flavours (demo and full versions), build variants can be: `demoDebug`, `demoRelease`, `fullDebug`, `fullRelease`. 15 | 16 | ## Links 17 | https://developer.android.com/studio/build/build-variants 18 | https://wajahatkarim.com/2018/04/difference-between-build-type-flavour-and-build-variant-in-android/ 19 | https://stackoverflow.com/questions/27905934/why-are-build-types-distinct-from-product-flavors 20 | -------------------------------------------------------------------------------- /Android/Difference between Room and SQLite.md: -------------------------------------------------------------------------------- 1 | # Room vs SQLite 2 | 3 | SQLite is an in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. 4 | 5 | SQLite is an embedded SQL database engine. Unlike most other SQL databases, SQLite does not have a separate server process. SQLite reads and writes directly to ordinary disk files. A complete SQL database with multiple tables, indices, triggers, and views, is contained in a single disk file. The database file format is cross-platform - you can freely copy a database between 32-bit and 64-bit systems or between big-endian and little-endian architectures 6 | 7 | The Room persistence library provides an abstraction layer over SQLite to allow for more robust database access while harnessing the full power of SQLite. 8 | 9 | The library helps you create a cache of your app's data on a device that's running your app. This cache, which serves as your app's single source of truth, allows users to view a consistent copy of key information within your app, regardless of whether users have an internet connection. 10 | 11 | Room is an ORM, Object Relational Mapping library. In other words, Room will map our database objects to Java objects. Room provides an abstraction layer over SQLite to allow fluent database access while harnessing the full power of SQLite. 12 | 13 | Difference between SQLite and Room persistence library: 14 | - In the case of SQLite, There is no compile-time verification of raw SQLite queries. But in Room, there is SQL validation at compile time. 15 | - You need to use lots of boilerplate code to convert between SQL queries and Java data objects. But, Room maps our database objects to Java Object without boilerplate code. 16 | - As your schema changes, you need to update the affected SQL queries manually. Room solves this problem. 17 | - Room is built to work with LiveData and RxJava for data observation, while SQLite does not. 18 | 19 | ## Links 20 | https://medium.com/mindorks/using-room-database-android-jetpack-675a89a0e942 21 | https://developer.android.com/topic/libraries/architecture/room 22 | https://www.sqlite.org/about.html 23 | -------------------------------------------------------------------------------- /Android/Difference between raw and assets folders.md: -------------------------------------------------------------------------------- 1 | # Raw folder vs Assets folder 2 | 3 | The files in both directories will be stored intact in the APK package after being packaged and will not be compiled into binary systems. 4 | 5 | **The differences between res/raw and assets:** 6 | 7 | Since `raw` is a subfolder of Resources (`res`), Android will automatically generate an ID for any file located inside it. This ID is then stored an the `R` class that will act as a reference to a file, meaning it can be easily accessed from other Android classes and methods and even in Android XML files. Using the automatically generated ID is the fastest way to have access to a file in Android. 8 | 9 | The Assets folder is an “appendix” directory. The `R` class does not generate IDs for the files placed there, so its less compatible with some Android classes and methods. Also, it’s much slower to access a file inside it, since you will need to get a handle to it based on a String. However some operations are more easily done by placing files in this folder, like copying a database file to the system’s memory. There’s no (easy) way to create an Android XML reference to files inside the Assets folder. 10 | 11 | ## Links 12 | https://developer.android.com/guide/topics/resources/providing-resources 13 | https://stackoverflow.com/questions/9563373/when-should-i-use-the-assets-as-opposed-to-raw-resources-in-android 14 | https://topic.alibabacloud.com/a/the-difference-between-the-asset-folder-and-the-raw-folder-in-android-deep-parsing-_android_1_21_20133424.html 15 | -------------------------------------------------------------------------------- /Android/Different between @id and @+id.md: -------------------------------------------------------------------------------- 1 | # @id vs @+id 2 | 3 | The at-symbol (`@`) at the beginning of the string indicates that the XML parser should parse and expand the rest of the ID string and identify it as an ID resource. The plus-symbol (`+`) means that this is a new resource name that must be created and added to our resources (in the `R.java` file). In other words, the `+` symbol tells Android build tools that you are declaring a new resource, `@id/` you are referring to an existing resource (predefined by `@+id/` and already exists in `R.java`. 4 | -------------------------------------------------------------------------------- /Android/How does RecyclerView differ from ListView.md: -------------------------------------------------------------------------------- 1 | With the advent of Android Lollipop, the **RecyclerView** made its way officially. The **RecyclerView** is much more powerful, flexible and a major enhancement over **ListView**. 2 | 3 | - ViewHolder Pattern 4 | In a **ListView**, it was recommended to use the **ViewHolder** pattern but it was never a compulsion. In case of **RecyclerView**, this is mandatory using the **RecyclerView.ViewHolder** class. 5 | 6 | - LayoutManager 7 | This is another massive enhancement brought to the **RecyclerView**. In a **ListView**, the only type of view available is the vertical **ListView**. There is no official way to even implement a horizontal **ListView**. 8 | Now using a **RecyclerView**, we can have a 9 | - LinearLayoutManager - which supports both vertical and horizontal lists, 10 | - StaggeredLayoutManager - which supports Pinterest like staggered lists, 11 | - GridLayoutManager - which supports displaying grids as seen in Gallery apps. 12 | 13 | - Item Animator 14 | **ListViews** are lacking in support of good animations, but the **RecyclerView** brings a whole new dimension to it. Using the **RecyclerView.ItemAnimator** class, animating the views becomes so much easy and intuitive. 15 | 16 | - Item Decoration 17 | In case of **ListViews**, dynamically decorating items like adding borders or dividers was never easy. But in case of **RecyclerView**, the **RecyclerView.ItemDecorator** class gives huge control to the developers but makes things a bit more time consuming and complex. 18 | -------------------------------------------------------------------------------- /Android/Service vs IntentService.md: -------------------------------------------------------------------------------- 1 | # Service vs IntentService 2 | A `Service` is an application component that can perform long-running operations in the background, and it doesn't provide a user interface. Another application component can start a service, and it continues to run in the background even if the user switches to another application. Additionally, a component can bind to a service to interact with it and even perform interprocess communication (IPC). 3 | 4 | The `Service` class is the base class for all services. When you extend this class, it's important to create a new thread in which the service can complete all of its work; the service uses your application's main thread by default, which can slow the performance of any activity that your application is running. 5 | 6 | The Android framework also provides the `IntentService` subclass of `Service` that uses a worker thread to handle all of the start requests, one at a time. `IntentService` is very similura to queue where it handles request (intents) from clients. Client can send the request to `IntentService` by using command - `Context.startService(Intent)`. For implements `IntentService` you should extend IntentService class and implements method - `onHandleIntent(Intent)` 7 | 8 | Using `IntentService` is not recommended for new apps as it will not work well starting with Android 8 Oreo, due to the introduction of Background execution limits. Moreover, it's deprecated starting with Android 11. You can use `JobIntentService` as a replacement for `IntentService` that is compatible with newer versions of Android. 9 | 10 | | `Service` | `IntentService` | 11 | |---|---| 12 | | Is invoked using `startService()` | Is invoked using `Intent` | 13 | | Can be invoked from any thread | Can in invoked from the Main thread only | 14 | | Runs background operations on the Main Thread of the Application by default. Hence it can block your Application’s UI | Creates a separate worker thread to run background operations | 15 | | Invoked multiple times would create multiple instances. | Invoked multiple times won’t create multiple instances | 16 | | Needs to be stopped using `stopSelf()` or `stopService()` | Automatically stops after the queue is completed. No need to trigger `stopService()` or `stopSelf()` | 17 | | Can run parallel operations | Multiple intent calls are automatically queued and they would be executed sequentially | 18 | 19 | ## Links 20 | https://developer.android.com/guide/components/services 21 | https://www.journaldev.com/20735/android-intentservice-broadcastreceiver 22 | https://stackoverflow.com/questions/15524280/service-vs-intentservice-in-the-android-platform 23 | -------------------------------------------------------------------------------- /Android/View lifecycle.md: -------------------------------------------------------------------------------- 1 | # View lifecycle 2 | `View` class represents the basic building block for user interface components. A View occupies a rectangular area on the screen and is responsible for drawing and event handling. View is the base class for *widgets*, which are used to create interactive UI components (buttons, text fields, etc.). 3 | 4 | Every `Activity` has it’s own lifecycle similarly Views also have a lifecycle. A view which was rendered on the screen must undergo these lifecycle methods to get drawn on the screen correctly. 5 | 6 | ![](./res/view_lifecycle.png "View lifecycle") 7 | 8 | - `onAttachedToWindow()` - Called when the view is attached to a window. This is the phase where the view knows it can be active and has a surface for drawing. So we can start allocating any resources or set up listeners. 9 | - `onFinishInflate()` - Called after a view and all of its children has been inflated from XML. 10 | - `onMeasure(int, int)` - Called to determine the size requirements for this view and all of its children. 11 | - `onLayout(boolean, int, int, int, int)` - Called when this view should assign a size and position to all of its children. 12 | - `onSizeChanged(int, int, int, int)` - Called when the size of this view has changed. 13 | - `onDraw(android.graphics.Canvas)` - Canvas object generated (or updates) has a list of OpenGL-ES commands (displayList) to send to the GPU. Never create objects in `onDraw()` as it gets called a number of times. 14 | - `invalidate()` - method that insists on force reDrawing of a particular view that we wish to show changes. Needs to be called when there was a change in view’s appearance. 15 | - `requestLayout()` - At some point, there is a state change in the view. `requestLayout()` is the signal to the view system that it needs to recalculate the Measure and Layout phase of the views (measure → layout → draw). 16 | - `onDetachedFromWindow()` - This is called when the view is detached from a window. At this point, it no longer has a surface for drawing. This place where you need to stop doing any kind of work that is scheduled or clean up resources that are allocated. This method is called when we call remove view on the `ViewGroup` or when the `Activity` is destroyed etc. 17 | 18 | ## Links 19 | https://proandroiddev.com/the-life-cycle-of-a-view-in-android-6a2c4665b95e 20 | https://codentrick.com/android-view-lifecycle/ 21 | https://medium.com/@sahoosunilkumar/understanding-view-lifecycle-in-android-e42890aab16 22 | https://developer.android.com/reference/android/view/View 23 | -------------------------------------------------------------------------------- /Android/What are Sticky Intent.md: -------------------------------------------------------------------------------- 1 | # Sticky Intent 2 | 3 | Sticky Intent - Sticks with Android, for future broadcast listeners. For example if *BATTERY_LOW* event occurs then that intent will stick with Android so that any future requests for *BATTERY_LOW*, will return the intent. Sticky Intent is also a type of Intent which allows communication between a function and a service sendStickyBroadcast(), performs a sendBroadcast(Intent), the Intent you are sending stays around after the broadcast is complete, so that others can quickly retrieve that data through the return value of registerReceiver(BroadcastReceiver, IntentFilter). In all other ways, this behaves the same as sendBroadcast(Intent). 4 | 5 | ## Links 6 | https://stackoverflow.com/questions/26038839/knowing-about-sticky-intent-in-android 7 | -------------------------------------------------------------------------------- /Android/What are the permission protection levels.md: -------------------------------------------------------------------------------- 1 | ## Protection levels in permission 2 | 3 | **Normal** - The default value. A lower-risk permission that gives requesting applications access to isolated application-level features, with minimal risk to other applications, the system, or the user. The system automatically grants this type of permission to a requesting application at installation, without asking for the user's explicit approval (though the user always has the option to review these permissions before installing). 4 | 5 | **Dangerous** - A higher-risk permission that would give a requesting application access to private user data or control over the device that can negatively impact the user. Because this type of permission introduces potential risk, the system may not automatically grant it to the requesting application. For example, any dangerous permissions requested by an application may be displayed to the user and require confirmation before proceeding, or some other approach may be taken to avoid the user automatically allowing the use of such facilities. 6 | 7 | **Signature** - A permission that the system grants only if the requesting application is signed with the same certificate as the application that declared the permission. If the certificates match, the system automatically grants the permission without notifying the user or asking for the user's explicit approval. 8 | 9 | **SignatureOrSystem** - Old synonym for **"signature|privileged"**. Deprecated in API level 23. 10 | 11 | A permission that the system grants only to applications that are in a dedicated folder on the Android system image or that are signed with the same certificate as the application that declared the permission. Avoid using this option, as the signature protection level should be sufficient for most needs and works regardless of exactly where apps are installed. The "signatureOrSystem" permission is used for certain special situations where multiple vendors have applications built into a system image and need to share specific features explicitly because they are being built together. 12 | 13 | ## Links 14 | https://developer.android.com/guide/topics/manifest/permission-element 15 | -------------------------------------------------------------------------------- /Android/What do you know about DiffUtil.md: -------------------------------------------------------------------------------- 1 | # DiffUtil 2 | 3 | `DiffUtil` is a utility class that calculates the difference between two lists and outputs a list of update operations that converts the first list into the second one. 4 | 5 | It can be used to calculate updates for a RecyclerView Adapter. See [ListAdapter](https://developer.android.com/reference/androidx/recyclerview/widget/ListAdapter) and [AsyncListDiffer](https://developer.android.com/reference/androidx/recyclerview/widget/AsyncListDiffer) which can simplify the use of `DiffUtil` on a background thread. 6 | 7 | `DiffUtil` uses Eugene W. Myers's difference algorithm to calculate the minimal number of updates to convert one list into another. Myers's algorithm does not handle items that are moved so DiffUtil runs a second pass on the result to detect items that were moved. 8 | 9 | Note that `DiffUtil`, `ListAdapter`, and `AsyncListDiffer` require the list to not mutate while in use. This generally means that both the lists themselves and their elements (or at least, the properties of elements used in diffing) should not be modified directly. Instead, new lists should be provided any time content changes. It's common for lists passed to `DiffUtil` to share elements that have not mutated, so it is not strictly required to reload all data to use `DiffUtil`. 10 | 11 | If the lists are large, this operation may take significant time so you are advised to run this on a background thread, get the `DiffUtil.DiffResult` then apply it on the `RecyclerView` on the main thread. 12 | 13 | ## DiffUtil.Callback 14 | `DiffUtil.Callback` class used by `DiffUtil` while calculating the diff between two lists. 15 | 16 | | `Method` | `Description` | 17 | |---|---| 18 | | `abstract Boolean areContentsTheSame(oldItemPosition: Int, newItemPosition: Int)` | Called by the `DiffUtil` when it wants to check whether two items have the same data. | 19 | | `abstract Boolean areItemsTheSame(oldItemPosition: Int, newItemPosition: Int)` | Called by the `DiffUtil` to decide whether two object represent the same Item. | 20 | | `open Any? getChangePayload(oldItemPosition: Int, newItemPosition: Int)` | When `areItemsTheSame(int, int)` returns `true` for two items and `areContentsTheSame(int, int)` returns false for them, `DiffUtil` calls this method to get a payload about the change. | 21 | | `abstract Int getNewListSize()` | Returns the size of the new list. | 22 | | `abstract Int getOldListSize()` | Returns the size of the old list. | 23 | 24 | # Links 25 | https://developer.android.com/reference/androidx/recyclerview/widget/DiffUtil 26 | https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DiffUtil.Callback 27 | https://medium.com/@iammert/using-diffutil-in-android-recyclerview-bdca8e4fbb00 28 | -------------------------------------------------------------------------------- /Android/What do you know about Parcelable.md: -------------------------------------------------------------------------------- 1 | # Parcelable 2 | 3 | `Parcelable` used for pass data between components. `Parcelable` is the analog of Java `Serializable` interface with optimization for mobile devices. It assumes a certain structure and way of processing it. 4 | 5 | Classes implementing the `Parcelable` interface must also have a non-null static field called `CREATOR` of a type that implements the `Parcelable.Creator` interface. 6 | 7 | A typical implementation of `Parcelable` is: 8 | 9 | ``` 10 | public class MyParcelable implements Parcelable { 11 | private int mData; 12 | 13 | public int describeContents() { 14 | return 0; 15 | } 16 | 17 | public void writeToParcel(Parcel out, int flags) { 18 | out.writeInt(mData); 19 | } 20 | 21 | public static final Parcelable.Creator CREATOR 22 | = new Parcelable.Creator() { 23 | public MyParcelable createFromParcel(Parcel in) { 24 | return new MyParcelable(in); 25 | } 26 | 27 | public MyParcelable[] newArray(int size) { 28 | return new MyParcelable[size]; 29 | } 30 | }; 31 | 32 | private MyParcelable(Parcel in) { 33 | mData = in.readInt(); 34 | } 35 | } 36 | ``` 37 | 38 | We can now pass the parcelable data between activities within an intent: 39 | ``` 40 | MyParcelable info = new MyParcelable(); 41 | Intent i = new Intent(this, NewActivity.class); 42 | i.putExtra("parcelableKey", info); 43 | startActivity(i); 44 | ``` 45 | 46 | For obtaining information in `NewActivity` should do next: 47 | ``` 48 | public class NewActivity extends Activity { 49 | @Override 50 | protected void onCreate(Bundle savedInstanceState) { 51 | MyParcelable info = (MyParcelable) getIntent().getParcelableExtra("parcelableKey"); 52 | } 53 | } 54 | ``` 55 | 56 | Resources for simplified generate the boilerplate code for creating `Parcelables`: 57 | - [parcelabler](http://www.parcelabler.com/) 58 | - [Android studio plugin](https://github.com/mcharmas/android-parcelable-intellij-plugin) 59 | - [Kotlin `@Parcelize`](https://kotlinlang.org/docs/reference/compiler-plugins.html#parcelable-implementations-generator) 60 | 61 | ## Links 62 | https://developer.android.com/reference/android/os/Parcelable 63 | https://guides.codepath.com/android/using-parcelable 64 | https://www.vogella.com/tutorials/AndroidParcelable/article.html 65 | -------------------------------------------------------------------------------- /Android/What do you know about RecyclerView ItemDecoration.md: -------------------------------------------------------------------------------- 1 | # RecyclerView.ItemDecoration 2 | An ItemDecoration allows the application to add a special drawing and layout offset to specific item views from the adapter's data set. This can be useful for drawing dividers between items, highlights, visual grouping boundaries and more. 3 | 4 | All ItemDecorations are drawn in the order they were added, before the item views(in `onDraw()` and after the items (in `onDrawOver(Canvas, RecyclerView, RecyclerView.State`). 5 | 6 | Multiple ItemDecorations can be added to a single `RecyclerView`. 7 | 8 | A few examples of `ItemDecoration`: 9 | 10 | `ItemDecoration` for set top and bottom margins: 11 | 12 | ``` 13 | import android.graphics.Rect 14 | import android.view.View 15 | import androidx.recyclerview.widget.RecyclerView 16 | 17 | class TopBottomMarginItemDecoration( 18 | private val topMargin: Int, 19 | private val bottomMargin: Int 20 | ) : RecyclerView.ItemDecoration() { 21 | 22 | override fun getItemOffsets( 23 | outRect: Rect, 24 | view: View, 25 | parent: RecyclerView, 26 | state: RecyclerView.State 27 | ) { 28 | with(outRect) { 29 | top = topMargin 30 | bottom = bottomMargin 31 | } 32 | } 33 | } 34 | ``` 35 | 36 | `ItemDecoration` for set right and left margins: 37 | 38 | ``` 39 | import android.graphics.Rect 40 | import android.view.View 41 | import androidx.recyclerview.widget.RecyclerView 42 | 43 | class EdgesMarginItemDecoration(private val edgesMargin: Int) : RecyclerView.ItemDecoration() { 44 | 45 | override fun getItemOffsets( 46 | outRect: Rect, 47 | view: View, 48 | parent: RecyclerView, 49 | state: RecyclerView.State 50 | ) { 51 | with(outRect) { 52 | val position = parent.getChildAdapterPosition(view) 53 | when (position) { 54 | 0 -> { 55 | left = edgesMargin 56 | right = edgesMargin / 2 57 | } 58 | parent.adapter!!.itemCount - 1 -> { 59 | right = edgesMargin 60 | left = edgesMargin / 2 61 | } 62 | else -> { 63 | left = edgesMargin / 2 64 | right = edgesMargin / 2 65 | } 66 | } 67 | } 68 | } 69 | } 70 | ``` 71 | 72 | # Links 73 | [RecyclerView.ItemDecoration](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration) 74 | 75 | # Further reading 76 | [ItemDecoration in Android](https://proandroiddev.com/itemdecoration-in-android-e18a0692d848) -------------------------------------------------------------------------------- /Android/What do you know about slices.md: -------------------------------------------------------------------------------- 1 | # Slices 2 | Slices are UI templates that can display rich, dynamic, and interactive content from your app from within the Google Search app and also in other places like the Google Assistant. Slices can help users perform tasks faster by enabling engagement outside of the fullscreen app experience. 3 | 4 | Components can display small, customizable search content called slices as part of search results. 5 | 6 | ![](./res/slices_image_1.png "Slices image 1") 7 | 8 | ## Principles 9 | 10 | Slices focus on one task, or a set of related tasks, and highlight the most important information. Slices reflect content or features from your app. 11 | 12 | **Focused** 13 | 14 | ![](./res/slices_image_2.png "Slices image 2") 15 | 16 | Slices focus on one task, or a set of related tasks, and highlight the most important information. 17 | 18 | **Related** 19 | 20 | ![](./res/slices_image_3.png "Slices image 3") 21 | 22 | Slices reflect content or features from your app. 23 | 24 | **Relevant** 25 | 26 | ![](./res/slices_image_4.png "Slices image 4") 27 | 28 | Slices provide only the information and controls needed to complete a task. 29 | 30 | ## Examples 31 | 32 | **Navigation**. Slices provide navigation to a specific feature, or content, in an app. 33 | 34 | ![](./res/slices_image_5.png "Slices image 5") 35 | 36 | **Task completion**. Slices allow users to complete tasks inline, such as by displaying controls like toggles or sliders. 37 | 38 | ![](./res/slices_image_6.png "Slices image 6") 39 | 40 | **Content discovery**. Slices remind users of past interactions with an app’s content and features. 41 | 42 | ![](./res/slices_image_7.png "Slices image 7") 43 | 44 | # Links 45 | [Slices](https://developer.android.com/guide/slices) 46 | 47 | [Android slices](https://material.io/design/platform-guidance/android-slices.html) 48 | 49 | # Further reading 50 | [Android Slices: Build interactive results for Google Search](https://www.youtube.com/watch?v=a7IVH5aNwwc) 51 | 52 | [Android Jetpack: Android Slices (Part-1) Introduction](https://proandroiddev.com/android-jetpack-android-slices-introduction-cf0ce0f3e885) 53 | 54 | [Android Jetpack: Android Slices Part-2](https://proandroiddev.com/android-jetpack-android-slices-part-2-688bede57f2d) 55 | -------------------------------------------------------------------------------- /Android/What is AndroidManifest.md: -------------------------------------------------------------------------------- 1 | # AndroidManifest 2 | 3 | The `AndroidManifest.xml` file contains information of your package, including components of the application such as activities, services, broadcast receivers, content providers etc. 4 | 5 | ## Responsibilities 6 | 7 | - Protect the application to access any protected parts by providing the permissions. 8 | - Declares the android api that the application is going to use. 9 | - Declares lists the instrumentation classes. The instrumentation classes provides profiling and other informations. 10 | - Specify whether app should be install on an SD card of the internal memory. 11 | 12 | ## Nodes 13 | 14 | - **uses-sdk** - It is used to define a minimum and maximum SDK version that must be available on a device so that our application function properly. However, beware that attributes in the **** element are overridden by corresponding properties in the `build.gradle` 15 | 16 | - **uses-configuration** - The uses-configuration nodes are used to specify the combination of input mechanisms that are supported by our application. 17 | 18 | - **uses-features** - It is used to specify which hardware and software features your app needs. 19 | 20 | - **supports-screens** - It is used to describe the screen support for application. 21 | 22 | - **permission** - It is used to create permissions to restrict access to shared application components. Also used the existing platform permissions for this purpose or define your own permissions in the manifest. 23 | 24 | - **application** - The declaration of the application. This element contains subelements that declare each of the application's components (such as *Activity*, *Service*, *Content Provider*, and *Broadcast Receiver*) and has attributes that can affect all the components. 25 | 26 | ## Links 27 | https://developer.android.com/guide/topics/manifest/manifest-intro 28 | https://www.geeksforgeeks.org/application-manifest-file-android/ 29 | -------------------------------------------------------------------------------- /Android/What is Overdraw.md: -------------------------------------------------------------------------------- 1 | # Overdraw 2 | 3 | An app may draw the same pixel more than once within a single frame, an event called overdraw. Overdraw is usually unnecessary, and best eliminated. It manifests itself as a performance problem by wasting GPU time to render pixels that don't contribute to what the user sees on the screen. 4 | 5 | ## Links 6 | https://developer.android.com/topic/performance/rendering/overdraw 7 | https://medium.com/wenable/overdraw-in-android-b3ecaaa620b5 8 | -------------------------------------------------------------------------------- /Android/What is StrictMode.md: -------------------------------------------------------------------------------- 1 | # `StrictMode` 2 | 3 | `StrictMode` is a developer tool which detects things you might be doing by accident and brings them to your attention so you can fix them. 4 | 5 | `StrictMode` is most commonly used to catch accidental disk or network access on the application's main thread, where UI operations are received and animations take place. Keeping disk and network operations off the main thread makes for much smoother, more responsive applications. By keeping your application's main thread responsive, you also prevent ANR dialogs from being shown to users.[1](https://developer.android.com/reference/android/os/StrictMode#:~:text=StrictMode%20is%20a,shown%20to%20users.) 6 | 7 | Example code to enable from early in your `Application`, `Activity`, or other application component's `Application.onCreate()` method: 8 | ``` 9 | override fun onCreate(savedInstanceState: Bundle?) { 10 | super.onCreate(savedInstanceState) 11 | StrictMode.setThreadPolicy( 12 | StrictMode.ThreadPolicy.Builder() 13 | .detectAll() 14 | .build() 15 | ) 16 | StrictMode.setVmPolicy( 17 | StrictMode.VmPolicy.Builder() 18 | .detectAll() 19 | .build() 20 | ) 21 | } 22 | ``` 23 | 24 | You can decide what should happen when a violation is detected. For example, using `StrictMode.ThreadPolicy.Builder.penaltyLog()` you can watch the output of adb logcat while you use your application to see the violations as they happen.[2](https://developer.android.com/reference/android/os/StrictMode#:~:text=Example%20code%20to,as%20they%20happen.) 25 | 26 | ## [Penalty Types](https://medium.com/@sandeepkella23/strictmode-your-android-apps-watchdog-4c97be188d57#:~:text=.onCreate()%3B%0A%7D-,Penalty%20Types,-StrictMode%20uses%20penalties) 27 | `StrictMode` uses penalties to signal violations: 28 | - `penaltyLog()`. Logs the violation in the system logcat, making it easy to see what went wrong; 29 | - `penaltyDeath()`. A drastic measure, forcing the app to crash on a violation. Useful for catching severe problems immediately; 30 | - `penaltyDialog()`. This would display a dialog to the user (not typically used in production). 31 | 32 | **Note**: The exact policies offered by `StrictMode` have evolved over Android versions. 33 | 34 | # Links 35 | [StrictMode](https://developer.android.com/reference/android/os/StrictMode) 36 | 37 | [StrictMode: Your Android App’s Watchdog](https://medium.com/@sandeepkella23/strictmode-your-android-apps-watchdog-4c97be188d57) 38 | 39 | # Further reading 40 | [Smooth Operator: Using StrictMode to make your Android App ANR free](https://riggaroo.dev/smooth-operator-using-strictmode-to-make-your-android-app-anr-free/) 41 | 42 | [Android Best Practices: StrictMode](https://code.tutsplus.com/android-best-practices-strictmode--mobile-7581t) 43 | 44 | [Raising the Bar with Android StrictMode](https://medium.com/wizeline-mobile/raising-the-bar-with-android-strictmode-7042d8a9e67b) 45 | -------------------------------------------------------------------------------- /Android/What is SurfaceView.md: -------------------------------------------------------------------------------- 1 | # SurfaceView 2 | 3 | `SurfaceView` can be updated on the background thread. 4 | 5 | - `SurfaceView` has dedicate surface buffer while all the view share one surface buffer that is allocated by ViewRoot. In another word, `SurfaceView` cost more resources. 6 | 7 | - `SurfaceView` cannot be hardware accelerated (as of JB4.2) while 95% operations on normal View are HW accelerated using openGL ES. 8 | 9 | - More work should be done to create your customized `SurfaceView`. You need to listener to the surfaceCreated/Destroy Event, create a render thread, more importantly, synchronized the render thread and main thread. 10 | 11 | - The timing to update is different. Normal view update mechanism is constraint or controlled by the framework: You call `view.invalidate()` in the UI thread or `view.postInvalidate()` in other thread to indicate to the framework that the view should be updated. However, the view won't be updated immediately but wait until next VSYNC event arrived. The easy approach to understand VYSNC is to consider it is as a timer that fire up every 16ms for a 60fps screen. In Android, all the normal view update, is synchronized with VSYNC to achieve better smoothness. 12 | 13 | ## Links 14 | https://developer.android.com/reference/android/view/SurfaceView 15 | -------------------------------------------------------------------------------- /Android/What is installLocation tag in AndroidManifest.md: -------------------------------------------------------------------------------- 1 | # installLocation tag 2 | 3 | `installLocation` is the tag in AndroidManifest that configure default install location for the app. The following keyword strings are accepted: 4 | 5 | | Value | Description | 6 | |---|---| 7 | | internalOnly | The app must be installed on the internal device storage only. If this is set, the app will never be installed on the external storage. If the internal storage is full, then the system will not install the app. This is also the default behavior if you do not define `android:installLocation`. | 8 | | auto | The app may be installed on the external storage, but the system will install the app on the internal storage by default. If the internal storage is full, then the system will install it on the external storage. Once installed, the user can move the app to either internal or external storage through the system settings. | 9 | | preferExternal | The app prefers to be installed on the external storage (SD card). There is no guarantee that the system will honor this request. The app might be installed on internal storage if the external media is unavailable or full. Once installed, the user can move the app to either internal or external storage through the system settings. | 10 | 11 | When an app is installed on the external storage: 12 | - The `.apk` file is saved to the external storage, but any app data (such as databases) is still saved on the internal device memory. 13 | - The container in which the `.apk` file is saved is encrypted with a key that allows the app to operate only on the device that installed it. (A user cannot transfer the SD card to another device and use apps installed on the card.) Though, multiple SD cards can be used with the same device. 14 | - At the user's request, the app can be moved to the internal storage. 15 | 16 | The user may also request to move an app from the internal storage to the external storage. However, the system will not allow the user to move the app to external storage if this attribute is set to `internalOnly`, which is the default setting. 17 | 18 | ## Links 19 | https://developer.android.com/guide/topics/manifest/manifest-element 20 | https://developer.android.com/guide/topics/data/install-location 21 | -------------------------------------------------------------------------------- /Android/What is savedInstanceState bundle.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1. **Bundle savedInstanceState** is a reference to the Bundle object that is passed to the `onCreate()` in an Activity. Activities have capability to restore themselves to a previous state using the stored in the Bundle. 5 | 6 | 2. First time the `bundle` object is always `null`. If some data is stored in the bundle object during the Activity lifecycle and Activity is recreated due to rotation then the `bundle` object will be `non-null`. 7 | 8 | During the Activity Lifecycle save the data in `onSaveInstanceState()` 9 | 10 | ``` 11 | 12 | int scrolledPosition = 0; 13 | 14 | @Override 15 | public void onSaveInstanceState(Bundle outState) { 16 | super.onSaveInstanceState(outState); 17 | outState.putInt("scrolled_position",scrolledPosition); 18 | } 19 | 20 | ``` 21 | 22 | After the orientation when the Activity is recreated and `onCreate()` is called 23 | 24 | ``` 25 | int scrolledPosition = 0; 26 | 27 | @Override 28 | public void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | if(savedInstanceState == null){ 31 | scrolledPosition = 0; 32 | }else{ 33 | scrolledPosition = savedInstanceState.getInt("scrolled_position",0); 34 | } 35 | } 36 | ``` 37 | 38 | There is an alternative way of restoring state , `onRestoreInstanceState()` which system calls after `onStart()`. The system calls `onRestoreInstanceState()` only if there is a state to restore. So there is no need to check if `bundle` object is `null`. 39 | 40 | int scrolledPosition = 0; 41 | 42 | public void onRestoreInstanceState(Bundle savedInstanceState) { 43 | // Always call the superclass so it can restore the view hierarchy 44 | super.onRestoreInstanceState(savedInstanceState); 45 | 46 | // Restore state members from saved instance 47 | scrolledPosition = savedInstanceState.getInt("scrolled_position",0); 48 | } 49 | 50 | 51 | 52 | 53 | **Note:** 54 | Always call the superclass implementation of `onRestoreInstanceState()`so the default implementation can restore the state of the view hierarchy. 55 | 56 | 57 | **What kind of data should be stored in `bundle` object** 58 | 59 | 60 | 61 | 1. User selections 62 | 63 | 2. Scroll positions 64 | 65 | 3. User submitted data 66 | 67 | 68 | 69 | **What kind of data shouldn't be stored in `bundle` object** 70 | 71 | 72 | 73 | 1. Bitmap 74 | 75 | 2. File 76 | 77 | 3. Big Model classes(POJO) 78 | 79 | **Reference Link:** 80 | 81 | https://developer.android.com/guide/components/activities/activity-lifecycle#restore-activity-ui-state-using-saved-instance-state 82 | -------------------------------------------------------------------------------- /Android/What is the difference between Activity and Fragment.md: -------------------------------------------------------------------------------- 1 | # `Activity` vs `Fragment` 2 | `Activity` is a crucial component of an application that provides a user interface for interacting with the app. Each `Activity` represents a single screen with which users can engage, similar to a window in a desktop application. `Activity` can serve as a host for fragments and `@Composable` functions, and it can also have its own UI. 3 | 4 | A `Fragment` represents a reusable portion of your app's UI. A fragment defines and manages its own layout, has its own lifecycle, and can handle its own input events. Fragments can't live on their own. They must be *hosted* by an activity or another fragment. The fragment’s view hierarchy becomes part of, or *attaches* to, the host’s view hierarchy. 5 | [1](https://developer.android.com/guide/fragments#samples:~:text=A%20Fragment%20represents,host%E2%80%99s%20view%20hierarchy.) 6 | 7 | | `Activity` | `Fragment` | 8 | |---|---| 9 | | A standalone component that doesn’t depend on anything else | A reusable UI component that must be hosted within an `Activity` or another `Fragment` | 10 | | Has its own independent lifecycle managed by the OS | Has a lifecycle tied to the hosting `Activity` but with additional lifecycle states | 11 | | Must be registered in the `AndroidManifest.xml` file | Does not need to be registered anywhere | 12 | | Can be launched from other applications | Cannot be launched from other applications | 13 | | Data transfer between activities requires serialization | Data transfer between fragments does not require serialization | 14 | | Can be resource-intensive | More lightweight, as multiple fragments can exist within a single `Activity` | 15 | | Managed by the system’s back stack | Managed by the `FragmentManager` back stack within an `Activity` or another `Fragment` | 16 | 17 | # Links 18 | [Introduction to activities](https://developer.android.com/guide/components/activities/intro-activities) 19 | 20 | [Fragments](https://developer.android.com/guide/fragments) 21 | 22 | # Next questions 23 | [How to communicate with fragments?](https://github.com/Kirchhoff-/Android-Interview-Questions/blob/master/Android/How%20to%20communicate%20with%20fragments.md) 24 | 25 | [What is Jetpack Compose?](https://github.com/Kirchhoff-/Android-Interview-Questions/blob/master/Android/What%20is%20Jetpack%20Compose.md) 26 | -------------------------------------------------------------------------------- /Android/What is the difference between Dialog & DialogFragment.md: -------------------------------------------------------------------------------- 1 | # Dialog vs DialogFragment 2 | 3 | The `Dialog` class is the base class for dialogs, but you should avoid instantiating `Dialog` directly. Instead, use one of it's subclasses. `Dialogs` are entirely dependent on Activities. If the screen is rotated, the dialog is dismissed. 4 | 5 | A `DialogFragment` is a fragment that displays a dialog window, floating on top of its activity's window. This fragment contains a `Dialog` object, which it displays as appropriate based on the fragment's state. Using `DialogFragment` to manage the dialog ensures that it correctly handles lifecycle events such as when the user presses the Back button or rotates the screen. 6 | 7 | ## Links 8 | https://developer.android.com/reference/android/app/Dialog.html 9 | https://developer.android.com/reference/android/app/DialogFragment 10 | https://developer.android.com/guide/topics/ui/dialogs 11 | -------------------------------------------------------------------------------- /Android/What is the difference between Serializable and Parcelable.md: -------------------------------------------------------------------------------- 1 | # Serializable vs Parcelable 2 | 3 | ## Serializable 4 | Serializable is a standard Java interface. For the serializable class just implement the Serializable interface and add override methods. This approach is a slow process. Its create a lot of temporary objects and a bit of garbage collection but the serializable interface is easier to implement. Java will automatically serialize it in certain situations. 5 | 6 | ## Parcelable 7 | Parcelable is another interface. Despite its rival (Serializable in case you forgot), it is a part of the Android SDK. Now, Parcelable was specifically designed in such a way that there is no reflection when using it. That is because we are being really explicit for the serialization process. 8 | 9 | ## Conclusion 10 | - **Parcelable** is faster than **Serializable** interface 11 | - **Parcelable** interface takes more time to implement compared to **Serializable** interface (with Kotlin this is not true) 12 | - **Serializable** interface is easier to implement 13 | - **Serializable** interface creates a lot of temporary objects and causes quite a bit of garbage collection 14 | 15 | ## Links 16 | https://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html 17 | https://developer.android.com/reference/android/os/Parcelable.html 18 | https://android.jlelse.eu/parcelable-vs-serializable-6a2556d51538 19 | -------------------------------------------------------------------------------- /Android/What's ContentProvider.md: -------------------------------------------------------------------------------- 1 | # Content Provider 2 | 3 | A content provider manages access to a central repository of data. You implement a provider as one or more classes in an Android application, along with elements in the manifest file. One of your classes implements a subclass `ContentProvider`, which is the interface between your provider and other applications. Although content providers are meant to make data available to other applications, you may of course have activities in your application that allow the user to query and modify the data managed by your provider. 4 | 5 | You need to build a content provider if you want to provide one or more of the following features: 6 | - You want to offer complex data or files to other applications. 7 | - You want to allow users to copy complex data from your app into other apps. 8 | - You want to provide custom search suggestions using the search framework. 9 | - You want to expose your application data to widgets. 10 | - You want to implement the `AbstractThreadedSyncAdapter`, `CursorAdapter`, or `CursorLoader` classes. 11 | 12 | You don't need a provider to use databases or other types of persistent storage if the use is entirely within your own application and you don’t need any of the features listed above. 13 | 14 | To understand how it works, consider the following diagram: 15 | 16 | ![](./res/content_provider.jpg "Content provider") 17 | 18 | ## Content URIs 19 | 20 | Content URIs are the uniform resource identifiers that identify the data in the content providers. A content URI includes two things: *Authority* that is the symbolic name of the Provider and a *Path* that is a name that points towards the data. Every content provider methods have an argument which is URI. URIs for content providers look like this: 21 | 22 | `content:////` 23 | 24 | - **content://** – It’s always present, and is the scheme portion of the URI. 25 | - **authority** – It is the unique name of the content provider, like photos, contacts. It’s a string that can identify the whole content provider. 26 | - **path** – It is often used to identify some or the other data of the provider. The path is mostly used to identify individual tables. 27 | - **optional_id** – id is used to access a single particular record of a file. We use this only in cases where we need to access only a particular record and not the complete file. It’s a numeric identifier to access a particular row of the data table. 28 | 29 | ## Links 30 | https://developer.android.com/guide/topics/providers/content-provider-creating 31 | https://medium.com/@saranyaan2710/content-provider-in-android-basics-d219cf42574d 32 | https://data-flair.training/blogs/content-provider-in-android/ 33 | -------------------------------------------------------------------------------- /Android/What's ViewGroup How are they different from Views.md: -------------------------------------------------------------------------------- 1 | # ViewGroup 2 | 3 | ![](./res/view_hierarchy.png "View hierarchy") 4 | 5 | A `ViewGroup` is a special view that can contain other views (called children.) The view group is the base class for layouts and views containers. This class also defines the `ViewGroup.LayoutParams` class which serves as the base class for layouts parameters. 6 | 7 | ViewGroups is invisible container in which other Views can be placed. The class `ViewGroup` extends the class `View` 8 | Popular ViewGroups: 9 | - LineraLayout 10 | - RelativeLayout 11 | - RelativeLayout 12 | - MotionLayout 13 | - ConstraintLayout 14 | 15 | `View` represents the basic building block for user interface components. A View occupies a rectangular area on the screen and is responsible for drawing and event handling. 16 | 17 | Popular Views: 18 | - TextView 19 | - ImageView 20 | - EditText 21 | - Button 22 | - SeekBar 23 | 24 | Summary: 25 | 26 | `View`: 27 | - `View` objects are the basic building blocks of User Interface(UI) elements in Android. 28 | - `View` is a simple rectangle box which responds to the user's actions. 29 | - `View` refers to the android.view.View class, which is the base class of all UI classes. 30 | 31 | `ViewGroup`: 32 | - `ViewGroup` is the invisible container. It holds `View` and `ViewGroup` 33 | - `ViewGroup` is the base class for Layouts. 34 | 35 | ## Links 36 | https://developer.android.com/reference/android/view/View 37 | https://developer.android.com/reference/android/view/ViewGroup 38 | https://stackoverflow.com/questions/27352476/difference-between-view-and-viewgroup-in-android 39 | https://proandroiddev.com/the-life-cycle-of-a-view-in-android-6a2c4665b95e 40 | -------------------------------------------------------------------------------- /Android/What's ViewStub.md: -------------------------------------------------------------------------------- 1 | # ViewStub 2 | 3 | A `ViewStub` is an invisible, zero-sized View that can be used to lazily inflate layout resources at runtime. When a ViewStub is made visible, or when `inflate()` is invoked, the layout resource is inflated. The ViewStub then replaces itself in its parent with the inflated View or Views. Therefore, the ViewStub exists in the view hierarchy until `setVisibility(int)` or `inflate()` is invoked. The inflated View is added to the ViewStub's parent with the ViewStub's layout parameters. Similarly, you can define/override the inflate View's id by using the ViewStub's inflatedId property. For instance: 4 | 5 | ```xml 6 | 12 | ``` 13 | The `ViewStub` thus defined can be found using the id "stub." After inflation of the layout resource "mySubTree," the `ViewStub` is removed from its parent. The `View` created by inflating the layout resource "mySubTree" can be found using the id "subTree," specified by the inflatedId property. The inflated `View` is finally assigned a width of 120dip and a height of 40dip. The preferred way to perform the inflation of the layout resource is the following: 14 | 15 | `ViewStub stub = findViewById(R.id.stub); 16 | View inflated = stub.inflate();` 17 | 18 | When `inflate()` is invoked, the `ViewStub` is replaced by the inflated View and the inflated View is returned. This lets applications get a reference to the inflated `View` without executing an extra `findViewById()`. 19 | 20 | ## Links 21 | https://developer.android.com/reference/android/view/ViewStub 22 | https://stackoverflow.com/questions/11577777/how-to-use-view-stub-in-android 23 | https://proandroiddev.com/viewstub-on-demand-inflate-view-or-inflate-lazily-layout-resource-e56b8c39398b 24 | -------------------------------------------------------------------------------- /Android/res/activity_lifecycle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/activity_lifecycle.png -------------------------------------------------------------------------------- /Android/res/anr_example_framed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/anr_example_framed.png -------------------------------------------------------------------------------- /Android/res/app_modules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/app_modules.png -------------------------------------------------------------------------------- /Android/res/app_signing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/app_signing.png -------------------------------------------------------------------------------- /Android/res/appearance_affecting_spans.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/appearance_affecting_spans.png -------------------------------------------------------------------------------- /Android/res/build_type.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/build_type.png -------------------------------------------------------------------------------- /Android/res/cold_start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/cold_start.png -------------------------------------------------------------------------------- /Android/res/compose_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/compose_1.png -------------------------------------------------------------------------------- /Android/res/content_provider.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/content_provider.jpg -------------------------------------------------------------------------------- /Android/res/context.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/context.png -------------------------------------------------------------------------------- /Android/res/context_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/context_table.png -------------------------------------------------------------------------------- /Android/res/data_modules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/data_modules.png -------------------------------------------------------------------------------- /Android/res/debug_broadcast_receiver_timeout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/debug_broadcast_receiver_timeout.png -------------------------------------------------------------------------------- /Android/res/debug_content_provider_anr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/debug_content_provider_anr.png -------------------------------------------------------------------------------- /Android/res/debug_execute_service_anr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/debug_execute_service_anr.png -------------------------------------------------------------------------------- /Android/res/debug_input_dispatch_anr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/debug_input_dispatch_anr.png -------------------------------------------------------------------------------- /Android/res/diagram_backstack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/diagram_backstack.png -------------------------------------------------------------------------------- /Android/res/diagram_multitasking.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/diagram_multitasking.png -------------------------------------------------------------------------------- /Android/res/downloadable_fonts_process.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/downloadable_fonts_process.png -------------------------------------------------------------------------------- /Android/res/feature_modules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/feature_modules.png -------------------------------------------------------------------------------- /Android/res/fragment-a-to-b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/fragment-a-to-b.png -------------------------------------------------------------------------------- /Android/res/fragment_add_replace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/fragment_add_replace.png -------------------------------------------------------------------------------- /Android/res/fragment_lifecycle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/fragment_lifecycle.png -------------------------------------------------------------------------------- /Android/res/fragment_stop_save_order.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/fragment_stop_save_order.png -------------------------------------------------------------------------------- /Android/res/fragments.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/fragments.png -------------------------------------------------------------------------------- /Android/res/handler_looper_message.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/handler_looper_message.jpeg -------------------------------------------------------------------------------- /Android/res/hot_start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/hot_start.png -------------------------------------------------------------------------------- /Android/res/layout-editor_2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/layout-editor_2x.png -------------------------------------------------------------------------------- /Android/res/lint_tool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/lint_tool.png -------------------------------------------------------------------------------- /Android/res/metric_affecting_spans.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/metric_affecting_spans.png -------------------------------------------------------------------------------- /Android/res/modularization_dependency_graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/modularization_dependency_graph.png -------------------------------------------------------------------------------- /Android/res/module_mediator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/module_mediator.png -------------------------------------------------------------------------------- /Android/res/modules_di_concept.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/modules_di_concept.png -------------------------------------------------------------------------------- /Android/res/modules_shared_data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/modules_shared_data.png -------------------------------------------------------------------------------- /Android/res/ninepatch_raw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/ninepatch_raw.png -------------------------------------------------------------------------------- /Android/res/nodpi_anydpi_source.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/nodpi_anydpi_source.png -------------------------------------------------------------------------------- /Android/res/notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/notification.png -------------------------------------------------------------------------------- /Android/res/paging_library_architecture.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/paging_library_architecture.webp -------------------------------------------------------------------------------- /Android/res/paragraph_affecting_spans.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/paragraph_affecting_spans.png -------------------------------------------------------------------------------- /Android/res/pass-parent-child.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/pass-parent-child.png -------------------------------------------------------------------------------- /Android/res/pinned_shortcuts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/pinned_shortcuts.png -------------------------------------------------------------------------------- /Android/res/product_flavor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/product_flavor.png -------------------------------------------------------------------------------- /Android/res/room.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/room.png -------------------------------------------------------------------------------- /Android/res/service_lifecycle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/service_lifecycle.png -------------------------------------------------------------------------------- /Android/res/singleInstance_scenario_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/singleInstance_scenario_1.png -------------------------------------------------------------------------------- /Android/res/singleTask_scenario_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/singleTask_scenario_1.png -------------------------------------------------------------------------------- /Android/res/singleTask_scenario_1_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/singleTask_scenario_1_2.png -------------------------------------------------------------------------------- /Android/res/singleTask_scenario_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/singleTask_scenario_2.png -------------------------------------------------------------------------------- /Android/res/singleTop_scenario_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/singleTop_scenario_1.png -------------------------------------------------------------------------------- /Android/res/singleTop_scenario_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/singleTop_scenario_2.png -------------------------------------------------------------------------------- /Android/res/sizes-phone-tablet_2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/sizes-phone-tablet_2x.png -------------------------------------------------------------------------------- /Android/res/slices_image_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/slices_image_1.png -------------------------------------------------------------------------------- /Android/res/slices_image_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/slices_image_2.png -------------------------------------------------------------------------------- /Android/res/slices_image_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/slices_image_3.png -------------------------------------------------------------------------------- /Android/res/slices_image_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/slices_image_4.png -------------------------------------------------------------------------------- /Android/res/slices_image_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/slices_image_5.png -------------------------------------------------------------------------------- /Android/res/slices_image_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/slices_image_6.png -------------------------------------------------------------------------------- /Android/res/slices_image_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/slices_image_7.png -------------------------------------------------------------------------------- /Android/res/spannable_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/spannable_table.png -------------------------------------------------------------------------------- /Android/res/test_modules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/test_modules.png -------------------------------------------------------------------------------- /Android/res/view_hierarchy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/view_hierarchy.png -------------------------------------------------------------------------------- /Android/res/view_lifecycle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/view_lifecycle.png -------------------------------------------------------------------------------- /Android/res/viewbinding_vs_databinding.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/viewbinding_vs_databinding.png -------------------------------------------------------------------------------- /Android/res/viewmodel_lifecycle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/viewmodel_lifecycle.png -------------------------------------------------------------------------------- /Android/res/wear_dep_graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/wear_dep_graph.png -------------------------------------------------------------------------------- /Android/res/work_manager_criteria.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Android/res/work_manager_criteria.png -------------------------------------------------------------------------------- /General/Describe Scrum and Kanban.md: -------------------------------------------------------------------------------- 1 | # Scrum vs Kanban 2 | 3 | ## Scrum 4 | 5 | Scrum is an agile process that helps to deliver the business value in the shortest time. It rapidly and repeatedly inspects actual working software. It emphasizes on teamwork and iterative progress of the software. Its goal is to deliver new software every 1-4 weeks. 6 | 7 | ## Kanban 8 | 9 | Kanban is a visual system for managing work. It visualizes both the process and the actual work passing through that process. The main objective of implementing Kanban is to identify potential bottlenecks in the process and fix them. Kanban goal is that work flow should proceed smoothly at an optimal speed. 10 | 11 | ## Conclusion 12 | 13 | | Scrum | Kanban | 14 | |---|---| 15 | | Scrum stresses on planning. It starts with sprint planning and ends up with sprint retrospective. | Kanban is open to making changes on the go. It means there is less rigidity and things can change frequently. | 16 | | It recommends collection of time measurements made during sprints | Kanban recommends graphs to get an overview of team's progress over time. | 17 | | Estimation has a very important role in Scrum | No mandatory requirements for estimation. | 18 | | Every individual has their role and responsibilities. | No set roles so flexibility in term of individual responsibilities. | 19 | | It is not possible to add items to ongoing iterations. | New items can easily add if the additional capacity is available. | 20 | | Measures production using velocity through sprints. | Measures production using cycle time or the exact time it takes to complete one full piece of a project. | 21 | 22 | ## Links 23 | https://www.guru99.com/scrum-vs-kanban.html 24 | https://kanbanize.com/blog/kanban-vs-scrum-infographic/ 25 | https://perfectial.com/blog/scrum-and-kanban-are-they-different/ 26 | -------------------------------------------------------------------------------- /General/Difference between git rebase and git merge.md: -------------------------------------------------------------------------------- 1 | 2 | **git merge** 3 | *`git merge`* simply remembers the history as it happened. It takes the two current versions, merge them together based on their common ancestor, fix any conflicts, and then record the history exactly as it happened. 4 | 5 | **git rebase** 6 | *`git rebase`* attempts to make the history look as simple as possible. It picks one of the two sides to be the base and all the changes on the other side are flattened into a linear series of changes happening afterwards. 7 | git rebase | git merge | 8 | | ------------- | ------------- | 9 | | 1. **git rebase** gets all unique commits from both branches and applies them one by one | 1. **git merge** apply all unique commits from branch A into branch B in one commit with final result. | 10 | | 2. **git rebase** rewrites commit history but doesn’t create extra commit for merging | 2. **git merge** doesn’t rewrite commit history, just adds one new commit. | 11 | 12 | **Links**: 13 | https://git-scm.com/book/en/v2/Git-Branching-Rebasing 14 | https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging#_basic_merging -------------------------------------------------------------------------------- /General/SOLID principles.md: -------------------------------------------------------------------------------- 1 | # SOLID Principles 2 | 3 | SOLID is a mnemonic acronym for five design principles intended to make software designs more understandable, flexible and maintainable. The theory of SOLID principles was introduced by Martin in his 2000 paper Design Principles and Design Patterns, although the SOLID acronym was introduced later by Michael Feathers. 4 | 5 | ## Concepts 6 | - **Single-responsibility principle** - A class should only have a single responsibility, that is, only changes to one part of the software's specification should be able to affect the specification of the class. 7 | - **Open–closed principle** - Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification. 8 | - **Liskov substitution principle** - Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program. 9 | - **Interface segregation principle** - Many client-specific interfaces are better than one general-purpose interface. 10 | - **Dependency inversion principle** - Depend on abstractions, not on concretions. 11 | 12 | # Links 13 | [SOLID](https://en.wikipedia.org/wiki/SOLID) 14 | 15 | [SOLID Principles made easy](https://medium.com/@dhkelmendi/solid-principles-made-easy-67b1246bcdf) 16 | 17 | [SOLID Principles: Explanation and examples](https://itnext.io/solid-principles-explanation-and-examples-715b975dcad4) 18 | 19 | # Further reading 20 | [👨‍💻Kotlin SOLID Principles](https://medium.com/huawei-developers/kotlin-solid-principles-tutorial-examples-192bf8c049dd) -------------------------------------------------------------------------------- /General/What is REST.md: -------------------------------------------------------------------------------- 1 | 2 | **REST**, or **REpresentational State Transfer**, is an architectural style for providing standards between computer systems on the web, making it easier for systems to communicate with each other.**REST**-compliant systems, often called RESTful systems/applications. 3 | 4 | - A RESTful application exposes information about itself in the form 5 | of information about its resources. It also enables the client to 6 | take actions on those resources, such as create new resources (i.e. 7 | create a new user) or change existing resources. 8 | - In web applications its always referred as RESTful APIs as it **REST** compliant.when a developer calls any **REST** API to fetch the resource, the API will return the state of that resource. The representation of the state can be in a JSON format, and probably for most APIs this is indeed the case. It can also be in XML or HTML format. 9 | -------------------------------------------------------------------------------- /General/What is the difference between DI and Service Locator.md: -------------------------------------------------------------------------------- 1 | # Dependency injection vs Service locator 2 | **Dependency injection** is a technique in which an object receives other objects that it depends on, called dependencies. Typically, the receiving object is called a client and the passed-in ('injected') object is called a service. The code that passes the service to the client is called the injector. Instead of the client specifying which service it will use, the injector tells the client what service to use. The 'injection' refers to the passing of a dependency (a service) into the client that uses it. 3 | 4 | The **service locator** pattern is a design pattern used to encapsulate the processes involved in obtaining a service with a strong abstraction layer. This pattern uses a central registry known as the "service locator", which on request returns the information necessary to perform a certain task. 5 | 6 | Both Dependency Injection and the Service Locator pattern are implementations of the Inversion of Control concept. 7 | 8 | Main difference between **DI** and **Service locator**: 9 | - In **DI** dependencies located outside the class that is used them, in other words, class is not responded of creating it's dependencies. It neither knows, nor cares where they come from. With this approach is much easer to test such class, cause it is easy to mock all required dependencies. 10 | 11 | - In **Service locator** class **pulls** all required dependencies from some storage. With this approach, during the testing, we have to go to the class to see all it's dependencies, and only after that, we can mock the storage in which dependencies are located. 12 | 13 | # Links 14 | [Dependency injection](https://en.wikipedia.org/wiki/Dependency_injection) 15 | 16 | [Service locator pattern](https://en.wikipedia.org/wiki/Service_locator_pattern) 17 | 18 | # Next questions 19 | [SOLID Principles](https://github.com/Kirchhoff-/Android-Interview-Questions/blob/master/General/SOLID%20principles.md) 20 | 21 | # Further reading 22 | [Inversion of Control Containers and the Dependency Injection pattern](https://martinfowler.com/articles/injection.html) 23 | 24 | [Dependency Injection or Service Locator](https://medium.com/mobile-app-development-publication/dependency-injection-and-service-locator-4dbe4559a3ba) -------------------------------------------------------------------------------- /General/What is the difference between GET and POST request.md: -------------------------------------------------------------------------------- 1 | # GET vs POST 2 | 3 | **GET** - It requests the data from a specified resource 4 | 5 | Example: 6 | ``` 7 | https://api.themoviedb.org/3/movie/1/account_states 8 | ``` 9 | 10 | Feature: 11 | - Remains in the browser history 12 | - Can be bookmarked 13 | - Can be cached 14 | - Have length restrictions 15 | - Should never be used when dealing with sensitive data 16 | - Should only be used for retrieving the data 17 | 18 | **POST** - It submits the processed data to a specified resource 19 | Example: 20 | ``` 21 | https://api.themoviedb.org/3/movie/1/rating 22 | 23 | RequestBody 24 | { 25 | "value": 8.5 26 | } 27 | ``` 28 | Feature: 29 | - Cannot be bookmarked 30 | - Have no restrictions on length of data 31 | - Never cached 32 | - Do not retain in the browser history 33 | 34 | | GET| POST | 35 | |---|---| 36 | | Passes request parameter in URL | Passes request parameter in request body | 37 | | Parameters remain in browser history because they are part of the URL | Parameters are not saved in browser history | 38 | | Can be bookmarked | Cannot be bookmarked | 39 | | URL length is restricted. A safe URL length limit is often 2048 | No restrictions for data length | 40 | | Only ASCII characters allowed | No restrictions. Binary data is also allowed | 41 | | Mostly used for view purpose (e.g. SQL SELECT) | Mainly use for update purpose (e.g. SQL INSERT or UPDATE) | 42 | 43 | ## Links 44 | https://www.w3schools.com/tags/ref_httpmethods.asp 45 | https://www.diffen.com/difference/GET-vs-POST-HTTP-Requests 46 | https://www.javatpoint.com/get-vs-post 47 | https://developers.themoviedb.org/3/movies 48 | -------------------------------------------------------------------------------- /General/What is the difference between HTTP and HTTPS.md: -------------------------------------------------------------------------------- 1 | # HTTP vs HTTPS 2 | 3 | **HTTP (Hypertext Transfer Protocol)** - is an application protocol for distributed, collaborative, hypermedia information systems. **HTTP** is the foundation of data communication for the World Wide Web, where hypertext documents include hyperlinks to other resources that the user can easily access, for example by a mouse click or by tapping the screen in a web browser. **HTTP** offers set of rules and standards which govern how any information can be transmitted on the World Wide Web. **HTTP** provides standard rules for web browsers & servers to communicate. 4 | 5 | **HTTP** is an application layer network protocol which is built on top of TCP. **HTTP** uses Hypertext structured text which establishes the logical link between nodes containing text. It is also known as "stateless protocol" as each command is executed separately, without using reference of previous run command. 6 | 7 | **HTTPS (Hypertext Transfer Protocol Secure)** - is an extension of the **HTTP** . It is used for secure communication over a computer network, and is widely used on the Internet. In **HTTPS**, the communication protocol is encrypted using Transport Layer Security (TLS) or, formerly, its predecessor, Secure Sockets Layer (SSL). 8 | 9 | The principal motivations for **HTTPS** are authentication of the accessed website, protection of the privacy and integrity of the exchanged data while in transit. It protects against man-in-the-middle attacks. The bidirectional encryption of communications between a client and server protects against eavesdropping and tampering of the communication. In practice, this provides a reasonable assurance that one is communicating without interference by attackers with the website that one intended to communicate with, as opposed to an impostor. 10 | 11 | | HTTP | HTTPS | 12 | |---|---| 13 | | It uses port 80 by default | It was use port 443 by default | 14 | | URLs begin with *http://* | URLs begin with *https://* | 15 | | No encryption before sending data. | Data encrypted before sending | 16 | | Website don't need SSL | Website need SSL | 17 | | Works at Application Layer | Works at Transport Layer | 18 | 19 | # Links 20 | [Hypertext Transfer Protocol](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol) 21 | 22 | [HTTPS](https://en.wikipedia.org/wiki/HTTPS) 23 | 24 | [What Is the Difference Between HTTP and HTTPS?](https://www.keycdn.com/blog/difference-between-http-and-https) 25 | 26 | [What's the difference between HTTP and HTTPS?](https://www.globalsign.com/en/blog/the-difference-between-http-and-https) 27 | 28 | [Difference between http:// and https://](https://www.geeksforgeeks.org/difference-between-http-and-https/) 29 | 30 | [HTTP vs HTTPS: What is Difference Between HTTP and HTTPS? Full Form](https://www.guru99.com/difference-http-vs-https.html) 31 | 32 | -------------------------------------------------------------------------------- /General/What is the difference between PUT and POST request.md: -------------------------------------------------------------------------------- 1 | # PUT vs POST 2 | 3 | **PUT** - It is used to send data to a server to create/update a resource. 4 | 5 | Example: 6 | ``` 7 | http://www.google.com/users/234 8 | 9 | PUT /new.html HTTP/1.1 10 | Host: example.com 11 | Content-type: text/html 12 | Content-length: 20 13 | 14 |

New File

15 | ``` 16 | 17 | Feature: 18 | - Cannot be bookmarked 19 | - Should only be used for update the data 20 | - Never cached 21 | - Do not retain in the browser history 22 | 23 | **POST** - It submits the processed data to a specified resource 24 | Example: 25 | ``` 26 | https://api.themoviedb.org/3/movie/1/rating 27 | 28 | RequestBody 29 | { 30 | "value": 8.5 31 | } 32 | ``` 33 | Feature: 34 | - Cannot be bookmarked 35 | - Have no restrictions on length of data 36 | - Never cached 37 | - Do not retain in the browser history 38 | 39 | | PUT| POST | 40 | |---|---| 41 | | Is idempotent | Is not idempotent | 42 | | If you send the same request multiple times, the result will remain the same | If you send the same POST request more than one time, you will receive different results | 43 | | Mostly used for UPDATE query | Mainly use for create query | 44 | 45 | ## Links 46 | https://www.keycdn.com/support/put-vs-post 47 | https://restfulapi.net/rest-put-vs-post/ 48 | https://www.guru99.com/put-vs-post.html 49 | https://developers.themoviedb.org/3/movies 50 | -------------------------------------------------------------------------------- /General/What is the difference between abstraction and encapsulation.md: -------------------------------------------------------------------------------- 1 | # Abstraction vs Encapsulation 2 | 3 | Abstraction is a basic OOP concept which focuses on just the relevant data of an object and hides all the irrelevant details which may or may not be for generic or specialized behavior. It hides the background details and emphasizes on the essential points to reduce complexity and increase efficiency. Basically, abstraction is a programming tool to manage complexity. Abstraction focuses on ideas rather than events. It hides the details on the design level by providing functionality to the users. The resulting object can also be called an abstraction. The programmer makes sure the named entity will have all the essential aspects included and none of the irrelevant ones. 4 | 5 | Encapsulation is yet another OOP concept which binds data and functions into a single component while restricting access to some components. It’s one of the main fundamental concepts of OOP which wraps data and information under a single unit. In technical terms, encapsulation means hiding attributes to shield variables from outside access so that change in one part of an application won’t affect the other parts. On the contrary, by making the information more open you’ll risk misuse of data. It provides basic integrity to the data by protecting it from the outside world. In simple terms, it hides the extra details from the outside world. 6 | 7 | | Abstraction | Encapsulation | 8 | |---|---| 9 | | Is the process or method of gaining the information | Is the process or method to contain the information | 10 | | Problems are solved at the design or interface level | Problems are solved at the implementation level | 11 | | Is the method of hiding the unwanted information | Is a method to hide the data in a single entity or unit along with a method to protect information from outside | 12 | | Can be implemented by using abstract class and interfaces | Can be implemented using by access modifier i.e. private, protected and public | 13 | | Implementation complexities are hidden using abstract classes and interfaces | The data is hidden using methods of getters and setters | 14 | | The objects that help to perform abstraction are encapsulated | Whereas the objects that result in encapsulation need not be abstracted | 15 | 16 | ## Links 17 | https://www.geeksforgeeks.org/difference-between-abstraction-and-encapsulation-in-java-with-examples/ 18 | http://www.differencebetween.net/technology/difference-between-abstraction-and-encapsulation/ 19 | -------------------------------------------------------------------------------- /General/What is the difference between git pull and git fetch.md: -------------------------------------------------------------------------------- 1 | # git pull vs git fetch 2 | 3 | `git-fetch` - Download objects and refs from another repository. Fetch branches and/or tags (collectively, "refs") from one or more other repositories, along with the objects necessary to complete their histories. 4 | 5 | By default, any tag that points into the histories being fetched is also fetched; the effect is to fetch tags that point at branches that you are interested in. `git fetch` can fetch from either a single named repository or URL, or from several repositories at once. When no remote is specified, by default the `origin` remote will be used, unless there’s an upstream branch configured for the current branch. 6 | 7 | `git-pull` - Fetch from and integrate with another repository or a local branch. Incorporates changes from a remote repository into the current branch. In its default mode, `git pull` is shorthand for `git fetch` followed by `git merge FETCH_HEAD`. 8 | 9 | More precisely, `git pull` runs `git fetch` with the given parameters and calls `git merge` to merge the retrieved branch heads into the current branch. With `--rebase`, it runs `git rebase` instead of `git merge`. 10 | 11 | ## Links 12 | https://git-scm.com/docs/git-fetch 13 | https://git-scm.com/docs/git-pull 14 | -------------------------------------------------------------------------------- /General/res/aggregation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/aggregation.jpg -------------------------------------------------------------------------------- /General/res/agile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/agile.png -------------------------------------------------------------------------------- /General/res/asymmetric-encryption.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/asymmetric-encryption.png -------------------------------------------------------------------------------- /General/res/asymmetric_base.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/asymmetric_base.png -------------------------------------------------------------------------------- /General/res/cohesion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/cohesion.png -------------------------------------------------------------------------------- /General/res/composition.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/composition.jpg -------------------------------------------------------------------------------- /General/res/concurrency.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/concurrency.png -------------------------------------------------------------------------------- /General/res/coupling.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/coupling.png -------------------------------------------------------------------------------- /General/res/ct_components.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/ct_components.jpeg -------------------------------------------------------------------------------- /General/res/ct_works.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/ct_works.jpeg -------------------------------------------------------------------------------- /General/res/encryption_base.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/encryption_base.png -------------------------------------------------------------------------------- /General/res/fdd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/fdd.png -------------------------------------------------------------------------------- /General/res/graphql_general.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/graphql_general.png -------------------------------------------------------------------------------- /General/res/man_in_the_middle_attack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/man_in_the_middle_attack.png -------------------------------------------------------------------------------- /General/res/osi_model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/osi_model.png -------------------------------------------------------------------------------- /General/res/parallelism.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/parallelism.png -------------------------------------------------------------------------------- /General/res/proto_buffers_types.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/proto_buffers_types.png -------------------------------------------------------------------------------- /General/res/soap_message.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/soap_message.png -------------------------------------------------------------------------------- /General/res/soap_protocol.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/soap_protocol.png -------------------------------------------------------------------------------- /General/res/ssl_certificate_work.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/ssl_certificate_work.png -------------------------------------------------------------------------------- /General/res/symmetric_base.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/symmetric_base.png -------------------------------------------------------------------------------- /General/res/symmetric_encryption.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/symmetric_encryption.png -------------------------------------------------------------------------------- /General/res/tcp_header.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/tcp_header.jpg -------------------------------------------------------------------------------- /General/res/udp_datagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/udp_datagram.png -------------------------------------------------------------------------------- /General/res/uri_syntax.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/uri_syntax.png -------------------------------------------------------------------------------- /General/res/waterfall_model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/waterfall_model.png -------------------------------------------------------------------------------- /General/res/xp_lifycycle.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/xp_lifycycle.webp -------------------------------------------------------------------------------- /General/res/yagni_image.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/General/res/yagni_image.webp -------------------------------------------------------------------------------- /Java/Can a constructor be inherited.md: -------------------------------------------------------------------------------- 1 | # Constructor inherited 2 | 3 | Short answer - no, a constructor cannot be inherited. Reasons: 4 | - Constructors are special and have same name as class name. So if constructors were inherited in child class then child class would contain a parent class constructor which is against the constraint that constructor should have same name as class name 5 | - A constructor cannot be called as a method. It is called when object of the class is created so it does not make sense of creating child class object using parent class constructor notation. i.e. `Child c = new Parent()`; 6 | - If constructors can be inherited then it will be impossible to achieving encapsulation. Because by using a super class’s constructor we can access/initialize private members of a class. 7 | 8 | ## Links 9 | https://www.geeksforgeeks.org/constructors-not-inherited-java/ 10 | https://stackoverflow.com/questions/18147768/why-constructors-can-not-be-inherited-in-java 11 | -------------------------------------------------------------------------------- /Java/Can a static method be overridden.md: -------------------------------------------------------------------------------- 1 | No it can’t. Because the idea of overridden is to get different behavior for children during inherence, but static method is not method of instance it’s method of class. 2 | -------------------------------------------------------------------------------- /Java/Comparable interface in java.md: -------------------------------------------------------------------------------- 1 | **Java Comparable interface** is used to compare objects and sort them according to the natural order. 2 | 3 | **Natural ordering** is referred to as its `compareTo()` function. The `String` objects are sorted lexicographically, and the `wrapper class` objects are sorted according to their built-in `compareTo()` function (like how Integers objects are sorted in ascending order) 4 | 5 | **compareTo()** 6 | The `compareTo()` function compares the current object with the provided object.This function is already implemented for default wrapper classes and primitive data types; but, this function also​ needs to be implemented for user-defined classes. 7 | It returns: 8 | 9 | 1. a `positive integer`, if the current object is greater than the provided object. 10 | 11 | 2. a `negative integer`, if the current object is less than the provided object. 12 | 13 | 3. `zero`, if the current object is equal to the provided object. 14 | 15 | ***Example*** 16 | **Sorting string** 17 | 18 | ArrayList list = new ArrayList<>(); 19 | 20 | list.add("E"); 21 | 22 | list.add("A"); 23 | 24 | list.add("C"); 25 | 26 | list.add("B"); 27 | 28 | list.add("D"); 29 | 30 | Collections.sort(list); 31 | 32 | System.out.println(list); // [A, B, C, D, E] 33 | 34 | **Sorting user defined objects** 35 | 36 | 37 | class Employee implements Comparable { 38 | private String name; 39 | private int age; 40 | 41 | Employee(String name, int age) { 42 | this.name = name; 43 | this.age = age; 44 | } 45 | 46 | @Override 47 | public int compareTo(Employee employee) { 48 | if (this.age == employee.age) 49 | return 0; 50 | else if (this.age > employee.age) 51 | return 1; 52 | else 53 | return -1; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return "[name=" + this.name + ", age=" + this.age +"]"; 59 | } 60 | } 61 | 62 | ========================================================== 63 | 64 | 65 | List employeeList = new ArrayList(); 66 | employeeList.add(new Employee("Emp1", 25)); 67 | employeeList.add(new Employee("Emp2", 10)); 68 | System.out.println(employeeList); // [[name=Emp1, age=25], [name=Emp2, age=10]] 69 | Collections.sort(employeeList); 70 | System.out.println(employeeList); // [[name=Emp2, age=10], [name=Emp1, age=25]] 71 | -------------------------------------------------------------------------------- /Java/Difference between Semaphore and Monitor.md: -------------------------------------------------------------------------------- 1 | # Semaphore vs Monitor 2 | Both semaphores and monitors are used to solve the critical section problem (as they allow processes to access the shared resources in mutual exclusion) and to achieve process synchronization in the multiprocessing environment. 3 | 4 | **Monitor** type high-level synchronization construct. It is an abstract data type. The Monitor type contains shared variables and the set of procedures that operate on the shared variable. 5 | 6 | When any process wishes to access the shared variables in the monitor, it needs to access it through the procedures. These processes line up in a queue and are only provided access when the previous process release the shared variables. Only one process can be active in a monitor at a time. Monitor has condition variables. 7 | 8 | **Semaphore** (`java.util.concurrent.Semaphore`) used for limit the number of threads accessing a specific resource. Conceptually, a semaphore maintains a set of permits. Each `acquire()` blocks if necessary until a permit is available, and then takes it. Each `release()` adds a permit, potentially releasing a blocking acquirer. However, no actual permit objects are used; the Semaphore just keeps a count of the number available and acts accordingly. 9 | 10 | Advantages of Monitors: 11 | - Monitors are easy to implement than semaphores; 12 | - Mutual exclusion in monitors is automatic while in semaphores, mutual exclusion needs to be implemented explicitly; 13 | - Monitors can overcome the timing errors that occur while using semaphores; 14 | - Shared variables are global to all processes in the monitor while shared variables are hidden in semaphores. 15 | 16 | Advantages of Semaphores: 17 | - Semaphores are machine independent (because they are implemented in the kernel services). 18 | - Semaphores permit more than one thread to access the critical section, unlike monitors. 19 | - In semaphores there is no spinning, hence no waste of resources due to no busy waiting. 20 | 21 | ## Links 22 | https://www.geeksforgeeks.org/monitor-vs-semaphore/ 23 | https://stackoverflow.com/questions/7335950/semaphore-vs-monitors-whats-the-difference 24 | -------------------------------------------------------------------------------- /Java/Difference between int and Integer.md: -------------------------------------------------------------------------------- 1 | # int vs Integer 2 | 3 | `int` is a primitive type. Variables of type `int` store the actual binary value for the integer you want to represent. Integer is a class, no different from any other in the Java language. Variables of type `Integer` store references to Integer objects, just as with any other reference (object) type. `Integer.parseInt("1")` is a call to the static method `parseInt` from class `Integer`. To be more specific, `Integer` is a class with a single field of type int. This class is used where you need an int to be treated like any other object, such as in generic types or situations where you need nullability. The automatic conversion of primitive data types into its equivalent Wrapper type is known as autoboxing and opposite operation is known as unboxing. 4 | 5 | ## Autoboxing: 6 | Converting a primitive value into an object of the corresponding wrapper class is called autoboxing. For example, converting int to Integer class. The Java compiler applies autoboxing when a primitive value is: 7 | - Passed as a parameter to a method that expects an object of the corresponding wrapper class. 8 | - Assigned to a variable of the corresponding wrapper class. 9 | 10 | ## Unboxing: 11 | Converting an object of a wrapper type to its corresponding primitive value is called unboxing. For example conversion of Integer to int. The Java compiler applies unboxing when an object of a wrapper class is: 12 | - Passed as a parameter to a method that expects a value of the corresponding primitive type. 13 | - Assigned to a variable of the corresponding primitive type. 14 | 15 | ## Links 16 | https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html 17 | http://illegalargumentexception.blogspot.com/2008/08/java-int-versus-integer.html 18 | https://www.geeksforgeeks.org/autoboxing-unboxing-java/ 19 | -------------------------------------------------------------------------------- /Java/Different between Array and ArrayList.md: -------------------------------------------------------------------------------- 1 | * **Resizable**: *Array* is static in size that is fixed length data structure, one cannot change the length after creating the Array object. *ArrayList* is dynamic in size. Each *ArrayList* object has instance variable capacity which indicates the size of the *ArrayList*. As elements are added to an *ArrayList* its capacity grows automatically. 2 | 3 | * **Performance**: Performance of *Array* and *ArrayList* depends on the operation you are performing: 4 | 1. *resize()* opertation : Automatic resize of *ArrayList* will slow down the performance as it will use temporary array to copy elements from the old array to new array. *ArrayList* is internally backed by Array during resizing as it calls the native implemented method `System.arrayCopy(src,srcPos,dest,destPos,length)`. 5 | 2. *add() or get()* operation : adding an element or retrieving an element from the array or arraylist object has almost same performance , as for *ArrayList* object these operations run in constant time. 6 | 7 | * **Primitives**: *ArrayList* cannot contains primitive data types (like int, float, double) it can only contains Object while *Array* can contain both primitive data types as well as objects. One get a misconception that we can store primitives(int,float,double) in *ArrayList* , but it is not true 8 | 9 | * **Type-Safety**: In Java, one can ensure Type Safety through Generics. while *Array* is a homogeneous data structure, thus it will contain objects of specific class or primitives of specific data type. In array if one tries to store the different data type other than the specified while creating the array object, `ArrayStoreException` is thrown. 10 | 11 | * **Multi-dimensional**: *Array* can be multi-dimensional, while *ArrayList* is always single dimensional. 12 | 13 | * **Adding elements**: We can insert elements into the *ArrayList* object using the add() method while in array we insert elements using the assignment operator. 14 | -------------------------------------------------------------------------------- /Java/HashSet vs TreeSet.md: -------------------------------------------------------------------------------- 1 | # HashSet vs TreeSet 2 | 3 | [HashSet](https://github.com/DevelopTest-byte/Md-test/blob/master/Java/HashSet.md) class implements the `Set` interface, backed by a hash table (actually a `HashMap` instance). It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time. This class permits the `null` element. 4 | 5 | This class offers constant time performance for the basic operations (*add*, *remove*, *contains* and *size*), assuming the hash function disperses the elements properly among the buckets. Iterating over this set requires time proportional to the sum of the `HashSet` instance's size (the number of elements) plus the "capacity" of the backing `HashMap` instance (the number of buckets). 6 | 7 | [TreeSet](https://github.com/DevelopTest-byte/Md-test/blob/master/Java/TreeSet.md) class implements the `Set` interface that uses a tree for storage. It inherits `AbstractSet` class and implements the `NavigableSet` interface. The elements are ordered using their natural ordering, or by a `Comparator` provided at set creation time, depending on which constructor is used. 8 | 9 | `TreeSet` is basically an implementation of a self-balancing binary search tree like a Red-Black Tree. Therefore operations like *add*, *remove*, and *search* take `O(log(n))` time. The reason is that in a self-balancing tree, it is made sure that the height of the tree is always `O(log(n))` for all the operations. Therefore, this is considered as one of the most efficient data structure in order to store the huge sorted data and perform operations on it. However, operations like printing N elements in the sorted order takes `O(n)` time. 10 | 11 | | Property | `HashSet` | `TreeSet` | 12 | |---|---|---| 13 | | Ordering | Does not maintain any order | Maintains an object in sorted order | 14 | | Comprasion | Uses `equals()` method | Uses `compareTo()` method | 15 | | Data structure | Implemented using HashTable | Implemented using a tree structure | 16 | | Null element | Allowed | Not allowed | 17 | | Performance | Time complexity average - `O(1)` | Guaranteed `O(log(n))` time cost for the basic operations | 18 | 19 | ## Links 20 | https://docs.oracle.com/javase/7/docs/api/java/util/TreeSet.html 21 | https://docs.oracle.com/javase/7/docs/api/java/util/HashSet.html 22 | https://www.geeksforgeeks.org/hashset-in-java/ 23 | https://www.geeksforgeeks.org/treeset-in-java-with-examples/ 24 | https://www.geeksforgeeks.org/hashset-vs-treeset-in-java/ 25 | https://www.tutorialspoint.com/difference-between-tree-set-and-hash-set-in-java 26 | -------------------------------------------------------------------------------- /Java/Method signature.md: -------------------------------------------------------------------------------- 1 | # Method signature 2 | 3 | Two of the components of a method declaration comprise the method signature - the **method's name** and the **parameter types**. The reason for the emphasis on just the method name and parameter list is because of *overloading*. It's the ability to write methods that have the same name but accept different parameters. 4 | 5 | The compiler does not consider return type when differentiating methods, so you cannot declare two methods with the same signature even if they have a different return type. 6 | 7 | ## Links 8 | https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html 9 | http://www.java2s.com/Tutorials/Java/OCA_Java_SE_8_Method_Class/0030__Java_Method_Signature.htm 10 | -------------------------------------------------------------------------------- /Java/References types.md: -------------------------------------------------------------------------------- 1 | # References types 2 | 3 | There are four type of references in java: 4 | - Strong 5 | - Weak 6 | - Soft 7 | - Phantom 8 | 9 | ## Strong reference 10 | Strong reference are the ordinary references in Java. Anytime we create a new object, a strong reference is by default created. Any object which has an active strong reference are not eligible for garbage collection. The object is garbage collected only when the variable which was strongly referenced points to null. 11 | 12 | `MyClass obj = new MyClass();` 13 | 14 | ## Weak reference 15 | 16 | Weak reference is a reference not strong enough to keep the object in memory. The object is garbage collected whenever a weak reference is found, the object will be recycled regardless of whether the system heap space is sufficient. 17 | 18 | `WeakReference obj = new MyClass();` 19 | 20 | ## Soft reference 21 | 22 | Think of a SoftReference as a stronger WeakReference. An object holding a SoftReference won't be reclaimed quickly by the JVM. JVM will determine when to recycle based on the current heap usage. Only when the heap usage is near the threshold, the SoftReferenced object will be collected. Therefore, SoftReference can be used to implement a memory-sensitive cache. 23 | 24 | `SoftReference obj = new MyClass();` 25 | 26 | ## Phantom reference 27 | 28 | PhantomReference is the weakest of all types. An object holding a PhantomReference is almost identical to having no reference and can be recycled by the garbage collector at any time. But, before removing them from the memory, JVM puts them in a queue called ‘reference queue’ . They are put in a reference queue after calling `finalize()` method on them. 29 | 30 | `PhantomReference obj = new MyClass();` 31 | 32 | ## Links 33 | https://docs.oracle.com/javase/8/docs/api/java/lang/ref/package-summary.html 34 | https://medium.com/google-developer-experts/finally-understanding-how-references-work-in-android-and-java-26a0d9c92f83 35 | https://www.tutorialdocs.com/article/java-4-referance-types.html 36 | -------------------------------------------------------------------------------- /Java/What are anonymous classes.md: -------------------------------------------------------------------------------- 1 | # Anonymous classes 2 | 3 | Anonymous classes are inner classes with no name. Since they have no name, we can't use them in order to create instances of anonymous classes. As a result, we have to declare and instantiate anonymous classes in a single expression at the point of use. 4 | Anonymous classes are defined inside an expression, hence it must be a part of a statement, so the semicolon is used at the end of anonymous classes to indicate the end of the expression. 5 | 6 | Anonymous inner class are mainly created in two ways: 7 | - Class (may be abstract or concrete) 8 | - Interface 9 | 10 | The anonymous class expression consists of the following: 11 | - The new operator 12 | - The name of an interface to implement or a class to extend. 13 | - Parentheses that contain the arguments to a constructor, just like a normal class instance creation expression. **Note**: When you implement an interface, there is no constructor, so you use an empty pair of parentheses. 14 | - A body, which is a class declaration body. More specifically, in the body, method declarations are allowed but statements are not. 15 | 16 | Restrictions of anonymous classes: 17 | - Cannot have explicitly declared constructors 18 | - Never be abstract 19 | - No way to extend them 20 | 21 | Like local classes, anonymous classes can capture variables; they have the same access to local variables of the enclosing scope: 22 | - An anonymous class has access to the members of its enclosing class. 23 | - An anonymous class cannot access local variables in its enclosing scope that are not declared as final or effectively final. 24 | - Like a nested class, a declaration of a type (such as a variable) in an anonymous class shadows any other declarations in the enclosing scope that have the same name. 25 | 26 | Anonymous classes also have the same restrictions as local classes with respect to their members: 27 | - Сannot declare static initializers or member interfaces in an anonymous class. 28 | - Сan have static members provided that they are constant variables. 29 | 30 | Note that you can declare the following in anonymous classes: 31 | - Fields 32 | - Extra methods (even if they do not implement any methods of the supertype) 33 | - Instance initializers 34 | - Local classes 35 | 36 | ## Links 37 | https://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html 38 | https://www.geeksforgeeks.org/anonymous-inner-class-java/ 39 | https://www.baeldung.com/java-anonymous-classes 40 | -------------------------------------------------------------------------------- /Java/What does the keyword synchronized mean.md: -------------------------------------------------------------------------------- 1 | # Synchronized keyword 2 | 3 | The `synchronized` keyword is all about different threads reading and writing to the same variables, objects and resources. `Synchronized` methods enable a simple strategy for preventing thread interference and memory consistency errors: if an object is visible to more than one thread, all reads or writes to that object's variables are done through `synchronized` methods. When you have two threads that are reading and writing to the same 'resource', say a variable named `foo`, you need to ensure that these threads access the variable in an atomic way. Without the `synchronized` keyword, your thread 1 may not see the change thread 2 made to foo, or worse, it may only be half changed. This would not be what you logically expect. Syntax-wise the `synchronized` keyword takes an `Object` as it's parameter (called a lock object), which is then followed by a `{ block of code }`. Adding `synchronized` keyword to a method definition is equal to the entire method body being wrapped in a synchronized code block with the lock object being this (for instance methods) and `ClassInQuestion.getClass()` (for class methods) 4 | 5 | - When execution encounters this keyword, the current thread tries to "lock/acquire/own" the lock object and execute the associated block of code after the lock has been acquired. 6 | 7 | - Any writes to variables inside the synchronized code block are guaranteed to be visible to every other thread that similarly executes code inside a synchronized code block using the same lock object. 8 | 9 | - Only one thread at a time can hold the lock, during which time all other threads trying to acquire the same lock object will wait (pause their execution). The lock will be released when execution exits the synchronized code block. 10 | 11 | ## Links 12 | https://docs.oracle.com/javase/tutorial/essential/concurrency/sync.html 13 | https://docs.oracle.com/javase/tutorial/essential/concurrency/locksync.html 14 | https://www.baeldung.com/java-synchronized 15 | -------------------------------------------------------------------------------- /Java/What is String Pool.md: -------------------------------------------------------------------------------- 1 | # String Pool 2 | 3 | String Pool in java is a pool of Strings stored in Java Heap Memory. We know that String is a special class in java and we can create String objects using a new operator as well as providing values in double-quotes. String pool helps in saving a lot of space for Java Runtime although it takes more time to create the String. 4 | 5 | Diagram that clearly explains how String Pool is maintained in java heap space and what happens when we use different ways to create Strings: 6 | ![](./res/string_pool.png "String pool") 7 | 8 | When you create a new string like this: 9 | 10 | `String s1 = “Cat”` 11 | 12 | JVM automatically checks if the same value exists in the string pool or not. 13 | - if yes, it occupies the already existing value. 14 | - If no, it creates a new string by itself and adds it to the string pool. 15 | 16 | If you create a string using new operator: 17 | 18 | `String s1 = new String(“Cat”)` 19 | 20 | you implicitly create a brand new object in the heap every time. 21 | 22 | For add string to string poll java provide method - `intern()`, you can call it on string object: 23 | 24 | `s1.intern()` 25 | 26 | Example: 27 | 28 | ``` 29 | public final class App { 30 | 31 | public static void main(String args[]) { 32 | String cat1 = "Cat"; 33 | String cat2 = "Cat"; 34 | String cat3 = new String("Cat"); 35 | 36 | System.out.println("cat1 == cat2 :" + (cat1 == cat2)); 37 | System.out.println("cat1 == cat3 :" + (cat1 == cat3)); 38 | } 39 | 40 | } 41 | ``` 42 | 43 | Will print: 44 | ``` 45 | cat1 == cat2 : true 46 | cat1 == cat3 : false 47 | ``` 48 | 49 | ## Links 50 | https://www.journaldev.com/797/what-is-java-string-pool 51 | https://examples.javacodegeeks.com/core-java/lang/string/java-string-pool-example/ 52 | https://www.edureka.co/blog/java-string-pool/ 53 | -------------------------------------------------------------------------------- /Java/What is immutable object.md: -------------------------------------------------------------------------------- 1 | # Immutable object 2 | An immutable object is an object whose internal state remains constant after it has been entirely created. This means that the public API of an immutable object guarantees us that it will behave in the same way during its whole lifetime. Examples of immutable objects from the JDK include String and Integer. 3 | 4 | Example: 5 | ``` 6 | public final class ImmutableClass { 7 | 8 | private final String property1; 9 | private final String property2; 10 | 11 | public ImmutableClass(String property1, String property2) { 12 | this.property1 = property1; 13 | this.property2 = property2; 14 | } 15 | 16 | public String getProperty1() { 17 | return property1; 18 | } 19 | 20 | public String getProperty2() { 21 | return property2; 22 | } 23 | } 24 | ``` 25 | 26 | ## A strategy for defining immutable objects 27 | - Don't provide "setter" methods — methods that modify fields or objects referred to by fields. 28 | - Make all fields `final` and `private`. 29 | - Don't allow subclasses to `override` methods. The simplest way to do this is to declare the class as `final`. A more sophisticated approach is to make the constructor private and construct instances in factory methods. 30 | - If the instance fields include references to mutable objects, don't allow those objects to be changed: 31 | - Don't provide methods that modify the mutable objects. 32 | - Don't share references to the mutable objects. Never store references to external, mutable objects passed to the constructor; if necessary, create copies, and store references to the copies. Similarly, create copies of your internal mutable objects when necessary to avoid returning the originals in your methods. 33 | 34 | ## Benefits of immutable objects 35 | - Thread safety 36 | - Atomicity of failure 37 | - Absence of hidden side-effects 38 | - Protection against null reference errors 39 | - Ease of caching 40 | - Prevention of identity mutation 41 | - Avoidance of temporal coupling between methods 42 | - Support for referential transparency 43 | - Protection from instantiating logically-invalid objects 44 | - Protection from inadvertent corruption of existing objects 45 | 46 | ## Links 47 | https://docs.oracle.com/javase/tutorial/essential/concurrency/imstrat.html 48 | https://www.baeldung.com/java-immutable-object 49 | http://www.javapractices.com/topic/TopicAction.do?Id=29 50 | https://www.leadingagile.com/2018/03/immutability-in-java/ 51 | -------------------------------------------------------------------------------- /Java/What is the difference between a Stream and an Iterator.md: -------------------------------------------------------------------------------- 1 | # Stream vs Iterator 2 | 3 | **Stream** represents a sequence of objects from a source, which supports aggregate operations. Stream doesn't store data and it's not a data structure. Also it never modifies data source from which it was created. Stream supports functional style operations (map, reduce and etc.) on streams of elements. 4 | 5 | **Iterator** is interface which helps retrieve elements from collection one by one. To use a Java `Iterator` you will have to obtain an `Iterator` instance from the collection of objects you want to iterate over. The obtained `Iterator` keeps track of the elements in the underlying collection to make sure you iterate through all of them. If you modify the underlying collection while iterating through an `Iterator` pointing to that collection, the `Iterator` will typically detect it, and throw an exception the next time you try to obtain the next element from the `Iterator`. 6 | 7 | Streams differ from collections in several ways: 8 | - No storage. A stream is not a data structure that stores elements; instead, it conveys elements from a source such as a data structure, an array, a generator function, or an I/O channel, through a pipeline of computational operations. 9 | - Functional in nature. An operation on a stream produces a result, but does not modify its source. For example, filtering a `Stream` obtained from a collection produces a new `Stream` without the filtered elements, rather than removing elements from the source collection. 10 | - Laziness-seeking. Many stream operations, such as filtering, mapping, or duplicate removal, can be implemented lazily, exposing opportunities for optimization. For example, "find the first String with three consecutive vowels" need not examine all the input strings. Stream operations are divided into intermediate (Stream-producing) operations and terminal (value- or side-effect-producing) operations. Intermediate operations are always lazy. 11 | - Possibly unbounded. While collections have a finite size, streams need not. Short-circuiting operations such as `limit(n)` or `findFirst()` can allow computations on infinite streams to complete in finite time. 12 | - Consumable. The elements of a stream are only visited once during the life of a stream. Like an `Iterator`, a new stream must be generated to revisit the same elements of the source. 13 | 14 | ## Links 15 | https://www.tutorialspoint.com/java8/java8_streams.htm 16 | http://tutorials.jenkov.com/java-collections/iterator.html 17 | https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#package.description 18 | -------------------------------------------------------------------------------- /Java/What is transient keyword.md: -------------------------------------------------------------------------------- 1 | # Transient 2 | 3 | Variables may be marked `transient` to indicate that they are not part of the persistent state of an object. When an object is transferred through the network, the object needs to be 'serialized'. Serialization converts the object state to serial bytes. Those bytes are sent over the network and the object is recreated from those bytes. Member variables marked by the java `transient` keyword are not transferred; they are lost intentionally. 4 | 5 | `transient` keyword plays an important role to meet security constraints. There are various real-life examples where we don’t want to save private data in file. Another use of transient keyword is not to serialize the variable whose value can be calculated/derived using other serialized objects or system such as age of a person, current date, etc. 6 | 7 | Since `static` fields are not part of state of the object, there is no use/impact of using `transient` keyword with `static` variables. However there is no compilation error. 8 | 9 | `transient` and `final` : `final` variables are directly serialized by their values, so there is no use/impact of declaring `final` variable as `transient`. There is no compile-time error though. 10 | 11 | ``` 12 | import java.io.*; 13 | class Test implements Serializable 14 | { 15 | // Normal variables 16 | int i = 10, j = 20; 17 | 18 | // Transient variables 19 | transient int k = 30; 20 | 21 | // Use of transient has no impact here 22 | transient static int l = 40; 23 | transient final int m = 50; 24 | 25 | public static void main(String[] args) throws Exception 26 | { 27 | Test input = new Test(); 28 | 29 | // serialization 30 | FileOutputStream fos = new FileOutputStream("abc.txt"); 31 | ObjectOutputStream oos = new ObjectOutputStream(fos); 32 | oos.writeObject(input); 33 | 34 | // de-serialization 35 | FileInputStream fis = new FileInputStream("abc.txt"); 36 | ObjectInputStream ois = new ObjectInputStream(fis); 37 | Test output = (Test)ois.readObject(); 38 | System.out.println("i = " + output.i); 39 | System.out.println("j = " + output.j); 40 | System.out.println("k = " + output.k); 41 | System.out.println("l = " + output.l); 42 | System.out.println("m = " + output.m); 43 | } 44 | } 45 | ``` 46 | 47 | Output: 48 | 49 | ``` 50 | i = 10 51 | j = 20 52 | k = 0 53 | l = 40 54 | m = 50 55 | ``` 56 | 57 | ## Links 58 | https://docs.oracle.com/javase/8/docs/api/java/beans/Transient.html 59 | https://en.wikibooks.org/wiki/Java_Programming/Keywords/transient 60 | https://www.geeksforgeeks.org/transient-keyword-java/ 61 | https://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html 62 | -------------------------------------------------------------------------------- /Java/What's Comparable and Comparator interface.md: -------------------------------------------------------------------------------- 1 | # Comparable vs Comparator 2 | 3 | ## Comparable 4 | 5 | `Comparable` interface has a single method `compareTo()` which is used to compare the value of an object with the one supplied in the method. `Comparable` interface defines the natural or default ordering of the objects of a class. On defining the `compareTo()` method in the class, we need to make sure that the return value can be: 6 | 7 | - **Negative**: Returns negative if the object which is to be compared is less than the supplied object value. 8 | - **Positive**: Returns positive if the object which is to be compared is greater than the supplied object value. 9 | - **Zero**: Returns zero, if the object which is compared is equal to the supplied object value. 10 | 11 | ## Comparator 12 | 13 | `Comparator` interface is used for the scenarios when we don’t want to use the natural ordering and want the ordering/ sorting of elements according to the specific requirements. As we cannot make any changes to the `compareTo()` method of `Comparable` interface, the `Comparator` interface provides a method `compare()` which is used to sort the objects of collection. It takes 2 arguments in the method and return value can be: 14 | 15 | - **Negative**: Returns a negative value if the value of the first argument is less than the value of the second argument. 16 | - **Positive**: Returns a positive value if the value of the first argument is greater than the value of the second argument. 17 | - **Zero**: Returns a zero value if the value of the first argument is equal to the value of the second argument. 18 | 19 | ## Conclusion 20 | 21 | | Comparable | Comparator | 22 | |---|---| 23 | | Comparable affects the original class, i.e., the actual class is modified. | Comparator doesn't affect the original class, i.e., the actual class is not modified. | 24 | | Comparable provides compareTo() method to sort elements. | Comparator provides compare() method to sort elements. | 25 | | We can sort the list elements of Comparable type by Collections.sort(List) method. | We can sort the list elements of Comparator type by Collections.sort(List, Comparator) method. | 26 | | Can sort the elements of collection on the basis of the single element | Can sort on the basis of multiple elements of the collections at a time | 27 | 28 | ## Links 29 | https://www.educba.com/comparable-vs-comparator/ 30 | https://www.baeldung.com/java-comparator-comparable 31 | https://www.javatpoint.com/difference-between-comparable-and-comparator 32 | https://dev.to/micosmin/understanding-comparable-and-comparator-3l0i 33 | https://www.javaworld.com/article/3323403/java-challengers-5-sorting-with-comparable-and-comparator-in-java.html 34 | -------------------------------------------------------------------------------- /Java/res/access_modifier.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/access_modifier.png -------------------------------------------------------------------------------- /Java/res/collection.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/collection.jpeg -------------------------------------------------------------------------------- /Java/res/deque_interface_java.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/deque_interface_java.jpeg -------------------------------------------------------------------------------- /Java/res/exception_hierarchy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/exception_hierarchy.jpg -------------------------------------------------------------------------------- /Java/res/garbage_collection_generations.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/garbage_collection_generations.png -------------------------------------------------------------------------------- /Java/res/garbage_collection_step_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/garbage_collection_step_1.png -------------------------------------------------------------------------------- /Java/res/garbage_collection_step_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/garbage_collection_step_2.png -------------------------------------------------------------------------------- /Java/res/garbage_collection_step_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/garbage_collection_step_3.png -------------------------------------------------------------------------------- /Java/res/iterators.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/iterators.png -------------------------------------------------------------------------------- /Java/res/java_list_class_diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/java_list_class_diagram.png -------------------------------------------------------------------------------- /Java/res/java_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/java_map.png -------------------------------------------------------------------------------- /Java/res/java_memory.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/java_memory.jpg -------------------------------------------------------------------------------- /Java/res/java_memory_leak.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/java_memory_leak.png -------------------------------------------------------------------------------- /Java/res/java_set_implementation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/java_set_implementation.png -------------------------------------------------------------------------------- /Java/res/jdk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/jdk.png -------------------------------------------------------------------------------- /Java/res/jre.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/jre.png -------------------------------------------------------------------------------- /Java/res/linkedlist-node.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/linkedlist-node.png -------------------------------------------------------------------------------- /Java/res/linkedlist_implemenation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/linkedlist_implemenation.png -------------------------------------------------------------------------------- /Java/res/metaspace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/metaspace.png -------------------------------------------------------------------------------- /Java/res/queue_interface_java.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/queue_interface_java.png -------------------------------------------------------------------------------- /Java/res/semaphore.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/semaphore.jpeg -------------------------------------------------------------------------------- /Java/res/serialize_deserialize_java.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/serialize_deserialize_java.png -------------------------------------------------------------------------------- /Java/res/stack_and_heap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/stack_and_heap.png -------------------------------------------------------------------------------- /Java/res/stack_vs_heap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/stack_vs_heap.png -------------------------------------------------------------------------------- /Java/res/string_pool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/string_pool.png -------------------------------------------------------------------------------- /Java/res/volatile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Java/res/volatile.png -------------------------------------------------------------------------------- /Kotlin/Crossinline keyword.md: -------------------------------------------------------------------------------- 1 | # Crossinline keyword 2 | 3 | The `crossinline` marker is used to mark lambdas that mustn’t allow non-local returns, especially when such lambda is passed to another execution context such as a higher order function that is not inlined, a local object or a nested function. In other words, helps us enforce the control flow (return statement) of lambda functions passed as arguments in inline functions. Avoiding non-local control flow. 4 | 5 | ![](./res/crossinline.png "Crossinline") 6 | 7 | ## Links 8 | https://kotlinlang.org/docs/reference/inline-functions.html 9 | https://medium.com/@tferreirap/kotlin-quick-look-at-inline-noinline-and-crossinline-e62e8833db1f 10 | https://android.jlelse.eu/inline-noinline-crossinline-what-do-they-mean-b13f48e113c2 11 | -------------------------------------------------------------------------------- /Kotlin/Difference between fold and reduce in Kotlin.md: -------------------------------------------------------------------------------- 1 | ### Reduce 2 | - `reduce` method transforms a given collection into a single result. It takes a lamda operator to combine a pair of elements into a accumulated value. 3 | It then traverses the collection from left to right and stepwise combines the accumulated value with the next element. 4 | 5 | val numbers: List = listOf(1, 2, 3); 6 | val sum = numbers.reduce { acc, next -> next + acc } ` 7 | 8 | - `reduce` method will throw `RuntimeException` if its operated on an empty list. 9 | 10 | - Signature of `reduce` method 11 | `inline fun Iterable.reduce(operation: (acc:S, T) -> S): S` 12 | The function defines a generic type S and subtype T of S, Finally reduce returns one value of type S. 13 | 14 | - In the following example the sum would exceed the range of `Int` because of that the data type of result is changed to Long. So it will throw compile error(Type argument is not within its bounds) 15 | ` val sum: Long = numbers.reduce { acc, next -> acc.toLong() + next.toLong() }` 16 | 17 | - To fix the compile error we will have to change the `Long` type to `Number` as `Number` is superset of `Int`. So **It doesnt solve the problem of changing the result type** 18 | 19 | ## Fold 20 | To address the issues created by `reduce` we can use `fold` 21 | 22 | `val numbers: List = listOf(1, 2, 3) 23 | val sum = numbers.fold(0, { acc, next -> next + acc })` 24 | 25 | Here first argument is initial value if list is empty the inital value is returned. 26 | `inline fun Iterable.fold(initial:R, (acc:R, T) -> R): R` 27 | In contrast to `reduce()`, it specifies two arbitrary generic types **T** and **R**. 28 | - We can change the result type to **Long** in the following example 29 | 30 | `val sum: Long = numbers.fold(0L, { acc, next -> acc + next.toLong() })` 31 | 32 | - `fold` **provides the ability to change the result type**. 33 | -------------------------------------------------------------------------------- /Kotlin/Enum.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Enum in Kotlin 4 | 5 | An `enum` in Kotlin is a special type that represents a group of related constants. It allows you to define a fixed set of values for a variable. Enum constants are typically used to represent a closed set of options or choices. 6 | 7 | To define an `enum` in Kotlin, you use the `enum class` keyword, followed by the name of the enum and the list of constant values inside curly braces. For example: 8 | 9 | ```kotlin 10 | enum class Color { 11 | RED, GREEN, BLUE 12 | } 13 | ``` 14 | 15 | In the above example, the `Color` enum has three constants: `RED`, `GREEN`, and `BLUE`. 16 | 17 | Enums in Kotlin can also have properties and methods, similar to classes. Each enum constant can have its own values for these properties. For example: 18 | 19 | ```kotlin 20 | enum class Color(val rgb: Int) { 21 | RED(0xFF0000), 22 | GREEN(0x00FF00), 23 | BLUE(0x0000FF) 24 | 25 | fun description(): String { 26 | return when (this) { 27 | RED -> "Red color" 28 | GREEN -> "Green color" 29 | BLUE -> "Blue color" 30 | } 31 | } 32 | } 33 | ``` 34 | 35 | In the above example, the `Color` enum has an additional property `rgb` associated with each constant. It also has a method `description()` that provides a textual description of each color. 36 | 37 | To access the properties and methods of an enum constant, you simply use dot notation. For example: 38 | 39 | ```kotlin 40 | val redColor = Color.RED 41 | println(redColor.rgb) // Output: 16711680 42 | println(redColor.description()) // Output: Red color 43 | ``` 44 | 45 | Enums in Kotlin can be useful in various scenarios, such as representing days of the week, menu options, status codes, and more. They provide a type-safe and concise way to define a fixed set of values. 46 | 47 | ## Further Reading: 48 | For more information about enums in Kotlin, you can refer to the following resources: 49 | 50 | - [Kotlin Enum Classes](https://kotlinlang.org/docs/enum-classes.html) 51 | - [Enums in Kotlin](https://www.baeldung.com/kotlin/enum) 52 | 53 | Feel free to explore these resources to deepen your understanding of enums in Kotlin. 54 | -------------------------------------------------------------------------------- /Kotlin/Kotlin collections.md: -------------------------------------------------------------------------------- 1 | 2 | ## Collection(Kotlin) 3 | 4 | `Collection` usually contains a number of objects of the same type. Objects in a collection are called `elements` or `items`. For example, all the students in a department form a collection that can be used to calculate their average age. The following collection types are relevant for Kotlin: 5 | 6 | - **List** is an ordered collection with access to elements by indices – integer numbers that reflect their position. Elements can occur more than once in a list. 7 | 8 | - **Set** is a collection of unique elements. It reflects the mathematical abstraction of set: a group of objects without repetitions. 9 | 10 | - **Map (or dictionary)** is a set of key-value pairs. Keys are unique, and each of them maps to exactly one value. The values can be duplicates. Maps are useful for storing logical connections between objects. 11 | 12 | 13 | 14 | ### Collection Types 15 | 16 | The Kotlin Standard Library provides implementations for basic collection types: sets, lists, and maps. A pair of interfaces represent each collection type: 17 | 18 | 19 | 20 | - A **read-only** interface that provides operations for accessing collection elements.The read-only collection types are `covariant`( collection types have the same subtyping relationship as the element types. If a `Rectangle` class inherits from `Shape`, you can use a `List` anywhere the `List` is required.) 21 | 22 | - A **mutable** interface that extends the corresponding read-only interface with write operations: adding, removing, and updating its elements. 23 | 24 | The mutable collections aren't covariant; otherwise, this would lead to runtime failures. If `MutableList` was a subtype of `MutableList`, you could insert other `Shape` inheritors (for example, `Circle`) into it, thus violating its `Rectangle` type argument. 25 | 26 | 27 | 28 | Below is a diagram of the Kotlin collection interfaces 29 | 30 | 31 | 32 | ![enter image description here](https://raw.githubusercontent.com/swayangjit/Android-Interview-Questions/master/Kotlin/res/collections-diagram.png) 33 | 34 | 35 | ## Links 36 | https://kotlinlang.org/docs/reference/collections-overview.html -------------------------------------------------------------------------------- /Kotlin/Visibility modifiers.md: -------------------------------------------------------------------------------- 1 | # Visibility modifiers 2 | 3 | Kotlin allows you to enforce symbol visibility via *visibility modifiers*, which can be placed on symbol declarations. 4 | 5 | There are four visibility modifiers in Kotlin: **private**, **protected**, **internal** and **public**. 6 | 7 | - **public**: declarations are visible everywhere. 8 | - **private**: means visible inside this class only (including all its members) 9 | - **protected**: means visible inside this class (including all its members) + visible in subclasses too 10 | - **internal**: modifier are visible everywhere in the same module. 11 | 12 | If you don't supply a visibility modifier, you get the default visibility level, which is **public**. 13 | 14 | ![](./res/visibility_modifiers.png "Visibility_modifiers") 15 | 16 | ## Java vs Kotlin 17 | - In Java, the default modifier is **package private**, in Kotlin is **public**. 18 | - Java’s **package private** doesn’t have an equivalent in Kotlin, the closest is **internal**. 19 | - An Outer class does not see **private** members of its inner class in Kotlin. 20 | - If you override a **protected** member and do not specify the visibility explicitly, the overriding member will also have **protected** visibility. In Java the visibility is according to the modifier and the default is still **public**. 21 | 22 | ## Links 23 | https://kotlinlang.org/docs/tutorials/kotlin-for-py/visibility-modifiers.html 24 | https://kotlinlang.org/docs/reference/visibility-modifiers.html 25 | https://medium.com/mindorks/kotlin-for-android-developers-visibility-modifiers-8d8a3b84d298 26 | https://medium.com/@HugoMatilla/kotlin-basics-visibility-modifiers-public-internal-protected-and-private-c3bf972aee11 27 | -------------------------------------------------------------------------------- /Kotlin/What do you know about Any, Nothing, Unit types.md: -------------------------------------------------------------------------------- 1 | # Any, Nothing, Unit 2 | 3 | `Any` the root of the Kotlin class hierarchy. `Any` is the super type of all non-nullable types. `Any` can't hold the `null` value, for holding `null` value you can use `Any?`. Kotlin compiler treats `kotlin.Any` and `java.lang.Object` as two different types, but at runtime they are represented with the same `java.lang.Object` class. 4 | 5 | `Nothing` has no instances. You can use Nothing to represent "a value that never exists": for example, if a function has the return type of Nothing, it means that it never returns (always throws an exception). `Nothing` implicity extend any object that exists. 6 | 7 | ``` 8 | fun fail(message: String): Nothing { 9 | throw IllegalStateException(message) 10 | } 11 | 12 | val address = employee.address ?: fail("${employee.name} has no address defined") 13 | println(address) 14 | 15 | // > java.lang.IllegalStateException: John has no address defined 16 | ``` 17 | 18 | `Unit` In Java if we want that a function does return nothing we use `void`, `Unit` is the equivalent in Kotlin.The main characteristics of `Unit` against Java’s `void` are: 19 | - `Unit` is a type and therefore can be used as a type argument. 20 | - Only one value of this type exists. 21 | - It is returned implicitly. No need of a `return` statement. 22 | 23 | ## Links 24 | https://itnext.io/kotlin-basics-types-any-unit-and-nothing-674cc858035 25 | https://proandroiddev.com/kotlins-nothing-type-946de7d464fb 26 | https://blog.kotlin-academy.com/kotlins-nothing-its-usefulness-in-generics-5076a6a457f7 27 | https://stackoverflow.com/questions/38761021/does-any-object 28 | https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/ 29 | https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-nothing.html 30 | https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/ 31 | -------------------------------------------------------------------------------- /Kotlin/What do you know about JvmOverloads annotation.md: -------------------------------------------------------------------------------- 1 | # JvmOverloads annotation 2 | Instructs the Kotlin compiler to generate overloads for this function that substitute default parameter values. 3 | 4 | If a method has *N* parameters and *M* of which have default values, *M* overloads are generated: the first one takes *N-1* parameters (all but the last one that takes a default value), the second takes *N-2* parameters, and so on. 5 | 6 | Functions with parameters having a default value must use `@JvmOverloads`. Without this annotation it is impossible to invoke the Kotlin function using any default values from Java. 7 | 8 | When using `@JvmOverloads`, inspect the generated methods to ensure they each make sense. If they do not, perform one or both of the following refactorings until satisfied: 9 | - Change the parameter order to prefer those with defaults being towards the end. 10 | - Move the defaults into manual function overloads. 11 | 12 | *Incorrect*: No `@JvmOverloads` 13 | ``` 14 | class Greeting { 15 | fun sayHello(prefix: String = "Mr.", name: String) { 16 | println("Hello, $prefix $name") 17 | } 18 | } 19 | ``` 20 | ``` 21 | public class JavaClass { 22 | public static void main(String... args) { 23 | Greeting greeting = new Greeting(); 24 | greeting.sayHello("Mr.", "Bob"); 25 | } 26 | } 27 | ``` 28 | 29 | *Correct*: `@JvmOverloads` annotation. 30 | ``` 31 | class Greeting { 32 | @JvmOverloads 33 | fun sayHello(prefix: String = "Mr.", name: String) { 34 | println("Hello, $prefix $name") 35 | } 36 | } 37 | ``` 38 | ``` 39 | public class JavaClass { 40 | public static void main(String... args) { 41 | Greeting greeting = new Greeting(); 42 | greeting.sayHello("Bob"); 43 | } 44 | } 45 | ``` 46 | 47 | # Links 48 | [JvmOverloads](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-jvm-overloads/#jvmoverloads) 49 | [Kotlin-Java interop guide](https://developer.android.com/kotlin/interop) 50 | 51 | # Further reading 52 | [Misconception about Kotlin @JvmOverloads for Android View Creation](https://proandroiddev.com/misconception-about-kotlin-jvmoverloads-for-android-view-creation-cb88f432e1fe) 53 | [@JvmOverloads for Android Views](https://zsmb.co/jvmoverloads-for-android-views/) 54 | -------------------------------------------------------------------------------- /Kotlin/What's Sequence.md: -------------------------------------------------------------------------------- 1 | # Sequence 2 | Sequences offer the same functions as `Iterable` but implement another approach to multi-step collection processing. 3 | 4 | When the processing of an `Iterable` includes multiple steps, they are executed eagerly: each processing step completes and returns its result – an intermediate collection. The following step executes on this collection. In turn, multi-step processing of sequences is executed lazily when possible: actual computing happens only when the result of the whole processing chain is requested. 5 | 6 | The order of operations execution is different as well: `Sequence` performs all the processing steps one-by-one for every single element. In turn, `Iterable` completes each step for the whole collection and then proceeds to the next step. 7 | 8 | So, the sequences let you avoid building results of intermediate steps, therefore improving the performance of the whole collection processing chain. However, the lazy nature of sequences adds some overhead which may be significant when processing smaller collections or doing simpler computations. Hence, you should consider both `Sequence` and `Iterable` and decide which one is better for your case. 9 | 10 | ## Sequence operations 11 | The sequence operations can be classified into the following groups regarding their state requirements: 12 | - *Stateless* operations require no state and process each element independently, for example, map() or filter(). Stateless operations can also require a small constant amount of state to process an element, for example, take() or drop(). 13 | - *Stateful* operations require a significant amount of state, usually proportional to the number of elements in a sequence. 14 | 15 | If a sequence operation returns another sequence, which is produced lazily, it's called `intermediate`. Otherwise, the operation is `terminal`. Examples of terminal operations are `toList()` or `sum()`. Sequence elements can be retrieved only with terminal operations. 16 | 17 | Sequences can be iterated multiple times; however some sequence implementations might constrain themselves to be iterated only once. That is mentioned specifically in their documentation. 18 | 19 | Example: 20 | ``` 21 | sequenceOf("A", "B", "C") 22 | .filter { 23 | println("filter: $it") 24 | true 25 | } 26 | .forEach { 27 | println("forEach: $it") 28 | } 29 | 30 | Output: 31 | // filter: A 32 | // forEach: A 33 | // filter: B 34 | // forEach: B 35 | // filter: C 36 | // forEach: C 37 | ``` 38 | 39 | ## Links 40 | https://kotlinlang.org/docs/reference/sequences.html 41 | https://typealias.com/guides/when-to-use-sequences/ 42 | https://medium.com/androiddevelopers/collections-and-sequences-in-kotlin-55db18283aca 43 | https://winterbe.com/posts/2018/07/23/kotlin-sequence-tutorial/ 44 | -------------------------------------------------------------------------------- /Kotlin/What's a const.md: -------------------------------------------------------------------------------- 1 | # Const val 2 | 3 | If the value of a read-only property is known at the compile time, mark it as a *compile time constant* using the `const `modifier. Such properties need to fulfil the following requirements: 4 | - Top-level, or member of an `object declaration` or a `companion object`. 5 | - Initialized with a value of type `String` or a primitive type 6 | - No custom getter 7 | 8 | ## Links 9 | https://kotlinlang.org/docs/reference/properties.html 10 | -------------------------------------------------------------------------------- /Kotlin/What's difference between == and ===.md: -------------------------------------------------------------------------------- 1 | # Difference between == and === 2 | 3 | In Kotlin there are two types of equality - referential and structural 4 | 5 | ## === (Referential Equality) 6 | For referential equality, we use the `===` symbol which allows us to evaluate the reference of an object, it will only be true if both the objects or variables pointing to the same object. This is an equivalent of `==` operator in Java. 7 | 8 | ## == (Structural Equality) 9 | For structural equality `==` operator is used. It will be true if data of both objects or variables a equal. This is an equivalent of `equals()` method in Java. 10 | 11 | ## Links 12 | https://kotlinlang.org/docs/reference/equality.html 13 | https://www.baeldung.com/kotlin-equality-operators 14 | https://medium.com/@agrawalsuneet/equality-in-kotlin-and-equals-d8373ef529f1 15 | -------------------------------------------------------------------------------- /Kotlin/What's init block.md: -------------------------------------------------------------------------------- 1 | # Init block 2 | 3 | A class in Kotlin can have a **primary constructor** and one or more **secondary constructors**. The primary constructor cannot contain any code. Initialization code can be placed in **initializer blocks**, which are prefixed with the `init` keyword. 4 | 5 | Code in initializer blocks effectively becomes part of the primary constructor. Delegation to the primary constructor happens as the first statement of a secondary constructor, so the code in all initializer blocks and property initializers is executed before the secondary constructor body. Even if the class has no primary constructor, the delegation still happens implicitly, and the initializer blocks are still executed. During an instance initialization, the initializer blocks are executed in the same order as they appear in the class body. 6 | 7 | ## Links 8 | https://kotlinlang.org/docs/reference/classes.html 9 | https://www.programiz.com/kotlin-programming/constructors 10 | -------------------------------------------------------------------------------- /Kotlin/What's inline class.md: -------------------------------------------------------------------------------- 1 | # Inline class 2 | 3 | Sometimes it is necessary for business logic to create a wrapper around some type. However, it introduces runtime overhead due to additional heap allocations. Moreover, if the wrapped type is primitive, the performance hit is terrible, because primitive types are usually heavily optimized by the runtime, while their wrappers don't get any special treatment. 4 | 5 | To solve such issues, Kotlin introduces a special kind of class called an inline class. 6 | Inline classes add a simple tool we can use to wrap some other type without adding runtime overhead through additional heap allocations. 7 | 8 | Inline classes are pretty straightforward. To make a class inlined, you just add the inline keyword to your class: 9 | 10 | `inline class WrappedInt(val value: Int)` 11 | 12 | Restriction of inline classes: 13 | - must have a single property initialized in the primary constructor 14 | - cannot have init blocks 15 | - inline class properties cannot have backing fields 16 | - can only have simple computable properties (no lateinit/delegated properties) 17 | - cannot extend other classes and must be final. 18 | 19 | ## Type Aliases vs. Inline Classes 20 | 21 | At first sight, inline classes may appear to be very similar to type aliases. Indeed, both seem to introduce a new type and both will be represented as the underlying type at runtime. 22 | However, the crucial difference is that type aliases are assignment-compatible with their underlying type (and with other type aliases with the same underlying type), while inline classes are not. 23 | In other words, inline classes introduce a truly new type, contrary to type aliases which only introduce an alternative name (alias) for an existing type 24 | 25 | ## Links 26 | https://kotlinlang.org/docs/reference/inline-classes.html 27 | https://kotlinexpertise.com/kotlin-inline-classes/ 28 | https://typealias.com/guides/introduction-to-inline-classes/ 29 | -------------------------------------------------------------------------------- /Kotlin/code/Questions.md: -------------------------------------------------------------------------------- 1 | ## How to create empty constructor for data class? 2 |
3 | Click to expand! 4 | If you give default value to all the fields - empty constructor is generated automatically by Kotlin: 5 | 6 | ``` 7 | data class Information( 8 | var title: String = "", 9 | var text: String = "", 10 | ) 11 | ``` 12 | 13 | or you can declare a secondary constructor that nas no parameter: 14 | ``` 15 | data class Information( 16 | var title: String, 17 | var text: String, 18 | ) { 19 | constructor(): this("", "") 20 | } 21 | ``` 22 |
23 | 24 | 25 | ## What will be result of the following code execurion? 26 | ``` 27 | val innerProperty by lazy { 28 | println("Calculating the value") 29 | "Result" 30 | } 31 | 32 | fun main(args: Array) { 33 | println(innerProperty) 34 | println(innerProperty) 35 | } 36 | ``` 37 |
38 | Click to expand! 39 | For lazy the first time you access the Lazy property, the initialisation (lazy() function invocation) takes place. The second time, this value is remembered and returned: 40 | 41 | ``` 42 | Calculating the value 43 | Result 44 | Result 45 | ``` 46 |
47 | -------------------------------------------------------------------------------- /Kotlin/map vs flatMap in collections.md: -------------------------------------------------------------------------------- 1 | # Map() vs FlatMap() 2 | `map()` - Returns a list containing the results of applying the given transform function to each element in the original array. 3 | ``` 4 | val numbers = listOf(1, 2, 3) 5 | println(numbers.map { it * it }) // [1, 4, 9] 6 | ``` 7 | 8 | `flatMap()` - Returns a single list of all elements yielded from results of transform function being invoked on each element of original array. 9 | ``` 10 | val list = listOf("123", "45") 11 | println(list.flatMap { it.toList() }) // [1, 2, 3, 4, 5] 12 | ``` 13 | 14 | Consider the example. Let’s first create class Player: 15 | ``` 16 | data class Player(val name: String) 17 | ``` 18 | 19 | Then create class Team, which contains list of the players: 20 | ``` 21 | data class Team(val players: List) 22 | ``` 23 | 24 | Let’s call `flatMap()` and `map()` on this data and print the outputs: 25 | ``` 26 | fun main(args: Array) { 27 | val tournament = 28 | listOf( 29 | Team(listOf(Player("Team1 first player"), Player("Team1 second player"))), 30 | Team(listOf(Player("Team2 first player"), Player("Team2 second player"))) 31 | ) 32 | 33 | val flatMapResult = tournament.flatMap { it.players } 34 | println(flatMapResult) 35 | 36 | val mapResult = tournament.map { it.players } 37 | println(mapResult) 38 | } 39 | ``` 40 | 41 | Output: 42 | ``` 43 | [Player(name=Team1 first player), Player(name=Team1 second player), Player(name=Team2 first player), Player(name=Team2 second player)] 44 | 45 | [[Player(name=Team1 first player), Player(name=Team1 second player)], [Player(name=Team2 first player), Player(name=Team2 second player)]] 46 | ``` 47 | 48 | `flatMap()` merges the two collections into a single one, `map()` simply results in a list of lists. 49 | 50 | ## Links 51 | https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/map.html 52 | https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/flat-map.html 53 | https://stackoverflow.com/questions/52078207/what-is-the-use-case-for-flatmap-vs-map-in-kotlin 54 | https://medium.com/@sachinkmr375/flatmap-vs-map-in-kotlin-aef771a4dae4 55 | -------------------------------------------------------------------------------- /Kotlin/res/collections-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Kotlin/res/collections-diagram.png -------------------------------------------------------------------------------- /Kotlin/res/coroutine_context.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Kotlin/res/coroutine_context.png -------------------------------------------------------------------------------- /Kotlin/res/coroutine_scope.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Kotlin/res/coroutine_scope.png -------------------------------------------------------------------------------- /Kotlin/res/crossinline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Kotlin/res/crossinline.png -------------------------------------------------------------------------------- /Kotlin/res/flow_entities.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Kotlin/res/flow_entities.png -------------------------------------------------------------------------------- /Kotlin/res/nullability_compile_time_error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Kotlin/res/nullability_compile_time_error.png -------------------------------------------------------------------------------- /Kotlin/res/scope_function.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Kotlin/res/scope_function.png -------------------------------------------------------------------------------- /Kotlin/res/visibility_modifiers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Kotlin/res/visibility_modifiers.png -------------------------------------------------------------------------------- /Kotlin/val mutableList vs var immutableList. When to use which.md: -------------------------------------------------------------------------------- 1 | # val mutableList vs var immutableList 2 | 3 | Mutable and immutable list increase the design clarity of the model. This is to force developer to think and clarify the purpose of collection. 4 | 5 | - If the collection will change as part of design, use mutable collection 6 | - If model is meant only for viewing, use immutable list 7 | 8 | Purpose of `val` and `var` is how reference will work with variable: 9 | - `var` - value/reference can be changed at any point of time 10 | - `val` - value/reference can be assigned only once and can't be changed later 11 | 12 | There are several reasons why immutable objects are often preferable: 13 | 14 | - They encourage functional programming, where state is not mutated, but passed on to the next function which creates a new state based on it. This is very well visible in the Kotlin collection methods such as `map`, `filter`, `reduce`, etc. 15 | - A program without side effects is often easier to understand and debug 16 | - In multithreaded programs, immutable resources cannot cause race conditions, as no write access is involved. 17 | 18 | Immutable objects also have some disadvantages: 19 | - Copying entire collections just to add/remove a single element is computationally expensive. 20 | - In some cases, immutability can make the code more complex, when you tediously need to change single fields. In Kotlin, data classes come with a built-in `copy()` method where you can copy an instance, while providing new values for only some of the fields. 21 | 22 | Example: 23 | 24 | ``` 25 | val mutableList = mutableListOf() 26 | var immutableList = listOf() 27 | 28 | fun testFunction() { 29 | 30 | //Can do 31 | mutableList.add(1) 32 | mutableList.add(2) 33 | 34 | //Can't do (val cannot be reassigned) 35 | val secondMutableList = mutableListOf() 36 | mutableList = secondMutableList 37 | 38 | //Can do 39 | val secondImmutableList = listOf() 40 | immutableList = secondImmutableList 41 | 42 | //Can't do 43 | immutableList.add(1) 44 | } 45 | ``` 46 | 47 | ## Links 48 | https://stackoverflow.com/questions/51718229/kotlin-val-mutablelist-vs-var-immutablelist-when-to-use-which 49 | -------------------------------------------------------------------------------- /Libraries/res/hilt_hierarchy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Libraries/res/hilt_hierarchy.png -------------------------------------------------------------------------------- /Libraries/res/interceptors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Libraries/res/interceptors.png -------------------------------------------------------------------------------- /Patterns/Singleton pattern.md: -------------------------------------------------------------------------------- 1 | # Singleton pattern 2 | Singleton pattern is a software design pattern that restricts the instantiation of a class to one "single" instance. This is useful when exactly one object is needed to coordinate actions across the system. The term comes from the mathematical concept of a singleton. 3 | 4 | The singleton design pattern solves problems like: 5 | - How can it be ensured that a class has only one instance? 6 | - How can the sole instance of a class be accessed easily? 7 | - How can a class control its instantiation? 8 | - How can the number of instances of a class be restricted? 9 | 10 | To create the singleton class, we need to have static member of class, private constructor and static factory method. 11 | - **Static member**: It gets memory only once because of static, itcontains the instance of the Singleton class. 12 | - **Private constructor**: It will prevent to instantiate the Singleton class from outside the class. 13 | - **Static factory metho**d: This provides the global point of access to the Singleton object and returns the instance to the caller. 14 | 15 | ``` 16 | public final class ClassSingleton { 17 | 18 | private static ClassSingleton INSTANCE; 19 | private String info = "Initial info class"; 20 | 21 | private ClassSingleton() { 22 | } 23 | 24 | public static ClassSingleton getInstance() { 25 | if(INSTANCE == null) { 26 | INSTANCE = new ClassSingleton(); 27 | } 28 | 29 | return INSTANCE; 30 | } 31 | 32 | // getters and setters 33 | } 34 | ``` 35 | 36 | Common uses: 37 | - The abstract factory, factory method, builder, and prototype patterns can use singletons in their implementation. 38 | - Facade objects are often singletons because only one facade object is required. 39 | - State objects are often singletons. 40 | 41 | ## Links 42 | https://en.wikipedia.org/wiki/Singleton_pattern 43 | https://www.journaldev.com/1377/java-singleton-design-pattern-best-practices-examples 44 | https://www.geeksforgeeks.org/singleton-class-java/ 45 | https://www.javatpoint.com/singleton-design-pattern-in-java 46 | https://www.baeldung.com/java-singleton 47 | https://sourcemaking.com/design_patterns/singleton 48 | -------------------------------------------------------------------------------- /Patterns/res/facade.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Patterns/res/facade.jpg -------------------------------------------------------------------------------- /Patterns/res/mvi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Patterns/res/mvi.png -------------------------------------------------------------------------------- /Patterns/res/mvp_android.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Patterns/res/mvp_android.png -------------------------------------------------------------------------------- /Patterns/res/mvvm_android.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Patterns/res/mvvm_android.png -------------------------------------------------------------------------------- /Patterns/res/state_pattern.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Patterns/res/state_pattern.jpeg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android-Interview-Questions 2 | 3 | This repository contains a number of android interview questions that can be used when vetting potential candidates. I created this list because wanted to have repo, where I can prepare for android job interview, without searching question and answers all around the internet. In all answers you can find the links with the source of the answer, where you may read more detailed information on the question. 4 | 5 | ## List of the questions 6 | You can find complete list of questions on the [wiki page](https://github.com/Kirchhoff-/Android-Interview-Questions/wiki) 7 | 8 | ## Test assignments 9 | Examples of test assignments can be found [here](https://github.com/Kirchhoff-/Android-Interview-Questions/wiki/Test-Assignments) 10 | 11 | ## Interview examples 12 | [Junior android developer](https://github.com/Kirchhoff-/Android-Interview-Questions/wiki/Junior-android-developer-interview-questions) 13 | [Middle android developer (Rx stack)](https://github.com/Kirchhoff-/Android-Interview-Questions/wiki/Middle-android-developer-interview-questions-(Rx-stack)) 14 | [Middle android developer (Coroutines stack)](https://github.com/Kirchhoff-/Android-Interview-Questions/wiki/Middle-android-developer-interview-questions--(Coroutines-stack)) 15 | 16 | ## Questions count 17 | 18 | [Android](https://github.com/Kirchhoff-/Android-Interview-Questions/wiki/Android): 95 19 | [Java](https://github.com/Kirchhoff-/Android-Interview-Questions/wiki/Java): 69 20 | [Kotlin](https://github.com/Kirchhoff-/Android-Interview-Questions/wiki/Kotlin): 49 21 | [Rx](https://github.com/Kirchhoff-/Android-Interview-Questions/wiki/Rx): 20 22 | [General](https://github.com/Kirchhoff-/Android-Interview-Questions/wiki/General): 45 23 | [Testing](https://github.com/Kirchhoff-/Android-Interview-Questions/wiki/Testing): 13 24 | [Patterns](https://github.com/Kirchhoff-/Android-Interview-Questions/wiki/Patterns): 28 25 | [Libraries](https://github.com/Kirchhoff-/Android-Interview-Questions/wiki/Libraries): 13 26 | 27 | Total number of questions: 330 28 | 29 | ## Discussions 30 | The [Discussions](https://github.com/Kirchhoff-/Android-Interview-Questions/discussions) section also works. It contains questions where your opinion would be interesting to know. 31 | 32 | ## Contributing 33 | Pull Request are highly appreciated. Feel free to create a pull request if you find any mistakes or have better answers. Thanks a lot, and hope this is useful. 34 | -------------------------------------------------------------------------------- /Rx/Observable types.md: -------------------------------------------------------------------------------- 1 | # Observable types 2 | 3 | Observables are the source which emits items to the Observers. Observables are the sources for the data. Usually they start providing data once a subscriber starts listening. An observable may emit any number of items (including zero items). It can terminate either successfully or with an error. 4 | 5 | ## Observable 6 | Emits 0 or n items and terminates with an success or an error event. The Observable class is the non-backpressured, optionally multi-valued base reactive class that offers factory methods, intermediate operators and the ability to consume synchronous and/or asynchronous reactive dataflows. 7 | 8 | ## Flowable 9 | Emits 0 or n items and terminates with an success or an error event. Supports backpressure, which allows to control how fast a source emits items. The Flowable class that implements the Reactive Streams Pattern and offers factory methods, intermediate operators and the ability to consume reactive dataflows. 10 | 11 | ## Single 12 | Emits either a single item or an error event. The reactive version of a method call. there are 2 methods in the subscription they are all mutually exclusive so just one of them can be called at the end. To know: 13 | - **onError** - will be called whenever an error is thrown in some point of the stream. 14 | - **onSuccess** - will be called if we get a response from the stream, in this case information about the user and we use a `Single` because we know 100% that a user has information to show. 15 | 16 | ## Maybe 17 | Succeeds with an item, or no item, or errors. The reactive version of an Optional. Maybe emits 0 or 1 items, but it can complete without emitting a value. There are 3 methods in the subscription they are all mutually exclusive so just one of them can be called at the end: 18 | - **onError** - will be called whenever an error is thrown in some point of the stream. 19 | - **onSuccess** - will be called if we get a response from the stream. 20 | - **onComplete** - will be called if we have an empty output. 21 | 22 | ## Completable 23 | Either completes with an success or with an error event. It never emits items. The reactive version of a Runnable. Completable is used in cases where you need to know whether an operation is completable successfully or not. Unlike Maybe and Single, the CompletableObserver doesn’t return any value at all. There are two method for subscription: 24 | - **onError** - will be called whenever an error is thrown at some point of the stream or if, in this case, we couldn’t perform the login for some reason. 25 | - **onComplete** - will be called if everything went right. In this case we don’t have any output, just a code block that will be invoked afterwards. 26 | 27 | ## Links 28 | http://reactivex.io/documentation/observable.html 29 | https://www.journaldev.com/22594/rxjava-observables-observers 30 | https://bugfender.com/blog/data-flows-in-rxjava2-observable-flowable-single-maybe-completable/ 31 | https://www.vogella.com/tutorials/RxJava/article.html 32 | -------------------------------------------------------------------------------- /Rx/RepeatWhen vs RetryWhen.md: -------------------------------------------------------------------------------- 1 | # Repeat vs. Retry 2 | 3 | Main difference between `repeat` and `retry` is event causes a resubscription: 4 | - `repeat()` resubscribes when it receives `onCompleted()`. 5 | - `retry()` resubscribes when it receives `onError()`. 6 | 7 | Key points about `repeatWhen` and `retryWhen`: 8 | - `repeatWhen` is identical to `retryWhen`, only it responds to `onCompleted` instead of `onError`. The input is `Observable`, since `onCompleted` has no type. 9 | - The `notificationHandler` (i.e. `Func1`) is only called once per subscription. This makes sense as you are given an `Observable`, which can emit any number of errors. 10 | - The output `Observable` has to use the input `Observable` as its source. You must react to the `Observable` and emit based on it; you can't just return a generic stream. 11 | - The `Observable` input only triggers on terminal events (`onCompleted` for `repeatWhen` / `onError` for `retryWhen`). It doesn't receive any of the `onNext` notifications from the source, so you can't examine the emitted data to determine if you should resubscribe. If you want to do that, you have to add an operator like `takeUntil()` to cut off the stream. 12 | 13 | ## Links 14 | https://blog.danlew.net/2016/01/25/rxjavas-repeatwhen-and-retrywhen-explained/ 15 | https://android.jlelse.eu/rx-grokking-retrywhen-and-repeatwhen-on-android-development-examples-af5c3ed0872b 16 | -------------------------------------------------------------------------------- /Rx/Schedulers types.md: -------------------------------------------------------------------------------- 1 | # Schedulers 2 | 3 | If you want to introduce multithreading into your cascade of Observable operators, you can do so by instructing those operators (or particular Observables) to operate on particular Schedulers. 4 | 5 | By default, an `Observable` and the chain of operators that you apply to it will do its work, and will notify its observers, on the same thread on which its `subscribe()` method is called. The `subscribeOn()` operator changes this behavior by specifying a different Scheduler on which the `Observable` should operate. The `observeOn()` operator specifies a different Scheduler that the `Observable` will use to send notifications to its observers. 6 | 7 | ## Schedulers types 8 | 9 | **IO** 10 | `observable.subscribeOn(Schedulers.io())` 11 | 12 | This is one of the most common types of Schedulers that are used. Generally used for IO related stuff. Such as network requests, file system operations. IO scheduler is backed by thread-pool. 13 | 14 | **Computation** 15 | `observable.subscribeOn(Schedulers.computation())` 16 | 17 | This scheduler is quite similar to IO Schedulers as this is backed by thread pool too. However, the number of threads that can be used is fixed to the number of cores present in the system. So if you have two cores in your mobile, it will have 2 threads in the pool. This also means that if these two threads are busy then the process will have to wait for them to be available. 18 | 19 | **NewThread** 20 | `observable.subscribeOn(Schedulers.newThread())` 21 | 22 | Creates and returns a Scheduler that creates a new Thread for each unit of work. Since thread creation is a costly operation and can have a drastic effect in mobile environment. 23 | 24 | **Single** 25 | `observable.subscribeOn(Schedulers.single())` 26 | 27 | Create single thread and perform all operations in it. 28 | 29 | **Trampoline** 30 | `observable.subscribeOn(Schedulers.trampoline())` 31 | 32 | Creates and returns a Scheduler that queues work on the current thread to be executed after the current work completes. Often used in tests. 33 | 34 | **Executor Scheduler** 35 | ``` 36 | val executor = Executors.newFixedThreadPool(10) 37 | val pooledScheduler = Schedulers.from(executor) 38 | ``` 39 | Converts an Executor into a new Scheduler instance. This can be used in scenarios where number of observables could be huge for IO Schedulers 40 | 41 | **Android scheduler** `AndroidSchedulers.mainThread()` 42 | This Scheduler is provided by rxAndroid library. This is used to bring back the execution to the main thread so that UI modification can be made. This is usually used in `observeOn()` method 43 | 44 | ## Links 45 | http://reactivex.io/documentation/scheduler.html 46 | https://android.jlelse.eu/rxjava-schedulers-what-when-and-how-to-use-it-6cfc27293add 47 | https://www.baeldung.com/rxjava-schedulers 48 | https://www.tutorialspoint.com/rxjava/rxjava_schedulers.htm 49 | -------------------------------------------------------------------------------- /Rx/What do you know about observeOn operator.md: -------------------------------------------------------------------------------- 1 | # ObserveOn 2 | `ObserveOn` specify the Scheduler on which an observer will observe this `Observable`. 3 | 4 | ![](./res/observeOn.png "ObserveOn") 5 | 6 | Many implementations of ReactiveX use “Schedulers” to govern an Observable’s transitions between threads in a multi-threaded environment. You can instruct an `Observable` to send its notifications to observers on a particular Scheduler by means of the `ObserveOn` operator. 7 | 8 | ![](./res/observeOn_flow.png "ObserveOn") 9 | 10 | Note that ObserveOn will forward an `onError` termination notification immediately if it receives one, and will not wait for a slow-consuming observer to receive any not-yet-emitted items that it is aware of first. This may mean that the `onError` notification jumps ahead of (and swallows) items emitted by the source `Observable`, as in the diagram above. 11 | 12 | The `SubscribeOn` operator is similar, but it instructs the `Observable` to itself operate on the specified Scheduler, as well as notifying its observers on that Scheduler. 13 | 14 | By default, an `Observable` and the chain of operators that you apply to it will do its work, and will notify its observers, on the same thread on which its `Subscribe` method is called. The `SubscribeOn` operator changes this behavior by specifying a different Scheduler on which the `Observable` should operate. The `ObserveOn` operator specifies a different Scheduler that the `Observable` will use to send notifications to its observers. 15 | 16 | As shown in this illustration, the SubscribeOn operator designates which thread the Observable will begin operating on, no matter at what point in the chain of operators that operator is called. ObserveOn, on the other hand, affects the thread that the Observable will use *below* where that operator appears. For this reason, you may call ObserveOn multiple times at various points during the chain of Observable operators in order to change on which threads certain of those operators operate. 17 | 18 | Example 19 | ``` 20 | fun observeOn() { 21 | Observable.create { 22 | it.onNext(1) 23 | it.onComplete() 24 | } 25 | .observeOn(Schedulers.newThread()) 26 | .subscribe { println("Observe on ${Thread.currentThread().name}") } 27 | } 28 | ``` 29 | 30 | Output: 31 | ``` 32 | Observe on RxNewThreadScheduler-1 33 | ``` 34 | 35 | # Links 36 | [ObserveOn](https://reactivex.io/documentation/operators/observeon.html) -------------------------------------------------------------------------------- /Rx/What do you know about subscribeOn operator.md: -------------------------------------------------------------------------------- 1 | # SubscribeOn 2 | `SubscribeOn` specify the Scheduler on which an Observable will operate. 3 | 4 | ![](./res/utility_subscribeon.png "Delay") 5 | 6 | Many implementations of ReactiveX use “Schedulers” to govern an Observable’s transitions between threads in a multi-threaded environment. You can instruct an `Observable` to do its work on a particular Scheduler by calling the Observable’s `SubscribeOn` operator. 7 | 8 | ![](./res/utility_schedulers.png "Delay") 9 | 10 | By default, an Observable and the chain of operators that you apply to it will do its work, and will notify its observers, on the same thread on which its `Subscribe` method is called. The `SubscribeOn` operator changes this behavior by specifying a different Scheduler on which the `Observable` should operate. The `ObserveOn` operator specifies a different Scheduler that the `Observable` will use to send notifications to its observers. 11 | 12 | As shown in this illustration, the `SubscribeOn` operator designates which thread the `Observable` will begin operating on, no matter at what point in the chain of operators that operator is called. `ObserveOn`, on the other hand, affects the thread that the `Observable` will use below where that operator appears. For this reason, you may call `ObserveOn` multiple times at various points during the chain of `Observable` operators in order to change on which threads certain of those operators operate. 13 | 14 | Example: 15 | ``` 16 | fun subscribeOn() { 17 | Observable.create { 18 | it.onNext(1) 19 | it.onComplete() 20 | } 21 | .subscribeOn(Schedulers.newThread()) 22 | .subscribe { println("Subscriber on ${Thread.currentThread().name}") } 23 | } 24 | ``` 25 | 26 | Output: 27 | ``` 28 | Subscriber on RxNewThreadScheduler-1 29 | ``` 30 | 31 | # Links 32 | [SubscribeOn](http://reactivex.io/documentation/operators/subscribeon.html) 33 | 34 | # Further reading 35 | [RxJava2 subscribeOn: How to use it](https://www.glureau.com/2020/05/02/RxJava-SubscribeOn-HowTo/) -------------------------------------------------------------------------------- /Rx/What's backpressure.md: -------------------------------------------------------------------------------- 1 | # Backpressure 2 | 3 | Backpressure is the inability of a Subscriber to handle all incoming events in time. In other words Backpressure can occur when the Producer of events is faster than the Consumer. There are a variety of strategies with which you can exercise flow control and backpressure in RxJava in order to alleviate the problems caused when a quickly-producing Observable meets a slow-consuming observer. 4 | 5 | For example, imagine using the zip operator to `zip` together two infinite Observables, one of which emits items twice as frequently as the other. A naive implementation of the `zip` operator would have to maintain an ever-expanding buffer of items emitted by the faster Observable to eventually combine with items emitted by the slower one. 6 | 7 | This could cause RxJava to seize an unwieldy amount of system resources. Since it requires system resources to handle backpressure, you need to choose right backpressure strategy that suits your requirement. 8 | There are a few backpressure strategies: 9 | - Drop: Discards the unrequested items if it exceeds the buffer size 10 | - Buffer: Buffers all the items from the producer, watch for OOMs 11 | - Latest: Keeps only the most recent item 12 | - Error: throws a `MissingBackpressureException` in case of over emission 13 | - Missing: No strategy, it would throw a MissingBackpressureException sooner or later somewhere on the downstream 14 | 15 | ## Links 16 | https://github.com/ReactiveX/RxJava/wiki/Backpressure 17 | https://proandroiddev.com/rxjava-backpressure-and-why-you-should-care-369c5242c9e6 18 | https://www.baeldung.com/rxjava-backpressure 19 | -------------------------------------------------------------------------------- /Rx/What's the difference between observeOn and subscribeOn.md: -------------------------------------------------------------------------------- 1 | # ObserveOn() vs SubscribeOn() 2 | 3 | `observeOn()` - specify the Scheduler on which an observer will observe this Observable. This method simply changes the thread of all operators further downstream (in the calls that come after). Example: 4 | ``` 5 | Observable.just("Random String") // UI 6 | .map(str -> str.length()) // UI 7 | .observeOn(Schedulers.computation()) // Changing the thread 8 | .map(length -> length - 2) // Computation 9 | .subscribe(result -> Log.d("", "Result = $result") 10 | ``` 11 | 12 | `subscribeOn()` - specify the Scheduler on which an Observable will operate. Position does not matter `subscribeOn()` can be put in any place in the stream because it affects only the time of subscription. Example: 13 | ``` 14 | Observable.just("Random String") // Computation 15 | .map(str -> str.length()) // Computation 16 | .map(length -> length - 2) // Computation 17 | .subscribeOn(Schedulers.computation()) 18 | .subscribe(result -> Log.d("", "Result = $result") // Computation 19 | ``` 20 | 21 | 22 | ![](./res/schedulers.png "Schedulers") 23 | 24 | By default, an Observable and the chain of operators that you apply to it will do its work, and will notify its observers, on the same thread on which its Subscribe method is called. The SubscribeOn operator changes this behavior by specifying a different Scheduler on which the Observable should operate. The ObserveOn operator specifies a different Scheduler that the Observable will use to send notifications to its observers. 25 | 26 | As shown in this illustration, the SubscribeOn operator designates which thread the Observable will begin operating on, no matter at what point in the chain of operators that operator is called. ObserveOn, on the other hand, affects the thread that the Observable will use below where that operator appears. For this reason, you may call ObserveOn multiple times at various points during the chain of Observable operators in order to change on which threads certain of those operators operate. 27 | 28 | Conclusion: 29 | - `observeOn()` works only downstream. 30 | - `subscribeOn()` works downstream and upstream. 31 | - consecutive subscribeOns do not change the thread. 32 | - consequent observeOns do change the thread. 33 | - Thread change by an `observeOn()` cannot be overridden by a `subscribeOn()`. 34 | 35 | ## Links 36 | http://reactivex.io/documentation/operators/observeon.html 37 | http://reactivex.io/documentation/operators/subscribeon.html 38 | https://medium.com/upday-devs/rxjava-subscribeon-vs-observeon-9af518ded53a 39 | https://stackoverflow.com/questions/44984730/rxandroid-whats-the-difference-between-subscribeon-and-observeon 40 | https://proandroiddev.com/rx-java-subscribeon-and-observeon-a7d95041ce96 41 | -------------------------------------------------------------------------------- /Rx/What’s the difference between flatMap(), concatMap() and switchMap().md: -------------------------------------------------------------------------------- 1 | # flatMap() vs concatMap() vs switchMap() 2 | 3 | ## FlatMap 4 | 5 | Transform the items emitted by an Observable into Observables, then flatten the emissions from those into a single Observable. 6 | 7 | ![](./res/flatMap.png "FlatMap") 8 | 9 | The FlatMap operator transforms an Observable by applying a function that you specify to each item emitted by the source Observable, where that function returns an Observable that itself emits items. FlatMap then merges the emissions of these resulting Observables, emitting these merged results as its own sequence. 10 | 11 | This method is useful, for example, when you have an Observable that emits a series of items that themselves have Observable members or are in other ways transformable into Observables, so that you can create a new Observable that emits the complete collection of items emitted by the sub-Observables of these items. 12 | 13 | **Note**: FlatMap merges the emissions of these Observables and not care about the order of the items! 14 | 15 | ## ConcatMap 16 | 17 | Simillar to `flatMap()` but `concatMap()` maintains the order of items and waits for the current Observable to complete its job before emitting the next one. 18 | 19 | ![](./res/concatMap.png "ConcatMap") 20 | 21 | Another difference between `flatMap()` and `concatMap()` operators. The `flatMap()` uses `merge` operator implicitly whereas `concatMap()` uses `concat` operator. 22 | 23 | ## SwitchMap 24 | 25 | Similar to `flatMap()`, except that it retains the result of only the latest observable, discarding the previous ones. 26 | 27 | ![](./res/switchMap.png "SwitchMap") 28 | 29 | `switchMap()`would emit only the latest observable after a particular delay. It ignores all the previous ones. 30 | 31 | ## Links 32 | http://reactivex.io/documentation/operators/flatmap.html 33 | https://www.journaldev.com/19300/rxjava-flatmap-switchmap-concatmap 34 | https://www.androidhive.info/RxJava/map-flatmap-switchmap-concatmap/ 35 | https://www.baeldung.com/rxjava-flatmap-switchmap 36 | https://medium.com/appunite-edu-collection/rxjava-flatmap-switchmap-and-concatmap-differences-examples-6d1f3ff88ee0 37 | -------------------------------------------------------------------------------- /Rx/res/async_subject_error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/async_subject_error.png -------------------------------------------------------------------------------- /Rx/res/async_subject_success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/async_subject_success.png -------------------------------------------------------------------------------- /Rx/res/behavior_subject_error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/behavior_subject_error.png -------------------------------------------------------------------------------- /Rx/res/behavior_subject_success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/behavior_subject_success.png -------------------------------------------------------------------------------- /Rx/res/combining_combineLatest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/combining_combineLatest.png -------------------------------------------------------------------------------- /Rx/res/combining_join.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/combining_join.png -------------------------------------------------------------------------------- /Rx/res/combining_merge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/combining_merge.png -------------------------------------------------------------------------------- /Rx/res/combining_startWith.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/combining_startWith.png -------------------------------------------------------------------------------- /Rx/res/combining_switch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/combining_switch.png -------------------------------------------------------------------------------- /Rx/res/combining_zip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/combining_zip.png -------------------------------------------------------------------------------- /Rx/res/concat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/concat.png -------------------------------------------------------------------------------- /Rx/res/concatMap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/concatMap.png -------------------------------------------------------------------------------- /Rx/res/conditional_all.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/conditional_all.png -------------------------------------------------------------------------------- /Rx/res/conditional_amb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/conditional_amb.png -------------------------------------------------------------------------------- /Rx/res/conditional_contains.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/conditional_contains.png -------------------------------------------------------------------------------- /Rx/res/conditional_defaultIfEmpty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/conditional_defaultIfEmpty.png -------------------------------------------------------------------------------- /Rx/res/conditional_sequenceEqual.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/conditional_sequenceEqual.png -------------------------------------------------------------------------------- /Rx/res/conditional_skipUntil.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/conditional_skipUntil.png -------------------------------------------------------------------------------- /Rx/res/conditional_skipWhile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/conditional_skipWhile.png -------------------------------------------------------------------------------- /Rx/res/conditional_takeUntil.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/conditional_takeUntil.png -------------------------------------------------------------------------------- /Rx/res/conditional_takeWhile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/conditional_takeWhile.png -------------------------------------------------------------------------------- /Rx/res/creating_create.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/creating_create.png -------------------------------------------------------------------------------- /Rx/res/creating_defer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/creating_defer.png -------------------------------------------------------------------------------- /Rx/res/creating_empty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/creating_empty.png -------------------------------------------------------------------------------- /Rx/res/creating_from.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/creating_from.png -------------------------------------------------------------------------------- /Rx/res/creating_interval.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/creating_interval.png -------------------------------------------------------------------------------- /Rx/res/creating_just.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/creating_just.png -------------------------------------------------------------------------------- /Rx/res/creating_never.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/creating_never.png -------------------------------------------------------------------------------- /Rx/res/creating_range.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/creating_range.png -------------------------------------------------------------------------------- /Rx/res/creating_repeat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/creating_repeat.png -------------------------------------------------------------------------------- /Rx/res/creating_start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/creating_start.png -------------------------------------------------------------------------------- /Rx/res/creating_throw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/creating_throw.png -------------------------------------------------------------------------------- /Rx/res/creating_timer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/creating_timer.png -------------------------------------------------------------------------------- /Rx/res/error_handling_catch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/error_handling_catch.png -------------------------------------------------------------------------------- /Rx/res/error_handling_onErrorResumeNext.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/error_handling_onErrorResumeNext.png -------------------------------------------------------------------------------- /Rx/res/error_handling_onErrorReturn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/error_handling_onErrorReturn.png -------------------------------------------------------------------------------- /Rx/res/error_handling_onExceptionResumeNext.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/error_handling_onExceptionResumeNext.png -------------------------------------------------------------------------------- /Rx/res/error_handling_retry.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/error_handling_retry.png -------------------------------------------------------------------------------- /Rx/res/error_handling_retryMain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/error_handling_retryMain.png -------------------------------------------------------------------------------- /Rx/res/error_handling_retryWhen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/error_handling_retryWhen.png -------------------------------------------------------------------------------- /Rx/res/filtering_debounce.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/filtering_debounce.png -------------------------------------------------------------------------------- /Rx/res/filtering_distinct.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/filtering_distinct.png -------------------------------------------------------------------------------- /Rx/res/filtering_elementAt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/filtering_elementAt.png -------------------------------------------------------------------------------- /Rx/res/filtering_filter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/filtering_filter.png -------------------------------------------------------------------------------- /Rx/res/filtering_first.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/filtering_first.png -------------------------------------------------------------------------------- /Rx/res/filtering_ignoreElements.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/filtering_ignoreElements.png -------------------------------------------------------------------------------- /Rx/res/filtering_last.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/filtering_last.png -------------------------------------------------------------------------------- /Rx/res/filtering_sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/filtering_sample.png -------------------------------------------------------------------------------- /Rx/res/filtering_skip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/filtering_skip.png -------------------------------------------------------------------------------- /Rx/res/filtering_skipLast.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/filtering_skipLast.png -------------------------------------------------------------------------------- /Rx/res/filtering_take.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/filtering_take.png -------------------------------------------------------------------------------- /Rx/res/filtering_takeLast.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/filtering_takeLast.png -------------------------------------------------------------------------------- /Rx/res/flatMap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/flatMap.png -------------------------------------------------------------------------------- /Rx/res/math_concat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/math_concat.png -------------------------------------------------------------------------------- /Rx/res/math_count.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/math_count.png -------------------------------------------------------------------------------- /Rx/res/math_reduce.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/math_reduce.png -------------------------------------------------------------------------------- /Rx/res/merge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/merge.png -------------------------------------------------------------------------------- /Rx/res/observeOn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/observeOn.png -------------------------------------------------------------------------------- /Rx/res/observeOn_flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/observeOn_flow.png -------------------------------------------------------------------------------- /Rx/res/publish_subject_error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/publish_subject_error.png -------------------------------------------------------------------------------- /Rx/res/publish_subject_success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/publish_subject_success.png -------------------------------------------------------------------------------- /Rx/res/replay_subject_success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/replay_subject_success.png -------------------------------------------------------------------------------- /Rx/res/schedulers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/schedulers.png -------------------------------------------------------------------------------- /Rx/res/serialize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/serialize.png -------------------------------------------------------------------------------- /Rx/res/switchMap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/switchMap.png -------------------------------------------------------------------------------- /Rx/res/transforming_buffer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/transforming_buffer.png -------------------------------------------------------------------------------- /Rx/res/transforming_flatMap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/transforming_flatMap.png -------------------------------------------------------------------------------- /Rx/res/transforming_groupBy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/transforming_groupBy.png -------------------------------------------------------------------------------- /Rx/res/transforming_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/transforming_map.png -------------------------------------------------------------------------------- /Rx/res/transforming_scan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/transforming_scan.png -------------------------------------------------------------------------------- /Rx/res/transforming_window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/transforming_window.png -------------------------------------------------------------------------------- /Rx/res/utility_delay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/utility_delay.png -------------------------------------------------------------------------------- /Rx/res/utility_dematerialize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/utility_dematerialize.png -------------------------------------------------------------------------------- /Rx/res/utility_do.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/utility_do.png -------------------------------------------------------------------------------- /Rx/res/utility_materialize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/utility_materialize.png -------------------------------------------------------------------------------- /Rx/res/utility_schedulers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/utility_schedulers.png -------------------------------------------------------------------------------- /Rx/res/utility_subscribeon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/utility_subscribeon.png -------------------------------------------------------------------------------- /Rx/res/utility_timeInterval.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/utility_timeInterval.png -------------------------------------------------------------------------------- /Rx/res/utility_timeout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/utility_timeout.png -------------------------------------------------------------------------------- /Rx/res/utility_timestamp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Rx/res/utility_timestamp.png -------------------------------------------------------------------------------- /Test Assignments/Google image search.md: -------------------------------------------------------------------------------- 1 | # Google Images Search 2 | 3 | Create an application that performs image search using Google Images Search (or Custom Google Search). 4 | 1. The main screen consists of two tabs: 5 | - **Search**. On this tab, the user can enter a query and view the results in a list; 6 | - **Favorites**. A list of images that the user has added to favorites. 7 | 8 | 2. Each list item should include the following elements: 9 | - An image; 10 | - A title; 11 | - A checkbox to add the image to favorites. 12 | 13 | 3. Display search results in batches of 10 items and implement lazy loading to fetch additional data when scrolling to the end (where appropriate). 14 | 15 | 4. Add functionality to save user-selected results in a local database. 16 | 17 | 5. On clicking an image, open a new screen to display the image with zoom functionality. 18 | 19 | 6. You can use any libraries/tools to implement the task. 20 | -------------------------------------------------------------------------------- /Testing/What do you know about espresso.md: -------------------------------------------------------------------------------- 1 | # Espresso 2 | Espresso is an open source android user interface (UI) testing framework developed by Google. Espresso is a simple, efficient and flexible testing framework. Google released the Espresso framework in Oct. 2013. Since its 2.0 release Espresso is part of the Android Support Repository. Espresso tests can be written in both Java and Kotlin, a modern programming language to develop android application. 3 | 4 | Espresso automatically synchronizes your test actions with the user interface of your application. The framework also ensures that your activity is started before the tests run. It also let the test wait until all observed background activities have finished. The Espresso API is simple and easy to learn. You can easily perform Android UI tests without the complexity of multi-threaded testing. Google Drive, Maps and some other applications are currently using Espresso. 5 | 6 | Espresso Testing works basically in three blocks: 7 | 8 | - `ViewMatchers` – allows you to find an item in the view 9 | - `ViewActions` – allows to execute actions on the elements 10 | - `ViewAssertions` – validate a view state 11 | 12 | Base Espresso Test 13 | ``` 14 | onView(ViewMatcher) //1 15 | .perform(ViewAction) // 2 16 | .check(ViewAssertion); //3 17 | ``` 18 | 1. Finds the view 19 | 2. Performs an action on the view 20 | 3. Validates a assertioin 21 | 22 | Features of Espresso: 23 | - Very simple API and so, easy to learn. 24 | - Highly scalable and flexible. 25 | - Provides separate module to test Android WebView component. 26 | - Provides separate module to validate as well as mock Android Intents. 27 | - Provides automatic synchronization between your application and tests. 28 | 29 | Advantages of Espresso: 30 | - Backward compatibility 31 | - Easy to setup. 32 | - Highly stable test cycle. 33 | - Supports testing activities outside application as well. 34 | - Supports JUnit4 35 | - UI automation suitable for writing black box tests. 36 | 37 | ## Links 38 | https://developer.android.com/training/testing/espresso 39 | https://www.vogella.com/tutorials/AndroidTestingEspresso/article.html 40 | https://www.tutorialspoint.com/espresso_testing/index.htm 41 | https://apiumhub.com/tech-blog-barcelona/introduction-espresso-testing/ 42 | -------------------------------------------------------------------------------- /Testing/What is robolectric.md: -------------------------------------------------------------------------------- 1 | # Robolectric 2 | Robolectric is the industry-standard unit testing framework for Android. With Robolectric, your tests run in a simulated Android environment inside a JVM, without the overhead of an emulator. 3 | 4 | Unlike traditional emulator-based Android tests, Robolectric tests run inside a sandbox which allows allows the Android environment to be precisely configured to the desired conditions for each test, isolates each test from its neighbors, and extends the Android framework with test APIs which provide minute control over the Android framework’s behavior and visibility of state for assertions. 5 | 6 | While much of the Android framework will work as expected inside a Robolectric test, some Android components’ regular behavior doesn’t translate well to unit tests: hardware sensors need to be simulated, system services need to be loaded with test fixture data. In those cases, Robolectric provides a test double that’s suitable for most unit testing scenarios. Robolectric replaced all Android classes by so-called shadow objects. If a method is implemented by Robolectric, it forwards these method calls to the shadow object. Shadow objects behave similar to the Android implementation. If a method is not implemented by the shadow object, it simply returns a default value, e.g., `null` or 0. 7 | 8 | Robolectric handles inflation of views, resource loading, and lots of other stuff that’s implemented in native C code on Android devices. This allows tests to do most things you could do on a real device. It’s easy to provide your own implementation for specific SDK methods too, so you could simulate error conditions or real-world sensor behavior, for example. 9 | 10 | Robolectric allows a test style that is closer to black box testing, making the tests more effective for refactoring and allowing the tests to focus on the behavior of the application instead of the implementation of Android. 11 | 12 | Example of test: 13 | ``` 14 | @RunWith(AndroidJUnit4.class) 15 | public class MyActivityTest { 16 | 17 | @Test 18 | public void clickingButton_shouldChangeResultsViewText() throws Exception { 19 | Activity activity = Robolectric.setupActivity(MyActivity.class); 20 | 21 | Button button = (Button) activity.findViewById(R.id.press_me_button); 22 | TextView results = (TextView) activity.findViewById(R.id.results_text_view); 23 | 24 | button.performClick(); 25 | assertThat(results.getText().toString(), equalTo("Testing Android Rocks!")); 26 | } 27 | } 28 | ``` 29 | 30 | ## Links 31 | http://robolectric.org/ 32 | https://github.com/robolectric/robolectric 33 | https://www.vogella.com/tutorials/Robolectric/article.html 34 | -------------------------------------------------------------------------------- /Testing/res/ab_testing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Testing/res/ab_testing.png -------------------------------------------------------------------------------- /Testing/res/tdd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Testing/res/tdd.png -------------------------------------------------------------------------------- /Testing/res/test_pyramid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kirchhoff-/Android-Interview-Questions/32d96757d50e4441f33a355f88988a1e2f3f23db/Testing/res/test_pyramid.png --------------------------------------------------------------------------------