Fendadis John has Published 98 Articles

Use static Import for sqrt() and pow() methods in class Math in Java

Fendadis John

Fendadis John

Updated on 30-Jul-2019 22:30:24

Static import means that the fields and methods in a class can be used in the code without specifying their class if they are defined as public static.The Math class methods sqrt() and pow() in the package java.lang are static imported. A program that demonstrates this is given as follows:Example Live ... Read More

Obtain the hash code for a string in Java

Fendadis John

Fendadis John

Updated on 30-Jul-2019 22:30:24

The hashCode() method is used to obtain the hash code for a string. This method does not accept any parameters as it is a default method and it returns a hash code value.A program that demonstrates the hashCode() method in Java is given as follows:Example Live Demoimport java.io.*; public class Demo ... Read More

What is a Nested Class in Java?

Fendadis John

Fendadis John

Updated on 30-Jul-2019 22:30:24

A nested class is a class inside a class in Java. It is of two types i.e. Static nested class and Inner class. A static nested class is a nested class that is declared as static. An inner class is a non-static nested class.A program that demonstrates a static nested ... Read More

Change Thread Priority in Java

Fendadis John

Fendadis John

Updated on 30-Jul-2019 22:30:24

A thread can be created by implementing the Runnable interface and overriding the run() method. Then a Thread object can be created and the start() method called.The thread priority determines when the processor is provided to the thread as well as other resources. It can be changed using the method ... Read More

A greedy qualifier in Java Regular Expressions

Fendadis John

Fendadis John

Updated on 30-Jul-2019 22:30:24

A greedy qualifier repeats the specified token as many times as possible and then the engine backtracks and the greedy qualifier gives up matches to eventually find the required match.The regex "(\w+)(\d)(\w+)" is used to find the match in the string "EarthHas1Moon".A program that demonstrates this is given as follows:Example Live ... Read More

Use find() to find a subsequence in Java Regexp

Fendadis John

Fendadis John

Updated on 30-Jul-2019 22:30:24

The find() method finds the subsequence in an input sequence that matches the pattern required. This method is available in the Matcher class that is available in the java.util.regex packageA program that uses the find() method to find a subsequence in Java is given as follows:Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; ... Read More

How to find the subsequence in an input sequence that matches the pattern required in Java Regular Expressions?

Fendadis John

Fendadis John

Updated on 30-Jul-2019 22:30:24

The find() method finds the subsequence in an input sequence that matches the pattern required. This method is available in the Matcher class that is available in the java.util.regex package.A program that demonstrates the method Matcher.find() in Java regular expressions is given as follows:Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class ... Read More

Name validation using Java Regular Expressions

Fendadis John

Fendadis John

Updated on 30-Jul-2019 22:30:24

The name can be validated using the java.util.regex.Pattern.matches() method. This method matches the regular expression for the name and the given input name and returns true if they match and false otherwise.A program that demonstrates this is given as follows:Example Live Demopublic class Demo {    public static void main(String args[]) ... Read More

Sorting collection of String and StringBuffer in Java

Fendadis John

Fendadis John

Updated on 30-Jul-2019 22:30:23

In order to sort in Java as we know we can use either Comparable or Comparator interfaces in which we could also define our custom logic to sort.One of the approach to sort is to add the entity in TreeSet or TreeMap which would sort the entries as internally they ... Read More

Streams in Java

Fendadis John

Fendadis John

Updated on 30-Jul-2019 22:30:23

Stream is a new abstract layer introduced in Java 8. Using stream, you can process data in a declarative way similar to SQL statements. For example, consider the following SQL statement. SELECT max(salary), employee_id, employee_name FROM Employee The above SQL expression automatically returns the maximum salaried employee's details, ... Read More

Advertisements