ShortBuffer hasArray Method in Java

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

108 Views

It can be checked if a buffer has the backing of an accessible short array by using the method hasArray() in the class java.nio.ShortBuffer. This method returns true if the buffer has the backing of an accessible double array and false otherwise.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 { ShortBuffer buffer = ShortBuffer.allocate(5); ... Read More

Duration toString Method in Java

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

180 Views

The string value of the duration can be obtained using the method toString() in the Duration class in Java. This method requires no parameters and it returns the string value of the duration.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.ofDays(2); System.out.println("The duration is: " + d.toString()); } }OutputThe duration is: PT48HNow let us understand the above program.The string value of the duration is obtained ... Read More

Create Triplet Tuple in Java Using with Method

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

124 Views

You can also create a Triplet tuple using with() method.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) {       Triplet < String, ... Read More

Add Positive Integer Constraint to Integer Column in MySQL

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

2K+ Views

You need to use unsigned for this because it won’t allow you to enter a negative number.The syntax is as followsCREATE TABLE yourTableName ( yourColumnName INT UNSIGNED );To understand the concept, let us create a table. The query to create a table is as followsmysql> create table OnlyPositiveValue - > ( - > Marks int UNSIGNED - > ); Query OK, 0 rows affected (0.58 sec)Before inserting data in the table, use the below query.The query is as followsmysql> SET @@SESSION.sql_mode = 'STRICT_TRANS_TABLES'; Query OK, 0 rows affected, ... Read More

Send Simple Text-Based Email Using JSP

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

311 Views

To send an email using a JSP, you should have the JavaMail API and the Java Activation Framework (JAF) installed on your machine.You can download the latest version of JavaMail (Version 1.2) from the Java's standard website.You can download the latest version of JavaBeans Activation Framework JAF (Version 1.0.2) from the Java's standard website.Download and unzip these files, in the newly-created top-level directories. You will find a number of jar files for both the applications. You need to add the mail.jar and the activation.jar files in your CLASSPATH.Send a Simple EmailHere is an example to send a simple email from ... Read More

Duration compareTo Method in Java

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

8K+ Views

Two durations can be compared using the compareTo() method in the Duration class in Java. This method requires a single parameter i.e. the duration to be compared.If the first duration is greater than the second duration it returns a positive number, if the first duration is lesser than the second duration it returns a negative number and if both the durations are equal it returns zero.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 d1 = Duration.ofHours(8); ... Read More

Collectors averagingDouble Method in Java 8

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

563 Views

The averagingDouble() method of the Collectors class in Java 8 returns a Collector that is the arithmetic mean of a double-valued function applied to the input elements.The syntax is as follows −public static Collector averagingDouble(ToDoubleFunction

View and Table with the Same Name in MySQL

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

1K+ Views

No, you cannot give the same name for view and table in MySQL.Let us first create a demo table −mysql> create table view_Table_Demo    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.80 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into view_Table_Demo values(100, 'Larry'); Query OK, 1 row affected (0.17 sec) mysql> insert into view_Table_Demo values(101, 'Mike'); Query OK, 1 row affected (0.20 sec) mysql> insert into view_Table_Demo values(102, 'Sam'); Query OK, 1 row affected (0.14 sec)Display all ... Read More

C++ Program to Implement Binary Heap

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

4K+ Views

A Binary Heap is a complete binary tree which is either Min Heap or Max Heap. In a Max Binary Heap, the key at root must be maximum among all keys present in Binary Heap. This property must be recursively true for all nodes in that Binary Tree. Min Binary Heap is similar to MinHeap.Function descriptions:void BHeap::Insert(int ele): Perform insertion operation to insert element in heap.void BHeap::DeleteMin(): Perform deleteion operation to delete minimum value from heap.int BHeap::ExtractMin(): Perfrom operation to extract minimum value from heap.void BHeap::showHeap(): To show the elements of heap.void BHeap::heapifyup(int in): maintain heap structure in bottom up ... Read More

Find All Non-Distinct Values of a Field in MongoDB

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

1K+ Views

Use aggregate() method to get all the non-distinct values of a field. Let us first create a collection with documents> db.findAllNonDistinctDemo.insertOne({"UserName":"John", "UserAge":28}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c995078863d6ffd454bb647") } > db.findAllNonDistinctDemo.insertOne({"UserName":"Larry", "UserAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c995081863d6ffd454bb648") } > db.findAllNonDistinctDemo.insertOne({"UserName":"Larry", "UserAge":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c995089863d6ffd454bb649") } > db.findAllNonDistinctDemo.insertOne({"UserName":"David", "UserAge":22}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c995093863d6ffd454bb64a") } > db.findAllNonDistinctDemo.insertOne({"UserName":"John", "UserAge":26}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c99509d863d6ffd454bb64b") } > db.findAllNonDistinctDemo.insertOne({"UserName":"Robert", "UserAge":24}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9950a7863d6ffd454bb64c") } > db.findAllNonDistinctDemo.insertOne({"UserName":"Robert", "UserAge":25}); ... Read More

Advertisements