Merge branch 'master' into readme-26
This commit is contained in:
commit
8435d122dc
@ -1,3 +1,3 @@
|
||||
### Relevant articles
|
||||
|
||||
- [Guide to Akka Streams](http://www.baeldung.com/akka-streams)
|
||||
- [Guide to Akka Streams](https://www.baeldung.com/akka-streams)
|
||||
|
@ -1,6 +1,6 @@
|
||||
## Relevant articles:
|
||||
|
||||
- [Introduction to Jenetics Library](http://www.baeldung.com/jenetics)
|
||||
- [Ant Colony Optimization](http://www.baeldung.com/java-ant-colony-optimization)
|
||||
- [Introduction to Jenetics Library](https://www.baeldung.com/jenetics)
|
||||
- [Ant Colony Optimization](https://www.baeldung.com/java-ant-colony-optimization)
|
||||
- [Design a Genetic Algorithm in Java](https://www.baeldung.com/java-genetic-algorithm)
|
||||
- [The Traveling Salesman Problem in Java](https://www.baeldung.com/java-simulated-annealing-for-traveling-salesman)
|
||||
|
@ -1,10 +1,10 @@
|
||||
## Relevant articles:
|
||||
|
||||
- [Dijkstra Algorithm in Java](https://www.baeldung.com/java-dijkstra)
|
||||
- [Dijkstra Shortest Path Algorithm in Java](https://www.baeldung.com/java-dijkstra)
|
||||
- [Introduction to Cobertura](https://www.baeldung.com/cobertura)
|
||||
- [Test a Linked List for Cyclicity](https://www.baeldung.com/java-linked-list-cyclicity)
|
||||
- [Introduction to JGraphT](https://www.baeldung.com/jgrapht)
|
||||
- [A Maze Solver in Java](https://www.baeldung.com/java-solve-maze)
|
||||
- [Create a Sudoku Solver in Java](https://www.baeldung.com/java-sudoku)
|
||||
- [Displaying Money Amounts in Words](https://www.baeldung.com/java-money-into-words)
|
||||
- [A Collaborative Filtering Recommendation System in Java](https://www.baeldung.com/java-collaborative-filtering-recommendations)
|
||||
- [A Collaborative Filtering Recommendation System in Java](https://www.baeldung.com/java-collaborative-filtering-recommendations)
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
- [Java Two Pointer Technique](https://www.baeldung.com/java-two-pointer-technique)
|
||||
- [Implementing Simple State Machines with Java Enums](https://www.baeldung.com/java-enum-simple-state-machine)
|
||||
- [Converting Between Roman and Arabic Numerals in Java](http://www.baeldung.com/java-convert-roman-arabic)
|
||||
- [Practical Java Examples of the Big O Notation](http://www.baeldung.com/java-algorithm-complexity)
|
||||
- [Converting Between Roman and Arabic Numerals in Java](https://www.baeldung.com/java-convert-roman-arabic)
|
||||
- [Practical Java Examples of the Big O Notation](https://www.baeldung.com/java-algorithm-complexity)
|
||||
- [Checking If a List Is Sorted in Java](https://www.baeldung.com/java-check-if-list-sorted)
|
||||
- [Checking if a Java Graph has a Cycle](https://www.baeldung.com/java-graph-has-a-cycle)
|
||||
- [A Guide to the Folding Technique in Java](https://www.baeldung.com/folding-hashing-technique)
|
||||
- [Creating a Triangle with for Loops in Java](https://www.baeldung.com/java-print-triangle)
|
||||
- [Efficient Word Frequency Calculator in Java](https://www.baeldung.com/java-word-frequency)
|
||||
- [Efficient Word Frequency Calculator in Java](https://www.baeldung.com/java-word-frequency)
|
||||
|
@ -1,9 +1,10 @@
|
||||
## Relevant articles:
|
||||
|
||||
- [Bubble Sort in Java](http://www.baeldung.com/java-bubble-sort)
|
||||
- [Bubble Sort in Java](https://www.baeldung.com/java-bubble-sort)
|
||||
- [Merge Sort in Java](https://www.baeldung.com/java-merge-sort)
|
||||
- [Quicksort Algorithm Implementation in Java](https://www.baeldung.com/java-quicksort)
|
||||
- [Insertion Sort in Java](https://www.baeldung.com/java-insertion-sort)
|
||||
- [Heap Sort in Java](https://www.baeldung.com/java-heap-sort)
|
||||
- [Shell Sort in Java](https://www.baeldung.com/java-shell-sort)
|
||||
- [Counting Sort in Java](https://www.baeldung.com/java-counting-sort)
|
||||
- [Sorting Strings by Contained Numbers in Java](https://www.baeldung.com/java-sort-strings-contained-numbers)
|
||||
|
@ -1,3 +1,3 @@
|
||||
## Relevant articles:
|
||||
|
||||
[Introduction to Animal Sniffer Maven Plugin](http://www.baeldung.com/maven-animal-sniffer)
|
||||
[Introduction to Animal Sniffer Maven Plugin](https://www.baeldung.com/maven-animal-sniffer)
|
||||
|
@ -1,2 +1,2 @@
|
||||
### Relevant Articles:
|
||||
- [Java Annotation Processing and Creating a Builder](http://www.baeldung.com/java-annotation-processing-builder)
|
||||
- [Java Annotation Processing and Creating a Builder](https://www.baeldung.com/java-annotation-processing-builder)
|
||||
|
@ -1,3 +1,3 @@
|
||||
### Relevant Articles:
|
||||
|
||||
- [Java with ANTLR](http://www.baeldung.com/java-antlr)
|
||||
- [Java with ANTLR](https://www.baeldung.com/java-antlr)
|
||||
|
@ -1,2 +1,2 @@
|
||||
### Relevant Articles:
|
||||
- [Guide to Apache Avro](http://www.baeldung.com/java-apache-avro)
|
||||
- [Guide to Apache Avro](https://www.baeldung.com/java-apache-avro)
|
||||
|
@ -1,2 +1,2 @@
|
||||
### Relevant Articles:
|
||||
- [Intro to Apache BVal](http://www.baeldung.com/apache-bval)
|
||||
- [Intro to Apache BVal](https://www.baeldung.com/apache-bval)
|
||||
|
@ -1,3 +1,3 @@
|
||||
### Relevant Articles:
|
||||
|
||||
- [Introduction to Apache Curator](http://www.baeldung.com/apache-curator)
|
||||
- [Introduction to Apache Curator](https://www.baeldung.com/apache-curator)
|
||||
|
@ -1,6 +1,6 @@
|
||||
## Relevant Articles:
|
||||
- [Introduction to Apache CXF Aegis Data Binding](http://www.baeldung.com/aegis-data-binding-in-apache-cxf)
|
||||
- [Apache CXF Support for RESTful Web Services](http://www.baeldung.com/apache-cxf-rest-api)
|
||||
- [A Guide to Apache CXF with Spring](http://www.baeldung.com/apache-cxf-with-spring)
|
||||
- [Introduction to Apache CXF](http://www.baeldung.com/introduction-to-apache-cxf)
|
||||
- [Introduction to Apache CXF Aegis Data Binding](https://www.baeldung.com/aegis-data-binding-in-apache-cxf)
|
||||
- [Apache CXF Support for RESTful Web Services](https://www.baeldung.com/apache-cxf-rest-api)
|
||||
- [A Guide to Apache CXF with Spring](https://www.baeldung.com/apache-cxf-with-spring)
|
||||
- [Introduction to Apache CXF](https://www.baeldung.com/introduction-to-apache-cxf)
|
||||
- [Server-Sent Events (SSE) In JAX-RS](https://www.baeldung.com/java-ee-jax-rs-sse)
|
||||
|
@ -1,3 +1,3 @@
|
||||
### Relevant Articles:
|
||||
================================
|
||||
- [Building a Microservice with Apache Meecrowave](http://www.baeldung.com/apache-meecrowave)
|
||||
- [Building a Microservice with Apache Meecrowave](https://www.baeldung.com/apache-meecrowave)
|
||||
|
@ -1,3 +1,4 @@
|
||||
## Relevant articles:
|
||||
|
||||
- [OData Protocol Guide](https://www.baeldung.com/odata)
|
||||
- [Intro to OData with Olingo](https://www.baeldung.com/olingo)
|
||||
|
@ -1,3 +1,3 @@
|
||||
### Relevant Articles
|
||||
|
||||
- [Intro to Apache OpenNLP](http://www.baeldung.com/apache-open-nlp)
|
||||
- [Intro to Apache OpenNLP](https://www.baeldung.com/apache-open-nlp)
|
||||
|
@ -1,4 +1,4 @@
|
||||
### Relevant Articles:
|
||||
- [Microsoft Word Processing in Java with Apache POI](http://www.baeldung.com/java-microsoft-word-with-apache-poi)
|
||||
- [Working with Microsoft Excel in Java](http://www.baeldung.com/java-microsoft-excel)
|
||||
- [Creating a MS PowerPoint Presentation in Java](http://www.baeldung.com/apache-poi-slideshow)
|
||||
- [Microsoft Word Processing in Java with Apache POI](https://www.baeldung.com/java-microsoft-word-with-apache-poi)
|
||||
- [Working with Microsoft Excel in Java](https://www.baeldung.com/java-microsoft-excel)
|
||||
- [Creating a MS PowerPoint Presentation in Java](https://www.baeldung.com/apache-poi-slideshow)
|
||||
|
@ -1,2 +1,2 @@
|
||||
### Relevant articles
|
||||
- [Introduction to Apache Shiro](http://www.baeldung.com/apache-shiro)
|
||||
- [Introduction to Apache Shiro](https://www.baeldung.com/apache-shiro)
|
||||
|
@ -1,4 +1,4 @@
|
||||
## Apache Solrj Tutorials Project
|
||||
|
||||
### Relevant Articles
|
||||
- [Guide to Solr in Java with Apache Solrj](http://www.baeldung.com/apache-solrj)
|
||||
- [Guide to Solr in Java with Apache Solrj](https://www.baeldung.com/apache-solrj)
|
||||
|
@ -1,4 +1,4 @@
|
||||
### Relevant articles
|
||||
|
||||
- [Introduction to Apache Spark](http://www.baeldung.com/apache-spark)
|
||||
- [Introduction to Apache Spark](https://www.baeldung.com/apache-spark)
|
||||
- [Building a Data Pipeline with Kafka, Spark Streaming and Cassandra](https://www.baeldung.com/kafka-spark-data-pipeline)
|
||||
|
@ -1,3 +1,3 @@
|
||||
## Relevant articles:
|
||||
|
||||
- [Working with Apache Thrift](http://www.baeldung.com/apache-thrift)
|
||||
- [Working with Apache Thrift](https://www.baeldung.com/apache-thrift)
|
||||
|
@ -4,4 +4,4 @@ This module contains articles about Apache Tika
|
||||
|
||||
### Relevant articles:
|
||||
|
||||
- [Content Analysis with Apache Tika](http://www.baeldung.com/apache-tika)
|
||||
- [Content Analysis with Apache Tika](https://www.baeldung.com/apache-tika)
|
||||
|
@ -4,4 +4,4 @@ This module contains articles about Apache Velocity
|
||||
|
||||
### Relevant articles:
|
||||
|
||||
- [Introduction to Apache Velocity](http://www.baeldung.com/apache-velocity)
|
||||
- [Introduction to Apache Velocity](https://www.baeldung.com/apache-velocity)
|
||||
|
@ -4,4 +4,4 @@ This module contains articles about Apache Zookeeper
|
||||
|
||||
### Relevant articles:
|
||||
|
||||
- [Getting Started with Java and Zookeeper](http://www.baeldung.com/java-zookeeper)
|
||||
- [Getting Started with Java and Zookeeper](https://www.baeldung.com/java-zookeeper)
|
||||
|
@ -4,5 +4,5 @@ This module contains articles about Asciidoctor
|
||||
|
||||
### Relevant articles:
|
||||
|
||||
- [Generating a Book with Asciidoctor](http://www.baeldung.com/asciidoctor-book)
|
||||
- [Introduction to Asciidoctor in Java](http://www.baeldung.com/asciidoctor)
|
||||
- [Generating a Book with Asciidoctor](https://www.baeldung.com/asciidoctor-book)
|
||||
- [Introduction to Asciidoctor in Java](https://www.baeldung.com/asciidoctor)
|
||||
|
@ -4,4 +4,4 @@ This module contains articles about ASM
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [A Guide to Java Bytecode Manipulation with ASM](http://www.baeldung.com/java-asm)
|
||||
- [A Guide to Java Bytecode Manipulation with ASM](https://www.baeldung.com/java-asm)
|
||||
|
@ -4,4 +4,4 @@ This module contains articles about Atomix
|
||||
|
||||
### Relevant articles:
|
||||
|
||||
- [Introduction to Atomix](http://www.baeldung.com/atomix)
|
||||
- [Introduction to Atomix](https://www.baeldung.com/atomix)
|
||||
|
@ -3,7 +3,6 @@
|
||||
This module contains articles about automatic code generation
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Introduction to AutoValue](http://www.baeldung.com/introduction-to-autovalue)
|
||||
- [Introduction to AutoFactory](http://www.baeldung.com/autofactory)
|
||||
- [Introduction to AutoValue](https://www.baeldung.com/introduction-to-autovalue)
|
||||
- [Introduction to AutoFactory](https://www.baeldung.com/autofactory)
|
||||
- [Google AutoService](https://www.baeldung.com/google-autoservice)
|
||||
|
@ -3,5 +3,5 @@
|
||||
This module contains articles about AWS Lambda
|
||||
|
||||
### Relevant Articles:
|
||||
- [Using AWS Lambda with API Gateway](http://www.baeldung.com/aws-lambda-api-gateway)
|
||||
- [Introduction to AWS Serverless Application Model](http://www.baeldung.com/aws-serverless)
|
||||
- [Using AWS Lambda with API Gateway](https://www.baeldung.com/aws-lambda-api-gateway)
|
||||
- [Introduction to AWS Serverless Application Model](https://www.baeldung.com/aws-serverless)
|
||||
|
@ -4,12 +4,12 @@ This module contains articles about AWS
|
||||
|
||||
### Relevant articles
|
||||
|
||||
- [AWS Lambda Using DynamoDB With Java](http://www.baeldung.com/aws-lambda-dynamodb-java)
|
||||
- [AWS S3 with Java](http://www.baeldung.com/aws-s3-java)
|
||||
- [AWS Lambda With Java](http://www.baeldung.com/java-aws-lambda)
|
||||
- [Managing EC2 Instances in Java](http://www.baeldung.com/ec2-java)
|
||||
- [Multipart Uploads in Amazon S3 with Java](http://www.baeldung.com/aws-s3-multipart-upload)
|
||||
- [Integration Testing with a Local DynamoDB Instance](http://www.baeldung.com/dynamodb-local-integration-tests)
|
||||
- [Using the JetS3t Java Client With Amazon S3](http://www.baeldung.com/jets3t-amazon-s3)
|
||||
- [Managing Amazon SQS Queues in Java](http://www.baeldung.com/aws-queues-java)
|
||||
- [AWS Lambda Using DynamoDB With Java](https://www.baeldung.com/aws-lambda-dynamodb-java)
|
||||
- [AWS S3 with Java](https://www.baeldung.com/aws-s3-java)
|
||||
- [AWS Lambda With Java](https://www.baeldung.com/java-aws-lambda)
|
||||
- [Managing EC2 Instances in Java](https://www.baeldung.com/ec2-java)
|
||||
- [Multipart Uploads in Amazon S3 with Java](https://www.baeldung.com/aws-s3-multipart-upload)
|
||||
- [Integration Testing with a Local DynamoDB Instance](https://www.baeldung.com/dynamodb-local-integration-tests)
|
||||
- [Using the JetS3t Java Client With Amazon S3](https://www.baeldung.com/jets3t-amazon-s3)
|
||||
- [Managing Amazon SQS Queues in Java](https://www.baeldung.com/aws-queues-java)
|
||||
- [Guide to AWS Aurora RDS with Java](https://www.baeldung.com/aws-aurora-rds-java)
|
||||
|
@ -4,4 +4,4 @@ This module contains articles about Axon
|
||||
|
||||
### Relevant articles
|
||||
|
||||
- [A Guide to the Axon Framework](http://www.baeldung.com/axon-cqrs-event-sourcing)
|
||||
- [A Guide to the Axon Framework](https://www.baeldung.com/axon-cqrs-event-sourcing)
|
||||
|
@ -1,4 +1,4 @@
|
||||
### Relevant Articles:
|
||||
|
||||
- [Deploy a Spring Boot App to Azure](http://www.baeldung.com/spring-boot-azure)
|
||||
- [Deploy a Spring Boot App to Azure](https://www.baeldung.com/spring-boot-azure)
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
### Relevant Articles:
|
||||
|
||||
- [Blade – A Complete Guidebook](http://www.baeldung.com/blade)
|
||||
- [Blade – A Complete Guidebook](https://www.baeldung.com/blade)
|
||||
|
||||
Run Integration Tests with `mvn integration-test`
|
||||
|
@ -1,2 +1,2 @@
|
||||
### Relevant Articles:
|
||||
- [Introduction to Bootique](http://www.baeldung.com/bootique)
|
||||
- [Introduction to Bootique](https://www.baeldung.com/bootique)
|
||||
|
@ -1,5 +1,5 @@
|
||||
### Relevant Articles:
|
||||
- [CDI Interceptor vs Spring AspectJ](http://www.baeldung.com/cdi-interceptor-vs-spring-aspectj)
|
||||
- [An Introduction to CDI (Contexts and Dependency Injection) in Java](http://www.baeldung.com/java-ee-cdi)
|
||||
- [CDI Interceptor vs Spring AspectJ](https://www.baeldung.com/cdi-interceptor-vs-spring-aspectj)
|
||||
- [An Introduction to CDI (Contexts and Dependency Injection) in Java](https://www.baeldung.com/java-ee-cdi)
|
||||
- [Introduction to the Event Notification Model in CDI 2.0](https://www.baeldung.com/cdi-event-notification)
|
||||
|
||||
|
@ -1,15 +1,16 @@
|
||||
package com.baeldung.cdi.cdi2observers.application;
|
||||
|
||||
import com.baeldung.cdi.cdi2observers.events.ExampleEvent;
|
||||
import javax.enterprise.inject.se.SeContainer;
|
||||
import javax.enterprise.inject.se.SeContainerInitializer;
|
||||
|
||||
public class BootstrappingApplication {
|
||||
|
||||
public static void main(String... args) {
|
||||
SeContainerInitializer containerInitializer = SeContainerInitializer.newInstance();
|
||||
try (SeContainer container = containerInitializer.initialize()) {
|
||||
container.getBeanManager().fireEvent(new ExampleEvent("Welcome to Baeldung!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.baeldung.cdi2observers.application;
|
||||
|
||||
import com.baeldung.cdi2observers.events.ExampleEvent;
|
||||
|
||||
import javax.enterprise.inject.se.SeContainer;
|
||||
import javax.enterprise.inject.se.SeContainerInitializer;
|
||||
|
||||
public class BootstrappingApplication {
|
||||
|
||||
public static void main(String... args) {
|
||||
SeContainerInitializer containerInitializer = SeContainerInitializer.newInstance();
|
||||
try (SeContainer container = containerInitializer.initialize()) {
|
||||
container.getBeanManager().fireEvent(new ExampleEvent("Welcome to Baeldung!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
package com.baeldung.cdi.cdi2observers.events;
|
||||
|
||||
public class ExampleEvent {
|
||||
|
||||
private final String eventMessage;
|
||||
|
||||
public ExampleEvent(String eventMessage) {
|
||||
this.eventMessage = eventMessage;
|
||||
}
|
||||
|
||||
public String getEventMessage() {
|
||||
return eventMessage;
|
||||
}
|
||||
}
|
||||
package com.baeldung.cdi2observers.events;
|
||||
|
||||
public class ExampleEvent {
|
||||
|
||||
private final String eventMessage;
|
||||
|
||||
public ExampleEvent(String eventMessage) {
|
||||
this.eventMessage = eventMessage;
|
||||
}
|
||||
|
||||
public String getEventMessage() {
|
||||
return eventMessage;
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
package com.baeldung.cdi.cdi2observers.events;
|
||||
|
||||
import javax.enterprise.event.Event;
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class ExampleEventSource {
|
||||
|
||||
@Inject
|
||||
Event<ExampleEvent> exampleEvent;
|
||||
|
||||
public void fireEvent() {
|
||||
exampleEvent.fireAsync(new ExampleEvent("Welcome to Baeldung!"));
|
||||
}
|
||||
}
|
||||
package com.baeldung.cdi2observers.events;
|
||||
|
||||
import javax.enterprise.event.Event;
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class ExampleEventSource {
|
||||
|
||||
@Inject
|
||||
Event<ExampleEvent> exampleEvent;
|
||||
|
||||
public void fireEvent() {
|
||||
exampleEvent.fireAsync(new ExampleEvent("Welcome to Baeldung!"));
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
package com.baeldung.cdi.cdi2observers.observers;
|
||||
|
||||
import com.baeldung.cdi.cdi2observers.events.ExampleEvent;
|
||||
import javax.annotation.Priority;
|
||||
import javax.enterprise.event.Observes;
|
||||
|
||||
public class AnotherExampleEventObserver {
|
||||
|
||||
public String onEvent(@Observes @Priority(2) ExampleEvent event) {
|
||||
return event.getEventMessage();
|
||||
}
|
||||
}
|
||||
package com.baeldung.cdi2observers.observers;
|
||||
|
||||
import com.baeldung.cdi2observers.events.ExampleEvent;
|
||||
|
||||
import javax.annotation.Priority;
|
||||
import javax.enterprise.event.Observes;
|
||||
|
||||
public class AnotherExampleEventObserver {
|
||||
|
||||
public String onEvent(@Observes @Priority(2) ExampleEvent event) {
|
||||
return event.getEventMessage();
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package com.baeldung.cdi.cdi2observers.observers;
|
||||
|
||||
import com.baeldung.cdi.cdi2observers.events.ExampleEvent;
|
||||
import com.baeldung.cdi.cdi2observers.services.TextService;
|
||||
import javax.annotation.Priority;
|
||||
import javax.enterprise.event.Observes;
|
||||
|
||||
public class ExampleEventObserver {
|
||||
|
||||
public String onEvent(@Observes @Priority(1) ExampleEvent event, TextService textService) {
|
||||
return textService.parseText(event.getEventMessage());
|
||||
}
|
||||
}
|
||||
package com.baeldung.cdi2observers.observers;
|
||||
|
||||
import com.baeldung.cdi2observers.events.ExampleEvent;
|
||||
import com.baeldung.cdi2observers.services.TextService;
|
||||
import javax.annotation.Priority;
|
||||
import javax.enterprise.event.Observes;
|
||||
|
||||
public class ExampleEventObserver {
|
||||
|
||||
public String onEvent(@Observes @Priority(1) ExampleEvent event, TextService textService) {
|
||||
return textService.parseText(event.getEventMessage());
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.baeldung.cdi.cdi2observers.services;
|
||||
|
||||
public class TextService {
|
||||
|
||||
public String parseText(String text) {
|
||||
return text.toUpperCase();
|
||||
}
|
||||
}
|
||||
package com.baeldung.cdi2observers.services;
|
||||
|
||||
public class TextService {
|
||||
|
||||
public String parseText(String text) {
|
||||
return text.toUpperCase();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
<beans xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
|
||||
http://java.sun.com/xml/ns/javaee/beans_1_2.xsd">
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
|
||||
bean-discovery-mode="all">
|
||||
<interceptors>
|
||||
<class>com.baeldung.interceptor.AuditedInterceptor</class>
|
||||
</interceptors>
|
||||
|
@ -1,14 +1,15 @@
|
||||
package com.baeldung.cdi.cdi2observers.tests;
|
||||
|
||||
import com.baeldung.cdi.cdi2observers.services.TextService;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TextServiceUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenTextServiceInstance_whenCalledparseText_thenCorrect() {
|
||||
TextService textService = new TextService();
|
||||
assertThat(textService.parseText("Baeldung")).isEqualTo("BAELDUNG");
|
||||
}
|
||||
}
|
||||
package com.baeldung.test.cdi2observers.tests;
|
||||
|
||||
import com.baeldung.cdi2observers.services.TextService;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TextServiceUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenTextServiceInstance_whenCalledparseText_thenCorrect() {
|
||||
TextService textService = new TextService();
|
||||
assertThat(textService.parseText("Baeldung")).isEqualTo("BAELDUNG");
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TimeLoggerFactoryUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenTimeLoggerFactory_whenCalledgetTimeLogger_thenOneAssertion() {
|
||||
TimeLoggerFactory timeLoggerFactory = new TimeLoggerFactory();
|
||||
|
@ -1,3 +1,3 @@
|
||||
### Relevant articles
|
||||
|
||||
- [The Checker Framework – Pluggable Type Systems for Java](http://www.baeldung.com/checker-framework)
|
||||
- [The Checker Framework – Pluggable Type Systems for Java](https://www.baeldung.com/checker-framework)
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
## Relevant articles:
|
||||
|
||||
- [String Matching in Groovy](http://www.baeldung.com/)
|
||||
- [Template Engines in Groovy](https://www.baeldung.com/groovy-template-engines)
|
||||
- [Groovy def Keyword](https://www.baeldung.com/groovy-def-keyword)
|
||||
- [Pattern Matching in Strings in Groovy](https://www.baeldung.com/groovy-pattern-matching)
|
||||
- [Working with XML in Groovy](https://www.baeldung.com/groovy-xml)
|
||||
- [Integrating Groovy into Java Applications](https://www.baeldung.com/groovy-java-applications)
|
||||
- [Concatenate Strings with Groovy](https://www.baeldung.com/groovy-concatenate-strings)
|
||||
- [Metaprogramming in Groovy](https://www.baeldung.com/groovy-metaprogramming)
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
## Relevant articles:
|
||||
|
||||
- [JDBC with Groovy](http://www.baeldung.com/jdbc-groovy)
|
||||
- [Working with JSON in Groovy](http://www.baeldung.com/groovy-json)
|
||||
- [JDBC with Groovy](https://www.baeldung.com/jdbc-groovy)
|
||||
- [Working with JSON in Groovy](https://www.baeldung.com/groovy-json)
|
||||
- [Reading a File in Groovy](https://www.baeldung.com/groovy-file-read)
|
||||
- [Types of Strings in Groovy](https://www.baeldung.com/groovy-strings)
|
||||
- [A Quick Guide to Iterating a Map in Groovy](https://www.baeldung.com/groovy-map-iterating)
|
||||
@ -12,4 +12,4 @@
|
||||
- [Finding Elements in Collections in Groovy](https://www.baeldung.com/groovy-collections-find-elements)
|
||||
- [Lists in Groovy](https://www.baeldung.com/groovy-lists)
|
||||
- [Converting a String to a Date in Groovy](https://www.baeldung.com/groovy-string-to-date)
|
||||
- [Guide to I/O in Groovy](https://www.baeldung.com/groovy-io)
|
||||
- [Guide to I/O in Groovy](https://www.baeldung.com/groovy-io)
|
||||
|
@ -5,6 +5,6 @@
|
||||
### Relevant Articles:
|
||||
- [Anonymous Classes in Java](http://www.baeldung.com/)
|
||||
- [How to Delay Code Execution in Java](https://www.baeldung.com/java-delay-code-execution)
|
||||
- [Run JAR Application With Command Line Arguments](https://www.baeldung.com/java-run-jar-with-arguments)
|
||||
- [Run a Java Application from the Command Line](https://www.baeldung.com/java-run-jar-with-arguments)
|
||||
- [Java 8 Stream skip() vs limit()](https://www.baeldung.com/java-stream-skip-vs-limit)
|
||||
- [Guide to Java BiFunction Interface](https://www.baeldung.com/java-bifunction-interface)
|
||||
|
@ -10,6 +10,7 @@
|
||||
- [Multi-Dimensional Arrays In Java](https://www.baeldung.com/java-jagged-arrays)
|
||||
- [Find Sum and Average in a Java Array](https://www.baeldung.com/java-array-sum-average)
|
||||
- [Arrays in Java: A Reference Guide](https://www.baeldung.com/java-arrays-guide)
|
||||
- [How to Invert an Array in Java](https://www.baeldung.com/java-invert-array)
|
||||
- [Read and Write User Input in Java](https://www.baeldung.com/java-console-input-output)
|
||||
- [How to Reverse an Array in Java](http://www.baeldung.com/java-invert-array)
|
||||
- [Sorting Arrays in Java](https://www.baeldung.com/java-sorting-arrays)
|
||||
- [Checking If an Array Is Sorted in Java](https://www.baeldung.com/java-check-sorted-array)
|
||||
|
@ -1,8 +1,13 @@
|
||||
## Relevant Articles:
|
||||
## Core Java Exceptions
|
||||
|
||||
- [Will an Error Be Caught by Catch Block in Java?](https://www.baeldung.com/java-error-catch)
|
||||
- [Java Global Exception Handler](http://www.baeldung.com/java-global-exception-handler)
|
||||
- [Common Java Exceptions](http://www.baeldung.com/java-common-exceptions)
|
||||
- [Throw Exception in Optional in Java 8](https://www.baeldung.com/java-optional-throw-exception)
|
||||
- [How to Find an Exception’s Root Cause in Java](https://www.baeldung.com/java-exception-root-cause)
|
||||
- [Java – Try with Resources](https://www.baeldung.com/java-try-with-resources)
|
||||
This module contains articles about core java exceptions
|
||||
|
||||
### Relevant articles:
|
||||
- [Chained Exceptions in Java](https://www.baeldung.com/java-chained-exceptions)
|
||||
- [ClassNotFoundException vs NoClassDefFoundError](https://www.baeldung.com/java-classnotfoundexception-and-noclassdeffounderror)
|
||||
- [Create a Custom Exception in Java](https://www.baeldung.com/java-new-custom-exception)
|
||||
- [Exception Handling in Java](https://www.baeldung.com/java-exceptions)
|
||||
- [Differences Between Final, Finally and Finalize in Java](https://www.baeldung.com/java-final-finally-finalize)
|
||||
- [Difference Between Throw and Throws in Java](https://www.baeldung.com/java-throw-throws)
|
||||
- [“Sneaky Throws” in Java](https://www.baeldung.com/java-sneaky-throws)
|
||||
- [The StackOverflowError in Java](https://www.baeldung.com/java-stack-overflow-error)
|
||||
|
@ -1,55 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung.exception.numberformat</groupId>
|
||||
<artifactId>core-java-exceptions</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>core-java-exceptions</name>
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<groupId>com.baeldung.exceptions</groupId>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-exceptions</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-exceptions</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-java</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-java</relativePath>
|
||||
</parent>
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-java</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-java</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh-generator-annprocess.version}</version>
|
||||
</dependency>
|
||||
<!-- test scoped -->
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>mail</artifactId>
|
||||
<version>${javax.mail.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- test scoped -->
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<commons-lang3.version>3.9</commons-lang3.version>
|
||||
<jmh-core.version>1.19</jmh-core.version>
|
||||
<assertj-core.version>3.10.0</assertj-core.version>
|
||||
<jmh-generator-annprocess.version>1.19</jmh-generator-annprocess.version>
|
||||
</properties>
|
||||
<properties>
|
||||
<javax.mail.version>1.5.0-b01</javax.mail.version>
|
||||
<!-- testing -->
|
||||
<assertj-core.version>3.10.0</assertj-core.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
</project>
|
@ -1,20 +0,0 @@
|
||||
package com.baeldung.exceptions;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Arithmetic {
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(Arithmetic.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
int result = 30 / 0; // Trying to divide by zero
|
||||
} catch (ArithmeticException e) {
|
||||
LOGGER.error("ArithmeticException caught!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package com.baeldung.exceptions;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ArrayIndexOutOfBounds {
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(ArrayIndexOutOfBounds.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
int[] nums = new int[] { 1, 2, 3 };
|
||||
|
||||
try {
|
||||
int numFromNegativeIndex = nums[-1]; // Trying to access at negative index
|
||||
int numFromGreaterIndex = nums[4]; // Trying to access at greater index
|
||||
int numFromLengthIndex = nums[3]; // Trying to access at index equal to size of the array
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
LOGGER.error("ArrayIndexOutOfBoundsException caught");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package com.baeldung.exceptions;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
public class CheckedUncheckedExceptions {
|
||||
public static void checkedExceptionWithThrows() throws FileNotFoundException {
|
||||
File file = new File("not_existing_file.txt");
|
||||
FileInputStream stream = new FileInputStream(file);
|
||||
}
|
||||
|
||||
public static void checkedExceptionWithTryCatch() {
|
||||
File file = new File("not_existing_file.txt");
|
||||
try {
|
||||
FileInputStream stream = new FileInputStream(file);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static int divideByZero() {
|
||||
int numerator = 1;
|
||||
int denominator = 0;
|
||||
return numerator / denominator;
|
||||
}
|
||||
|
||||
public static void checkFile(String fileName) throws IncorrectFileNameException {
|
||||
if (fileName == null || fileName.isEmpty()) {
|
||||
throw new NullOrEmptyException("The filename is null.");
|
||||
}
|
||||
if (!isCorrectFileName(fileName)) {
|
||||
throw new IncorrectFileNameException("Incorrect filename : " + fileName);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isCorrectFileName(String fileName) {
|
||||
if (fileName.equals("wrongFileName.txt"))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package com.baeldung.exceptions;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
class Animal {
|
||||
|
||||
}
|
||||
|
||||
class Dog extends Animal {
|
||||
|
||||
}
|
||||
|
||||
class Lion extends Animal {
|
||||
|
||||
}
|
||||
|
||||
public class ClassCast {
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(ClassCast.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
Animal animalOne = new Dog(); // At runtime the instance is dog
|
||||
Dog bruno = (Dog) animalOne; // Downcasting
|
||||
|
||||
Animal animalTwo = new Lion(); // At runtime the instance is animal
|
||||
Dog tommy = (Dog) animalTwo; // Downcasting
|
||||
} catch (ClassCastException e) {
|
||||
LOGGER.error("ClassCastException caught!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.baeldung.exceptions;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class FileNotFound {
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(FileNotFound.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(new File("/invalid/file/location")));
|
||||
} catch (FileNotFoundException e) {
|
||||
LOGGER.error("FileNotFoundException caught!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package com.baeldung.exceptions;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Handler globalExceptionHandler = new Handler();
|
||||
Thread.setDefaultUncaughtExceptionHandler(globalExceptionHandler);
|
||||
new GlobalExceptionHandler().performArithmeticOperation(10, 0);
|
||||
}
|
||||
|
||||
public int performArithmeticOperation(int num1, int num2) {
|
||||
return num1/num2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Handler implements Thread.UncaughtExceptionHandler {
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(Handler.class);
|
||||
|
||||
public void uncaughtException(Thread t, Throwable e) {
|
||||
LOGGER.info("Unhandled exception caught!");
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.baeldung.exceptions;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class IllegalArgument {
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(IllegalArgument.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
Thread.sleep(-1000);
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.error("IllegalArgumentException caught!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package com.baeldung.exceptions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class IllegalState {
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(IllegalState.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
List<Integer> intList = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
intList.add(i);
|
||||
}
|
||||
|
||||
Iterator<Integer> intListIterator = intList.iterator(); // Initialized with index at -1
|
||||
|
||||
try {
|
||||
intListIterator.remove(); // IllegalStateException
|
||||
} catch (IllegalStateException e) {
|
||||
LOGGER.error("IllegalStateException caught!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package com.baeldung.exceptions;
|
||||
|
||||
public class IncorrectFileNameException extends Exception {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public IncorrectFileNameException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
}
|
||||
|
||||
public IncorrectFileNameException(String errorMessage, Throwable thr) {
|
||||
super(errorMessage, thr);
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package com.baeldung.exceptions;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
class ChildThread extends Thread {
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(ChildThread.class);
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.error("InterruptedException caught!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class InterruptedExceptionExample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
ChildThread childThread = new ChildThread();
|
||||
childThread.start();
|
||||
childThread.interrupt();
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.baeldung.exceptions;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class MalformedURL {
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(MalformedURL.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
URL baeldungURL = null;
|
||||
|
||||
try {
|
||||
baeldungURL = new URL("malformedurl");
|
||||
} catch (MalformedURLException e) {
|
||||
LOGGER.error("MalformedURLException caught!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.baeldung.exceptions;
|
||||
|
||||
public class NullOrEmptyException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public NullOrEmptyException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
}
|
||||
|
||||
public NullOrEmptyException(String errorMessage, Throwable thr) {
|
||||
super(errorMessage, thr);
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package com.baeldung.exceptions;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class NullPointer {
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(NullPointer.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Person personObj = null;
|
||||
|
||||
try {
|
||||
String name = personObj.personName; // Accessing the field of a null object
|
||||
personObj.personName = "Jon Doe"; // Modifying the field of a null object
|
||||
} catch (NullPointerException e) {
|
||||
LOGGER.error("NullPointerException caught!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class Person {
|
||||
|
||||
public String personName;
|
||||
|
||||
public String getPersonName() {
|
||||
return personName;
|
||||
}
|
||||
|
||||
public void setPersonName(String personName) {
|
||||
this.personName = personName;
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.baeldung.exceptions;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class NumberFormat {
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(NumberFormat.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
String str1 = "100ABCD";
|
||||
|
||||
try {
|
||||
int x = Integer.parseInt(str1); // Converting string with inappropriate format
|
||||
int y = Integer.valueOf(str1);
|
||||
} catch (NumberFormatException e) {
|
||||
LOGGER.error("NumberFormatException caught!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.baeldung.exceptions;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ParseExceptionExample {
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(ParseExceptionExample.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
DateFormat format = new SimpleDateFormat("MM, dd, yyyy");
|
||||
|
||||
try {
|
||||
format.parse("01, , 2010");
|
||||
} catch (ParseException e) {
|
||||
LOGGER.error("ParseException caught!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
package com.baeldung.exceptions;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Period;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Utility class to find root cause exceptions.
|
||||
*/
|
||||
public class RootCauseFinder {
|
||||
|
||||
private RootCauseFinder() {
|
||||
}
|
||||
|
||||
public static Throwable findCauseUsingPlainJava(Throwable throwable) {
|
||||
Objects.requireNonNull(throwable);
|
||||
Throwable rootCause = throwable;
|
||||
while (rootCause.getCause() != null && rootCause.getCause() != rootCause) {
|
||||
rootCause = rootCause.getCause();
|
||||
}
|
||||
return rootCause;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the age of a person from a given date.
|
||||
*/
|
||||
static class AgeCalculator {
|
||||
|
||||
private AgeCalculator() {
|
||||
}
|
||||
|
||||
public static int calculateAge(String birthDate) {
|
||||
if (birthDate == null || birthDate.isEmpty()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
try {
|
||||
return Period
|
||||
.between(parseDate(birthDate), LocalDate.now())
|
||||
.getYears();
|
||||
} catch (DateParseException ex) {
|
||||
throw new CalculationException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static LocalDate parseDate(String birthDateAsString) {
|
||||
|
||||
LocalDate birthDate;
|
||||
try {
|
||||
birthDate = LocalDate.parse(birthDateAsString);
|
||||
} catch (DateTimeParseException ex) {
|
||||
throw new InvalidFormatException(birthDateAsString, ex);
|
||||
}
|
||||
|
||||
if (birthDate.isAfter(LocalDate.now())) {
|
||||
throw new DateOutOfRangeException(birthDateAsString);
|
||||
}
|
||||
|
||||
return birthDate;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class CalculationException extends RuntimeException {
|
||||
|
||||
CalculationException(DateParseException ex) {
|
||||
super(ex);
|
||||
}
|
||||
}
|
||||
|
||||
static class DateParseException extends RuntimeException {
|
||||
|
||||
DateParseException(String input) {
|
||||
super(input);
|
||||
}
|
||||
|
||||
DateParseException(String input, Throwable thr) {
|
||||
super(input, thr);
|
||||
}
|
||||
}
|
||||
|
||||
static class InvalidFormatException extends DateParseException {
|
||||
|
||||
InvalidFormatException(String input, Throwable thr) {
|
||||
super("Invalid date format: " + input, thr);
|
||||
}
|
||||
}
|
||||
|
||||
static class DateOutOfRangeException extends DateParseException {
|
||||
|
||||
DateOutOfRangeException(String date) {
|
||||
super("Date out of range: " + date);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package com.baeldung.exceptions;
|
||||
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
public class StackTraceToString {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Convert a StackTrace to String using core java
|
||||
try {
|
||||
throw new NullPointerException();
|
||||
} catch (Exception e) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
|
||||
System.out.println(sw.toString());
|
||||
}
|
||||
|
||||
// Convert a StackTrace to String using Apache Commons
|
||||
try {
|
||||
throw new IndexOutOfBoundsException();
|
||||
} catch (Exception e) {
|
||||
System.out.println(ExceptionUtils.getStackTrace(e));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.baeldung.exceptions;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class StringIndexOutOfBounds {
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(StringIndexOutOfBounds.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
String str = "Hello World";
|
||||
|
||||
try {
|
||||
char charAtNegativeIndex = str.charAt(-1); // Trying to access at negative index
|
||||
char charAtLengthIndex = str.charAt(11); // Trying to access at index equal to size of the string
|
||||
} catch (StringIndexOutOfBoundsException e) {
|
||||
LOGGER.error("StringIndexOutOfBoundsException caught");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package com.baeldung.chainedexception;
|
||||
package com.baeldung.exceptions.chainedexception;
|
||||
|
||||
import com.baeldung.chainedexception.exceptions.GirlFriendOfManagerUpsetException;
|
||||
import com.baeldung.chainedexception.exceptions.ManagerUpsetException;
|
||||
import com.baeldung.chainedexception.exceptions.NoLeaveGrantedException;
|
||||
import com.baeldung.chainedexception.exceptions.TeamLeadUpsetException;
|
||||
import com.baeldung.exceptions.chainedexception.exceptions.GirlFriendOfManagerUpsetException;
|
||||
import com.baeldung.exceptions.chainedexception.exceptions.ManagerUpsetException;
|
||||
import com.baeldung.exceptions.chainedexception.exceptions.NoLeaveGrantedException;
|
||||
import com.baeldung.exceptions.chainedexception.exceptions.TeamLeadUpsetException;
|
||||
|
||||
public class LogWithChain {
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.baeldung.chainedexception;
|
||||
package com.baeldung.exceptions.chainedexception;
|
||||
|
||||
import com.baeldung.chainedexception.exceptions.GirlFriendOfManagerUpsetException;
|
||||
import com.baeldung.chainedexception.exceptions.ManagerUpsetException;
|
||||
import com.baeldung.chainedexception.exceptions.NoLeaveGrantedException;
|
||||
import com.baeldung.chainedexception.exceptions.TeamLeadUpsetException;
|
||||
import com.baeldung.exceptions.chainedexception.exceptions.GirlFriendOfManagerUpsetException;
|
||||
import com.baeldung.exceptions.chainedexception.exceptions.ManagerUpsetException;
|
||||
import com.baeldung.exceptions.chainedexception.exceptions.NoLeaveGrantedException;
|
||||
import com.baeldung.exceptions.chainedexception.exceptions.TeamLeadUpsetException;
|
||||
|
||||
public class LogWithoutChain {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.chainedexception.exceptions;
|
||||
package com.baeldung.exceptions.chainedexception.exceptions;
|
||||
|
||||
public class GirlFriendOfManagerUpsetException extends Exception {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.chainedexception.exceptions;
|
||||
package com.baeldung.exceptions.chainedexception.exceptions;
|
||||
|
||||
public class ManagerUpsetException extends Exception {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.chainedexception.exceptions;
|
||||
package com.baeldung.exceptions.chainedexception.exceptions;
|
||||
|
||||
public class NoLeaveGrantedException extends Exception {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.chainedexception.exceptions;
|
||||
package com.baeldung.exceptions.chainedexception.exceptions;
|
||||
|
||||
public class TeamLeadUpsetException extends Exception {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.customexception;
|
||||
package com.baeldung.exceptions.customexception;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.customexception;
|
||||
package com.baeldung.exceptions.customexception;
|
||||
|
||||
public class IncorrectFileExtensionException extends RuntimeException{
|
||||
private static final long serialVersionUID = 1L;
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.customexception;
|
||||
package com.baeldung.exceptions.customexception;
|
||||
|
||||
public class IncorrectFileNameException extends Exception {
|
||||
private static final long serialVersionUID = 1L;
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.exceptionhandling;
|
||||
package com.baeldung.exceptions.exceptionhandling;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
@ -0,0 +1,5 @@
|
||||
package com.baeldung.exceptions.exceptionhandling;
|
||||
|
||||
public class MyException extends Throwable {
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.exceptionhandling;
|
||||
package com.baeldung.exceptions.exceptionhandling;
|
||||
|
||||
public class Player {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.exceptionhandling;
|
||||
package com.baeldung.exceptions.exceptionhandling;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.exceptionhandling;
|
||||
package com.baeldung.exceptions.exceptionhandling;
|
||||
|
||||
public class PlayerScoreException extends Exception {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.exceptionhandling;
|
||||
package com.baeldung.exceptions.exceptionhandling;
|
||||
|
||||
public class TimeoutException extends Exception {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.keywords.finalize;
|
||||
package com.baeldung.exceptions.keywords.finalize;
|
||||
|
||||
public class FinalizeObject {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.keywords.finalkeyword;
|
||||
package com.baeldung.exceptions.keywords.finalkeyword;
|
||||
|
||||
public final class Child extends Parent {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.keywords.finalkeyword;
|
||||
package com.baeldung.exceptions.keywords.finalkeyword;
|
||||
|
||||
/*public class GrandChild extends Child {
|
||||
// Compilation error
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.keywords.finalkeyword;
|
||||
package com.baeldung.exceptions.keywords.finalkeyword;
|
||||
|
||||
public class Parent {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.keywords.finallykeyword;
|
||||
package com.baeldung.exceptions.keywords.finallykeyword;
|
||||
|
||||
public class FinallyExample {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.noclassdeffounderror;
|
||||
package com.baeldung.exceptions.noclassdeffounderror;
|
||||
|
||||
public class ClassWithInitErrors {
|
||||
static int data = 1 / 0;
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.noclassdeffounderror;
|
||||
package com.baeldung.exceptions.noclassdeffounderror;
|
||||
|
||||
public class NoClassDefFoundErrorExample {
|
||||
public ClassWithInitErrors getClassWithInitErrors() {
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.sneakythrows;
|
||||
package com.baeldung.exceptions.sneakythrows;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.sneakythrows;
|
||||
package com.baeldung.exceptions.sneakythrows;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.stackoverflowerror;
|
||||
package com.baeldung.exceptions.stackoverflowerror;
|
||||
|
||||
public class AccountHolder {
|
||||
private String firstName;
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.stackoverflowerror;
|
||||
package com.baeldung.exceptions.stackoverflowerror;
|
||||
|
||||
public class ClassOne {
|
||||
private int oneValue;
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.stackoverflowerror;
|
||||
package com.baeldung.exceptions.stackoverflowerror;
|
||||
|
||||
public class ClassTwo {
|
||||
private int twoValue;
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.stackoverflowerror;
|
||||
package com.baeldung.exceptions.stackoverflowerror;
|
||||
|
||||
public class InfiniteRecursionWithTerminationCondition {
|
||||
public int calculateFactorial(final int number) {
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.stackoverflowerror;
|
||||
package com.baeldung.exceptions.stackoverflowerror;
|
||||
|
||||
public class RecursionWithCorrectTerminationCondition {
|
||||
public int calculateFactorial(final int number) {
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.stackoverflowerror;
|
||||
package com.baeldung.exceptions.stackoverflowerror;
|
||||
|
||||
public class UnintendedInfiniteRecursion {
|
||||
public int calculateFactorial(int number) {
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.throwsexception;
|
||||
package com.baeldung.exceptions.throwvsthrows;
|
||||
|
||||
public class DataAccessException extends RuntimeException {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.throwsexception;
|
||||
package com.baeldung.exceptions.throwvsthrows;
|
||||
|
||||
import com.sun.mail.iap.ConnectionException;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user