- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 2617 Articles for Java
![Mahesh Parahar](https://www.tutorialspoint.com/assets/profiles/127878/profile/60_2277600-1655382864.jpg)
10K+ Views
Scanner and BufferReader both classes are used to read input from external system. Scanner is normally used when we know input is of type string or of primitive types and BufferReader is used to read text from character streams while buffering the characters for efficient reading of characters. Following are the important differences between Scanner class and a BufferReader class.Sr. No.KeyScanner ClassBufferReader Class1SynchronousScanner is not syncronous in nature and should be used only in single threaded case.BufferReader is syncronous in nature. During multithreading environment, BufferReader should be used.2Buffer MemoryScanner has little buffer of 1 KB char buffer.BufferReader has large buffer ... Read More
![Mahesh Parahar](https://www.tutorialspoint.com/assets/profiles/127878/profile/60_2277600-1655382864.jpg)
10K+ Views
In Java, abstraction is achieved using Abstract classes and interfaces. An abstract class contains abstract methods which a child class. Following are the important differences between abstract class and a concrete class. Sr. No. Key Abstract Class Concrete Class 1 Supported Methods Abstract class can have both an abstract as well as concrete methods. A concrete class can only have concrete methods. Even a single abstract method makes the class abstract. 2 Instantiation Abstract class can not be instantiated using new keyword. Concrete class can be instantiated using new keyword. 3 Abstract Method Abstract class may or may not have abstract methods. Concrete clas can not have an abstract method. 4 Final Abstract class can not be declared as ... Read More
![Mahesh Parahar](https://www.tutorialspoint.com/assets/profiles/127878/profile/60_2277600-1655382864.jpg)
5K+ Views
In Java, abstraction is achieved using Abstract classes and interfaces. Both contains abstract methods which a child class or implementing class has to implement. Following are the important differences between abstract class and an interface. Sr. No. Key Abstract Class Interface 1 Supported Methods Abstract class can have both an abstract as well as concrete methods. Interface can have only abstract methods. Java 8 onwards, it can have default as well as static methods. 2 Multiple Inheritance Multiple Inheritance is not supported. Interface supports Multiple Inheritance. 3 Supported Variables final, non-final, static and non-static variables supported. Only static and final variables are permitted. 4 Implementation Abstract class can implement an interface. Interface can not implement an interface, it can extend ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
3K+ Views
The following is the regular expression to match the date in the dd-MM-yyyy format.^(1[0-2]|0[1-9])/(3[01]|[12][0-9]|0[1-9])/[0-9]{4}$To match a date in a string in that format.Compile the above expression of the compile() method of the Pattern class.Get the Matcher object bypassing the required input string as a parameter to the matcher() method of the Pattern class.The matches() method of the Matcher class returns true if a match occurs else it returns false. Therefore, invoke this method to validate the data.Example 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class MatchingDate { public static void main(String[] args) { String date = "01/12/2019"; ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
174 Views
This class matches the upper case alphabetic characters.Example 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Posix_LowerExample { public static void main( String args[] ) { //Regular expression to match upper case letters String regex = "^\p{Upper}+$"; //Getting the input data Scanner sc = new Scanner(System.in); System.out.println("Enter 5 input strings: "); String input[] = new String[5]; for (int i=0; i
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
191 Views
This class matches the lower case alphabetic characters i.e. a to z.Example 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Posix_LowerExample { public static void main( String args[] ) { //Regular expression to match lower case letters String regex = "^\p{Lower}+$"; //Getting the input data Scanner sc = new Scanner(System.in); System.out.println("Enter 5 input strings: "); String input[] = new String[5]; for (int i=0; i
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
921 Views
The Posix character class \p{ASCII} matches the ASCII characters and the meta character ^ acts as negation.i.e. The following expression matches all the non-ASCII characters."[^\p{ASCII}]"The replaceAll() method of the String class accepts a regular expression and a replacement-string and, replaces the characters of the current string (matching the given pattern) with the specified replacement-string.Therefore, You can remove the matched characters by replacing them with the empty string “, using the replaceAll() method.Example 1import java.util.Scanner; public class Exp { public static void main( String args[] ) { Scanner sc = new Scanner(System.in); String regex = ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
199 Views
The compile method of the patter class accepts two parameters −A string value representing the regular expression.An integer value a field of the Pattern class.The filed LITERAL of the enables literal parsing of the pattern. i.e. all the regular expression metacharacters and escape sequences don’t have any special meaning they are treated as literal characters. Therefore, If you need to match the regular expression metacharacters as normal characters you need to pass this as a flag value to the compile() method along with the regular expression.Exampleimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
150 Views
The compile method of the patter class accepts two parameters −A string value representing the regular expression.An integer value a field of the Pattern class.This CASE_INSENSITIVE field of the Pattern class matches characters irrespective of case. Therefore, if you pass as flag value to the compile() method along with your regular expression, characters of both cases will be matched.Example 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main( String args[] ) { Scanner sc = new Scanner(System.in); System.out.println("Enter input data: "); String input = sc.nextLine(); ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
14K+ Views
You can match numbers in the given string using either of the following regular expressions −“\d+” Or, "([0-9]+)"Example 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class ExtractingDigits { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter sample text: "); String data = sc.nextLine(); //Regular expression to match digits in a string String regex = "\d+"; //Creating a pattern object Pattern pattern = Pattern.compile(regex); //Creating a Matcher object Matcher ... Read More