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

You don't need two while loops for populating your Deque; also your logic is flawed at this place:

character = inputFile.readChar();
                while (!character.equals('\u0003')) {
                    if (character.equals('\u0008'))
                        deck.removeBack();
                    else
                        deck.addToBack(character);
                }

As soon as you read a character which is not '\u0003', the control enters the second `while` and never moves out since you don't change `character` inside the loop.

Since you have your catch block outside your logic, an EOFException would cause the control to move out of your logic and never execute the part which follows.

Also, I hope you are reading a char which was written using writeChar; if not, use a Scanner for reading simple text files.

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

It would also be really nice to be able to customize the number line so if you repost their code, you could specify what line it is on.

Maybe there is already a way of doing all or a part of this and I just don't know about it?

One way of doing this would be to post the code, preview the posted content and update your post with the line number which has been generated by the preview.

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

Is it true that during autoboxing, the type.valueOf() method is called (which creates a new object only if another with the same primitive constant is not in the intern list. This applies to cases where interning is allowed

AFAIK, the specification doesn't require anything of this sort. Yes, it requires that when boxing, cached values be used for certain cases:

If the value p being boxed is true, false, a byte, a char in the range \u0000 to \u007f, or an int or short number between -128 and 127, then let r1 and r2 be the results of any two boxing conversions of p. It is always the case that r1 == r2.

but it doesn't explicitly say that it is the "valueOf" method which would be invoked.

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

@justin

BTW, if your question gets answered, please ensure that you mark the thread as solved (this time I've done it for you). Think of this as a way of saying thanks to those who have helped you out plus making it easier for others to stumble upon your solution.

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

Why is that special treatment?

Because arrays themselves are special. For e.g., every class which supports cloning (implements Cloneable) provides a public implementation for the clone method which shows up when you iterate through the methods of that class.

for(Method m : ArrayList.class.getMethods()) {
    System.out.println(m.getName());
}

prints out the name "clone" because ArrayList implements Cloneable and provides an implementation of the clone() method. This is again true for every other class which implements Cloneable except for arrays. I.e.

for(Method m : String[].class.getMethods()) {
    System.out.println(m.getName());
}

does not print out the "clone" method even though the Javadoc of the "clone()" method of Object class specifically says:

[...] Note that all arrays are considered to implement the interface <tt>Cloneable</tt>[...]

Notice the play of words here; it says "considered" and not "actually" implement the Cloneable interface. I guess this was expected for a language construct which can be assigned to a reference type but doesn't have a programmer accessible class. I'm sure carefully thinking about how arrays are used in Java would give you a few more points as to *why* arrays in Java are special. :-)

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

Because arrays get special treatment as per the specs:

The public method clone, which overrides the method of the same name in class Object and throws no checked exceptions. The return type of the clone method of an array type T[] is T[].

Ezzaral commented: Nice find. +14
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I think the digest mails from Daniweb do have a unsubscribe link at the end of it. If that isn't the case, try visiting this page and disabling email notifications and other things which you don't require.

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

Visit this link and delete all the subscribed threads which show up there. Also, visit the forum to which you are subscribed to (which you already know since you are getting email subscriptions I presume?) and click on the "mail" icon (just besides the RSS icon on the top right of the forum).

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

You quoted me out of context. I said "we do" in response to your statement

Ah, quoted out of context indeed.

BTW, I think as long as those contributing to the "moved" thread (OP + the collaborators) receive the new link via a PM, it really shouldn't be a problem. If that isn't possible, leaving time bound redirects as Nick proposed should be a good alternative.

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

In that case any server-less (embedded) pure Java database (read H2, Derby etc.) should work out well for you, unless of course you are looking to make a move away from relational databases. Just be careful when porting queries.

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

The purpose of redirects is so that members can find moved threads. When a moderator moves a thread, the thread starter gets a PM that their thread has been moved. However, all the other members and website visitors who may have been following the thread, whether or not they replied to it, can easily become frustrated in that the thread suddenly mysteriously disappears.

Sounds logical.

Another situation is that a thread in a less popular forum might be moved to a more popular forum where it is no longer on the first page. In this case, not having a Moved redirect is just an instant death sentence to the thread upon being moved.

Let's assume the thread is moved from IT Professional's Lounge to the C++ forum. For someone who helps out in the C++ forum, he/she would certainly not visit other sub-forums and look for moved threads. If a thread is moved from the "Lounge" to the "C++" forum, it would anyways mean death whether or not you have redirects in the parent forum unless of course you mean that redirected threads are always placed at the top.

I wish the mods would leave no redirect links

Well, we do, and we should

Choose one, will ya? :-)

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

I thought that those redirects were visible to only mods and above and not normal members. Also, I'm not sure normal members should be even seeing those redirects.

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

You are welcome. I see that this thread was not "marked as solved" even though you found a solution to your original question (which I've done it for you for now). Please ensure that the threads you create are "marked as solved" if a resolution has been reached for the original problem. This might actually help those who search for only solved threads when searching for answers to questions which have been previously asked on this forum.

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

Not true if you want to keep your files in top level, meaning classes folder. At that time you do not need package declarations.

...which unfortunately is a really bad idea in case anyone reading this thread thinks that it would be a convenient one. As of Java 1.4, unnamed namespaced classes can't be imported by namespaced classes i.e. are effectively invisible to namespaced classes.

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

> so please i want to know where i can start learning jsp and servlets

The Java EE tutorial is a solid starting point. Also, reading the stickies at the top of this forum should be helpful at this point. A few other resources:

> thanks in advance

HTH

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

In case it has been already decided to phase out the old data storage mechanism, you need to give us a bit more detail as to the nature of your application. Does this new face lift also involve making the entire logic distributed or would it still be a desktop single user application? What kind of database activity is you application expecting? Is the application installed for multiple users? If yes, is there any data-syncing activity which takes place for your application?

BTW, for a single user desktop application any server-less database engine like H2, Derby etc. should be good to go.

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

Well, i saw these two already, but i was hoping to get, like a beginner's tutorial explaining it step by step.

I don't think you would find anything more basic than the "Getting started" stuff offered by the Sun L&F docs. For how long have you been programming in Java? If you have recently started out with Java, that might explain the initial discomfort with the L&F tutorials.

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

First advice; avoid the "big re-write". The worst thing you could possibly do would be try to phase out everything and struggle when something stops working. No matter what datastore you are accessing, using the DAO pattern should help you isolate the database/datastore specific logic to a fixed set of classes. Just ensure that you program to interfaces when accessing data and migrating to something different shouldn't be very difficult.

A few other points to help you get started:

  • Start by analyzing the application and find out whether it uses any platform (Windows) specific stuff
  • At least have a basic design of your application chalked out. A really bad thing to do would be to dive head first into implementation without having at least a rough idea of how the application might be structured when migrated to Java
  • Have several small milestones which are followed by rigorous testing. Getting the users of the application to test your milestones would be a good idea
  • Make database migration your priority only if you application has to be deployed on both Linux and Windows box
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Strange, I thought he left due to the issues he was having with posting to Daniweb...

EDIT: Aha, found the post in which he mentions the same.

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

Apart from those already mentioned, I miss a few other posters from the C/C++ forums:

Come to think of it, the Java forum is in serious need of some awesome programmers like the ones mentioned in this thread. :-)

~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

@Override ensures that you don't end up *supposedly* overriding a super-class method and wondering why it doesn't work. E.g. every object inherits a toString() method from the Object class. A small typo in your toString() implementation might leave you scratching your head as to why your toString is not being called.

public String toSTring() {
  // something; notice the uppercase T
}

Compilation of the above code leads to no compile time errors. Contrast it with this piece of code:

@Override
public String toSTring() {
  // something
}

The above piece of code won't compile since there is no super-type method by the name of toSTring(). Something that would have normally got caught at runtime can now be caught at compile time. Much better.

Simply put, @Override just makes your intents much more clear to the compiler.

EDIT: Beaten!

tux4life commented: Marvelous explanation :) +8
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Recommended reading; post again if you get stuck with implementation. Also do have a look at the links mentioned in the comments there.

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

, it is not able to find class B.I have removed all the package declarations from the files.. The unnamed namespace is no longer the one that contains B.java (as B.java is in the home folder and I have moved from my home folder to the pkg folder and am compiling from there, so the unnamed namespace is the pkg folder now)

I'm not sure why that is the case since in the end both are unnamespaced classes. But trying out the same locally works for me so it must be something at your end. Double check the file contents.

Also, when both the files (with package declarations intact) were in the pkg folder and I was compiling A.java from the home folder with classpath set to the current directory, why was the compiler able to find B.java in the pkg directory. Does it check the package mentioned in the source file for classes too, along with the classpath ?

AFAIK, it follows it's own custom dependency check algorithm which really shouldn't concern you since it's not part of any specification and can vary from implementation to implementation.

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

:)

Nick Evan commented: Thanks +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The servlet container creates a single instance of the servlet and reuses the same for every request. This has the implication that your instance variables in your Servlet would be shared across all reqests thereby resulting in the `accBalance` being shared across all accounts. You can of course synchronize all the actions which operate on the `accBalance` variable but that would effectively mean only a "single" client would be able to work with the `accBalance` variable thereby killing any chances of concurrent requests being processed. The solution? Use session variables for maintaining balance for each "account"/"client".

public class MyServlet extends HttpServlet {
    protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        String action = getAction(req);
        double amt = Double.parseDouble(req.getParameter("amt"));
        HttpSession session = req.getSession(true);
        synchronized(session) {
            Double oldAmt = session.getAttribute("accBalance");
            Double newAmt = // add old amt and amt
            session.putAttribute("accBalance", newAmt);
        }
    }
}

Also, delegate your view rendering to a JSP instead of embedding the HTML rendering in your servlet; any more complicated view logic and your servlet would become unmaintainable. Read up the official servlet/JSP tutorial; http://download.oracle.com/javaee/1.4/tutorial/doc/ (assuming you are using java ee 1.4)

More recommended reading:
http://stackoverflow.com/questions/2183974/difference-each-instance-of-servlet-and-each-thread-of-servlet-in-servlets
http://www.velocityreviews.com/forums/t388103-how-servlet-works.html

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

i know how to run query and how to get values in result set using while loop already. ResultSet.next() and ResultSet.previous are the methods to scroll through resultset values i used all these in my program but there was sum prob in navigation.

Also, make sure you request a scroll insensitive ResultSet when preparing the statement so that you can move to the last row of the ResultSet and navigate it from last to first. Something like:

final Statement stmt = conn.prepareStatement("select * from tbl", ResultSet.TYPE_SCROLL_SENSITIVE);
final ResultSet rs = stmt.executeQuery();
if(!rs.last()) return; // no rows
while(true) {
  // process result set
  if(!rs.previous()) break;
}
// cleanup
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Even if I remove the package declaration from B.java

Then B becomes part of the unnamed namespace and types belonging to the unnamed namespace are invisible to namespaced types starting Java 1.4 since there is no mechanism wherein you can import those. Your example should work if you also move the class A outside the 'pkg' directory (i.e. remove the package declaration).

~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

Will Dani make it the primary feature in the future? Probably not
[...]
The writers aren't paid (AFAIK)

Surely you jest, no? :-)

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

Cheers mate, so to verify, the variable "str" basically holds the correct line being read from the program and, as long as it doesn't equal null, increments the lineCount and then passes the value of the next line to "str," and so on and so on?

Correction; 'str' holds the current line which "was" read from the file. If it's NULL (end of file reached), you break out of the loop, if it isn't, you print out the same and increment the line count.

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

Because each call to `readLine` bumps up/increments the file pointer, so as per your example, you effectively end up reading two lines in a single iteration. Declare a variable which would hold the string read and you should be good to go.

String str = null;
while((str = reader.readLine()) != null) {
  System.out.println(str);
  lineCount++;
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Double is a wrapper class whereas `double` is a primitive numeric type. Read this and follow the links in the comments.

BTW, are you by any chance using pre Java 1.5 since for Java 5 and above, autoboxing should have taken care of this for you.

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

The error says that you are trying to invoke the method setAttribute with parameters (String, double) whereas the expected types are (String, Object). Simply put, the compiler expects the second parameter to be of any reference type but definitely not a primitive. Convert the `double` primitive value to `Double` and it should work out fine. Look into the Javadoc of the `Double` class.

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

Is it just me, or do you find your patience stretched rather thin when posting here at Daniweb sometimes?

A long time back, yes. Now? No.

I've come up with a couple of simple points/markers which I use when answering threads:

  • A post well written with a polite tone but not too much begging
  • Attempt to describe the problem in detail with every visible effort of not making the helper do a lot of work; after all it's "you" who are asking a favour
  • Questions without any sense of urgency
  • The past record of the one posting the thread; bonus points if a first timer satisfies all of the above

Another reason for you might be your familiarity of the topic for which you are answering the question. Explaining Java classpath problems once is cool, twice is a burden and thrice is a PITA. Ever noticed how threads which are interesting to people won't irritate people posting on them even if the complete solution is handed out or if the OP decides to act like a 5 year old kid? This is because you learnt something new, you enjoyed replying to the thread. Also, I normally prefer not to reply to simple threads since the purpose of any forum is to not only help the needful but help the entire forum in growing up. If the simple queries are given quick answers, there is no room for those who are new to the language but want …

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

You can also use PreparedStatement which utilizes wildcards; just make sure that the "pin" you are setting already has those wildcard characters.

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

AFAIK, you'll get NULL only if you request the value of a form element which is not present in your form. If "name"/"address"/"username"/"password" are valid form fields, their value would be a blank string and not NULL in case you leave those fields blank.

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

Read the Javadocs for the Console class; it has the answer for your "why".

[...] Whether a virtual machine has a console is dependent upon the underlying platform and also upon the manner in which the virtual machine is invoked. If the virtual machine is started from an interactive command line without redirecting the standard input and output streams then its console will exist and will typically be connected to the keyboard and display from which the virtual machine was launched. If the virtual machine is started automatically, for example by a background job scheduler, then it will typically not have a console. [...]

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

I would like though something less verbose instead of "You are currently viewing page 13 of this multi-page discussion thread;" for mobile use.

^ Agreed; something like "Page 3 of 3" would be pretty awesome.

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

I gave a pretty coarse grained suggestion; of course, you should send mails only for threads created in specific forums, mainly that being programming related forums. Also, I really don't think it should be a big bother to receive a mail every month. After all, you do send out newsletter every month. Why not couple it with a request to mark threads as solved?

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

Another good thing might be to periodically mail out to members who have created threads but not marked them as solved after X number of days. This would help with members who might have wanted to mark their threads as solved but won't bother going to the website and searching for the thread which they posted. Just a thought.

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

How Sun micro system given the rights to share the own product with Microsoft product Dot net for developing J#

Simple, because MS were not violating any patents/copyrights by doing so. If there were legal issues surrounding it, VJ# would never have been created. About J#

BTW, there is no "Sun" micro systems now; it's Oracle. Plus, J# is now officially dead.

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

The part in bold is called the enhanced for loop which was introduced in Java 5. The program iterates over the variable number of double arguments (varargs) passed to the method and computes their average.

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

Instead of Java 1.4/5 which you are using, you need to use JDK 6 since Console is a class which was introduced in Java 6.

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

My question is will the 2 and true overwrite the 2 and false or they both exist in the Hashtable?

The value would be overwritten/updated for multiple `put`s done on the same `key`.

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

That is the part I was interested in seeing.

I don't have the source code for those since they are pre-packaged with the standard eclipse distribution. If you are still curious, you can try:
1) decompiling the classes using a decompiler like JAD
2) Google for the classes present in the org.eclipse.* package structure and you would surely stumble upon a link to the source.

Hope that helped.

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

As already mentioned, the first zip file does a lot of extra things:

  • Read the manifest file programatically
  • Create new URL classloaders with the URL being the JAR url
  • Retrieve the main class using reflection and invoke the `main` method on it

Anyways, you really need not run the first zip. There is absolutely no difference between the two JARs code wise. The first JAR was uploaded so as to show the extra classes present in that JAR which are used for dynamically setting the classpath based on nested zips. Trying out the same in Eclipse should give you a a better picture.

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

Also the posted notes on executing the programs has a different name than the zip file:
second-external.zip vs second-internal.zip

That was a mistake on my part. You got those names right in the run.

Here's what I get in the console when I run the zip files. What is the first one supposed to do? Why is it trying to get permissions?

The second one works because all the dependencies have been unjarred and copied to the new JAR file and hence it has the same effect as that of having the entire Log4j source code in your own project (and thereby its class files in the JAR).

The first one doesn't work because the Eclipse utility class attempts to read the Manifest file, read the JAR files packaged in the JAR file and add them to the classspath of my Postfix calculator. Since all this isn't done by default by the `java` process but our custom code, the security exception is thrown. What kind of policy file are you using? If you don't give it even the "read" permissions, I don't think the first approach would work out.

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

Why do you want one jar file inside of another jar file?

This is so that the JAR can be self-sufficient in executing your packaged application without relying on the user to place the JAR dependencies at pre-determined locations.

What programs are able to access the contents of the internal jar file?

AFAIK, there is no "standard" way of referring to a JAR file which is packaged within a given JAR file. Currently there are two approaches that are followed by packaging tools:

  • Approach 1: Create a custom classloader which will be the main class for our JAR and which is responsible for loading the contents of the JAR file packaged in the JAR. Here the manifest file is the one which is responsible for all the magic. In this case, we use the utility class offered by Eclipse for doing the same. Take a look at the contents of the "org" package in the attached "first-external.zip" file.
  • Approach 2: Uncompress all the dependent JAR files (e.g. log4j) and place the entire package hierarchy in the newly created JAR

Eclipse supports both the behaviors (enabled by selecting option 1 or option 2 in the "Library Handling" part which I mentioned in my previous post). I'm currently attaching the two JARs (zips, doesn't really matter) created using both the approaches in case you are interested. It's a throwaway Postfix calculator which uses log4j instead of sysouts. For executing:

java -jar first-external.zip "12 3 /"
java …
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The logical thing to do here is to package all the runtime dependencies with your application JAR i.e. have the Bouncy jar present in the application jar file you create. If you are using eclipse, it's pretty easy.

1) Right Click Project -> Export -> Java -> Runnable JAR
2) In Launch Configuration select the name of your main class
3) In export destination select the path and name for your application JAR
4) In Library handling select the second option (package required libraries...)
5) Open the newly created JAR with any unzip utility and verify whether you have a Bouncy jar placed inside the newly created JAR. If it isn't go to step 6 else step 7
6) Right Click on project -> Java build path -> Order and Export tab; ensure that the Bouncy jar is checked.
7) Fin

You are now done. Just run the generated JAR using the command:

java -jar YourAppJar.jar

and it should work without any hassles.