With all these daily advancements in technology, it has become much easier to connect with the outside world: be it looking for an old friend or searching for a new job. Earlier people had to scan all the newspapers to check whether there are any openings in any company and then, would rush to the spot for the interviews. Today all we have to do is just update our resumes on different sites, and they take the pain to mail us back with all the suitable jobs according to our qualification.Talking about connecting to the corporate world with a pool ... Read More
Following is the regular expression to match hexadecimal number greater than 10 with even length −^(?=.{10,255}$)(?:0x)?\p{XDigit}{2}(?:\p{XDigit}{2})*$Where,^ − Matches the starting of the sentence.(?=.{10,255}$) − String ending with characters with 10 to 255.\p{XDigit}{2} − Two hexa-decimal characters.(?:\p{XDigit}{2})* − 0 or more sequences of double hexa-decimal characters.$ − Matches the end of the sentence.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class JavaExample51 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String nums[] = new String[5]; for(int i=0; i
IntUnaryOperator represents a functional interface that takes an int value and returns another int value. It is defined in java.util.function package and used as an assignment target for a lambda expression or method reference. It contains one abstract method: applyAsInt(), two default methods: compose(), andThen() and one static method: identity().Syntax@FunctionalInterface public interface IntUnaryOperatorExampleimport java.util.function.IntUnaryOperator; public class IntUnaryOperatorLambdaTest1 { public static void main(String[] args) { IntUnaryOperator getSquare = intValue -> { // lambda expression int result = intValue * intValue; System.out.println("Getting square: "+ result); return result; }; ... Read More
An event handling code that runs on a special thread called event dispatch thread(EDT). Most of the code that invokes swing methods also runs on this EDT thread. It is necessary because most of swing object methods do not thread-safe. SwingUtilities is a utility class and has one important static method, invokeLater(). This method can be used to perform a task asynchronously in the AWT event dispatcher thread.Syntaxpublic static void invokeLater(Runnable doRun)Exampleimport javax.swing.*; public class InvokeLAterLambdaTest { public static void main(String[] args) { SwingUtilities.invokeLater(() -> { // lambda expression code JFrame frame = ... Read More
To implement static method in Interface, the Java code is as follows −Example Live Demointerface my_interface{ static void static_fun(){ System.out.println("In the newly created static method"); } void method_override(String str); } public class Demo_interface implements my_interface{ public static void main(String[] args){ Demo_interface demo_inter = new Demo_interface(); my_interface.static_fun(); demo_inter.method_override("In the override method"); } @Override public void method_override(String str){ System.out.println(str); } }OutputIn the newly created static method In the override methodAn interface is defined, inside which a static function is defined. ... Read More
The Static Control Flow identify static members, executes static blocks, and then executes the static main method. Let us see an example −Example Live Demopublic class Demo{ static int a = 97; public static void main(String[] args){ print(); System.out.println("The main method has completed executing"); } static{ System.out.println(a); print(); System.out.println("We are inside the first static block"); } public static void print(){ System.out.println(b); } static{ System.out.println("We are inside the second static block"); } ... Read More
DoubleBinaryOperator is a functional interface defined in java.util.function package. It accepts two parameters of type double as input and produces another double value as a result. DoubleBinaryOperator interface can be used as an assignment target for a lambda expression or method reference and has only one abstract method applyAsDouble().Syntax@FunctionalInterface public interface DoubleBinaryOperator { double applyAsDouble(double left, double right); }Example-1import java.util.function.DoubleBinaryOperator; public class DoubleBinaryOperatorTest { public static void main(String args[]) { // using lambda expression DoubleBinaryOperator sum = (d1, d2) -> d1 + d2; DoubleBinaryOperator mul = (d1, d2) -> d1 * d2; DoubleBinaryOperator div = ... Read More
Following is the Java program for Standard Normal Distribution −Example Live Demoimport java.io.*; import java.util.*; public class Demo{ public static void main(String[] args){ double std_dev, val_1, val_3, val_2; val_1 = 68; val_2 = 102; val_3 = 26; std_dev = (val_1 - val_2) / val_3; System.out.println("The standard normal deviation is: " + std_dev); } }OutputThe standard normal deviation is: -1.3076923076923077A class named Demo contains the main function, where certain double values are defined, and the formula for standard deviation is applied ((val_1 - val_2) / val_3) on these values and the resultant output is displayed on the console.
Following is the Java program for Stooge sort −Example Live Demoimport java.io.*; public class Demo { static void stooge_sort(int my_arr[], int l_val, int h_val){ if (l_val >= h_val) return; if (my_arr[l_val] > my_arr[h_val]){ int temp = my_arr[l_val]; my_arr[l_val] = my_arr[h_val]; my_arr[h_val] = temp; } if (h_val-l_val+1 > 2){ int temp = (h_val-l_val+1) / 3; stooge_sort(my_arr, l_val, h_val-temp); stooge_sort(my_arr, l_val+temp, h_val); ... Read More
IntPredicate interface is a built-in functional interface defined in java.util.function package. This functional interface accepts one int-valued argument as input and produces a boolean value as an output. This interface is a specialization of the Predicate interface and used as an assignment target for a lambda expression or method reference. It provides only one abstract method, test ().Syntax@FunctionalInterface public interface IntPredicate { boolean test(int value); }Example for Lambda Expressionimport java.util.function.IntPredicate; public class IntPredicateLambdaTest { public static void main(String[] args) { IntPredicate intPredicate = (int input) -> { // lambda expression if(input == 100) { ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP