comp.lang.java.programmer http://groups-beta.google.com/group/comp.lang.java.programmer [EMAIL PROTECTED]
Today's topics: * Execute problem with JCreator - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b864ab013f6b9085 * Java, Hyperterminal, File Transfer - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/1c43517d2ed0e59d * Is instanceof dirty? - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/395347a70489adef * Thread-question - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5766e179910e25fa * ZipOutputStream, ZipFile and Linux unzip do not agree on the file count in zip - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7aced318b9e04b5c * A Java "interface" declaration does not allow a constructor to be specified in it ... - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a241d06ab76f90b8 * stubbing methods on test objexct with jMock - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b8c79c894a412218 * Node value in a DOM model - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6ad224790943b9f * Implicit object creation - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7ea9ee9cb601f58c * braindead languages? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/c6ebaa9cc432a569 * Can't display Java gui - 2 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/70509f2693ffc62a * How to encode Japanese string into UTF-32 ? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/c919aa51791b9bdd * runtime.getRuntim().exec(somecmd) problem with linux - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a3f83ceedc3184b0 * How to translate Japanese String into UTF-32 encoded using Java APIs ? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5c01f1e464ef13e3 ========================================================================== TOPIC: Execute problem with JCreator http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b864ab013f6b9085 ========================================================================== == 1 of 3 == Date: Tues, Nov 9 2004 10:21 am From: "Mark K" <[EMAIL PROTECTED]> First of all the compile worked ( i received no errors) The book refers to 'a java - how to program manual' I tried to paste the error but I had to use paint shop pro to copy the error as its hard to paste a command prompt and part of the code here. I did try to read the help but it was 'no help' and lastly.. give a newbie a break! If you dont have an answer or can provide any help, please dont post! just that simple.... I provided what I could. I would be more than happy to send the screen shot to someones email acct. for viewing. "Mark K" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I have a simple test program that was copied from the book. It compiles > fine but when I try to execute it I get a command prompt that runs some > GE2001.exe which shows the help for trying to execute the .JAVA program. > > == 2 of 3 == Date: Tues, Nov 9 2004 11:23 am From: "Ann" <[EMAIL PROTECTED]> "Mark K" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > heres the screen shot... > > > "Mark K" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > I have a simple test program that was copied from the book. It compiles > > fine but when I try to execute it I get a command prompt that runs some > > GE2001.exe which shows the help for trying to execute the .JAVA program. Ok try this "java Test" == 3 of 3 == Date: Tues, Nov 9 2004 11:41 am From: Andrew Thompson <[EMAIL PROTECTED]> On Tue, 09 Nov 2004 18:21:58 GMT, Mark K wrote: > If you dont have an answer or can provide any help, please dont post! I have done this conversation too many times to do it again for yet another 'screaming noob', I'm too busy at the moment. So I'll ask you straight up. Are you more interested in .. a) Learning Java? b) P*ssing off those who are trying to help you? -- Andrew Thompson http://www.PhySci.org/codes/ Web & IT Help http://www.PhySci.org/ Open-source software suite http://www.1point1C.org/ Science & Technology http://www.LensEscapes.com/ Images that escape the mundane ========================================================================== TOPIC: Java, Hyperterminal, File Transfer http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/1c43517d2ed0e59d ========================================================================== == 1 of 1 == Date: Tues, Nov 9 2004 10:23 am From: [EMAIL PROTECTED] (JP) Hi, So does anyone have any insights to this file-transfer problem?? Thank you, James [EMAIL PROTECTED] (JP) wrote in message news:<[EMAIL PROTECTED]>... > Hello again, > > I just read through some more info and found out that apparently there > are zmodem implementations in Java available, except I have to > purchase them... I am not sure if purchasing is an option at this > point, does anyone know of a free implementation of zmodem file > transfer protocol that's in Java? > > If not, how about just some general ideas as to how I can implement > zmodem protocol? Or is this a non-trivial task? > > Thank you, > > James ========================================================================== TOPIC: Is instanceof dirty? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/395347a70489adef ========================================================================== == 1 of 2 == Date: Tues, Nov 9 2004 10:36 am From: [EMAIL PROTECTED] (Jesper Nordenberg) DeMarcus <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > Hi, > > I come from the C++ world and there they say "no no" when > you want to switch on type information. Even the inventor > of C++ say so. > > What's the common opinion about using the java keyword > instanceof? While I basicly agree with the other posts I think there are cases when instanceof is unavoidable. One good example is you want traverse a tree and want to perform different operations depending on the type of node you encounter. One might argue that the visitor pattern should be used in this case, but that requires that support for the visitor pattern has been implemented in the node class structure. You can't extend an existing class structure with the visitor pattern. Even if the visitor pattern has been implemented it's very awkward and inflexible solution that don't allow arbitrary arguments to be passed. The cleanest solution, which unfortunately is impossible to implement in Java, is multi-methods like those found in Nice, http://nice.sourceforge.net/visitor.html. In Java your best option is to use lots of "if (node instanceof X)" statements. Or you can use a Map<Class, Runnable> solution. Both are solutions are sub-optimal. /Jesper Nordenberg == 2 of 2 == Date: Tues, Nov 9 2004 10:39 am From: "John C. Bollinger" <[EMAIL PROTECTED]> Chris Uppal wrote: > Think of it this way: the system (Java's semantics and OO in general) is > designed so that objects are responsible for their own behaviour. That's to > say that it's /their/ responsibility to know "what they are" and what they > should do in any specific circumstance. If you use instanceof then you are > cutting them out of the loop. In effect you are saying, "no, I don't care > what > you think, I'm going to do this /my/ way". > > Now that's fine if you know what you are doing and have a good reason. But > you > are also throwing away the modularity, flexibility, comprehensibility, and > maintainability that were the point of using OO in the first place. The one place where I find myself frequently using instanceof in Java is in equals() methods, where it is common that I want to determine whether the object to compare to is an instance of the class to which the method belongs (so as to perform a comparison appropriate for that class, or return false if that's not possible). That particular kind of use doesn't seem to quite to square with your characterization (above) because the question isn't really a generic "what class are you?" but rather "is your class compatible with mine?". Would you agree that that kind of use makes more sense in your worldview? Do you have a preferred idiom to suggest? John Bollinger [EMAIL PROTECTED] ========================================================================== TOPIC: Thread-question http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5766e179910e25fa ========================================================================== == 1 of 3 == Date: Tues, Nov 9 2004 10:44 am From: "Andy Flowers" <[EMAIL PROTECTED]> Have you thought about overriding finalize() in the objects you wish to have some final clean up ? "Ao" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi everybody, > > when closing my program I would like to start a Thread which does some > cleaning up in the background, but opf course before exiting I need to be > sure, that this Thread has finished running... > > How can I wait for that Thread to finish, the following code does work, > but freezes my UI... > > ... > private boolean cleanedUp = false; > > ... > public void programmBeenden() { > Thread cleaner = new Thread() { > public void run() { > // clean up some things... > cleanedUp=true; > } > } > cleaner.start(); > > // ... do some other stuff > // finally wait for cleaner to finish > while(!cleanedUp) { > try { > Thread.sleep(100); > } catch(InterruptedExecption iuE) {} > } > > System.exit(0); > } > > > What else can I do to make sure that cleaner has finished without freezing > my UI. > > Thanks, Aloys == 2 of 3 == Date: Tues, Nov 9 2004 10:48 am From: Carl Howells <[EMAIL PROTECTED]> Andy Flowers wrote: > Have you thought about overriding finalize() in the objects you wish to have > some final clean up ? Bad idea. On most modern JVMs, finalizers seriously mess up garbage collection. In fact, if the JVM can avoid it, it'll just *not* collect objects with finalizers. It's not a very good way to get code run. If you need post-collection cleanup of non-memory resources, remember that PhantomReference is your friend. == 3 of 3 == Date: Tues, Nov 9 2004 10:52 am From: "Stefan Schulz" <[EMAIL PROTECTED]> On Fri, 05 Nov 2004 16:03:42 +0100, Ao <[EMAIL PROTECTED]> wrote: > What else can I do to make sure that cleaner has finished without > freezing my UI. Since you are shutting down anyway, take a look at Runtime.addShutdownHook() -- Whom the gods wish to destroy they first call promising. ========================================================================== TOPIC: ZipOutputStream, ZipFile and Linux unzip do not agree on the file count in zip http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7aced318b9e04b5c ========================================================================== == 1 of 2 == Date: Tues, Nov 9 2004 10:52 am From: [EMAIL PROTECTED] (C B) I think there is a bug in ZipFile... I use ZipOutputStream to build a zip file. The program zipped 72417 files, but after checking it with ZipFile, ZipFile.size() reported only 6881 files in the file. So unfortunately, Java is unable to read all the entries in the zip file, but Linux's PK-INFO (unzip) is able to read the file. I went on an older UNIX (non linux) server around here and tried unzip, it said: note: didn't find end-of-central-dir signature at end of central dir. (please check that you have transferred or created the zipfile in the appropriate BINARY mode and that you have compiled UnZip properly) The zip file is not corrupt, there isn't any data loss (with Linux's unzip I can read all entries). I'm using an IBM JVM, Java 1.4.2. Any suggestions? == 2 of 2 == Date: Tues, Nov 9 2004 11:16 am From: Andrew Thompson <[EMAIL PROTECTED]> On 9 Nov 2004 10:52:54 -0800, C B wrote: > I think there is a bug in ZipFile... Extraordinary claims require extraordinary evidence. > ..Any suggestions? One thing that extraordinary evidence will contain is a reproducible example of the behaviour. For tips on that example.. <http://www.physci.org/codes/sscce.jsp> -- Andrew Thompson http://www.PhySci.org/codes/ Web & IT Help http://www.PhySci.org/ Open-source software suite http://www.1point1C.org/ Science & Technology http://www.LensEscapes.com/ Images that escape the mundane ========================================================================== TOPIC: A Java "interface" declaration does not allow a constructor to be specified in it ... http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a241d06ab76f90b8 ========================================================================== == 1 of 3 == Date: Tues, Nov 9 2004 10:11 am From: Oscar kind <[EMAIL PROTECTED]> xarax <[EMAIL PROTECTED]> wrote: > > If Java supported full multiple inheritance (which is > the implication of interface constructors), then there > would be no need for interfaces; just use abstract classes > in place of interfaces. Which poses other problems. Imagine the following (but please bear with the slightly off analogy): abstract class Person has a non-abstract method "transport", that implements walking. abstract class MailDelivery has a non-abstract method "transport", which implements mail delivery. class MailMan extends both, and thus inherits the method transport from both classes. For some reason, there is no reason to override it. Now please think about these questions: - Which one is inherited? - If one is chosen automatically, what about dependencies in another superclass? The two methods may have an incompatible contract. - If the method autometically becomes abstract, why? Abstract methods are always marked thus (either by the keyword abstract or by being defined in an interface). - How do you select the transport method from Person? Extend the syntax again, with Person.super.transport()? It's hardly efficient to get a complicated, arcane syntax. -- Oscar Kind http://home.hccnet.nl/okind/ Software Developer for contact information, see website PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2 == 2 of 3 == Date: Tues, Nov 9 2004 12:37 pm From: "xarax" <[EMAIL PROTECTED]> "Oscar kind" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > xarax <[EMAIL PROTECTED]> wrote: > > > > If Java supported full multiple inheritance (which is > > the implication of interface constructors), then there > > would be no need for interfaces; just use abstract classes > > in place of interfaces. > > Which poses other problems. Imagine the following (but please bear with > the slightly off analogy): > > abstract class Person has a non-abstract method "transport", that > implements walking. > > abstract class MailDelivery has a non-abstract method "transport", which > implements mail delivery. > > class MailMan extends both, and thus inherits the method transport from both > classes. For some reason, there is no reason to override it. Now please > think about these questions: > - Which one is inherited? Both. > - If one is chosen automatically, what about dependencies in another > superclass? The two methods may have an incompatible contract. n/a > - If the method autometically becomes abstract, why? Abstract methods are > always marked thus (either by the keyword abstract or by being defined > in an interface). Not abstract. > - How do you select the transport method from Person? Extend the syntax > again, with Person.super.transport()? It's hardly efficient to get a > complicated, arcane syntax. The child class is the one causing the name conflict. Therefore there would be a facility to rename one of the conflicting methods in one of the parent classes. The Eiffel language has full multiple inheritance. When a name conflict arises, it is the responsibility of the inheriting class to resolve the conflict by renaming. Otherwise, a compile-time error occurs. The renaming is at the compile-time so that the compiler can distinguish which parent method is getting called. Extending the Java language to support full MI requires such language extensions to specify which constructors are called (with whatever appropriate parameters), the order in which those constructors are called, and to resolve the issue of name conflicts. On the extends clause where the parents are specified is likely where the renaming would occur through something like: ========================================= public class MailMan extends Person [rename transport:transportBlah], MailDelivery { public MailMan() { super { Person(); MailDelivery(); } } } ========================================= I used square brackets '[]', rather than braces '{}', for the renaming to avoid parsing confusion with the class body braces. The keyword "rename" is probably not a good choice, as it is likely already in wide use as a normal identifier. Another issue arises with polymorphism when the MailMan instance is up-cast to either Person or MailDelivery, and subsequently the "transport" method is called. If there was no redefinition, then the non-renamed method would likely be called. However, redefining a method in the subtype would require specifying some kind of "preference" as to which parent method is called. IIRC, Eiffel uses the term "polymorphic catcalls" for this situation and there are complicated rules as to resolving the ambiguity. In the current Java language, the last redefinition of a method is the one that takes effect. Implementing multiple interfaces with the same method signature can lead to confusion. So, such situations are avoided when practical (cannot rename inherited methods in Java). There would also be issues involving the JVM and the reflection libraries, which presume that an instance has a linear chain of parents, and interfaces are treated quite differently from classes. == 3 of 3 == Date: Tues, Nov 9 2004 12:52 pm From: "Stefan Schulz" <[EMAIL PROTECTED]> On Tue, 09 Nov 2004 20:37:31 GMT, xarax <[EMAIL PROTECTED]> wrote: > ========================================= > public class MailMan > extends Person [rename transport:transportBlah], > MailDelivery > { > public MailMan() > { > super > { > Person(); > MailDelivery(); > } > } > } > ========================================= I don't see any renames for clone(), hashCode(), toString()... This would be a major hassle. The common ancestor for all types is a nice thing, but it introduces a guaranteed set of clashes. More trouble then it is worth, IMHO. -- Whom the gods wish to destroy they first call promising. ========================================================================== TOPIC: stubbing methods on test objexct with jMock http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b8c79c894a412218 ========================================================================== == 1 of 1 == Date: Tues, Nov 9 2004 11:21 am From: [EMAIL PROTECTED] (PeterS) Bryce <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > On 7 Nov 2004 05:02:15 -0800, [EMAIL PROTECTED] (PeterS) wrote: > > >I am using jMock for doing my unit tests and it works fine. But there > >is one point I do not know how to solve it. I want to test a method ( > >e.g. "testMethod")in my object which calls another method (e.g. > >"anotherMethod") of the same object. I do not want to execute > >anotherMethod it´s own code. Instead it shall return a value > >controlled by the test case class. Can someone tell me what I have to > >do to achieve this aim with jMock? > > I'm not sure what you are trying to do. > > I think you are saying that you have a class, like this: > > public class MyClass { > public void testMethod() { > String temp = anotherMethod(); > } > > public String anotherMethod() { > .... > } > } > > Is this the case? > > Then, assuming you are testing MyClass, its not possible to do it as > written. However, if you've written your class in another way you > could (I'm throwing this together quickly, so it may not compile, but > gives you an outline): > > public class MyClass { > private AnotherClass anotherClass; > > public void setAnotherClass(AnotherClass ac) { > this.anotherClass = ac; > } > > public void testMethod() { > String temp = anotherClass.anotherMethod(); > } > } > > public interface AnotherClass { > public String anotherMethod(); > } > > public class AnotherClassImpl implements AnotherClass { > public String anotherMethod() { > ... > } > } > > Then, your test code would look like this: > > public class TestMyClass extends MockObjectsTestCase{ > public void testTestMethod() { > MyClass myClass = new MyClass(); > > Mock mock = new Mock(AnotherClass.class); > myClass.setAnotherClass((AnotherClass)myClass.proxy); > > > mock.expects(once).method("anotherMethod").withNoArguments().will(returnValue("testString)); > > myClass.testMethod(); > > mock.verify(); > } > } > > I suppose an easier way to do it, without using Mocks is to just > subclass your class, and override the method you need to.: > > public class MyClassMock extends MyClass { > public String anotherMethod() { > return "Hard coded string"; > } > } Hi Bryce, your understanding is correct. That´s exactly what I wanted to do. Subclassing was also an idea I had but I hoped that there would be another possibilty without writing a new class. So I have to use one of the two methods - delegating or subclassing. Many thanks for your answer. ========================================================================== TOPIC: Node value in a DOM model http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6ad224790943b9f ========================================================================== == 1 of 1 == Date: Tues, Nov 9 2004 11:21 am From: "Steve W. Jackson" <[EMAIL PROTECTED]> In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Cyril Vi?ville) wrote: >:I'm using a DOM model to create a XML file of usual connections. >:All is good but when i'm using the "getMachine" method, i always have >:textnode value to null for TEXT_NODE nodes. >: >:my XML file is something like that for 1 usual connection >:<?xml version="1.0" encoding="UTF-8" ?> >:- <connexion> >: - <machine> >: <adresse>Captain</adresse> >: <port>6445</port> >: <systeme>Linux</systeme> >: </machine> >: </connexion> >: >:My java code : >: >:import java.io.*; >:import org.w3c.dom.*; >:import javax.xml.parsers.*; >:import org.apache.xml.serialize.*; >: >:public class DOMParsing { >: private Document Doc; >: >: public DOMParsing() { >: try { >: File XMLFile = new File("connexions.xml"); >: DocumentBuilderFactory Factory = >:DocumentBuilderFactory.newInstance(); >: DocumentBuilder Builder = Factory.newDocumentBuilder(); >: if (! XMLFile.exists()) { >: Doc = Builder.newDocument(); >: Element RootElem = Doc.createElement("connexion"); >: Doc.appendChild(RootElem); >: } >: else { >: Doc = Builder.parse(XMLFile); >: XMLFile.delete(); >: fileModify(); >: } >: } >: catch (Exception ex) { >: System.out.println(ex.toString()); >: } >: } >: >: public void addMachine(String Address, String Port, String Systm) { >: Node RootElem = Doc.getFirstChild(); >: Element Elem = Doc.createElement("machine"); >: RootElem.appendChild(Elem); >: Element FirstElem = Doc.createElement("adresse"); >: FirstElem.appendChild(Doc.createTextNode(Address)); >: Elem.appendChild(FirstElem); >: Element SecondElem = Doc.createElement("port"); >: SecondElem.appendChild(Doc.createTextNode(Port)); >: Elem.appendChild(SecondElem); >: Element ThirdElem = Doc.createElement("systeme"); >: ThirdElem.appendChild(Doc.createTextNode(Systm)); >: Elem.appendChild(ThirdElem); >: fileModify(); >: } >: >: public void deleteMachine(int placement) { >: Element Machine = (Element) >:Doc.getElementsByTagName("machine").item(placement); >: Machine.getParentNode().removeChild(Machine); >: fileModify(); >: } >: >: public void getMachine(int placement) { >: Node Machine = Doc.getElementsByTagName("machine").item(placement); >: NodeList Nodes = Machine.getChildNodes(); >: for (int Number = 0; Number < Nodes.getLength(); Number++) { >: Node Child = Nodes.item(Number); >: if (Child.getNodeType() != Node.TEXT_NODE) { >: System.out.println("Mixed content! Skipping child element " + >:Child.getNodeName()); >: continue; >: } >: else { >: System.out.println("Hello " + Child.getNodeName()); >: } >: } >: } >: >: private void fileModify() { >: try { >: XMLSerializer XMLOut = new XMLSerializer(new >:FileWriter("connexions.xml"), >: new OutputFormat("xml", >:"UTF-8", true)); >: XMLOut.serialize(Doc); >: } catch (Exception ex) { >: System.out.println(ex.toString()); >: } >: } >:} First, a note regarding coding conventions. The preferred practice among most Java developers is that class and interface names begin with upper case letters, while all variable and method names begin with lower case letters. You'll find that many of us who offer assistance will encourage you to follow this convention in all your Java code. As to the problem you're encountering, you've got more than one issue in the above code. Your addMachine() method begins with a getFirstChild() call on the Document, but you've got other code that clearly indicates you know about the getDocumentElement() method you should be using there. In your getMachine() method, you're executing getElementsByTagName() against the document rather than its root element, which may well be the source of your first real trouble. But more to the point, you're assuming that the Machine variable does in fact contain a non-null Node. What if the document doesn't contain as many "machine" elements as your "placement" variable would imply? The result is that you're going to get a NullPointerException on the next line. So perhaps you should cover that possibility and respond with some indication that the placement value isn't valid. HTH. = Steve = -- Steve W. Jackson Montgomery, Alabama ========================================================================== TOPIC: Implicit object creation http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7ea9ee9cb601f58c ========================================================================== == 1 of 2 == Date: Tues, Nov 9 2004 11:25 am From: [EMAIL PROTECTED] (RHC) I have a question regarding garbage collection. Assume the following public class Myclass { public Myclass() {} public int getTheNumberOne() { return 1;} } Now suppose in some other class, say a servlet or something I have the following.. int first = new Myclass().getTheNumberOne(); when / how is this new Object of type Myclass garbage collected??? TIA RHC == 2 of 2 == Date: Tues, Nov 9 2004 11:32 am From: "Steve W. Jackson" <[EMAIL PROTECTED]> In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (RHC) wrote: >:I have a question regarding garbage collection. Assume the following >: >:public class Myclass >:{ >: public Myclass() >: {} >: public int getTheNumberOne() >: { return 1;} >: >:} >: >:Now suppose in some other class, say a servlet or something I have the >:following.. >: >:int first = new Myclass().getTheNumberOne(); >: >:when / how is this new Object of type Myclass garbage collected??? >: >:TIA >: >:RHC The how is the same as any other garbage collection. The when is entirely at the discretion of the JVM based on numerous factors. But it's eligible for collection immediately after the execution of that line since you're not keeping a reference to the created object. = Steve = -- Steve W. Jackson Montgomery, Alabama ========================================================================== TOPIC: braindead languages? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/c6ebaa9cc432a569 ========================================================================== == 1 of 1 == Date: Tues, Nov 9 2004 1:27 pm From: Laura <[EMAIL PROTECTED]> perldoc perltoot | grep 'braindead' -A 1 -B 1 :-) ========================================================================== TOPIC: Can't display Java gui http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/70509f2693ffc62a ========================================================================== == 1 of 2 == Date: Tues, Nov 9 2004 12:46 pm From: [EMAIL PROTECTED] (Conrad Eaglehill) Gordon Beaton <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > A workaround that's ok for testing purposes but should be avoided > otherwise, is to disable the authorization mechanism. The display > owner can type e.g. "xhost +localhost" to let others on the localhost > connect without the authorization key. I've actually tried this. "xhost + localhost" fromt he command-line prior to running the mail program has no effect. Calling it from the sendmail program itself gives "xhost: command not found." > Depending on exactly what your program needs to do, it's probably not > necessary to actually modify sendmail to start your program. Sendmail > can be configured to run external programs each time mail is > delivered, either through a .forward file in the recipient user's home > directory, or with procmail, a popular local delivery agent. This info needs to be displayed before email is delivered, though this was an interesting idea I hadn't considered. > Note that there are other issues to consider when attempting to > connect to the X server from sendmail. First, there may not always be > an X server running when sendmail is running. Good point--this project assumes an X server is running, however. > Second, the X server is > restarted each time the user logs in and will consequently be owned by > different users at different times and have different authorisation > keys. This is bad news, and may strike the project down. Why is there such a control lock on the X server? What's the big difference between an image displayed and text displayed? > At any rate, a much cleaner solution would be to divide your code into > two parts: run the GUI manually (under control of the current logged > in user), and have it connect to sendmail and wait for instructions > from there. This hurdle came very late into my work--I hadn't assumed that displaying a gui was such a big deal. I can't see why info in one format is freely allowed but info in another format is strictly prohibited. But thanks for the info, Gordon. You pointed me in avenues I hadn't considered. :-) > /gordon Conrad Eaglehill == 2 of 2 == Date: Tues, Nov 9 2004 12:50 pm From: [EMAIL PROTECTED] (Conrad Eaglehill) Rogan Dawes <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > > Another alternative might be to use socket based comms in a > client-server process. Have the GUI listen on a localhost socket for a > connection, and pop up the GUI when it receives one. your C program > passes the necessary info to the GUI, the operator makes his decision, > and returns the decision to your C program via the socket. > > Your GUI effectively operates as a daemon, however it is running with > the appropriate permissions for the desktop (if it is run as the user > who owns the desktop), so it can interact with the operator/user. > > If nothing else, this is probably more efficient than starting a new JVM > for every email that comes through. You incur the startup costs once > only, at initial startup. Depending on your mail volume, this may or may > not be important. > > It also means that you can properly queue the emails for the operator's > attention, so that multiple emails arriving simultaneously do not all > compete for attention/focus/whatever. Hmm...I've had more practice in sockets with C than in Java, but this might be the way to go. I'll give this a shot. Thanks, Rogan! I think you may have helped me out quite a bit! > Regards, > > Rogan Conrad Eaglehill ========================================================================== TOPIC: How to encode Japanese string into UTF-32 ? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/c919aa51791b9bdd ========================================================================== == 1 of 1 == Date: Tues, Nov 9 2004 12:51 pm From: [EMAIL PROTECTED] (Marat) Hello to all! I have to encode some Japanese string typed in text edit box (all characters are 3-byte characters) into UTF-32 and store in *.txt file .. The following work arrounds throws exceptions : OutputStreamWriter out = new OutputStreamWriter(new ByteArrayOutputStream(), "UTF-32"); out.write(value); out.flush(); String tmp = out.toString(); OR byte[] bytedValue = value.getBytes("UTF-32"); value = new String(bytedValue,"UTF-32"); Any ideas ? ========================================================================== TOPIC: runtime.getRuntim().exec(somecmd) problem with linux http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a3f83ceedc3184b0 ========================================================================== == 1 of 1 == Date: Tues, Nov 9 2004 12:56 pm From: "A. Bolmarcich" <[EMAIL PROTECTED]> On 2004-11-09, wex <[EMAIL PROTECTED]> wrote: > I apologize for not giving more accurate code but I thought it was > easier with the simplistic example which I did test. But anyways the > "real code". [snip] > I have bypassed all this in my testing and tried just executing the > command: > String cmd ="java -Xms64m -Xmx128m -cp /home/ryan/documents/program > files/hsqldb.jar org.hsqldb.Server -port 9001 -database > /home/ryan/documents/program files/data/med -silent false -trace > false"; > Runtime rt = Runtime.getRuntime(); > Process process = rt.exec(cmd); As Gordon Beaton and Ian A. Mason wrote in previously replies, this does not work because exec(String command) breaks the command into command line arguments at whitespace characters. > And I have of course tried every variation of quotes and backslashes > surrounding the path(notice the space between "program files"): > cmd ="java -Xms64m -Xmx128m -cp \"/home/ryan/documents/program > files/hsqldb.jar\" org.hsqldb.Server -port 9001 -database > \"/home/ryan/documents/program files/data/med\" -silent false -trace > false"; The command is broken up at whitespace characters. The quotes and backslashes do not make a difference. [snip] > I have tried encapsulating the whole command in a string array and > passing that off to rt.exec with various quotes, backslashes, etc. > String[] cmds = {cmd}; > Runtime rt = Runtime.getRuntime(); > Process process = rt.exec(cmds); This trys to run a command whose name is the value of cmd. I doubt if there is a command name starts with java -Xms64m -Xmx128m -cp /home/ryan/documents/program files/hsqldb.jar As others have pointed out, you need to use a String[] that has the command already tokenized into command line arguments. That is, you need something like String [] cmds = {"java", "-Xms64m", "-Xmx128m", "-cp", "/home/ryan/documents/program files/hsqldb.jar", "org.hsqldb.Server", "-port", "9001", "-database", "/home/ryan/documents/program files/data/med", "-silent", "false", "-trace", "false" }; Runtime rt = Runtime.getRuntime(); Process process = rt.exec(cmds); > And of course all of this works fine when there is no space. It also > works completely fine in windows by just putting quotes around the > paths. So I hope this contains some better info for you. Really > appreciate everyone trying to help. It works in Microsoft Windows because Microsoft Windows is doing an extra layer of interpretation of what is exec'ed that Linux does not do. To Linux putting quotation marks around a value means that the value contains quotation marks. You can have Linux do the extra layer of interpretation by running the command under a shell; the shell will interpret the quotation marks. However, that is a complication that you don't need. At least you don't need it yet. It would have helped if you originally gave the exact value being used as an argument to the exec method. What you originally wrote was However I have run into a problem where it will not work when the command contains a path with spaces in it on a linux platform. For instance a string that executes any random exec. Runtime rt = Runtime.getRuntime(); Process process = rt.exec("/path with space/somecmd.bat"); The solution to this problem, which was to use String[] {"/path with space/somecmd.bat"} as the argument to exec did not solve your problem because your problem was that what is being exec'ed is not just the name of a command, but the name of a command and command arguments. ========================================================================== TOPIC: How to translate Japanese String into UTF-32 encoded using Java APIs ? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5c01f1e464ef13e3 ========================================================================== == 1 of 1 == Date: Tues, Nov 9 2004 12:56 pm From: [EMAIL PROTECTED] (Marat) Hello to all! I have to encode some Japanese string typed in text edit box (all characters are 3-byte characters) into UTF-32 and store in *.txt file .. The following work arrounds throws exceptions : OutputStreamWriter out = new OutputStreamWriter(new ByteArrayOutputStream(), "UTF-32"); out.write(value); out.flush(); String tmp = out.toString(); OR byte[] bytedValue = value.getBytes("UTF-32"); value = new String(bytedValue,"UTF-32"); Any ideas ? ======================================================================= 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
