Java tutorials with detailed examples
2024-04-01
To deserialize a JSON string to a Java object, we could use the FasterXML Jackson library.
2023-11-14
See this tutorial of creating a Java websocket server and a Java websocket client.
2023-09-10
Since Java 9, Java release a feature called Module. Module allows a jar to declare availability of packages and its dependencies of packages from other jars, thus reduce the chance of ClassNotFoundException and increase encapsulation.
2022-12-18
Exclude a particular class from a jar inside a war file using Gradle. This could be due to multiple versions of a library are included and we want to avoid the application to load the unwanted version but we don't want to exclude the whole jar.
2022-12-08
Exclude a particular class from a jar inside a war file using Maven. This could be due to multiple versions of a library are included and we want to avoid the application to load the unwanted version but we don't want to exclude the whole jar.
2022-07-30
Quicksort is a fast sorting algorithm, see the implementation in Java.
2022-07-20
Mergesort is a fast sorting algorithm, see the implementation in Java.
2022-03-30
Java annotation can be used to modify the behavior of a class, method or variable.
2022-02-25
In Java, for a method to accept any number(including zero) of arguments, we can use varargs which has the format myMethod(myType ... myArgumentName).
2022-02-02
Threads in Java runs independently. To synchronize between threads we could use the wait() and notify() function.
2022-01-28
There are 2 ways to create a thread. One is to extend the Thread class overriding the run() method. The other is to implement the Runnable interface also overriding the run() method.
2022-01-08
We could convert a date or time to a specific string format, and/or change the timezone, by using SimpleDateFormat.
2021-12-28
Using parallel stream allow running code in deparallel in a relatively simply way.
2021-11-14
We could use reflection to modify a field or call a method which is private of a class.
2021-11-14
Java Immutable class is, once the object is initiated, none of the fields can have its value changed.
2021-10-14
In Java, all the class are extending from the Object class and so inherited the equals and hashCode method. The equals method is used to determine whether 2 objects are the same, while hashCode is used to determine which bucket to put the object if hashing structure is used.
2021-09-30
In Java, Functional Interface is an interface with just one non-static abstract method, with an annotation @FunctionalInterface.
2021-09-20
If multiple threads are operating on a shared variable at the same time, and the operations are not atomic, the result would be unpredictable. In order to solve this problem, we could put synchronized blocks around the operations, to make sure only at most one thread could operate on the variable at one time.
2021-08-06
Both Comparable and Comparator can be used to compare the elements of the list, which allows you to sort the list with your own logic.
2021-08-06
The difference between checked and unchecked exception is that unchecked exception will not cause compile error even though it is not caught or not declared to be thrown.
2021-07-18
In a RESTful Spring Web Service, we can use FasterXML Jackson to serialize Java object back to JSON response.
2021-07-18
In a RESTful Spring Web Service, we can use FasterXML Jackson to deserialize JSON request to Java object.
2021-06-30
To serialize a Java object to a JSON string, we could use the FasterXML Jackson library.