Sunday, 8 July 2012

What Constitutes excellent customer service







Sunday, 16 January 2011

TARGET MARKET & PRICING STRATEGIES

B.B.Q Tonight has always been charging slightly higher prices;

For Example: Earlier, the price of a seekh kabab plate was Rs.16 elsewhere whereas they charged Rs.20. Similarly, tikka was Rs.18 each but they charged Rs.22

Mr.Aziz quoted; “We target middle class and lower middle class.”

By claiming the above, it will not be fair to assume that Bar B Q Tonight is targeting middle and lower middle class because the prices that they charge are much higher than what a middle class person can afford.

Daily approximately 3000 customers visit the restaurant and pay around Rs.500 per head. It can accommodate around 1500 hundred people at a time.

There has been an increase in profits and sales every year and more and more people have started to visit it. Summer holidays in June and July are a peak period of sales for Bar B Q Tonight. 40% of the customers are from local community.

Friday, 19 November 2010

Monitor File for changes in Java

import java.io.File;import java.util.Hashtable;import java.util.Timer;import java.util.TimerTask;/** * Monitor files for changes. This singleton class maintains a map of files to * monitor and objects to notify when something they change. */public class FileMonitor { private static final FileMonitor SINGLETON = new FileMonitor(); private Timer timer; private Hashtable timerTasks; private FileMonitor() { timer = new Timer(true); timerTasks = new Hashtable(); } /** * Returns the singleton instance of this class. * @return the singleton instance */ public static FileMonitor getInstance() { return SINGLETON; } /** * Start monitoring a file. * * @param listener listener to notify when the file changed. * @param fileName name of the file to monitor. * @param period polling period in milliseconds. */ public void addFileChangeListener(FileChangeListener listener, String fileName, long period) { removeFileChangeListener(listener, fileName); FileMonitorTask task = new FileMonitorTask(listener, fileName); timerTasks.put(fileName + listener.hashCode(), task); timer.schedule(task, period, period); } /** * Remove the listener from the notification list. * * @param listener the listener to be removed. */ public void removeFileChangeListener(FileChangeListener listener, String fileName) { FileMonitorTask task = (FileMonitorTask) timerTasks.remove(fileName + listener.hashCode()); if (task != null) { task.cancel(); } } protected void fireFileChangeEvent(FileChangeListener listener, String fileName) { listener.fileChanged(fileName); } class FileMonitorTask extends TimerTask { FileChangeListener listener; String fileName; File monitoredFile; long lastModified; public FileMonitorTask(FileChangeListener listener, String fileName) { this.listener = listener; this.fileName = fileName; this.lastModified = 0; monitoredFile = new File(fileName); this.lastModified = getLastModified(); } private long getLastModified() { if (monitoredFile.exists()) { return monitoredFile.lastModified(); } else { return -1; } } @Override public void run() { long lastModified = getLastModified(); if (lastModified != this.lastModified) { this.lastModified = lastModified; fireFileChangeEvent(this.listener, this.fileName); } } } public interface FileChangeListener { public void fileChanged(String fileName); }}

Tuesday, 12 October 2010

Java Socket Programming with AES Encryption

Server Side Code:
import java.io.*;
import java.net.*;

import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;

public class RealEchoServer{
public static void main(String[] args ){
int i = 1;
try{
ServerSocket s = new ServerSocket(9003);

for (;;){
Socket incoming = s.accept( );
System.out.println("Spawning " + i);
new RealEchoHandler(incoming, i).start();
i++;
}
} catch (Exception e){ System.out.println(e); }
}
}

class RealEchoHandler extends Thread{
DataInputStream in;
DataOutputStream out;
private Socket incoming;
private int counter;

public RealEchoHandler(Socket i, int c){
incoming = i;
counter = c;
}

public void run(){
try {


String key1 = "1234567812345678";
byte[] key2 = key1.getBytes();
SecretKeySpec secret = new SecretKeySpec(key2, "AES");
String msg = "Singapore Malaysia Japan India Indonesia HongKong Taiwan China England";
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, secret);
byte[] encrypted = cipher.doFinal(msg.getBytes());

in = new DataInputStream(incoming.getInputStream());
out = new DataOutputStream(incoming.getOutputStream());

boolean done = false;
String str="";
out.writeUTF("Connected!\n");
out.flush();
while (!done){
out.writeUTF(">");
out.flush();
str = in.readUTF();
System.out.println(in+":"+str);
if (str == null)
done = true;
else{
System.out.println("Sending Ciphertext : " + new String(encrypted));
out.writeUTF(new String(encrypted));
out.flush();
}
}
incoming.close();
} catch (Exception e){
System.out.println(e);
}
}
}

Client Side code:

import java.io.*;
import java.net.*;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.util.*;

class RealSocketTest{
public static void main(String[] args) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException{

String str = "";
String str2 = "";
DataOutputStream out;
DataInputStream in;

try {
Socket t = new Socket("127.0.0.1", 9003);
in = new DataInputStream(t.getInputStream());
out = new DataOutputStream(t.getOutputStream());
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));

boolean more = true;
System.out.println(in.readUTF());

while (more) {
str = in.readUTF();
System.out.print(str);
str2 = br.readLine();
out.writeUTF(str2);
out.flush();
str = in.readUTF();

System.out.println("Encrypted Info: " + str);

try {

String key1 = "1234567812345678";
byte[] key2 = key1.getBytes();
SecretKeySpec secret = new SecretKeySpec(key2, "AES");

Cipher cipher = Cipher.getInstance("AES");

cipher.init(Cipher.DECRYPT_MODE, secret);
byte[] decrypted = cipher.doFinal(str.getBytes());
System.out.println("Decrypted Info: " + new String(decrypted));
}
catch(BadPaddingException e){
System.out.println("Wrong Key!");
}
catch(InvalidKeyException f) {
System.out.println("Invalid Key!");
}
}
}
catch(IOException e){
System.out.println("Error");
}
}
}

This is just a proof of concept please feel free to customize yourself..Enjoy ;)

Thursday, 22 October 2009

Java Socket Programming

The Server
The server's main function is to wait for incoming requests, and to service them when they come in. So the code to implement the server can be further broken down to the following steps:
1. Establish a server that monitors a particular port. This is done by creating an instance of the ServerSocket class. There are four different ways to create an instance of ServerSocket. They are:
a. ServerSocket(), which simply sets the implementation that means everything is taken as default values. b. ServerSocket(int port), which creates a server-side socket and binds the socket to the given port number.c. ServerSocket(int port, int backlog), which not only binds the created socket to the port but also create a queue of length specified by the number passed as the backlog parameter. d. ServerSocket(int port, int backlog, InetAddress bindAddr), which creates a server-side socket that is bound to the specified port number with the queue of length specified by the backlog and bound to the address specified by the bindAddr argument.
So to create a socket bound to port number 8888 with a backlog queue of size 5 and bound with address of local host the statement would be:
ServerSocket server = new ServerSocket(8888, 5, InetAddress.getLocalHost() );
One point to keep in mind is that the above mentioned constructors return TCP sockets and not UDP sockets.
2. The next step is to tell the newly created server socket to listen indefinitely and accept incoming requests. This is done by using the accept() method of ServerSocket class. When a request comes, accept() returns a Socket object representing the connection. In code it would be:
Socket incoming = server.accept();
3. Communicating with the socket, which means reading from and writing to the Socket object. To communicate with a Socket object, two tasks have to be performed. First the Input and Output stream corresponding to the Socket object has to be obtained. That can be done by using the getInputStream() and getOutputStream() methods of Socket class. In code it would be:
BufferedReader in = new BufferedReader (new InputStreamReader(incoming.getInputStream()));PrintWriter out = new PrintWriter (incoming.getOutputStream(), true /* autoFlush */);
The second task is to read from and write to the Socket object. Since the communication has to continue until the client breaks the connection, the reading from and writing to is done within a loop, like this:
boolean done = false; while (!done) { String line = in.readLine(); if (line == null) done = true; else { out.println("Echo: " + line);
if (line.trim().equals("BYE")) done = true; } }
The actual syntax for reading and writing is not different from the I/O done for simple files.
4. Once the client breaks the connection or stops sending the request, the Socket object representing the client has to be closed. This can be done by calling close() method on the Socket object. The statement would be:
incoming.close();
That's how a server is coded. The next section deals with creating a client.
The Client
The main purpose of the client is to connect to the server and communicate with it using the connection. So coding a client requires the following steps:
1. Connect to the server. Connecting to the server can be accomplished in two steps:
a. Creating a Socket object. The socket at client side just needs to know the host name (the name of the machine where server is running) and the port where the server is listening. To create a Socket object, there are seven constructors provided by the Socket class, of which the most commonly used are:
Socket(), which creates a new Socket instance without connecting to host.
Socket(InetAddress address, int port), which creates a new Socket object and connects to the port specified at the given address.
Socket(java.lang.String host, int port), which works the same way as Socket(), except that instead of an address, the host name is used.
So to create a Socket object that connects to 'localhost' at 8888, the statement would be:
Socket s=new Socket("localhost",8888);
b. Connecting to the server comes into picture if no argument constructor is used. It takes the object of the SocketAddress object as an argument. So to connect to localhost at port 8888, the code would be:
Socket s= new Socket();s.connect(new SocketAddress("localhost",8888));
2. Communicating with the server. Communicating with the server using a socket at client side is no different from how the server communicates with the client. First, the input and output streams connected with the Socket object are to be retrieved thus:
BufferedReader in = new BufferedReader (new InputStreamReader(s.getInputStream()));PrintWriter out = new PrintWriter (s.getOutputStream(), true /* autoFlush */);
Then you read and write using the corresponding streams. For example, if the client just waits for the data sent by the server, the code would be
boolean more = true;while (more) { String line = in.readLine(); if (line == null) more = false; else System.out.println(line); }
That covers all the steps involved in creating a network enabled application. In the next section I will be developing a file server application with multi-threading to handle multiple clients.