Interview Questions for Java Engineers

Status
Not open for further replies.

green_buddy

Wise, Aged Ars Veteran
126
OFTS,

You are wise beyond your "smack-fu master, in training" my friend. I couldn't agree more with all you've said. Which prompts me to want to read every post you've ever posted! ;)

Anyway, my rant was related to something like the following...

The other day, the day after you posted your original BST question, which prompted me to do some quick re-reading on the subject, I was at an interview. I figured that they were going to ask me something about O(n) something or other, give me some kind of question involving BST's, and then a bunch of other stuff about what I had done. The funny thing was, when the interview came, I was exactly right... they asked me all of that. Exactly all of it. The bummer was that the O(n) question was the same as the BST question. They wanted me to write a search routine something like the following...

code:<HR>
Code:
<P>/* Search through an int[] and return true if any of the numbers add up to 7... ie. x + y = 7 */<P>boolean search (int[] a) {
  for (int indx = 0; indx < a.length; indx++) {
    int firstValue = a[indx];
    for (int j = indx + 1; j < a.length; j++) {
      int secondValue = a[j];
      if ((firstValue + secondValue) == 7) {
        return true;
      }
    }
  }
  return false;
}<P>

So that was the answer I threw out there in like 2 min. They just gave me the stub. So then, the interviewer was like... ok, so what's the order of that algorithm, and I said it was O(n^2). So far so good... I think!?! So then the interviewer was like... ok, so how would you optimize that without modifying the array? Meaning that you can't add things to a list of values that you had already searched, or reorder the list to know that once you had reached a number higher than 7 that you could discontinue searching... and I totally blanked. I thought about it for a minute, or two, and just totally blanked. Because eventhough I had written and could talk about how I created a persistence layer to get by having to waste 25K per cpu on weblogic to use their ejb server, I couldn't for the life of me figure out on the spot how I could optimize that call without just sorting and pre-sorting and massaging the list... then the interviewer said... what if you used a BST? And I can't tell you how stupid I felt. I had just looked at it, read up on it (granted it was like 2am and I was exhausted when doing it), but what the book failed to tell me was the shit I hadn't done in over 6 years... that it's used to reduce O(n^2) algorithms like the one above to O(1). So that just bummed me out, and made me laugh at myself. I think I even told the interviewer how embarrassed I was.

I thought instantly of your question, and hoped that I hadn't also done anything else to make me an unworthy candidate for the job, as if that wasn't enough already.

So then on my way home I started stewing about the typical stuff you stew about after a long-ass interview without any lunch. I was hoping that they'd judge me on the stuff that I knew, and what I had done, and how I had been able to talk intelligently about the stuff that I had worked on over the past several years. I had even written the exact same stuff as one of the interviewers. So we talked about some of that a little bit... incidentally, he also happened to be the same interviewer that asked me the BST question. :(

So anyway, the stewing got me to thinking about why I could talk intelligently about all this other shit, but couldn't talk intelligently about BST's. I mean, BST's are simple right? And they are, but they're not something that people need anymore, and that's why I couldn't answer the question even to my satisfaction... 'cause I usually don't ding people for not knowing their academic shit. I think formalized education is a joke, eventhough I have more than most! :rolleyes:

And the only answer I came up with is the one I posted above regarding how they don't make sense unless you're writing normal command-line utilities and the like. They're just not structures that are used anymore... for much of anything. Or atleast in nothing I've seen lately! :confused:

The other thing that generally bumms me out about technical interviews is that they invariably turn into a pissing contest. 'Cause you end up getting some guy in there who wants to prove that he's smarter than you, so he spends his time on a question trying to explain something, and all he ends up doing is confusing himself.

No doubt, I interviewed with this other guy at the same organization who wanted me to draw the arrows between nodes after inserting and removing things from a Linked List. But the problem was that he never said that. The whole time we were talking about designing an EntityCache for a persistence layer, and then he jumps in with:

And how would you remove that element?

I was kinda confused, and just looked at him and said, well... I'd call

code:<HR>
Code:
...
LinkedList someList = new LinkedList(aBunchOfItems);<P>someList.remove(whateverIndexYouWant);
...

And he said that was wrong. So then I was like... huh? What do you mean that's wrong? I'm prettysure that call exists in the java.util.LinkedList. And then he said... well, ok, let's forget about removing the object, how would you add it?

code:<HR>
Code:
...
LinkedList someList = new LinkedList(aBunchOfItems);<P>someList.add(someItem, whateverIndexYouWant);
...

He told me that was wrong again... And that's when I knew there was something we weren't connecting on so I asked him what he really meant? It took him 10 minutes to explain to me that he just wanted me to draw the head, tail, and next pointer arrows that you used to draw in your second semester CS course. At that point, I didn't know who was interviewing who? So I finally got that out of him, drew the pretty little arrows, and we moved on... but I'm sure that part of the interview dinged me, 'cause he was trying to pull his d*%k out and put it on the table :mad:, and for some reason wanted me to do the same. I just don't really operate like that. He wanted to get into a pissing contest over drawing arrows for addition and deletion of items in a Linked List. :eek:

All things I'd be concerned about if I was fresh out of school, but things that I have forgotten since I've finished my data structures and algorithms course.

However, I'm rapidly recognizing that I need to brush up on these outdated skills, 'cause people don't really care about if you know what you're doing, just if you can fit their mold. So my only alternative is to conquer the technical interview or say f*@k-it and become a Systems Engineer! :p

My problem there is that I really like writing code, and using my brain. :D

-green
 

green_buddy

Wise, Aged Ars Veteran
126
Ok OFTS,

I've got the answer to your Binary Tree question... just thought you and others... might be interested. It's a little more complex than you asked for, but I actually coded it out and debugged it completely... total time probably took about 45 min. from start to finish without any resources, and I answered the question a little more completely than you asked for...

Originally posted by OneFootsTheSame:
My "best" interview question goes something like this:

Let's work up a basic implementation of an Object Oriented binary tree with an integer key. Don't worry about implementations of add and delete, just declare your class or classes, any members you'll need, and create a search method that will tell me if a node exists in the tree with a given value. I'll also want to know how to use it. Please ask me any questions you have.

(...)

So, Mr. Green ... what's your answer? ;)

Here's my answer...

code:<HR>
Code:
package com.self.examples.bst;

/*
 * Node.java
 *
 * Created on February 17, 2002, 4:54 PM
 *
 * @author green_buddy
 */

public class Node {
    
    private int value;
    
    private int count = 0;
    
    /**
     * Creates a new node with value set to 0.
     */
    public Node () {
        this(0);
    }
    
    /**
     * Creates a new node with value set to val.
     */
    public Node (int val) {
        this.value = val;
        this.count++;
    }
    
    public boolean equals (Node item) {
        if (this.getValue() == item.getValue()) {
            return true;
        }
        
        return false;
    }
    
    public int getCount () {
        return this.count;
    }
    
    public void setCount (int total) {
        this.count = total;
    }
    
    public int getValue () {
        return this.value;
    }

    public void setValue (int val) {
        this.value = val;
    }
    
    public static void main (String[] args) {
        Node n1 = new Node();
        System.out.println("n1: " + n1.getValue());
        
        Node n2 = new Node(10);
        System.out.println("n2: " + n2.getValue());
        
        Node n3 = new Node(10);
        System.out.println("n3: " + n3.getValue());
        
        if (n1.equals(n2)) {
            System.out.println("n1 is equal to n2");
        } else {
            System.out.println("n1 is not equal to n2");
        }
        
        if (n2.equals(n3)) {
            System.out.println("n2 is equal to n3");
        } else {
            System.out.println("n2 is not equal to n3");
        }
    }        
}

package com.self.examples.bst;

/*
 * BinaryTree.java
 *
 * Created on February 17, 2002, 5:05 PM
 *
 * @author green_buddy
 */
public class BinaryTree {
    
    private Node root;
    
    private BinaryTree leftBranch;
    
    private BinaryTree rightBranch;        

    /**
     * Creates an empty BinaryTree.
     */
    public BinaryTree () {
        this(new Node(0));
    }
    
    /**
     * Creates an empty BinaryTree with root set to the Node item, 
     *  and left and right branches null.
     */
    public BinaryTree (Node item) {
        this.root = item;           
        this.leftBranch = null;        
        this.rightBranch = null;        
    }
    
    /**
     * Creates a BinaryTree out of an array of integers.
     */
    public BinaryTree (int[] array) {
        // get the first value of the array for the first node
        this.root = new Node(array[0]);
        
        // insert the rest of the array into the BinaryTree
        for (int i = 1; i < array.length; i++) {
            Node newNode = new Node(array[i]);
            this.insert(newNode);
        }        
    }
    
    public int getNodeCount () {
        return this.nodeCount(this);
    }
    
    /**
     * Gets the root node of this tree.
     *
     * @returns Node    The root node of this tree.
     */
    public Node getRoot () {
        return this.root;
    }
    
    /**
     * Checks this BinaryTree to see if it's a leaf node.  A 
     *  BinaryTree is a leaf node iff both the leftBranch and 
     *  rightBranch sub-trees are both null.
     *
     * @returns boolean Which is true iff both the left branch and 
     *  the right branch are null.
     */
    public boolean isLeaf () {
        if ((this.getLeftBranch() == null) &&
            (this.getRightBranch() == null)) {
            return true;
        }
        
        return false;
    }
    
    /**
     * Insert a node into the binary tree.
     */
    public void insert (Node item) {
        int rootValue = this.getRoot().getValue();
        
        if (item.getValue() == rootValue) { // increase the current element count
            
            int curCount = this.getRoot().getCount();
            this.getRoot().setCount(curCount + 1);
            
        } else if (item.getValue() < rootValue) {   // insert left branch
            
            if (this.getLeftBranch() == null) { // check the left branch to
                                                // make sure it's not null
                this.setLeftBranch(new BinaryTree(item));
                
            } else {    // insert the item into the LeftBranch
                
                this.getLeftBranch().insert(item);
            }
            
        } else {    // insert right branch
            
            if (this.getRightBranch() == null) {    // check the right branch to
                                                    // make sure it's not null
                this.setRightBranch(new BinaryTree(item));
                
            } else {    // insert the item into the RightBranch
                
                this.getRightBranch().insert(item);            
            }
        }               
    }
    
    /* stub */
    public void remove (Node item) {
        
    }
    
    /**
     * Searches this BinaryTree for the existance of the integer... 
     *  convenience method for just this instance of BinaryTree which 
     *  assumes that the Node's are based on IntegerNodes.
     */
    public boolean exists (int value) {
        return this.exists(new Node(value));
    }
    
    /**
     * Searches this BinaryTree for the existance of the node.
     */
    public boolean exists (Node item) {
        if (item.getValue() == this.getRoot().getValue()) {
            return true;
        } else {    // check left branch
            boolean left = this.getLeftBranch().exists(item);
            if (left) {
                return true;
            } else {    // check righ branch
                return this.getRightBranch().exists(item);
            }
        }        
    }
            
    /**
     * Counts the number of nodes in the tree including this node.
     *
     * @param tree  The BinaryTree that we are counting the number of 
     *   nodes in.
     *
     * @returns int The number of nodes in the tree including all 
     *   left & right branches and this node itself.
     */
    public int nodeCount (BinaryTree tree) {
        if (tree == null) {
            return 0;
        } else if (tree.isLeaf()) {
            return tree.getRoot().getCount();
        } 
        // get the node count of the left tree
        int leftNodes = this.nodeCount(tree.getLeftBranch());
        
        int rightNodes = this.nodeCount(tree.getRightBranch());
        
        // return the number of left nodes + right nodes + this node
        return (leftNodes + rightNodes + tree.getRoot().getCount());
    }
    
    /**
     * Gets the left-branch of this BinaryTree.
     */
    public BinaryTree getLeftBranch () {
        return this.leftBranch;
    }
    
    /**
     * Sets the left-branch of this BinaryTree.
     */
    public void setLeftBranch (BinaryTree left) {
        this.leftBranch = left;
    }
    
    /**
     * Gets the right-branch of this BinaryTree.
     */
    public BinaryTree getRightBranch () {
        return this.rightBranch;
    }
    
    /**
     * Sets the right-branch of this BinaryTree.
     */
    public void setRightBranch (BinaryTree right) {
        this.rightBranch = right;
    }
    
    /**
     * Prints the nodes in this BinaryTree.
     */
    public void print (String location) {
        if (this.getRoot() == null) {
            System.out.println(location + ": null");
        } else {
            System.out.println(location + ": " + 
                               this.getRoot().getValue());
            
            if (this.getLeftBranch() == null) {
                System.out.println(location + ":leftBranch: null");
            } else {                
                this.getLeftBranch().print(location + ":leftBranch");
            }
            
            if (this.getRightBranch() == null) {
                System.out.println(location + ":rightBranch: null");
            } else {
                this.getRightBranch().print(location +
                                            ":rightBranch");
            }
        }                
    }
    
    public static void main (String[] args) {
        int[] array = {2, 4, 9, 7, 5, 10, 1, 0};    
        
        BinaryTree bt = new BinaryTree(array);
        
        System.out.println("node count: " + bt.getNodeCount());
        
        bt.print("root");
    }
}

package com.self.examples.bst;

/*
 * BinarySearchTree.java
 *
 * Created on February 17, 2002, 6:22 PM
 *
 * @author green_buddy
 */
public class BinarySearchTree {
    
    private BinaryTree tree;

    /** 
     * Creates a new BinarySearchTree.
     */     
    public BinarySearchTree () {
        this(null);
    }
    
    public BinarySearchTree (BinaryTree bt) {
        this.tree = bt;
    }
    
    public BinaryTree getTree () {
        return this.tree;
    }
    
    public void setTree (BinaryTree bt) {
        this.tree = bt;
    }
    
    /**
     * Search this BinarySearchTree for the specified Node.
     */
    public boolean search (Node item) {
        Node root = this.getTree().getRoot();        
                
        if (root.equals(item)) {            
            return true;            
        } else {    // search the left-branch
            boolean left = false;
            
            if (this.traverseLeftBranch().getTree() != null) {
                
                left = this.traverseLeftBranch().search(item);
            }
            
            if (left) {
                return true;
            } else {    // search the right-branch
                boolean right = false;
                    
                if (this.traverseRightBranch().getTree() != null) {
                    right = this.traverseRightBranch().search(item);
                }
                    
                return right;
            }
        }
    }
    
    /**
     * Traverses the left branch of this BinarySearchTree.
     */
    public BinarySearchTree traverseLeftBranch () {
        BinaryTree leftBranch = this.getTree().getLeftBranch();
                
        return (new BinarySearchTree(leftBranch));
    }
    
    /**
     * Traverses the right branch of this BinarySearchTree.
     */    
    public BinarySearchTree traverseRightBranch () {
        BinaryTree rightBranch = this.getTree().getRightBranch();
        
        return (new BinarySearchTree(rightBranch));
    }
    
    public static void main (String[] args) {
        
        int[] array = {7, 9, 4, 6, 8, 10, 3, 1};
        
        BinaryTree bt = new BinaryTree(array);               
        
        BinarySearchTree bst = new BinarySearchTree(bt);
        
        Node n1 = new Node(3);
                                
        if (bst.search(n1)) {
            System.out.println(n1.getValue() + " - found");
        } else {
            System.out.println(n1.getValue() + " - not found");
        }
        
        Node n2 = new Node(5);
        
        if (bst.search(n2)) {
            System.out.println(n2.getValue() + " - found");
        } else {
            System.out.println(n2.getValue() + " - not found");
        }
    }
}

So OFTS, is that acceptable? Granted, I think you lose some information that you're looking for by not being able to judge my reaction to the question, and also not being able to ask me any interim questions probably hurts as well... and my answer is a bit longer than 20 lines! ;)

Originally posted by lensam69:

Q: Does Java support recursive functions?
A: Yes.

It's the simple questions in life that screw us...

Well... my above answer to BST, definitely proves that point! ;)

Ok... next! :D

-green
 

OneFootsTheSame

Smack-Fu Master, in training
70
You are wise beyond your "smack-fu master, in training" my friend. I couldn't agree more with all you've said. Which prompts me to want to read every post you've ever posted!

Hi Green. Wow ... I sure appreciate the vote of confidence, but I'm afraid you may be disappointed if you actually try to read all my posts. I'm as full of shit as everyone else. :)

That's pretty cool about your interview. I'm glad you were prepared for it.

Your answer is way more then I would expect in an interview situation, especially considering what I usually get. I'm generally happy if they can declare a class with the int value and references for the child nodes and then actually write a method that check the value for the current node and then passes the request to the children if necessary. But, I'll take a look at it when I get a bit of time. Currently I'm in Chicago on business, so I don't have much in the way of free time.

So, how did it go with the interview? Any offers yet? :D
 
And the funny thing is... everywhere I've worked so far, never has any implementations of Binary Search Trees, or Binary Trees for that matter for anything. So if they're so important... why aren't they everywhere? Why isn't there an implementation of it in any of the jdk's? More specifically, why isn't there a java.util.tree.* package which includes a BinaryTree, and BinarySearchTree in addition to others?

Why isn't there a java tree in the SDK? Because there is. Check out the TreeMap class; it's a perfectly good implementation of a Red-Black BST. As for never seeing a company which used them: you probably have, but they've just been located under the surface where they should be. For example, many databases store information in BSTs. Finally, I forget the name of the award, but there's an award for the most important contribution of CS theory to practice. About ten years ago, one of the winners was Dan Sleater and Robert Tarjan for Splay Trees, an extension to the BST data type which provides amortized O(lg n) access, find, and insert times with no extra data storage. I find it hard to believe that something as trivial as you claim would win that.

floccinau
 

Handor

Ars Tribunus Militum
2,513
I had just looked at it, read up on it (granted it was like 2am and I was exhausted when doing it), but what the book failed to tell me was the shit I hadn't done in over 6 years... that it's used to reduce O(n^2) algorithms like the one above to O(1).

Um, in what way can a BST reduce any operation to O(1)? Maybe I'm misunderstanding the question, but unless you are looking for the root node there is no O(1) operation in a BST. It's all O(log n), optimally. And I'm certain there's no O(1) solution to the problem you proposed... so am I missing something?
 

Quaro

Ars Scholae Palatinae
803
I can't think of an O(1) solution either, I think he must have meant something else by saying O(1). I'd be really interested in what you meant.

And yeah, I agree, BSTs are used in java all the time. You can change any collection into a treemap or whatever and keep the same code even. You rarely code them for the same reason you rarely code a linked list -- they are SO useful and SO common that they are built right in.
 

green_buddy

Wise, Aged Ars Veteran
126
Originally posted by floccinau:

Why isn't there a java tree in the SDK? Because there is. Check out the TreeMap class; it's a perfectly good implementation of a Red-Black BST. As for never seeing a company which used them: you probably have, but they've just been located under the surface where they should be. For example, many databases store information in BSTs. Finally, I forget the name of the award, but there's an award for the most important contribution of CS theory to practice. About ten years ago, one of the winners was Dan Sleater and Robert Tarjan for Splay Trees, an extension to the BST data type which provides amortized O(lg n) access, find, and insert times with no extra data storage. I find it hard to believe that something as trivial as you claim would win that.

floccinau

Thanks for the pointer... I don't know why I've never taken a look at this class before. I even checked out the 'All Classes' link and scrolled down through all the available classes in jdk1.4 and looked through some of the stuff starting with Tree* (ie. TreeCellEditor, TreeNode, etc.), and I noticed that all that stuff related to the java.swing.tree.* package... skimmed right over TreeMap, and TreeSet without even looking at it! :eek: Doh!!! I hate posting shit that's wrong that's right in front of my face! :rolleyes:

But then again... that's why I use ars, 'cause I don't claim to know everything, and I want to learn more, from you guys, so that I can be better at what I do, so thanks for showing me the way!

Regarding your quote for Splay Trees and the like... good one! A little history to straighten me out is always a good way to reprimand someone who oversteps his bounds! :eek:

I just have one question for you floccinau... what's a "Wise, Aged Ars Veteran" doing not knowing how to properly use the 'Quote' button? ;)

Originally posted by Handor:

Um, in what way can a BST reduce any operation to O(1)? Maybe I'm misunderstanding the question, but unless you are looking for the root node there is no O(1) operation in a BST. It's all O(log n), optimally.

Yes Handor (and others), I'm sorry, you're right, I mis-typed/mis-thought... in fact, it didn't make much sense to me either when I was typing it the first time, nor when I heard the interviewer tell me that it reduced things to O(1)... I was pretty much just regurgitating, not to mention the fact that it should be obvious to you all now that I think that O-notation is largely academic at this point. I don't really concern myself with thinking about it anymore. I mean, seriously... does anyone sit in meetings anymore discussing the order of your algorithms you are using... seriously? :confused:

I just can't remember the last time I've ever sat in on in a meeting like that!

But by any means... the thing I hate about engineering interviews are the pissing contests that some interviewers tend to like getting into. It seems that's the only way some engineers can find value in themselves... by pointing out how much more they think they know than you! :rolleyes:

Originally posted by OneFootsTheSame:

So, how did it go with the interview? Any offers yet? :D

Nope... not yet. But I did get a call back from the interview, but for a different position. They hired another, seemingly more senior guy, for the server-side position, but they're going to give me a shot at a client-side job... atleast giving me equal chance to interview for it, which is all I ask for. Just give me a shot. I don't like getting rejected... does anyone? But atleast I'd like a shot at a job, and I'll take that over no shot anyday. I can deal with the rejection later! ;)

Which brings another question to mind. When you're talking about J2EE, would you consider Servlet's/JSP's to be included in that?

I would, but apparently some recruiters do not. Any thoughts on why, or can you just chalk it up to the fact that you're dealing with a recruiter? :cool:

Anyways, are there any other cool interview questions, or is it all just damn O-notation bullshit that anyone cares about? It's not like I'm fresh out of college... it's been like 5 years... why the hell do people still care about O-notation? There's gotta be more to engineering... arsians!?! :confused:

-green
 

green_buddy

Wise, Aged Ars Veteran
126
Originally posted by Level_7:
Cool. I love how nowadays the word engineer is tacked on to just about anything that isn't clearly art.

Java Engineer
Database Engineer
C++ Engineer
Game Engineer
PC Engineer


Hmmm...

That's a very interesting statement, but I think the above all do apply to the term engineer... As far as I can tell Engineering defined:

1 : to lay out, construct, or manage as an engineer
2 a : to contrive or plan out usually with more or less subtle skill and craft b : to guide the course of

Although, I also see it as something extremely creative.

-green
 
That's a very interesting statement, but I think the above all do apply to the term engineer... As far as I can tell Engineering defined:
quote:

1 : to lay out, construct, or manage as an engineer
2 a : to contrive or plan out usually with more or less subtle skill and craft b : to guide the course of

Although, I also see it as something extremely creative.

Haha.

Its funny when someone who doesn't really understand what something is and pulls out the dictionary.

There is no argument here.

There is no such thing as a Java Engineer, or a Game Engineer, or any of the ones I mentioned above.

The correct definition if you want to play the dictionary game is as follows.

en·gi·neer n.
1. One who is trained or professionally engaged in a branch of engineering.
2. One who operates an engine.
3. One who skillfully or shrewdly manages an enterprise.

tr.v. en·gi·neered, en·gi·neer·ing, en·gi·neers
1. To plan, construct, or manage as an engineer.
2. To alter or produce by methods of genetic engineering: 'Researchers... compared insulin manufactured by bacteria genetically engineered with recombinant DNA techniques to the commercial insulin obtained from swine or cattle' (Fusion).
3. To plan, manage, and put through by skillful acts or contrivance; maneuver.


[Middle English enginour, from Old French engigneor, from Medieval Latin ingeni tor, contriver, from ingeni re, to contrive, from Latin ingenium, ability. See engine.]

engineer

n 1: a person who uses scientific knowledge to solve practical problems

The point is that you are an engineer 'if and only if' you are of an engineering discipline.

en·gi·neer·ing n.

The application of scientific and mathematical principles to practical ends such as the design, manufacture, and operation of efficient and economical structures, machines, processes, and systems.
The profession of or the work performed by an engineer.

Let me list the engineering disciplines accredited as such:

Computer Engineering
Electrical Engineering
Mechanical Engineering
Civil Engineering
Chemical Engineering
Geological Engineering
Engineering Science (or Systems Design Engineering)

Of course if you were an engineer, you'd know all of the above already.

Are you "trained or engaged in a branch of engineering"? If yes, you are an engineer. If not, no. That's it.

Also, you forget that engineering is a professional degree. Do you go around calling yourself a lawyer or doctor? No. But calling yourself an engineer is somehow okay? Engineers are legally liable for their designs and go through rigourous programs unlike others. Engineering programs and engineering mentality and jobs are alot different.

But again, you'd know that if you were an engineer.

CS is not engineering. Math is not engineering. Java (coding) is not engineering.
 

green_buddy

Wise, Aged Ars Veteran
126
Originally posted by Level_7:

Haha.

Its funny when someone who doesn't really understand what something is and pulls out the dictionary.

There is no argument here.

There is no such thing as a Java Engineer, or a Game Engineer, or any of the ones I mentioned above.

The correct definition if you want to play the dictionary game is as follows.

en·gi·neer n.
1. One who is trained or professionally engaged in a branch of engineering.
2. One who operates an engine.
3. One who skillfully or shrewdly manages an enterprise.

tr.v. en·gi·neered, en·gi·neer·ing, en·gi·neers
1. To plan, construct, or manage as an engineer.
2. To alter or produce by methods of genetic engineering: 'Researchers... compared insulin manufactured by bacteria genetically engineered with recombinant DNA techniques to the commercial insulin obtained from swine or cattle' (Fusion).
3. To plan, manage, and put through by skillful acts or contrivance; maneuver.


[Middle English enginour, from Old French engigneor, from Medieval Latin ingeni tor, contriver, from ingeni re, to contrive, from Latin ingenium, ability. See engine.]

(1) you're off topic, and I'd respect if you took this up in the Battlefront room.

(2) I find your use of the dictionary remarkable... did they teach you that in high-school or college?

The point is that you are an engineer 'if and only if' you are of an engineering discipline.

(3) Correct... at least you know a little something about induction.

I find your argument as flawed as it is immature. Your mis-understanding of the above is so fundamentally flawed that it's no wonder you're still in college. That kind of logic would never apply in the real world. Yes, I agree with you abou the following...

en·gi·neer·ing n.

The application of scientific and mathematical principles to practical ends such as the design, manufacture, and operation of efficient and economical structures, machines, processes, and systems.
The profession of or the work performed by an engineer.

However, the fundamental engineering discipline is mathematics so that has to be added to your list below. This is the reason that so many engineering organizations depend on mathematicians, and physicists for their research. Mathematics is the fundamental language by which everything is understood, and applied.

Let me list the engineering disciplines accredited as such:

Computer Engineering
Electrical Engineering
Mechanical Engineering
Civil Engineering
Chemical Engineering
Geological Engineering
Engineering Science (or Systems Design Engineering)

Of course if you were an engineer, you'd know all of the above already.

Are you "trained or engaged in a branch of engineering"? If yes, you are an engineer. If not, no. That's it.

Also, you forget that engineering is a professional degree. Do you go around calling yourself a lawyer or doctor? No. But calling yourself an engineer is somehow okay? Engineers are legally liable for their designs and go through rigourous programs unlike others. Engineering programs and engineering mentality and jobs are alot different.

But again, you'd know that if you were an engineer.

CS is not engineering. Math is not engineering. Java (coding) is not engineering.

And let me try and prove to you why Computer Science is an engineering discipline as well... especially if you consider yourself a Software Engineer.

By the definitions you posted above... which are a little more complete than the ones I summarized you say, and I agree with that,

2. One who operates an engine.

does qualify one as an Engineer.

Turing Machine

Turing Machines are considered to be Engines. They do work on an input to produce an output.

Computer Programs are very sofisticated Turing Machines. Some Computer Scientists specialize in the discipline of Software Engineering. I'm sure this course exists at your school too, you should take your argument to one of the Software Engineering professors on your campus and see what he/she says.

All Computer Scientists with a Computer Science degree are trained at some level in writing programs.

Therefore, Computer Science is considered to be an Engineering discipline.

But I'll start a topic in the Battlefront so you can post to that. Please keep this thread for what I tried to make it.

So what I suggest you do is stay in school, grow up a little, and then maybe you'll be ready for the real world when you get out.

-green

[This message was edited by green_buddy on February 23, 2002 at 00:24.]
 

green_buddy

Wise, Aged Ars Veteran
126
Originally posted by Richard Berg:
Write a swap function, i.e. the equivalent of
<BLOCKQUOTE class="ip_ubbcode_code">code:<HR>
Code:
template<class T>
void swap(T & a, T & b)
{
  T & c = a;
  a = b;
  b = c;
}
Not terribly difficult but forces you to think critically about what goes on behind the scenes in Java; the direct analogue to C++ certainly won't work.<HR></BLOCKQUOTE>

Yes, that's for sure... the direct anaologue to C++ won't work! I played around with this for a while, but couldn't really come up with a solid answer to the question that I was happy with. I just proved to myself why it wouldn't work... and then I found this online, but the reference, while a good explanation, still doesn't write a swap routine that would do what you asked.

Anyone care to post an answer? This is a really good fundamental question, but not one that's readily apparent! :rolleyes:

-green
 

EgalitarianBovine

Ars Tribunus Angusticlavius
8,086
green_buddy:

I don't think it's possible. It's impossible to take the address of a variable in Java. C++ references are essentially pointers with value semantics.

The only thing I could think of is macros, which Java does not officially support.

Richard Berg:

I'd be really interested in hearing what you think is the direct Java analogue for that C++ code. I can't think of any.

-EB
 
Originally posted by green_buddy:

Which brings another question to mind. When you're talking about J2EE, would you consider Servlet's/JSP's to be included in that?

I would, but apparently some recruiters do not. Any thoughts on why, or can you just chalk it up to the fact that you're dealing with a recruiter? :cool:

Hi there... this is my first official post on Ars. :) I come from the [H], but their programming forum is a little weak, and not nearly as Java-knowledgeable as this one... I can see I will be coming here frequently! :)

To your question, green... Absolutely. J2EE (Java 2 Enterprise Edition) is comprised of all the classes and SDKs involved in server-side web-to-client programming. This includes EJB, JSP, Servlet, and some miscellaneous XML parsing, security, and data layer stuff. In fact, if you check out the official API documentation for the J2EE 1.3.1 SDK here, you will be able to see all the packages that are included in the official API.

A lot of recruiters are pretty stupid... they only get paid if you get the job, so they try to sell you like you're Linus Torvalds to every customer, just because more interviews increases the odds that they'll get paid for all the time they spent on you. :) It's hard to believe that now, after all the economic shakedown, that there's still one in the business of finding Java resources that doesn't know that JSP/Servlet is part of J2EE, but hey, I guess they can't learn everything. :)

Anyway, I'd like to throw in my two cents and stir up this discussion by saying that I would walk out of any interview where they gave me a "pop quiz", language or otherwise... specific knowledge means squat, you hire a person based on what they can accomplish for you Big Picture. I couldn't solve that stupid problem that was posted if my life depended on it, but then again, there's more to modern J2EE programming than... well, programming. Sure, the better programmers will have more of these algorithmic patterns stuffed into their heads, but there is a LOT of architecture, object design, hardware system, and XML knowledge required by modern Java programmers/architects, and all questions like that do is tell you who comes from a C++ background. :) No offense meant to anybody... those are just my thoughts...
 

green_buddy

Wise, Aged Ars Veteran
126
Originally posted by EgalitarianBovine:
green_buddy:
I don't think it's possible. It's impossible to take the address of a variable in Java. C++ references are essentially pointers with value semantics.

Yes, that's what I understood as well, which is what was so puzzling, however, I wrote a cut & paste code snippet to indicate the issue at hand...

code:<HR>
Code:
package com.self.examples;

/*
 * Swap.java
 *
 * Created on February 22, 2002, 6:30 PM
 *
 * @author green_buddy
 */

public abstract class Swap {
    
    public static void badSwap (Integer a, Integer b) {              
        Integer temp = new Integer(a.intValue());   // temp = a
                        
        a = new Integer(b.intValue());  // a = b                
        
        b = new Integer(temp.intValue());   // b = temp        
    }
    
    /**
     * This really isn't a swap method at all, because it doesn't really
     *  swap the references in the historical C/C++ context of what a swap
     *  function does, but it does handle swaping the values of the objects
     *  referenced by the arguments passed.  But if that's what we're talking
     *  about, then every class would require it's own implementation of this
     *  method, because every class defines its own set of instance variables
     *  local to the class you're looking to swap... which is class specific.
     */
    public static void goodSwap (MyInt a, MyInt b) {
        MyInt temp = new MyInt(a.intValue());   // temp = a
        
        a.setIntValue(b.intValue());   // a = b
        
        b.setIntValue(temp.intValue());    // b = temp
    }
    
    public static void badIntSwap (int a , int b) {
        int temp = a;   // temp = a
        
        a = b;  // a = b
        
        b = temp;  // b = temp
        
        System.out.println();
        System.out.println("<--------RETURNING-------->");
        System.out.println("int a: " + a);
        System.out.println("int b: " + b);
        System.out.println("<------------------------->");        
        System.out.println();
    }   
    
    public static void main (String[] args) {
        Integer a = new Integer(1);        
        Integer b = new Integer(2);
        
        System.out.println("START badSwap");
        System.out.println("<--------BEFORE-------->");
        System.out.println("Integer a: " + a.intValue());
        System.out.println("Integer b: " + b.intValue());
        System.out.println("<---------------------->");
        
        badSwap(a, b);
        System.out.println();
        
        System.out.println("<---------AFTER--------->");
        System.out.println("Integer a: " + a.intValue());
        System.out.println("Integer b: " + b.intValue());
        System.out.println("<----------------------->");
        System.out.println("END badSwap");
        
        System.out.println();
        
        MyInt c = new MyInt(3);
        MyInt d = new MyInt(4);
        
        System.out.println("START goodSwap");
        System.out.println("<--------BEFORE-------->");
        System.out.println("MyInt c: " + c.intValue());
        System.out.println("MyInt d: " + d.intValue());
        System.out.println("<---------------------->");
        
        goodSwap(c, d);        
        System.out.println();
        
        System.out.println("<---------AFTER--------->");
        System.out.println("MyInt c: " + c.intValue());
        System.out.println("MyInt d: " + d.intValue());        
        System.out.println("<----------------------->");
        System.out.println("END goodSwap");
        
        System.out.println();
        int e = 5;
        int f = 6;
        
        System.out.println("START badIntSwap");
        System.out.println("<--------BEFORE-------->");
        System.out.println("int e: " + e);
        System.out.println("int f: " + f);
        System.out.println("<---------------------->");
        
        badIntSwap(e, f);
        System.out.println();
        
        System.out.println("<--------AFTER-------->");
        System.out.println("int e: " + e);
        System.out.println("int f: " + f);
        System.out.println("<--------------------->");
        System.out.println("END badIntSwap");        
    }           
}

class MyInt {
    
    int intValue;
    
    public MyInt (int value) {
        this.intValue = value;
    }
    
    public int intValue () {
        return this.intValue;
    }
    
    public void setIntValue (int value) {
        this.intValue = value;
    }
}

So I would be interested in understanding what Richard Berg was looking for as well... Berg? :confused:

Originally posted by Mister Internet:
Hi there... this is my first official post on Ars. :) I come from the _http://www.hardforum.com_, but their programming forum is a little weak, and not nearly as Java-knowledgeable as this one... I can see I will be coming here frequently! :)

Welcome!!! :D

Originally posted by Mister Internet:
To your question, green... Absolutely. J2EE (Java 2 Enterprise Edition) is comprised of all the classes and SDKs involved in server-side web-to-client programming. This includes EJB, JSP, Servlet, and some miscellaneous XML parsing, security, and data layer stuff. In fact, if you check out the official API documentation for the J2EE 1.3.1 SDK http://java.sun.com/j2ee/sdk_1.3/techdocs/api/index.html, you will be able to see all the packages that are included in the official API.

Ok cool... I was definitely aware of the fact that jsp/servlet packages were apart of the J2EE libs, but I was wondering why one of the recruiters I was working with was so concerned about the fact that I was missing J2EE, and I didn't think I was. In fact, I wrote my own persistence layer in order to get around some of the heavyweight use of EJB's in a web development environment, so I would say that I know J2EE fairly well. However, what I don't have a ton of experience in is the EJB part of the J2EE libs. I've only written a few practice EJB's at my last job before the company decided that they didn't want to spend so much cash on Weblogic's EJB server per CPU when their express version is sooo much cheaper... hence, the persistence layer framework! ;)

If technical recruiters were actually required to prove their ability by actually knowing something about the technology they were trying to sell engineers for, I bet it would make the jobs of the interviewer and interviewee a lot easier! ;)

-green
 

Richard Berg

Ars Legatus Legionis
43,037
Subscriptor
Answer: there's no good way - that's what makes it a great interview question :D

Does the interviewee recognize that there's a problem? (separates the imbiciles from the boys) If so is he stymied or does he try to come up with workarounds? (separates the boys from the men)

None of these is fully generic of course, but something along these lines would at least show that his brain was engaged:
code:<HR>
Code:
public static void swap (int[] x, int[] y) {
  int hold = x[0];
  x[0] = y[0];
  y[0] = hold;
}

// or...

public static void swap (int data[], int x, int y){
    int temp = data[x];
    data[x] = data[y];
    data[y] = temp;
}

// or...

class Foo {
    public int x;
}
public static void swap(Foo f1, Foo f2) {
    int temp = f1.x;
    f1.x = f2.x;
    f2.x = temp;
}

Even better: they ask you if maybe there's a swap() method hidden somewhere in the standard library. (answer: not really, but every container has a method that lets you do things like myContainer.swap( myOtherContainer ) )

All of the above, of course, is in the [occasionally] humble opinion of a silly undergrad who just started learning Java last week
 

green_buddy

Wise, Aged Ars Veteran
126
Here's another one that I think is pretty good, and really applies to the new java.nio.* stuff in jdk1.4... aaahhh non-blocking IO! ;)

What are the significant advantages when looking at the differences between blocking and non-blocking IO (input-output)?

Mostly interested in how it pertains directly to Sockets, but also how it pertains to Files. :eek:

I think we've tackled most of the new-grad questions... it's time to start really talking about the things that are significant to real development engineering work. :cool:

-green
 

dpowers

Ars Scholae Palatinae
1,395
Subscriptor
I don't know how it applies to I/O, but when used in the network world:

non-blocking indicates that a switch connection between 2 ports will not block any other 2 ports from connecting at the same time. Thus, a network of switches will have much greater bandwidth than the bandwidth of just one port. The definition of blocking is obvious from here.

Does it even compare? :p
 

green_buddy

Wise, Aged Ars Veteran
126
Originally posted by tig_ol_bitties:

Does it even compare?

I'm not sure, but I don't think that's the idea. When talking about blocking/non-blocking I think it's referring to the fact that the thread of control either blocks (ie. waits), or doesn't block on some form of input, so I'm just trying to figure out why this might be so special, 'cause I haven't quite figured it out really. I'm hoping someone with some experience here will be able to help me understand this, or atleast link me to some resources with more specific information than this.

Another question of merit:

What are the five advantages/disadvantages/differences between Java and C++?

What I mean is, what are your top five things that make Java better/worse, or just plain different than C++? I don't really think there's a right or wrong answer here, but to get an idea, I'd say one of the would be:

1. Quicker to develop and maintain code across large groups of engineers. But that's just my opinion... see what I'm getting at!?! ;)

-green
 

Thank You and Best of Luck!

Ars Legatus Legionis
21,219
Subscriptor
Originally posted by lensam69:
Here are some other ones (They are simple, but you never know):


Q: How may interfaces can a class implement?
A: As many as it needs.

Q: How do you create a class so that nobody can extend it?
A: Add the keyword "final" in the class declaration.

Q: How many constructors can a class have? How is this called?
A: As many as it needs (With different parameters of course). Polymorphism.

Q: Does Java support recursive functions?
A: Yes.

Q: Would you say Java is an OOP type Language or an Imperative type Language?
A: Both (Imperative languages are based on the memory assignment paradigm. Example a = 3 means that memory cell to which "a" points will store the value "3")


It's the simple questions in life that screw us...

1) I didn't think that was true, since you can't implement both MouseListener and MouseMotionListener, you have to implement MouseInputListener to be able to get access to both interfaces.

2) Correct.

3) While part of your answer is correct, that's not an example of Polymorphism, it's an example of overloading.

4) This question is kind of silly since all languages support recursion, by simply calling a function inside itself. Depending on the type of scoping a language uses you can create problems.

5) This question doesn't really make any sense, just because a language is built around references doesn't make it OO, though it's certianly not imperative. The comparison of OO and imperative doesn't make much sense though. OO vs. Functional or Procedural would make more sense.
 

newton_meter

Ars Scholae Palatinae
1,424
Originally posted by naschbac:
1) I didn't think that was true, since you can't implement both MouseListener and MouseMotionListener, you have to implement MouseInputListener to be able to get access to both interfaces.

Why didn't you just try it and discover you are wrong? There's no problem at all with multiple interface inheritance in Java, since there is only single implementation inheritance. If you wanted to quibble, you could probably say that there is a practical limit determined by the memory available for compiler data structures and/or the disk space available to write the class file.

2) Correct.

But a smartass would talk about how simple it would be to read a class file, modify it so that it wasn't final, then write it back out to a new class file. Voila, a "copy" of the final class that you can extend.

3) While part of your answer is correct, that's not an example of Polymorphism, it's an example of overloading.

Err, maybe you should look that up. Overloading is ad hoc polymorphism.

4) This question is kind of silly since all languages support recursion, by simply calling a function inside itself. Depending on the type of scoping a language uses you can create problems.

Probably kind of silly, but you catch out applicants that are fuzzy about recursion. I want my job applicants to have recursive dreams. By the way, the first implementations of Fortran effectively didn't provide useful recursion, because parameters and local variables were not stored in the call stack (they were all "static" in C parlance). And (you'll correct me if I'm wrong) early implementations of Forth prohibited recursion, because the definition of a word was not in scope for the body of the word.

5) This question doesn't really make any sense, just because a language is built around references doesn't make it OO, though it's certianly not imperative. The comparison of OO and imperative doesn't make much sense though. OO vs. Functional or Procedural would make more sense.

Is a banana a fruit or a snack? You ask that to catch out people that try to say "Umm, it's a fruit, not a snack" or "it's definitely a snack, not a fruit". I don't think you're entirely clear on what does make a language OO. Your "procedural" and "imperative" are (or should be) the same thing. It would make more sense to say that the OO/non-OO language distinction is independent of the functional/imperative language distinction, though it does make sense to talk about imperative/object-oriented/functional/logical programming paradigms as separate ways to build solutions to problems.

(kg*m*m)/(s*s)

PS: I probably wouldn't hire you.
 

Thank You and Best of Luck!

Ars Legatus Legionis
21,219
Subscriptor
Originally posted by newton_meter:

PS: I probably wouldn't hire you.

1) I just did try it, and I got a Java compile time error. Maybe it's something specific about The MouseEvent hierarchy? I was left having to use MouseInputListener.

2)

3) I checked my OPL text and you are right, but if someone were to describe the original scenario to me as just "Polymorphism". I would either be waiting for additional explaination, or I would assume they either didn't know what overloading or what polymorphism really mean in general and typical terms.

4) Yes FORTRAN doesn't adequately support recursion because of it's scoping and branching design, but so long as you are very careful and meticulous it is possible to perform some recursive operations. So far as Forth goes, I don't know. I never used it other than to install a version of Pong into my OpenFirmware, so I'll have to take your "word" for it(pun only sort of intended :)).

5) No I understand quite well what constitutes an Object Oriented language in both loose and strict terms. Which is why I said the comparison didn't make much sense in the first place. However if the question is merely designed to weed out people who can't tell the difference between a banana and a fruit snack, then I understand it's purpose and placement.

[This message was edited by naschbac on March 12, 2002 at 13:44.]
 

green_buddy

Wise, Aged Ars Veteran
126
Why is it that all of my threads turn into pissing contests? Can't we all just get along? Why do we feel the need to constantly ad hom? Ugh! :rolleyes:

I think the best hiring rule of all is not hiring people who ad hom, 'cause they likely aren't approachable as an employee, and if that's the attitude of the boss... you're surely in for hell! :(

Originally posted by naschbac:

Q: How do you create a class so that nobody can extend it?
A: Add the keyword "final" in the class declaration.

2) Correct.

I believe naschbac is right here regarding the original question. From what I understand the question wasn't, how do we reverse engineer a final class so that anybody can extend it?

In the spirit of the thread...

Write an OutputStream so that it doesn't force a close on the underlying OutputStream. And provide a case for why that would be useful.

-green
 

newton_meter

Ars Scholae Palatinae
1,424
Originally posted by green_buddy:
Why is it that all of my threads turn into pissing contests? Can't we all just get along? Why do we feel the need to constantly ad hom? Ugh! :rolleyes:

One person's pissing contest is another's vital scientific debate. Seriously, I'm not sure who you think is engaging in ad hominem. lensam69 posted a list of questions, naschbac posted answers while saying that some of the questions are not very good. I posted hypothetical justifications for some of the questions and corrections to some of the answers.

Unless you thought "I wouldn't hire you" was an attempt by me to address naschbac's technical claims by attacking his personal character. I didn't intend it that way; and I thought we were doing a pretty good job of addressing the claims and not the person making the claims. Or do you just mean "not being the most polite you could" when you say ad hominem? In that case, guilty as charged. Sorry, naschbac. After reading your response, I might consider hiring you.

I believe naschbac is right here regarding the original question. From what I understand the question wasn't, _how do we reverse engineer a final class so that anybody can extend it?_

Well that was almost exactly my point, but perhaps it was too subtle. And I don't mean "you didn't get it", but "I didn't make it". How you understood the question was all important in formulating your answer. And how the questioner understood the question was all important in the "right" answer.

Asking questions about technical minutiae is a little silly. A lot of these questions have multiple correct interpretations that lead to different answers. Why are you asking me about how to create a class that can't be extended? Do you want to make sure I am aware of what the final modifier means when applied to a class definition? You didn't just ask that. Do you want to see if I understand that in a language with dynamically loaded code and run-time reflection it's not really possible to make anything truly "final"? You didn't ask that either. Do you want to distribute a software library and prohibit users from reusing your code? Hey look, I'm just trying to get hired, so you're going to have to tell me why you want to know. Give me a problem to solve, not a trivia question.

Then, imagine that these questions are posed by some management type that doesn't actually do Java (or whatever) development. Look back and see how many times in this thread the answers given by the people who posed the questions were sloppy or just plain wrong.

I used to teach the Introduction to Computer Science and Programming Languages courses at a university. We told our students that knowing how to solve problems was a more useful job skill than being able to write programs in a particular language. And we told them that it was better to know how important kinds of programming languages were put together and worked than to learn the syntax of every programming language--there are too many languages and syntax is not understanding. We told them that if they knew what they were talking about, they could convince a potential employer that picking up the syntax of Object-oriented COBOL was just a bit of bookkeeping.

But now, I'm in the real world, and I know that you've got to be extremely quick thinking and confident bordering on arrogant to pull that off, because the employer's going to ask crap like "How do you create a class so that nobody can extend it?" Sometimes that just burns me up. I guess you should answer that by saying: "Tell me why you want to know, and give me a copy of The Java Programming Language, The Java Language Specification, and the API docs, and I guarantee I'll solve it for you". Or, you could say: "If I punch you in the face, kick you in the nuts, and break all your fingers, then you won't be able to extend this class, bucko!".

(kg*m*m)/(s*s)

PS: Don't forget to insert smileys for me. I gave them up for Lent.

[This message was edited by newton_meter on March 13, 2002 at 11:57.]
 
Status
Not open for further replies.