Nishtha Thakur

Nishtha Thakur

398 Articles Published

Articles by Nishtha Thakur

Page 17 of 40

How to filter array elements in MongoDB?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 353 Views

You can use $setIntersection operator along with aggregate framework to filter array elements in MongoDB. Let us first create a collection with documents −> db.filterArrayElementsDemo.insertOne( { "Scores": [10, 45, 67, 78, 90, 98, 99, 92] } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd2d582b64f4b851c3a13c8") }Following is the query to display all documents from a collection with the help of find() method −> db.filterArrayElementsDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd2d582b64f4b851c3a13c8"),    "Scores" : [       10,       45,       67,       78,       90,   ...

Read More

How to ceate right justified JTextField in Java?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 2K+ Views

To create right justified JTextField, set the alignment to be RIGHT. Here, we will be using the setHorizontalAlignment() method as well and within that the alignment would be set.Create a JTextField −JTextField emailId = new JTextField(20);Now, align it to the right −emailId.setHorizontalAlignment(JTextField.RIGHT);The following is an example to create right justified JTextField −Examplepackage my; import java.awt.FlowLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.SwingConstants; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame("Enter emailid...");       JLabel label;       frame.setLayout(new FlowLayout());       label = ...

Read More

nextafter() and nexttoward() in C/C++

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 311 Views

Here we will see the effect of nextafter() and nextforward() functions in C or C++. These functions are present in the math.h or cmath library.if the functions are like nextafter(a, b) and nextforward(a, b). These functions are used to find the next representable value after a in the direction of b. The nextforward() has more precise second parameter b.Example#include #include main () {    //The nextafter function()    printf ("Smallest representable number after 0 towards 1 : %e", nextafter(0.0, 1.0));    printf ("Largest representable number before -1 towards 0 :%e", nextafter(0.0, -1.0));    printf ("Largest +ve representable number ...

Read More

Get at least one match in list querying with MongoDB?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 470 Views

Use $in operator to get at least one match. Let us first create a collection with documents −> db.atleastOneMatchDemo.insertOne({"StudentFavouriteSubject":["MySQL", "MongoDB"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd2db5db64f4b851c3a13ce") } > db.atleastOneMatchDemo.insertOne({"StudentFavouriteSubject":["Java", "C", "MongoDB"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd2db71b64f4b851c3a13cf") } > db.atleastOneMatchDemo.insertOne({"StudentFavouriteSubject":["Python", "C++", "SQL Server"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd2db87b64f4b851c3a13d0") } >db.atleastOneMatchDemo.insertOne({"StudentFavouriteSubject":["Ruby", "Javascript", "C#", "MySQL"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd2dba9b64f4b851c3a13d1") }Following is the query to display all documents from a collection with the help of find() method −> db.atleastOneMatchDemo.find().pretty();This will produce the following output −{    "_id" : ...

Read More

How do I search according to fields in inner classes using MongoDB db.coll.find()?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 196 Views

Use dot notation(.) to search in inner classes using MongoDB. Let us first create a collection with documents −> db.searchInInnerDemo.insertOne( ...    { ...       "StudentFirstName" : "Robert", ...       "StudentTechnicalDetails": ...       { ...          "StudentBackEndTechnology" : "MongoDB", ...          "StudentLanguage" : "Java" ...       } ...    } ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd2dd89b64f4b851c3a13d2") } > > db.searchInInnerDemo.insertOne( ...    { ...       "StudentFirstName" : "David", ...       "StudentTechnicalDetails": ...       { ... ...

Read More

Get all fields names in a MongoDB collection?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 3K+ Views

You can use the concept of Map Reduce. Let us first create a collection with documents −> db.getAllFieldNamesDemo.insertOne({"StudentFirstName":"David", "StudentAge":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd998e9b50a6c6dd317ad90") }Following is the query to display all documents from a collection with the help of find() method −> db.getAllFieldNamesDemo.find();This will produce the following output −{ "_id" : ObjectId("5cd998e9b50a6c6dd317ad90"), "StudentFirstName" : "David", "StudentAge" : 23 }Following is the query to get all fields names in a MongoDB collection −> myMapReduce = db.runCommand({    "mapreduce" : "getAllFieldNamesDemo",    "map" : function() {       for (var myKey in this) { emit(myKey, null); } ...

Read More

Java Program to enable drag and drop between two text fields in Java

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 554 Views

Yes, we can enable drag and drop between two text fields in Java. Let us first create two JTextFields and set content in it as shown below −JTextField one = new JTextField(20); one.setText("You can drag!"); JTextField two = new JTextField(20); two.setText("Drag here or there");Now, we will enable and drag and drop for both the components created above −one.setDragEnabled(true); two.setDragEnabled(true);The following is an example to enable drag and drop between two text fields −Examplepackage my; import java.awt.Container; import java.awt.FlowLayout; import javax.swing.BoxLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.SwingConstants; public class SwingDemo {    public static void main(String[] args) throws Exception ...

Read More

pthread_self() in C

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 9K+ Views

Here we will see what will be the effect of pthread_self() in C. The pthread_self() function is used to get the ID of the current thread. This function can uniquely identify the existing threads. But if there are multiple threads, and one thread is completed, then that id can be reused. So for all running threads, the ids are unique.Example#include #include #include void* func(void* p) {    printf("From the function, the thread id = %d", pthread_self()); //get current thread id       pthread_exit(NULL);    return NULL; } main() {    pthread_t thread; // declare thread   ...

Read More

How to determine if an activity has been called by a Notification in Android?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 452 Views

This example demonstrate about How to determine if an activity has been called by a Notification in AndroidStep 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.     Step 3 − Add the following code to src/MainActivity.package app.tutorialspoint.com.notifyme ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.app.PendingIntent ; import android.content.Intent ; import android.os.Bundle ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.util.Log ; import android.view.View ; public class MainActivity extends AppCompatActivity {    public ...

Read More

How to allow only a single tree node to be selected in a JTree with Java?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 674 Views

Set the selection mode to SINGLE_TREE_SELECTION, if you want only a single tree node to be selected −tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);The following is an example to allow only a single tree node to be selected in a JTree −Examplepackage my; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeSelectionModel; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame("Demo");       DefaultMutableTreeNode node = new DefaultMutableTreeNode("Products");       DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("Clothing");       DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("Electronics");       DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("Home Decor");   ...

Read More
Showing 161–170 of 398 articles
« Prev 1 15 16 17 18 19 40 Next »
Advertisements