Found 9150 Articles for Object Oriented Programming

How to check whether a NaN is a NaN or not in JavaScript?

Manisha Patil
Updated on 04-Aug-2022 11:50:13

389 Views

In this article let us understand how to check whether a NaN is a NaN or not in JavaScript. Literal constant that is not quoted Not-a-Number is represented by NaN, a special value. NaN is commonly used to signal an error condition for a function that should return a valid number since it always compares unequally to any number, including NaN. Differentiating between different undefined values in JavaScript can be tricky. When working with NaN values in Boolean operations, there are a handful of difficulties to be careful of. The numeric type in JavaScript permits you to describe numbers of ... Read More

What is the importance of str.padStart() method in JavaScript?

vineeth.mariserla
Updated on 30-Jun-2020 15:31:18

189 Views

We can attach two strings using the concat() method. But if we need to attach a specific string at the starting of the first string then the easiest way is string.padStart(). This method not only adds the second string at the start of the first string but also looks after the number of characters to be added. It basically takes two parameters one is the length and the other is second string. The method string.padStart() add the second string to the first based on the length provided to it.syntaxstring.padStart(length, "string");It takes the length as the parameter to concise the resulted string to those ... Read More

How many types of selection modes for a JList in Java?

raja
Updated on 10-Feb-2020 07:01:22

812 Views

A JList is a component that can extend JComponent class used to display a list of objects that allows the user to select one or more items.There are three types of selection modes for a JList in JavaListSelectionModel.SINGLE_SELECTION: Only one list index can be selected at a time.ListSelectionModel.SINGLE_INTERVAL_SELECTION: Only one contiguous interval can be selected at a time.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION: In this mode, there is no restriction on what can be selected. This is a default mode.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class JListSelectionModeTest extends JFrame implements ActionListener {    private JList list;    private DefaultListModel listModel;    public JListSelectionModeTest() {     ... Read More

How to concatenate two strings so that the second string must concatenate at the end of first string in JavaScript?

vineeth.mariserla
Updated on 27-Jul-2022 07:58:42

1K+ Views

concat() methodThe fundamental operation for combining two strings is concatenation. String combining is a necessary part of programming. We need to first clear out the fundamentals before we can discuss "String Concatenation in JavaScript." A new string is produced when an interpreter performs the operation.In order to create a new string, the concat() method joins the calling string and the string arguments. The initial string and the string that was returned are unaffected by changes to either.When concatenating, string values are first transformed from parameters that are not of the type string.SyntaxFollowing is the syntax of concat() methodconcat(str1) concat(str1, str2) ... Read More

How to implement a program to count the number in Java?

raja
Updated on 10-Feb-2020 06:17:01

1K+ Views

The program uses a JLabel to hold a count label, a JTextField component to hold the number count, JButton component to create add, remove and reset buttons. When we click the add button, the count in the JTextField will get incremented by '1' and by clicking the remove button the count will be decremented by '1'. If we click the Reset button, it will reset the count to '0'.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class CounterTest extends JFrame implements ActionListener {    private JLabel label;    private JTextField text;    private JButton addBtn, removeBtn, resetBtn;    private int count;    public CounterTest() {       setTitle("Counter Test");   ... Read More

How can we set a border to JCheckBox in Java?

Alshifa Hasnain
Updated on 05-May-2025 18:33:11

674 Views

In this article, we will learn to set a border for JCheckBox in Java. JCheckBox is a Swing component that is commonly used in user interface selection. Although it includes a default appearance, we can customize its look by setting borders in order to have a good visual effect. What is a JCheckBox? A JCheckBox is a component that extends JToggleButton, and an object of JCheckBox represents an option that can be checked or unchecked. Syntax The following is the syntax for JCheckBox initialization: JCheckBox Checkbox_name = new JCheckBox(); If there are two or more options, then any ... Read More

How to modify an array value of a JSON object in JavaScript?

Sai Teja Kotha
Updated on 07-Dec-2022 12:59:09

7K+ Views

In this article, we are going to discuss how to modify an array value of a JSON object in JavaScript. We try to update a new value or modify the existing value in an array. Modifying an array is just like modifying an object when that array is inside the object. The normal general principles of modifying will apply here. Syntax Following is the syntax of the for…in statement. for (var in obj) { //code } Example 1 In this example, we are trying to loop through an array using the for…in statement. This statement ... Read More

How can we implement cut, copy and paste functionality of JTextField in Java?

Alshifa Hasnain
Updated on 21-Apr-2025 19:27:48

2K+ Views

A JTextField is a child class of the JTextComponent class through which a single line of text can be edited. Cut, copy, and paste operations of the JTextField component can be implemented using the cut(), copy(), and paste() methods. These are built-in methods in the JTextField class. built-in methodsJTextField class The Cut Operation Cutting involves removing selected text from the JTextField and placing it on the clipboard. Method Declaration: public void cut() { textField.cut(); } The Copy Operation Copying places a copy of the selected text on the clipboard without removing it from the JTextField. Method ... Read More

What are the differences between a JTextField and a JFormattedTextField in Java?

Alshifa Hasnain
Updated on 23-Apr-2025 17:18:55

1K+ Views

In Java, a JTextField can be used for plain text, whereas a JFormattedTextField is a class that extends JTextField, and it can be used to set any format to the text that it contains, phone numbers, e-mails, dates, etc. JTextField A JTextField is one of the most important components that allows the user to type an input text value in a single-line format. A JTextField can also generate the MouseListener and KeyListener interfaces. Syntax The following is the syntax for a JTextField initialization: JTextField textField = new JTextField(20); // 20 columns wide A JTextField can generate an ActionListener interface ... Read More

How to get the Width and Height of the screen in JavaScript?

Sai Teja Kotha
Updated on 07-Dec-2022 12:51:20

9K+ Views

In this article, we are going to discuss how to get the width and height of the screen in JavaScript. Javascript provides an window.screen object that contains information regarding the user's screen. The information includes height and width, and also many other features. To find the height and width of the screen you need to use the following read-only properties Screen.height − This property is used to get the height of the screen in pixels. Screen.width − This property is used to get the width of the screen in pixels. Syntax Following is the syntax of the height ... Read More

Advertisements