Programming Articles - Page 2567 of 3366

How to hide e-mail address from an unauthorized user in JavaScript?

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

1K+ Views

Hiding an e-mail addressThe following steps are to be followed to hide our e-mail from unauthorized users. In every email address '@' symbol is common so try to remove it from the email address using split() method. In the following example after splitting the email(batman@gmail.com) we get the result as batman, gmail.com.Divide the result in to 2 parts(split1 and split2). Using substring() method remove some of string from split1 and join resulted part with split2 using '...@'. Return the joined part as the final output. In our example the resulted output is "bat...@gmail.com".ExampleLive Demo newEmail = function (email) { ... Read More

What are the differences between import and static import statements in Java?

Shriansh Kumar
Updated on 20-May-2025 18:22:18

5K+ Views

The import statement is used to bring certain classes and interfaces from other packages into our Java program, so we can access them without using their fully qualified names. We can use the short name instead. Java also supports static import statements, which were introduced in Java 5. It helps in accessing static members such as methods and constants. In this article, we are going to learn the difference between import and static import statements in Java. The import Statement in Java To access a class or method from another package, we need to either use the fully qualified ... Read More

How to access a function property as a method in JavaScript?

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

1K+ Views

Accessing a function as a method A javascript object is made up of properties. To access a property as a method, just define a function to a property and include other properties in that function.In the following example an object called "employee" is created with properties "fullName", "lastName" , "firstName" and "id". A function is defined under property "fullName" and properties such as "firstName" and "lastName" were included in it. So when the property "fullName" is called, the full name of the employee is going to display as shown in the output.Example-1Live Demo    var employee = {   ... Read More

What are the differences between compareTo() and compare() methods in Java?

Shriansh Kumar
Updated on 20-May-2025 19:28:58

9K+ Views

The compareTo() and compare() methods are both used to compare two objects. They return an int value after comparison, which tells if both objects are equal, if not, which is lesser, and which is greater. The primary difference between these two methods is that the compareTo() method is used when the Comparable interface is implemented, whereas the compare() method is used when the Comparator interface is implemented. Let's understand the use of compareTo() and compare() methods in Java, and then we will discuss how these two methods are different from each other. The compareTo() Method in Java The compareTo() method compares the ... Read More

How to add a number and a string in JavaScript?

vineeth.mariserla
Updated on 29-Jun-2020 09:44:54

11K+ Views

In javascript , we can add a number and a number but if we try to add a number and a string then, as addition is not possible, 'concatenation' takes place.In the following example, variables a, b, c and d are taken. For variable 'a', two numbers(5, 5) are added therefore it returned a  number(10). But in case of variable 'b' a string and a number ('5', 5) are added therefore, since a string is involved, we get the result as '55', which is a string. since strings are involved, Variables 'c' and 'd' also return a string as shown in the ... Read More

Can we write any statements between try, catch and finally blocks in Java?

raja
Updated on 06-Feb-2020 11:53:15

3K+ Views

No, we cannot write any statements in between try, catch and finally blocks and these blocks form one unit.  The functionality of try keyword is to identify an exception object and catch that exception object and transfer the control along with the identified exception object to the catch block by suspending the execution of the try block. The functionality of the catch block is to receive the exception class object that has been sent by the try and catch that exception class object and assigns that exception class object to the reference of the corresponding exception class defined in the catch block. The finally blocks are ... Read More

How to count a number of words in given string in JavaScript?

vineeth.mariserla
Updated on 29-Jun-2020 09:34:01

5K+ Views

Using regular expressions it is easy to count number of words in a given string in javascript. There are some steps to be followed to count number of wordsSteps to followWe know that a sentence or a phrase is made up of words that are separated with spaces in between and there are some instances in which the words are separated by 2 or more spaces. A developer must notice all these points while calculating no of words. Step-1Exclude the start and end spaces of a string. The following line of regex expression will remove the start and end spaces of ... Read More

What are the differences between recursion and iteration in Java?

Shriansh Kumar
Updated on 16-May-2025 19:03:05

3K+ Views

The Recursion and Iteration both repeatedly execute the set of instructions. Recursion is when a function calls itself repeatedly. The iteration is when a loop repeatedly executes until the controlling condition becomes false. The primary difference between recursion and iteration is that recursion repeats the statement in a function, whereas iteration is applied to the set of instructions that we want to execute repeatedly. In this article, we will compare recursion and iteration in Java and discuss the difference between them. Before we proceed, it is important to understand these two concepts with an example. Recursion in Java Recursion is ... Read More

What is the difference between for...in and for...of loops in JavaScript?

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

2K+ Views

Difference between for...in and for...of loopsBoth the loops iterate over something. The main difference between them is in what they iterate over.1) for...in loopThis loop iterates over enumerable properties of an object in an arbitrary order. It cares only about properties but not values.In the following example by using for...in loop the properties of the array are iterated. Since it is an array, Index is an important property so index of each and every element will be iterated and displayed in the output. In addition to indexes some inherited properties such as "inherProp2", "inherProp1" are also displayed.Example-1Live Demo   ... Read More

What are unreachable catch blocks in Java?

Shriansh Kumar
Updated on 20-May-2025 19:24:08

6K+ Views

A block of statements that the program control can never reach under any circumstances can be called an unreachable block. Java does not support unreachable blocks, such code will cause a compile-time error. Any code that is written but never executed is considered unnecessary by the Java compiler. In this article, we will discuss unreachable catch blocks in Java. But, before that, let's understand what is a catch-block in Java. The catch Block in Java The catch block is written just after the try block and cannot have any code between them. It is an exception handler and contains code ... Read More

Advertisements