Administrator

Lokesh Gupta

A fun-loving family man, passionate about computers and problem-solving, with over 15 years of experience in Java and related technologies. An avid Sci-Fi movie enthusiast and a fan of Christopher Nolan and Quentin Tarantino.

Website: https://howtodoinjava.com

Github: https://github.com/lokeshgupta1981/

Twitter: @HowToDoInJAVA

LinkedIn: https://www.linkedin.com/in/lokeshgupta1981/

My Articles:

TestNG – Test Groups with Examples

The ability to group the related tests is one of the most important features of TestNG. Users can group multiple tests into a named group. The user can execute a particular set of tests belonging to a group or multiple groups. The test grouping feature allows the tests to be …

TestNG @Parameters

TestNG parameterization feature allows user to pass parameters to tests as arguments. This is supported by using the testng @Parameters annotation.

TestNG Test Timeouts

Learn to configure TestNG tests to timeout after some pre-configured duration. Learn to configure timeout for test method, class and suite.

TestNG – Disable or Ignore Tests

When executing TestNG tests, there may be some scenarios where you may have to disable a particular test or a test suite from getting executed. For example, consider a scenario where a serious bug exists in a feature due to certain tests belonging to certain scenarios that cannot be executed. …

TestNG – Expected Exceptions

Learn to write TestNG exception-based tests using the expectedExceptions attribute and assert messages with expectedExceptionsMessageRegExp.

TestNG – Test LifeCycle

TestNG before and after annotations. @BeforeSuite, @AfterSuite, @BeforeTest, @AfterTest, @BeforeGroups, @AfterGroups, @BeforeClass, @AfterClass, @BeforeMethod and @AfterMethod.

TestNG Annotations

TestNG uses annotations to help developers to write the tests. Let us learn a few important testng annotations and their lifecycle.

Setting Up TestNG in Eclipse

Learn about TestNG features, installing the TestNG plugin into Eclipse and writing and executing TestNG tests through Eclipse IDE.

Java Regex – Credit Card Number Validation

In this java regular expression tutorial, we will learn to use regex to validate credit card numbers. We will learn about number format and validations of credit card numbers from multiple providers such as VISA, Mastercard, Amex and Diners etc. 1. Valid Credit Card Numbers Formats On an actual credit …

Regex for UK Postal Code Validation

Learn to use regular expressions for UK postcode validation in Java. You can modify the regex to suit it for any other format such as US postal codes.

Java Regex to Validate ISBN

Learn to use regular expressions to test whether a user has entered a valid International Standard Book Number (ISBN).

Regex to Validate SSN (Social Security Number)

In this Java regex tutorial, we will learn to use regular expressions to test whether a user has entered a valid Social Security number in your application or website form. 1. Valid SSN Pattern United States Social Security numbers are nine-digit numbers in the format AAA-GG-SSSS with the following rules. …

Regex to Limit the Number of Lines in Text

In this Java regex tutorial, we will learn to test whether several lines in input text are between some minimum and maximum limit, without regard for how many total characters appear in the string. The regex for matching the number of lines will depend on the exact characters or character …

Java Regex to Limit Number of Words

In this Java regex tutorial, we will learn to test whether the number of words in input text is within a certain minimum and maximum limit.

Regex for Alphanumeric Characters (+ Example)

To create a regular expression that allows only alphanumeric characters, we can use the regex pattern ^[a-zA-Z0-9]+$. This pattern ensures that the string consists solely of uppercase alphabets, lowercase alphabets, and digits. Alphanumeric characters are all alphabets and numbers i.e. letters A–Z, a–z, and digits 0–9. 1. Alphanumeric Regex Pattern …

Java date validation using RegEx

In this Java date validation using regex, we will learn to validate simple date formats such as mm/dd/yy, mm/dd/yyyy, dd/mm/yy and dd/mm/yyyy. Here we want to use a regex that simply checks whether the input is a valid date without trying to eliminate things such as February 31st. We might …

Regex to Validate International Phone Numbers

In this regex tutorial, we will learn to validate international phone numbers based on industry-standard notation specified by ITU-T E.123. The rules and conventions used to print international phone numbers vary significantly around the world, so it’s hard to provide meaningful validation for an international phone number unless you adopt …

Regex for North American Phone Number Validation

In this regex tutorial, we will learn to validate user-entered phone numbers for a specific format (in this example phone numbers are formatted in North American format) and if the numbers are correct then reformat them to a standard format for display. I have tested formats including 1234567890, 123-456-7890, 123.456.7890, …

Java Email Validation using Regex

Simple Java email validation example. Learn to validate email in Java using regular expressions. Five different regex patterns for email validation.

Regex: Matching Exact Word or Contains Word

Java regex word boundary example to match specific word or check if string contain word using Java regular expressions. java regex contain word example. java regex match specific word example.

Java Delete Temporary File

Learn how to delete a temporary file in Java. We will see examples to use File.deleteOnExit() and File.delete() methods.

Java Create Temp File or Directory

Learn to create a temp file and directory in Java using the legacy and NIO classes. Also, learn to delete temp files or temp directories on JVM shutdown.

Writing to Temporary File in Java

Learn to create a temporary file and write to it in Java. We will use the code sample used for creating a temporary file example.

Read File to Byte[] in Java

Learn reading data from files into a byte array in Java using NIO Files, FileInputStream, Commons IO FileUtils, and Guava ByteStreams classes.

Guide to Hibernate Criteria Queries

Learn about hibernate Criteria query interface, its basics, syntax, fetching data with multiple conditions including pagination and sorting.

Hibernate @Immutable Entities

Learn to use the Hibernate @Immutable annotation to create immutable entities, similar to immutable classes in Java, a rather well-known concept.

Guide to Lazy Loading in Hibernate

Hibernate fetches data from the database either in eager or lazy mode. Lazy loading refers to a strategy when data is loaded on demand.

Cascade Types in JPA and Hibernate

Learn JPA Cascade Types and how they are related to Hibernate Cascade Types. Learn how to control the orphan removal with an example.

Hibernate save(), update() and saveOrUpdate()

Learn the different methods for persisting and updating the entity states in the database using Hibernate Session APIs to use save(), update() and saveOrUpdate() methods under different usecases. Starting Hibernate 6.0, all save(), update() and saveOrUpdate() methods have been marked deprecated in favor of Jakarta persistence API provided persist() and …

Defining Hibernate Association Mappings

When we annotate the Java POJOs with JPA annotations and make them persistent entities, we can face situations where two entities can be related, and we must reference these entities from each other. This reference between the entities can be either uni-direction or in bi-direction. Creating these references is called …

Hibernate Entity LifeCycle

A hibernate entity, in context to persistence context or Session, can have 4 lifecycle states: transient, persistent, detached and removed.

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.