~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
assertArrayEquals(int[] correctDuplicateSort, int[] sort.sort(duplicateInts));

assertArrayEquals expects two array references as its parameters; what you've got there is an array declaration. The correct way would be:

assertArrayEquals(correctDuplicateSort, sort.sort(duplicateInts));
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Read the example provided for ScheduledExecutorService.

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

> Any advice on how I should create/define the document?

Here's a simple throw-away implementation in JDOM [requires jdom.jar of course]:

public static void main(String args[]) throws Exception {
   DocumentBuilder builder = DocumentBuilderFactory.newInstance()
         .newDocumentBuilder();
   DOMBuilder domBuilder = new DOMBuilder();
   Document jdomDoc = domBuilder.build(builder.parse(new File("src/home/projects/misc/Test.xml")));
   Iterator iter = jdomDoc.getRootElement().getChildren("JOB").iterator();
   while(iter.hasNext()) {
      Element jobElem = (Element)iter.next();
      if(jobElem.getChild("JOBNAME").getValue().equals("Second job")) {
         jobElem.getChild("INPUTFOLDER").setText("MY-NEW-LOCATION");
      }
   }
   XMLOutputter outputter = new XMLOutputter();
   outputter.output(jdomDoc, System.out);
}

In your case you can output or direct the XML to some other stream/file.

> But the quickest way to do your current task would probably be
> the regular methods such as Scanner and Regex

Given that I've dabbled with both XML processing API's and regular expressions, I disagree. I'd love to see a regular expression implementation of the above having the same sort of clarity and brevity. :-)

> rather than learn how to use JDOM.

I personally feel that one shouldn't shy away from using the best possible tool for the job even if it comes with a bit of learning curve. Experience has shown that implementing something in a round-a-bout way brings in too much pain and generally has a higher cost associated than learning the right tool and doing things right.

> There are some sort of web services xml bindings for java

You can very well use the XML processing libraries which implement the XML specifications without getting involved with web services i.e. XML processing != Web …

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

Using a XML processing library like JDOM would significantly ease your job. All you'd need to do with such a library is:
- Parse the source XML document
- Get all the JOB nodes and filter the JOB node with the given JOBNAME
- Update the child elements of the JOB element
- Save the in-memory XML back to the file

But do keep in mind that this would become unwieldy if the file becomes too large due to the overhead of reading and writing an XML document. XML IMO is a bad format for frequent reading/writing of data. An embeddable small memory footprint database like H2/Derby would shine for your given use case.

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

IMO, if you are planning to work both in embedded and server modes, Derby would be a good choice for a beginner database. It supports almost all SQL features which you might need along with support for user defined procedures and functions. Also, it's a pure Java database with a type 4 JDBC driver which is easily available.

Of course, if it were some "enterprisy" project, I would have recommended PostgreSQL or Oracle[if you have the moolah]. :-)

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

> How I go about getting documentantion?

Any JDBC tutorial out there should be good enough to get you started. The only difference would be the way the SQL driver is loaded. This would be a good start.

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

> Should I use Connection Pooling?

Depends; all real life projects use pooling but if you have just started out, cutting down the complexity by not bothering about pooling wouldn't be that bad. There are some SQL mapping frameworks out there [iBatis] which handle all the pooling behind the scenes.

> any way to hold the result for that user utill he logout

Server side sessions; though putting in a lot of data might just slow down things. Caching at the DAO layer is yet another option. Again, frameworks like iBatis and Hibernate shine in this area with configurable caching options.

> Do I need to use MultiThread?

No, at least not when developing a web app since the servlet takes care of spawning a new thread for each request made.

> How should I divide it to get the MVC Model confirmed .

By using a framework which helps you enforce a clear separation of concerns. Spring MVC, Wicket, Struts 2, Tapestry are good contenders.

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

> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

It seems that you are using a pre JSTL 2.0 URI; in pre 2.0 JSTL, the set action is configured to not accept run-time expressions [rtexpr=false].

Try using <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> instead; it should work.

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

> At least it proves that Dani does still listen to what members of the
> community say...

Yeah, that's really a nice thing; especially when almost all the regulars are out on the streets baring their pitchforks and torches, foaming at the mouth. ;)

Ancient Dragon commented: LOL :) +0
Nick Evan commented: Roaarr! ;) +0
sknake commented: lol :P +0
nav33n commented: :D heh +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Why use abstract classes at all? Why not just declare a class and
> then make sure you never instantiate any variables of that type?

...because compile time checks are far superior/efficient when compared to your code blowing up at run time. Languages which don't have the concept of Abstract classes baked in reply on hacks to achieve the same [e.g. Actionscript 3].

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

You can either modify the properties of the command window [cmd] to show more than 500 lines [ALT + SPACE + P -> Screen Buffer Size -> Height] or pipe the output of your java program to some text file [java YourProgram > file.txt].

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

> Well, 650,000 users cannot be involved in every single discussion.

I guess nor they would want to as many of them are here for a quick solution.

> Even 20 regulars who post in the feedback forum only represent the
> most vocal members

Correction, the most "faithful" and "caring" members; members who care when things change.

> Well then be more vocal about which features you use and how you use them.

Pretty twisted way of asking for a feedback, eh? :-)

> When you first visit DaniWeb, how do you begin your visit?

UserCP; the subscribed forum list along with the no-email thread subscription works wonders for me. I've never seen the main page, ever.

> The DaniWeb homepage is going to be entirely retooled to actually
> be useful, so hopefully it will make a good first destination when you
> visit the site.

How about keeping on making changes to the main page *without* touching the existing layout? :)

After all there seems to be a lot of space on the right as Mel said; this change seems as if you are forcing all the existing members to visit the home page before they start their daily routine surfing.

But then again, this thread has the same feel as the "quick reply v/s advanced reply" or "IT professional's lounge v/s Geeks Lounge" thread, so bleh. :-)

sknake commented: agreed +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Consider the possibility of Adatapost giving the green rep for the following content:

Points to be noted, raghuhr84

* Give the complete program, that is, give #include<stdio.h> . Becomes easier for us to check.
* Use proper indentation
* Use code tags around your program (See the forum rules)

No where does adatapost specify that the solution is a *good solution*. Overzealous, much? :P

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

Try using the DocumentBuilderFactory instead of explicitly instantiating the parser.

public static void main(String args[]) throws Exception {
   DocumentBuilder builder = DocumentBuilderFactory.newInstance()
         .newDocumentBuilder();
   Document doc = builder.parse(new File("Test.xml"));
   System.out.println(doc.getElementsByTagName("name"));
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

NumberFormat is an abstract class; use its static factory method to get your choice of number formatter.

public class MainTest {
   
   public static void main(String args[]) throws Exception {
      // Get a number formatter for the default locale
      NumberFormat nf = NumberFormat.getNumberInstance();
      nf.setMinimumFractionDigits(2);
      System.out.println(nf.format(1.1));
      
      // Get a number formatter for a different locale e.g. french
      nf = NumberFormat.getNumberInstance(Locale.FRENCH);
      nf.setMinimumFractionDigits(2);
      System.out.println(nf.format(1.1));
   }
   
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The commas and the brackets are a part of the ArrayList class's toString() implementation. If you need your own row representation, either write your own method which does so or better yet, create a custom class called BoggleRow which uses composition or inheritance to mimic the ArrayList class. Something like:

public class TestRun3 {
    // your code here

    public void displayRow(List row) {
        // code which loops over the list & displays the row
    }
}

//OR

public class BoggleRow {
    private List row;
    public BoggleRow() {
        row = new ArrayList();
    }

    @Override
    public String toString() {
        // your code here
    }
}

// OR

public class BoggleRow extends ArrayList {
    
    public BoggleRow() {
        super();
    }

    @Override
    public String toString() {
        // your code here
    }
}

The above code gives you a rough sketch of how your class would look like. My personal preference would be the second implementation.

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

Use getValues().nextLine().equals("n") instead. The Scanner name is confusing BTW, just name it scanner instead of getValues which is more appropriate for a method name.

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

You are comparing a Scanner object with a String object.

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

This doesn't seem to be a JSTL problem since the class missing belongs to the jsp-api.jar library which is a part of the standard distribution [i.e. part of the specification, placed in Tomcat/lib]. Have you tried making your application work outside Netbeans by copy-pasting the WAR file in the Tomcat directory?

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

> If re-direction must occur, it must be the first line of a constructor. Why?

To ensure that the parent class is completely initialized before it gets used in the child class's constructor body. If this restriction was not imposed, you could have code like this which really doesn't make sense:

public class A {}
public class B {
  public B() {
    // How do you expect to access something before it is contructed?
    Class c = super.getClass();
    super();
  }
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

What's wrong with the getTime() method of the Date class which returns the number of milliseconds elapsed since January 1970 as long? To get the seconds, just divide by 1000.

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

> is it possible to loop through the contents of two arrays to populate a
> third array with the combined content?

In my code I'm using looping through two Lists and populating a third list which is then converted to an array and returned.

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

Sadly, this simple a thing becomes pretty clunky to implement when it comes to Java. A sample implementation might be something like:

class YourClass {
   
   private static final List<String> LOWER_CASE_CHARS;
   
   private static final List<String> UPPER_CASE_CHARS;
   
   static {
      LOWER_CASE_CHARS = listFromArray("abcdefgh".toCharArray());
      UPPER_CASE_CHARS = listFromArray("ABCDEFGH".toCharArray());
   }
   
   private static List<String> listFromArray(char[] charArray) {
      List<String> list = new ArrayList<String>(charArray.length);
      for(char ch : charArray) {
         list.add(String.valueOf(ch));
      }
      return list;
   }
   
   public String[] fillResultArray() {
      boolean checkBoxOneChecked = true, checkBoxTwoChecked = true;
      List<String> stringList = new ArrayList<String>();
      if(checkBoxOneChecked) {
         stringList.addAll(LOWER_CASE_CHARS);
      }
      if(checkBoxTwoChecked) {
         stringList.addAll(UPPER_CASE_CHARS);
      }
      return stringList.toArray(new String[] {});
   }
   
}

Does that work out for you?

cwarn23 commented: great code snippet... +4
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Does anybody know how I can append to the array

You can't. The best you can do is perform a copy-on-write if the content to be written is more than the initial capacity with which the array was created. Try using an implementation like ArrayList which relieves you of all this resizing business. Is there any specific requirement you are trying to fulfill which can't utilize better data structures?

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

Maybe the use of <E> in the iterator class is taken as a new declaration of a type, and masks the <E> that is declared for the outer class? If so, maybe you could declare the iterator class as
public class CircularListIterator<F extends E> ...

IMO, though the analysis is correct, the solution provided isn't because an Iterator over a collection of elements of type E isn't the same as an Iterator over a collection of elements of type F which extends E. The solution here is to declare CircularListIterator like:

private final class CircularIterator implements Iterator<E> {
  // methods go here
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmmm...insanely strange. If you are talking about the 'Flag Bad Post' link, see it in the attached screeny.

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

[edit]

It's not a snippet anymore, now I can also see both links. But see this snippet for example. I can flag comments, but not the snippet.

Have you tried clearing your cache? Because I can see the 'Flag Bad post' link...

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

I can see both the links. Try clearing the cache using a force refresh.

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

> Can i remove that duplicated post ??

Just report that post using the "Flag Bad Post" option and it should get appropriately handled.

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

Yes, as long as it's not a space, it would work. For a more standardized naming approach, trying replacing the underscore with a hyphen.

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

There are many good books, blog posts and articles out there for getting started with JEE; your best bet would be the free JEE 5 tutorial hosted by Sun.

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

> also, would this be something to do with JavaEE instead of JavaSE?

Depends on what you need to learn and where your expertise lies, but yeah, nowadays the core business functionality *is* developed using JEE.

You can develop a core business functionality using web services i.e. expose your business logic using web services. You can then use a web-client developed using any one of the web development MVC frameworks out there along with a standalone client developed using Swing, SWT etc. In short, a web and standalone client for consuming a business functionality exposed as web services [which are nothing but just glorified servlets].

A serious web application might be a policy management system wherein you sell policies to customers, customers pay their premium, you generate an invoice etc. But then again, these *serious* business apps might just put you off and you'd lose motivation easily.

It'd be better to start off with something which you find fun. Something like an online TODO list application, a web application which helps you maintain a list of all the cartoons you have seen till date, an online text to PDF converter [easy since you can use the libraries out there] etc. The possibilities are infinite...

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

> But in second, I am getting exception that filenotfound.

Because the file "spring.xml" is not present at the root of the class path; you need to state the hierarchy or the path to your config file from the classpath root.

> In my web application configuration file is located exactly in WEB-INF folder

I couldn't find any statement in the servlet specification which said that the entire WEB-INF folder is added to the classpath; the servlet specification states that:

The contents of the WEB-INF directory are:
• The /WEB-INF/web.xml deployment descriptor.
• The /WEB-INF/classes/ directory for servlet and utility classes. The classes in this directory must be available to the application class loader.
• The /WEB-INF/lib/*.jar area for Java ARchive files. These files contain servlets, beans, and other utility classes useful to theWeb application. TheWeb application class loader must be able to load classes from any of these archive files.

TheWeb application class loader must load classes from the WEB-INF/ classes directory first, and then from library JARs in the WEB-INF/lib directory.

Given the above excerpt, just ensure that your application context file lies inside the folder "classes" and it should work out fine.

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

"Stops running" is a pretty vague description; have you looked at the server logs? BTW, reading this article might help you get things done the right way.

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

Your second file is missing the class imports. I don't see the declaration of your `Convert' enum class. Your naming conventions are still off.

These are pretty simple error messages to hunt down and fix; I'd recommend reading the sticky at the top of the forum.

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

A few observations:
- Always perform resource cleanup in the `finally' block to be rest assured that the cleanup indeed is performed even if the code ends up throwing an exception.
- The way you have written your code resembles the procedural ad-hoc way of writing code. Break up your logic in methods and create logical classes which represent your problem domain.

Taking a look at the sticky created at the top of the forum might just help you get started in the right direction.

majestic0110 commented: Sound advice. +5
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Thinking about it in this way might help your cause:

power(2, 3) =>

 - 2 * power(2, 2)
   - 2 * (2 * power(2, 1))
     - 2 * (2 * (2 * power(2, 0)))
   - 2 * (2 * (2 * 1))
 - 2 * (2 * 2)

= 8

The trick here is to force the repetition of `base' for an `exponent' number of times by using recursion.

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

>Thanks a lot guys for the help!

Good luck with the remaining exercises.

> I will flag this as solved when I get my account fixed.

Done and done. :-)

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

Read the contract of the substring method; substring(4, 6) == 2 characters.

Also get in the habit of using uppercase characters for enums i.e. `BIN' instead of `bin'.

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

> How do I do that....I'm very new to Java

Steps:

  • Declare a TreeSet<String> instance variable for your class
  • Read the file using Scanner
  • For each line read, create the PublisherRecord instance as per your requirement
  • Push or add the publisher name to the TreeSet
  • After the file parsing is complete, your TreeSet will contain the list of unique publisher names
  • Write a separate method to print the contents of the TreeSet as desired

> 5 1/2 weeks not enough time to absorb it all.

That should be more than enough IMO given that reading the documentation of the TreeSet class and absorbing the examples doesn't take more than a day even if you are new to Java programming [and not programming in general].

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

> Using the TreeSet class, how do I accomplish this

It's pretty simple; just keep on reading the lines from the text file and add the last entry i.e. the publisher name to a TreeSet<String> . So you'd probably have a `parse' method which would take a File instance [the handle to the data file] and a method which returns the list of all publisher names in the TreeSet. Of course, to make it more *OO*, you need to put in a bit more effort when structuring your classes.

BTW, package names should always contain only lowercase characters. Don't catch exceptions if you are anyways not going to do anything specific with them. Try to break processing logic and the data concerning the logic into separate classes rather than having a single class with lot of static members.

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

> I think I need multiple loops to get rid of the commas, dollar sign, and
> end bracket separately.

Not required IMO; a single application of the replaceAll method of the String class on each line read should do the job. Use a regular expression for your task.

public class TrioTest {
   
   public static void main(final String[] args) {
      String s = "[2H, 4C, KC, 5D] $10 [QS, QD] $5 [AC, 3C, 4D] $25 [10H, 5C, 7H]";
      Pattern pat = Pattern.compile("[$,\\[\\]]");
      System.out.println(pat);
      Matcher mat = pat.matcher(s);
      String newS = mat.replaceAll("");
      System.out.println("Old S: " + s + "\nNew S: " + newS);
   }

}

Or, simply use the `replace' method of the String class to strip off each unrequired character from the target string.

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

You essentially throw away almost all the records read by reading the database entries in the ResultSet loop by not doing anything. If you want to compare the user entered value with the ones present in the database, do the comparison in the ResultSet loop. Set a flag and break out of the loop if the comparison succeeds.

Also a few points worth mentioning:

- Class names in Java should begin with an uppercase character; the same applies for Servlets.

- Since the JVM maintains a string pool, try not to use new String() *ever* in your code. Just use the string literals and let the JVM do the heavy lifting of deciding whether to use the existing pool instance or create a new one i.e.

// Instead of doing
String name = new String("");

// Do
String name = "";

// Or better yet; though depends on the particular use case
String name = null;

- For production/real use, don't prefer a JDBC-ODBC bridge driver but a pure Java Type 4 driver. Even if you are trying out things, doing things the right way would be much preferred. Use a database like MySQL or Derby along with the type 4 drivers which come along with it.

- You can simplify things a *lot* by modifying the query instead of jumping through all those hoops yourself. Just add an additional WHERE clause in your query and check if the returned ResultSet has at least one record; …

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

> If anybody reads this and is pinning topics *coughcough* please take a
> look at:

You can of course go ahead and create a sticky-worth thread in the forum you feel appropriate and PM the concerned sub-forum moderator regarding the same; that should get the job done. If everything else fails, PM me. :-)

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

I did see it when I first logged in, but trying after around half an hour made it go away.

iamthwee commented: test +23
kvprajapati commented: Yes! +13
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

>Are you talking from personal experience?

Yeah, kind of. :-P

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

>The Java platform supports a simple, deterministic scheduling
>algorithm called fixed-priority scheduling

Any official links? AFAIK, the JVM specification makes no such claim and leaves the details entirely to the implementation. I personally would be rather cautious in accepting anything which isn't stated in the official docs/ vm specification.

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

>that some couple getting married

Agree; marriage is surely a crazy thing! :-)

sknake commented: agreed +7