Pass Long Parameter to an Overloaded Method in Java

Rishi Raj
Updated on 30-Jun-2020 08:41:58

3K+ Views

Method overloading in a class contains multiple methods with the same name but the parameter list of the methods should not be the same. One of these methods can have a long parameter in their parameter list.A program that demonstrates this is given as follows −Example Live Democlass PrintValues {    public void print(int val) {       System.out.println("The int value is: " + val);    }    public void print(long val) {       System.out.println("The long value is: " + val);    } } public class Demo {    public static void main(String[] args) {       ... Read More

Method Overloading Based on the Order of Arguments in Java

Jai Janardhan
Updated on 30-Jun-2020 08:40:27

2K+ Views

In method overloading, the class can have multiple methods with the same name but the parameter list of the methods should not be the same. One way to make sure that the parameter list is different is to change the order of the arguments in the methods.A program that demonstrates this is given as follows −Example Live Democlass PrintValues {    public void print(int val1, char val2) {       System.out.println("The int value is: " + val1);       System.out.println("The char value is: " + val2);    }    public void print(char val1, int val2) {       ... Read More

Use Overloaded Methods to Print Array of Different Types in Java

Arushi
Updated on 30-Jun-2020 08:38:41

934 Views

In method overloading, the class can have multiple methods with the same name but the parameter list of the methods should not be the same.Overloaded methods can be used to print an array of different types in Java by making sure that the parameter list of the methods contains different types of arrays that can be printed by the method.A program that demonstrates this is given as follows −Example Live Demopublic class Demo {    public static void arrPrint(Integer[] arr) {       System.out.print("The Integer array is: ");       for (Integer i : arr)         ... Read More

Role of Matcher find(int) Method in Java Regular Expressions

Rishi Raj
Updated on 30-Jun-2020 08:37:18

279 Views

The Matcher.find(int) method finds the subsequence in an input sequence after the subsequence number that is specified as a parameter. This method is available in the Matcher class that is available in the java.util.regex package.The Matcher.find(int) method has one parameter i.e. the subsequence number after which the subsequence is obtained and it returns true is the required subsequence is obtained else it returns false.A program that demonstrates the method Matcher.find(int) in Java regular expressions is given as follows −Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo {    public static void main(String args[]) {       Pattern p = ... Read More

Class Declaration with One Method in Java

Vikyath Ram
Updated on 30-Jun-2020 08:34:50

375 Views

A class declaration can contain a single method. A program that demonstrates this is given as follows:Example Live Democlass Message {    public void messagePrint() {       System.out.println("This is a class with a single method");    } } public class Demo {    public static void main(String args[]) {       Message m = new Message();       m.messagePrint();    } }OutputThis is a class with a single methodNow let us understand the above program.The Message class is created with a single member function messagePrint(). A code snippet which demonstrates this is as follows −class Message { ... Read More

Sort, Sorted, np.argsort, and np.lexsort in Python

Pradeep Elance
Updated on 30-Jun-2020 08:34:19

705 Views

Ordering of data elements in a specific order is a frequently needed operation. To sort elements in an array, python uses the functions named sorted() and array.sort().sorted(array)This function returns a sorted array without modifying the original array.a = [9, 5, 3, 1, 12, 6] b = sorted([9, 5, 3, 1, 12, 6]) print "Sorted Array :", print (b) print "Original Array :", print (a)Running the above code gives us the following result −Sorted Array : [1, 3, 5, 6, 9, 12] Original Array : [9, 5, 3, 1, 12, 6]list.sort()The sort function returns a sorted array by doing in-place modification ... Read More

Use Pattern Class to Match in Java

Vikyath Ram
Updated on 30-Jun-2020 08:33:56

234 Views

The representation of the regular expressions are available in the java.util.regex.Pattern class. This class basically defines a pattern that is used by the regex engine.A program that demonstrates using the Pattern class to match in Java is given as follows −Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo {    public static void main(String args[]) {       Pattern p = Pattern.compile("p+");       Matcher m = p.matcher("apples and peaches are tasty");       System.out.println("The input string is: apples and peaches are tasty");       System.out.println("The Regex is: p+ ");       System.out.println();     ... Read More

Why Variables are Declared Final in Java

Rishi Raj
Updated on 30-Jun-2020 08:32:59

1K+ Views

A variable cannot be modified after it is declared as final. In other words, a final variable is constant. So, a final variable must be initialized and an error occurs if there is any attempt to change the value.A program that demonstrates a final variable in Java is given as follows −Example Live Demopublic class Demo {    public static void main(String[] args) {       final double PI = 3.141592653589793;       System.out.println("The value of pi is: " + PI);    } }OutputThe value of pi is: 3.141592653589793Now let us understand the above program.In the main() method in ... Read More

Role of Matcher matches() Method in Java Regular Expressions

Arushi
Updated on 30-Jun-2020 08:32:13

154 Views

The method java.time.Matcher.matches() matches the given region against the specified pattern. It returns true if the region sequence matches the pattern of the Matcher and false otherwise.A program that demonstrates the method Matcher.matches() in Java regular expressions is given as follows −Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo {    public static void main(String args[]) {       Pattern p = Pattern.compile("Apple");       String str1 = "apple";       String str2 = "Apple";       String str3 = "APPLE";       Matcher m1 = p.matcher(str1);       Matcher m2 = p.matcher(str2);   ... Read More

Get Current Thread in Java

Rishi Raj
Updated on 30-Jun-2020 08:30:48

16K+ Views

A thread can be created by implementing the Runnable interface and overriding the run() method.The current thread is the currently executing thread object in Java. The method currentThread() of the Thread class can be used to obtain the current thread. This method requires no parameters.A program that demonstrates this is given as follows −Example Live Demopublic class Demo extends Thread {    public void run() {       for (int i = 0; i < 5; i++) {          System.out.println("The Thread name is " + Thread.currentThread().getName());       }    }    public static void main(String[] ... Read More

Advertisements