A Subscription can be shared by exactly one Publisher and one Subscriber for the purpose of mediating data exchange. That is the reason subscribe() method doesn't return created Subscription, instead returns void. The Subscription is only passed to Subscriber through the onSubscribe() method callback. The Subscription interface contains two methods: request() and cancel().Syntaxpublic interface Subscription { public void request(long n); public void cancel(); }Rules for Subscription interface:Subscription.request() and Subscription.cancel() methods must be called only inside of its Subscriber context.Subscription must allow Subscriber to call the Subscription.request() method synchronously from within onNext() or onSubscribe() methods.Subscription.request() method must place an upper ... Read More
Any element that can be annotated with @Deprecated signifies that this particular element no longer be used for below reasonsUsing it is risky and may cause errors.May be incompatible in future versions.May be removed in future versions.A better and more efficient solution has replaced it.Java 9 has added two new elements: since and forRemoval attributes.1) since: The element specifies the deprecated version of the annotated API element.2) forRemoval: The element representing the annotated API element can be removed in a future version, and the API can be migrated.The following webpage is the documentation for a Boolean class in Java 9. The @Deprecated annotation ... Read More
Try-with-resources statement has been improved in Java 9. If we already have a resource that is final or equivalent to the final variable, then we can use that variable in a try-with-resources statement without having to declare a new variable in a try-with-resources statement.We can declare multiple resources in a try block. Try initialization block can have any number of resources resulting in either null or non-null resources.In the below example, we can able to declare multiple resources in the try-with-resources statement.Exampleimport java.io.BufferedReader; import java.io.IOException; import java.io.Reader; import java.io.StringReader; public class MultipleResourcesTest { public static void main(String args[]) throws ... Read More
JShell is a command-line interactive tool introduced in Java 9 version that allows the programmer to execute simple statements, expressions, variables, methods, classes, interfaces, etc.. without declaring the main() method.In JShell, the compiler warns the programmer about typecasting issues by throwing errors. However, if the programmer is aware of it, then explicit casting will be required. If we need to store a smaller data value into a larger type conversion, then implicit casting will be required.There are two kinds of integer typecasting:Literal-to-variable assignment: For instance, short s1 = 123456, the data is out of range. It is known at compile-time, and the compiler flags an ... Read More
The DateTimeOffset.FromFileTime() method in C# is used to convert the specified Windows file time to an equivalent local time.SyntaxFollowing is the syntax −public static DateTimeOffset FromFileTime (long time);Above, time is the Windows file time, in ticks.ExampleLet us now see an example to implement the DateTimeOffset.FromFileTime() method −using System; public class Demo { public static void Main() { DateTimeOffset offset = DateTimeOffset.FromFileTime(0); Console.WriteLine("DateTimeOffset = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", offset); } }OutputThis will produce the following output −DateTimeOffset = 01 January 1601, 12:00:00ExampleLet us now see another example to implement the DateTimeOffset.FromFileTime() method −using ... Read More
The Type.GetEnumName() method in C# returns the name of the constant that has the specified value, for the current enumeration type.SyntaxFollowing is the syntax −public virtual string GetEnumName (object val);Above, Val is the value whose name is to be retrieved.ExampleLet us now see an example to implement the Type.GetEnumName() method −using System; public class Demo { enum Vehicle {Car, Bus, Bike} public static void Main(){ Vehicle v = Vehicle.Bike; Type type = v.GetType(); string str = type.GetEnumName(v); Console.WriteLine("GetEnumName() to return the constant name = " + ... Read More
This example demonstrates how to use ArrayAdapter in android to create a simple listview in Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to MainActivity.ktimport android.os.Bundle import android.widget.ArrayAdapter import android.widget.ListView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) title = "KotlinApp" val arrayAdapter: ArrayAdapter ... Read More
This example demonstrates how to use SearchView in the Toolbar in Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇉ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Open res/strings.xml and add the following code− Q38 January February March April May June July August ... Read More
This example demonstrates how to get Spinner value in Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇉ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Open res/strings.xml and add the following code − Q39 crane Cuckoo Pigeon Eagle Owl Vulture WoodPecker Step 4 − Add the ... Read More
This example demonstrates programmatically turning off and turning on WiFi in Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇉ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to MainActivity.ktimport android.net.wifi.WifiManager import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View import android.widget.Toast class MainActivity : AppCompatActivity() { lateinit var wifiManager: WifiManager override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) title = "KotlinApp" ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP