
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7442 Articles for Java

857 Views
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

393 Views
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

1K+ Views
In Java, as we know, Collections are one of the most important concepts that make Java a powerful language in itself. It's the support of collections in Java that makes it support any type of data in a convenient and efficient way, along with possible CRUD operations over them. But on the same phase, when collections get exposed to a multi-threading its performance gets somewhat degraded because somewhere collections lack the support for a multi-threading environment. To overcome this limitation, Java introduces Concurrent Collections, which not only overcome the multi-threading environment limitation but also enhance Java to perform with multiple ... Read More

2K+ Views
The javafx.event package provides a framework for Java FX events. The Event class serves as the base class for JavaFX events and associated with each event is an event source, an event target, and an event type. An ActionEvent widely used when a button is pressed.In the below program, we can implement an ActionEvent for a button by using method reference.Exampleimport javafx.application.*; import javafx.beans.property.*; import javafx.event.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; import javafx.scene.effect.*; public class MethodReferenceJavaFXTest extends Application { private Label label; public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { ... Read More

446 Views
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

534 Views
This character class \p{javaLowerCase} matches lower case letters. This class matches the characters which returns true when passed as a parameter to the isLowerCase() method of the java.lang.Character class.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample { public static void main(String args[]) { //Reading String from user System.out.println("Enter a string"); Scanner sc = new Scanner(System.in); String input = sc.nextLine(); //Regular expression String regex = "[\p{javaLowerCase}]"; //Compiling the regular expression Pattern pattern = ... Read More

506 Views
This class matches white space characters. i.e. \t, , \x, 0B, \f, \r.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class SpaceCharacters { public static void main(String args[]) { //Reading String from user System.out.println("Enter a string"); Scanner sc = new Scanner(System.in); String input = sc.nextLine(); //Regular expression String regex = "[\p{Space}]"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex); //Retrieving the matcher object Matcher matcher = pattern.matcher(input); ... Read More

396 Views
This class matches hexa-decimal characters i.e. [0-9a-fA-F].Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class SpaceCharacters { public static void main(String args[]) { //Reading String from user System.out.println("Enter a string"); Scanner sc = new Scanner(System.in); String input = sc.nextLine(); //Regular expression String regex = "[\p{XDigit}]"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex); //Retrieving the matcher object Matcher matcher = pattern.matcher(input); int count = 0; ... Read More

827 Views
If you want to specify the number of occurrences while constructing a regular expression you can use quantifiers. Java supports three types of quantifiers namely: greedy quantifiers, reluctant quantifiers and possessive quantifiers.Greedy quantifiers − Greedy quantifiers are the default quantifiers. A greedy quantifier matches as much as possible from the input string (longest match possible) if match not occurred it leaves the last character and matches again.Exampleimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter input text: "); ... Read More

1K+ Views
This class matches all the printable characters.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class PrintableCharacters { public static void main(String args[]) { //Reading String from user System.out.println("Enter a string"); Scanner sc = new Scanner(System.in); String input = sc.nextLine(); //Regular expression String regex = "[\p{Print}]"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex); //Retrieving the matcher object Matcher matcher = pattern.matcher(input); int count = 0; ... Read More