It can be checked if a particular Instant object is before the other Instant object in a timeline using the isBefore() method in the Instant class in Java. This method requires a single parameter i.e. the Instant object that is to be compared. It returns true if the Instant object is before the other Instant object and false otherwise.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; import java.time.temporal.ChronoUnit; public class Demo { public static void main(String[] args) { Instant i1 = Instant.parse("2019-01-13T11:45:13.00Z"); Instant i2 = Instant.parse("2019-01-13T15:30:12.00Z"); boolean ... Read More
The time in the form of seconds of the day can be obtained using the toSecondOfDay() method in the LocalTime class in Java. This method requires no parameters and it returns the time in the form of seconds of the day.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main { public static void main(String[] args) { LocalTime lt = LocalTime.parse("05:15:30"); System.out.println("The LocalTime is: " + lt); System.out.println("The seconds of the day are: " + lt.toSecondOfDay()); } }OutputThe LocalTime is: 05:15:30 The seconds of ... Read More
In MongoDB, there is no concept of columns since MongoDB is schema-less and does not contain tables. It contains the concept of collections and a collection has different types of documents to store items.Let us see the syntax −db.yourCollectionName.insertOne({“YourFieldName”:yourValue, “yourFieldName”:”yourValue”, .......N});If you want a single record from a collection, you can use findOne() and in order to get all records from the collection, you can use find().The syntax is as follows −db.yourCollectionName.findOne(); //Get Single Record db.yourCollectionName.find(); // Get All RecordTo understand the above syntax, let us create a collection with the document. The query to create a collection with a ... Read More
A hash table is a data structure which is used to store key-value pairs. Hash function is used by hash table to compute an index into an array in which an element will be inserted or searched.This is a C++ Program to Implement Hash Tables Chaining with List Heads.AlgorithmFor insert:Begin Declare function Insert(int k, int v) int hash_v = HashFunc(k) if (ht[hash_v] == NULL) ht[hash_v] = new ListHead(k, v) else ListHead *en = ht[hash_v] while (en->n != NULL) ... Read More
For this, use ORDER BY along with GROUP BY clause. Let us first create a table with Student Name and Score −mysql> create table countRowValueDemo -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20), -> StudentMathScore int -> ); Query OK, 0 rows affected (0.71 sec)Following is the query to insert records in the table using insert command −mysql> insert into countRowValueDemo(StudentName, StudentMathScore) values('Larry', 45); Query OK, 1 row affected (0.19 sec) mysql> insert into countRowValueDemo(StudentName, StudentMathScore) values('Mike', 56); Query OK, 1 row affected (0.16 sec) mysql> insert into ... Read More
To convert positive int to negative and vice-versa, use the Bitwise Complement Operator.Let us first initialize a positive int −int positiveVal = 200;Now, let us convert it to negative −int negativeVal = (~(positiveVal - 1));Now, let’s say we have the following negative int −int negativeVal = -300;The following will convert the negative to positive int −positiveVal = ~(negativeVal - 1);Example Live Demopublic class Demo { public static void main(String[] args) throws java.lang.Exception { int positiveVal = 100; int negativeVal = (~(positiveVal - 1)); System.out.println("Result: Positive value converted to Negative = "+negativeVal); ... Read More
To sort time in AM/PM in MySQL, you can use ORDER BY STR_TO_DATE(). Following is the syntax −select yourColumnName from yourTableName ORDER BY STR_TO_DATE(yourColumnName , '%l:%i %p');Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserLogoutTime varchar(200) ); Query OK, 0 rows affected (0.97 sec)Insert records in the table using insert command −mysql> insert into DemoTable(UserLogoutTime) values('09:45 PM'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(UserLogoutTime) values('11:56 AM'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(UserLogoutTime) values('01:01 AM'); Query OK, 1 row affected (0.17 ... Read More
We have seen previously that the linker is invoked in three modes i.e. they are command line mode, prompt mode and data file mode. In the Prompt mode the linker is run by simply typing the ‘LINK85’. Responding to the prompt the linker requests the user for the file name. In the given example, responding with ‘MULT.OBJ’ is there in fact MULT is enough.The linker prompts for the address of the offset. The value of the offset which is input by means of the user is finally added to the value of any ORG statements in the file. In response ... Read More
We use this method when there is a lack of accurate knowledge of the timing characteristics of the Input Output device which takes maximum time for the device to be ready for use. Suppose we resort for the checking of data transfer; the processor here wastes a huge time in the loop for the device to get ready up to the mark. For avoiding this problem, we use the interrupt-driven data transfer process. Here the processor goes ahead with its desired work, and as soon as the device is ready for data transfer process, the corresponding Input Output port sends ... Read More
This example demonstrates How to write an image file in external storage with runtime permission 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 a button. When user click on button, it will store data in external storage.Step 3 − Add the following code to src/MainActivity.javapackage com.example.andy.myapplication; import android.annotation.TargetApi; import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; ... Read More