Duration dividedBy Method in Java

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

97 Views

An immutable copy of a duration where the required duration is divided by a value can be obtained using the method dividedBy() in the Duration class in Java. This method requires a single parameter i.e. the value which is to be divided and it returns the immutable copy of the duration which is divided by a value.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; import java.time.temporal.*; public class Demo {    public static void main(String[] args) {       Duration d = Duration.ofHours(15);       System.out.println("The duration is: " + d);       ... Read More

List All Databases in the Mongo Shell

Anvi Jain
Updated on 30-Jul-2019 22:30:25

721 Views

To list all databases in the Mongo shell, you need to use show command. The syntax is as follows −show dbs;Let us implement the above syntax for MongoDB. The query is as follows −> show dbs;The following is the output −admin 0.000GB config 0.000GB local 0.000GB sample 0.000GB sampleDemo 0.000GB test 0.003GBIf you create a new database in MongoDB then it won’t be present in list of databases.Let us check the same. Create a new database −> use studentTracker; switched to db studentTrackerNow list all the databases from Mongo shell. The query is as follows −> show dbs;The following is ... Read More

Achieve Pagination with MongoDB

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

284 Views

You can achieve pagination with the help of limit() and skip() in MongoDB.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.paginationDemo.insertOne({"CustomerName":"Chris", "CustomerAge":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c949de44cf1f7a64fa4df52") } > db.paginationDemo.insertOne({"CustomerName":"Robert", "CustomerAge":26}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c949df14cf1f7a64fa4df53") } > db.paginationDemo.insertOne({"CustomerName":"David", "CustomerAge":24}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c949dfc4cf1f7a64fa4df54") } > db.paginationDemo.insertOne({"CustomerName":"Carol", "CustomerAge":28}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c949e3e4cf1f7a64fa4df55") } > db.paginationDemo.insertOne({"CustomerName":"Bob", "CustomerAge":29}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c949e474cf1f7a64fa4df56") ... Read More

C++ Program for Inorder Tree Traversal Without Recursion

Anvi Jain
Updated on 30-Jul-2019 22:30:25

675 Views

If a binary tree is traversed in-order, the left subtree is visited first, then the root and later the right sub-tree. The output the key in ascending order in in_order traversal. This is a C++ Program for Inorder Tree Traversal without Recursion.AlgorithmBegin      Function inOrder():       Declare a stack s.       Declare the current node as root.       While current node is not null and stack is not empty do          While current node is not null do             Push the current node on the ... Read More

Evaluation Order of Function Parameters in C

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

626 Views

We pass different arguments into some functions. Now one questions may come in our mind, that what the order of evaluation of the function parameters. Is it left to right, or right to left?To check the evaluation order we will use a simple program. Here some parameters are passing. From the output we can find how they are evaluated.Example Code#include void test_function(int x, int y, int z) {    printf("The value of x: %d", x);    printf("The value of y: %d", y);    printf("The value of z: %d", z); } main() {    int a = 10;    test_function(a++, a++, ... Read More

Get Returned Record Set Ordered by Position in MySQL IN Clause

Anvi Jain
Updated on 30-Jul-2019 22:30:25

126 Views

To return record set order, you need to use FIND_IN_SET(). Let us first create a table −mysql> create table recordSetOrderDemo    -> (    -> EmployeeId int,    -> EmployeeName varchar(30)    -> ); Query OK, 0 rows affected (0.63 sec)Following is the query to insert some records in the table using insert command −mysql> insert into recordSetOrderDemo values(20, "John"); Query OK, 1 row affected (0.20 sec) mysql> insert into recordSetOrderDemo values(10, "Larry"); Query OK, 1 row affected (0.14 sec) mysql> insert into recordSetOrderDemo values(100, "Mike"); Query OK, 1 row affected (0.14 sec) mysql> insert into recordSetOrderDemo ... Read More

MySQL Query to List All Items in a Group in One Record

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

1K+ Views

You can use GROUP_CONCAT() function to list all the items in a group in one record. Let us first create a table −mysql> create table DemoTable (    ProductId int,    ProductName varchar(40),    ProductCategory varchar(40) ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Product-1', '1Product'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(101, 'Product-2', '2Product'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(100, 'Product-1', '3Product'); Query OK, 1 row affected (0.14 sec)Following is the query to display all ... Read More

FloatBuffer allocate Method in Java

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

127 Views

A new FloatBuffer can be allocated using the method allocate() in the class java.nio.FloatBuffer. This method requires a single parameter i.e. the capacity of the buffer. It returns the new FloatBuffer that is allocated. If the capacity provided is negative, then the IllegalArgumentException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          FloatBuffer buffer = FloatBuffer.allocate(n);          buffer.put(4.5F);          buffer.put(1.2F);   ... Read More

KeyPairGenerator getAlgorithm Method in Java

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

90 Views

The algorithm name for the key pair generator can be obtained using the method getAlgorithm() in the class java.security.KeyPairGenerator. This method requires no parameters and it returns the algorithm name for the key pair generator.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo {    public static void main(String[] argv) {       try {          KeyPairGenerator kpGenerator = KeyPairGenerator.getInstance("DSA");          String algorithm = kpGenerator.getAlgorithm();          System.out.println("The Algorithm is: " + algorithm);       } catch (NoSuchAlgorithmException e) {     ... Read More

Use OR and Conjunctive Operators in Android SQLite

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

141 Views

Before getting into example, we should know what sqlite data base in android is. SQLite is an open source SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. SQLite supports all the relational database features. In order to access this database, you don't need to establish any kind of connections for it like JDBC, ODBC etc.This example demonstrate about How to use OR Conjunctive Operators in Android sqlite.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details ... Read More

Advertisements