~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The problem with your previous implementation was that the invocation of next() was inside a condition which shouldn't have been the case. Also, you can again avoid casts by declaring next as E next = null; .

Again, like I said, making the method accept a Collection is plain wrong since a Collection doesn't support the notion or is not aware of indexed/ordered access. Your custom list implementation should accept only a List which would make your class semantically correct.

Anyways, here is my stab at it:

public class LinkedListTest {

    public static void main(final String[] args) {
        testNormal();
        testEmpty();
        testNull();
    }

    private static void testNormal() {
        List<Integer> list = new ArrayList<Integer>();
        list.add(10);   list.add(20);  list.add(30);  list.add(40);
        NodeList<Integer> nodeList = new NodeList<Integer>();
        nodeList.add(1);
        nodeList.addAll(2, list);
        System.out.println(nodeList);
    }

    private static void testNull() {
        NodeList<Integer> nodeList = new NodeList<Integer>();
        nodeList.add(1);
        nodeList.addAll(2, null);
        System.out.println(nodeList);
    }

    private static void testEmpty() {
        List<Integer> list = new ArrayList<Integer>();
        NodeList<Integer> nodeList = new NodeList<Integer>();
        nodeList.add(1);
        nodeList.addAll(2, list);
        System.out.println(nodeList);
    }

}

class NodeList<E> extends LinkedList<E> {

    private static final long serialVersionUID = 1L;

    public boolean addAll(final int startIdx, final Collection<? extends E> collection) {
        if (collection == null || collection.isEmpty()) {
            return false;
        }

        final int size = collection.size();
        if (startIdx < 0 || startIdx > size - 1) {
            throw new IndexOutOfBoundsException(
                    "An out of bounds index specified: " + startIdx);
        }

        int i = 0;
        boolean collectionChanged = false;
        for (Iterator<? extends E> iter = collection.iterator(); iter.hasNext(); ++i) {
            E elem = iter.next();
            if …
BestJewSinceJC commented: Very helpful feedback +4
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Think about what you've written for a while; do you really need two looping structures just to loop over a subset of a collection?

Given that Collection interface doesn't have a get method, the only option which remains is to keep an external counter which is incremented inside the iterator loop. This counter would keep track of the elements which need to be skipped (by comparing the counter value with the `index' passed in).

Oh and BTW, if this requirement is plain wrong/illogical. There is a reason why the Collection interface doesn't have a get method...

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Create a new task which depends on these tasks so that whenever your custom task is executed, it would in turn execute these three.

On a side note, I've always found Eclipse a pleasure to work with when developing web applications esp the auto-publish feature. You should definitely give Eclipse a try unless you are forced to work with JCreator for some reason.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Which terms are you trying to match here? Post a sample text along with the output you are expecting.

Also, the trick to creating complex regular expressions is to build the regular expression incrementally rather than writing it in a single go only to find it doesn't work as expected.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The problem is that you never use the `index' parameter in your overridden method. Also, you can avoid the cast by using the iterator as Iterator<? extends E> .

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hint: c.iterator() creates a new Iterator instance.

Also, calling next() on an Iterator without testing the presence of an element using hasNext() is not recommended.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Hum ... never new we could do that

Yes you can, and there's more where it came from. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Okay. So how do I search for a multi-word string in the forums?

I prefer to use Google for my power-searching needs. For e.g., in your case a query like site:[url]www.daniweb.com[/url] "free online television" when entered in the google search field should give decent results. Try it out, works out prettty well for me at least.

Ancient Dragon commented: Good idea :) +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> I suppose the impact is positive. Could you confirm?

Not sure what you mean by positive here; given that yet another layer of abstraction is being used, it would only end up hurting the performance. When it comes to plain and simple inserts without any business logic, nothing can beat the bulk load capabilities offered by your database.

I remember reading once that a functionality which took around 10-15 minutes in pure Java took only 10 seconds to run when executed as a stored procedure. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Does hibernate help in improving "insert" performance? Or is it only for
> read/update?

Any persistence framework you use would only impact your performance when it comes to bulk inserts; be it iBatis or Hibernate. But still, if you are stuck with using Hibernate, I'd recommend checking out the Hibernate mailing list for more suggestions.

Also make sure you turn off auto-commit if doing this from Java; a commit after each insert would end up killing the performance here.

After trying out various things if things still don't work out, try explaining the problem space in depth along with the methods you've tried out and we might together be able to come up with something.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

So essentially, declaring, in the method header, that a method throws an Exception, forces the programmer calling the method to deal with an Exception if one occurs

Not necessary if you are talking about exceptions in general and not the Exception class. Exception classes which extend RuntimeException and Error can be used in the throws clause without forcing the client or the consumer to catch them. This is normally done for documentation purposes but is perfectly legal and common scenario.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I guess there is a bit of confusion here as to how the Daniweb IRC works.

The Daniweb IRC channel is meant to be a place to hang out and relax; we normally don't entertain technical queries though you are free to answer if someone asks them. The normal protocol is to direct members to the forums instead. In short, Daniweb IRC is not a forum replacement.

Also expecting someone to start chatting with you the moment you join the channel is kinda unfair. There are times when not a word is said for days. The best way IMO is to join the channel, try to start a conversation if you feel like it or just stay put and jump in if someone starts one. Currently, John, Toba, Squires & Rashakil are the regulars who hang out there with me, Narue and Dave dropping by sometimes. :-)

> is there some alert when someone else joins/posts?

Depends on the IRC client you are using, but yes, it's possible.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> This has already lead down the path of a typical serkan thread.

Indeed and thread closed to prevent any more casualties...

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I kinda like this system, no, really. But I guess this thing won't work if you have a bucket load of *engineers* to be interviewed, something which is quite common in my country. :-(

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Check out the RSS, WebServices and SOAP forum placed under the Web-Development forums.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You need to implement some sort of buffered reading/writing; the way your code is currently written(single character I/O) it makes way too many I/O calls which can be a real performance killer.

A better option IMO is to use the libraries out there which ease the task of zipping/unzipping; some well known ones are 7-Zip-JBinding and TrueZip.

kvprajapati commented: TrueZip! Pure java. +6
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Eclipse all the way given that it's:
- Free
- Choke full of plugins for almost every conceivable thing out there
- Great community

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> more info on republic day?

More info on Republic Day :-)

> Happy Australia Day too!

Kinda strange given the recent turn of events in Australia. :-(

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I wish all the Indians out there a very Happy 61st Republic Day! :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

A good filtering criteria is asking what the individual has worked on and evaluating him based on the same. This way even the applicant can't turn all defensive and claim that he was being asked unjust questions (something which happens way too often). This is pretty much applicable to everyone -- from fresh-out-of-grad-school kiddos to seasoned professionals.

Oh and BTW, I'm not surprised at all. Ask someone to write a binary search algorithm and he/she might be in a bit of a shock; ask him about architecting enterprise applications and you're in a real treat of design patterns -- ranging from proxy to template to strategy design pattern. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I'm not quite clear as to what your end requirements are but as far as embeddable containers go, Jetty and Grizzly are worth a look.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

There are a choke full of online resources out there for the same. A simple google search for "connect to oracle using java" should be good to go.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The entire else block code can be replaced with dat = y - 1986; .

BTW, how are you persisting the data? DataOutputStream or plain old FileOutputStream?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

If all you would want to do is import/insert some bulk data in your database, you are better off using a specialized/optimized approach rather than the plain old inserts wrapped under some stupid managed bean method invocations. Given that you are OK with solutions like using a CSV file, I'd assume that using Java is not a requirement here. In that case, you can follow the tips mentioned here and see if that works out for you.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> what about the Jcreator compare to the eclipse which is prettier?

I've never heard of/used JCreator so can't really comment on that.

> i have downloaded the eclipse but i dont know how to use it ...

Read the online documentation for Eclipse; search terms like "eclipse beginner tutorial" might help.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Initialize allData or allDccs (I guess there is some sort of mix-up here) in the while loop and you should be good to go without having to clear the list.

Anyways, to clarify up the matter, there is only one list in your case which is pointed to or referred by two different references. So when you say you clear one of those lists, you are actually using one of those references to clear the only list you have and hence it is giving you issues.

KirkPatrick commented: Thank you for the help and explanation of why it was going wrong. It helps to understand how/why code isn't working the way I intended it to. Cheers bud +1
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Jeez guys, get a grip

...on each others' necks; no point in continuing with this pointless discussion. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Suppose I call
new Tomcat(3, false, "Pussy"); // wrong, but no error raised

The assignment in the super calll would overwrite the passed in value of the isMale property so it really shouldn't be a problem.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Where is my error?

I could have sworn I saw a double equals there ( isMale==true ). Disregard my previous comment.

Oh and BTW, you've got your class naming wrong there. The class names should ideally reflect a simulation of a real-world entity. Animals is just a collection of Animal entity. Along the same line, Cats are just a group of Cat entities. The state of your class (variables) reflects that you are trying to model a single entity(Animal) but your class name says otherwise (Animals). Drop the plurals and you should be good to go.

Also instead of having an explicit printInfo() method, override the toString() method of the Object class. This would give help you write code like System.out.println(myCat); instead of myCat.printInfo() .

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You don't specify the .java extension when executing Java programs since you are no longer concerned with .java files [the javac command compiles your Java files to the bytecode which is placed in .class files). Read the documentation of the `java' command for more details.

Edit: D'oh, beaten.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> is that all?

Does that code even compile?
Hint: The way you are invoking the constructor of the super-class is erroneous.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> please suggest me if what is the best compiler for java?

The JDK provided by Sun along with Eclipse as an IDE works out pretty well for me.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Firstly, an abstract class from definition contains atleast one abstract method

Really? ;-)

abstract class MyClass {}

I don't want to open a connection to the database, write the record and close the connection, since I have to implement that for the other three subclasses and it's a lot of repeating code.

Yes, you are right, that's a lot of repeating code plus creating and closing connections is an overhead. Consider using a connection pool as a Datasource instead of asking connections from DriverManager. To get around the problem of repeating code (getting the connection, closing statements, result sets and finally the connection) create a class similar to SimpleJdbcTemplate which handles all the repetitive boiler plate code.

To have the same interface for both writing to STDOUT and database, create a StudenDao which exposes the insertStudent method and create two implementations for the same. Something like:

public interface StudentDao {
  void insertStudent(Student student);
}

public class JdbcStudentDao extends SimpleJdbcTemplate implements StudentDao {
  public void insertStudent(Student student) {
    someHelperMethodOfTemplate(yourQuery, student);
  }
}

public class LoggingStudentDao implements StudentDao {
  public void insertStudent(Student student) {
    System.out.println("Student name: " + student.getName());    
  }
}

Of course there might be other better ways/patterns of doing the same; these are the easiest ones.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yes, given that you can't spawn multiple instances, it's kinda difficult to get your requirement to work. Anyways, as a last resort, you can always try out the Tomcat user forum.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

SoapUI can be used for testing web services. The debugger which comes with your IDE (Netbeans/Eclipse) should be good enough for all your debugging needs.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Is it necessary for the request to come from browser for the server to
> maintain session.

No, sessions are normally implemented using Cookies. So as long as your application makes sure that the cookie returned in the headers of your very first response are sent to the web application when making consequent requests, there shouldn't be any issues per se.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Given that Dani is pretty busy these days, I've created a new announcement in the Web Development section for the time being.

As far as the entire 'homework help' debate is concerned, I personally feel that the ones who lose out the most when posting ready solutions are the OP and the one who has posted the solution. I've been posting on site for 3+ years and have learnt to differentiate between lazy homework requests and genuine efforts put in by the OP. Helping someone arrive at a solution by guiding them takes much more effort and patience than posting code that solves the question at hand IMO.

The entire 'teach a man to fish' v/s the 'here ya go kiddo' debate in the end boils down to ones understanding/interpretation of the 'Homework help' rule though I'm personally in favour of the former.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

To me, being the best means much more than being lean and mean, so yeah, it's Firefox for me; can't beat those add-ons. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

>You are supposed to post something valuable

And you are not? Posting one liner questions one after another gives the impression that you are not at all putting in effort for solving your own queries. How about something like:

I've read about X v/s Y at http://random.net and am still having doubts about why Z happens; any pointers appreciated

Don't get me wrong; the first reply to your post does go out of the line but it's kinda difficult to not get irritated given a lack of effort on your part.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It's just as the error says, the container was unable to compile the JSP. There must be something different in both the environments. It'd be difficult to help you out without getting the entire stack trace along with the details of both the environments.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> is there any way around if I can pass all corresponding values
> (itemName, itemLocation, status) for SELECTED checkbox

That would be a flawed approach since the client can easily intercept the request and inject spurious data in it corresponding to your item ID. I've always followed the rule of thumb to *not* pass something which can be retrived by your business layer. The risk involved in sending the data from the client is far more than the performance implications of calling the query again. BTW, if you are implementing a kind of item processing system, why not just work with ITEM ID's instead of dealing with all the details again?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> if I check few checkboxes and on clicking submit how to pass each
> row data values

Read the replies posted by me and Peter again...

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Should I use simple ArrayList or HashMap as I need to pass selected
> checkbox values...

Just ensure that all your checkbox elements have the same name and then use the HttpServletRequest.getParamterValues('elementName') to retrieve a String array containing the list of item id's.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Please post your question as a forum thread and not a code snippet. Also, try pasting your code again given that your code got eaten up when moving this thread from code snippets section to forums.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> I tried manipulating the blob datatype by setting..

The way you are going about to do this won't work. You can't render an image on your markup without using the IMG tag just by grabbing the binary content. You'd need to create a separate servlet mapping which would read the contents of the image from the database and write it out to the servlet output stream. You'd then use it like:

<img src="/yourWebApp/yourServletPath/grabImage?id=yourImgName" />
public class MyController extends HttpServlet {
  public void doGet(HttpServletRequest req, HttpServletResponse res) {
    // check if the path contains 'grabImage'
    String id = request.getParameter("id");
    // read the binary content using the code present in your JSP
    byte[] data = readImage();
    response.getOutputStream().write(data);
    // perform misc cleanup
  }
}

> assuming i want the size of that image to be width=200,height=200 on
> display,how do i achieve this

Use some image manipulation library to do the same. Google if your friend.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> We just can't have personal instances of the application in our individual
> computers because we only have one license

One license of what? Is it something which your application refers to which can't be deployed on different machines? Maybe explaining things in more depth might help us give more relevant solutions.

Anyways, how about spawning different Tomcat processes for each developer? Given that you only have a single development machine, I'm sure it'd be good enough to handle that kind of load.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

...when almost every ongoing discussion on 'teh' internet makes you *sigh*. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> The problem might be that there is 11 digits in you value

That shouldn't be a problem since he is storing a string.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> you need to then scroll all the way back to the top

Pressing the HOME key works wonders IMO. :-)

diafol commented: hohoho like it +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The action /Login should be /YourWebAppName/Login .