Selection modes sets the table's selection mode to allow only single selections, a single contiguous interval, or multiple intervals. Let us see the selection modes one by one −Single Selection modeThe following is an example of Single Selection mode for a JTable. It allows you to select one cell at a time −Examplepackage my; import java.awt.Color; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.border.TitledBorder; public class SwingDemo { public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); ... Read More
To query array of nested string, you can use the dot(.) notation. Let us first create a collection with documents −> db.nestedStringDemo.insertOne( { "CustomerName": "John", "CustomerOtherDetails": [ { "Age":29, "CountryName": "US" }, { "CompanyName": "Amazon", "Salary": 150000, "ProjectName": ["Online Library Management System", "Pig Dice Game"] } ] } ); { "acknowledged" : true, "insertedId" : ObjectId("5cea4629ef71edecf6a1f690") } > db.nestedStringDemo.insertOne( { "CustomerName": "Chris", "CustomerOtherDetails": [ { "Age":27, "CountryName": "AUS" }, { "CompanyName": "Google", "Salary": 250000, "ProjectName": ["Chat Application", "Game ... Read More
In Java classes and interfaces related to each other are grouped under a package. Package is nothing but a directory storing classes and interfaces of a particular concept. For example, all the classes and interfaces related to input and output operations are stored in java.io package.There are two types of packages namely user-defined packages and built-in packages (pre-defined)The import keywordWhenever you need to use the classes from a particular package −First of all, you need to set class path for the JAR file holding the required package.Import the required class from the package using the import keyword. While importing you ... Read More
Adding up all natural numbers up to n, that are divisible by X or Y is selecting all the numbers that are divisible by X or Y and adding them to a variable that stores the sum.To find the sum of the first N natural numbers which are divisible by X or Y, there are two methods −Using loops and conditional statementsUsing formulaMethod 1 − Using loops and conditional statementsThis method uses a loop that counts up to n numbers and selects numbers that are divisible by X or Y and adds them and save to a variables at each ... Read More
Selenium 2Selenium2 is nothing but integration of WebDriver with Selenium RC(Selenium1). Selenium 1 is a well-established framework that supports various many browsers due to its JavaScript implementation. To step out of JavaScript Sandbox, WebDriver is developed for each browser which provides a headless browser emulator which is very speedy. The strengths of both WebDriver and Selenium 1 are imbibed in Selenium2 which also helps in getting rid of their respective drawbacks.Selenium 3For users of WebDriver API’s, this is a drop-in replacement. The major change being, removing the core and replacing it with the back-end WebDriver. Selenium 3.0 has become a ... Read More
This is a C++ program to find ith largest number from a given list using Order-Statistic Algorithm.AlgorithmsBegin function Insert() to insert nodes into the tree: Arguments: root, d. Body of the function: If tree is completely null then insert new node as root. If d = tmp->data, increase the count of that particular node. If d < tmp->data, move the tmp pointer to the left child. If d > tmp->data, move the tmp pointer to the right child. End Begin ... Read More
The DROP TABLE removes the table completely and also removes all data. If you want to remove all data completely and wants the table structure, then you can use TRUNCATE TABLE command. The TRUNCATE command will recreate the table.Let us first check the DROP TABLE. For that, we will first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(20) ); Query OK, 0 rows affected (0.20 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name) values('Larry'); Query OK, 1 row affected (0.07 sec) ... Read More
Let us first set rows and columns for our table −String[][] rec = { { "1", "Steve", "AUS" }, { "2", "Virat", "IND" }, { "3", "Kane", "NZ" }, { "4", "David", "AUS" }, { "5", "Ben", "ENG" }, { "6", "Eion", "ENG" }, }; String[] header = { "Rank", "Player", "Country" };Now, set the above in a table as rows and columns −JTable table = new JTable(rec, header);Add the table in the panel −JPanel panel = new JPanel(); panel.add(new JScrollPane(table));The following is an example to create a table in a panel −Examplepackage my; ... Read More
To retrieve an embedded object as a document, use the aggregation $replaceRoot. Let us first create a collection with documents −> db.embeddedObjectDemo.insertOne( { _id: new ObjectId(), "UserDetails": { "UserName": "John", "UserAge": 24, "UserEmailId": "John22@gmail.com" } } ); { "acknowledged" : true, "insertedId" : ObjectId("5ced580fef71edecf6a1f693") } > db.embeddedObjectDemo.insertOne( { _id: new ObjectId(), "UserDetails": { "UserName": "Carol", "UserAge": 26, "UserEmailId": "Carol123@gmail.com" } } ); { "acknowledged" : true, "insertedId" : ObjectId("5ced5828ef71edecf6a1f694") }Following is the query to display all documents from a collection with the help of find() method −> db.embeddedObjectDemo.find().pretty();This will produce the ... Read More
The program to print the sum of the first N prime numbers uses the method to find n prime numbers and then add them to find the sum. This sum is saved to an integer that outputs the sum .The code takes a number checks it for prime, if it is prime then adds it to the sum variable. Till n prime number it does the same and then after that it prints the sum.Example Code Live Demo#include int isprime(int j) { int count=0; for(int i = 2 ; i