- What are the various ways to implement threads.
- How do we make a section of code thread-safe.
- What all do you know about Springs Framework.
- Which template have you used in Springs DAO.
- Explain some features of Hibernate.
- How is Hibernate different that Springs DAO.
- Which version of Struts have you worked on.
- Explain the flow of control in a struts framework.
Tuesday, May 27, 2008
Java interview questions
Thursday, May 22, 2008
AverTV Super 007 on Linux ( Ubuntu )
I recently purchased this tuner card was disappointed to discover that it was not running on Ubuntu 8.04, I read forums and was happy to know that it was not impossible, but the issue was that a lot of stuff was written, I have filtered out to few steps that helped me to get the card working
- sudo apt-get install mercurial
- hg clone http://linuxtv.org/hg/v4l-dvb
- cd v4l-dvb
- sudo make
- sudo make load
PHP, MySQL Interview questions
- What are the differences between PHP4 & PHP 5.
- Give your ideas how you can scale up a LAMP based website.
- Which design pattern is used by Symfony.
- what is the difference between pass by value and pass by reference.
- Describe the highlights of MVC architecture.
- How many types of tables does MySQL have.
- What are the differences between MyIASM and INNODB table types.
- What could be a possible reason if someone is looking to store session information inside a database, what are the steps involved in doing the same.
- How would you do clustering in MySQL.
- What are the different types of Indexes in MySQL.
- Explain FullText index in MySQL.
- Can we overwrite a row using insert in MySQL if the primary key is unique.
- Suggest some optimization steps in MySQL and sql queries.
- How would you create a function which would accept variable number of inputs.
Thursday, May 8, 2008
Postgres showprocesslist
Looking for something like showporcesslist for postgres, here is something I found.
Edit your postgres.conf
This must be set to true for the statistics collector to be launched at all.
This enables monitoring of the current command being executed by any server process. The statistics collector subprocess need not be running to enable this feature.
After restarting postgres the following query will show currently running queries
only as user "postgres"
Edit your postgres.conf
stats_start_collector = true
This must be set to true for the statistics collector to be launched at all.
stats_command_string = true
This enables monitoring of the current command being executed by any server process. The statistics collector subprocess need not be running to enable this feature.
After restarting postgres the following query will show currently running queries
psql -U postgres template1 -c "select * from pg_stat_activity"
only as user "postgres"
Monday, April 28, 2008
Weekend with Suse 11 Beta, FreeBSD
Last weekend I was ready to test SUSE 11 Beta ( 55 days were still to go before its release ) and FreeBSD. Installation of SUSE was great I felt like I am installing a Microsoft product, when I ran it for the first time KDE4 was really cool. I have been using Gnome since quite sometime now and recently KDE4 was a lot talked about in the air, so I wanted to give it a try.
I made some changes in the screen resolution and refresh rate. and restarted the xserver, to my surprise the taskbar didn't load, I restarted the machine but same issue, I then created a new user and the new user desktop was fine, but when I logged on to the new user again the same thing happened.
I reinstalled with Gnome, still many bugs, then I finally installed FreeBSD. as expected it was good from the optimal resource utilization angle, but user friendliness I guess Linux (especially Ubuntu) has an upper hand.
I made some changes in the screen resolution and refresh rate. and restarted the xserver, to my surprise the taskbar didn't load, I restarted the machine but same issue, I then created a new user and the new user desktop was fine, but when I logged on to the new user again the same thing happened.
I reinstalled with Gnome, still many bugs, then I finally installed FreeBSD. as expected it was good from the optimal resource utilization angle, but user friendliness I guess Linux (especially Ubuntu) has an upper hand.
Tuesday, April 22, 2008
OpenSUSE 11
This is something I am really excited about opensuse 11, I have used and loved enough of Fedora and recently Ubuntu and was always impressed by something different in OpenSUSE, but the only reason I could not use OpenSUSE was that SUSE was not very friendly to my hardware configuration, maybe this new release bridges the gap so that people like me could use it.
Its beta version is available freely for download.
Its beta version is available freely for download.
Thursday, April 17, 2008
Java based multi threaded webserver
Had nothing to do since last few days so decided to make a small webserver, it has a small configuration file also, here the code that I landed up creating
-----------------------------------------------------------------------
import java.io.*;
import java.net.*;
import java.util.Properties;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class myServer {
public static void main(String args[]) {
String configFileName="config.properties";
String docRoot="";
int portNumber=80;
// ---- Load configuration file. ------
try {
configFileName = args[0];
}
catch(ArrayIndexOutOfBoundsException aioobe){
//Look for default configuration file.
}
try{
Properties properties = new Properties();
properties.load(new FileInputStream(configFileName));
System.out.println("Using configuration file "+configFileName);
portNumber = Integer.parseInt(properties.getProperty("port"));
docRoot = properties.getProperty("documentRoot");
}
catch(IOException ioex){
System.out.println("\nConfiguration file not found.\nPlease specify config file to use\nExample:\n\tjava myServer "+configFileName);
return;
}
// declare a server socket and a client socket for the server
ServerSocket echoServer = null;
Socket clientSocket = null;
// declare an input and an output stream
String line="";
DataInputStream is;
PrintStream os;
// Try to open a server socket on port 9876
try {
echoServer = new ServerSocket(portNumber);
System.out.println("HTTP Server started at port number "+Integer.toString(portNumber)+", Document root as "+docRoot+"\nTo stop server press ^c");
}
catch (IOException e) {
System.out.println(e);
}
while(true){ // Server runs infinitely.
try {
clientSocket = echoServer.accept();
is = new DataInputStream(clientSocket.getInputStream());
os = new PrintStream(clientSocket.getOutputStream());
for (int i=1;i<5 ;i++ ){
line = line.concat(is.readLine());
}
Runnable runnable = new HandleClient(os, line, docRoot);
Thread thread = new Thread(runnable);
thread.start();
line="";
}
catch (IOException e) {
System.out.println(e);
}
}
}
}
class HandleClient implements Runnable{
PrintStream printStream;
String clientData;
String requestFileName;
String docRoot;
public HandleClient(PrintStream in_printStream, String in_clientData, String in_docRoot){
this.printStream = in_printStream;
this.clientData = in_clientData;
this.docRoot = in_docRoot;
//Set filename
this.requestFileName = this.clientData.substring(3, this.clientData.indexOf("HTTP/1.1")).trim().replaceAll("/", "\\\\");
this.requestFileName = this.docRoot.concat(this.requestFileName);
}
public void run(){
try {
//System.out.println("About to serve "+this.requestFileName);
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
File file = new File(this.requestFileName);
if (file.exists()){
//System.out.println("File Exists");
}
else{
System.out.println("File does not Exist "+this.requestFileName);
this.printStream.println("Not found.");
this.printStream.close();
return;
}
fis = new FileInputStream(file);
// Here BufferedInputStream is added for fast reading.
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
// dis.available() returns 0 if the file does not have more lines.
while (dis.available() != 0) {
// this statement reads the line from the file and print it to
// the console.
//this.printStream.println(dis.readLine());
this.printStream.write(dis.read());
}
this.printStream.close();
// dispose all the resources after using them.
fis.close();
bis.close();
dis.close();
//System.out.println("served "+this.requestFileName);
} catch (FileNotFoundException e) {
e.printStackTrace();
this.printStream.println("Not found.");
this.printStream.close();
return;
} catch (IOException e) {
e.printStackTrace();
this.printStream.println("Not found.");
this.printStream.close();
return;
}
}
}
---------------------------------------------------------------------------
--------- Configuration file --------------
#Configuration file
documentRoot=d:\\amit\\docroot
port=9999
errorPage=404.html
-----------------------------------------------------------------------
import java.io.*;
import java.net.*;
import java.util.Properties;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class myServer {
public static void main(String args[]) {
String configFileName="config.properties";
String docRoot="";
int portNumber=80;
// ---- Load configuration file. ------
try {
configFileName = args[0];
}
catch(ArrayIndexOutOfBoundsException aioobe){
//Look for default configuration file.
}
try{
Properties properties = new Properties();
properties.load(new FileInputStream(configFileName));
System.out.println("Using configuration file "+configFileName);
portNumber = Integer.parseInt(properties.getProperty("port"));
docRoot = properties.getProperty("documentRoot");
}
catch(IOException ioex){
System.out.println("\nConfiguration file not found.\nPlease specify config file to use\nExample:\n\tjava myServer "+configFileName);
return;
}
// declare a server socket and a client socket for the server
ServerSocket echoServer = null;
Socket clientSocket = null;
// declare an input and an output stream
String line="";
DataInputStream is;
PrintStream os;
// Try to open a server socket on port 9876
try {
echoServer = new ServerSocket(portNumber);
System.out.println("HTTP Server started at port number "+Integer.toString(portNumber)+", Document root as "+docRoot+"\nTo stop server press ^c");
}
catch (IOException e) {
System.out.println(e);
}
while(true){ // Server runs infinitely.
try {
clientSocket = echoServer.accept();
is = new DataInputStream(clientSocket.getInputStream());
os = new PrintStream(clientSocket.getOutputStream());
for (int i=1;i<5 ;i++ ){
line = line.concat(is.readLine());
}
Runnable runnable = new HandleClient(os, line, docRoot);
Thread thread = new Thread(runnable);
thread.start();
line="";
}
catch (IOException e) {
System.out.println(e);
}
}
}
}
class HandleClient implements Runnable{
PrintStream printStream;
String clientData;
String requestFileName;
String docRoot;
public HandleClient(PrintStream in_printStream, String in_clientData, String in_docRoot){
this.printStream = in_printStream;
this.clientData = in_clientData;
this.docRoot = in_docRoot;
//Set filename
this.requestFileName = this.clientData.substring(3, this.clientData.indexOf("HTTP/1.1")).trim().replaceAll("/", "\\\\");
this.requestFileName = this.docRoot.concat(this.requestFileName);
}
public void run(){
try {
//System.out.println("About to serve "+this.requestFileName);
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
File file = new File(this.requestFileName);
if (file.exists()){
//System.out.println("File Exists");
}
else{
System.out.println("File does not Exist "+this.requestFileName);
this.printStream.println("Not found.");
this.printStream.close();
return;
}
fis = new FileInputStream(file);
// Here BufferedInputStream is added for fast reading.
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
// dis.available() returns 0 if the file does not have more lines.
while (dis.available() != 0) {
// this statement reads the line from the file and print it to
// the console.
//this.printStream.println(dis.readLine());
this.printStream.write(dis.read());
}
this.printStream.close();
// dispose all the resources after using them.
fis.close();
bis.close();
dis.close();
//System.out.println("served "+this.requestFileName);
} catch (FileNotFoundException e) {
e.printStackTrace();
this.printStream.println("Not found.");
this.printStream.close();
return;
} catch (IOException e) {
e.printStackTrace();
this.printStream.println("Not found.");
this.printStream.close();
return;
}
}
}
---------------------------------------------------------------------------
--------- Configuration file --------------
#Configuration file
documentRoot=d:\\amit\\docroot
port=9999
errorPage=404.html
Subscribe to:
Posts (Atom)