Method Overloading and Null Error in Java

AmitDiwan
Updated on 14-Sep-2020 08:55:40

871 Views

When method is overloaded in Java, the functions have the same name, and the number of parameters to the function is same. In such cases, if the parameters are non-primitive and have the ability to accept null values, the compiler gets confused when the function is called with a null value, since it can’t choose either of them, because both of them have the ability to accept null values. This results in a compile time error.ExampleBelow is an example showing the same − Live Demopublic class Demo {    public void my_function(Integer i) {       System.out.println("The function with integer ... Read More

Convert Buffer to Readable String in JavaScript

AmitDiwan
Updated on 14-Sep-2020 08:55:00

728 Views

For this, use the concept of toString(‘utf8’). Following is the code −In the code below, there are detailed explanations about the buffer.Examplevar actualBufferObject = Buffer.from('[John Smith]', 'utf8') console.log("The actual buffer object="); console.log(JSON.stringify(actualBufferObject)) console.log("Get back the original object="); console.log(actualBufferObject.toString('utf8')); var myObjectValue = '[John Smith]'; console.log("The data you are getting from the buffer is equal to ASCII code equivalent...") for (var counter = 0; counter < myObjectValue.length; counter++) {    console.log("The ascii value of " + myObjectValue[counter] + " is ="    + (myObjectValue.charCodeAt(counter))); }To run the above program, you need to use the following command −node fileName.js.Here, my file name is ... Read More

Multiset Interface in Java

AmitDiwan
Updated on 14-Sep-2020 08:53:29

1K+ Views

Multiset is a collection in Java, that helps in order-independent equality, similar to Set structure. But the only difference is that a multiset can also contain duplicate elements.If multiset is visualized as a list, then this wouldn’t be the case since lists can’t hold duplicate values, and list elements are always in a specific order.Multiset can be thought of as a collection that lies somewhere between a list and a set structure. In multiset, the duplicates values are allowed, and there is no guarantee that the elements in a multiset would occur in a specific order. Multiset is also known ... Read More

Avoid Inserting Null Values to a Table with JavaScript

AmitDiwan
Updated on 14-Sep-2020 08:53:20

607 Views

In order to get rid of null values inserted into a table, you need to check the condition while entering the value.The condition to check NULL must be as follows −while( !( yourVariableName1==null || yourVariableName2==null || yourVariableName3==null…...N){    // yourStatement1    .    .    N }The above logic will never allow inserting the null values.Now you can use for loop and insert value into the table without NULL. Following is the code −Example Live Demo Document Demo Of Inserting the value into the table This is demo on the javascript ... Read More

Multimap in Java

AmitDiwan
Updated on 14-Sep-2020 08:51:49

308 Views

Multimap is a general method to bind the keys with random multiple values. The Multimap framework in Guava has methods that help in dealing with mapping keys to multiple values. Multimap can be visualized as a framework that −Is a collection of mapping from one key to one specific valueIs a collection of mapping from unique key to multiple values, i.e. collection of values.It can be implemented in places that use Map.Advantages of MultimapAn empty collection need not be populated before added a key value pair with the help of the function ‘put’.The ‘get’ method doesn’t return a null, except ... Read More

Remove Values in Array by Comparing 0th Index in JavaScript

AmitDiwan
Updated on 14-Sep-2020 08:47:28

252 Views

Let’s say the following is our array &mius;var subjectNameAlongWithMarks = [    ["JavaScript", 78],    ["Java", 56],    ["JavaScript", 58],    ["MySQL", 77],    ["MongoDB", 75],    ["Java", 98] ]Above, we have repeated values, which we need to remove by comparing the duplicate values 0th index. Use the concept of Set() from JavaScript for this −Examplevar subjectNameAlongWithMarks = [    ["JavaScript", 78],    ["Java", 56],    ["JavaScript", 58],    ["MySQL", 77],    ["MongoDB", 75],    ["Java", 98] ] var distinctResult = subjectNameAlongWithMarks.filter(function ([value]){    return !this.has(value) && !!this.add(value) }, new Set()) console.log(distinctResult);To run the above program, you need to use ... Read More

Multi-Selection of Checkboxes on Button Click in jQuery

AmitDiwan
Updated on 14-Sep-2020 08:46:08

463 Views

For this, use jQuery() with id property. Following is the code −Example Live Demo Document    .changeColor {       color: red    }; Javascript MySQL MongoDB Python    jQuery("#selectDemo").click(function () {       jQuery(this).toggleClass("changeColor");       if (jQuery(this).hasClass("changeColor")) {          jQuery(".isSelected").prop("checked", true);          jQuery(this).val("Want To UnSelect All Values");       } else {   ... Read More

Searching Characters and Substring in a String in Java

AmitDiwan
Updated on 14-Sep-2020 08:44:41

647 Views

Following is the Java program to search characters and substring in a string −Example Live Demoimport java.io.*; import java.lang.*; public class Demo {    public static void main (String[] args) {       String test_str = "Hello";       CharSequence seq = "He";       boolean bool_1 = test_str.contains(seq);       System.out.println("Was the substring found? " + bool_1);       boolean bool_2 = test_str.contains("Lo");       System.out.println("Was the substring found? " + bool_2);    } }OutputWas the substring found? true Was the substring found? FalseA class named Demo contains the main function. Here, a string ... Read More

JavaScript Parent and Child Classes with Same Method Name

AmitDiwan
Updated on 14-Sep-2020 08:42:46

1K+ Views

Yes, parent and child classes can have a method with the same name.Exampleclass Parent {    constructor(parentValue) {       this.parentValue = parentValue;    }    //Parent class method name which is same as Child Class method name.    showValues() {       console.log("The parent method is called.....");       console.log("the value is="+this.parentValue);    } } class Child extends Parent {    constructor(parentValue, childValue){       super(parentValue);       this.childValue = childValue;    }    //Child class method name which is same as Parent Class method name.    showValues() {       console.log("The child ... Read More

Filter JSON Data with Multiple Objects

AmitDiwan
Updated on 14-Sep-2020 08:40:38

17K+ Views

To filter JSON data with multiple objects, you can use the concept of filter along with ==.Exampleconst jsonObject= [    {       studentId:101,       studentName:"David"    },    {       studentId:102,       studentName:"Mike"    },    {       studentId:103,       studentName:"David"    },    {       studentId:104,       studentName:"Bob"    } ] var result=jsonObject.filter(obj=> obj.studentName == "David"); console.log(result);To run the above program, you need to use the following command −node fileName.js.OutputHere, my file name is demo194.js. This will produce the following output −PS C:\Users\Amit\javascript-code> node demo194.js [    { studentId: 101, studentName: 'David' },    { studentId: 103, studentName: 'David' } ]

Advertisements