Programming Articles - Page 2583 of 3366

Comparison of floating point values in PHP.

Alok Prasad
Updated on 31-Dec-2019 08:15:59

919 Views

In PHP, testing floating point values for equality is problematic, because PHP is failing when checking if one floating point number is equal to another. Despite the fact floating point numbers seems to have the same value do not need to actually be identical. So in this article will demonstrate the problem we are facing in comparison of Floating-Point Numbers and different procedures to avoid this problem.ExampleLet's test this with a simple example:output:a and b are not same.Explanation:In this code, the else condition is executed instead of the if condition, even though $a and $b are the same. It is ... Read More

How to handle the Runtime Exception in Java?

Shriansh Kumar
Updated on 14-May-2025 14:21:29

13K+ Views

The error that occurs at runtime after successful compilation of the Java program is called a runtime error or unchecked exception. It disrupts the normal flow of a program’s execution and terminates the program abruptly.These errors are not detected by the compiler but by JVM. The runtime errors in Java are represented by a class called RuntimeException. In this article, we are going to learn what RuntimeException is and its common types. Also, we will discuss how to handle RuntimeException in Java. What is RuntimeException in Java? In Java, the RuntimeException of the java.lang package is a parent class of ... Read More

Comparison between "&&" and "AND" operator in PHP.

Alok Prasad
Updated on 31-Dec-2019 09:28:32

543 Views

PHP offers incredible operators to perform operations such as arithmetic, assignment, comparison and many more ...In this article, more importance will be laid on logical operators "&&" and "AND" and will study how they can be utilized based on their precedence. Logical operators "&&" and "AND" produce true-or-false as results, and therefore these are also known as Boolean operators. Before diving into deep let's learn what is "AND" operator? "AND" operator returns true if and only if both the conditions are true. Let's take an example to demonstrate "AND" operator.ExampleOutput:TrueExplanation:Since variable $val1 = 20 and $val2 = 50, the condition $val1 ... Read More

How can closures cause memory leak and how to prevent it?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

2K+ Views

ClosureOne of the strengths of javascript is closures. Javascript allows nested functions, a function inside a function, to access the variables of parent functions. This process of accessing outer function's variable by an inner function is called a closure. A memory leak occurs when a declared variable is automatically available to the inner nested function and resides in a memory despite it is not referenced in the inner nested function.In the following example 'childFunction' is the inner function defined within the 'parentFunction' the outer function. When a call is made to 'parentFunction' with a parameter "outer val", the outer variable ... Read More

How to solve an IllegalArgumentException in Java?

Shriansh Kumar
Updated on 12-May-2025 11:34:05

30K+ Views

In Java, an IllegalArgumentException is thrown in order to indicate that a method has been passed an illegal argument. An illegal argument is one that does not meet the required input from user. This exception extends the RuntimeException class and thus, belongs to those exceptions that can be thrown during the operation of the Java Virtual Machine (JVM). It is an unchecked exception and thus, it does not need to be declared in a method's or a constructor's throws clause. Reasons for java.lang.IllegalArgumentException Some of the reasons for IllegalArgumentException in Java is as follows: ... Read More

How to create a submenu for a Menu in Java

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

2K+ Views

Let us first create a MenuBar −JMenuBar menuBar = new JMenuBar(); UIManager.put("MenuBar.background", Color.ORANGE);To create a submenu for a Menu, the following is an example −Examplepackage my; import java.awt.Color; import java.awt.event.KeyEvent; import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; 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);       JMenuBar menuBar = new JMenuBar();       UIManager.put("MenuBar.background", Color.ORANGE);       JMenu fileMenu = new JMenu("File");       fileMenu.setMnemonic(KeyEvent.VK_F);       menuBar.add(fileMenu); ... Read More

How to create a Default Cell Editor that uses a JComboBox in Java?

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

349 Views

Create a combo box first and set some values −JComboBox comboBox = new JComboBox(new String[]{"Product1", "Product2", "Product3", "Product4"});Seth the JComboBox for the editor so that the editor uses the combo box −TreeCellEditor editor = new DefaultCellEditor(comboBox); tree.setEditable(true); tree.setCellEditor(editor);The following is an example to create a Default Cell Editor that uses a JComboBox −Examplepackage my; import javax.swing.DefaultCellEditor; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeCellEditor; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame("Demo");       DefaultMutableTreeNode node = new DefaultMutableTreeNode("Products");       DefaultMutableTreeNode node1 ... Read More

How to implement quick sort in JavaScript?

Nikhilesh Aleti
Updated on 19-Dec-2022 16:54:07

3K+ Views

In this article, we are going to discuss how to implement quick sort in JavaScript with suitable examples. Quick sort The Quick sort is a divide and conquers algorithm similar to the merge sort. In this, we pick a pivot element and divide the array around the pivot element. There are many ways to pick the pivot element. Always pick the first element as a pivot element. Always pick the last element as a pivot element. (Implemented in the below program) Pick a random element as pivot element Pick the middle element as pivot element. The main process ... Read More

Concatenation of two strings in PHP

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

3K+ Views

PHP offers different kinds of operators having distinctive functionalities. Operators enable us to perform arithmetic activities, string concatenation, compare values and to perform boolean operations, more...In this article, we will learn string operators given by PHP. Let's first learn the types of string operators in php. There are two string operators provided by PHP.  1.Concatenation Operator ("."):      This operator combines two string values and returns it as a new string. 2.Concatenating Assignment operator (".="):      This operation attaches the argument on the right side to the argument on the left side. Let's demonstrate the utility of the above operators by following examples.Example:Output ... Read More

How to automatically resize a JTree in Java

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

387 Views

To automatically resize a JTree, use the setVisibleRowCount() method in Java. At first, create a node in the tree −DefaultMutableTreeNode node = new DefaultMutableTreeNode("Project");Now, add nodes to the node created above −DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("App"); DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("Website"); DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("WebApp"); node.add(node1); node.add(node2); node.add(node3);Now, create more nodes and set them as child nodes for the nodes we creted above −DefaultMutableTreeNode one = new DefaultMutableTreeNode("Learning website"); DefaultMutableTreeNode two = new DefaultMutableTreeNode("Business website"); DefaultMutableTreeNode three = new DefaultMutableTreeNode("News publishing website"); DefaultMutableTreeNode four = new DefaultMutableTreeNode("Android app"); DefaultMutableTreeNode five = new DefaultMutableTreeNode("iOS app"); DefaultMutableTreeNode six = new DefaultMutableTreeNode("Editor ... Read More

Advertisements