Sunday, June 18, 2017

Servlet Interface

The Servlet interface specified s contract between the servlet container and the servlet.  Servlet container calls the init method of the servlet one time during start up.  When a request comes in, servlet engine calls the service method of the servlet to process it.

Servlet engine will also pass in a ServletConfig object to the servlet application's init method.  ServletConfig contains initialization parameters. ServletConfig also provide a SrvletContext object. The ServleCcontext contains global data accessible by all classes in the servlet. In a distributed environment, each servlet instance can access the same ServletContext data.

Servlet also defines two objects - ServletRequest and ServletResponse that used by service method.  ServletRequest defines methods to retrieve parameters submitted in a request.  For example, "id" is the parameter which the method returns as string value.

http:::.../servlet?id=1

ServletResponse simplifies the returning of response to the client. It defines methods to let the application to write the response to a certain stream and let servlet container to handle the rest.

To implement a serlvet, one create a class implement the Servlet interface or extend a class that implemented the Servlet interface.

Monday, May 1, 2017

Function Pointer

Pointer to a function is declared as follows

void (*fn)()

Void is the return type
fn is the function name
() is the parameter types

For example

int (*abc)(int, int) is a function pointer for a function abc which accepts 2 integer arguments and returns an integer result

To use a function pointer

int sum(int a, int b)
{
    return a + b;
)

abc = sum;
z = abc(x, y);


Pointer Arithmatic.

Adding an integer, say i, to a pointer is actually advancing the pointer to i unit of the underlying data type the pointer points to.  For example,

int *p;
p = &j
p = p + 3;  /* p = p + 3*4 as integer is 4 bytes in length */

Likewise, for subtraction, the pointer is deducted by i units of the underlying data type.

When subtracting 2 pointers, the result is the number of units of the underlying data type.  A minus result indicate the first pointer is less than the second pointer in the expression.

Constant and Ponter

const int *p is a pointer to a constant integer.  We cannot change the variable that the pointer is pointing to but we can change the pointer to point to another variable.  However, even if the new variable it points to is not a constant, C runtime will not allow us to change it as it thinks the pointer is pointing to a constant as declared.

For example

const int *p;
const int i = 100
int j = 20

p = &i;  /* ok */
p = &j;  /* ok */
*p = 300;  /* error */

int *const p is a constant point pointing to an integer variable.  The pointer value cannot be change but we can change the variable it points to.

*p = 100;  /* ok */
p = &j;  /* error */

const int *const p is a constant pointer pointing to a constant variable. When the pointer is declard, it must be initialized.

const int *const p = &i

const int *const *p is a pointer to a constant pointer to a constant integer variable

Reading C Pointer Declaration

Reading the pointer declaration backward is easier.

For example, int * p

p = p is a variable
* = p is a pointer variable
int = p is a pointer variable points to an integer

const int * p = a pointer to an constant intege

Wednesday, November 16, 2016

Javascript

JavaScript was created in Netscape and incorporated into Netscape browser in 1995.  It was initially called Mocha and Livescript. Later on a marketing deal was made between Netscape and Sun whom own Java, it was named to Javascript.  To justified for the name, all Java keywords are reserved words in Javascript.  Javascript's standard library also uses the naming convention as Java.  It'd Msth and Date functions also based on the standard class of Java 1.0 objects.  ECMA standardised Javascript and it is called ECMAscript.  So Javascript is like a dialect of ECMAscript.  Likewise Microsoft's JScript is also a dialect of ECMAscript but there are some incompatibilities.

Monday, October 10, 2016

Greek Mythology

Orion

He is a son of king of Thrace whom was initially childless.  He was liked by Gods and in return, the Gods grant him a son.  They asked him for the hide of a bull he has scarified.  Zeus, Poseidon and Hermes urinated on the hide and buried it.  Nine month later, Orion was born from the spot and his father named him Urion or Orion, i.e. "urine boy".

Amazon

A tribe of worrier women who lived in distant shore of Black Sea.  When a child is born and is a boy, he would be killed.  If it was a girl, the tribe would accept it as one of them and raise it.  When the girl reached puberty, they would cut off her right breast for her to have a better draw of bow.  The "a" means no and "mazos" means breast.

Pan

Son of Hermes and a nymph called Dryope.  When he was born, the laughing child has feet of goat. horns and a full beard.  Hermes brought him to show to the Gods of Olympus and they were delighted, naming him Pan which mean "all" in Greek.  He chased a nymph called Syrinx whom ran way.  When pan nearly caught up, she prayed to the river nymph for help and they transform her to reed.  Pan cut the reed to different length and invented the pan pipe.  Pan would bring terror to those that offended him and thus "panic" means uncontrollable fear.