Posts

Card Dealer In Java in Less than 5 minutes

Image
Code: package design; import java.util.Collections; import java.util.Stack; public class CardDealer { private int totalPlayers; private static Stack<Card> deck; CardDealer(int players){ totalPlayers=players; deck =  Deck.getCardDeck(); } public static void main(String[] args) { CardDealer cardDealer = new CardDealer(5); cardDealer.dealCards(); } public void dealCards(){ int cardsToPlayer = deck.size()/totalPlayers; for(int i=0;i<cardsToPlayer;i++){ for(int j=1;j<=totalPlayers;j++){ System.out.println("Player:"+j+ " gets "+deck.pop()); } } } private int getPlayers() { return totalPlayers; } }  class Deck{ static Stack<Card> deck = new Stack<Card>(); static Deck d=null; static { d = new Deck(); } public static Stack<Card> getCardDeck(){ return deck; } private Deck(){ populateDeckWithcards(); shuffle(); } pr...

Creating PhoneBook using AngularJS, Java, Spring MVC, Spring Data, JSON Web Tokens and Mysql Lesson 5 to Lesson 8

Image
Here in this videos we will go through and create a PhoneBook application with CRUD functionality, Login and Authentication Management using AngularJS, Java, Spring MVC, Spring Data, JSON Web Tokens and Mysql The Videos are available on Youtube or you can watch them right here, the code will be hosted on Github which is complete and can be used as base to create enterprise applications. The videos are posted with topics and numbers for easy accessibility.. Code: Here

Creating PhoneBook using AngularJS, Java, Spring MVC, Spring Data, JSON Web Tokens and Mysql

Image
Here in this videos we will go through and create a PhoneBook application with CRUD functionality, Login and Authentication Management using AngularJS, Java, Spring MVC, Spring Data, JSON Web Tokens and Mysql The Videos are available on Youtube or you can watch them right here, the code will be hosted on Github which is complete and can be used as base to create enterprise applications. The videos are posted with topics and numbers for easy accessibility.. Lesson 1 to 4 Below Next Post will have Lessons 5 to Lesson 8 Code: Here

Selection Sort Algorithm in Java

Image
Code: package algorithm.sort; public class SelectionSort { public static void main(String[] args) { int[] array = { 64, 25, 12, 22, 11 }; for (int i = 0; i < array.length - 1; i++) { print(array); // find smallest element, move it to its right place int indexOfMinimumInArray = i; for (int j = i + 1; j < array.length; j++) { if (array[indexOfMinimumInArray] > array[j]) { indexOfMinimumInArray = j; } } if (indexOfMinimumInArray != i) { // swap the smallest element to its right position swap(i, indexOfMinimumInArray, array); } } } private static void swap(int i, int indexOfMinimumInArray, int[] array) { int temp = array[i]; array[i] = array[indexOfMinimumInArray]; array[indexOfMinimumInArray] = temp; } static void print(int[] arr) { for (int i = 0; i < arr.length; i++) { System.out.print(" " + arr[i]); } S...

InsertionSort Algorithm in Java

Image
Code: package sort; public class InsertionSort { public static void main(String[] args) { int[] arr = {3,7,4,9,5,2,6,1}; for(int i=1;i<arr.length;i++){ int currentValue=arr[i]; int previousIndex=i-1; int insertions=0; while(previousIndex>=0 && (arr[previousIndex]>currentValue)){ //if previous is greater than current arr[previousIndex+1]=arr[previousIndex]; //swap it , assign greater to current location 7 previousIndex=previousIndex-1; // drives the loop System.out.println("previousIndex:"+previousIndex); insertions++; } System.out.println("CurrentValue["+currentValue+"]  insertions:["+insertions+"]"); arr[previousIndex+1]=currentValue; //assign the current(smaller value) to previous position 4 printArray(arr); System.out.println(); } } private static void   printArray(int[] arr){     //utility function to print array ...

Bubble Sort In Java

Image
Code : public class BubbleSort {     static int swapCount=0;     static int passes=0;             public static void main(String[] args) {         int[] array={5,1,4,2,8};                 printArray(array);//Before                 bubbleSort(array);                 printArray(array);//After                 System.out.println("\n Total Passes:"+passes);                 System.out.println("\n Total Swaps:"+swapCount);     }     private static void bubbleSort(int[] array) {         boolean swapped=false;   ...

Up and Running With Spring MVC Controller

Image
MVC or model view controller pattern relies on the front controller pattern, simply said the DispatcherServlet receives a request for an URl and gives it to a mapped  Controller to take the request and handle it. The DispatcherServlet in Spring is generally configured in the XML like below  <servlet>         <servlet-name>Login</servlet-name>         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>         <load-on-startup>1</load-on-startup>     </servlet>     Similarly a Java based approach might look like below         Dynamic dispatcherServlet = servletContext.addServlet("dispatcherServlet", new DispatcherServlet(context)); So its the first file to be loaded. So once we have our dispatcherservle...