Pages

Friday, March 8, 2013

Simple Encoding and Decoding for Alpha Numeric String

Below is the code in java for alpha numeric string encoding and  decoding.


public class EncodeDecode {

private String getString() {
StringBuffer chrStr = new StringBuffer();

for (int x = 0; x <= 25; x++) {
int ch = 65 + x;
chrStr.append((char) ch);
}
for (int x = 0; x <= 9; x++) {
int ch = x;
chrStr.append(ch);
}
for (int x = 0; x <= 25; x++) {
int ch = 97 + x;
chrStr.append((char) ch);
}
return chrStr.toString();
}

private String encodedString(){
String chrStr = getString();
int from = 13;
int to = (chrStr.toString().length());
return chrStr.substring(from, to) + chrStr.substring(0, from);
}

public String decode(String input) {
String strDecode = "";

String chrStr = getString();

String abTo = encodedString();

for (int i = 0; i < input.length(); i++) {
int y = abTo.indexOf(input.charAt(i));

if (y == 0) {
strDecode = strDecode + input.charAt(i);
} else {
strDecode = strDecode + chrStr.charAt(y);
}
}
return strDecode;
}

public String encode(String input) {
String strEncode = "";
String chrStr = getString();

String abTo = encodedString();

for (int i = 0; i < input.length(); i++) {
int y = chrStr.indexOf(input.charAt(i));

if (y == 0) {
strEncode = strEncode + input.charAt(i);
} else {
strEncode = strEncode + abTo.charAt(y);
}
}

return strEncode;
}

Friday, March 1, 2013

Difference between API Vs. Web Services.




API (Application Programming Interface) is nothing but the protocol intended to be used as an interface by software components to communicate with each other. An API acts as an interface between two different applications so that they can communicate with each other.

Web Service is an API used in the context of
 web development. A Web service is a method of communication between two electronic devices over the World Wide Web.

API use any means of communication to initiate interaction between applications. API has a complete set of rules and specifications for a software program to interaction with each other.

A Web service may not have a complete set of specifications and sometimes might not be able to perform all the tasks.

API can be stripped in a various ways: COM Object, DLL files, Header files with .h extension, RMI in java etc, linux kernel API.

Web Services must be exposed the API is strictly through a network. Web Service API almost always uses HTTP or SMTP. Web Services can be SOAP, XML-RPC, REST, etc. 

Web API i.e. Web Service is typically defined as a set of Hypertext Transfer Protocol (HTTP) request messages, along with a definition of the structure of response messages, which is usually in an Extensible Markup Language (XML) or JavaScript Object Notation (JSON) format.

All Web services are APIs but all APIs are not Web services.