The best way to map @OneToOne


@OneToOneThe best approach to bidirectional @OneToOne is to use @MapsIdStudent entity@Entity@Data@Table(name = "students")public class Student implements Serializable {     @Id     @GeneratedValue     private Integer id;     private...

The best way to map @ManyToMany


@ManyToManyMany to many relationships can be easily mapped by creating another table using @JoinTable as follows.Student entity@Data@Table(name = "Student")@Entitypublic class Student implements Serializable {     @Id     @GeneratedValue(strategy = GenerationType.AUTO)...

How to avoid NullPointerException


java.lang.NullPointerExceptionWhen can it be thrown?According to the JavaDoc, the following scenarios can be found.Calling the instance method of a null object.Accessing or modifying the field of a null object.Taking the length of null as if it were an array.Accessing or modifying the slots of null...

Thread pool in Java


The Thread poolIntroductionExecutor implementations use thread pools.The thread pool is a collection of worker threads that are ready to serve.Creating new threads and manage them uses a big amount of data.Worker threads in the thread pool will help to reduce this overhead of creating threads.Tasks...

Java ExecutorService


Java ExecutorServiceIntroductionIf an application has few threads, it can be used threads very easily using the above methods.But if an application has many threads, it will be not easy to handle this.Executors can be used to avoid this complexity.The executor framework is a framework that can be...

Thread priority


Thread priorityEach thread has a priority.It starts from 1 to 10 and the highest priority is 10 while the lowest is 1.The default priority of the main thread is 5.If you set the thread priority out of 10, it will give a compile-time errorException in thread "main" java.lang.IllegalArgumentExcepti...

List vs Queue vs Set vs Map


 List vs Queue vs Set vs MapListQueueSetMapDuplicatesYesYesNoNo(Allow duplicate values not keys)OrderYesYesNoNoNull valuesYesPriority queue doesn't allow, but queue using LinkedList allows nullSingle nullSingle null key and many null valu...