Saturday, September 7, 2024

Design patterns

 From @SumitM_X

You are planning to introduce breaking changes to a public-facing microservice API that is being used by multiple clients. How would you manage these changes to ensure existing clients are not disrupted?

The Strangler Fig pattern is an architectural pattern used in software development to incrementally migrate a legacy system to a new one. The name comes from the strangler fig plant, which grows around a host tree and eventually replaces it.

Here’s a brief overview of how it works:

  1. Incremental Replacement: Instead of replacing an entire legacy system at once, you gradually replace specific pieces of functionality with new applications and services.
  2. Façade: A façade intercepts requests going to the backend legacy system and routes them either to the legacy application or the new services. This allows the old and new systems to coexist during the transition.
  3. Gradual Migration: Over time, as more features are migrated to the new system, the legacy system is eventually “strangled” and can be safely decommissioned12.

This pattern helps minimize risks and spread the development effort over time, making it easier to manage complex migrations12.

Thursday, March 7, 2024

GIT : 


Error :  fatal: cannot create a directory at '': Filename too long


git config --global http.proxy http://proxy.****.com:80

git config --global core.longpaths true git clone *** URL***



Wednesday, November 6, 2019

How to increase CPU Performance ?

Run below commands & Sift+Delete

1. ccmcache
2. prefetch
3. %temp%

Download latest drive from laptop product & Install.

Thursday, July 16, 2015

javax.xml.bind.PropertyException:name: com.sun.xml.bind.xmlDeclaration value: false

javax.xml.bind.PropertyException: name: com.sun.xml.bind.xmlDeclaration value: false
at javax.xml.bind.helpers.AbstractMarshallerImpl.setProperty(AbstractMarshallerImpl.java:349)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.setProperty(MarshallerImpl.java:544)
at com.cat.rr.tdmscdl.inf.ErrorMessageService.getErrorMsgXML(ErrorMessageService.java:65)
at com.cat.rr.tdmscdl.inf.ErrorMessageService.sendGrieftoTVS(ErrorMessageService.java:27)
at com.cat.rr.tdmscdl.inf.ErrorMessageService.main(ErrorMessageService.java:53)


The above error will be appears when we are using Java 1.6 and JAXB.
jm.setProperty("com.sun.xml.bind.xmlDeclaration", Boolean.FALSE);

Please include following Jars in libs


jaxb-core.jar
jaxb-api.jar
jaxb-impl.jar

Thursday, November 29, 2012

In windows 7 : The specified DSN Contains an architecture mismatch between the Driver and Application

ODBC Driver setup

The following steps show how to access a 32-bit ODBC driver from a 64-bit application on a 64-bit Windows machine. The ODBC driver used is the Microsoft Access ODBC driver. The application used is the SQL Server Integration Services (SSIS) Import and Export Wizard.
  1. In the 32-bit ODBC Data Source Administrator, configure a System data source for the Access ODBC driver. To access the 32-bit ODBC Data Source Administrator, run the following command in the Windows Run dialog box:
    %windir%\syswow64\odbcad32.exe

Sunday, August 26, 2012

Java : Getting no days between dates in java

private static double durationInDays(Date dateFrom, Date dateTo) {


TimeZone tz = Calendar.getInstance().getTimeZone();

/*TimeZone ltz = TimeZone.getTimeZone(tz.getID());

System.out.println(tz.getID());*/

double timeTo = dateTo.getTime();

double timeFrom = dateFrom.getTime();

double duration = timeTo - timeFrom;

if (tz.inDaylightTime(dateFrom)) {

if (!tz.inDaylightTime(dateTo)) {

System.out.println("in daylight saving from: " + dateFrom);

System.out.println("not in daylight saving to: " + dateTo);

duration -= 60 * 60 * 1000;

}

} else {

if (tz.inDaylightTime(dateTo)) {

System.out.println("not in daylight saving from: " + dateFrom);

System.out.println("in daylight saving to: " + dateTo);

duration += 60 * 60 * 1000;

}

}

return duration / (24 * 60 * 60 * 1000);

}

Monday, February 6, 2012

Content Assist (Ctrl + Space) Is Not Working in Eclipse IDE / RAD in Windows 7

In Windows7 the content assist is not working in Eclipse IDE /RAD 7.0. I have Google the same information at not able find right solution.

At last I have changed content assist key to other key settings.


Preference ---> General ---> keys--->

Scheme: Default
Name: Content Assist
binding : Shift+spacebar ( Previous its CTRL +SPACEBAR )



Now short cut changed its working fine.


Tuesday, April 19, 2011

Time Difference in Minute with Current Date / TIme

public class MinuteDiffrence {


public static void main(String[] args) {
String dbD = "04/19/2011-19:39:02";
System.out.println(" Diffirence in Minute"+timeDiff(dbD,"MM/dd/yyyy-HH:mm:ss"));
}
public static long timeDiff(String dbD,String pattern){
try {
DateFormat formatter;
Date dDB;
dDB = (Date) new SimpleDateFormat(pattern).parse(dbD);
Date dApp=new Date();
System.out.println("Given Date " + dDB+"\nToday Date "+dApp);
long time=dApp.getTime()-dDB.getTime();
return time/60000;

} catch (ParseException e) {
System.out.println("Exception :" + e);
}
return 0;
}
}


OutPut:

Given Date Tue Apr 19 19:39:02 IST 2011
Today Date Tue Apr 19 20:53:42 IST 2011
74

Tuesday, July 6, 2010

Second Highest Element in Array



package sun.sort;

public class SecondHigestinArray {

public static void main(String[] args) {

int arr[]={1,4,2,9,6,7,8,9};

int temp,h,sH;
sH=h=arr[0];

for (int i = 0; i < arr.length; i++) {

temp=arr[i];
if (temp > h) {

sH=h;
h=temp;
}else if(temp > sH || sH==h){

sH=temp;
}
}
System.out.println("second Highest "+sH);

Tuesday, June 1, 2010

Sorting HashMap by Value in java

package sun.sort;

import java.util.*;

// for JDK 1.5 and above
/**
* sorting hashMap based on the value and if Hash map contains null or empty to
* be added in last elements of map
* @author akamesh
*/
public class HashMapSort {
@SuppressWarnings("unchecked")
public static void main(String[] args) {
Map hm = new HashMap();
hm.put("a", "0.2");
hm.put("b", "1.2");
hm.put("c", "3");
hm.put("d", "5");
hm.put("e", "1");
hm.put("f", "2");
hm.put("g", "0");
hm.put("h", "");
// To make insertion order of values to be same
Map hm1 = new LinkedHashMap();
Map hMap = new LinkedHashMap();
List sortedList = sortByValue(hm);

for (Iterator i = sortedList.iterator(); i.hasNext();) {
String key = (String) i.next();
String value = (String) hm.get(key);
if (value != null && value.equals("")) {
hMap.put(key, value);
} else {
hm1.put(key, hm.get(key));
}
System.out.printf("key: %s, value: %s\n", key, hm.get(key));
}

Iterator myVeryOwnIterator = hm1.entrySet().iterator();
while (myVeryOwnIterator.hasNext()) {
System.out.println(myVeryOwnIterator.next());
}
System.out.println("****MAPs contains No values *******");

Iterator myVeryOwnIterator1 = hMap.entrySet().iterator();
while (myVeryOwnIterator1.hasNext()) {
System.out.println(myVeryOwnIterator1.next());
}
hm1.putAll(hMap);

System.out.println("**** Final values *******");

Iterator myVeryOwnIterator2 = hm1.entrySet().iterator();
while (myVeryOwnIterator2.hasNext()) {
System.out.println(myVeryOwnIterator2.next());
}

}

public static List sortByValue(final Map m) {
List keys = new ArrayList();
keys.addAll(m.keySet());
System.out.println("keys" + keys);
Collections.sort(keys, new Comparator() {
public int compare(Object o1, Object o2) {
Object v1 = m.get(o1);
Object v2 = m.get(o2);
if (v1 == null) {
return (v2 == null) ? 0 : 1;
} else if (v1 instanceof Comparable) {
return ((Comparable) v1).compareTo(v2);
} else {
return 0;
}
}
});
return keys;
}
}


OUTPUT:

keys[d, a, h, c, f, g, b, e]
key: h, value:
key: g, value: 0
key: a, value: 0.2
key: e, value: 1
key: b, value: 1.2
key: f, value: 2
key: c, value: 3
key: d, value: 5
g=0
a=0.2
e=1
b=1.2
f=2
c=3
d=5
****MAPs contains No values *******
h=
**** Final values *******
g=0
a=0.2
e=1
b=1.2
f=2
c=3
d=5
h=

Wednesday, April 14, 2010

Sorting Hashtable in java

import java.util.Hashtable;
import java.util.Iterator;
import java.util.TreeMap;

public class IteratorTest {
public static void main(String[] args) {
Hashtable ht = new Hashtable();
ht.put("A", "Avalue");
ht.put("E", "Evalue");
ht.put("B", "Bvalue");
ht.put("C", "Cvalue");
ht.put("D", "Dvalue");

TreeMap tm = new TreeMap(ht);
Iterator iter = (tm.keySet()).iterator();
System.out.println(ht);
//System.out.println(iter);
while (iter.hasNext()) {
System.out.println(ht.get(iter.next()));
}

}

Monday, April 21, 2008

Const Array create how?

JAVA Code:
final int array[]={1,2,4};
array[0]=5;
System.out.println(array[0]);

output: 5 // Becoz final keyword will not yield the desired effect, because it will just make the variable not be able to point to another object (like a const pointer) - it will not make the object referred by it constant.


JAVA Code: //to make an constant Array
import java.util.*;
public class Test
{
static Object array[] = {new Integer(1), new Integer(2), new Integer(4)};
public static final List CONST =
Collections.unmodifiableList(Arrays.asList(array));
public static void main(String args[])
{
CONST.set(0, new Integer(5));
System.out.println(CONST.get(0));
}
}
JAVA Code:Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableList.set(Collections.java:1141)
at Test.main(Test.java:12)

Get num of rows in ResultSet -JDBC

public static void main(String[] args)

{

System.out.println("Count records example using prepared statement!");

Connection con = null;

int records = 0; try{

Class.forName ("com.mysql.jdbc.Driver").newInstance ();

con = DriverManager.getConnection ("jdbc:mysql://localhost/adportal", "root", "admin");

con.setAutoCommit(true);

try{

String sql = "SELECT COUNT(*) FROM postmessage";

PreparedStatement prest = con.prepareStatement(sql);

ResultSet rs = prest.executeQuery();

while (rs.next())

{

records = rs.getInt(1);

}

System.out.println("Number of records: " + records);

con.close(); }

catch (SQLException s){ System.out.println("Table does not exist in the database!");

}

}

catch (Exception e){ e.printStackTrace(); }

}

Return more than one values from a method !!

//returns student first name, last name, age given the ssn
public Map getStudentInfo(String ssn){
String fName = null;
String lName = null;
int age = 0;
Hashtable info = new Hashtable();

//pretend we looked up the information rather than hardcoding it and place
//items in a Hashtable in this case

info.put("FName", "Jean-Luc");
info.put("LName", "Pickard");
info.put("Age", new Integer(52)); //age is of type int; like all primitives, it must be wrapped

//return the object
return info;
}
In the calling method you need to get the items out of the Map and cast to what you needMap stuInfo = getStudentInfo("123-45-6789");
String firstName = (String)stuInfo.get("FName");
String lastName = (String)stuInfo.get("LName");
int stuAge = ((Integer)stuInfo.get("Age")).intValue(); //Get the value of the wrapper object

...