Skip to main content

Posts

Showing posts from August, 2015

How to find all Permutations and Combinations of a String

Algorithm Used We will be using the following algorithm to find all the permutations of a string Take the first letter as a prefix and find all the permutations of the remaining string. Each of the prefix will also be a permutation itself. If you want to find all the permutations of string with same length as the original string then skip the prefix's as the combination. public class Permute { static String codes = "eki"; static int count; public static void main(String args[]) { permute("", codes); System.out.println(">>>>>>>" + count); } public static void permute(String prefix, String str) { System.out.println(prefix); count++; int n = str.length(); if (n == 0) { System.out.println(prefix); } else { for (int i = 0; i < n; i++) permute(prefix + str.charAt(i), str.substring(0, i) + str.substring(i + 1, n)); } } } The above code will give the following output e ek eki eki ei eik eik k ke kei kei ki

Spring Boot Maven Dependencies to create basic CRUD application

Spring Boot Maven to create basic CRUD application. You need to add the following dependencies to the pom.xml to make the basic CRUD application spring-boot-starter-data-jpa spring-boot-starter-jdbc spring-boot-starter-web jstl mysql-connector-java spring-boot-starter-tomcat tomcat-embed-jasper So your pom.xml may look like the following pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.ekiras</groupId> <artifactId>springboot</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>springboot</name> <description>Basic Springboot CRUD applicat

Spring Boot Gradle MVC sample CRUD project

This is a sample Spring Boot Application that uses  JDBC Mysql JPA MVC Gradle Create Basic CRUD for Person Entity with JPA and Mysql Download from GitHub Project Structure  build.gradle View Maven Dependencies (pom.xml) here. buildscript { ext { springBootVersion = '1.2.5.RELEASE' } repositories { maven { url "http://repo.spring.io/libs-milestone" } mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") classpath("io.spring.gradle:dependency-management-plugin:0.5.1.RELEASE") } } apply plugin: 'java' apply plugin: 'eclipse-wtp' apply plugin: 'idea' apply plugin: 'spring-boot' apply plugin: 'io.spring.dependency-management' apply plugin: 'war' war { baseName = 'springboot' version = '0.0.1-SNAPSHOT' } sourceCompatibility = 1.7 targetCompatibility = 1.7 rep

Get free Airtel 4G sim by tweeting #GetAirtel4G

Wow! you can get an Airtel 4G Sim  totally free. Here is how? If you are an Airtel user and you have the required 4G handset with you, you just have to tweet #GetAirtel4G to get a 4G sim delivered to your home for TOTALLY FREE .     Steps to get your Airtel 4g SIM Tweet with #GetAirtel4G on twitter,  Get the reply from Official Airtel India handle @AirtelIndia to fill details Fill your details and address where you want your sim to be delivered. You are done. You will get your Airtel 4g Sim within hours to a day or two at max. I got my sim in just 4 hours. Why should I go for 4G services from Airtel It is much faster than 3G services It does not cost your anything You get super fast speed for a great browsing experience You can always flaunt your 4G network among your group. Lets Take a look what is so special about Airtel 4g. India's top telecom service provider Bharti Airtel on Thursday said it has commercially launched its fourth generation (4G) communications services in 296

Spring Boot Making CLI Application using Java

Points To Remember You can make the cli application without writing any configurations or xml's that you needed to do in traditional spring framework. Spring boot automatically adds the boiler plate code to the application that may look like this // import org.springframework.web.bind.annotation.Controller // other imports ... // @Grab("org.springframework.boot:spring-boot-web-starter:0.5.0") // @EnableAutoConfiguration @RestController @RequestMapping("/") class Hello { @RequestMapping(value="/hello") public String index(){ return "<h1>Hello World !! Today's date is " + new Date() + "</h1>"; } // public static void main(String[] args) { // SpringApplication.run(Example.class, args); // } } The following code is a self sufficient code to run in a servlet container. Hello.java import java.util.Date; @RestController @RequestMapping(value="/") class Hello{ @RequestMapping(value="/hello")

Spring Boot Making CLI Application using Groovy

Points To Remember You can make the cli application without writing any configurations or xml's that you needed to do in traditional spring framework. Spring boot automatically adds the boiler plate code to the application that may look like this // import org.springframework.web.bind.annotation.Controller // other imports ... // @Grab("org.springframework.boot:spring-boot-web-starter:0.5.0") // @EnableAutoConfiguration @RestController @RequestMapping("/") class Hello { @RequestMapping(value="/hello") public String index(){ return "<h1>Hello World !! Today's date is " + new Date() + "</h1>"; } // public static void main(String[] args) { // SpringApplication.run(Example.class, args); // } } The following code is a self sufficient code to run in a servlet container. Hello.groovy import java.util.Date; @RestController @RequestMapping(value="/") class Hello{ @RequestMapping(value="/hello")

Hibernate : @Table Annotation

Points To Remember @Table Annotation is an annotation that is used to give the table level information. It can be uesd to specify the following Table name  (optional,default ="")- to set the name of the table in database Table schema  (optional,default ="")- to set the schema of the table in database Table catalog  (optional,default ="") -to set the catalog of the table Table Constraints  (optional,default = []) to set the constraints on the table. It belongs to the package javax.persistence.Table @Table( name="person", schema="ekiras", uniqueConstraints = {@UniqueConstraint(columnNames = {"id","email"})} ) public class Person { private Long id; private String name; private String email; // code } If you do not define the name  property of the  @Table annotation then the hibernate would have created table by name Person  but now it will create the table by name person . The person  table will have the unique

Exception in thread java.util.ConcurrentModificationException

Points To Remember ConcurrentModificationException  occurs when the you you try to modify the collection you are using or iterating. It can be prevented if you create a new object of that collection and do operations on that and then assign it back to the original object. java.util.ConcurrentModificationException In the following code we will be iterating on the list and trying to remove the null objects from the list. import java.util.*; public class Demo { public static void main(String args[]) { // create an array of string objs String init[] = { "One", "Two", null, null, "One", "Two", null, "Three", "Four", "Two", null }; // create two lists List<String> list = new ArrayList(Arrays.asList(init)); for (String str: list) { if (str == null) list.remove(str); } System.out.println("List value: " + list); } } The above code will throw the following Exception Exception in thread &

How to remove all nulls from a Collection in Java

How to remove nulls from a List in Java One way is to iterate the objects from the Collection ( like List, Array, Map etc) and remove null objects. Remove a particular object from List, Array or Map by searching the object and then removing it. Using the Collections.singleton(T o)  method from the java.util  package and then it will remove all the objects from the collection. Removing Objects in Traditional Way. We will be taking the following list of String for all our Examples String init[] = { "One", "Two", "One", "Three", "One", "Two", "Three","Four", "Two" }; Here we will remove the objects by finding it from the Collection. List list = new ArrayList(Arrays.asList(init)); list.remove("One"); System.out.println("List value: "+list); list.remove("Two"); System.out.println("List value: "+list); list.remove("Three"); System.out.println("List