Posts

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","*"); } }; }

Java Interview Coding Questions:

1) How To Reverse a String without using reverse method:     public class Reverse {     public static void main ( String [] args ) {         String str = "STRING" ;         char [] chr = str . toCharArray ();         for ( int i = chr . length - 1 ; i >= 0 ; i --) {             System . out . print ( chr [ i ]);         }             } }   2) Swap two numbers without using third variable:  public class Swap {         public static void main ( String [] args ) {         int a = 11 ;         int b = 12 ;         //logic         b = b - a ;         a = a + b ;         b = a - b ;         System . out . println ( "value of a is " + a ); ...

Data Structure

Image
Data Structures: A data structure is a particular way of organizing data in a computer so that it can be used effectively. The idea is to reduce the space and time complexities of different tasks. Below is an overview of some popular linear data structures. 1. Array 2. Linked List 3. Stack 4. Queue Array   The array is a data structure used to store homogeneous elements at contiguous locations. The size of an array must be provided before storing data.  Example:  For example, let us say, we want to store marks of all students in a class, we can use an array to store them. This helps in reducing the use of a number of variables as we don’t need to create a separate variable for marks of every subject. All marks can be accessed by simply traversing the array.  Linked List   A linked list is a linear data structure (like arrays) where each element is a separate object. Each element (that is node) of a list is comprised of two items – the data and a reference to th...