Monday, April 7, 2008

Pimp My Ride - Geek Style

Went to Fry's Electronics Sunnyvale

Got:


PC Case: Apevia X-QPACK2


Graphics Card: BFG 9600GT



Main Memory: Corsair 2DMM 2GB

Processor: Intel Core2Quad 2.4GHz 8MB Cache

Hard Disk: Maxtor 500 GB HD

Motherboard: Intel DQ35JO

Monitor: Samsung 22" LCD 800:1 DC

OS: Windows XP Pro

Game Headset: Inland Vibration

Game Mouse: Razer DeathAdde Infrafred (Glowing Heartbeat!)

Game Keyboard: Saitek blue LED backlighting

Tuesday, February 12, 2008

Architect Questions

How do you ensure scalability in J2EE environment?


what version of hibernate have you used?

What parts of J2EE architecture do you recommend to avoid?

Friday, February 8, 2008

Interview Questions that were interesting...

Have you used Distributed Cache Product

http://www.oracle.com/products/middleware/coherence/index.html

The Leading Distributed In-Memory Data Grid Solution
Oracle Coherence is a component of Oracle Fusion Middleware that enables organizations to predictably scale mission-critical applications by providing fast and reliable access to frequently used data. By automatically and dynamically partitioning data in memory across multiple servers, Oracle Coherence enables continuous data availability and transactional integrity, even in the event of a server failure. As a shared infrastructure, Oracle Coherence combines data locality with local processing power to perform real-time data analysis, in-memory grid computations, and parallel transaction and event processing. Oracle Coherence comes in three editions. Find the edition that's right for you.

Announcing Oracle Coherence 3.3
Among many enhancements in the new release are improved performance, Quality-of-Service and clustering capabilities, and support for Microsoft's .NET Framework.

Do you know what a Covariant return type?

In J2SE 5 a method in a subclass may return an object whose type is a subclass of the type returned by the method with the same signature in the superclass. This feature removes the need for excessive type checking and casting.

More specifically, covariance of the return type refers to a situation where the return type of the overriding method is changed to a type related to (but different from) the return type of the original overridden method. The relationship between the two covariant return types is usually one which allows substitution of the one type with the other, following the Liskov substitution principle. This usually implies that the return types of the overridding methods will be subtypes of the return type of the overridden method. The above example specifically illustrates such a case.

http://en.wikipedia.org/wiki/Covariant_return_type

What is an anonymous class? What is it used for?

An anonymous class can be particularly useful in those cases where
There is no reason for an object of the anonymous class to exist in the absence of an object of the enclosing class.
There is no reason for an object of the anonymous class to exist outside a method of the enclosing class.
Methods of the object of the anonymous class need access to members of the object of the enclosing class.
Methods of the object of the anonymous class need access to final local variables and method parameters belonging to the method in which the anonymous class is defined.
Only one instance of the anonymous class is needed.
There is no need for the class to have a name that is accessible elsewhere in the program.

Write a bean class that utilizes generics in its syntax?

public class GenericsBean <T> {

private T t; // T stands for "Type"

public void set(T t) {
this.t = t;
}

public T get() {
return t;
}
}

Type Parameter Naming Conventions

E - Element (used extensively by the Java Collections Framework)
K - Key
N - Number
T - Type
V - Value
S,U,V etc. - 2nd, 3rd, 4th types


Hibernate version have you used?

EJB Version?

CDN experience content delivery networks

Easy Homework Assignment

Instructions

The following questions will help us assess your Java Programming skills. In all questions below, please make sure that the code you write is syntactically and semantically correct. Ideally, we should be able to compile and execute your code. Psuedo-code is not acceptable. Please read all instructions and directions before proceeding.

1. Is there a memory leak in the code below? If yes, can you spot the memory leak and fix the code to not leak?

public class Stack {
private Object[] elements;
private int size = 0;

public Stack(int initialCapacity) {
this.elements = new Object[initialCapacity];
}

public void push(Object e) {
ensureCapacity();
elements[size ++] = e;
}

public Object pop() {
if(size == 0)
throw new EmptyStackException();
return elements[--size];
}

public void ensureCapacity() {
if(elements.length == size) {
Object[] oldElements = elements;
elements = new Object[2 * elements.length + 1];
System.arraycopy(oldElements, 0, elements, 0, size);
}
}
}

If the stack grows and then shrinks, the objects will not be garbage collected that are being popped off the stack. The method should be re-written as:

public Object pop() {
If (size > 0) {
Object returnVal = elements[--size];
elements[size] = null;
return returnVal;
}
return null;
}


2. Write a class StringUtil that has a method reverseElements that accepts a String array and which returns the SAME String array with the array elements in reverse order. The signature of reverseElements should be

Void reverseElements(String[] strArr)


If strArr is { “dog”, “cat”, “mouse”, “cow” } before calling reverseElements, it should be {“cow”, “mouse”, “cat”, “dog”} after the call.

Using any other extra collection/array should also be avoided. We want you to manipulate the contents of the strArr itself.

public class StringUtil {
public StringUtil() { }

public void reverseElements(String[] strArr) {
int left, right;

for (left=0, right=strArr.length-1; left < right; left++, right--) {
String temp = strArr[left];
strArr[left] = strArr[right];
strArr[right] = temp;
}
}
}

3. Write a unit test for StringUtil#reverseElements.

public void testReverseElements() {
String myStrArr[] = { "dog", "cat", "mouse", "cow" };
StringUtil mySU = new StringUtil();
mySU.reverseElements(myStrArr);
assertEquals("cow", myStrArr[0]);
assertEquals("mouse", myStrArr[1]);
assertEquals("cat", myStrArr[2]);
assertEquals("dog", myStrArr[3]);
}


4. Define class Foo such that there can at any time be exactly one instance of Foo.

public class Foo {
private static Foo myInstance;

private Foo() { }

public static Foo getInstance() {
if (myInstance == null)
myInstance = new Foo();

return myInstance;
}
}


5. class Bar {
private String _name;
private int _age;

Bar(String inName, int inAge) {
_name = inName;
_age = inAge;
}
}

Identify the base class of Bar. Bar is its own base class
Determine the method signature of equals in Bar’s base class equals(String, int)
Override and re-implement it such that the equals method returns true only if name and age match. In other words we want to be able to compare two Bar instances.

class FooBar extends Bar {
FooBar(String inName, int inAge) {
super(inName, inAge);
}

@Override
public boolean equals(String inName, int inAge) {
return super.equals(inName, inAge);
}
}


6. In the question above, if you override the equals method, is there any other method of class Object that needs to be overridden? If so, which one?

It is a general rule that if you override the equals() method you always override the hashCode() method also.

Wednesday, January 30, 2008

Perl Scripts

Perl script that I wrote

#!/usr/bin/perl
# validHPFF.pl

# Command Line Arguement processing
$numArgs = $#ARGV + 1;
if($numArgs == 1) {
# print "Input Directory = $ARGV[0]\n";
} else {
print "Not enough command line arguements were provided\n";
die "Usage: validHPFF.pl \n";
}

#Now get input directory and start to generate files into output directory
$currentPath = `pwd`;
chop($currentPath);
$inputDir = $currentPath . "/" . $ARGV[0];
# print "Input Directory = " . $inputDir . "\n";
#opendir(DIRHANDLE,$inputDir);
opendir(DIRHANDLE,$ARGV[0]);
@files = readdir(DIRHANDLE);
foreach $file (@files) {
if ( index($file, '.OUT') != -1) {
$infile = $ARGV[0] . '/' . $file;
open(INFILE, "$infile") or die "could not open $infile\n";
print "Validating file: " . $file . "\n";
$firstTime = 1;
# This while statement will load each line from infile
# and place its contents into a variable called $_
# and iterate through the file until EOF
$fileLineCount = 0;
while( ) {
$fileLineCount = $fileLineCount + 1;

# Header Section
if(m/^H/) {

# Validation section
@headerFields = split(/\/, $_);
$hfCount = 0;
foreach my $field (@headerFields) {
$hfCount = $hfCount + 1;
# print "header field " . $hfCount . ": $field\n";
if ( length($field) == 0) {
print "Error: Header field " . $hfCount . " is empty\n";
print "Error: Line number " . $fileLineCount . "\n";
}
}
if ( $hfCount != 2) {
print "Error: Header didn't have enough fields: " . $hfCount . " expected 2\n";
print $_ . "\n";
}
}

# Now check Account
if(m/^A/) {

# Validation section
@accountFields = split(/\/, $_);
$afCount = 0;
foreach my $field (@accountFields) {
$afCount = $afCount + 1;
# print "account field " . $afCount . ": $field\n";
if ( length($field) == 0) {
print "Error: Account field " . $afCount . " is empty, line number " . $fileLineCount . "\n";
}
}
if ( $afCount != 3) {
print "Error: Account didn't have enough fields: " . $afCount . " expected 3, line number: " . $fileLineCount . "\n";
print $_ . "\n";
}
}

# Billsummary section
if(m/^B/) {

# Validation section
@billsummFields = split(/\/, $_);
$bfCount = 0;
foreach my $field (@billsummFields) {
$bfCount = $bfCount + 1;
# print "billsumm field " . $bfCount . ": $field\n";
if ( length($field) == 0) {
print "Error: Billsumm field " . $bfCount . " is empty, line number " . $fileLineCount . "\n";
}
}
if ( $bfCount != 9) {
print "Error: Billsumm didn't have enough fields: " . $bfCount . " expected 9, line number: " . $fileLineCount . "\n";
print $_ . "\n";
}
}

# P Member section
if(m/^PM/) {
# $reportHash{"PM"} = $reportHash{"PM"} + 1;

# Validation section
@pmFields = split(/\/, $_);
$pfCount = 0;
foreach my $field (@pmFields) {
$pfCount = $pfCount + 1;
# print "pm field " . $pfCount . ": $field\n";
if ( length($field) == 0) {
if ( ($pfCount != 7) && ($pfCount != 9) && ($pfCount != 6) ) {
print "Error: PM field " . $pfCount . " is empty, line number " . $fileLineCount . "\n";
}
}
}
if ( $pfCount != 10) {
print "Error: PM didn't have enough fields: " . $pfCount . " expected 10, line number: " . $fileLineCount . "\n";
print $_ . "\n";
}
}

# PR section
if(m/^PR/) {
# $reportHash{"PR"} = $reportHash{"PR"} + 1;

# Validation section
@pmFields = split(/\/, $_);
$pfCount = 0;
foreach my $field (@pmFields) {
$pfCount = $pfCount + 1;
# print "pr field " . $pfCount . ": $field\n";
if ( length($field) == 0) {
if ( ($pfCount != 6) && ($pfCount != 8) && ($pfCount != 9) ) {
print "Error: PR field " . $pfCount . " is empty, line number " . $fileLineCount . "\n";
}
}
}
if ( $pfCount != 10) {
print "Error: PR didn't have enough fields: " . $pfCount . " expected 10 fields, line number: " . $fileLineCount . "\n";
print $_ . "\n";
}
}

# RA section
if(m/^RA/) {
# $reportHash{"RA"} = $reportHash{"RA"} + 1;

# Validation section
@raFields = split(/\/, $_);
$rfCount = 0;
foreach my $field (@raFields) {
$rfCount = $rfCount + 1;
# print "RA field " . $rfCount . ": $field\n";
if ( length($field) == 0) {
if ( ($rfCount != 6) && ($rfCount != 7) && ($rfCount != 8) &&
($rfCount != 10) && ($rfCount != 11) && ($rfCount != 12) &&
($rfCount != 13) ) {
print "Error: RA field " . $rfCount . " is empty, line number " . $fileLineCount . "\n";
}
}
}
if ( $rfCount != 15) {
print "Error: RA didn't have enough fields: " . $rfCount . " expected 15, line number: " . $fileLineCount . "\n";
print $_ . "\n";
}
}

# RD section
if(m/^RD/) {
# $reportHash{"RD"} = $reportHash{"RD"} + 1;

# Validation section
@rdFields = split(/\/, $_);
$rfCount = 0;
foreach my $field (@rdFields) {
$rfCount = $rfCount + 1;
# print "RD field " . $rfCount . ": $field\n";
if ( length($field) == 0) {
if ( ($rfCount != 7) && ($rfCount != 8) && ($rfCount != 11) ) {
print "Error: RD field " . $rfCount . " is empty, line number " . $fileLineCount . "\n";
}
}
}
if ( $rfCount != 13) {
print "Error: RD didn't have enough fields: " . $rfCount . " expected 13, line number: " . $fileLineCount . "\n";
print $_ . "\n";
}
}

# P section
if(m/^P\/) {
# $reportHash{"P"} = $reportHash{"P"} + 1;

# Validation section
@pFields = split(/\/, $_);
$pfCount = 0;
foreach my $field (@pFields) {
$pfCount = $pfCount + 1;
# print "P field " . $pfCount . ": $field\n";
if ( length($field) == 0) {
print "Error: P field " . $pfCount . " is empty, line number " . $fileLineCount . "\n";
}
}
if ( $pfCount != 13) {
print "Error: P didn't have enough fields: " . $pfCount . " expected 13, line number: " . $fileLineCount . "\n";
print $_ . "\n";
}
}

# Footer section
if(m/^F/) {
# $reportHash{"F"} = $reportHash{"F"} + 1;

# Validation section
@fFields = split(/\/, $_);
$fCount = 0;
foreach my $field (@fFields) {
$fCount = $fCount + 1;
# print "F field " . $pfCount . ": $field\n";
if ( length($field) == 0) {
print "Error: F field " . $fCount . " is empty, line number " . $fileLineCount . "\n";
}
}
if ( $fCount != 2) {
print "Error: F didn't have enough fields: " . $fCount . " expected 2, line number: " . $fileLineCount . "\n";
print $_ . "\n";
}
}
}

close (INFILE);
}
}

Friday, January 25, 2008

Eclipse Plugins

I have found a number of interesting articles over the years regarding eclipse that I think it would be useful to document for later referal:

Sangam Eclipse Plugin: http://sangam.sourceforge.net/
Useful for pair programming