comp.lang.java.programmer http://groups-beta.google.com/group/comp.lang.java.programmer [EMAIL PROTECTED]
Today's topics: * Two inheritence hierachies are associated - Cast or Hide ? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/37441f8dca8b8d7b * background process: existing jsp/servlet or new applet? - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/22361eba54ae92f9 * Exception in thread "main" java.lang.NoClassDefFoundError - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/26169d28389c68bd * String reuse - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7689b54f75702319 * Java Class File loader demostration app - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d86b0de046797a6f * Receiving Unicast packets on Multicast socket - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e907757f0d4c609d * Character encoding between Win and *nix - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d00907704bee1888 * Round a Double - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/159d9c3cd9c737ed * meaning of synchronized keyword - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/493bf61d1c5501d3 * 1.4.2 translate errors - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/500030113b379ec * Unable to establish a socket connection - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3db1070c05ec0b49 * Experienced programmer: where to start with Java? - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/92371952fdc705d2 * help with my first project on first job, how to read a strange file, thanks a lot!!!!!!! - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8c32ba1a17d68c9a * school viva question? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/61e5d7e09c6dd6a6 * Applet console in internet explorer gone? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/665ca7a354dd89d8 * How do I make my JDialog's buttons respond to enter key? - 2 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/42d85a46a4a0b455 * Parsing commnad lines - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6c763684e884ce5e * Java, Hyperterminal, File Transfer - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/1c43517d2ed0e59d * Building Java Apps for Mobile Phones - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f7cac84d6b2aaed0 ========================================================================== TOPIC: Two inheritence hierachies are associated - Cast or Hide ? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/37441f8dca8b8d7b ========================================================================== == 1 of 1 == Date: Fri, Oct 22 2004 1:35 pm From: "John C. Bollinger" <[EMAIL PROTECTED]> VisionSet wrote: > "John C. Bollinger" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > >>If you like, you can create a method to do it for you (e.g. ButchDog >>getDogAsButchDog()); that might be particularly appealing if you are >>already self-encapsulating anyway, and/or if you don't want class A to >>expose its member variable directly. >> > > > Actually, something else... > > This is all very well when you have a class to put method body in to do the > cast but if you have interfaces you end up with this sort of thing: > > interface Dog { > > Bone getBone(); > } > > interface ButchDog extends Dog { > > ButchBone getButchBone(); > } > > ButchBone being a subclass of Bone I don't personally find the interface case any more confusing than the class case. YMMV. John Bollinger [EMAIL PROTECTED] ========================================================================== TOPIC: background process: existing jsp/servlet or new applet? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/22361eba54ae92f9 ========================================================================== == 1 of 3 == Date: Fri, Oct 22 2004 1:42 pm From: Bryce <[EMAIL PROTECTED]> On 22 Oct 2004 11:25:30 -0700, [EMAIL PROTECTED] (robert) wrote: >- post to the controller servlet which spawns a thread to do the db > update, then sends a response back to the browser. all using the > existing infrastructure. adv.: the application comes back fast. > disadv.: one loses contact with the db update, so confirming that > it worked is some work. We do exactly this (using ThreadPools and worker threads). You lose track in that its an asynchronous transaction. A status page retrieves the data, to view if the transaction was successful. -- now with more cowbell == 2 of 3 == Date: Fri, Oct 22 2004 2:16 pm From: "John C. Bollinger" <[EMAIL PROTECTED]> robert wrote: > given an existing code base of jsp/servlet ala Struts; how best > (efficiency of execution secondary, getting the code done primary) to > support background processing: spec. database writes?? > > - post to the controller servlet which spawns a thread to do the db > update, then sends a response back to the browser. all using the > existing infrastructure. adv.: the application comes back fast. > disadv.: one loses contact with the db update, so confirming that > it worked is some work. > > - add an applet, which spawns a thread to do the db update. adv.: the > applet can keep track of the update, and can respond with update > status with a bit less work. disadv.: integrating the applet with > the existing L&F of the jsp. > > oddly (it seems to me), i can't find any discussions of these alternatives, > either on c.l.j or various servlet texts. You sure have a slow DB update going on if the servlet can't just wait until the update is done to respond. Are you sure you're not making work that doesn't need to be done? Does the client actually need to know when the background job has finished? Supposing that you really do need to do this sort of thing, a solution I have seen before is that the server sends a page containing an "in progress" message to the client; the page auto-refreshes every few seconds until the background work is complete; and then the client gets a page with a "job complete" message. I would recommend against trying to work up an applet specifically for this task; it would be way more trouble than it's worth. John Bollinger [EMAIL PROTECTED] == 3 of 3 == Date: Fri, Oct 22 2004 4:39 pm From: "Will Hartung" <[EMAIL PROTECTED]> "robert" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > given an existing code base of jsp/servlet ala Struts; how best > (efficiency of execution secondary, getting the code done primary) to > support background processing: spec. database writes?? > > - post to the controller servlet which spawns a thread to do the db > update, then sends a response back to the browser. all using the > existing infrastructure. adv.: the application comes back fast. > disadv.: one loses contact with the db update, so confirming that > it worked is some work. > > - add an applet, which spawns a thread to do the db update. adv.: the > applet can keep track of the update, and can respond with update > status with a bit less work. disadv.: integrating the applet with > the existing L&F of the jsp. We used an auto-refreshing hidden frame. We create the process, give it an ID, spit off a thread, and then the process updates a database row (in a seperate transaction) using the ID, and then we have the auto-refreshing hidden frame query the servlet layer and then update the displayed frame based on what it gets from the status table. When it completes, we redirect to the result page. This technique will work whether you run the process in a seperate thread, or spit it out to a handy JMS server to do the processing. Regards, Will Hartung ([EMAIL PROTECTED]) ========================================================================== TOPIC: Exception in thread "main" java.lang.NoClassDefFoundError http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/26169d28389c68bd ========================================================================== == 1 of 2 == Date: Fri, Oct 22 2004 1:49 pm From: [EMAIL PROTECTED] (Roubles) > > Hi All, > <snip> > > #47 > javac Cell.java GameOfLifeBoard.java GameOfLife.java > > RunButton.java > > Assuming your source files contain lines like this: > package org.eclipse.lifegame.domain > then use this: > > javac -d . Cell.java GameOfLifeBoard.java GameOfLife.java > RunButton.java > > <snip> > > #49 > java -cp . org/eclipse/lifegame/domain/GameOfLife > > Exception in thread "main" java.lang.NoClassDefFoundError: > > org/eclipse/lifegame/domain/GameOfLife > > java -cp . org.eclipse.lifegame.domain.GameOfLife This worked beautifully (thanks to all that replied), on windows, but on my linux system it hangs. # javac -d . Cell.java GameOfLifeBoard.java GameOfLife.java RunButton.java # java -cp . org.eclipse.lifegame.domain.GameOfLife Hello. Got this far. Got this far 2. Got this far 3. [ctrl-c] [EMAIL PROTECTED] domain]# # cat GameOfLife.java package org.eclipse.lifegame.domain; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.applet.*; import java.io.*; import java.text.NumberFormat; public class GameOfLife { public static void main(String[] args) { System.out.println("Hello. Got this far."); //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { GameOfLifeBoard b = new GameOfLifeBoard(); System.out.println("Got this far 2."); b.displayGUI(); System.out.println("Got this far 3."); } }); } } No frame pops up. Nothing happens. I have ctrl-c the application. Any Clue ? tia, rouble == 2 of 2 == Date: Fri, Oct 22 2004 3:20 pm From: Sudsy <[EMAIL PROTECTED]> Roubles wrote: <snip> > This worked beautifully (thanks to all that replied), on windows, but > on my linux system it hangs. Probable cause: application cannot connect to the X11 server. Either the server is not running (you haven't run the "startx" command) or it's running under someone else's uid. In the latter case, do a "man xhost" to figure out the command you need to run to permit other users to connect to the server. NOTE: The error message is not generated immediately. IIRC it can take 30 or 60 seconds to fail. Make sure that you don't ^C the app too soon else you'll never see the message. -- Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development. ========================================================================== TOPIC: String reuse http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7689b54f75702319 ========================================================================== == 1 of 1 == Date: Fri, Oct 22 2004 1:58 pm From: "John C. Bollinger" <[EMAIL PROTECTED]> Lee Fesperman wrote: > Tony Morris wrote: > >>"Matt SDF Smith" <[EMAIL PROTECTED]> wrote in message >>news:[EMAIL PROTECTED] >> >>>Java creates a String constant pool where all String literals live. >> >>This comment is potentially misleading. >>The concept of a "String literal pool" is in fact a very abstract one, that >>should be used only to understand how String compile-time constants (JLS 2e >>15.28) are handled at runtime. That is, there is no 'actual pool'. > > > Why do you say that? java.lang.String#intern() states that it uses the pool (of > unique > strings.) The class String maintains a pool of unique Strings, to which String.intern() method may add a String when invoked. References to compile-time constant Strings are guaranteed to refer to an interned String. However, as I was recently made aware, otherwise unreferenced String instances can be GC'd from the intern pool ("can" in the sense that recent Sun JVMs can be observed to do so), so it is not in general safe to assume that the String instance representing a particular compile-time constant String at one point in your program's execution is the same instance that represents the same or an equal String at some other point in your program's execution. Whether this is a reasonable behavior is subject to debate, but the fact that Sun's own JVM exhibits it makes the question rather moot. John Bollinger [EMAIL PROTECTED] ========================================================================== TOPIC: Java Class File loader demostration app http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d86b0de046797a6f ========================================================================== == 1 of 2 == Date: Fri, Oct 22 2004 2:02 pm From: "John C. Bollinger" <[EMAIL PROTECTED]> Albretch wrote: > I need one. Kind of a hex file viewer that understand teh java class > file format definition > > I looked into Bill Verner's "Inside the JVM 2e" examples and found out > that he wasn't really reading through the class file format but a mock > text file "/applets/GettingLoaded/ActText.txt" > > Now, isn't that one a really odd joke or what? > > Where could you get a viewer that steps through the java class file? You could build one fairly easily with Jakarta BCEL. (BCEL == ByteCode Engineering Library.) There may be existing apps that do what you want, but I can't name any for you. John Bollinger [EMAIL PROTECTED] == 2 of 2 == Date: Fri, Oct 22 2004 4:12 pm From: [EMAIL PROTECTED] (Albretch) As a follow up. Actually, there is ej-technologies' jclasslib www.ej-technologies.com/products/jclasslib/overview.html Which works einwandfrei for me ========================================================================== TOPIC: Receiving Unicast packets on Multicast socket http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e907757f0d4c609d ========================================================================== == 1 of 1 == Date: Fri, Oct 22 2004 2:06 pm From: [EMAIL PROTECTED] (Rich DeMarinis) Is it possible to have a single MulticastSocket also receive Unicast packets in Java? I'm able to bind one of each socket to the same port but I'd like to be able to use just one socket. I'm running under RedHat 9.0. Thanks, Rich ========================================================================== TOPIC: Character encoding between Win and *nix http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d00907704bee1888 ========================================================================== == 1 of 1 == Date: Fri, Oct 22 2004 2:10 pm From: [EMAIL PROTECTED] (Yamin) [EMAIL PROTECTED] wrote in message news:<[EMAIL PROTECTED]>... > I want to use a Windows client to send a character stream via http > to a *nix server, that should interpret my characters as such. My > problem > lies with non-ascii chars. For example: if my char is ' ' (byte 248), > I > want to keep that byte, and not the *nix interpretation of it 'ΓΈ' > (bytes 195,184). ... > I'd really like to know what kind of data you are actually passing between the two programs...as well as whether or not you have control over both ends, as well as...what are you actually trying to do. 1. You actually want to transmit binary data (numbers like int...)If it's meant to be binary data, then why not simply transmit the string representation of those numbers on a byte for byte basis? On your windows client you simply encode everything on a byte for byte basis into a string...really easy to do. then transmit that big string. YOu will end up using 2X bandwidth as if you were transmitting binary only data...but that's what you get for sending through http. 2. For lord knows what reason, you actually want to transmit textual data from your windows PC to the unix server without the character translation...guess, what...I'd do the exact same thing here. On the windows client, get the numerical value of your characters. Hopefully your character set has each character being a set size. Convert these to bytes, and then convert that into a String representation. Yamin ========================================================================== TOPIC: Round a Double http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/159d9c3cd9c737ed ========================================================================== == 1 of 1 == Date: Fri, Oct 22 2004 2:16 pm From: marcus <[EMAIL PROTECTED]> If I need Strings of a particular number of decimal places I usually work in ints at the order of magnitude I need. 16.35 = 1635, with a routine that takes the int and returns a string, modified with placeholders if necessessary. Fast and neat, and no rounding. -- clh <- Chameleon -> wrote: > e.g. > > Double d = 12.34567; > I want this String: "12.35" and this Double: 12.35 > > Double d = 12; > I want this String: "12.00" and this Double: 12 > > > How? ========================================================================== TOPIC: meaning of synchronized keyword http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/493bf61d1c5501d3 ========================================================================== == 1 of 1 == Date: Fri, Oct 22 2004 2:40 pm From: marcus <[EMAIL PROTECTED]> (see *) Tri, trying to reconstruct your thought process and actual questions / issues / needs based on your posts is numbing my brain. You start by asking questions incorrectly using jargon like "spin" and "sleep", you display a reasonably shallow understanding of the topic as a whole, then you insist you need documented specifications to prove some sort of theory you are working on. Why in heaven's name are you posting to a newsgroup asking if there is a published work specifying how a thread functions in a JVM? Of course there is a spec. A JVM could not be written without a spec. Could you read the spec if you had it? I imagine if you could read the spec you would know where to find it and what questions to ask. If not, how are you going to prove anything -- take a newsgroup survey? Or you just need a paragraph or to to plagiarize for your project. gods help the next generation of programmers. Learn to paint. >>> >>>The multithreaded application I'm writing runs on Windows 2000 on a >>>quad processor machine (Intel Xeon 500Mhz processors). I'm comparing >>>Java's synchronized locking with lock-free algorithms. Looking at the >>>test results, I do *need to know* what happens to a thread when it is >>>blocked using synchronized locking. I'm also using JDK1.5. >>> >>>Does it spin? >> >>no > > > > *Where can I verify this?* Is there some published work stating this? > > Thank You, > > Tri ========================================================================== TOPIC: 1.4.2 translate errors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/500030113b379ec ========================================================================== == 1 of 3 == Date: Fri, Oct 22 2004 2:42 pm From: "Chris Uppal" <[EMAIL PROTECTED]> Andrew Neiderer wrote: > java.lang.ArrayIndexOutOfBoundsException: 5376 > > at com.sun.tools.javac.v8.code.ClassReader.readPool(ClassReader.java:453) > at com.sun.tools.javac.v8.code.ClassReader.readName(ClassReader.java:554) > at > com.sun.tools.javac.v8.code.ClassReader.readMethod(ClassReader.java:798) > at com.sun.tools.javac.v8.code.ClassReader.readClass(ClassReader.java:883) > at > com.sun.tools.javac.v8.code.ClassReader.readClassFile(ClassReader.java:936) Can you compile /anything/ ? Does even a simple 'hello world' fail in the same way ? My first guess, looking at the above, is that your java compiler is breaking because it's trying to read a corrupted classfile somewhere. Just a very remote chance, but do you have an incomplete file hanging around from some previous attempt at compiling ? -- chris == 2 of 3 == Date: Fri, Oct 22 2004 3:26 pm From: "Yogo" <n o s p a m> "Alex Hunsley" wrote > > If the replying post is relaying information to the OP about something > they did in their post the wrong way - then yes, it is clearly acceptable, > if you look at the way Usenet works currently: how often is a post, which > addresses the OP's bad form of posting style, marked 'off-topic'? Never > seen it, in my experience. And I've never seen anyone make a fuss about it > before now. I've put "Off topic" in the subject of my reply to tell people that my reply had nothing to do with the original topic "1.4.2 translate errors" so that they don't have to loose time reading my reply if they are only interested in the original topic. I think that makes sense. > Can you provide links to messages on google groups that show anyone else > is bothered by that? On the contrary, I can supply you with any number of > posts that show that the thing you're complaining about is accepted > standard practice. Hmm, you've never seen people complaining about off-topic messages? > I think the key is that while mentioning a technicality about someones > post isn't talking about the topic at hand, it isn't talking about a > different topic either, which is what "off-topic" would suggest (at least > to me). > > Tell me, honestly, what you think hurts usenet more: people multiposting > ad nauseum, or people giving feedback on how better to use usenet without > adding 'off-topic' to the subject line? Personnally I don't care about multipost as long as the groups are related to the topic. But I'm annoyed by multipost when the message has nothing to do with the group: it's like, hmmm, a time-waisting off-topic message (without any clear mention of its off-topicness). Yogo == 3 of 3 == Date: Fri, Oct 22 2004 3:55 pm From: Paul Lutus <[EMAIL PROTECTED]> "Yogo" <n o s p a m> wrote: > > "Paul Lutus" wrote: >> Your system has a bug -- it made you post the exact same post in two >> different newsgroups. This is called "mutiposting" and it is universally >> unacceptable. > > Is being off topic without mentioning it _clearly_ acceptable ? Usenet rule discussions are always on-topic, and you just revealed your total ignorance of Usenet rules of behavior. > No, it's not. False premise, false conclusion. > So please mention that your post is off-topic or don't post it at all. Learn something before posting again. -- Paul Lutus http://www.arachnoid.com ========================================================================== TOPIC: Unable to establish a socket connection http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3db1070c05ec0b49 ========================================================================== == 1 of 1 == Date: Fri, Oct 22 2004 2:54 pm From: Steve Horsley <[EMAIL PROTECTED]> S J Rulison wrote: > > Actually, I didn't get any exceptions. And I guess I should have > mentioned that in my original post. In that case you are connecting succesfully. There are only two possible outcomes to calling new Socket(), and that is either a connected socket, or an exception thrown. Maybe you are catching and ignoring the exception? Steve ========================================================================== TOPIC: Experienced programmer: where to start with Java? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/92371952fdc705d2 ========================================================================== == 1 of 2 == Date: Fri, Oct 22 2004 2:57 pm From: [EMAIL PROTECTED] (Dave) I'm an experienced programmer with a strong background in OOP and I'm interested in learning Java. I pick up languages very quickly, so the syntax does not concern me, although I suspect, like most languages, it takes time to gain experience learning the libraries and foundation classes. I'm wondering where to start with Java. I'm not talking about the Java For Dummies. I mean what aspects of Java should I be learning: applets, programs, wireless? I realize it's used in a wide variety of devices and environments, so my main question is: I don't even know what I want to do with it yet, I just like it - where do I start? Any ideas? == 2 of 2 == Date: Fri, Oct 22 2004 4:33 pm From: "Will Hartung" <[EMAIL PROTECTED]> "Dave" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I'm an experienced programmer with a strong background in OOP and I'm > interested in learning Java. I pick up languages very quickly, so the > syntax does not concern me, although I suspect, like most languages, > it takes time to gain experience learning the libraries and foundation > classes. I'm wondering where to start with Java. I'm not talking > about the Java For Dummies. I mean what aspects of Java should I be > learning: applets, programs, wireless? I realize it's used in a wide > variety of devices and environments, so my main question is: I don't > even know what I want to do with it yet, I just like it - where do I > start? You need to approach it from the other end. For all the reasons you mentioned, you should pick "what do you want to do" and start there. Since you can pretty much do anything you want, don't "learn Java", choose a task and then simply use it, and learn the appropriate bits as you go along. Note that most folks who just want to "learn C" don't have this question, they simply do what they want and go from there. All of the the multitude of Java acronyms and projects et al are worthless if they're not applicable to your application. Let your application guide you. There's nothing stopping you from browsing the rest of the store, but don't let it overwhelm you or distract you from whatever it is you plan on doing. Good luck! Regards, Will Hartung ([EMAIL PROTECTED]) ========================================================================== TOPIC: help with my first project on first job, how to read a strange file, thanks a lot!!!!!!! http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8c32ba1a17d68c9a ========================================================================== == 1 of 3 == Date: Fri, Oct 22 2004 3:17 pm From: [EMAIL PROTECTED] (matt) Java guys: this is my first project at my first job. so pls help if you could. i am working with a text file with strange format. The file has a lot of white space between the last line of valid text and the end of file character. And the file is update frequently. New valid text is appended behind the original valid text and overwrite some whitespace. I need to feed this file as an input to an application. but this application only take files without such whitespace. The application need to read the file frequently to see whether new text is appended. if there is, get the appended text. My initial solution is to convert the original file into a new file in which the whitespace is truncated. then the application can read the new file. possibility 1: loop read 1 line of text of original file write this line to new file until read the long line of white space close both file in this case, what class and method should i use, especially in examing the white spaces? possibility 2: the previous one is not smart because the same text is read and write each time when the file is read. so is there a way i can just each time check whether update happens to the file and then just write the update to the new file? such as in C, a file pointer know the position of last read. can i do the same in Java or C#? or other ways to do it? possibility 3: very unlikely but smarter, read the file in a stream, truncate the whitespace inside the stream, then feed the stream directly into the application. but it is unlikely because i can not change the souce code the application. any other possibilies to solve this problem? for all the possibilities, pls tell me what class and method should i use, sample code and website is extremely helpful. thanks a lot!!!!! == 2 of 3 == Date: Fri, Oct 22 2004 3:52 pm From: Paul Lutus <[EMAIL PROTECTED]> matt wrote: > Java guys: > this is my first project at my first job. so pls help if you could. > i am working with a text file with strange format. The file has a lot > of white space between the last line of valid text and the end of > file character. And the file is update frequently. New valid text is > appended behind the original valid text and overwrite some whitespace. > I need to feed this file as an input to an application. but this > application only take files without such whitespace. The application > need to read the file frequently to see whether new text is appended. > if there is, get the appended text. First things first. Explain exactly what the file consists of. Do not describe it, show it. Second, for what is probably true about your file, use String.trim() on the text lines that you read from the file. -- Paul Lutus http://www.arachnoid.com == 3 of 3 == Date: Fri, Oct 22 2004 3:54 pm From: Alex Kizub <[EMAIL PROTECTED]> You didn't mention OS. Probably it could be solved only by OS tools. For example for UNIX like it could be grep, tail -f, awk... |, > Java has other features, but since you can't change application and should only change the file (which is not good solution itself) here are some solutions for you. Use java.io.RandomAccessFile. So you can set position which you alreadu reached with method seek, you can know length of new open file with method length(). Then, I suggest, read file with method read(byte[] b) copy none white spaces to another array and write it to the new file. Pretty easy. BTW. With java.io.File you can understand last modification time and decide do you need reread file again. Good luck in your new job. Alex Kizub. matt wrote: > Java guys: > this is my first project at my first job. so pls help if you could. > i am working with a text file with strange format. The file has a lot > of white space between the last line of valid text and the end of > file character. And the file is update frequently. New valid text is > appended behind the original valid text and overwrite some whitespace. > I need to feed this file as an input to an application. but this > application only take files without such whitespace. The application > need to read the file frequently to see whether new text is appended. > if there is, get the appended text. > My initial solution is to convert the original file into a new file in > which the whitespace is truncated. then the application can read the > new file. > possibility 1: > loop > read 1 line of text of original file > write this line to new file > until read the long line of white space > close both file > > in this case, what class and method should i use, especially in > examing the white spaces? > > possibility 2: > the previous one is not smart because the same text is read and write > each time when the file is read. so is there a way i can just each > time check whether update happens to the file and then just write the > update to the new file? such as in C, a file pointer know the position > of last read. can i do the same in Java or C#? or other ways to do it? > possibility 3: > very unlikely but smarter, > read the file in a stream, truncate the whitespace inside the > stream, then feed the stream directly into the application. but it is > unlikely because i can not change the souce code the application. > > any other possibilies to solve this problem? > for all the possibilities, pls tell me what class and method should i > use, sample code and website is extremely helpful. > thanks a lot!!!!! ========================================================================== TOPIC: school viva question? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/61e5d7e09c6dd6a6 ========================================================================== == 1 of 1 == Date: Fri, Oct 22 2004 3:28 pm From: Tor Iver Wilhelmsen <[EMAIL PROTECTED]> "Madhur Ahuja" <[EMAIL PROTECTED]> writes: > I dont think, there is any. Am I right? Other than for purposes of any chosen code standard: no. Only the return type has a particular position: right before the method name. ========================================================================== TOPIC: Applet console in internet explorer gone? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/665ca7a354dd89d8 ========================================================================== == 1 of 1 == Date: Fri, Oct 22 2004 3:33 pm From: Tor Iver Wilhelmsen <[EMAIL PROTECTED]> [EMAIL PROTECTED] (bam) writes: > With ie 6 under xp it seems to be missing, how do I enable it? I have > the sun jvm installed and applets that require suns jvm by using the > object tag are running fine. The console has "moved" when you install the Sun VM and lets it take the Applet element from IE. You can open it using the "coffee cup" or "Duke" (depending on version) icon that appears in the systray when an applet loads. You should also have "Sun Java console" under "Tools" in IE if oyu have a new enough Sun VM integrated with IE. ========================================================================== TOPIC: How do I make my JDialog's buttons respond to enter key? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/42d85a46a4a0b455 ========================================================================== == 1 of 2 == Date: Fri, Oct 22 2004 4:04 pm From: "Bryan Cooper" <[EMAIL PROTECTED]> Did you try out this solution? "Bryan Cooper" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > "Paul Tomblin" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> How do I make JDialog buttons work like the buttons in JOptionPane, where >> pressing the enter/return key does the action of the selected button? At >> first I thought I was my code, so I downloaded the JDialog code from two >> Swing books, and both of them have the same problem - it highlights the >> buttons as you tab around, but hitting return does nothing. >> >> I've tried this on both Mac OS X and Linux, Java 1.4.2. >> >> -- >> Paul Tomblin <[EMAIL PROTECTED]> http://xcski.com/blogs/pt/ >> When the revolution comes, we'll need a longer wall. >> -- Tom De Mulder > > I wrote a utility class that maps actions to key events. Here's the > class: > > > import java.awt.Component; > import java.awt.DefaultKeyboardFocusManager; > import java.awt.KeyEventDispatcher; > import java.awt.KeyEventPostProcessor; > import java.awt.event.ActionEvent; > import java.awt.event.KeyEvent; > import java.awt.event.KeyListener; > import java.util.HashMap; > import java.util.Set; > > import javax.swing.Action; > > import org.apache.log4j.Logger; > > /** > * This class handles the default key strokes the users type > * in a panel or container by executing the registered actions. If no > * actions are registered, then nothing will happen. Any key > * stroke can be mapped to an action, however, the two main > * key strokes mapped in this object are the \<enter\> and > * \<escape\> keys. The key is a KeyEvent.VK_<key> static > * value and the action is what will be executed if > * the keystroke is typed by the user. > * @author B. Cooper > * @since v1.0.0 > */ > public class DefaultKeyHandler > extends DefaultKeyboardFocusManager > implements KeyListener, KeyEventDispatcher, KeyEventPostProcessor { > /** The table that will hold the actions to execute */ > private HashMap actionMap = new HashMap(); > /** The logger object */ > private Logger logger = Logger.getLogger( DefaultKeyHandler.class); > > /** > * Default Constructor > */ > public DefaultKeyHandler() { > super(); > } > > /** > * @see > java.awt.KeyEventDispatcher#dispatchKeyEvent(java.awt.event.KeyEvent) > */ > public boolean dispatchKeyEvent(KeyEvent e) { > /** Add custom code here if you need to... */ > return false; > } > > /** > * If a KeyEvent matches the key in the actionMap object, > * the associated action will be fired. > * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent) > */ > public void keyPressed(KeyEvent e) { > int keyCode = e.getKeyCode(); > Set keys = actionMap.keySet(); > Integer findKey = new Integer(keyCode); > if (keys.contains(findKey)) { > > final Action a = (Action)actionMap.get(findKey); > try { > a.actionPerformed( > new ActionEvent( > this, > 1, > (String)a.getValue(Action.ACTION_COMMAND_KEY))); > } catch (Exception ex) { > logger.error("Exception on ketPressed action!", ex); > } > } > } > > /** > * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent) > */ > public void keyReleased(KeyEvent e) { > } > > /** > * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent) > */ > public void keyTyped(KeyEvent e) { > } > > /** > * This method will map an action to the enter key event > * @param action > */ > public void mapEnterKeyAction(Action action) { > actionMap.put(new Integer(KeyEvent.VK_ENTER), action); > } > > /** > * This method will map an action to the escape key event > * @param action > */ > public void mapEscapeKeyAction(Action action) { > actionMap.put(new Integer(KeyEvent.VK_ESCAPE), action); > } > > /** > * This method will map an action to the escape key event > * @param keyEventId > * @param action > */ > public void mapKeyAction(int keyEventId, Action action) { > actionMap.put(new Integer(keyEventId), action); > } > > /** > * @see > java.awt.KeyEventPostProcessor#postProcessKeyEvent(java.awt.event.KeyEvent) > */ > public boolean postProcessKeyEvent(KeyEvent e) { > /** Add custom code here if you need to... */ > return false; > } > > /** > * @see > java.awt.KeyEventPostProcessor#postProcessKeyEvent(java.awt.event.KeyEvent) > */ > public void processKeyEvent(Component component, KeyEvent e) { > /** Add custom code here if you need to... */ > } > > /** > * This method registers a component for the mapped actions. > * @param component > */ > public void registerComponent(Component component) { > component.addKeyListener(this); > if (component instanceof Container) { > Component[] comps = ((Container)component).getComponents(); > for (int i = 0; i < comps.length; i++) { > registerComponent((comps[i]); > } > } > } > } > > Here's how you would use it: > > public MyPanel extends JPanel { > > private DefaultKeyHandler keyHandler = new DefaultKeyHandler(); > ... > public MyPanel() { > keyHandler.mapEnterKeyAction(new YourOKButtonAction()); > keyHandler.mapEscapeKeyAction(new YourCancelButtonAction()); > keyHandler.registerComponent(this); > } > ... > } > > The registerComponent method will register the panel and all of it's > contained components with the actions that you defined. > > Hope this helps out. > > Bryan Cooper > == 2 of 2 == Date: Fri, Oct 22 2004 4:39 pm From: "Bryan Cooper" <[EMAIL PROTECTED]> If that didn't help, try this link, it may help. http://java.sun.com/j2se/1.4.2/docs/api/java/awt/doc-files/FocusSpec.html "Bryan Cooper" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Did you try out this solution? > > "Bryan Cooper" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> >> "Paul Tomblin" <[EMAIL PROTECTED]> wrote in message >> news:[EMAIL PROTECTED] >>> How do I make JDialog buttons work like the buttons in JOptionPane, >>> where >>> pressing the enter/return key does the action of the selected button? >>> At >>> first I thought I was my code, so I downloaded the JDialog code from two >>> Swing books, and both of them have the same problem - it highlights the >>> buttons as you tab around, but hitting return does nothing. >>> >>> I've tried this on both Mac OS X and Linux, Java 1.4.2. >>> >>> -- >>> Paul Tomblin <[EMAIL PROTECTED]> http://xcski.com/blogs/pt/ >>> When the revolution comes, we'll need a longer wall. >>> -- Tom De Mulder >> >> I wrote a utility class that maps actions to key events. Here's the >> class: >> >> >> import java.awt.Component; >> import java.awt.DefaultKeyboardFocusManager; >> import java.awt.KeyEventDispatcher; >> import java.awt.KeyEventPostProcessor; >> import java.awt.event.ActionEvent; >> import java.awt.event.KeyEvent; >> import java.awt.event.KeyListener; >> import java.util.HashMap; >> import java.util.Set; >> >> import javax.swing.Action; >> >> import org.apache.log4j.Logger; >> >> /** >> * This class handles the default key strokes the users type >> * in a panel or container by executing the registered actions. If no >> * actions are registered, then nothing will happen. Any key >> * stroke can be mapped to an action, however, the two main >> * key strokes mapped in this object are the \<enter\> and >> * \<escape\> keys. The key is a KeyEvent.VK_<key> static >> * value and the action is what will be executed if >> * the keystroke is typed by the user. >> * @author B. Cooper >> * @since v1.0.0 >> */ >> public class DefaultKeyHandler >> extends DefaultKeyboardFocusManager >> implements KeyListener, KeyEventDispatcher, KeyEventPostProcessor { >> /** The table that will hold the actions to execute */ >> private HashMap actionMap = new HashMap(); >> /** The logger object */ >> private Logger logger = Logger.getLogger( DefaultKeyHandler.class); >> >> /** >> * Default Constructor >> */ >> public DefaultKeyHandler() { >> super(); >> } >> >> /** >> * @see >> java.awt.KeyEventDispatcher#dispatchKeyEvent(java.awt.event.KeyEvent) >> */ >> public boolean dispatchKeyEvent(KeyEvent e) { >> /** Add custom code here if you need to... */ >> return false; >> } >> >> /** >> * If a KeyEvent matches the key in the actionMap object, >> * the associated action will be fired. >> * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent) >> */ >> public void keyPressed(KeyEvent e) { >> int keyCode = e.getKeyCode(); >> Set keys = actionMap.keySet(); >> Integer findKey = new Integer(keyCode); >> if (keys.contains(findKey)) { >> >> final Action a = (Action)actionMap.get(findKey); >> try { >> a.actionPerformed( >> new ActionEvent( >> this, >> 1, >> (String)a.getValue(Action.ACTION_COMMAND_KEY))); >> } catch (Exception ex) { >> logger.error("Exception on ketPressed action!", ex); >> } >> } >> } >> >> /** >> * @see >> java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent) >> */ >> public void keyReleased(KeyEvent e) { >> } >> >> /** >> * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent) >> */ >> public void keyTyped(KeyEvent e) { >> } >> >> /** >> * This method will map an action to the enter key event >> * @param action >> */ >> public void mapEnterKeyAction(Action action) { >> actionMap.put(new Integer(KeyEvent.VK_ENTER), action); >> } >> >> /** >> * This method will map an action to the escape key event >> * @param action >> */ >> public void mapEscapeKeyAction(Action action) { >> actionMap.put(new Integer(KeyEvent.VK_ESCAPE), action); >> } >> >> /** >> * This method will map an action to the escape key event >> * @param keyEventId >> * @param action >> */ >> public void mapKeyAction(int keyEventId, Action action) { >> actionMap.put(new Integer(keyEventId), action); >> } >> >> /** >> * @see >> java.awt.KeyEventPostProcessor#postProcessKeyEvent(java.awt.event.KeyEvent) >> */ >> public boolean postProcessKeyEvent(KeyEvent e) { >> /** Add custom code here if you need to... */ >> return false; >> } >> >> /** >> * @see >> java.awt.KeyEventPostProcessor#postProcessKeyEvent(java.awt.event.KeyEvent) >> */ >> public void processKeyEvent(Component component, KeyEvent e) { >> /** Add custom code here if you need to... */ >> } >> >> /** >> * This method registers a component for the mapped actions. >> * @param component >> */ >> public void registerComponent(Component component) { >> component.addKeyListener(this); >> if (component instanceof Container) { >> Component[] comps = ((Container)component).getComponents(); >> for (int i = 0; i < comps.length; i++) { >> registerComponent((comps[i]); >> } >> } >> } >> } >> >> Here's how you would use it: >> >> public MyPanel extends JPanel { >> >> private DefaultKeyHandler keyHandler = new DefaultKeyHandler(); >> ... >> public MyPanel() { >> keyHandler.mapEnterKeyAction(new YourOKButtonAction()); >> keyHandler.mapEscapeKeyAction(new YourCancelButtonAction()); >> keyHandler.registerComponent(this); >> } >> ... >> } >> >> The registerComponent method will register the panel and all of it's >> contained components with the actions that you defined. >> >> Hope this helps out. >> >> Bryan Cooper >> > > ========================================================================== TOPIC: Parsing commnad lines http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6c763684e884ce5e ========================================================================== == 1 of 1 == Date: Fri, Oct 22 2004 4:13 pm From: Paul Lutus <[EMAIL PROTECTED]> Travis Spencer wrote: > > "Thomas Weidenfeller" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> Travis Spencer wrote: >>> I was hopeing to have a conversation aboue software engineering rather >>> than hacking. >> >> No, you were hoping that someone does your homework, like the horde of >> students currently mistaking the comp.lang.java.* groups for cheaters >> paradise and thinking we all just can't wait doing lazy student's >> homework. >> > > You've never been more wrong, Thomas. Then you will have no problem posting your code to prove your integrity and your point. -- Paul Lutus http://www.arachnoid.com ========================================================================== TOPIC: Java, Hyperterminal, File Transfer http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/1c43517d2ed0e59d ========================================================================== == 1 of 1 == Date: Fri, Oct 22 2004 4:15 pm From: Paul Lutus <[EMAIL PROTECTED]> G Winstanley wrote: > On Thu, 21 Oct 2004 08:54:53 -0700, the cup of Paul Lutus > <[EMAIL PROTECTED]> overfloweth with the following: > >> >> >> >> ...SNIP... >> >> >> >> This is not an automatic code creation machine. Please post your code >> >> and ask specific questions. >> > >> > But it seems that you might be an automaton Paul. Almost every post I >> > see here from you is simply complaining that people don't post code. >> >> And that problem is solved by having people post their code along with >> their code creation questions. The reply I gave, by the way, is hardly >> limited to me. All the regulars offer the same advice. >> >> > OP is >> > asking for generic advice on solving a problem, which is a very valid >> > reason for using this NG. He obviously requires direction rather than >> > criticism. >> >> Which criticism was that? Point it out. >> > > It was an indirect criticism of not posting any code, thereby not enabling > anyone to help. That is not a criticism, unless all teaching is criticism in disguise. > It's simply not the case that a problem *requires* code > submission to be answered usefully. It is the case in this case. -- Paul Lutus http://www.arachnoid.com ========================================================================== TOPIC: Building Java Apps for Mobile Phones http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f7cac84d6b2aaed0 ========================================================================== == 1 of 1 == Date: Fri, Oct 22 2004 4:53 pm From: "Lee" <[EMAIL PROTECTED]> "Lee" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > If I bought the correct lead (either USB or serial) for my phone and > connected the phone to my PC how easy would it be to use java to access the > functions of the phone via the lead? Ideally I would like to send SMS > messages from my PC. > > anyone?? btw, cheers for the above advice ======================================================================= You received this message because you are subscribed to the Google Groups "comp.lang.java.programmer". comp.lang.java.programmer [EMAIL PROTECTED] Change your subscription type & other preferences: * click http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe Report abuse: * send email explaining the problem to [EMAIL PROTECTED] Unsubscribe: * click http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe ======================================================================= Google Groups: http://groups-beta.google.com
