Java Concepts

Thread Pool
A thread pool reuses previously created threads to execute current tasks and offers a solution to the problem of thread cycle overhead and resource thrashing. It is a software design pattern for achieving concurrency of execution in a computer program. Since the thread is already existing when the request arrives, the delay introduced by thread creation is eliminated, making the application more responsive. The size of a thread pool is the number of threads kept in reserve for executing tasks

What does Static word in Java mean? Can we override a Static method?
A member of a class that can be accessed without instantiating the object of the class.
We cannot override static method in java since overriding is based on dynamic binding at runtime and static members are bound at compile time

Can abstract class have static methods?
If we declare a method in a class abstract to use it, we must override this method in the subclass. But, overriding is not possible with static methods. Therefore, an abstract method cannot be static.

Can abstract class/method be final?
We cannot override final class/methods in Java.
But, in-case of abstract, we must override an abstract method to use it.
Therefore, we cannot use abstract and final together before a method.

can we override a method which has a return type?


Android Launch Modes

Standard

This is the default launch mode. If you don’t specify any launch mode, activity will open with standard launch mode.

This is the simplest of all. It’ll just launch one activity over the other. Even if the activity is already present.

For example:

android launch modes

SingleTop

Remember this as: Only a single instance of the activity will remain on top.

In this android launch mode:

  1. If the Activity is present on the top, then a new instance is NOT created. Instead the onNewIntent() method is invoked.
  2. If the activity is NOT present on the top, then a new instance is created and added to the top. Just like the standard launch mode.

android launch modes singleTop

SingleTask

Remember this as: Only a single instance of an activity can survive in a Task.

If an activity has SingleTask launch mode, then a new Task is created when the activity is launched the first time. And this activity instance is placed at the root. Now for the two cases:

In this android launch mode:

  1. If an Activity is present on top, then a new instance is NOT created. Instead the onNewIntent() method is invoked.
  2. If an instance of the Activity is already present but NOT ON TOP, it pops all the other activities and invokes the onNewIntent() method.

android launch mode: singleTask

android singleTask launch mode

SingleInstance

Remember this as: Single Instance in Single Task

In this android launch mode, just like Single Task a new Task is created and the activity placed at the root. But this new task will only contain that activity instance and nothing else. If a new activity is launched from this, then it’s done in a separate task.

Since only one instance can remain in a task:

  1. If an instance of the activity exists in a different task, then onNewIntent() method is called for that activity.
  2. If a new Activity is launched from a singleInstance activity, it’s launched in a separate task.

launch modes single instance

 

Comments

Popular posts from this blog

Android - Using KeyStore to encrypt and decrypt the data

Stack and Queue

Java Reflection API