Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
BufferedReader br = new BufferedReader(new FileReader("c:/test.txt"));
            String strLine;
            while((strLine=br.readLine())!=null) {
                if (strLine.length()>0) System.out.println(strLine);
            }

Of course, you will probably want to write those lines back out to a file instead of printing them to System.out.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> Also, if you need high performance concatenation of many strings use a StringBuffer instead.

StringBuffer is thread safe. If programming in a single threaded environment, I would recommend StringBuilder.

Good point. I tend to forget about that one since we were stuck at 1.4 code base for a long time hehe

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, from the code he posted, they are all primitive constants, so declaring them as final statics on the class should alleviate all of his concerns about the overhead. He says that his method just appends them together based upon some conditions, so it sounds like using a StringBuffer to build his result from the constants would offer him the best performance.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Also consider that Sun has a ton of online Java tutorials for free.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, since it is homework, I'll just give a general tip and let you figure the rest. Make each of your operation classes extend Thread. This means they must all implement a "run()" method. I think you can figure out how that applies to what you are aiming for.

I would also suggest that the one thing all of these do is operate on a file, so you may consider this a good thing to pass into the constructor.

For the main method, read the tutorials on basic thread handling. It should be fairly straight forward from there.

peter_budo commented: Nice advice, but I think its to early for threads :) +6
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If they are constants, you can declare them "static final" and they will only be allocated once and directly inlined into expressions.

Also, if you need high performance concatenation of many strings ( as in your "String str = v1 + v2 + v3;" statement), use a StringBuffer instead.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You should be able to just strip the roman numerals first and then remove the remaining "." occurrences.

On your other question about combining, yes, you can combine some of them but not all. If you add [ ] brackets, it becomes an OR comparision, so "[\\d\\"\\?:]" would strip all of those characters. Don't combine it with the others though, which need to match a specific sequence. If you add those expressions in between the brackets, it will strip any of those characters (such as P) even if the whole sequence does not match.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Thanks a lot for your answer.

I would like to ask you something more about split parameter.

How can I make a regular expression that delete the words that is like I. II. III. IV. .... and <P ID=#> <P>.

Well, you will have to work a little bit on the regular expressions to match on your content. The expression "<P ID=\d+>" would match your "<P ID=#>" tags, if they are always of that form. "<P>" by itself will match "<P>", so not much to that one. The roman numerals will be a little trickier, since they are merely a sequence of vertain capital letters followed by a period (in your example at least). You might get away with the pattern "[IVXLCDM]+\." for those, but there is a slight change you might accidently match some of your text by mistake (pretty unlikely I would say though.

Have I to call split a lot of times or can I do it differently?

You can first use the regular expressions to strip things you do not want to capture. If you are reading a line at a time in to a string variable, you can strip things out by calling replaceAll() with your regular expression and an empty string"" for the replacement string. After stripping out the unwanted content, call split(" ") to split on spaces to get your array of words to write out to file.

BufferedReader reader = new BufferedReader(new FileReader("foo.in"));
String inputString = reader.readLine();

// strip out …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It's worth noting as well, that if the recruiter is ignoring your C++ experience and pushing you to get Java certified when you do not have any Java experience, then the recruiter is probably worthless. Making a recommendation to learn Java because there are a lot of employment opportunities is fine, but asking you to get certified and get back to him makes the impression that he just wants to shove you into a position quickly with no regard to your ability to perform it. He just wants to get paid.

As far as study time, that depends entirely on you and how quickly you can learn enough to pass it. You don't have to take a course to take the exam. There are a ton of preparation courses out there that would love to charge you a huge fee, but you can study up for the exam on your own just fine.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Actually, you should use the split() method of String instead of StringTokenizer and use regular expressions to remove text that you do not wish to include. Split will split your string by whatever delimiter you specify and return the parts as a string array. Regular expressions will allow you to specify patterns to match the pieces you don't want to include. Sun has a tutorial on regular expressions here: http://java.sun.com/docs/books/tutorial/essential/regex/

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Perhaps your sound is in the recycle bin?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Function arguments in Java are by value, however, since object and array variables are references themselves, they are effectively by reference (sort of). Objects and arrays passed as parameters can be modified by the method, but the reference itself cannot be changed. This means that a function doSomething(Object someObject) can modify the properties of someObject, but changing the reference someObject to point to some other object will have no effect on the reference in the calling class.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Use Object arg = ie.getItem() to get the object that triggered the event.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This forum is actually for Java language programming. Your error seems to be related to settings on your particular browser.

I would recommend putting the exact message you are getting into Google and reading those forums that are coming up.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Use a BufferedWriter instead of DataOutputStream. You created a BufferedWriter like so:

BufferedWriter writer = new BufferedWriter( new FileWriter("myFile.txt") );

The tutorial that peter_budo linked should provide any other info you need on usage.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, if you have a static IP address with a registered domain, he could have obtained it from domain registry look up. Though this really has no relation to Java at all.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It appears you have copied the code from the actionPerformed() method directly into the itemStateChanged() method. The parameter to itemStateChanged function is "ie", not "e" as it was in actionPerformed.

Even if you change the "e" to "ie", the code will still not work since getActionCommand is a method of the ActionEvent, not ItemEvent. With ItemEvent, you will need to use getItem() to determine the item that was selected or deselected.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I don't think we can provide any insight without seeing the panel and frame classes.

On a side note, your may want to reconsider your design in making everything static and trying to manage the interactions by calling static methods on the objects. The main method should really only be responsible for creating whatever minimal number of objects are needed to set up the environment of your program. All other operations should be performed by those objects themselves.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just ran across this interesting example on JavaWorld http://www.javaworld.com/javaworld/jw-11-2004/jw-1101-spider.html?page=2 "Create Intelligent Web Spiders" which demonstrates connecting to servers, parsing html, etc. It might provide some good techniques to get you started.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

First let me say that I haven't written any apps to do this myself, so perhaps there are specific libraries that make these things much easier, but basically you are just talking about communicating through a socket via http. In your login case, a POST would need to be sent with the appropriate data. In the web lookup case, you are merely requesting a page and parsing the html text that is returned.

For some basic examples of http through a socket, take a look at this example: http://www.exampledepot.com/egs/java.net/ReadFromURL.html?l=rel

There are few related examples listed at the bottom of the page - one of which involves sending a POST.

Anyway, that is pretty generic info but hopefully will give you a place to start.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

There should be a ton of tutorials on the Net for both of those. I would recommend Googling for them. You might also want to check out http://www.gamedev.net.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You will need to use an XML parser to read the files for processing. If you are using J2SE5.0 or above, JAXP provides built-in XML libraries. If you are using earlier versions of Java, you will need to download a parser such as JDOM or Xerces (easily found with Google). If you use JAXP, you can find many tutorials on processing XML in Java at http://java.sun.com/webservices/jaxp/learning/tutorial/index.html

~s.o.s~ commented: Good help to beginners. +20
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

There are two commands available on a File object to create a directory. File.mkDir() will create just the directory specified by the File object. All parent directories must already exist. The second method, File.mkDirs() will create any necessary directories to create the entire path specified.

// if ParentDir exists, this invocation will work
File targetDir = new File("c:/ParentDir/TargetDir");
if (!targetDir.exists())
    targetDir.mkDir();

// if ParentDir may not exist yet, you can use 
// mkDirs() instead and all directories will be created
File targetDir = new File("c:/ParentDir/TargetDir");
if (!targetDir.exists())
    targetDir.mkDirs();
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Without a doubt, start with 2D if you are not already familiar with game programming concepts and graphics programming.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Narue and Ancient Dragon are correct. There is not a simple ratio. No developer can tell you that x minutes development results in y minutes maintenance. It just doesn't work that way. You say that you have a ratio for documentation to development. I would be skeptical of that as well. Real world development just does not work based upon such clearly defined ratios and any project is going to vary greatly. Such ratios are really only useful to people wanting to sell books on design methodologies and are often worth less than the paper upon which they are printed.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, since you don't include the Deck class, it's difficult to see the whole domain, but a couple of things stand out.

First, make the Deck class responsible for it's own Card collection. Your applet shouldn't have to push things into the Deck. The Deck will have a maximum of 52 cards, which can be obtained from Deck.dealCard() until no more cards remain in the Deck.

Second, I would create a Player class to keep track of each players current hand and perhaps a Game class to contain the rules of the current game, such as number of cards per player, etc. This would allow for different games within the applet if you want to add them later.

Whether you choose to put it in a game class or keep it in the main applet class, a method dealNewGame() could iterate the number of cards and a collection of players as follows:

for ( int i = 0; i < SIZE_OF_HAND; i++ ) {
    for (Player player : players)
        player.addToHand(cardDeck.dealCard());
}

Hope those suggestions help a bit.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You haven't specified any text for your menus. Use the constructor

JMenu gameMenu = new JMenu("Game");

and you will have a top level "Game" menu. Add the text for the other items and you will be set.

Also, you can ditch the getContentPane().add(topMenu). The setJMenuBar is sufficient.