Skip to main content

Posts

Showing posts from 2017

Tree Traversal Implementation

Tree Traversal Implementation: public class Node { public int data ; public Node leftNode ; public Node rightNode ; Node( int Data ){ this . data = Data ; this . leftNode = null ; this . rightNode = null ; } } public class Traversal { public void inOrder(Node n ) { if ( n == null ) return ; inOrder( n . leftNode ); System. out .println( n . data ); inOrder( n . rightNode ); } public void preOrder(Node n ) { if ( n == null ) return ; System. out .println( n . data ); preOrder( n . leftNode ); preOrder( n . rightNode ); } public void postOrder(Node n ) { if ( n == null ) return ; postOrder( n . leftNode ); postOrder( n . rightNode ); System. out .println( n . data ); } } public class main { public static void main(String s []) { Node n1 = new Node(5); Node n2 = new Node(3); Node n3 = new Node(2); N...

Different Sorting Algorithm

Selection Sort: The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from unsorted part and putting it at the beginning. arr[] = 64 25 12 22 11 // Find the minimum element in arr[0...4] // and place it at beginning 11 25 12 22 64 // Find the minimum element in arr[1...4] // and place it at beginning of arr[1...4] 11 12 25 22 64 // Find the minimum element in arr[2...4] // and place it at beginning of arr[2...4] 11 12 22 25 64 // Find the minimum element in arr[3...4] // and place it at Insertion Sort: Merge Short. QuickSort 2.9 Like  Merge Sort , QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot.  There are many different versions of quickSort that pick pivot in different ways. Always pick first element as pivot. Always pick last elem...

Dependency Injection Definition

What is dependency management in Spring? Lets consider the following interfaces and concrete class that implements interface. public interface IOutputGenerator { public void generateOutput ( ) ; }   public class CsvOutputGenerator implements IOutputGenerator { public void generateOutput ( ) { System . out . println ( "Csv Output Generator" ) ; } } public class JsonOutputGenerator implements IOutputGenerator { public void generateOutput ( ) { System . out . println ( "Json Output Generator" ) ; } }   Lets call it directly.      public class App { public static void main ( String [ ] args ) { IOutputGenerator output = new CsvOutputGenerator ( ) ; output . generateOutput ( ) ; } }   In this way, the problem is the “output” is coupled tightly to CsvOutputGenerator, every change of output generator may involve code change. If this code is scattered all over of your project...

ifference between @RestController and @Controller

Difference between @RestController and @Controller Annotation in Spring MVC and REST Read more:  http://javarevisited.blogspot.com/2017/08/difference-between-restcontroller-and-controller-annotations-spring-mvc-rest.html#ixzz4sbGy2Glh The  @RestController  annotation in Spring MVC is nothing but a combination of  @Controller  and  @ResponseBody  annotation. It was added into Spring 4.0 to make the development of RESTful Web Services in Spring framework easier. If you are familiar with the  REST web services  you know that the fundamental difference between a web application and a REST API is that the response from a web application is generally view (HTML + CSS + JavaScript) while REST API just return data in form of JSON or XML. This difference is also obvious in the  @Controller  and  @RestController  annotation. The job of  @Controller  is to create a Map of model object and find a view but  @RestContr...