Quantcast
Channel: Java Archives - Java Code Geeks
Browsing all 743 articles
Browse latest View live

Execute Scheduled Task Only Once in Spring Boot

Usually, we configure tasks to run periodically. However, there are situations where we may need to schedule a task to execute just once at a specified future time, such as for resource initialization...

View Article


An Introduction to Contract Testing in Java with Pact

In modern microservice architectures, communication between services is key. However, ensuring that services interact correctly can be challenging, especially when they evolve independently. This is...

View Article


Mocking an Enum Using Mockito

When writing unit tests in Java, there are scenarios where we need to mock certain classes or behaviors to isolate and test specific functionality. While mocking objects in Java is straightforward with...

View Article

Property-Based Testing in Java with jqwik: Practical Examples

Testing is a critical aspect of software development, and traditional unit testing often focuses on specific inputs and outputs. Property-based testing, however, takes a broader approach by verifying...

View Article

JUnit 5 vs. TestNG vs. Spock: Mastering Java Testing

Unit testing is an essential practice in software development, ensuring that individual components of your code work as expected. With several frameworks available in the Java ecosystem, choosing the...

View Article


Java Interface vs Annotation @interface

In Java, both interface and @interface are used to define a contract for classes, but they serve different purposes. Let us delve into understanding Java interface vs annotation. 1. Interface An...

View Article

Java File To Two Dimensional Array

Handling data files is a common task in many Java applications, especially when working with structured data like tables or matrices. Let us delve into understanding how to work with a Java file...

View Article

Mastering Mocking in Spock: Clean and Maintainable Tests

When it comes to testing in Java, Spock is a powerful and expressive framework that combines simplicity with an intuitive syntax. Among its many features, Spock’s approach to mocking and stubbing...

View Article


Java Implicit Classes & Instance Main

Java, one of the most widely used programming languages, has seen continuous evolution over the years. One of the lesser-known features of Java is the use of implicitly declared classes and instance...

View Article


How to Parse XML from a String in Java

When working with XML in Java, it’s common to parse XML from a file using classes like DocumentBuilder and DocumentBuilderFactory. However, there are scenarios where XML needs to be parsed directly...

View Article

Using Java’s ForkJoin Framework for Parallel Processing

Parallel processing is a critical tool for optimizing performance in modern applications, especially when handling large datasets or computationally intensive tasks. Java’s ForkJoin Framework,...

View Article

Java’s Modern Toolbox: Records, Sealed Classes, and Pattern Matching

Java has been a steadfast player in the programming world for decades. However, recent updates have shown that Java isn’t just resting on its laurels—it’s evolving to meet modern development needs....

View Article

Query JPA Single Table Inheritance

In Java Persistence API (JPA), inheritance mapping provides a way to map Java class hierarchies to database tables. Single Table Inheritance is one of the inheritance strategies where all entities in a...

View Article


Java float to int Conversion

In Java, converting a float to an int is a common operation that is often required when dealing with numeric data. Since float is a floating-point data type, it can hold decimal values, whereas int can...

View Article

Fuzz Testing in Java: A Beginner’s Guide to Security

In today’s digital landscape, software security is not just a priority—it’s a necessity. Applications face threats from every angle, and developers must ensure their systems can handle not only valid...

View Article


java.lang.classnotfoundexception: com.mysql.cj.jdbc.driver Resolved

The error java.lang.classnotfoundexception: com.mysql.cj.jdbc.driver occurs when your Java application cannot locate the MySQL JDBC driver class at runtime. This issue is common in projects involving...

View Article

Insert a Number Into a Sorted Array Example

1. Introduction Manipulating sorted arrays is a common requirement in Java applications that maintain ordered collections either for efficient retrieval or ranking. In this example, I will show two...

View Article


Enhancing Java Testing with PIT: A Guide to Mutation Testing

In software development, ensuring code quality is a critical component of creating robust, maintainable applications. Traditional testing approaches like unit and integration testing are essential, but...

View Article

Java Input Handling: Read Multiple Integers from One Line

Using the Scanner class is a common way to read user input in Java. However, if you are trying to read multiple integers from a single line of input, you might encounter issues like only retrieving the...

View Article

Spring Boot Test Mock @value

In Spring Boot, the @Value annotation is widely used to inject values from property files, environment variables, or other external sources into the application. Testing components that use @Value...

View Article
Browsing all 743 articles
Browse latest View live