Programming Articles - Page 2568 of 3366

How to remove html tags from a string in JavaScript?

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

7K+ Views

Removing HTML tags from a stringWe can remove HTML/XML tags in a string using regular expressions in javascript. HTML elements such as span, div etc. are present between left and right arrows for instance , etc. So replacing the content within the arrows, along with the arrows, with nothing('') can make our task easy.Syntaxstr.replace( /(]+)>)/ig, '');Example-1Live Demo function removeTags(str) { if ((str===null) || (str==='')) return false; else str = str.toString(); ... Read More

Why Char[] array is more secure (store sensitive data) than String in Java?

Shriansh Kumar
Updated on 20-May-2025 19:16:27

5K+ Views

Both String class and Char[] array in Java are used to store textual data. However, Strings are immutable, which means you can't make changes to a String once defined, and the char[] array is not immutable. In the official documentation of Java Cryptography Architecture, it is clearly written that String objects are not suitable for storing sensitive data, such as passwords, SSN, etc. Use a char array instead, as it is more secure than String. This article will help you understand why char[] array is used to store sensitive data. Char Array is more secure than String Let's discuss why ... Read More

What is the contract between equals() and hashCode() methods in Java?

Shriansh Kumar
Updated on 21-May-2025 15:49:06

15K+ Views

Every Java object has two very important methods,  equals() and hashCode(), and these methods are designed to be overridden according to their specific general contract. Since the Object class is the parent class of every class, the default implementation of the equals() and hashCode() methods is already present in each class. However, we need to override these methods based on the requirement. Let's discuss the contract between equals() and hashCode() methods in Java. But before that, we need to understand these methods. The hashCode() Method The hashCode() method returns an integer value, which is referred to as the hash code value ... Read More

What is Pass By Reference and Pass By Value in PHP?

Alok Prasad
Updated on 29-Jun-2020 08:51:12

6K+ Views

In this article, we will learn about pass by value and pass by reference in PHP. Now, let’s understand these two concepts in detail.In PHP generally, we followed to pass the arguments to the function with passed by value approach. We are following this practice because if the value of the argument within the function is changed, it does not get changed outside of the function.In some cases we may need to modify function arguments, So to allow a function to modify its arguments, they must be passed by reference.Let's begin with passed by reference. As it is already mentioned we ... Read More

What is global namespace pollution in JavaScript?

vineeth.mariserla
Updated on 29-Jun-2020 08:55:29

1K+ Views

Global namespace pollutionPolluting Global namespace causes name collision. This name collision is very common in large projects where we may be using several javascript libraries. Let's discuss in detail what a name collision is.let's take a scenario in which 2 teams named A1 and A2 are working on a project. They both prepared their own javascript files that is TeamA1.js and TeamA2.js as shown below.TeamA1.jsTeamA1 has created a student function and has 2 parameters fname and lname(firstname & lastname).function student(fname, lname){    this.fname = fname;    this.lname = lname;    this.getFullName = function (){       return this.fname + " " ... Read More

What is the main difference between objects created using object literal and constructor function?

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

2K+ Views

Objects created using object literal are singletons, this means when a change is made to the object, it affects the object entire the script. Whereas if an object is created using constructor function and a change is made to it, that change won't affect the object throughout the script. Let's discuss them individually.1) Objects created using object literalSince these are singletons, a change to an object persists throughout the script. A change in one instance will affect all the instances of the object. In the following example if we observe, both the objects "student" and "newStudent" display the same name(Ravi) initially. But ... Read More

How to get a part of string after a specified character in JavaScript?

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

15K+ Views

To get a part of a string, string.substring() method is used in javascript. Using this method we can get any part of a string that is before or after a particular character.str.substring() This method slices a string from a given start index(including) to end index(excluding). If only one index is provided then the method slice the entire string from the start of the index. syntax-1Using this line of code we can get a part of a string after a particular character.string.substring(string.indexOf(character) + 1);syntax-2Using this line of code we can get a part of a string before a particular character.string.substring(0, string.indexOf(character));ExampleLive Demo ... Read More

What are the differences between tight coupling and loose coupling in Java?

Shriansh Kumar
Updated on 20-May-2025 18:33:46

16K+ Views

In object-oriented programming, coupling is a term used to describe the level of dependency each class or component of an application has on another. Tight coupling in Java means features of different classes and objects have high dependence on one another, whereas Loose coupling means components have very low or no dependency on one another. This article explains how tight coupling is different from loose coupling in Java. Tight Coupling in Java In tight coupling, if the implementation of one class changes, the dependent class might also need to be changed. It makes Java code less flexible and more difficult ... Read More

C++ Program to Create the Prufer Code for a Tree

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

820 Views

Prufer code uniquely identifies a tree which is given by user as a graph representation with labels from 1 to p. This tree consist p(value is given by user) labels of node. It has sequence of p – 2 values.AlgorithmBegin    Declare i, j, ver, edg, minimum, p to the integer datatype.    Print “Enter the number of vertexes: ”.    Enter the value of ver.    Initialize edg = ver-1.    Declare EDG[edg][2], DG[ver+1] to the integer datatype.       Initialize DG[ver+1] = {0}.    Print “This tree has (value of edg) edges for (value of ver) vertexes”. ... Read More

Print prime numbers in a given range using C++ STL

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

614 Views

It is the program to print prime numbers in a given range.AlgorithmsBegin    Declare a user define datatype stl.    Declare a vector number to the stl datatype.    Declare variable a to the stl datatype.    Declare vector Prime_Number to the Boolean datatype.       Prime_Number[0] = false.       Prime_Number[1] = false.    Declare b to the integer datatype.       Initialize b = sqrt(a).    for (stl pr=2; pr

Advertisements