Skip to main content

Posts

Basic Sortings (Bubble, Selection and Insertion Sorts)

public class BasicSortings {

public static void main(String[] args) {

int temp;
int iterationCount = 0;
int array[] = { 2, 33, 29, 30, 21, 98};

//Bubble sort or Simple sort
for (int i = 0; i < array.length - 1; i++) { for (int j = i + 1; j < array.length; j++) { if (array[i] > array[j]) {
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
iterationCount++;
}
}
System.out.println("Bubble Sort Big 0(n) --> " + iterationCount);
for (int s = 0; s < array.length; s++) { System.out.print(array[s] + "\t"); } System.out.println("\n"); System.out.println("\n"); //Selection Sort
iterationCount =0;
int sortPointer=0;
for (int i = sortPointer; i < array.length; i++) { for(int j=i+1;j< array.length;j++) { if(array[i] > array[j])
{
temp = array[i];
array[i] = array[j];
array[j] = temp;
}

iterationCount++;
Recent posts

Finding Second Highest element in an Array

package com.sbs.java8.praticse;
public class SecondHightestClass {
public static void main(String[] args) { final Integer[] intArray = { 10, 2, 36, 7, 29, 30, 100, 20, 90, 83, 87 };
final int n = intArray.length; int sortPointer = intArray.length;
for (int m = n; m > (n - sortPointer); m--) {
for (int i = 0; i < n - 1; i++) { int j = i + 1; if (intArray[i] > intArray[j]) { int temp = intArray[i]; intArray[i] = intArray[j]; intArray[j] = temp; }
}
sortPointer--;
}
System.out.println(intArray[n - 2]); } }

Anogram Java Program

package com.sbs.java8.praticse;

import java.util.Arrays;

public class AnagramClass {

public static void main(String[] args) {
String firstString = "1MASS1111124";
String secondString = "1SAMS1111124";
boolean status = false;

if (validateString(firstString,secondString)) {
char array1[] = firstString.toLowerCase().toCharArray();
char array2[] = secondString.toLowerCase().toCharArray();

Arrays.sort(array1);
Arrays.sort(array2);

status = Arrays.equals(array1, array2);
}
System.out.println("Anogram Status " + status);

}

private static boolean validateString(String string,String string2) {
if (string == null || string.isEmpty()) {
return false;
}
if (string2 == null || string2.isEmpty()) {
return false;
}
if(string.length() != string2.length()){
return false;
}

return true;
}
}

NO SQL Types and vendors in market

NO SQL

KEY - VALUE Store  - Similar to a  MAP.
   e.g. Dynamo DB or REDIS

DOCUMENT Sore  - Similar to KEY-VALUE, value can be JSON/XML and key will be unqiuely idnetified this document.
   e.g. Coutch DB or mongoDB.

Column Store - Multi timentional table, identifying data with row and column numbers.
  e.g.  Cassandra or Apache HBase

Graph Store - Store relation between nodes (record entities). It has better transaction management
e.g. Neo4J and Orient DB.




Maven Build Life Cyles

Following are the maven build life cycles.

Clean - Removes the generated files in 'target' folder.

command : mvn clean

Validate - It validates your project and verify all the necessary information is there in project or not.

mvn  valiate

Compile - It compiles your project code.

mvn compile

Package - It takes the compiled code and packaged to JAR/WAR/EAR. It also compiles your code if your code is not compiled.

mvn package

Install -   It takes the packaged code and puts in your local maven repository (M2_HOME). It also does the compile and package if these are not already been done.

mvn install

Deploy - It takes the package and puts in remote repository for sharing accross team members or for other projects.

mvn deploy


FYI - Above commands can be used as variety of combinations.
e.g. mvn clean install
mvn clean package
mvn clean compile package install

To skip the tests to run 
mvn clean install -DskipTests