Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

 

and many more ....

 

 

Check where a class was loaded from

This is an example of how to check where a class was loaded from. To check where a class was loaded from we have created a class, CheckWhereAClassWasLoadedFrom. It has a method void getLocation() that gets the location of the class. The steps of the method are described below: It gets the runtime class of this Object using getClass() API ...

Read More »

Simple validation example

In this example we shall show you how to make a simple validation of a String, using a Matcher against a specified Pattern. To make a simple String validation one should perform the following steps: Create a new Pattern, by compiling to it a regular expression. The regular expression constructed here is the word “Java” followed by a space character ...

Read More »

Find duplication in strings example

With this example we are going to demonstrate how to find duplication in Strings. In order to check if there are duplications in a String we have created a Matcher against a specified Pattern and used the Matcher API in boolean hasDuplicateWord(String phrase) method. In short the steps of the method are: Compile a String regular expression to a Pattern, ...

Read More »

Determine if a string matches a pattern exactly

This is an example of how to determine if a String matches to a Pattern exactly. Using a Matcher to check if a String matches to a specified Pattern implies that you should: Compile a given String regular expression to a Pattern, using compile(string regex) API method of Pattern. The given regex in the example is the character “b”. Use ...

Read More »

Matcher.appendReplacement example – Part 2

In this example we shall show you how to use Matcher.appendReplacement(StringBuffer sb, String replacement) API method to append to a StringBuffer the result of a Matcher. To use a StringBuffer to append a Matcher’s result one should perform the following steps: Compile a given String regular expression to a Pattern, using compile(string regex) API method of Pattern. Use matcher(CharSequence input) ...

Read More »

Strip extra spaces in a string

With this example we are going to demonstrate how to strip extra spaces in a String. In short, to strip extra spaces in a String you should: Use a given String with spaces between words. Use replaceAll(String regex, String replacement) API method of String, with a given regular expression. The regular expression is constructed by the white character between the ...

Read More »

Simple positive Lookbehind

This is an example of a simple positive look behind. Positive look behind methods assert the existence of a pattern to the left of the position of a String. You can form positive look behinds by opening a noncapturing group with (?<=. Positive looking behind in a String implies that you should: Compile a given String regular expression to a ...

Read More »

Find occurances of a letter in a string

In this example we shall show you how to find occurances of a specific letter in a String. To find occurances of a letter in a String one should perform the following steps: Compile a given String regular expression to a Pattern, using compile(string regex) API method of Pattern. The given regex in the example is a word boundary followed ...

Read More »

Get all digits from a string

With this example we are going to demonstrate how to get all digits from a String, using a regular expression. In short, to get all digits from a String you should: Use a given String with letters and digits. Use replaceAll(String regex, String replacement) API method of String, with a given regular expression and a String to be used as ...

Read More »

Split a string by regular expression

This is an example of how to split a String using regular expression. Splitting a String with a regular expression implies that you should: Compile a given String regular expression to a Pattern, using compile(string regex) API method of Pattern. The given regular expression in the example is the String “ian”. Use split(CharSequence input) API method of Pattern to split ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Spring Interview QnA
  • Multithreading & Concurrency QnA
  • JPA Minibook
  • JVM Troubleshooting Guide
  • Advanced Java
  • Java Interview QnA
  • Java Design Patterns