diff --git a/algorithms-miscellaneous-1/README.md b/algorithms-miscellaneous-1/README.md index 6f18396005..7ed805f7c4 100644 --- a/algorithms-miscellaneous-1/README.md +++ b/algorithms-miscellaneous-1/README.md @@ -15,3 +15,5 @@ - [Find Substrings That Are Palindromes in Java](https://www.baeldung.com/java-palindrome-substrings) - [Find the Longest Substring without Repeating Characters](https://www.baeldung.com/java-longest-substring-without-repeated-characters) - [Java Two Pointer Technique](https://www.baeldung.com/java-two-pointer-technique) +- [Permutations of an Array in Java](https://www.baeldung.com/java-array-permutations) +- [Implementing Simple State Machines with Java Enums](https://www.baeldung.com/java-enum-simple-state-machine) diff --git a/apache-spark/README.md b/apache-spark/README.md index fb8059eb27..a4dce212b4 100644 --- a/apache-spark/README.md +++ b/apache-spark/README.md @@ -1,3 +1,4 @@ ### Relevant articles - [Introduction to Apache Spark](http://www.baeldung.com/apache-spark) +- [Building a Data Pipeline with Kafka, Spark Streaming and Cassandra](https://www.baeldung.com/kafka-spark-data-pipeline) diff --git a/core-java-11/README.md b/core-java-11/README.md index c8039f4bc5..3c8b94fa28 100644 --- a/core-java-11/README.md +++ b/core-java-11/README.md @@ -3,3 +3,4 @@ - [Java 11 Single File Source Code](https://www.baeldung.com/java-single-file-source-code) - [Java 11 Local Variable Syntax for Lambda Parameters](https://www.baeldung.com/java-var-lambda-params) - [Java 11 String API Additions](https://www.baeldung.com/java-11-string-api) +- [Java 11 Nest Based Access Control](https://www.baeldung.com/java-nest-based-access-control) diff --git a/core-java-9/README.md b/core-java-9/README.md index c96267dc95..d9586ba684 100644 --- a/core-java-9/README.md +++ b/core-java-9/README.md @@ -26,3 +26,4 @@ - [Initialize a HashMap in Java](https://www.baeldung.com/java-initialize-hashmap) - [Java 9 Platform Logging API](https://www.baeldung.com/java-9-logging-api) - [Guide to java.lang.Process API](https://www.baeldung.com/java-process-api) +- [Immutable Set in Java](https://www.baeldung.com/java-immutable-set) diff --git a/core-java-arrays/README.md b/core-java-arrays/README.md index 400dd7793c..ed8221ebe4 100644 --- a/core-java-arrays/README.md +++ b/core-java-arrays/README.md @@ -14,3 +14,4 @@ - [Array Operations in Java](http://www.baeldung.com/java-common-array-operations) - [Intersection Between two Integer Arrays](https://www.baeldung.com/java-array-intersection) - [Sorting Arrays in Java](https://www.baeldung.com/java-sorting-arrays) +- [Convert a Float to a Byte Array in Java](https://www.baeldung.com/java-convert-float-to-byte-array) diff --git a/core-java-collections/README.md b/core-java-collections/README.md index be83621429..710be31a08 100644 --- a/core-java-collections/README.md +++ b/core-java-collections/README.md @@ -31,3 +31,4 @@ - [A Guide to EnumMap](https://www.baeldung.com/java-enum-map) - [A Guide to Iterator in Java](http://www.baeldung.com/java-iterator) - [Differences Between HashMap and Hashtable](https://www.baeldung.com/hashmap-hashtable-differences) +- [Java ArrayList vs Vector](https://www.baeldung.com/java-arraylist-vs-vector) diff --git a/core-java-collections/src/test/java/com/baeldung/queueInterface/PriorityQueueUnitTest.java b/core-java-collections/src/test/java/com/baeldung/queueinterface/PriorityQueueUnitTest.java similarity index 100% rename from core-java-collections/src/test/java/com/baeldung/queueInterface/PriorityQueueUnitTest.java rename to core-java-collections/src/test/java/com/baeldung/queueinterface/PriorityQueueUnitTest.java diff --git a/core-java-io/README.md b/core-java-io/README.md index fcb3302a48..9a25009849 100644 --- a/core-java-io/README.md +++ b/core-java-io/README.md @@ -38,3 +38,5 @@ - [How to Get the File Extension of a File in Java](http://www.baeldung.com/java-file-extension) - [Getting a File’s Mime Type in Java](http://www.baeldung.com/java-file-mime-type) - [Create a Directory in Java](https://www.baeldung.com/java-create-directory) +- [How to Write to a CSV File in Java](https://www.baeldung.com/java-csv) +- [List Files in a Directory in Java](https://www.baeldung.com/java-list-directory-files) diff --git a/core-java-lang-syntax/README.md b/core-java-lang-syntax/README.md index a7c1b7cc4a..99c8613929 100644 --- a/core-java-lang-syntax/README.md +++ b/core-java-lang-syntax/README.md @@ -16,4 +16,5 @@ - [Quick Guide to java.lang.System](http://www.baeldung.com/java-lang-system) - [Java Switch Statement](https://www.baeldung.com/java-switch) - [The Modulo Operator in Java](https://www.baeldung.com/modulo-java) -- [Ternary Operator In Java](https://www.baeldung.com/java-ternary-operator) \ No newline at end of file +- [Ternary Operator In Java](https://www.baeldung.com/java-ternary-operator) +- [Java instanceof Operator](https://www.baeldung.com/java-instanceof) diff --git a/core-java-lang/README.md b/core-java-lang/README.md index 7af962558d..c1c22caf6c 100644 --- a/core-java-lang/README.md +++ b/core-java-lang/README.md @@ -34,4 +34,10 @@ - [“Sneaky Throws” in Java](http://www.baeldung.com/java-sneaky-throws) - [Retrieving a Class Name in Java](https://www.baeldung.com/java-class-name) - [Java Compound Operators](https://www.baeldung.com/java-compound-operators) -- [Guide to Java Packages](https://www.baeldung.com/java-packages) \ No newline at end of file +- [Guide to Java Packages](https://www.baeldung.com/java-packages) +- [The Java Native Keyword and Methods](https://www.baeldung.com/java-native) +- [If-Else Statement in Java](https://www.baeldung.com/java-if-else) +- [Control Structures in Java](https://www.baeldung.com/java-control-structures) +- [Java Interfaces](https://www.baeldung.com/java-interfaces) +- [Attaching Values to Java Enum](https://www.baeldung.com/java-enum-values) +- [Variable Scope in Java](https://www.baeldung.com/java-variable-scope) diff --git a/core-java-perf/README.md b/core-java-perf/README.md index 252ee4cc45..1b3b590bf8 100644 --- a/core-java-perf/README.md +++ b/core-java-perf/README.md @@ -5,4 +5,5 @@ - [Different Ways to Capture Java Heap Dumps](https://www.baeldung.com/java-heap-dump-capture) - [Understanding Memory Leaks in Java](https://www.baeldung.com/java-memory-leaks) - [OutOfMemoryError: GC Overhead Limit Exceeded](http://www.baeldung.com/java-gc-overhead-limit-exceeded) -- [Basic Introduction to JMX](http://www.baeldung.com/java-management-extensions) \ No newline at end of file +- [Basic Introduction to JMX](http://www.baeldung.com/java-management-extensions) +- [Monitoring Java Applications with Flight Recorder](https://www.baeldung.com/java-flight-recorder-monitoring) diff --git a/core-java-security/README.md b/core-java-security/README.md index 415171094b..d3343f79ca 100644 --- a/core-java-security/README.md +++ b/core-java-security/README.md @@ -8,4 +8,5 @@ - [Encrypting and Decrypting Files in Java](http://www.baeldung.com/java-cipher-input-output-stream) - [Hashing a Password in Java](https://www.baeldung.com/java-password-hashing) - [SSL Handshake Failures](https://www.baeldung.com/java-ssl-handshake-failures) -- [SHA-256 Hashing in Java](https://www.baeldung.com/sha-256-hashing-java) \ No newline at end of file +- [SHA-256 Hashing in Java](https://www.baeldung.com/sha-256-hashing-java) +- [Enabling TLS v1.2 in Java 7](https://www.baeldung.com/java-7-tls-v12) diff --git a/core-java/README.md b/core-java/README.md index d6cb619ed3..d2fd903c10 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -47,3 +47,7 @@ - [Console I/O in Java](http://www.baeldung.com/java-console-input-output) - [Formatting with printf() in Java](https://www.baeldung.com/java-printstream-printf) - [Retrieve Fields from a Java Class Using Reflection](https://www.baeldung.com/java-reflection-class-fields) +- [Introduction to Basic Syntax in Java](https://www.baeldung.com/java-syntax) +- [Using Curl in Java](https://www.baeldung.com/java-curl) +- [Finding Leap Years in Java](https://www.baeldung.com/java-leap-year) +- [Java Bitwise Operators](https://www.baeldung.com/java-bitwise-operators) diff --git a/core-kotlin/README.md b/core-kotlin/README.md index 225ad87e87..6ee79b2a2e 100644 --- a/core-kotlin/README.md +++ b/core-kotlin/README.md @@ -51,3 +51,4 @@ - [Operator Overloading in Kotlin](https://www.baeldung.com/kotlin-operator-overloading) - [Inline Classes in Kotlin](https://www.baeldung.com/kotlin-inline-classes) - [Creating Java static final Equivalents in Kotlin](https://www.baeldung.com/kotlin-java-static-final) +- [Nested forEach in Kotlin](https://www.baeldung.com/kotlin-nested-foreach) diff --git a/guice/pom.xml b/guice/pom.xml index f3e7873245..5c4518da7a 100644 --- a/guice/pom.xml +++ b/guice/pom.xml @@ -26,4 +26,4 @@ 4.1.0 - + \ No newline at end of file diff --git a/guice/src/main/java/com/baeldung/examples/common/Account.java b/guice/src/main/java/com/baeldung/examples/common/Account.java new file mode 100644 index 0000000000..fd2df005ac --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/common/Account.java @@ -0,0 +1,24 @@ +package com.baeldung.examples.common; + +public class Account { + + private String accountNumber; + private String type; + + public String getAccountNumber() { + return accountNumber; + } + + public void setAccountNumber(String accountNumber) { + this.accountNumber = accountNumber; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + +} diff --git a/guice/src/main/java/com/baeldung/examples/common/AccountService.java b/guice/src/main/java/com/baeldung/examples/common/AccountService.java new file mode 100644 index 0000000000..97a64e3c6e --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/common/AccountService.java @@ -0,0 +1,5 @@ +package com.baeldung.examples.common; + +public interface AccountService { + +} diff --git a/guice/src/main/java/com/baeldung/examples/common/AccountServiceImpl.java b/guice/src/main/java/com/baeldung/examples/common/AccountServiceImpl.java new file mode 100644 index 0000000000..18d6777c4a --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/common/AccountServiceImpl.java @@ -0,0 +1,5 @@ +package com.baeldung.examples.common; + +public class AccountServiceImpl implements AccountService { + +} diff --git a/guice/src/main/java/com/baeldung/examples/common/AudioBookService.java b/guice/src/main/java/com/baeldung/examples/common/AudioBookService.java new file mode 100644 index 0000000000..5d501f2051 --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/common/AudioBookService.java @@ -0,0 +1,5 @@ +package com.baeldung.examples.common; + +public interface AudioBookService { + +} diff --git a/guice/src/main/java/com/baeldung/examples/common/AudioBookServiceImpl.java b/guice/src/main/java/com/baeldung/examples/common/AudioBookServiceImpl.java new file mode 100644 index 0000000000..c64e953a58 --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/common/AudioBookServiceImpl.java @@ -0,0 +1,5 @@ +package com.baeldung.examples.common; + +public class AudioBookServiceImpl implements AudioBookService { + +} diff --git a/guice/src/main/java/com/baeldung/examples/common/AuthorService.java b/guice/src/main/java/com/baeldung/examples/common/AuthorService.java new file mode 100644 index 0000000000..9be148b8c3 --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/common/AuthorService.java @@ -0,0 +1,5 @@ +package com.baeldung.examples.common; + +public interface AuthorService { + +} diff --git a/guice/src/main/java/com/baeldung/examples/common/AuthorServiceImpl.java b/guice/src/main/java/com/baeldung/examples/common/AuthorServiceImpl.java new file mode 100644 index 0000000000..bac532e469 --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/common/AuthorServiceImpl.java @@ -0,0 +1,5 @@ +package com.baeldung.examples.common; + +public class AuthorServiceImpl implements AuthorService { + +} diff --git a/guice/src/main/java/com/baeldung/examples/common/BookService.java b/guice/src/main/java/com/baeldung/examples/common/BookService.java new file mode 100644 index 0000000000..56339c1398 --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/common/BookService.java @@ -0,0 +1,5 @@ +package com.baeldung.examples.common; + +public interface BookService { + +} diff --git a/guice/src/main/java/com/baeldung/examples/common/BookServiceImpl.java b/guice/src/main/java/com/baeldung/examples/common/BookServiceImpl.java new file mode 100644 index 0000000000..aee0d22e51 --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/common/BookServiceImpl.java @@ -0,0 +1,7 @@ +package com.baeldung.examples.common; + +public class BookServiceImpl implements BookService { + + private AuthorService authorService; + +} diff --git a/guice/src/main/java/com/baeldung/examples/common/PersonDao.java b/guice/src/main/java/com/baeldung/examples/common/PersonDao.java new file mode 100644 index 0000000000..980fee0252 --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/common/PersonDao.java @@ -0,0 +1,5 @@ +package com.baeldung.examples.common; + +public interface PersonDao { + +} diff --git a/guice/src/main/java/com/baeldung/examples/common/PersonDaoImpl.java b/guice/src/main/java/com/baeldung/examples/common/PersonDaoImpl.java new file mode 100644 index 0000000000..ecbf198cc0 --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/common/PersonDaoImpl.java @@ -0,0 +1,5 @@ +package com.baeldung.examples.common; + +public class PersonDaoImpl implements PersonDao { + +} \ No newline at end of file diff --git a/guice/src/main/java/com/baeldung/examples/guice/Foo.java b/guice/src/main/java/com/baeldung/examples/guice/Foo.java new file mode 100644 index 0000000000..fca32b165b --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/guice/Foo.java @@ -0,0 +1,4 @@ +package com.baeldung.examples.guice; + +public class Foo { +} diff --git a/guice/src/main/java/com/baeldung/examples/guice/FooProcessor.java b/guice/src/main/java/com/baeldung/examples/guice/FooProcessor.java new file mode 100644 index 0000000000..929013cd2b --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/guice/FooProcessor.java @@ -0,0 +1,9 @@ +package com.baeldung.examples.guice; + +import com.google.inject.Inject; + +public class FooProcessor { + + @Inject + private Foo foo; +} \ No newline at end of file diff --git a/guice/src/main/java/com/baeldung/examples/guice/GuicePersonService.java b/guice/src/main/java/com/baeldung/examples/guice/GuicePersonService.java new file mode 100644 index 0000000000..ce12e3e528 --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/guice/GuicePersonService.java @@ -0,0 +1,19 @@ +package com.baeldung.examples.guice; + +import com.baeldung.examples.common.PersonDao; +import com.google.inject.Inject; + +public class GuicePersonService { + + @Inject + private PersonDao personDao; + + public PersonDao getPersonDao() { + return personDao; + } + + public void setPersonDao(PersonDao personDao) { + this.personDao = personDao; + } + +} diff --git a/guice/src/main/java/com/baeldung/examples/guice/GuiceUserService.java b/guice/src/main/java/com/baeldung/examples/guice/GuiceUserService.java new file mode 100644 index 0000000000..0e58d0bacf --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/guice/GuiceUserService.java @@ -0,0 +1,19 @@ +package com.baeldung.examples.guice; + +import com.baeldung.examples.common.AccountService; +import com.google.inject.Inject; + +public class GuiceUserService { + + @Inject + private AccountService accountService; + + public AccountService getAccountService() { + return accountService; + } + + public void setAccountService(AccountService accountService) { + this.accountService = accountService; + } + +} diff --git a/guice/src/main/java/com/baeldung/examples/guice/Person.java b/guice/src/main/java/com/baeldung/examples/guice/Person.java new file mode 100644 index 0000000000..d54b5110eb --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/guice/Person.java @@ -0,0 +1,24 @@ +package com.baeldung.examples.guice; + +public class Person { + private String firstName; + + private String lastName; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + +} diff --git a/guice/src/main/java/com/baeldung/examples/guice/modules/GuiceModule.java b/guice/src/main/java/com/baeldung/examples/guice/modules/GuiceModule.java new file mode 100644 index 0000000000..fbcd36b56a --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/guice/modules/GuiceModule.java @@ -0,0 +1,50 @@ +package com.baeldung.examples.guice.modules; + +import com.baeldung.examples.common.AccountService; +import com.baeldung.examples.common.AccountServiceImpl; +import com.baeldung.examples.common.BookService; +import com.baeldung.examples.common.BookServiceImpl; +import com.baeldung.examples.common.PersonDao; +import com.baeldung.examples.common.PersonDaoImpl; +import com.baeldung.examples.guice.Foo; +import com.baeldung.examples.guice.Person; +import com.google.inject.AbstractModule; +import com.google.inject.Provider; +import com.google.inject.Provides; + +public class GuiceModule extends AbstractModule { + + @Override + protected void configure() { + try { + bind(AccountService.class).to(AccountServiceImpl.class); + bind(Person.class).toConstructor(Person.class.getConstructor()); + // bind(Person.class).toProvider(new Provider() { + // public Person get() { + // Person p = new Person(); + // return p; + // } + // }); + bind(Foo.class).toProvider(new Provider() { + public Foo get() { + return new Foo(); + } + }); + bind(PersonDao.class).to(PersonDaoImpl.class); + + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + @Provides + public BookService bookServiceGenerator() { + return new BookServiceImpl(); + } + +} diff --git a/guice/src/test/java/com/baeldung/examples/GuiceUnitTest.java b/guice/src/test/java/com/baeldung/examples/GuiceUnitTest.java new file mode 100644 index 0000000000..dd2a89e101 --- /dev/null +++ b/guice/src/test/java/com/baeldung/examples/GuiceUnitTest.java @@ -0,0 +1,61 @@ +package com.baeldung.examples; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +import com.baeldung.examples.common.BookService; +import com.baeldung.examples.guice.FooProcessor; +import com.baeldung.examples.guice.GuicePersonService; +import com.baeldung.examples.guice.GuiceUserService; +import com.baeldung.examples.guice.Person; +import com.baeldung.examples.guice.modules.GuiceModule; +import com.google.inject.Guice; +import com.google.inject.Injector; + +public class GuiceUnitTest { + + @Test + public void givenAccountServiceInjectedInGuiceUserService_WhenGetAccountServiceInvoked_ThenReturnValueIsNotNull() { + Injector injector = Guice.createInjector(new GuiceModule()); + GuiceUserService guiceUserService = injector.getInstance(GuiceUserService.class); + assertNotNull(guiceUserService.getAccountService()); + } + + @Test + public void givenBookServiceIsRegisteredInModule_WhenBookServiceIsInjected_ThenReturnValueIsNotNull() { + Injector injector = Guice.createInjector(new GuiceModule()); + BookService bookService = injector.getInstance(BookService.class); + assertNotNull(bookService); + } + + @Test + public void givenMultipleBindingsForPerson_WhenPersonIsInjected_ThenTestFailsByProvisionException() { + Injector injector = Guice.createInjector(new GuiceModule()); + Person person = injector.getInstance(Person.class); + assertNotNull(person); + } + + @Test + public void givenFooInjectedToFooProcessorAsOptionalDependency_WhenFooProcessorIsRetrievedFromContext_ThenCreationExceptionIsNotThrown() { + Injector injector = Guice.createInjector(new GuiceModule()); + FooProcessor fooProcessor = injector.getInstance(FooProcessor.class); + assertNotNull(fooProcessor); + } + + @Test + public void givenGuicePersonServiceConstructorAnnotatedByInject_WhenGuicePersonServiceIsInjected_ThenInstanceWillBeCreatedFromTheConstructor() { + Injector injector = Guice.createInjector(new GuiceModule()); + GuicePersonService personService = injector.getInstance(GuicePersonService.class); + assertNotNull(personService); + } + + @Test + public void givenPersonDaoInjectedToGuicePersonServiceBySetterInjection_WhenGuicePersonServiceIsInjected_ThenPersonDaoInitializedByTheSetter() { + Injector injector = Guice.createInjector(new GuiceModule()); + GuicePersonService personService = injector.getInstance(GuicePersonService.class); + assertNotNull(personService); + assertNotNull(personService.getPersonDao()); + } + +} diff --git a/jackson/README.md b/jackson/README.md index 04e88d0ea1..e201a06727 100644 --- a/jackson/README.md +++ b/jackson/README.md @@ -37,3 +37,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Serialize Only Fields that meet a Custom Criteria with Jackson](http://www.baeldung.com/jackson-serialize-field-custom-criteria) - [Mapping Nested Values with Jackson](http://www.baeldung.com/jackson-nested-values) - [Convert XML to JSON Using Jackson](https://www.baeldung.com/jackson-convert-xml-json) +- [Deserialize Immutable Objects with Jackson](https://www.baeldung.com/jackson-deserialize-immutable-objects) diff --git a/java-collections-maps/README.md b/java-collections-maps/README.md index b4ab270448..5d65e961de 100644 --- a/java-collections-maps/README.md +++ b/java-collections-maps/README.md @@ -19,3 +19,4 @@ - [How to Check If a Key Exists in a Map](https://www.baeldung.com/java-map-key-exists) - [Comparing Two HashMaps in Java](https://www.baeldung.com/java-compare-hashmaps) - [Immutable Map Implementations in Java](https://www.baeldung.com/java-immutable-maps) +- [Map to String Conversion in Java](https://www.baeldung.com/java-map-to-string-conversion) diff --git a/java-dates/README.md b/java-dates/README.md index ac3166d938..8171e5def9 100644 --- a/java-dates/README.md +++ b/java-dates/README.md @@ -27,4 +27,5 @@ - [Convert Between java.time.Instant and java.sql.Timestamp](https://www.baeldung.com/java-time-instant-to-java-sql-timestamp) - [Convert between String and Timestamp](https://www.baeldung.com/java-string-to-timestamp) - [A Guide to SimpleDateFormat](https://www.baeldung.com/java-simple-date-format) -- [ZoneOffset in Java](https://www.baeldung.com/java-zone-offset) \ No newline at end of file +- [ZoneOffset in Java](https://www.baeldung.com/java-zone-offset) +- [Differences Between ZonedDateTime and OffsetDateTime](https://www.baeldung.com/java-zoneddatetime-offsetdatetime) diff --git a/java-streams/README.md b/java-streams/README.md index f2afd570f6..15ea1c742a 100644 --- a/java-streams/README.md +++ b/java-streams/README.md @@ -16,3 +16,4 @@ - [Introduction to Protonpack](https://www.baeldung.com/java-protonpack) - [Java Stream Filter with Lambda Expression](https://www.baeldung.com/java-stream-filter-lambda) - [Counting Matches on a Stream Filter](https://www.baeldung.com/java-stream-filter-count) +- [Java 8 Streams peek() API](https://www.baeldung.com/java-streams-peek-api) diff --git a/java-strings/README.md b/java-strings/README.md index b72a378d06..1ab5e098f6 100644 --- a/java-strings/README.md +++ b/java-strings/README.md @@ -50,3 +50,6 @@ - [Remove Leading and Trailing Characters from a String](https://www.baeldung.com/java-remove-trailing-characters) - [Concatenating Strings In Java](https://www.baeldung.com/java-strings-concatenation) - [Java toString() Method](https://www.baeldung.com/java-tostring) +- [Java String Interview Questions and Answers](https://www.baeldung.com/java-string-interview-questions) +- [Check if a String is a Pangram in Java](https://www.baeldung.com/java-string-pangram) +- [Check If a String Contains Multiple Keywords](https://www.baeldung.com/string-contains-multiple-words) diff --git a/kotlin-libraries/README.md b/kotlin-libraries/README.md index 4110bfe12e..5e2526e64e 100644 --- a/kotlin-libraries/README.md +++ b/kotlin-libraries/README.md @@ -9,3 +9,4 @@ - [Working with Dates in Kotlin](https://www.baeldung.com/kotlin-dates) - [Introduction to Arrow in Kotlin](https://www.baeldung.com/kotlin-arrow) - [Kotlin with Ktor](https://www.baeldung.com/kotlin-ktor) +- [REST API With Kotlin and Kovert](https://www.baeldung.com/kotlin-kovert) diff --git a/libraries-server/README.md b/libraries-server/README.md index 28f963ade8..75c12fd61a 100644 --- a/libraries-server/README.md +++ b/libraries-server/README.md @@ -7,3 +7,4 @@ - [Creating and Configuring Jetty 9 Server in Java](http://www.baeldung.com/jetty-java-programmatic) - [Testing Netty with EmbeddedChannel](http://www.baeldung.com/testing-netty-embedded-channel) - [MQTT Client in Java](https://www.baeldung.com/java-mqtt-client) +- [Guide to XMPP Smack Client](https://www.baeldung.com/xmpp-smack-chat-client) diff --git a/libraries/README.md b/libraries/README.md index b247caedda..378317778e 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -64,7 +64,8 @@ - [Exactly Once Processing in Kafka](https://www.baeldung.com/kafka-exactly-once) - [An Introduction to SuanShu](https://www.baeldung.com/suanshu) - [Implementing a FTP-Client in Java](http://www.baeldung.com/java-ftp-client) -- [Introduction to Functional Java](https://www.baeldung.com/java-functional-library +- [Introduction to Functional Java](https://www.baeldung.com/java-functional-library) +- [Intro to Derive4J](https://www.baeldung.com/derive4j) The libraries module contains examples related to small libraries that are relatively easy to use and does not require any separate module of its own. diff --git a/persistence-modules/java-jpa/README.md b/persistence-modules/java-jpa/README.md index 5fe119cca4..2c26581bab 100644 --- a/persistence-modules/java-jpa/README.md +++ b/persistence-modules/java-jpa/README.md @@ -5,3 +5,4 @@ - [Fixing the JPA error “java.lang.String cannot be cast to Ljava.lang.String;”](https://www.baeldung.com/jpa-error-java-lang-string-cannot-be-cast) - [JPA Entity Graph](https://www.baeldung.com/jpa-entity-graph) - [JPA 2.2 Support for Java 8 Date/Time Types](https://www.baeldung.com/jpa-java-time) +- [Converting Between LocalDate and SQL Date](https://www.baeldung.com/java-convert-localdate-sql-date) diff --git a/persistence-modules/spring-boot-persistence/README.MD b/persistence-modules/spring-boot-persistence/README.MD index cab6be1ec8..6fe5e6f05f 100644 --- a/persistence-modules/spring-boot-persistence/README.MD +++ b/persistence-modules/spring-boot-persistence/README.MD @@ -6,4 +6,4 @@ - [Configuring a Tomcat Connection Pool in Spring Boot](https://www.baeldung.com/spring-boot-tomcat-connection-pool) - [Hibernate Field Naming with Spring Boot](https://www.baeldung.com/hibernate-field-naming-spring-boot) - [Integrating Spring Boot with HSQLDB](https://www.baeldung.com/spring-boot-hsqldb) - +- [Configuring a DataSource Programmatically in Spring Boot](https://www.baeldung.com/spring-boot-configure-data-source-programmatic) diff --git a/persistence-modules/spring-data-jpa/README.md b/persistence-modules/spring-data-jpa/README.md index 976a692699..739031ff5e 100644 --- a/persistence-modules/spring-data-jpa/README.md +++ b/persistence-modules/spring-data-jpa/README.md @@ -19,6 +19,7 @@ - [Sorting Query Results with Spring Data](https://www.baeldung.com/spring-data-sorting) - [INSERT Statement in JPA](https://www.baeldung.com/jpa-insert) - [Pagination and Sorting using Spring Data JPA](https://www.baeldung.com/spring-data-jpa-pagination-sorting) +- [Spring Data JPA Query by Example](https://www.baeldung.com/spring-data-query-by-example) ### Eclipse Config After importing the project into Eclipse, you may see the following error: diff --git a/spring-5-reactive-oauth/README.md b/spring-5-reactive-oauth/README.md index 0f27cf5d20..ec5176670b 100644 --- a/spring-5-reactive-oauth/README.md +++ b/spring-5-reactive-oauth/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [Spring Security OAuth Login with WebFlux](https://www.baeldung.com/spring-oauth-login-webflux) +- [Spring WebClient and OAuth2 Support](https://www.baeldung.com/spring-webclient-oauth2) diff --git a/spring-boot-bootstrap/README.md b/spring-boot-bootstrap/README.md index 76b977c129..2186aa8fec 100644 --- a/spring-boot-bootstrap/README.md +++ b/spring-boot-bootstrap/README.md @@ -5,3 +5,4 @@ - [Deploying a Spring Boot Application to Cloud Foundry](https://www.baeldung.com/spring-boot-app-deploy-to-cloud-foundry) - [Deploy a Spring Boot Application to Google App Engine](https://www.baeldung.com/spring-boot-google-app-engine) - [Deploy a Spring Boot Application to OpenShift](https://www.baeldung.com/spring-boot-deploy-openshift) +- [Deploy a Spring Boot Application to AWS Beanstalk](https://www.baeldung.com/spring-boot-deploy-aws-beanstalk) diff --git a/spring-boot-mvc/README.md b/spring-boot-mvc/README.md index bf32e4fc7c..0e1ac5a8ce 100644 --- a/spring-boot-mvc/README.md +++ b/spring-boot-mvc/README.md @@ -9,4 +9,5 @@ - [Display RSS Feed with Spring MVC](http://www.baeldung.com/spring-mvc-rss-feed) - [A Controller, Service and DAO Example with Spring Boot and JSF](https://www.baeldung.com/jsf-spring-boot-controller-service-dao) - [Cache Eviction in Spring Boot](https://www.baeldung.com/spring-boot-evict-cache) -- [Setting Up Swagger 2 with a Spring REST API](http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api) \ No newline at end of file +- [Setting Up Swagger 2 with a Spring REST API](http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api) +- [Conditionally Enable Scheduled Jobs in Spring](https://www.baeldung.com/spring-scheduled-enabled-conditionally) diff --git a/spring-core/README.md b/spring-core/README.md index e5c359c11b..dcc15a4cb9 100644 --- a/spring-core/README.md +++ b/spring-core/README.md @@ -22,3 +22,4 @@ - [Spring Application Context Events](https://www.baeldung.com/spring-context-events) - [Unsatisfied Dependency in Spring](https://www.baeldung.com/spring-unsatisfied-dependency) - [What is a Spring Bean?](https://www.baeldung.com/spring-bean) +- [Spring PostConstruct and PreDestroy Annotations](https://www.baeldung.com/spring-postconstruct-predestroy) diff --git a/spring-core/src/main/java/com/baeldung/di/spring/Account.java b/spring-core/src/main/java/com/baeldung/di/spring/Account.java new file mode 100644 index 0000000000..6d9883bda5 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/di/spring/Account.java @@ -0,0 +1,27 @@ +package com.baeldung.di.spring; + +import org.springframework.stereotype.Component; + +@Component +public class Account { + + private String accountNumber; + private String type; + + public String getAccountNumber() { + return accountNumber; + } + + public void setAccountNumber(String accountNumber) { + this.accountNumber = accountNumber; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + +} diff --git a/spring-core/src/main/java/com/baeldung/di/spring/AccountService.java b/spring-core/src/main/java/com/baeldung/di/spring/AccountService.java new file mode 100644 index 0000000000..75ba6bb3eb --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/di/spring/AccountService.java @@ -0,0 +1,5 @@ +package com.baeldung.di.spring; + +public interface AccountService { + +} diff --git a/spring-core/src/main/java/com/baeldung/di/spring/AccountServiceImpl.java b/spring-core/src/main/java/com/baeldung/di/spring/AccountServiceImpl.java new file mode 100644 index 0000000000..4a4baf7d92 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/di/spring/AccountServiceImpl.java @@ -0,0 +1,8 @@ +package com.baeldung.di.spring; + +import org.springframework.stereotype.Component; + +@Component +public class AccountServiceImpl implements AccountService { + +} diff --git a/spring-core/src/main/java/com/baeldung/di/spring/AudioBookService.java b/spring-core/src/main/java/com/baeldung/di/spring/AudioBookService.java new file mode 100644 index 0000000000..c82e5ed282 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/di/spring/AudioBookService.java @@ -0,0 +1,5 @@ +package com.baeldung.di.spring; + +public interface AudioBookService { + +} diff --git a/spring-core/src/main/java/com/baeldung/di/spring/AudioBookServiceImpl.java b/spring-core/src/main/java/com/baeldung/di/spring/AudioBookServiceImpl.java new file mode 100644 index 0000000000..53a544b65a --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/di/spring/AudioBookServiceImpl.java @@ -0,0 +1,5 @@ +package com.baeldung.di.spring; + +public class AudioBookServiceImpl implements AudioBookService { + +} diff --git a/spring-core/src/main/java/com/baeldung/di/spring/AuthorService.java b/spring-core/src/main/java/com/baeldung/di/spring/AuthorService.java new file mode 100644 index 0000000000..cfb525ddf9 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/di/spring/AuthorService.java @@ -0,0 +1,5 @@ +package com.baeldung.di.spring; + +public interface AuthorService { + +} diff --git a/spring-core/src/main/java/com/baeldung/di/spring/AuthorServiceImpl.java b/spring-core/src/main/java/com/baeldung/di/spring/AuthorServiceImpl.java new file mode 100644 index 0000000000..007eb29930 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/di/spring/AuthorServiceImpl.java @@ -0,0 +1,5 @@ +package com.baeldung.di.spring; + +public class AuthorServiceImpl implements AuthorService { + +} diff --git a/spring-core/src/main/java/com/baeldung/di/spring/BookService.java b/spring-core/src/main/java/com/baeldung/di/spring/BookService.java new file mode 100644 index 0000000000..8e693e687d --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/di/spring/BookService.java @@ -0,0 +1,5 @@ +package com.baeldung.di.spring; + +public interface BookService { + +} diff --git a/spring-core/src/main/java/com/baeldung/di/spring/BookServiceImpl.java b/spring-core/src/main/java/com/baeldung/di/spring/BookServiceImpl.java new file mode 100644 index 0000000000..b4ea602234 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/di/spring/BookServiceImpl.java @@ -0,0 +1,10 @@ +package com.baeldung.di.spring; + +import org.springframework.beans.factory.annotation.Autowired; + +public class BookServiceImpl implements BookService { + + @Autowired(required = false) + private AuthorService authorService; + +} diff --git a/spring-core/src/main/java/com/baeldung/di/spring/Foo.java b/spring-core/src/main/java/com/baeldung/di/spring/Foo.java new file mode 100644 index 0000000000..9d9b5d0888 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/di/spring/Foo.java @@ -0,0 +1,4 @@ +package com.baeldung.di.spring; + +public class Foo { +} diff --git a/spring-core/src/main/java/com/baeldung/di/spring/FooProcessor.java b/spring-core/src/main/java/com/baeldung/di/spring/FooProcessor.java new file mode 100644 index 0000000000..9baaaef7a3 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/di/spring/FooProcessor.java @@ -0,0 +1,6 @@ +package com.baeldung.di.spring; + +public class FooProcessor { + + private Foo foo; +} \ No newline at end of file diff --git a/spring-core/src/main/java/com/baeldung/di/spring/PersonDao.java b/spring-core/src/main/java/com/baeldung/di/spring/PersonDao.java new file mode 100644 index 0000000000..8dde7ed1e0 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/di/spring/PersonDao.java @@ -0,0 +1,5 @@ +package com.baeldung.di.spring; + +public interface PersonDao { + +} diff --git a/spring-core/src/main/java/com/baeldung/di/spring/PersonDaoImpl.java b/spring-core/src/main/java/com/baeldung/di/spring/PersonDaoImpl.java new file mode 100644 index 0000000000..efcc2e0f21 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/di/spring/PersonDaoImpl.java @@ -0,0 +1,8 @@ +package com.baeldung.di.spring; + +import org.springframework.stereotype.Component; + +@Component +public class PersonDaoImpl implements PersonDao { + +} \ No newline at end of file diff --git a/spring-core/src/main/java/com/baeldung/di/spring/SpringBeansConfig.java b/spring-core/src/main/java/com/baeldung/di/spring/SpringBeansConfig.java new file mode 100644 index 0000000000..4cb6943fc9 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/di/spring/SpringBeansConfig.java @@ -0,0 +1,14 @@ +package com.baeldung.di.spring; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SpringBeansConfig { + + @Bean + public AudioBookService audioBookServiceGenerator() { + return new AudioBookServiceImpl(); + } + +} diff --git a/spring-core/src/main/java/com/baeldung/di/spring/SpringMainConfig.java b/spring-core/src/main/java/com/baeldung/di/spring/SpringMainConfig.java new file mode 100644 index 0000000000..75066fd539 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/di/spring/SpringMainConfig.java @@ -0,0 +1,18 @@ +package com.baeldung.di.spring; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +@Configuration +@Import({ SpringBeansConfig.class }) +@ComponentScan("com.baeldung.di.spring") +public class SpringMainConfig { + + @Bean + public BookService bookServiceGenerator() { + return new BookServiceImpl(); + } + +} diff --git a/spring-core/src/main/java/com/baeldung/di/spring/SpringPersonService.java b/spring-core/src/main/java/com/baeldung/di/spring/SpringPersonService.java new file mode 100644 index 0000000000..b85c749982 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/di/spring/SpringPersonService.java @@ -0,0 +1,20 @@ +package com.baeldung.di.spring; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class SpringPersonService { + + @Autowired + private PersonDao personDao; + + public PersonDao getPersonDao() { + return personDao; + } + + public void setPersonDao(PersonDao personDao) { + this.personDao = personDao; + } + +} diff --git a/spring-core/src/main/java/com/baeldung/di/spring/UserService.java b/spring-core/src/main/java/com/baeldung/di/spring/UserService.java new file mode 100644 index 0000000000..330d7f7448 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/di/spring/UserService.java @@ -0,0 +1,20 @@ +package com.baeldung.di.spring; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class UserService { + + @Autowired + private AccountService accountService; + + public AccountService getAccountService() { + return accountService; + } + + public void setAccountService(AccountService accountService) { + this.accountService = accountService; + } + +} diff --git a/spring-core/src/test/java/com/baeldung/di/spring/SpringUnitTest.java b/spring-core/src/test/java/com/baeldung/di/spring/SpringUnitTest.java new file mode 100644 index 0000000000..7df8dfac89 --- /dev/null +++ b/spring-core/src/test/java/com/baeldung/di/spring/SpringUnitTest.java @@ -0,0 +1,57 @@ +package com.baeldung.di.spring; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = { SpringMainConfig.class }) +public class SpringUnitTest { + @Autowired + ApplicationContext context; + + @Test + public void givenAccountServiceAutowiredToUserService_WhenGetAccountServiceInvoked_ThenReturnValueIsNotNull() { + UserService userService = context.getBean(UserService.class); + assertNotNull(userService.getAccountService()); + } + + @Test + public void givenBookServiceIsRegisteredAsBeanInContext_WhenBookServiceIsRetrievedFromContext_ThenReturnValueIsNotNull() { + BookService bookService = context.getBean(BookService.class); + assertNotNull(bookService); + } + + @Test + public void givenBookServiceIsRegisteredAsBeanInContextByOverridingAudioBookService_WhenAudioBookServiceIsRetrievedFromContext_ThenNoSuchBeanDefinitionExceptionIsThrown() { + BookService bookService = context.getBean(BookService.class); + assertNotNull(bookService); + AudioBookService audioBookService = context.getBean(AudioBookService.class); + assertNotNull(audioBookService); + } + + @Test + public void givenAuthorServiceAutowiredToBookServiceAsOptionalDependency_WhenBookServiceIsRetrievedFromContext_ThenNoSuchBeanDefinitionExceptionIsNotThrown() { + BookService bookService = context.getBean(BookService.class); + assertNotNull(bookService); + } + + @Test + public void givenSpringPersonServiceConstructorAnnotatedByAutowired_WhenSpringPersonServiceIsRetrievedFromContext_ThenInstanceWillBeCreatedFromTheConstructor() { + SpringPersonService personService = context.getBean(SpringPersonService.class); + assertNotNull(personService); + } + + @Test + public void givenPersonDaoAutowiredToSpringPersonServiceBySetterInjection_WhenSpringPersonServiceRetrievedFromContext_ThenPersonDaoInitializedByTheSetter() { + SpringPersonService personService = context.getBean(SpringPersonService.class); + assertNotNull(personService); + assertNotNull(personService.getPersonDao()); + } + +} diff --git a/spring-security-mvc-jsonview/src/main/java/com/baeldung/spring/SecurityJsonViewControllerAdvice.java b/spring-security-mvc-jsonview/src/main/java/com/baeldung/spring/SecurityJsonViewControllerAdvice.java index 66c7207e91..d6d022a110 100644 --- a/spring-security-mvc-jsonview/src/main/java/com/baeldung/spring/SecurityJsonViewControllerAdvice.java +++ b/spring-security-mvc-jsonview/src/main/java/com/baeldung/spring/SecurityJsonViewControllerAdvice.java @@ -31,6 +31,7 @@ public class SecurityJsonViewControllerAdvice extends AbstractMappingJacksonResp .collect(Collectors.toList()); if (jsonViews.size() == 1) { bodyContainer.setSerializationView(jsonViews.get(0)); + return; } throw new IllegalArgumentException("Ambiguous @JsonView declaration for roles "+ authorities.stream().map(GrantedAuthority::getAuthority).collect(Collectors.joining(","))); } diff --git a/testing-modules/junit-5/README.md b/testing-modules/junit-5/README.md index 1fbd7a4a5e..4ed01e7fa9 100644 --- a/testing-modules/junit-5/README.md +++ b/testing-modules/junit-5/README.md @@ -16,3 +16,4 @@ - [Running JUnit Tests Programmatically, from a Java Application](https://www.baeldung.com/junit-tests-run-programmatically-from-java) - [Testing an Abstract Class With JUnit](https://www.baeldung.com/junit-test-abstract-class) - [A Quick JUnit vs TestNG Comparison](http://www.baeldung.com/junit-vs-testng) +- [Guide to JUnit 5 Parameterized Tests](https://www.baeldung.com/parameterized-tests-junit-5)