Posts

Hibernate Interview Questions

  What is a Session in Hibernate? A session is an object that maintains the connection between Java object application and database. Session also has methods for storing, retrieving, modifying or deleting data from database using methods like persist(), load(), get(), update(), delete(), etc. Additionally, It has factory methods to return Query, Criteria, and Transaction objects. What is a SessionFactory? SessionFactory provides an instance of  Session . It is a factory class that gives the Session  objects  based on the configuration parameters in order to establish the connection to the database. As a good practice, the application generally has a single instance of SessionFactory. The internal state of a SessionFactory which includes metadata about ORM is immutable, i.e once the instance is created, it cannot be changed. What is the difference between first level cache and second level cache? Hibernate has 2 cache types. First level and second level cache for whic...

Working of HashMap in Java

Image
Working of HashMap in Java What is Hashing It is the process of converting an object into an integer value. The integer value helps in indexing and faster searches. What is HashMap HashMap is a part of the Java collection framework. It uses a technique called Hashing. It implements the map interface. It stores the data in the pair of Key and Value. HashMap contains an array of the nodes, and the node is represented as a class. It uses an array and LinkedList data structure internally for storing Key and Value. There are four fields in HashMap. Before understanding the internal working of HashMap, you must be aware of hashCode() and equals() method. equals():  It checks the equality of two objects. It compares the Key, whether they are equal or not. It is a method of the Object class. It can be overridden. If you override the equals() method, then it is mandatory to override the hashCode() method. hashCode():  This is the method of the object class. It returns the memory refere...

Java 8 Features

  Java 8 Features Oracle released a new version of Java as Java 8 in March 18, 2014. It was a revolutionary release of the Java for software development platform. It includes various upgrades to the Java programming, JVM, Tools and libraries. Java 8 Programming Language Enhancements Java 8 provides following features for Java Programming: Lambda expressions, Method references, Functional interfaces, Stream API, Default methods, Base64 Encode Decode, Static methods in interface, Optional class, Collectors class, ForEach() method, Nashorn JavaScript Engine, Parallel Array Sorting, Type and Repating Annotations, IO Enhancements, Concurrency Enhancements, JDBC Enhancements etc. Lambda Expressions Lambda expression helps us to write our code in functional style. It provides a clear and concise way to implement SAM interface(Single Abstract Method) by using an expression. It is very useful in collection library in which it helps to iterate, filter and extract data. Method References Java...

Postman form-data sending complex object with file

  @PostMapping(value = "/evaluate", produces = "application/json") public ResponseEntity<?> sendEvaluateForm( @RequestParam ( "client" ) String client, @RequestParam(value = "files", required = false) MultipartFile files) throws IOException { ObjectMapper mapper = new ObjectMapper (); Client clientobject = mapper.readValue(client, Client.class); return ResponseEntity.ok().build(); }

CORS issue - Response to preflight request doesn't pass access control check:

  I am using React with Spring JWT faced similar issue as blocked by CORS policy . added  http.cors()  in my SecurityConfigurer class to resolve @EnableWebSecurity public class SecurityConfigurer extends WebSecurityConfigurerAdapter { @Override protected void configure( HttpSecurity http) throws Exception { http.cors().and().csrf().disable()....... } } And Write some lines of inside Spring boot application: @Bean public WebMvcConfigurer configure() { return new WebMvcConfigurer() { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").allowedHeaders("Acces-Control-Allow-Origin","*"); } }; }