Is Main Method Compulsory in Java?

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

3K+ Views

To compile a program, you doesn’t really need a main method in your program. But, while execution JVM searches for the main method. In the Java the main method is the entry point Whenever you execute a program in Java JVM searches for the main method and starts executing from it.The main method must be public, static, with return type void, and a String array as argument.public static int main(String[] args){ }You can write a program without defining a main it gets compiled without compilation errors. But when you execute it a run time error is generated saying “Main method ... Read More

HTML DOM Input Checkbox Form Property

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

193 Views

The HTML DOM Input Checkbox form property returns the form containing the input checkbox.SyntaxFollowing is the syntax −Returning reference to the form objectinputCheckboxObject.formExampleLet us see an example of HTML DOM Input Checkbox form property − Live Demo Student Details Show Form ID: Get ID of form containing this Checkbox    function getFormID(){       var checkboxFilter = document.getElementById("formID");       var showResultDiv = document.getElementById("showResult");       if(checkboxFilter.checked == true){          showResultDiv.textContent = 'Form ID: ' + checkboxFilter.form.id;       } else {          showResultDiv.textContent = 'Check the checkbox';       }    } OutputThis will produce the following output −Before checking ‘Show Form ID’ checkbox −After checking ‘Show Form ID’ checkbox −

BFS Using STL for Competitive Coding in C++

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

687 Views

The Breadth First Search (BFS) traversal is an algorithm, which is used to visit all of the nodes of a given graph. In this traversal algorithm one node is selected and then all of the adjacent nodes are visited one by one. After completing all of the adjacent vertices, it moves further to check another vertices and checks its adjacent vertices again.In The competitive coding, we have to solve problems very quickly. We will use the STL (Standard Library of C++) to implement this algorithm, we need to use the Queue data structure. All the adjacent vertices are added into ... Read More

Sort a List that Places Nulls First in Java

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

579 Views

Let us create a list first with string elements. Some of the elements are null in the List:List list = Arrays.asList("Jack", null, "Thor", null, "Loki", "Peter", null, "Hulk");Now, sort the above list and place nulls first with nullsFirst:list.sort(Comparator.nullsFirst(String::compareTo));The following is an example to sort a List that places nulls first:Exampleimport java.util.Arrays; import java.util.Comparator; import java.util.List; public class Demo {    public static void main(String... args) {       List list = Arrays.asList("Jack", null, "Thor", null, "Loki", "Peter", null, "Hulk");       System.out.println("Initial List = "+list);       list.sort(Comparator.nullsFirst(String::compareTo));       System.out.println("List placing nulls first = "+list); ... Read More

Catch Ctrl+C Event in C++

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

14K+ Views

The CTRL + C is used to send an interrupt to the current executing task. In this program, we will see how to catch the CTRL + C event using C++.The CTRL + C is one signal in C or C++. So we can catch by signal catching technique. For this signal, the code is SIGINT (Signal for Interrupt). Here the signal is caught by signal() function. Then one callback address is passed to call function after getting the signal.Please see the program to get the better idea.Example#include #include #include #include using namespace std; // Define ... Read More

Increment Inside the Update Function in MongoDB

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

306 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,    "insertedId" : ObjectId("5cd2b407345990cee87fd895") }Following is the query to display all documents from a collection with the help of find() method −> db.addInUpdateFunctionDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd2b3f4345990cee87fd893"),    "PlayerName" : "Chris",    "PlayerScore" : 78 } {    "_id" : ObjectId("5cd2b3fc345990cee87fd894"),    "PlayerName" : "Robert", ... Read More

Set JCheckBoxMenuItem for a MenuItem in Java

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

154 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 for a MenuItem in Java −Examplepackage my; import java.awt.Color; import java.awt.event.KeyEvent; import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.UIManager; public class SwingDemo {    public static void main(final String args[]) {       JFrame frame = new JFrame("MenuBar Demo");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     ... Read More

Display Vertical Grid Lines in a Table with Java

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

432 Views

To display vertical grid lines in a table, use the setShowVerticalLines() method. Let us first create a 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" }; JTable table = new JTable(rec, header);Now, let us display vertical grid lines −table.setShowVerticalLines(true);You can also give a color to these lines −table.setGridColor(Color.blue);The following is an example to display vertical grid lines in JTable ... Read More

Count Most Frequently Occurring Values in MySQL

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

1K+ Views

For this, use the aggregate function COUNT() along with GROUP BY. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Value int    ); Query OK, 0 rows affected (0.74 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Value) values(976); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(Value) values(67); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Value) values(67); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(Value) values(1); Query OK, 1 row affected (0.27 sec) mysql> ... Read More

HTML DOM Input Checkbox Name Property

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

166 Views

The HTML DOM Input Checkbox name property returns a string, which is the value of the name attribute of input checkbox. User can also set it to a new string.SyntaxFollowing is the syntax −Returning string valueinputCheckboxObject.nameSetting name attribute to a string valueinputCheckboxObject.name = ‘String’ExampleLet us see an example of Input Checkbox name property − Live Demo Name Attribute of Checkbox Enable new name: Change Name Attribute    function getFormID(){       var oldNameAttr = document.getElementById("formID");       var newNameAttr = document.getElementById("nameAttr");       if(oldNameAttr.checked == true){     ... Read More

Advertisements