Get the Abstract Methods of a Class
With the Java Reflection API, we can isolate the abstract methods from a class via the following snippet of code: List abstractMethods = new ArrayList();Class clazz = Foo.class;Method[] methods =
With the Java Reflection API, we can isolate the abstract methods from a class via the following snippet of code: List abstractMethods = new ArrayList();Class clazz = Foo.class;Method[] methods =
Knowing the current flush mode can be done as follows: // via EntityManagerentityManager.getFlushMode();// in Hibernate JPA, via Session(entityManager.unwrap(Session.class)).getFlushMode();// starting with Hibernate 5.2(entityManager.unwrap(Session.class)).getHibernateFlushMode();
Java supports creating of ServerSocket(s) in more than one way. This is an important aspect of security. SSLServerSocketFactory is a secure way of achieving this. This ensures that the socket is
By default, Spring Boot uses HikariCP as the connection pool. Via the connection pool, we can disable the auto-commit mode. For example, the following setting disabled auto-commit mode from application.properties:
If em is the EntityManager, then the following query results will be cached: Query query = em .createQuery(“SELECT u FROM User u”); query.setHint(“eclipselink.cache-usage”, “CheckCacheThenDatabase”);
For formatting the SQL statements in a Spring Boot application, we can set hibernate.format_sql in the application.properties as follows: spring.jpa.properties.hibernate.format_sql= true
In order to join (combine) fix file paths we can use Path#resolve() and Path#resolveSibling():. // using Path#resolve()Path base1 = Paths.get(“D:/learning/books”); Path path1 = base1.resolve(“Java.pdf”);// using Path#resolveSibling()Path base2 = Paths.get(“D:/learning/books/Java.pdf”);Path path3
An approach for sorting a Java collection can rely on Collections.sort() method as in the following example: List names = new ArrayList(); names.add(“John”); names.add(“Alicia”); names.add(“Tom”); Collections.sort(names); // sort ascending by
Instructing Spring Boot to connect to a database can be done in application.properties via the JDBC URL, user and password as in the following example: spring.datasource.url=jdbc:mysql://localhost:3306/mydb?createDatabaseIfNotExist=truespring.datasource.username=rootspring.datasource.password=root