Merge remote-tracking branch 'upstream/master' into BAEL_4302
This commit is contained in:
@@ -8,7 +8,7 @@ This module contains articles about Java 11 core features
|
||||
- [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)
|
||||
- [Exploring the New HTTP Client in Java 9 and 11](https://www.baeldung.com/java-9-http-client)
|
||||
- [Exploring the New HTTP Client in Java](https://www.baeldung.com/java-9-http-client)
|
||||
- [An Introduction to Epsilon GC: A No-Op Experimental Garbage Collector](https://www.baeldung.com/jvm-epsilon-gc-garbage-collector)
|
||||
- [Guide to jlink](https://www.baeldung.com/jlink)
|
||||
- [Negate a Predicate Method Reference with Java 11](https://www.baeldung.com/java-negate-predicate-method-reference)
|
||||
|
||||
+6
-3
@@ -1,12 +1,15 @@
|
||||
package com.baeldung.modules.main;
|
||||
|
||||
import com.baeldung.modules.hello.HelloInterface;
|
||||
import com.baeldung.modules.hello.HelloModules;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
public class MainApp {
|
||||
public static void main(String[] args) {
|
||||
HelloModules.doSomething();
|
||||
|
||||
HelloModules module = new HelloModules();
|
||||
module.sayHello();
|
||||
|
||||
Iterable<HelloInterface> services = ServiceLoader.load(HelloInterface.class);
|
||||
HelloInterface service = services.iterator().next();
|
||||
service.sayHello();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,4 @@ This module contains articles about core Java features that have been introduced
|
||||
- [Java 9 Platform Logging API](https://www.baeldung.com/java-9-logging-api)
|
||||
- [Java 9 Reactive Streams](https://www.baeldung.com/java-9-reactive-streams)
|
||||
- [Multi-Release JAR Files with Maven](https://www.baeldung.com/maven-multi-release-jars)
|
||||
- [The Difference between RxJava API and the Java 9 Flow API](https://www.baeldung.com/rxjava-vs-java-flow-api)
|
||||
|
||||
@@ -9,3 +9,4 @@ This module contains articles about Java 9 core features
|
||||
- [Iterate Through a Range of Dates in Java](https://www.baeldung.com/java-iterate-date-range)
|
||||
- [Initialize a HashMap in Java](https://www.baeldung.com/java-initialize-hashmap)
|
||||
- [Immutable ArrayList in Java](https://www.baeldung.com/java-immutable-list)
|
||||
- [Easy Ways to Write a Java InputStream to an OutputStream](https://www.baeldung.com/java-inputstream-to-outputstream)
|
||||
|
||||
@@ -5,4 +5,4 @@ This module contains complete guides about arrays in Java
|
||||
### Relevant Articles:
|
||||
- [Arrays in Java: A Reference Guide](https://www.baeldung.com/java-arrays-guide)
|
||||
- [Guide to the java.util.Arrays Class](https://www.baeldung.com/java-util-arrays)
|
||||
- [What is [Ljava.lang.Object;?]](https://www.baeldung.com/java-tostring-array)
|
||||
- [What is \[Ljava.lang.Object;?](https://www.baeldung.com/java-tostring-array)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
## Core Java Collections Cookbooks and Examples
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Time Comparison of Arrays.sort(Object[]) and Arrays.sort(int[])](https://www.baeldung.com/arrays-sortobject-vs-sortint)
|
||||
- [Java ArrayList vs Vector](https://www.baeldung.com/java-arraylist-vs-vector)
|
||||
- [Differences Between HashMap and Hashtable](https://www.baeldung.com/hashmap-hashtable-differences)
|
||||
@@ -10,3 +11,4 @@
|
||||
- [Performance of contains() in a HashSet vs ArrayList](https://www.baeldung.com/java-hashset-arraylist-contains-performance)
|
||||
- [Fail-Safe Iterator vs Fail-Fast Iterator](https://www.baeldung.com/java-fail-safe-vs-fail-fast-iterator)
|
||||
- [Quick Guide to the Java Stack](https://www.baeldung.com/java-stack)
|
||||
- [Convert an Array of Primitives to a List](https://www.baeldung.com/java-primitive-array-to-list)
|
||||
|
||||
@@ -15,4 +15,5 @@ This module contains articles about advanced topics about multithreading with co
|
||||
- [The ABA Problem in Concurrency](https://www.baeldung.com/cs/aba-concurrency)
|
||||
- [Introduction to Lock-Free Data Structures](https://www.baeldung.com/lock-free-programming)
|
||||
- [Introduction to Exchanger in Java](https://www.baeldung.com/java-exchanger)
|
||||
- [Why Not To Start A Thread In The Constructor?](https://www.baeldung.com/java-thread-constructor)
|
||||
- [[<-- previous]](/core-java-modules/core-java-concurrency-advanced-2)
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
This module contains articles about basic Java concurrency
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [How to Delay Code Execution in Java](https://www.baeldung.com/java-delay-code-execution)
|
||||
- [wait and notify() Methods in Java](https://www.baeldung.com/java-wait-notify)
|
||||
- [Difference Between Wait and Sleep in Java](https://www.baeldung.com/java-wait-and-sleep)
|
||||
- [Guide to the Synchronized Keyword in Java](https://www.baeldung.com/java-synchronized)
|
||||
- [Life Cycle of a Thread in Java](https://www.baeldung.com/java-thread-lifecycle)
|
||||
- [Guide to AtomicMarkableReference](https://www.baeldung.com/java-atomicmarkablereference)
|
||||
- [Why are Local Variables Thread-Safe in Java](https://www.baeldung.com/java-local-variables-thread-safe)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-concurrency-basic)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
This module contains articles about date operations in Java.
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Get the Current Date Prior to Java 8](https://www.baeldung.com/java-get-the-current-date-legacy)
|
||||
- [Skipping Weekends While Adding Days to LocalDate in Java 8](https://www.baeldung.com/java-localdate-add-days-skip-weekends)
|
||||
- [Checking If Two Java Dates Are on the Same Day](https://www.baeldung.com/java-check-two-dates-on-same-day)
|
||||
@@ -9,4 +10,5 @@ This module contains articles about date operations in Java.
|
||||
- [How to Set the JVM Time Zone](https://www.baeldung.com/java-jvm-time-zone)
|
||||
- [How to determine day of week by passing specific date in Java?](https://www.baeldung.com/java-get-day-of-week)
|
||||
- [Finding Leap Years in Java](https://www.baeldung.com/java-leap-year)
|
||||
- [Getting the Week Number From Any Date](https://www.baeldung.com/java-get-week-number)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-date-operations-1)
|
||||
|
||||
@@ -12,3 +12,5 @@ This module contains articles about core java exceptions
|
||||
- [Java – Try with Resources](https://www.baeldung.com/java-try-with-resources)
|
||||
- [Java Global Exception Handler](https://www.baeldung.com/java-global-exception-handler)
|
||||
- [How to Find an Exception’s Root Cause in Java](https://www.baeldung.com/java-exception-root-cause)
|
||||
- [Java IOException “Too many open files”](https://www.baeldung.com/java-too-many-open-files)
|
||||
- [When Does Java Throw the ExceptionInInitializerError?](https://www.baeldung.com/java-exceptionininitializererror)
|
||||
|
||||
@@ -13,4 +13,4 @@ This module contains articles about core Java input and output (IO)
|
||||
- [How to Copy a File with Java](https://www.baeldung.com/java-copy-file)
|
||||
- [Create a Directory in Java](https://www.baeldung.com/java-create-directory)
|
||||
- [Java IO vs NIO](https://www.baeldung.com/java-io-vs-nio)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-io)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-io)[[More -->]](/core-java-modules/core-java-io-3)
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
## Core Java IO
|
||||
|
||||
This module contains articles about core Java input and output (IO)
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Java – Create a File](https://www.baeldung.com/java-how-to-create-a-file)
|
||||
- [Check If a Directory Is Empty in Java](https://www.baeldung.com/java-check-empty-directory)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-io-2)
|
||||
@@ -0,0 +1,86 @@
|
||||
<?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>
|
||||
<artifactId>core-java-io-3</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-io-3</name>
|
||||
<packaging>jar</packaging>
|
||||
<parent>
|
||||
<groupId>com.baeldung.core-java-modules</groupId>
|
||||
<artifactId>core-java-modules</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<!-- utils -->
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<!-- utils -->
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
<!-- logging -->
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
<!-- test scoped -->
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.github.tomakehurst/wiremock -->
|
||||
<dependency>
|
||||
<groupId>com.github.tomakehurst</groupId>
|
||||
<artifactId>wiremock</artifactId>
|
||||
<version>${wiremock.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>core-java-io-3</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>${maven-javadoc-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
||||
<wiremock.version>2.26.3</wiremock.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package com.baeldung.createfile;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class CreateFileUnitTest {
|
||||
|
||||
private final String FILE_NAME = "src/test/resources/fileToCreate.txt";
|
||||
|
||||
@AfterEach
|
||||
@BeforeEach
|
||||
public void cleanUpFiles() {
|
||||
File targetFile = new File(FILE_NAME);
|
||||
targetFile.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenUsingNio_whenCreatingFile_thenCorrect() throws IOException {
|
||||
Path newFilePath = Paths.get(FILE_NAME);
|
||||
Files.createFile(newFilePath);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenUsingFile_whenCreatingFile_thenCorrect() throws IOException {
|
||||
File newFile = new File(FILE_NAME);
|
||||
boolean success = newFile.createNewFile();
|
||||
assertTrue(success);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenUsingGuava_whenCreatingFile_thenCorrect() throws IOException {
|
||||
com.google.common.io.Files.touch(new File(FILE_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenUsingCommonsIo_whenCreatingFile_thenCorrect() throws IOException {
|
||||
FileUtils.touch(new File(FILE_NAME));
|
||||
}
|
||||
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package com.baeldung.emptiness;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class DirectoryEmptinessUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenPath_whenInvalid_thenReturnsFalse() throws IOException {
|
||||
assertThat(isEmpty(Paths.get("invalid-addr"))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenPath_whenNotDirectory_thenReturnsFalse() throws IOException {
|
||||
Path aFile = Paths.get(getClass().getResource("/notDir.txt").getPath());
|
||||
assertThat(isEmpty(aFile)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenPath_whenNotEmptyDir_thenReturnsFalse() throws IOException {
|
||||
Path currentDir = new File("").toPath().toAbsolutePath();
|
||||
assertThat(isEmpty(currentDir)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenPath_whenIsEmpty_thenReturnsTrue() throws Exception {
|
||||
Path path = Files.createTempDirectory("baeldung-empty");
|
||||
assertThat(isEmpty(path)).isTrue();
|
||||
}
|
||||
|
||||
private static boolean isEmpty(Path path) throws IOException {
|
||||
if (Files.isDirectory(path)) {
|
||||
try (DirectoryStream<Path> directory = Files.newDirectoryStream(path)) {
|
||||
return !directory.iterator().hasNext();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isEmpty2(Path path) throws IOException {
|
||||
if (Files.isDirectory(path)) {
|
||||
try (Stream<Path> entries = Files.list(path)) {
|
||||
return !entries.findFirst().isPresent();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isEmptyInefficient(Path path) {
|
||||
return path.toFile().listFiles().length == 0;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ This module contains articles about core Java input/output(IO) APIs.
|
||||
- [A Guide to the Java FileReader Class](https://www.baeldung.com/java-filereader)
|
||||
- [The Java File Class](https://www.baeldung.com/java-io-file)
|
||||
- [Java FileWriter](https://www.baeldung.com/java-filewriter)
|
||||
- [Differences Between the Java WatchService API and the Apache Commons IO Monitor Library](https://www.baeldung.com/java-watchservice-vs-apache-commons-io-monitor-library)
|
||||
- [Comparing getPath(), getAbsolutePath(), and getCanonicalPath() in Java](https://www.baeldung.com/java-path)
|
||||
- [Quick Use of FilenameFilter](https://www.baeldung.com/java-filename-filter)
|
||||
- [Guide to BufferedReader](https://www.baeldung.com/java-buffered-reader)
|
||||
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
package com.baeldung.dirmonitoring;
|
||||
|
||||
import org.apache.commons.io.monitor.FileAlterationListener;
|
||||
import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
|
||||
import org.apache.commons.io.monitor.FileAlterationMonitor;
|
||||
import org.apache.commons.io.monitor.FileAlterationObserver;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class DirectoryMonitoringExample {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DirectoryMonitoringExample.class);
|
||||
|
||||
private static final int POLL_INTERVAL = 500;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
FileAlterationObserver observer = new FileAlterationObserver(System.getProperty("user.home"));
|
||||
FileAlterationMonitor monitor = new FileAlterationMonitor(POLL_INTERVAL);
|
||||
FileAlterationListener listener = new FileAlterationListenerAdaptor() {
|
||||
@Override
|
||||
public void onFileCreate(File file) {
|
||||
LOG.debug("File: " + file.getName() + " created");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileDelete(File file) {
|
||||
LOG.debug("File: " + file.getName() + " deleted");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileChange(File file) {
|
||||
LOG.debug("File: " + file.getName() + " changed");
|
||||
}
|
||||
};
|
||||
observer.addListener(listener);
|
||||
monitor.addObserver(observer);
|
||||
monitor.start();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,4 +8,6 @@ This module contains articles about working with the Java Virtual Machine (JVM).
|
||||
- [Measuring Object Sizes in the JVM](https://www.baeldung.com/jvm-measuring-object-sizes)
|
||||
- [Adding Shutdown Hooks for JVM Applications](https://www.baeldung.com/jvm-shutdown-hooks)
|
||||
- [boolean and boolean[] Memory Layout in the JVM](https://www.baeldung.com/jvm-boolean-memory-layout)
|
||||
- More articles: [[<-- prev]](/core-java-modules/core-java-jvm)
|
||||
- [Where Is the Array Length Stored in JVM?](https://www.baeldung.com/java-jvm-array-length)
|
||||
- [Memory Address of Objects in Java](https://www.baeldung.com/java-object-memory-address)
|
||||
- More articles: [[<-- prev]](/core-java-modules/core-java-jvm)
|
||||
|
||||
@@ -2,4 +2,6 @@
|
||||
|
||||
This module contains articles about core features in the Java language
|
||||
|
||||
- [Class.isInstance vs Class.isAssignableFrom](https://www.baeldung.com/java-isinstance-isassignablefrom)
|
||||
- [Converting a Java String Into a Boolean](https://www.baeldung.com/java-string-to-boolean)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-lang-2)
|
||||
|
||||
@@ -39,4 +39,4 @@
|
||||
<assertj.version>3.12.2</assertj.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.staticvariables;
|
||||
|
||||
public class StaticVariableDemo {
|
||||
public static int i;
|
||||
public static int j = 20;
|
||||
public static int z;
|
||||
|
||||
static {
|
||||
z = 30;
|
||||
a = 40;
|
||||
}
|
||||
|
||||
public static int a = 50;
|
||||
|
||||
public static final int b = 100;
|
||||
|
||||
public StaticVariableDemo() {
|
||||
}
|
||||
|
||||
static class Nested {
|
||||
public static String nestedClassStaticVariable = "test";
|
||||
}
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
package com.baeldung.staticvariables;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class StaticVariableUnitTest {
|
||||
|
||||
@Test
|
||||
public void initializeStaticVariable_checkAssignedValues() {
|
||||
|
||||
try {
|
||||
Class<?> staticVariableDemo = this.getClass()
|
||||
.getClassLoader()
|
||||
.loadClass("com.baeldung.staticvariables.StaticVariableDemo");
|
||||
|
||||
Field field1 = staticVariableDemo.getField("i");
|
||||
|
||||
assertThat(field1.getInt(staticVariableDemo)).isEqualTo(0);
|
||||
|
||||
Field field2 = staticVariableDemo.getField("j");
|
||||
|
||||
assertThat(field2.getInt(staticVariableDemo)).isEqualTo(20);
|
||||
|
||||
} catch (ClassNotFoundException | NoSuchFieldException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initializeStaticVariable_checkStaticBlock() {
|
||||
|
||||
try {
|
||||
Class<?> staticVariableDemo = this.getClass()
|
||||
.getClassLoader()
|
||||
.loadClass("com.baeldung.staticvariables.StaticVariableDemo");
|
||||
|
||||
Field field1 = staticVariableDemo.getField("z");
|
||||
|
||||
assertThat(field1.getInt(staticVariableDemo)).isEqualTo(30);
|
||||
|
||||
Field field2 = staticVariableDemo.getField("a");
|
||||
|
||||
assertThat(field2.getInt(staticVariableDemo)).isEqualTo(50);
|
||||
|
||||
} catch (ClassNotFoundException | NoSuchFieldException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initializeStaticVariable_checkFinalValues() {
|
||||
|
||||
try {
|
||||
Class<?> staticVariableDemo = this.getClass()
|
||||
.getClassLoader()
|
||||
.loadClass("com.baeldung.staticvariables.StaticVariableDemo");
|
||||
|
||||
Field field1 = staticVariableDemo.getField("b");
|
||||
|
||||
assertThat(field1.getInt(staticVariableDemo)).isEqualTo(100);
|
||||
|
||||
} catch (ClassNotFoundException | NoSuchFieldException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initializeStaticVariable_checkInnerClassValues() {
|
||||
|
||||
try {
|
||||
Class<?> staticVariableDemo = this.getClass()
|
||||
.getClassLoader()
|
||||
.loadClass("com.baeldung.staticvariables.StaticVariableDemo");
|
||||
|
||||
Class<?>[] nestedClasses = staticVariableDemo.getClasses();
|
||||
|
||||
for (Class<?> nestedClass : nestedClasses) {
|
||||
if (nestedClass.getName()
|
||||
.equals("Nested")) {
|
||||
|
||||
Field field1 = nestedClass.getField("nestedClassStaticVariable");
|
||||
assertThat(field1.get(nestedClass)).isEqualTo("test");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (ClassNotFoundException | NoSuchFieldException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,9 @@
|
||||
This module contains articles about methods in Java
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Methods in Java](https://www.baeldung.com/java-methods)
|
||||
- [Method Overloading and Overriding in Java](https://www.baeldung.com/java-method-overload-override)
|
||||
- [Java equals() and hashCode() Contracts](https://www.baeldung.com/java-equals-hashcode-contracts)
|
||||
- [Guide to hashCode() in Java](https://www.baeldung.com/java-hashcode)
|
||||
- [The Covariant Return Type in Java](https://www.baeldung.com/java-covariant-return-type)
|
||||
|
||||
@@ -12,4 +12,5 @@ This module contains articles about networking in Java
|
||||
- [Authentication with HttpUrlConnection](https://www.baeldung.com/java-http-url-connection)
|
||||
- [Download a File from an URL in Java](https://www.baeldung.com/java-download-file)
|
||||
- [Handling java.net.ConnectException](https://www.baeldung.com/java-net-connectexception)
|
||||
- [Getting MAC addresses in Java](https://www.baeldung.com/java-mac-address)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-networking)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
### Relevant Articles:
|
||||
|
||||
- [Reading the Value of ‘private’ Fields from a Different Class in Java](https://www.baeldung.com/java-reflection-read-private-field-value)
|
||||
@@ -8,5 +8,4 @@
|
||||
- [Changing Annotation Parameters At Runtime](http://www.baeldung.com/java-reflection-change-annotation-params)
|
||||
- [Dynamic Proxies in Java](http://www.baeldung.com/java-dynamic-proxies)
|
||||
- [What Causes java.lang.reflect.InvocationTargetException?](https://www.baeldung.com/java-lang-reflect-invocationtargetexception)
|
||||
- [How to Find all Getters Returning Null](http://www.baeldung.com/java-getters-returning-null)
|
||||
- [How to Get a Name of a Method Being Executed?](http://www.baeldung.com/java-name-of-executing-method)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
## Core Java 8 Cookbooks and Examples
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [An Overview of Regular Expressions Performance in Java](https://www.baeldung.com/java-regex-performance)
|
||||
- [A Guide To Java Regular Expressions API](http://www.baeldung.com/regular-expressions-java)
|
||||
- [Guide to Escaping Characters in Java RegExps](http://www.baeldung.com/java-regexp-escape-char)
|
||||
@@ -11,3 +12,4 @@
|
||||
- [How to Use Regular Expressions to Replace Tokens in Strings](https://www.baeldung.com/java-regex-token-replacement)
|
||||
- [Regular Expressions \s and \s+ in Java](https://www.baeldung.com/java-regex-s-splus)
|
||||
- [Validate Phone Numbers With Java Regex](https://www.baeldung.com/java-regex-validate-phone-numbers)
|
||||
- [How to Count the Number of Matches for a Regex?](https://www.baeldung.com/java-count-regex-matches)
|
||||
|
||||
@@ -9,4 +9,5 @@ This module contains articles about core Java Security
|
||||
- [Hashing a Password in Java](https://www.baeldung.com/java-password-hashing)
|
||||
- [SHA-256 and SHA3-256 Hashing in Java](https://www.baeldung.com/sha-256-hashing-java)
|
||||
- [Checksums in Java](https://www.baeldung.com/java-checksums)
|
||||
- [How to Read PEM File to Get Public and Private Keys](https://www.baeldung.com/java-read-pem-file-keys)
|
||||
- More articles: [[<-- prev]](/core-java-modules/core-java-security)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
### Relevant Articles:
|
||||
|
||||
- [Version Comparison in Java](https://www.baeldung.com/java-comparing-versions)
|
||||
@@ -72,6 +72,7 @@
|
||||
|
||||
<module>core-java-io</module>
|
||||
<module>core-java-io-2</module>
|
||||
<module>core-java-io-3</module>
|
||||
<module>core-java-io-apis</module>
|
||||
<module>core-java-io-conversions</module>
|
||||
<module>core-java-io-conversions-2</module>
|
||||
|
||||
Reference in New Issue
Block a user