Get Default Device SDK Version in Android

Chandu yadav
Updated on 30-Jul-2019 22:30:25

224 Views

This example demonstrate about How to get default device sdk version in android.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.     In the above code, we have taken text view to show device sdk version.Step 3 − Add the following code to java/MainActivity.xmlpackage com.example.myapplication; import android.Manifest; import android.content.Context; import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.RequiresApi; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AppCompatActivity; import android.telephony.TelephonyManager; import android.widget.TextView; import static android.Manifest.permission.READ_PHONE_NUMBERS; import ... Read More

Duration isZero Method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

136 Views

It can be checked if the duration is of zero length or not using the isZero() method in the Duration class in Java. This method requires no parameters. Also, it returns true if the duration is of zero length and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo { public static void main(String[] args) { Duration d = Duration.ofHours(1); boolean flag = d.isZero(); System.out.println("The duration is: " + d); ... Read More

IntStream count Method in Java

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

160 Views

The count() method of the IntStream class in Java returns the count of elements in this streamThe syntax is as followslong count()First, create an IntStream and add some elementsIntStream intStream = IntStream.of(30, 13, 67, 56, 89, 99, 76, 56);Now, get the count of elements of the stream using the count() methodlong num = intStream.count();The following is an example to implement IntStream count() method in JavaExample Live Demoimport java.util.*; import java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       IntStream intStream = IntStream.of(30, 13, 67, 56, 89, 99, 76, 56);       long num = ... Read More

Get Distinct Record Values in MongoDB

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

475 Views

You can use distinct() method in MongoDB to get distinct record values. The syntax is as follows −db.yourCollectionName.distinct(“yourFieldName”);To understand the above syntax, let us create a collection with document. The query to create a collection with document is as follows −> db.distinctRecordDemo.insertOne({"StudentId":1, "StudentName":"John", "StudentAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c77a78299b97a65744c1b50") } > db.distinctRecordDemo.insertOne({"StudentId":2, "StudentName":"John", "StudentAge":22}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c77a78b99b97a65744c1b51") } > db.distinctRecordDemo.insertOne({"StudentId":3, "StudentName":"Carol", "StudentAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c77a79a99b97a65744c1b52") } > db.distinctRecordDemo.insertOne({"StudentId":4, "StudentName":"Carol", "StudentAge":26}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c77a7a499b97a65744c1b53") } > db.distinctRecordDemo.insertOne({"StudentId":5, "StudentName":"Sam", "StudentAge":24}); ... Read More

Find Minimum Value in MongoDB

Smita Kapse
Updated on 30-Jul-2019 22:30:25

1K+ Views

To find the minimum value in MongoDB, you can use sort() along with limit(1). The syntax is as follows −db.yourCollectionName.find().sort({yourFieldName: 1}).limit(1);To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.findMinValueDemo.insertOne({"StudentMarks":78}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8f80ea2f684a30fbdfd59f") } > db.findMinValueDemo.insertOne({"StudentMarks":69}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8f80f02f684a30fbdfd5a0") } > db.findMinValueDemo.insertOne({"StudentMarks":79}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8f80f32f684a30fbdfd5a1") } > db.findMinValueDemo.insertOne({"StudentMarks":59}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8f80f82f684a30fbdfd5a2") } > db.findMinValueDemo.insertOne({"StudentMarks":91}); {    "acknowledged" : true,   ... Read More

Insert Data into a CachedRowSet in JDBC

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

730 Views

The CachedRowSet is the base implementation of disconnected row sets. It connects to the data source, reads data from it, disconnects with the data source and the processes the retrieved data, reconnects to the data source and writes the modifications.Creating a CachedRowSetYou can create a Cached RowSet object using the createCachedRowSet() method of the RowSetFactory.You can create a RowSetFactory object using the newfactory() method of the RowSetProvider method.Create a CachedRowSet object using the above mentioned methods as shown below −//Creating the RowSet object RowSetFactory factory = RowSetProvider.newFactory(); CachedRowSet rowSet = factory.createCachedRowSet();Connecting to the data sourceAfter creating a RowSet object you ... Read More

Clear Items in a Nested MongoDB Array

George John
Updated on 30-Jul-2019 22:30:25

135 Views

To clear items in a nested array, use the $set operator. Let us first create a collection. Following is the query to create a collection with documents> db.clearingItemsInNestedArrayDemo.insertOne( { ... ...    "StudentName" : "John", ...    "StudentDetails" : [ ...       { ...          "ProjectName" : "Online Banking", ...          "ProjectDetails" : [ ...             { ...                "TechnologyUsed" : "Java", ...                "TeamSize":5 ...             }, ... ... ... Read More

Add Value to the Top of an Array in MongoDB

Samual Sam
Updated on 30-Jul-2019 22:30:25

230 Views

To add a value to the top of an array in MongoDB, you can use unshift() −yourArrayName.unshift("yourValue");The above syntax will add the value to the top of an array in MongoDB. Let us first create an array of strings −> technicalSkills=["Java", "MySQL", "C", "SQL SERVER", "ORACLE", "PL/SQL"];This will produce the following output −[ "Java", "MySQL", "C", "SQL SERVER", "ORACLE", "PL/SQL" ]Following is the query to add to the top of an array in MongoDB. Here, we will add “MongoDB” to top of an array using unshift() −> technicalSkills.unshift("MongoDB"); This will produce the following output −7Let us check the “MongoDB” has ... Read More

Get Total Number of Rows While Using LIMIT in MySQL

Samual Sam
Updated on 30-Jul-2019 22:30:25

1K+ Views

To get the total number of rows when using LIMIT, use the following syntax −select SQL_CALC_FOUND_ROWS * FROM yourTableName LIMIT 0, yourLastValue;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table RowsUsingLimit -> ( -> Id int NOT NULL, -> Name varchar(10) -> ); Query OK, 0 rows affected (3.50 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into RowsUsingLimit values(10, 'Larry'); Query OK, ... Read More

Iterate Through Triplet Class in JavaTuples

Samual Sam
Updated on 30-Jul-2019 22:30:25

303 Views

The iteration in Triplet class works in the same way as Arrays collection.Let us first see what we need to work with JavaTuples. To work with Triplet class in JavaTuples, you need to import the following package −import org.javatuples.Triplet;Note − Steps to download and run JavaTuples program If you are using Eclipse IDE to run Triplet Class in JavaTuples, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file.The following is an example −Exampleimport org.javatuples.Triplet; public class Demo {    public static void main(String[] args) {       ... Read More

Advertisements