You can use distinct() to get the equivalent of select distinct. Let us first create a collection with documents −> db.distinctNameAndAgeDemo.insertOne({"ClientFirstName":"John", "Age":23}); { "acknowledged" : true, "insertedId" : ObjectId("5cd12759e3526dbddbbfb60b") } > db.distinctNameAndAgeDemo.insertOne({"ClientFirstName":"Larry", "Age":25}); { "acknowledged" : true, "insertedId" : ObjectId("5cd12768e3526dbddbbfb60c") } > db.distinctNameAndAgeDemo.insertOne({"ClientFirstName":"David", "Age":25}); { "acknowledged" : true, "insertedId" : ObjectId("5cd12773e3526dbddbbfb60d") } > db.distinctNameAndAgeDemo.insertOne({"ClientFirstName":"Carol", "Age":26}); { "acknowledged" : true, "insertedId" : ObjectId("5cd1277ee3526dbddbbfb60e") } > db.distinctNameAndAgeDemo.insertOne({"ClientFirstName":"Sam", "Age":25}); { "acknowledged" : true, "insertedId" : ObjectId("5cd12793e3526dbddbbfb60f") } > db.distinctNameAndAgeDemo.insertOne({"ClientFirstName":"Larry", "Age":25}); { "acknowledged" : true, "insertedId" : ObjectId("5cd127a3e3526dbddbbfb610") } > db.distinctNameAndAgeDemo.insertOne({"ClientFirstName":"Carol", "Age":26}); ... Read More
Memory cycleRegardless of the programming language, the memory cycle is almost same for any programming language. There are 3 steps in a memory life cycle1) Allocation of memory .2) use the allocated memory(reading or writing)3) Release the allocated memory when it is unnecessary.The first and last parts are directly connected in low-level languages but are indirectly connected in high-level languages such as JavaScript.1) Allocation of memory in javascriptJavaScript is called garbage collected language, that is when variables are declared, it will automatically allocate memory to them.When there are no more references for the declared variables, allocated memory will be released. ExampleIn the ... Read More
For this, create JOptionPane.QUESTION_MESSAGE and with the user action display individual messages, for example −int res = JOptionPane.showOptionDialog(new JFrame(), "Do you like Cricket?", "Hobbies", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] { "Yes", "No" }, JOptionPane.YES_OPTION); if (res == JOptionPane.YES_OPTION) { System.out.println("Selected Yes!"); }Above, we have displayed a message on console if the user will selects YES button. The following is an example to make JOptionPane to handle Yes, No and Closed buttons −Examplepackage my; import javax.swing.JFrame; import javax.swing.JOptionPane; public class SwingDemo { public static void main(String args[]) { int res = JOptionPane.showOptionDialog(new JFrame(), "Do you like ... Read More
To combine multiple rows into a comma delimited list, use the GROUP_CONCAT() method. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(30), Marks int ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name, Marks) values('John', 67); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable(Name, Marks) values('Carol', 69); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(Name, Marks) values('Sam', 69); Query OK, 1 row affected (0.12 sec) mysql> insert ... Read More
In C++, a null pointer can be defined by as a null pointer constant is an integer constant expression with the value 0, like −int*p = 0;But in c, a null pointer can be defined by as a null pointer constant is an integer constant expression with the value 0 or such an expression cast to void*, like −Int *p = 0;;Orint*p = (void*) 0;In C++11 a keyword “nullptr” is used to represent nullpointer.int* ptr = nullptr;In CExample Live Demo#include int main() { int *p= NULL; //initialize the pointer as null. printf("The value of pointer is %u", p); ... Read More
Creating an exact copy of an existing object in the memory is known as cloning.The clone() method of the class java.lang.Object accepts an object as a parameter, creates and returns a copy of it (clones).In order to use this method, you need to make sure that your class implements the Cloneable interface.Example Live Demoimport java.util.Scanner; public class CloneExample implements Cloneable { private String name; private int age; public CloneExample(String name, int age){ this.name = name; this.age = age; } public void displayData(){ System.out.println("Name : "+this.name); ... Read More
The HTML DOM Select type property returns the value of the type attribute of drop-down list in an HTML document.SyntaxFollowing is the syntax −object.typeExampleLet us see an example of HTML DOM select type property − Live Demo html{ height:100%; } body{ text-align:center; color:#fff; background: radial-gradient( circle farthest-corner at 23.1% 64.6%, rgba(129, 125, 254, 1) 0%, rgba(111, 167, 254, 1) 90% ) no-repeat; height:100%; } p{ font-weight:700; font-size:1.1rem; } .drop-down{ ... Read More
To set single selection for JList, use DefaultListSelectionModel and set it to SINGLE_SELECTION:String values[]= { "One", "Two", "Three", "Four", "Five", "Six"}; JList list = new JList(values); list.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);The following is an example to set the selection mode for JList only for single selection:Examplepackage my; import java.awt.event.*; import java.awt.*; import javax.swing.*; class SwingDemo extends JFrame { static JFrame frame; static JList list; public static void main(String[] args) { frame = new JFrame("JList Demo"); SwingDemo s = new SwingDemo(); JPanel panel = new JPanel(); String values[]= { ... Read More
In C++, the inline keyword is used in different places. To create inline variables, or inline namespace, and as well as to create inline methods or functions.C++ inline function is powerful concept that is commonly used with classes. If a function is inline, the compiler places a copy of the code of that function at each point where the function is called at compile time.Any change to an inline function could require all clients of the function to be recompiled because compiler would need to replace all the code once again otherwise it will continue with old functionality.To inline a ... Read More
If a collection does not exist then MongoDB creates a collection in indexing part. The createdCollectionAutomatically tells that the operation created a collection.For our example, let us create a collection with an index −> db.createCollectionDemo.createIndex({"ClientCountryName":1});This will produce the following output −{ "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 }Let us create a collection with documents −> db.createCollectionDemo.insertOne({"ClientName":"Larry", "ClientCountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2950be3526dbddbbfb612") }Following is the query to display all documents from a collection with the help of find() method −> db.createCollectionDemo.find().pretty();This will produce the following output ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP