To set value in the JavaTuples KeyValue class, you need to use the setValue() method. Let us first see what we need to work with JavaTuples. To work with KeyValue class in JavaTuples, you need to import the following packageimport org.javatuples.KeyValue;Note Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project -> Properties -> Java Build Path -> Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuplesSteps: How to run JavaTuples program in EclipseThe following is an example to set ... Read More
You can use $facet operator for this. To understand the concept, let us create a collection with document. The query to create a collection with document is as follows −> db.totalDocumentDemo.insertOne({"InstructorId":100, "InstructorName":"Larry", "InstructorFav ouriteSubject":["Java", "MongoDB", "Python"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c76e6701e9c5dd6f1f78274") } > db.totalDocumentDemo.insertOne({"InstructorId":200, "InstructorName":"Sam", "InstructorFav ouriteSubject":["SQL Server", "C#", "Javascript"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c76e69c1e9c5dd6f1f78275") }Display all documents from a collection with the help of find() method. The query is as follows −> db.totalDocumentDemo.find().pretty();Output{ "_id" : ObjectId("5c76e6701e9c5dd6f1f78274"), "InstructorId" : 100, "InstructorName" : "Larry", "InstructorFavouriteSubject" : [ ... Read More
To find the largest document size in MongoDB, you need to write a script in the shell.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.largestDocumentDemo.insertOne({"StudentName":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ed2e32f684a30fbdfd57d") } > db.largestDocumentDemo.insertOne({"StudentName":"Carol", "StudentAge":22, "StudentCountryName":"US", "TechnicalSubject":["C", "C++", "Java", "MySQL"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ed3282f684a30fbdfd57e") } > db.largestDocumentDemo.insertOne({"StudentName":"Mike", "StudentAge":22}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ed3382f684a30fbdfd57f") }Display all documents from a collection with the help of find() method. The query is as follows −> ... Read More
The valueOf() method of the Date object accepts a String value representing a Date in JDBC escape format i.e. yyyy-mm-dd and converts the given String value into java.sql.Date object.Date date = Date.valueOf(“date_string”);Assume we have created a table named employee_data with the description as shown below:+----------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+--------------+------+-----+---------+-------+ | id | int(11) | YES | | NULL | | | Name | varchar(255) | YES | ... Read More
It is not possible to return only embedded document. However, it will return all the documents from a collection. Let us first implement the following query to create a collection with documents>db.queryToEmbeddedDocument.insertOne({"UserName":"Larry", "PostDetails":[{"UserMessage":"Hello", "UserLikes":8}, {"UserMessage":"Hi", "UserLikes":6}, {"UserMessage":"Good Morning", "UserLikes":12}, {"UserMessage":"Awesome", "UserLikes":4}]}); { "acknowledged" : true, "insertedId" : ObjectId("5c988a9f330fd0aa0d2fe4bd") }Following is the query to display all documents from a collection with the help of find() method> db.queryToEmbeddedDocument.find().pretty();This will produce the following output{ "_id" : ObjectId("5c988a9f330fd0aa0d2fe4bd"), "UserName" : "Larry", "PostDetails" : [ { "UserMessage" : "Hello", ... Read More
The variable declaration must be between BEGIN and END. Under BEGIN and END, the first statement must be declaration of variable. After that you can include insert, select, etc.Let us now see an example. Here, the variable name is “output”:mysql> DELIMITER // mysql> CREATE PROCEDURE showVariablesValue() -> BEGIN -> DECLARE output varchar(100); -> SET output="Hello MySQL"; -> SELECT output; -> END -> // Query OK, 0 rows affected (0.25 sec) mysql> DELIMITER ;Now you can call the stored procedure using call ... Read More
For random numbers in Java, create a Random class object −Random randNum = new Random();Now, create a HashSet to get only the unique elements i.e. no duplicates −Setset = new LinkedHashSet();Generate random numbers with Random class nextInt −while (set.size() < 5) { set.add(randNum.nextInt(5)+1); }Exampleimport java.util.LinkedHashSet; import java.util.Random; import java.util.Set; public class Demo { public static void main(final String[] args) throws Exception { Random randNum = new Random(); Setset = new LinkedHashSet(); while (set.size() < 5) { set.add(randNum.nextInt(5)+1); } System.out.println("Random numbers with no duplicates = "+set); } }OutputRandom numbers with no duplicates = [2, 4, 1, 3, 5]
This is a C++ Program to Generate N Number of Passwords of Length M Each.AlgorithmBegin Take the length of password as input. function permutation() generate random passwords: /* Arguments A pointer array a. Total Number of random numbers m. Length of the password s. */ // Body of the function: if (m == s) for i = 0 to s-1 Print *(a + i) else for i = m to s-1 ... Read More
Let us take an example here: for those interested in gaming, a PC offers an experience that truly has a flavor of it’s own. Yet perhaps, the most interesting aspect of this whole debate, is a line from Ray Ozzie, Microsoft’s former Chief Software Architect who matter of factly states “Why are we arguing? Of course, we are in a post-PC world” Somewhere, this line denotes a certain acceptance of the turn of events.Gamers like SmartphonesWith each passing year, we get introduced to yet another fleet of mobile devices that are way more powerful than those preceding it. We're at ... Read More
The equality of two Java clock objects can be checked using the method equals() in the Clock Class in Java. This method requires a single parameter i.e. the object that is to be compared with the existing clock object. Also it returns true if both the clock objects are equal and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Clock; import java.time.ZoneId; public class Demo { public static void main(String[] args) { Clock c1 = Clock.systemDefaultZone(); Clock c2 = Clock.systemDefaultZone(); System.out.println("Clock c1: " + c1.toString()); ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP