Download General How long have you been programming? 6 years on the job

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
General
1.
2.
3.
4.
5.
How long have you been programming? 6 years on the job, 3 years in school
When did you start/learn programming? Pascal course in 1994 at UT Austin
First Programming language? Pascal
Rate your Java knowledge level from 1 to 10: 10 is expert level and 1 is very new to Java? 6
How lines of Java would you estimate that you’ve written? 5000
Java
1.
2.
3.
4.
5.
6.
7.
8.
9.
What is the name of the class that is super class for every Java classes? Object
What is the entry method to invoke Java class? Public static void main(String[] args)
Can you extend Java String class java.lang.String? No (final class)
What primitives are defined in Java? int, short, long, char, boolean, arrays, float, double
Java doesn’t support multi-inheritance. What feature of Java is used to simulate multiple-inheritance in Java? interface
What is the difference between class constructor and class method? Constructor called when object is first instantiated,
used to initialize object variables. Method performs logic when it is invoked either by a client of the object or when called
within the constructor.
What is passing by value? Passing by reference? Is Java passing by value or passing by reference? Passing by value is
sending a copy of the parameters into the body of the method, not the original passed in variables themselves. Pass by
reference is passing a “pointer” to the parameter variables into the method body, where the method can change the values
of the original variables that exist outside the scope of the method. Java is pass by value, where primitives pass copies of
the value into the method, and objects pass a copy of the references.
What is encapsulation? Inheritance? Polymorphism? Encapsulation is using objects to contain variables and methods,
where users can only get access or update the object variables through method calls (setters, getters, other methods).
Inheritance is where a programmer can extend a class to include the methods and variables of a superclass but can also
provide new variables and methods in the subclass. Polymorphism means “many shapes” and means that a user can
override method calls in subclasses or overload method calls within an existing class.
What is difference between “Y”.equals(x) and x.equals(“Y”). Here x is a string variable? For the first one, the string constant
“Y” is being converted to a string object and then “equals()” is being called on the string object, using the “x” string as input
to the method. For the second one, “x” is already a string object, so “equals()” is simply called on it with the string constant
“Y” passed into the method.
10. Examine the following java code. What do you think about it? There should be a “default” case at the end, even though
irand will always be either 0, 1 or 2, in case programmer error removes any of the “break” statements. This kind of
programmer error is why switch/case statements should be replaced with if/else if/else statements.
Random rand = new Random();
int irand = rand.nextInt();
irand = irand % 3;
// switch all cases of irand and process case scenarios
switch (irand) {
case 0:
…………
break;
case 1:
…………
break;
case 2:
…………
break;
}
11. For the following code, what is printed?
public class Ref {
public static void check(StringBuffer buf) {
buf.append(“This is appended!”);
buf = new StringBuffer(“This is newly created!!”);
}
public static void main(String[] args) {
StringBuffer sb = new StringBuffer(“Hi, “);
check(sb);
System.out.println(sb.toString());
}
}
Hi, This is appended!
12. Write a Java Method to solve the following problem:
a. Evaluate the result of the series: 1-2+3-4+5-6+……+n (or –n depending on value of n).
public int evaluateSeries(int n){
int currentValue = 0;
int counter = 0;
int signMultiplier = 1;
for(int i=1; i<n; i++){
signMultiplier = (i % 2 == 0 ? -1 : 1);
currentValue += (i * signMultiplier);
}
return currentValue;
}
13. The following java code for Point class. What do you think about it? This code calls the “toString()” method on Point p to
concatenate with “”. The toString() method returns “this” (which itself calls the toString() method on Point’s superclass
Object, which returns a string representation of the object), adds to this the character “@” and adds to this the result of the
method “hashCode()” which is called on the superclass “Object”. hashCode() returns a character String that is unique for
the object “p”.
public class Point implements Serializable {
int x;
int y;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public String toString() {
return this + "@" + this.hashCode();
}
public static void main(String[] args) {
Point p = new Point();
p.setX(0);
p.setY(1);
System.out.println(""+p);
}
}
14. Turn the following code from recursive into non-recursive call:
public static HashMap dirwalk (String dirname) {
if (dirname == null)
dirname = ".";
File topdir = new File(dirname);
if (!topdir.exists())
return null;
HashMap map = new HashMap();
if (!topdir.isDirectory()) {
map.put(".", dirname);
return map;
}
String[] fs = topdir.list();
map.put(dirname, fs);
int size = fs == null ? 0 : fs.length;
for (int i = 0; i < size; i++) {
String fpi = dirname + File.separator + fs[i];
File ffi = new File(fpi);
if (ffi.isDirectory()) {
HashMap submap = dirwalk (ffi.getAbsolutePath());
map.putAll(submap);
}
}
return map;
}
Public static HashMap dirwalk2(String dirname){
if (dirname == null)
dirname = ".";
Stack<ArrayList<String>> dirStack = new Stack<ArrayList<String>>();
ArrayList<String> stackList = ArrayList<String>();
HashMap<String, String[]> map = new HashMap<String, String[]>();
File topdir = new File(dirname);
if (!topdir.exists())
return null;
if (!topdir.isDirectory()) {
map.put(".", dirname);
return map;
}
String[] fs = topdir.list();
stackList.add(dirname);
stackList.add(fs);
dirStack.push(stackList);
String fpi = “”;
File ffi = = null;
While(true){
try{
stackList = dirStack.pop();
dirname = stackList.get(0);
if (dirname == null)
dirname = ".";
File topdir = new File(dirname);
if (!topdir.exists())
continue;
if (!topdir.isDirectory()) {
map.put(".", dirname);
continue;
}
fs = stackList.get(1);
map.put(dirname, fs);
int size = fs == null ? 0 : fs.length;
for (int i = 0; i < size; i++) {
fpi = dirname + File.separator + fs[i];
ffi = new File(fpi);
if (ffi.isDirectory()) {
fs = ffi.list();
stackList = ArrayList<String>();
stackList.add(fpi);
stackList.add(fs);
dirStack.push(stackList);
}
}
}catch(EmptyStackException ese){
// leave the while loop when stack is empty ..
Break;
}catch(Exception e){
e.printStackTrace();
}
}
return map;
}
Database
1. What do you think about the following SQL Statement?
SELECT cm.customer_name
,cm.customer_no
,sa.order_no
,sa_order_dt
,sa.order_price
FROM cu_master cm
INNER JOIN sa_order so ON so.customer_no = cm.customer_no
“sa” may need to be “so”, but in any case there is no “sa” table alias shown. “sa_order_dt” has no prefix, so should be unique
between cu_master and sa_order tables, but this is probably a typo, where “order_dt” is probably the column name. It is
probably best to make join condition cm.customer_no = so.customer_no to match the order that the tables are
listed in the join statement, but it’s not required.
2.
What do you think about the following SQL Statement? How can it be rewritten?
SELECT cm.*
, a.*
FROM cu_master cm
INNER JOIN (SELECT * FROM sy_address) a ON a.ref_no = cm.customer_no
Don’t need cm.*, a.* syntax, just a single “*” will do this just as well. Second table in inner join doesn’t need to be a subquery, it can just be the table sy_address itself. Also, I would flip the order of the ON join statement to list cm first to reflect
the order of the inner join table names, but it’s not necessary.
SELECT * FROM cu_master cm INNER JOIN sy_address a ON cm.customer_no = a.ref_no
3.
Write a query that returns all the sales order for Customer # 12345 during the month of June:
SELECT * FROM sa_order
WHERE cu_master_id = ‘12345’ AND
order_dt BETWEEN ‘2014-06-01 00:00:00.000’ AND ‘2014-06-30 00:00:00.000’
4.
Using the following ER Diagram, write a query to select all vendors (Account # and Name), and any related contact records.
Sort the records by vendor and contact type. NOTE: there are three different contact types: PUR=Purchasing, AP=Payables,
& OTH=Other
SELECT vm.vendor_no, vm.company_name, vmc.*, sc.*
FROM vn_master vm FULL OUTER JOIN vn_master_contact vmc ON vm.id = vmc.vn_master_id FULL OUTER JOIN sy_contact
sc ON vmc.sy_contact_id = sc.id
WHERE vmc.contact_type IN (‘PUR’, ‘AP’, ‘OTH’)
ORDER BY vm.vendor_no, vmc.contact_type