Arushi has Published 152 Articles

Minimum and Maximum Priority Threads in Java

Arushi

Arushi

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

3K+ Views

The thread priority determines when the processor is provided to the thread as well as other resources. It can be changed using the method setPriority() of class Thread.There are three static variables for thread priority in Java i.e. MIN_PRIORITY, MAX_PRIORITY and NORM_PRIORITY. The values of these variables are 1, 10 ... Read More

Is null a literal in Java?

Arushi

Arushi

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

691 Views

The null in Java is a literal of the null type. It cannot be cast to a primitive type such as int. float etc. but can be cast to a reference type. Also, null does not have the value 0 necessarily.A program that demonstrates null in Java is given as ... Read More

Use the ? quantifier in Java Regular Expressions

Arushi

Arushi

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

130 Views

In general, the ? quantifier represents 0 or 1 occurrences of the specified pattern. For example - X? means 0 or 1 occurrences of X.The regex "t.+?m" is used to find the match in the string "tom and tim are best friends" using the ? quantifier.A program that demonstrates this ... Read More

Validate Email address in Java

Arushi

Arushi

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

3K+ Views

The Email address can be validated using the java.util.regex.Pattern.matches() method. This method matches the regular expression for the E-mail and the given input Email and returns true if they match and false otherwise.A program that demonstrates this is given as follows:Example Live Demopublic class Demo {    static boolean isValid(String email) ... Read More

Split a string around a particular match in Java

Arushi

Arushi

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

265 Views

The specified string can be split around a particular match for a regex using the String.split() method. This method has a single parameter i.e. regex and it returns the string array obtained by splitting the input string around a particular match for the regex.A program that demonstrates splitting a string ... Read More

Class declaration with a method that has a parameter in Java

Arushi

Arushi

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

171 Views

A class declaration can contain a method that has a parameter in Java. A program that demonstrates this is given as follows:Example Live Democlass Message {    public void messagePrint(String msg) {       System.out.println("The message is: " + msg);    } } public class Demo { ... Read More

Demonstrating variable-length arguments in Java

Arushi

Arushi

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

4K+ Views

A method with variable length arguments(Varargs) in Java can have zero or multiple arguments. Variable length arguments are most useful when the number of arguments to be passed to the method is not known beforehand. They also reduce the code as overloaded methods are not required.A program that demonstrates this ... Read More

How to extend Interfaces in Java

Arushi

Arushi

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

25K+ Views

An interface contains variables and methods like a class but the methods in an interface are abstract by default unlike a class. An interface extends another interface like a class implements an interface in interface inheritance.A program that demonstrates extending interfaces in Java is given as follows:Example Live Demointerface A { ... Read More

A static initialization block in Java

Arushi

Arushi

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

8K+ Views

Instance variables are initialized using initialization blocks. However, the static initialization blocks can only initialize the static instance variables. These blocks are only executed once when the class is loaded. There can be multiple static initialization blocks in a class that is called in the order they appear in the ... Read More

Add elements at the end of a Vector in Java

Arushi

Arushi

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

311 Views

Elements can be added at the end of a Vector using the java.util.Vector.add() method. This method has a single parameter i.e. the element to be added. It returns true if the element is added to the Vector as required and false otherwise.A program that demonstrates this is given as follows:Example Live ... Read More

Advertisements