Skip to main content

Posts

Showing posts from March, 2018

Twelve Factor app development for Microservices

The Twelve (12) Factor app methodology is a list of principles for any Web Application or Software as a Service, and it is especially useful for microservices. This methodology can be applied to apps written in any programming language that use any combination of backing services(database, queue, memory cache, etc). 1. Code Base  - There should a dedicated code base per app. There should be a dedicated code base for each App, and multiple code bases can not use the same code base. If any code base is required by more than one application, separate that code into a separate repository, and inject that using dependency manager into the dependent apps. The same code base can be used to deploy the application to different environments like develop, stage, and production. 2.  Dependencies  - Explicitly declare and isolate dependencies. All the dependencies need to be explicitly declared, and should be available as part of the build process. The should not depend on any implic

Java Comparator Applications

Java Comparator is one of the favourite questions in Java Interviews. This concept looks deceptively simple, and slight variations of this could be asked in the interviews. 1) Write an AlphaNumeric Comparator in Java that sorts the given strings in the human readable     format.  e.g., file1, file2, file 3, file4, file 10 Not like the typical comparator file1, file10 2) Chained Comparator which can be used to join Multiple Comparators 3) Given a List of Employee Objects group the Objects such that all the employees are grouped by     Department and by Name. 4) Use Java 8 Style Comparators

Java Dynamic Programming

1) This class handles the Fibonacci Series Problem using Dynamic Programming, and Memoization 2) This class solves the Stair Case Problem by finding the Number of Jumps possible to the Top of the StairCase. 3) This class Solves the Coin Change problem using Dynamic Programming and Memoization

Data Structures - Strings

1) Find if a given First String is a SubSequence of a Second String 2) Find Max Occurring Frequency Character in  a String 3) Check if Sequence of Characters of Two Strings can become same by removal of a Character 4) Remove all Duplicate Words from a String 5) Find for a Given Two Strings, if one is the rotation of the Other. 6) Find if two Strings are K-Anagrams 7) Longest Common Subsequence where character occurs at least k times. 8) Find if the two given Strings are anagrams of Each Other. 9) Anagram SubString Search

Searching Algorithms

1) Binary Search Iterative Approach /**   *  */ package com . test . search ; /**   * @author Kiran   *  */ public class BinarySearchIterative { /** * @param args */ public static void main ( String [ ] args ) { BinarySearchIterative binarySearch = new BinarySearchIterative ( ) ; int [ ] elements = new int [ ] { 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 } ; int searchElement = 11   ; int start = 0 ; int end = 0 ; if ( elements ! = null ) { end =   ( elements . length ) ; } int elementIndex = binarySearch . doBinarySearchIterative ( elements , searchElement , start , end ) ; if ( elementIndex ! = - 1 ) { System . out . println ( " Found the searching element" + " at the Index of " + elementIndex ) ; } else { System . out . println ( " The element is Not" + "  found in the Array " ) ; } } /** * * @param elements * @param sea

Spring Boot Applications

1) Spring Boot Application integration with Kafka 2) Spring Boot Application integration with Redis 3) Spring Boot Application integration with CouchDB 4) Spring Boot Application Integration with Cassandra 5) Spring Boot Application with MongoDB

Java 8 new features

1) What are the new features in Java 8 2) Streams Interview Questions in Java 8 Print the elements of the  a Collection using Stream 3) Lamdas Interview Questions in Java 8 4) HashMap Interview Questions for Java 8

Gang of Four Design Patterns

Gang of Four(GOF) Design Patterns are divided in to 3 categories. Creational Design Patterns ( 5 Patterns ) AbstractFactory Builder Method Factory Method Prototype Singleton Singleton pattern is used when there is only one instance of the object need to be created per JVM instance. This pattern is used internally by the Connection Pooling to create the objects only on demand. Structural Design Patterns ( 7 Patterns ) Adapter Bridge Pattern Composite Pattern Decorator Pattern Facade FlyWeight FlyWeight Pattern is used when there are a large number of objects to be created, and they need to be created efficiently. This pattern is used by many frame works to create the objects using configuration. Proxy Behavioral Design Patterns ( 11 Patterns ) Chain Of Responsibility Pattern Command Interpreter Iterator Mediator Memento Memento is used internally by Text Editor Applications, where ctr+Z or cmd+Z operations are used to remember the snap shot of the data. State State Design Pattern is use

HashMap in Java

1) Implement HashMap in Java, with the put and get operations   HashMap can be implemented in Java Using Arrays. Use the same logic that the Out of the Box   HashMap follows, for resizing, and load factor, when ever the HashMap reaches the size of the   resize with the load factor a new Array is created, and the previous array contents are copied over   to the new Array.  HashMap is Not Synchronized by default. We can synchronize the whole map by using Synchronization, or by using collection.synchronizedmap(map), which synchronizes all the operations on the map. Alternatively We can use the CocurrentHashMap which does not lock the read operations, rather locks the segments that are being written. 2) HashMap vs LinkedHashMap vs IdentityHashMap 3) HashMap vs ConcurrentHashMap 4) Implement a Cache using LinkedHashMap

Stacks in Java

1) Implement Stack Data Structure in Java 2) Print the elements of a Stack 3) Find if the given set of open and closed parenthesis are valid, such that each open character     contains the corresponding closing character. 4) Reverse a Stack Using Iteration and Recursion 5) Sort Stacks 6) Create a Stack from a Queue 7) N Stack Problem 8) Max Element of a Stack 9) Use a Single Array to Implement 3 Stacks 10) Implement Queue using Stack 11) Reverse a Number using Stack

LinkedList Interview Questions

1) Print Elements of Linked List 2) Reverse LinkedList 3) Delete a given Element of a LinkedList 4) Delete kth Element from headNode of  a LinkedList 5) Delete kth Element from tailNode of  a LinkedList 6) Detect if a LinkedList contains a Cycle 7) Remove an Element from a DoublyLinkedList 8) Merge Elements of a DoublyLinkedList 9) Create a Cache such that the Elements can be added at Head and removed from Tail, in O(1) 10) Merge K Sorted Lists K Sorted Linked Lists cab be merged using MinHeap. All the elements from all the K Linked Lists are added to the MinHeap one by one. Create a Dummy LinkedList Node and add all the nodes from the Min Heap to the LinkedList node. Return the Next Node of the dummy Node which becomes the head for the combined LinkedList.

LinkedLists in Java

1) Print Elements of Linked List 2) Reverse LinkedList 3) Delete a given Element of a LinkedList 4) Delete kth Element from headNode of  a LinkedList 5) Delete kth Element from tailNode of  a LinkedList 6) Detect if a LinkedList contains a Cycle 7) Remove an Element from a DoublyLinkedList 8) Merge Elements of a DoublyLinkedList 9) Create a Cache such that the Elements can be added at Head and removed from Tail, in O(1)

Java Sorting Algorithms

1) Bubble Sort 2) Selection Sort 3) Insertion Sort Insertion sort is inserting the element at the right place, such that all the elements to the left are less than the element, and all the elements to the right are after the element, the same technique used to play card game. 4) Merge Sort 5) Quick Sort 6) Bucket Sort 7) Radix Sort

Arrays in Java

  1) Find a Missing number in an integer array of 1 to 100 This class finds the missing number from an array It uses two approaches a)Using sum of first n numbers which is n(n+1)/2, and   subtract each of the array elements from the sum, which   gives the missing number. b) Using XOR, Which finds the XOR of all numbers in the    given array, and also the XOR of first n numbers the XOR for these two calculations will give the    missing number 2)  Find 2 Missing Numbers from an Array This class finds two missing numbers from an Array It uses the XOR approach to find the results, and uses the three step approach First will do the XOR to find the missing number(which could be  the sum of the two numbers, says 3 and 5 are missing from the Array,We get 8, as the Array is sorted 8 can not be the sum of 4 and 4. So 8 has to be the sum of one number less than 4(half of it) and one number more than it.   3) Find First Non-Repeating elements in an array of Integers.