Found 9150 Articles for Object Oriented Programming

What is the importance of _isEqual() method in JavaScript?

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

1K+ Views

_isEqual() _isEqual() is from the underscore and lodash library of javascript. It is used to compare javascript objects. The importance of this method is that it doesn't care about the order of properties while comparing the objects. It only checks whether the properties in the two objects are equal or not. Whereas JSON.stringify(), which is used in comparing the objects, checks even the order of properties of the objects, making _isEqual() the better option. syntax_.isEqual(object1, object2);It accepts two objects as parameters and scrutinizes whether they are equal or not.ExampleLive Demo    var obj1 = {name: "Sikha", designation: "Content developer"}; ... Read More

What are the different types of JOptionPane dialogs in Java?

Alshifa Hasnain
Updated on 11-Apr-2025 12:24:55

11K+ Views

The JOptionPane is a subclass of the JComponent class, which includes static methods for creating and customizing modal dialog boxes using a simple code. The JOptionPane is used instead of JDialog to minimize the complexity of the code. The JOptionPane displays the dialog boxes with one of the four standard icons (question, information, warning, and error) or the custom icons specified by the user. Types of Dialogue Boxes in JOptionPane The JOptionPane class is used to display four types of dialog boxes: MessageDialog ConfirmDialog InputDialog ... Read More

How to convert a double value to String in Java?

Venkata Sai
Updated on 04-May-2022 13:10:21

2K+ Views

The double data type in Java stores double-precision 64-bit IEEE 754 floating point number. It is used as the default type for decimal value in Java.Like all other primitive variables double also have a wrapper class (Double) wrapping the primitive data type. Since java supports auto boxing, the primitive value and the object can be used interchangeably.You can convert a double value into String in various different ways in Java −Using the “+” operator −The + operator is an addition operator but when used with Strings it acts as a concatenation operator. It concatenates the other operand to String and ... Read More

What are the rules to be followed while making a variable static and final?

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

312 Views

Static variables − Static variables are also known as class variables. You can declare a variable static using the keyword. Once you declare a variable static there would only be one copy of it in the class, regardless of how many objects are created from it.public static int num = 39;final − Once you declare a variable final you cannot reassign value to it. When you declare a variable of a class static and final we are making it constant.Rules to be followedInitialization is mandatory − It is not mandatory to initialize the instance variables of a class in java. ... Read More

How to implement constants in java?

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

1K+ Views

A constant variable is the one whose value is fixed and only one copy of it exists in the program. Once you declare a constant variable and assign value to it, you cannot change its value again throughout the program.You can create a constant in c language using the constant keyword (one way to create it) as −const int intererConstant = 100; or, const float floatConstant = 16.254; ….. etcConstants in javaUnlike in C language constants are not supported in Java(directly). But, you can still create a constant by declaring a variable static and final.Static − Once you declare a ... Read More

Can we use Switch statement with Strings in java?

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

11K+ Views

A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.Syntaxswitch(expression) {    case value :       // Statements       break;    case value :       // Statements       break;       // You can have any number of case statements.       default :     // Statements }Strings in switchYes, we can use a switch statement with Strings in Java. While doing so you need ... Read More

What happens when you add a double value to a String in java?

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

2K+ Views

The “+” operator with a String acts as a concatenation operator.Whenever you add a String value to a double using the “+” operator, both values are concatenated resulting a String object.In-fact adding a double value to String is the easiest way to convert a double value to Strings.Exampleimport java.util.Scanner;    public class StringsExample {       public static void main(String args[]){          Scanner sc = new Scanner(System.in);          System.out.println("Enter a double value: ");          double d = sc.nextDouble();          System.out.println("Enter a String value: ");       ... Read More

What are the rules to be followed while using varargs in java?

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

287 Views

Since JSE1.5 you can pass a variable number of values as argument to a method. These arguments are known as var args and they are represented by three dots (…)Syntaxpublic myMethod(int ... a) { // method body }Rules to follow while using varargs in JavaWe can have only one variable argument per method. If you try to use more than one variable arguments a compile time error is generated.ExampleIn the following Java example we are trying to accepts two varargs from the method sample().public class VarargsExample{ void demoMethod(int... ages), String... names) { ... Read More

Explain about Varargs in java?

Deepti S
Updated on 29-Aug-2023 15:41:22

553 Views

A method can accept a variable number of parameters thanks to a Java feature called variable arguments, or varargs. This can be helpful for methods that need to be able to manage an unknown or variable number of inputs. We had two ways to handle methods that needed to take a variable number of arguments prior to introduction of varargs in Java 5. One way was to use overloaded methods. The method has to be developed in numerous iterations, each with a different number of arguments. If the process had many arguments, it might become complicated and challenging ... Read More

What is variable shadowing in java?

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

5K+ Views

In Java you can declare three types of variables namely, instance variables, static variables and, local variables.Local variables − Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and the variable will be destroyed when the method has completed.Instance variables − Instance variables are variables within a class but outside any method. These variables are initialized when the class is instantiated. Instance variables can be accessed from inside any method, constructor or blocks of that particular class.Class (static) variables − Class variables are variables declared within a class, ... Read More

Advertisements