Anvi Jain has Published 569 Articles

Get the path of the file selected in the JFileChooser component with Java

Anvi Jain

Anvi Jain

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

1K+ Views

To get the path of the selected file, at first get the selected file −java.io.File f = file.getSelectedFile();Now, get the path of the selected file which we will get using the above method −System.err.println(f.getPath());The following is an example to get the path of the file selected in the JFileChooser component ... Read More

Why do we pass a Pointer by Reference in C++?

Anvi Jain

Anvi Jain

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

823 Views

If we need to modify a pointer rather than the object that the pointer is pointing to, we pass a pointer by reference.Here is an example of how to pass a pointer by reference −Example Live Demo#include using namespace std; void Decrement( int*& d ) {    --d; } int ... Read More

How to search documents through an integer array in MongoDB?

Anvi Jain

Anvi Jain

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

328 Views

You can use $where operator for this. Let us first create a collection with documents −>db.searchDocumentArrayIntegerDemo.insertOne({"StudentFirstName":"John", "StudentScores":[45, 78, 89, 90]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd2a219345990cee87fd88c") } >db.searchDocumentArrayIntegerDemo.insertOne({"StudentFirstName":"Larry", "StudentScores":[45, 43, 34, 33]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd2a22a345990cee87fd88d") } >db.searchDocumentArrayIntegerDemo.insertOne({"StudentFirstName":"Chris", "StudentScores":[]}); {    "acknowledged" ... Read More

Set whether the column in the table model can be selected or deselected in Java?

Anvi Jain

Anvi Jain

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

71 Views

We can set or disallow selection of column in the table using setColumnSelectionAllowed().Let’s say the following is our table −DefaultTableModel tableModel = new DefaultTableModel(); JTable table = new JTable(tableModel);If you want to allow selection of column, then set the method to TRUE −table.setColumnSelectionAllowed(true);If you want to disallow selection of column, ... Read More

C++ Program to Solve Travelling Salesman Problem for Unweighted Graph

Anvi Jain

Anvi Jain

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

4K+ Views

Travelling Salesman Problem use to calculate the shortest route to cover all the cities and return back to the origin city. This method is use to find the shortest path to cover all the nodes of a graph.This is the program to find shortest route of a unweighted graph.AlgorithmBegin   ... Read More

Using G++ to compile multiple .cpp and .h files

Anvi Jain

Anvi Jain

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

5K+ Views

To compile multiple files like file_name.h, or file_name.cpp at once, we can use the files like a list one after another. The syntax will be like this −g++ abc.h xyz.cppTo run the program, we can use this −./a.outExamplefloat area(float r){    return (3.1415*r*r); //area of a circle } float area(float ... Read More

Check for null in MongoDB?

Anvi Jain

Anvi Jain

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

588 Views

We will use the Null type here. Following are the null types with the alias −TypeNumberAliasDouble1“double”String2“string”Object3“object”Array4“array”Binary data5“binData”Undefined6“undefined”ObjectId7“objectId”Boolean8“bool”Date9“date”Null10“null”Regular Expression11“regex”Following is the syntax for type 10 i.e. null −db.yourCollectionName.find({"yourFieldName":{ $type: 10 } });The above syntax will find only those documents which have null value. Let us first create a collection with documents ... Read More

How to increment inside the update() function in MongoDB?

Anvi Jain

Anvi Jain

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

300 Views

You can use $inc operator to increment. Let us first create a collection with documents −> db.addInUpdateFunctionDemo.insertOne({"PlayerName":"Chris", "PlayerScore":78}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd2b3f4345990cee87fd893") } > db.addInUpdateFunctionDemo.insertOne({"PlayerName":"Robert", "PlayerScore":88}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd2b3fc345990cee87fd894") } > db.addInUpdateFunctionDemo.insertOne({"PlayerName":"David", "PlayerScore":99}); {    "acknowledged" : true,   ... Read More

How to set JCheckBoxMenuItem for a MenuItem in Java?

Anvi Jain

Anvi Jain

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

148 Views

Let’s say we have a menu and within that we need to set the JCheckBoxMenuItem. Here’s the Menu −JMenu editMenu = new JMenu("Edit"); editMenu.setMnemonic(KeyEvent.VK_E); menuBar.add(editMenu);Now, set the JCheckBoxMenuItem and add it to the editMenu created above −JCheckBoxMenuItem checkMenuItem = new JCheckBoxMenuItem("SelectAll"); checkMenuItem.setMnemonic(KeyEvent.VK_B); editMenu.add(checkMenuItem);The following is an example to set JCheckBoxMenuItem ... Read More

C++ Program to Find Closest Pair of Points in an Array

Anvi Jain

Anvi Jain

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

829 Views

This is the program to find closest pair of points in an array.AlgorithmsFor Distance between Closest pointBegin    Declare function Closest_dist_Spoint(poi stp[], int s, double dist, poi &pnt1, poi &pnt2) to the double datatype.    Declare Minimum to the double datatype.       Initialize Minimum = dist.    for ... Read More

Advertisements