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

> Did you remake some of the old API listings with new and improved ones that consist of
> examples of function usage? O_O

No, I didn't. It's one of those sites which mirror the Java docs along with samples wherever possible. And yes, setting up something of this sort definitely takes up a lot of effort so we should be thankful to those who did this when referring to their API usage / examples. :-)

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

> for some reason the file doesn't start with a eof character does it?

EOF isn't a character, this is one of the reasons why the read method in Java and the getchar / fgetc function in C returns an int instead of a char [hint: since char is unsigned, there would be no way of differentiating between a valid character and an EOF being reached]. An EOF is signaled when no more bytes could be read from the underlying stream / file. EOFException , -1 and null are some of the ways used to signal an EOF in Java.

~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

You don't need `session' to display the request parameters; just use request.getParameter("parameterName") inside your servlets' doGet / doPost and you should be good to go.

BTW, you can get a reference to the `session' using the HttpServletRequest ; read the API docs.

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

> 1. Should we use any FrameWorks ? if yes. which one is better and simpe ?

Yes, using one of the Frameworks out there would be far better a choice, no point in reinventing the wheel as long as you know what goes behind the scenes. I have worked with JSF and found it to be quite unsatisfactory. The best bet here would be to try out some of the widely used frameworks out there, implement a prototype and get a feel of how things work out to be. Struts2, Spring MVC, Wicket etc. come to mind. Here is an interesting read.

> 2. If not using any Framework, then what you suggest ?

If you don't use any framework, you end up creating one in the process of developing a complex application like forum. It all depends on what you are up to; if this is a learning activity either implement everything from scratch [if you have enough time!] or use a framework and understand its internals. If you are into serious business, using a framework is advisable.

> 3. any reference through how to make a simple Forum using MVC pattern.

As for the open source forum softwares out there, here is a good reference for you.

./sos

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

> I guess that you mean something like Subversion?

Yes, or maybe CVS.

> lets say that someone would like to add some functionality 2 years later.
> Thats why I would like to allow page to use plug-ins or modules.

Well, like I said in my previous post, following good J2EE practices and design patterns ensures that the enhancements are as smooth and painless as possible. You might also want to look into JSP includes [both static and dynamic] to add real *modularity* to your page i.e. your typical page would be composed of a header inclusion, the body and a footer. This is how the tiles concepts in Struts works. Google for those terms and it would be clear enough for you.

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

Trial and error has little place in programming; get a good book or a solid online reference (MSDN or Mozilla tutorials) and learn more about Ajax.

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

> I'm using ajax and can't use post method!!

Technically, you *can* use the POST method when using Ajax, there is nothing which prevents you from doing so; whether it pertains to your application/business is another question.

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

You have two options:
- Either come up with intelligent URL rewriting rules so that situation as mentioned above can be effortlessly handled. I am sure it can be, it just requires a bit of tact with regular expressions, that's all.
- Use the POST method when making asynchronous calls; this isn't as such recommended if you are trying to get some query results.

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

Look into the DOM methods createElement and createTextNode (a simple google search should give you a lot of food for thought).

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

> here it is impossible to add variables to the url and success

Why is it impossible?

What prevents you from creating a URL of the form http://somesite.net/en/page?name=somename&age=someage ?

Anyways, if the operation involves POSTing data rather than GETting it, consider using POST requests rather than GET ones when making asynchronous calls.

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

> use a for loop for a known size

Not necessary; while loops can be completely avoided. A `for' loop can easily replace a `while' and `do while' looping constructs.

// while equivalent
String line = null;
for( ; (line = reader.readLine()) != null; ) {
  // process the line read
}

// do..while equivalent
boolean keepGoing = true;
for( ; keepGoing; ) {
  // do some processing
  if(reply.equals("quit")) {
    keepGoing = false;
  }
}

@carlcarman: Consider using code tags the next time you post code snippets.

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

> The code fails if the url does not end in a filename. So if I were to input:

You have a URL and it points to a resource; filename or not, it doesn't matter. There are multiple representations of exposing the same resource. The different representations don't matter as long as they expose the required resource; http://www.google.com/ or http://www.google.com/pages/index.html or http://www.google.com/index.html doesn't matter as long as I get the resource `index.html'.

> h t t ps://w w w.sportsbet.com.au/results/racing/Date/today

Hint: Secure resources require authentication information be supplied before you access them.

> The code fails if the url does not end in a filename.

Fails in what sense? Don't you get a response or are you unable to come up with a file name? If it is the latter, you need to come up with a better design than mapping remote resources to file names. If your final motive is scraping data from a web page, dump the file name convention and either directly process the HTTP response or come up with a better naming scheme.

> The problem you are running into is with indexing urls that are "urlrewrite"

That isn't a problem, it's just a way of exposing meaningful representations to the client. It's a technique widely used to create user and search engine friendly URL's. Plus it is the responsibility of the server to process the URL in a way previously configured …

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

If possible, set up a version control system so that at every point in time the entire team has a view of the functionality currently existing in the system. Follow good J2EE practices by making use of JSTL instead of using scriptlets so that you don't end up creating messy and difficult to maintain pages.

Assigning a given functionality to a member shouldn't present any problems unless you are working on something which depends on other modules. Also make sure the changes are planned as opposed to ad hoc.

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

Post the formal problem definition as mentioned in your assignment and we might just help you with a pseudo code / class design.

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

Oh yes, the enhanced for loop certainly deserves its own mention. But I guess Iterators still have an upper hand here given the feature that one can add/remove elements when iterating. :-)

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

Dear Ming,

We are also very much interested in helping you study Java programming, but we strongly feel that handing out source code hinders the learning process. We recommend you start something and come back again to this message board once you are stuck.

If you still feel that grabbing the source code is a must for you, there are many open source Java games out there; you just need to google for the right things e.g. 'open source java games'.

Regards,
sos.

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

> can somebody give me some good example of how to iterate over list,

Just use an Iterator / ListIterator for iterating over a List in a implementation agnostic manner. Iterators have the benefit of being able to allow you to add / remove an element without any additional effort.

Using a simple looping construct for a LinkedList has serious performance implications since each get() walks the list till the element with the given index is found i.e. it's not a O(1) operation as in the case of an ArrayList but a O(n) operation.

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

You try to display something which you don't even process after declaring i.e. the local array `arr' declared in main(); hence the given result. Either pass the local variable `arr' to your class instances or write a display method which works on class members i.e. `arr' of Class1.

But come to think of it; this is possibly the one of the most ill designed class hierarchy I have ever seen; the naming conventions not being followed is yet another woe. Consider reading on some good material as mentioned in the Java forum sticky.

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

> I would really appreciate it if anyone could help me as i understand most of the concepts of
> java

Are you sure? The line while (operationS != 'q') && (operationS != 'Q'); is choke full of syntactic errors. Make sure you concentrate on understanding the concepts rather than just making your homework assignment *work*.

And searching the web for the problem you are facing gives you enough information to solve it yourself.

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

Unless you post a *complete* working code, there is no way we can *see* what's wrong on your code. If not that, then present a SSCE which explains your situation. Either that or use an IDE like Eclipse to help you in debugging your application.

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

Don't use scriptlets; use JSP's only for view purposes. Use JSTL along with servlet.

> whenever i retrieve that data in my jsp page, it only shows this
> Ljava.lang.String@123EGa something similar to this..

This is because you are trying to print a String array and the above just happens to how toString of an array looks like.

Here you can find some sample J2EE applications along with the J2EE design patterns free book which you can use to read more about Data Access Object pattern.

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

>The problem is, I am not the author of the original and as such have not clue as to what
> methods the classes have and in which class.

Then how do you propose on adding additional functionality as mentioned in your first post?

Ezzaral commented: That's exactly what I was wondering. +13
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Don't be shy! Share some information for my Survey! %_%

OK, here is an interesting fact for your survey; I don't have a credit card. :-)

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

> - You are trying to cast a List into a Limb. this cant work.

Yes, it's true; look at my previous post for the answer.

> You have not instatiated the limbs list, how can you then call its add() method

This comment seems weird since you have instantiated the ` limbs ' list in the Mammal constructor.

BTW, your implementation of removeLimbs is broken. Why do you require instanceof checks? Plus, those nested IF blocks are incorrect. You could have simply done a limbs.clear() and got away with it.

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

Use the addAll method of the ArrayList class; it's a good idea to consult the documentation once in a while, at least for the classes which you plan on using.

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

Don't create multiple threads for the same problem if you don't intend on reading the replies given in your previous threads. In this thread, you were given a thorough explanation of how arrays work; if you still don't get it then maybe this assignment is too tough for you.

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

> do you and narue code for a living?

Me, yes; can't say the same about Narue-chan, though the last time I heard of her, she definitely did code for a living. :-)

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

> aah! its seems we're not communicating! You are complicating the code further

Yes, rightly said, because it is what you asked for in the first place. Re-read your first post:

any help on how to modify the code so that it can print out all the family members.

> NOTE: Other sections have no problem except this array section.

There is no `array section' here; it is how the toString() to the ArrayList class is implemented.

There are two ways of doing it; either the way mentioned in my first post or writing a method which takes the List , loops over it and extracts the name, either printing them or adding them again to a new List which then gets displayed.

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

> If this means anything to anyone here I think it will be a small miracle.

IMO, it isn't that difficult given the keywords in that post; most probably an assignment to create a simple compiler.

*miracle*

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

Whenever in need of a sane string representation of your instance, override the toString() method for the given class. This makes sure that each class is responsible for giving out its own representation without having to write the same temporary code again and again. For pretty printing arrays, convert them first to a list using Arrays.asList(yourArray) .

public class Family {
  private Adult father;
  private Adult mother;
  private Child[] children;

  public String toString() {
    StringBuilder buf = new StringBuilder(256);
    buf.append("Father {").append(father)
         .append("} Mother {").append(mother)
         .append("} Children {").append(Arrays.asList(children))
         .append("}");
    return buf.toString();
  }

}

public class Adult {
  private String name;
  // other instance variables go here
  
  public String toString() {
    StringBuilder buf = new StringBuilder(128);
    buf.append("Name: ").append(name);
    return buf.toString();
  }

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

Use the tabindex property supported by the A , AREA , BUTTON , SELECT , INPUT , OBJECT and TEXTAREA elements. BTW, this has got nothing to do with JSP or in fact any server side language; it's a pure markup question.

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

> You are using the value "X" in the .equals(Object) method which expects an Object as a
> parameter.

Huh? Firstly, the equals method is overridden in the String class. Secondly, if a method accepts an Object, you can pass any reference type to that method.

The problem here is that `conditional operator' is incorrectly used.

int currentPlayer = mark.equals("X") ? 1 : 0;
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

...struggling to keep a straight face after reading all those; priceless. :-)

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

I guess the same is with `IT Professionals'. ;-)

I still wonder how many of the regular posters here code for a living; but maybe that's a question which demands its own thread.

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

Your HTML document is not valid; it lacks a DOCTYPE. Also your question isn't very clear here. What kind of an help do you need since except for a few problems it pretty much looks OK. As for the formula, you would be the best person to come up with it. Here is a cleaner valid version of the same code. Just plug-in your formula calculation part and it should go well.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Grade Calc</title>
    <meta name="generator" content="Vim">
    <meta name="author" content="sos">
    <script type="text/javascript">
      function getLetterGrade(totalGrade) {
        var letterGrade = "F";
        if (totalGrade >= 90)
          letterGrade = "A";
        else if (totalGrade < 90 && totalGrade >= 80)
          letterGrade = "B";
        else if (totalGrade < 80 && totalGrade >= 70)
          letterGrade = "C";
        else if (totalGrade < 70 && totalGrade >= 60)
          letterGrade = "D";
        return(letterGrade);
      }

      function gradeCalc() {
        var gradeOut = "";

        var gradecp = document.gradeform.cp1.value;
        var gradecp2 = document.gradeform.cp2.value;
        var gradecp3 = document.gradeform.cp3.value;
        var gradecp4 = document.gradeform.cp4.value;
        var gradecp5 = document.gradeform.cp5.value;
        var gradecp6 = document.gradeform.cp6.value;
        var gradecp7 = document.gradeform.cp7.value;
        var gradeLabs = document.gradeform.labs1.value;
        var gradeLabs2 = document.gradeform.labs2.value;
        var gradeLabs3 = document.gradeform.labs3.value;
        var gradeLabs4 = document.gradeform.labs4.value;
        var gradeLabs5 = document.gradeform.labs5.value;
        var gradeLabs6 = document.gradeform.labs6.value;
        var gradetests = document.gradeform.tests1.value;
        var gradetests2 = document.gradeform.tests2.value;
        var gradeFinal = document.gradeform.final.value;
        var gradeEC = document.gradeform.ec.value;

        var totalGrade = 56 /* some formula */;

        var cp = 'some cp', lab = 'some-lab',
            exams = 'some-exams', credit = 'some-credit'

              gradeOut = "...adding …
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Read the above post; if it's still unclear, it's time for you to go back to your class notes / tutorials.

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

Post a compilable piece of code; what you posted isn't even remotely a valid Java program.

In Java, multi-dimensional arrays are represented as array of array. This allows you to ignore the second dimension when defining a two dimensional array. Generically speaking, this concept allows you to ignore all the dimensions except the first one. Also in case of a two dimensional array, the first slot of your array will hold a reference to another array and so on.

A simple example:

public class ArrayTest {

  public static void main(final String[] args) {
    arrayTest();
  }

  private static void arrayTest() {

    int[][] arrTwo = new int[3][];
    for(int i = arrTwo.length - 1; i >= 0; --i) {
      // arrTwo[i] is null since we ignored the second dimension
      // when declaring arrTwo
      System.out.println("arrTwo[" + i + "] -> " + arrTwo[i]);
    }
    System.out.println("\n\n");

    // When an array is defined, its slots hold the default value for the
    // type for which it is defined. Hence in case of an int array it
    // would be 0 while in the case of a String array it would be `null'.
    
    int[][] arrOne = new int[3][3];
    for(int i = arrOne.length - 1; i >= 0; --i) {
      // arrOne[i] is an array having length 3
      int[] tmp = arrOne[i];
      System.out.println("arrOne[" + i + "] -> " + tmp);
      for(int j = tmp.length - 1; j >= 0; --j) {
        System.out.println("arrOne[" + i + "][" + j + "] -> " + tmp[j]); …
jasimp commented: nice example +9
javaAddict commented: good explanation +4
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Can anyone tell me or give me a hint as to how am i going to sort the words
> in alphabetical order.

Look into the Collections#sort method which takes a Comparator instance to facilitate custom sorting.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
for(int number = 10; number >= 0; --number) {
  oRocket.countDown(number);
}

No?

But this seems to be logically wrong since the `driver' class shouldn't be the one performing the countdown; the rocket instance should be provided with a default counter which would be decremented and the rocket would take off when Rocket.takeOff() is called.

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

> try this <% String up = session.getAttribute("myText").toString(); %> .

...which would anyways throw a NullPointerException in this case.

> The session attribute is of object datatype.so we have to convert it to string .

What? The ` session ' variable is of the type ` HttpSession '.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
> public Payroll(String Name, String Id)
> public void setempId(String Id)

Follow Java naming conventions; `Name' should have been `name'. `setempId' should be `setEmpId'.

> private double empPR;            // holds the Employee Pay Rate
> private double empHR;            // holds the Employee Hours Worked
> private double grossPay;         // holds the Employee Gross Pay

Though not a big concern here, you should know that calculations using `double' and `float' are not exact. Always use the BigDecimal class when doing monetary calculations.

darkagn commented: Didn't know that about BigDecimal, cheers :) +3
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Push the list into the session and access it in your JSP using JSTL. Look into the c:forEach tag of JSTL.

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

The logs generated by your web server and your application.

Assuming you are using a logging library, your application should generate some kind of logs when it runs. E.g. when an exception is encountered, where do you see its exception trace?

Also, in case of Apache Tomcat, a servlet container, the logs are generated at <TOMCAT_HOME>\logs.

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

validation of an url..
got from google search..

var theurl=document.formaddad.url.value;
     var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
     if (!tomatch.test(theurl))
     {
          window.alert("URL invalid..See the example giving beside the textbox.");
		 a.url.focus();
		  return false;
             }

Today I learned that 'http://...zzz' is a valid URL....

I learned to eat lobster.

So is it that this was the first time you ate a lobster or were you eating lobster all these days not knowing it was a lobster or was it that you did eat a lobster but made sure that you didn't learn it. ;-)

I learned that reading completely random things that others claim to have learned today is not extraordinarily illuminating.

That wasn't very illuminating. :-)

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

> Could I tokenize and parse the query string that is sent and set each tokenized part to
> toAddress, ect?

Sent where? Just having a HTML form doesn't help; you need to provide an action which will be executed once the form is submitted. Unless you have your own web application hosted somewhere, this isn't possible; there is nowhere for the data to be submitted.

> I'm not real familiar with jsp or servlets.

Now is a good time; head over to Sun's site for sample applications / tutorial. Either that or just create a simple console driven application.

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

You have a few options. You can either host a web application in a servlet container like Tomcat, submit the form to the servlet which would then do the processing. Or you can either create a standalone GUI/Command Line client which accepts the input from the user and sends the mail.

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

Bad terminology yet again.

> Yes, I am very sorry for mixing static fields and members.

Members of a class include fields, methods and nested classes and interfaces. So the statement, *mixing static fields and members* doesn't make much sense.

> Fields execute once and only once when the first object of the type is created

Fields don't *execute*, they are initialized. Static fields are initialized when the class is first loaded / initialized.

> otherwise if a program executed all static fields of all objects at compile time it would not
> be a very good thing X_X

At compile time, the `compile time constant expressions' are evaluated irrespective of whether the LHS is a static field or not. The Java Language Specification has rules laid down for what exactly are `compile time constant expressions'.

public class Test {

  private static double d = Math.PI;  // compile time constant expression

  private static Test me = new Test(); // not a compile time constant expression

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

You should have posted the entire scenario in the first post instead of posting in parts. You must have messed up with the java.policy because of which you are getting a null SecurityManager from the System. Either restore the file from a backup or re-install the JDK to fix this problem.

If you want to create your own security policy, either override the SecurityManager class to roll in your own implementation or create your own customized java.policy file for your application. Google for these topics and look at the FAQ topic at the top of this forum.

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

Use JSP's only for presenting data / view purposes only; use servlets for processing. Submit the above form to a servlet which would grab the mail related details, create a SMTPSender instance with the values obtained and do the required task.