I received a curious email today in response to my resume. It says nothing
about the position; the author wants me to answer a long sequence of questions
about Java before we talk again:
---------- Forwarded message ----------
From: amanda rocap <amandarocap@gmail.com>
Date: 2009/04/09
Subject: Java requirement
To: amandarocap@gmail.com
** CRAIGSLIST ADVISORY --- AVOID SCAMS BY DEALING LOCALLY
** Avoid: wiring money, cross-border deals, work-at-home
** Beware: cashier checks, money orders, escrow, shipping
** More Info: http://www.craigslist.org/about/scams.html
Hi,
Please answer the following questions and send it across,We have a
Java requirement.I will give a call once I receive a reply.
The Position Summary is as follows.
The sr. java developer will play a key role in developing new
technology initiatives for a very high growth organization. These new
initiatives will include content and contact management systems,
reporting systems, and other mission-critical applications as
appropriate. As a member of the dynamic and highly motivated
application development team, the systems and software developer plays
a key role in all aspects of the system development life cycle.
Depending upon the scope of each project, the systems and software
developer will work directly with business owners or through project
managers, but will always communicate closely with the rest of the
application development team. The sr. java developer reports to the
managing director, application development – architecture.
.......................................................................................
they need you to answer the test.do well.best of luck.
Java Fundamentals
1) Assume the Person class is defined and responds to
“updateAccessTime()” and “getName()”. You have a populated map,
“aMap”, that maps person name strings to Person instances. Identify
the problem in this code. How could the problem be fixed?
Person person = (Person) aMap.get("bob");
if (person != null) {
person.updateAccessTime();
}
String name = person.getName();
System.out.println(“name is ” + name);
Answer:
2) What does this code snippet print? Describe why it does so.
String b = "bob";
b.replace('b', 'p');
if (b.equals("pop")) {
System.out.println(“pop”);
} else {
System.out.println(“bob”);
}
Answer:
3) Somebody calls “new Thing("start stop")” to create a new Thing
object, but an error occurs. Identify the problem in the code below.
What change would you make to fix the problem?
public class Thing {
private List actions;
public Thing(String startingActions) {
StringTokenizer tokenizer = new StringTokenizer(startingActions);
while (tokenizer.hasMoreTokens()) {
actions.add(tokenizer.nextToken());
}
}
}
Answer:
SQL Knowledge
4) Based on the following table DDL, write a SQL query to select all
products and SKUs where the username was “google” and the date ordered
was between January 1, 2009 and March 15, 2009. Date format is
YYYY-MM-DD.
CREATE TABLE ‘product_order’ (
‘id’ int(10) unsigned NOT NULL auto_increment,
‘product’ varchar(45) NOT NULL,
‘sku’ varchar(45) NOT NULL,
‘desc’ varchar(45) NOT NULL,
‘username’ varchar(45) NOT NULL,
‘user_order_num’ varchar(45) NOT NULL,
‘date_ordered’ date NOT NULL,
‘creation_timestamp’ date NOT NULL,
PRIMARY KEY (‘id’)
);
Answer:
Identifying Bugs / Spring & Servlets Knowledge
5) Examine the following poorly-written servlet and Spring context
file. Assume correct web deployment descriptors, assume everything
compiles, etc.
MyServlet.java
package com.clearwire.stuff;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import org.springframework.*;
public class MyServlet extends HttpServlet {
private static Happy happy ;
private static Sad sad;
public void init(ServletConfig config) throws ServletException {
super.init(config);
happy = (Happy) SpringApplicationContext.getBean("happy");
sad = (Sad) SpringApplicationContext.getBean("sad");
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
if (request.getParameter("param").equalsIgnoreCase("happy")) {
happy = new Happy();
System.out.println(happy.message.toUpperCase());
}
else if (request.getParameter("param").equalsIgnoreCase("sad")) {
System.err.println(sad.message.toLowerCase());
}
else {
out.println("Panic!");
}
}
public static class Happy {
public String message;
}
public static class Sad {
public String sadMessage;
}
}
ApplicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans>
<bean id="happy" class="com.clearwire.stuff.MyServlet$Happy">
<property name=”message” value=“I’m very happy!”/>
</bean>
<bean id="sad" class="com.clearwire.stuff.MyServlet$Sad"/>
</beans>
5a) Explain what would happen if someone passed
‘http://localhost/myapp/MyServlet?param=happy’ to a machine running
this servlet within an appropriate servlet container.
Answer:
5b) What about ‘http://localhost/myapp/MyServlet?param=sad’? Why?
Answer:
5c) What about ‘http://localhost/myapp/MyServlet?param=foo’? Why?
Answer:
5d) What changes would you make to this code so that it functions as intended?
Answer:
Hibernate Knowledge
6) What is the purpose of the following annotation on an object?
@Entity
Answer:
7) What is the purpose of the following annotation on an object? Is
the “@Table” annotation always required for entities? If not, what is
the default table name?
@Table(name=”my_table”)
Answer:
8) What is the purpose of the following annotation on an object? Why
would you use this type of annotation?
@org.hibernate.annotations.Cache(usage =
org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE)
Answer:
9) What is the purpose of the following annotations on an object?
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
Answer:
Programming Challenge
10) You are standing at a point located at 50, 50 on a Cartesian X-Y
coordinate grid. The grid is shown in this elegant ASCII art: :)
100
^
|y
|
| x
0 +-------> 100
0
The grid's X values are in the range:
0 (x origin) to 100
The grid's Y values are in the range:
0 (y origin) to 100
You are given the following ten random points on the grid:
12, 34
95, 12
82, 6
7, 89
24, 57
53, 19
91, 5
32, 36
14, 68
23, 41
Write the code to print the 3 closest points to where you are
standing. You may write the code in Java or in detailed pseudocode.
HINT
The equation to find the distance D between any two points A and B is:
D = square root ( (By - Ay)^2 + (Bx - Ax)^2 )
<Answer question in the space below and on the next page>
Answer:
regards
amanda
------------------------------------------------------------------
this message was remailed to you via: res-jgana-1115071475@craigslist.org
------------------------------------------------------------------