Saturday, March 10, 2018

Spring Boot Application With Docker

-->




1)    Create Spring Boot Application

a)     Use Spring Tool Suite (STS) to create spring boot application
b)    Start New Project



c.Add Required Dependency

Here we add Actuator ,Web,Jercy(JAX-RS)



and Click Finish.




2)    Create Rest Service Class



3)    Change POM File









4)    Add Actuator and custom port



5)    Create Docker File

6)    mvn clean

7)    mvn clean install




8)    Build Docker

9)    Docker Images

10) Run Docker

11) Check in Browser

12) Check Actuator

13) Check in Health Status

14) Check in Actuator Env








Tuesday, February 21, 2017

Microservices


  • Micro service is a new way of developing Applications.
  • Each micro service contains a specific task.
  • There is no proper definition in the industry
  • It will do a specific job with one  or two supporting tools.
  • for example one micro service will handle all Read Requests
  • Another micro service will handle all Write Operations.
Development Environment
  • we can develop micro services using Docker.
  • Docker is a platform to build test and run applications.
Language

Framework:

  • SpringBoot: Spring Boot is a powerful frame work in java, which is used to create production ready and stand alone application in a short time.


Monday, August 11, 2014

String Word Reverse without Reverse Function

we have the string = Java programming is fun and we want to reverse that string in each word wise
avaJ gnimmargorp si nuf ,without using any reverse function.


/**
* @author TechSivam
* Reverse the string each word and not to use any string reverse methods.
*/
public class StringReverse {

public static void main(String[] args) {
StringBuffer a = new StringBuffer("Java programming is fun");
System.out.println(a);

String[] s=a.toString().split(" ");

for (String string : s) {

for (int i = string.length()-1; i >=0; i--) {
System.out.print(string.charAt(i));
}
System.out.print(" ");
}
}
}


OUTPUT:
Java programming is fun
avaJ gnimmargorp si nuf

Collections in Immutable Class

  • immutable class in java is not allowing to modify the value of the variables.
  • but in normal immutable class with collections , if we are not using setter method also , we can change the collection values.
  • normally when we use the getter method , we directly return the reference of the collections.
  • here we can change the values for the collection, even though,it is final .

public class ImmutableClassCollections {
private final  String name;
private final List arrayList;
public ImmutableClassCollections(String name, List arrayList) {
this.name = name;
this.arrayList = arrayList;
}
public String getName() {
return name;
}
public List getArrayList() {
return arrayList;
}
/**
* @param args
*/
public static void main(String[] args) {
List mylist=new ArrayList<>();
mylist.add("A");
mylist.add("B");
ImmutableClassCollections example=new ImmutableClassCollections("Siva", mylist);

System.out.println(example.getName());

List arrayList2 = example.getArrayList();

for (String string : arrayList2) {
System.out.println(string);
}
System.out.println("Add C to Array List");
example.getArrayList().add("C");
arrayList2 = (ArrayList) example.getArrayList();
for (String string : arrayList2) {
System.out.println(string);
}


}
}
OUTPUT:
Siva
A
B
Add C to Array List
A
B
C

How to Avoid Collection also in Immutable Class:
we can use two approaches in getter method
  1.  create local copy of the collection and return the copy reference only
  2. using collections API-return Collections.unmodifiableXXX(XXX);

1) Create  Local Copy:
  • It will create new copy and return that value. so it will not change the original value
public List getArrayList() {
List arrayList1=new ArrayList<>(arrayList);
return arrayList1;
}
OUTPUT:
Siva
A
B
Add C to Array List
A
B

Here we are using Collections.unmodifiableList(arrayList);
now we change the return value, it will throw the exception.
public List getArrayList() {
return Collections.unmodifiableList(arrayList);
}
OUTPUT:
Siva
A
B
Add C to Array List
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableCollection.add(Unknown Source)
at com.ts.immutable.ImmutableClassCollections.main(ImmutableClassCollections.java:42)

unmodifiableList Implementation in Collections Class:

/**
* Returns an unmodifiable view of the specified list. This method allows
* modules to provide users with "read-only" access to internal
* lists. Query operations on the returned list "read through" to the
* specified list, and attempts to modify the returned list, whether
* direct or via its iterator, result in an
* UnsupportedOperationException.
*
* The returned list will be serializable if the specified list
* is serializable. Similarly, the returned list will implement
* {@link RandomAccess} if the specified list does.
*
* @param list the list for which an unmodifiable view is to be returned.
* @return an unmodifiable view of the specified list.
*/
public static List unmodifiableList(List list) {
return (list instanceof RandomAccess ?
new UnmodifiableRandomAccessList<>(list) :
new UnmodifiableList<>(list));
}