Ankith Reddy has Published 996 Articles

MongoDB query to select one field if the other is null and the first field if both are not null?

Ankith Reddy

Ankith Reddy

Updated on 30-Jul-2019 22:30:26

446 Views

For this, use $ifNull operatorLet us first create a collection with documents −> dbquerySelectDemoinsertOne({"Value1":10, "Value2":null}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cefc0ceef71edecf6a1f6b6") } > dbquerySelectDemoinsertOne({"Value1":null, "Value2":30}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cefc0d7ef71edecf6a1f6b7") } > dbquerySelectDemoinsertOne({"Value1":60, "Value2":40}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cefc0e2ef71edecf6a1f6b8") ... Read More

Check whether a node is a root node or not in JTree

Ankith Reddy

Ankith Reddy

Updated on 30-Jul-2019 22:30:26

295 Views

To check whether a node is a root node or not, use the isRoot() method. This returns a boolean value. TRUE if the node is a root node, else FALSE is returned. For example, TRUE is returned since the following node is a root node −node.isRoot()Another example, FALSE is returned ... Read More

How to add Internal Frame to a JDesktopPane in Java?

Ankith Reddy

Ankith Reddy

Updated on 30-Jul-2019 22:30:26

676 Views

At first, create a JDesktoPane −JDesktopPane desktopPane = new JDesktopPane();Now, create an Internal frame and add it to the JDesktopPane −JInternalFrame intFrame = new JInternalFrame("Our Frame", true, true, true, true); desktopPane.add(intFrame); The following is an example to add Internal Frame to a JDesktopPane − package my; import java.awt.BorderLayout; import javax.swing.JButton; ... Read More

HTML

Ankith Reddy

Ankith Reddy

Updated on 30-Jul-2019 22:30:26

412 Views

The name attribute of the element is used to set the name for a button. More than one button can have the same name, but we can submit different values from these buttons using the name attribute.Following is the syntax −Above, btn_name is the name of the button. Let ... Read More

Specify return format in MongoDB to return the values as an array?

Ankith Reddy

Ankith Reddy

Updated on 30-Jul-2019 22:30:26

216 Views

Use aggregation for this and add the values to an array using the $group and $addToSet operatorLet us first create a collection with documents −> dbspecifyReturnFormatDemoinsertOne({"Subject":"MongoDB"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cefd364ef71edecf6a1f6c0") } > dbspecifyReturnFormatDemoinsertOne({"Subject":"MySQL"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cefd369ef71edecf6a1f6c1") } > dbspecifyReturnFormatDemoinsertOne({"Subject":"SQL ... Read More

Get the number of siblings of a node in JTree with Java

Ankith Reddy

Ankith Reddy

Updated on 30-Jul-2019 22:30:26

248 Views

Use the getSiblingCount() method to get the number of siblings of a node in JTree. For example, let’s say we have a node, which isn’t a root node. For that, we will find the sibling count −node1.getSiblingCount()The following is an example to get the number of siblings of a node ... Read More

How to print results of script in MongoDB?

Ankith Reddy

Ankith Reddy

Updated on 30-Jul-2019 22:30:26

1K+ Views

We will use printjson() for this. Let us first create a collection with documents −> dbprintResultScriptDemoinsertOne({"StudentName":"John", "StudentAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cf22c02b64a577be5a2bc0b") } > dbprintResultScriptDemoinsertOne({"StudentName":"Carol", "StudentAge":20}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cf22c09b64a577be5a2bc0c") } > dbprintResultScriptDemoinsertOne({"StudentName":"David", "StudentAge":19}); {    "acknowledged" : true,    "insertedId" ... Read More

How to set TabLayout Policy to JTabbedPane in Java when all the tabs does not fit in a single run

Ankith Reddy

Ankith Reddy

Updated on 30-Jul-2019 22:30:26

409 Views

To set TabLayout Policy to JTabbedPane in Java when all the tabs does not fit in a single run, use the method setTabLayoutPolicy() −JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);Above we have set the constant to be SCROLL_TAB_LAYOUT, which is a tab layout policy for providing a subset of available tabs ... Read More

Make the JSlider vertical and move top-to-bottom in Java

Ankith Reddy

Ankith Reddy

Updated on 30-Jul-2019 22:30:26

265 Views

To set the JSlider to be vertical, use the VERTICAL constant while creating the slider −JSlider slider = new JSlider(JSlider.VERTICAL, 0, 100, 60);Now, for the inverted slider i.e. moving from top-to-bottom −slider.setInverted(true);The following is an example to set the slider vertical and move top-to-bottom −Examplepackage my; import javax.swing.JFrame; import javax.swing.JPanel; ... Read More

HTML DOM Anchor hreflang Property

Ankith Reddy

Ankith Reddy

Updated on 30-Jul-2019 22:30:26

119 Views

The HTML DOM Anchor hreflang property is used to set or return the value of the hreflang attribute of a link.Following is the syntax to set the hreflang property −anchorObj.hreflang = language_codeAbove, language_code represents the language of the linked document. This language code examples, include en for English, bn for ... Read More

Advertisements