Posts

Showing posts from August, 2020

Aggregate function with spring data

Image
I was working on a small project. Requirement was different in term of object mapping. There is simple way to map  java object with database table. Aggregate function in query is not mapped with entity class. We don't have direct mapping attribute in JPA annotation to map aggregate function with entity class. Spring data support this using interface. In ORM query we use aggregate function e.g. count , sum etc. the output of these aggregate function cannot directly map with the Entity class. To collect the outcome of aggregate methods. We need to map using interface in java and provide the Interface class with mapping method.      public List<ITeacherReport> getTeacherReport(String teacherName); Our requirement is to count solved question per month by teacher from answer table. We have below environment configuration. Thymeleaf (for view,  this is template engine) JDK 1.8 Maven Springboot framework  MySql  for database operation Open the start....

Why can't we override System class methods in Java

Image
Below is a link to the source code of the system class of Java's LANG package. Which I have taken from the internet. http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/cf44386c8fe3/src/share/classes/java/lang/System.java There are two main points 1. The system class is a final class. It cannot be extended. If we are declaring someone as a finalist then it means that it will not be expanded further. You are in a situation from which you should not move forward. 2. Perhaps you never tried to look at the System class. If you would have seen by opening the system class, then you would know that all its methods are static. Now you know about the static method, then you will also know that these methods will be loaded with the class. Static methods  are common to all object of same class. If a method is static, it cannot be overridden. I am assuming here that you know to override a method of  class, S...