comp.lang.java.programmer http://groups-beta.google.com/group/comp.lang.java.programmer [EMAIL PROTECTED]
Today's topics: * How to know if a CD is inserted in the cdrom drive from java ? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b5d0b1b8567b852 * Contructor bad practices----WAS: Re: Can someone use invokeLater()... - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/70ac1bf0cc54a090 * Unable to establish a socket connection - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3db1070c05ec0b49 * sorting an ArrayList by int - 5 messages, 5 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/127ea15b32732f1 * Is there a unix-like select in Java - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e44542f7c53cca5c * Problems with regular expressions using JDK java.util.regex package - 2 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/85e2934c64426894 * Problem in XJC with recognizing jaxb: prefix - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/9f1c47a74f32a804 * Can these two statements be made into one statement? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b46830783d9cc8b0 * How tom create a NEW class online - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/1552191b47783f48 * HOW-TO: Create Servlets - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/91304bc9c8f8d361 * newbie question - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/abba4305d2a3593 * Java application developped under Linux running ridiculously slow under Windows - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/accd6c66f1db2bc9 * How to get server name within applet? - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6f7650fa9e13c3b9 * GridBagConstrainst fill error - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a5a41fc0e3ce41f * how my Database can send me a message? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/96ee48d269aefeb4 * Enums in inner classes - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7ecb6f0754c4b0df ========================================================================== TOPIC: How to know if a CD is inserted in the cdrom drive from java ? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b5d0b1b8567b852 ========================================================================== == 1 of 1 == Date: Tues, Oct 26 2004 12:12 pm From: [EMAIL PROTECTED] (Greg Smith) [EMAIL PROTECTED] (Toni) wrote in message news:<[EMAIL PROTECTED]>... > I would like to know if there is a way to handle the cdrom drive from > java, > like to know if a CD is inserted and maybe know some specifications > about the cd inserted like if it contains data or if it is CD-R or > CD-RW.Thank you. check out the JMF - Java Media Framework. It has stuff for animation, graphics, MP3, etc... there are native libs for windows. i dont know if it accesses cdroms directly. let us know... greg ps - JMF is available at http://java.sun.com/products/java-media/jmf/index.jsp ========================================================================== TOPIC: Contructor bad practices----WAS: Re: Can someone use invokeLater()... http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/70ac1bf0cc54a090 ========================================================================== == 1 of 1 == Date: Tues, Oct 26 2004 12:27 pm From: "xarax" <[EMAIL PROTECTED]> "Alex Hunsley" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Thomas G. Marshall wrote: > > Alex Hunsley coughed up: > > > > ...[rip]... > > > > > >>>Overly strict. I cannot /count/ the number of times I've seen > >>>horribly convoluted code set out to avoid putting nearly /anything/ > >>>into a constructor. > >> > >>"Constructors should *not* call non-final or > >>non-private methods" is not overly strict > > > > > > STOP RIGHT THERE. > > Please don't shout, it's considered rude. > > > You meant: should *not* call non-final or non-private methods of that same > > object? Sorry, I misunderstood your intent. > > well, if I didn't mean that, then I would be talking about calling > private methods of *other classes* which wouldn't make any sense. So > yes, I meant of that same object, sorry if I wasn't clear on that. > > > Then I totally agree. > > > > Here's something else I see *all the time*: (pseudo-java, ignore scoping > > rules): > > > > class A > > { > > A() { helper(); } > > > > helper() {....}; > > } > > > > class B extends A > > { > > helper() {....}; // dangerous: overridden > > } > > Yup, I see that too. I see dead people. Yes, that can be dangerous when the subclass doesn't properly handle the set-up that the original helper() is supposed to do. OTOH, I've seen things like this: public class A { private final List myList; protected abstract List init(); protected A() { myList = init(); } } public final class B extends A { protected List init() { List result; result = /* Create and initialize the List */; return result; } } The c'tor for class A is designed to call method init() that is implemented by a subclass. This is a good design, because there is no "default" version of init() to override. The subclass must fulfill its implied contract with the parent class, and it must be careful not to reference any subclass elements that have not yet been initialized (because the parent is still constructing). The init() method must be completing self-contained with no dependencies on the subclass instance. ========================================================================== TOPIC: Unable to establish a socket connection http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3db1070c05ec0b49 ========================================================================== == 1 of 2 == Date: Tues, Oct 26 2004 12:29 pm From: [EMAIL PROTECTED] (S J Rulison) Steve Horsley <[EMAIL PROTECTED]> wrote in message news:<[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 Dear Mr. Horsley: You were correct in your reply to my post when you stated that I might be catching and ignoring the exception. Upon further review of my code, I noticed that I had the e.printstackTrace(System.err) commented out. I have printed out the exceptions that were thrown below. It appears that I need to go threw the java security manager and grant permission to the applet to open a socket connection to the server application but I'm not exactly sure how that's done. Do you know of any examples I can look at to see what code needs to be added to the applet and the application? The closest I came to finding an example was a snippet of code for granting permissions: grant{java.security.AllPermissions;}. I wasn't able to figure out where this fits into the scheme of things. I would really appreciate any help you could give me on this. Thanks. EXCEPTIONS: java.security.AccessControlException: access denied (java.net.SocketPermission 10.44.250 resolve) at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkConnect(Unknown Source) at java.net.InetAddress.getAllByName0(Unknown Source) at java.net.InetAddress.getAllByName0(Unknown Source) at java.net.InetAddress.getAllByName(Unknown Source) at java.net.InetAddress.getByName(Unknown Source) at java.net.InetSocketAddress.<init>(Unknown Source) at java.net.Socket.<init>(Unknown Source) at PTABLookup.createSocket(PTABLookup.java:110) at PTABLookup.init(PTABLookup.java:87) at sun.applet.AppletPanel.run(Unknown Source) at java.lang.Thread.run(Unknown Source) == 2 of 2 == Date: Tues, Oct 26 2004 12:55 pm From: Steve Horsley <[EMAIL PROTECTED]> S J Rulison wrote: > Steve Horsley <[EMAIL PROTECTED]> wrote in message news:<[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 > > > Dear Mr. Horsley: > You were correct in your reply to my post when you stated that I might > be catching and ignoring the exception. Upon further review of my > code, I noticed that I had the e.printstackTrace(System.err) commented > out. I have printed out the exceptions that were thrown below. It > appears that I need to go threw the java security manager and grant > permission to the applet to open a socket connection to the server > application but I'm not exactly sure how that's done. Do you know of > any examples I can look at to see what code needs to be added to the > applet and the application? The closest I came to finding an example > was a snippet of code for granting permissions: > grant{java.security.AllPermissions;}. I wasn't able to figure out > where this fits into the scheme of things. > > > I would really appreciate any help you could give me on this. > > Thanks. > > > EXCEPTIONS: > java.security.AccessControlException: access denied > (java.net.SocketPermission 10.44.250 resolve) > at java.security.AccessControlContext.checkPermission(Unknown Source) > at java.security.AccessController.checkPermission(Unknown Source) > at java.lang.SecurityManager.checkPermission(Unknown Source) > at java.lang.SecurityManager.checkConnect(Unknown Source) > at java.net.InetAddress.getAllByName0(Unknown Source) > at java.net.InetAddress.getAllByName0(Unknown Source) > at java.net.InetAddress.getAllByName(Unknown Source) > at java.net.InetAddress.getByName(Unknown Source) > at java.net.InetSocketAddress.<init>(Unknown Source) > at java.net.Socket.<init>(Unknown Source) > at PTABLookup.createSocket(PTABLookup.java:110) > at PTABLookup.init(PTABLookup.java:87) > at sun.applet.AppletPanel.run(Unknown Source) > at java.lang.Thread.run(Unknown Source) Now you've caught me out. I've never messed around with security managers, so I can't help you. But now you know what the problem is, maybe someone else can chip in. Or maybe you can google for something like "applet socket securityexception". This has been discussed many times before. Steve ========================================================================== TOPIC: sorting an ArrayList by int http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/127ea15b32732f1 ========================================================================== == 1 of 5 == Date: Tues, Oct 26 2004 12:32 pm From: Steve Horsley <[EMAIL PROTECTED]> zcraven wrote: > "Bent C Dalager" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>In article <[EMAIL PROTECTED]>, >>Steve Horsley <[EMAIL PROTECTED]> wrote: >> >>>I suggest that you write an implementation of the Comparator class that >>>goes something like (off the top of my head, not reading the docs): >>> >>>public class ClubPointsComparator implements Comparator { >>> public int compare(Object o1, Object o2) { >>> Club c1 = (Club) o1; >>> Club c2 = (Club) o2; >>> return c2.points - c1.points; >> >>This has the potential of running into an underflow problem. Not >>particularly likely in this case, perhaps, but still. >> >>You could either do an if-sequence or you might write something like >>return new Integer(c1.points).compareTo(new Integer(c2.points)); >> >>Unless the code is likely to become a performance bottleneck, I prefer >>this way since it more clearly spells out exactly what you're trying >>to do and why. It's also less error prone. >> > > > Interesting, can you explain how your way is different? What is an > underflow problem? > > Zac > > > He's quite right. If c2.points is -1.5 billion and c1.points is +1.5 billion the the result should be -3 billion. But since the result is an unsigned int (range +/- 2 billion) then the returned value would be +1 billion instead, and the clubs would be sorted in the wrong order. Not likely with football club points, true, but Bent has indeed spotted a logical flaw in my code. This would not suffer the same problem: public int compare(Object o1, Object o2) { Club c1 = (Club) o1; Club c2 = (Club) o2); if (c2.points > c1.points) { return 1; } else if (c2.points == c1 points) { return(0); } else { return -1; } } This is OK for a comparator because only the SIGN of the result is used to decide the sorting order (or zero of course). And it cannot wrap and return the wrong sign result. Steve. == 2 of 5 == Date: Tues, Oct 26 2004 12:40 pm From: "xarax" <[EMAIL PROTECTED]> "zcraven" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > "Bent C Dalager" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > In article <[EMAIL PROTECTED]>, > > Steve Horsley <[EMAIL PROTECTED]> wrote: > > > > > >I suggest that you write an implementation of the Comparator class that > > >goes something like (off the top of my head, not reading the docs): > > > > > >public class ClubPointsComparator implements Comparator { > > > public int compare(Object o1, Object o2) { > > > Club c1 = (Club) o1; > > > Club c2 = (Club) o2; > > > return c2.points - c1.points; > > > > This has the potential of running into an underflow problem. Not > > particularly likely in this case, perhaps, but still. > > > > You could either do an if-sequence or you might write something like > > return new Integer(c1.points).compareTo(new Integer(c2.points)); YUCK! Hugely inefficient instantiating 2 new Integer instances, then immediately discarding them. > > Unless the code is likely to become a performance bottleneck, I prefer > > this way since it more clearly spells out exactly what you're trying > > to do and why. It's also less error prone. The Comparator approach is the best way. > > Interesting, can you explain how your way is different? What is an > underflow problem? Arithmetic with integers is subject to wrap-around without any error or exception thrown. Thus, subtracting one point from another point could yield the wrong algebraic sign. Think about what happens if the first point is Integer.MIN_VALUE and the second point is 1. Integer.MIN_VALUE-1 will wrap (underflow) around to the Integer.MAX_VALUE. The safest way is something like this: public class ClubPointsComparator implements Comparator { public int compare(final Object o1, final Object o2) { final Club c1 = (Club) o1; final Club c2 = (Club) o2; final int p1 = c1.points; final int p2 = c2.points; return ((p1 == p2) ? 0 : ((p1 < p2) ? -1 : 1)); } } Then instantiate a singleton instance of ClubPointsComparator and use that for sorting the array of Club elements. The implementation of Comparator above is far faster than instantiating 2 new Integer instances for each array element comparison. If your Club class implements Comparable, then it can only compare instances in one (natural) way. Using Comparator instances lets you compare Club instances in a variety of ways. -- ---------------------------- Jeffrey D. Smith Farsight Systems Corporation 24 BURLINGTON DRIVE LONGMONT, CO 80501-6906 http://www.farsight-systems.com z/Debug debugs your Systems/C programs running on IBM z/OS for FREE! == 3 of 5 == Date: Tues, Oct 26 2004 1:11 pm From: [EMAIL PROTECTED] (Bent C Dalager) In article <[EMAIL PROTECTED]>, xarax <[EMAIL PROTECTED]> wrote: >> "Bent C Dalager" <[EMAIL PROTECTED]> wrote in message >> news:[EMAIL PROTECTED] >> > >> > You could either do an if-sequence or you might write something like >> > return new Integer(c1.points).compareTo(new Integer(c2.points)); > >YUCK! Hugely inefficient instantiating 2 new Integer >instances, then immediately discarding them. This is not likely to be anything even resembling a problem unless it's inside of a tight loop. As it is, I am perfectly happy to take an insignificant performance hit in exchange for clearer, less error-prone, more maintainable code. I find that optimising for correctness and maintainability is more important than optimising for performance in almost all cases. Cheers Bent D -- Bent Dalager - [EMAIL PROTECTED] - http://www.pvv.org/~bcd powered by emacs == 4 of 5 == Date: Tues, Oct 26 2004 2:02 pm From: Eric Sosman <[EMAIL PROTECTED]> Bent C Dalager wrote: > In article <[EMAIL PROTECTED]>, > xarax <[EMAIL PROTECTED]> wrote: > >>>"Bent C Dalager" <[EMAIL PROTECTED]> wrote in message >>>news:[EMAIL PROTECTED] >>> >>>>You could either do an if-sequence or you might write something like >>>>return new Integer(c1.points).compareTo(new Integer(c2.points)); >> >>YUCK! Hugely inefficient instantiating 2 new Integer >>instances, then immediately discarding them. > > This is not likely to be anything even resembling a problem unless > it's inside of a tight loop. Read the Subject line again: this comparison will be used as part of a sort. Thus, it *is* in a tight loop -- or more accurately, in a loop that is executed often. Some people seem to equate "O(N log N) is efficient" with "O(N log N) is negligible." Do the math: on a 1000- element array, an N lg N sort needs about 10000 comparisons. A 10000-element array requires about 133000 comparisons, and a million comparisons aren't enough for 62747 elements. O(N log N) may be the best one can do for a comparison- based general-purpose sort, but it's still superlinear and far from cheap. It's the best of a bad lot, that's all. > As it is, I am perfectly happy to take an insignificant performance > hit in exchange for clearer, less error-prone, more maintainable code. > I find that optimising for correctness and maintainability is more > important than optimising for performance in almost all cases. Now, I'll concede that the O.P. posed his problem in connection with the scores in a sports league, and it's probably the case that there are significantly fewer than ten thousand teams in his league. If there are ten teams, say, an N lg N sort will need only about thirty-three comparisons, and questions of efficiency scarcely arise. But one of the biggest promises of the object-oriented Weltanschauung is code reuse, is it not? Whether the promise will be (or even can be) kept is a topic for another day, but it surely will *not* be kept if people are taught to write code that relies on "N is small" and can't be extended to "N is moderate," much less "large." The practice of creating and discarding two useless objects merely to avoid writing an `if' is, I think, indefensible. -- [EMAIL PROTECTED] == 5 of 5 == Date: Tues, Oct 26 2004 3:17 pm From: Michael Borgwardt <[EMAIL PROTECTED]> zcraven wrote: >> Did you implement a compareTo() method? When >>you said that your class "implements Comparable," >>you promised to provide compareTo(). > > The Club class should not abstract so it seems I cannot include the line > 'implements Comparable' No, that's not what it means. It means you must implement the method int compareTo(Object) in your class, which provides the comparison on which the sort order is going to be based. ========================================================================== TOPIC: Is there a unix-like select in Java http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e44542f7c53cca5c ========================================================================== == 1 of 1 == Date: Tues, Oct 26 2004 12:28 pm From: "Filip Larsen" <[EMAIL PROTECTED]> Amit wrote > select is a fn that is used to listen to one or more descriptors. When > there is data on any one of them, we are notified. This way, as soon > as the server closes down, the client gets to know about it. > > Is there smth of this sort in java. In Java 1.4 the new packages in java.nio and below introduced Selectors, SelectableChannel and SelectionKey that corresponds more or less to select on *nix. Don't forget to read the documentation before you use them, because there are some pitsfall: http://java.sun.com/j2se/1.4.2/docs/guide/nio/ http://java.sun.com/developer/JDCTechTips/2004/tt0914.html Regards, -- Filip Larsen ========================================================================== TOPIC: Problems with regular expressions using JDK java.util.regex package http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/85e2934c64426894 ========================================================================== == 1 of 2 == Date: Tues, Oct 26 2004 1:07 pm From: [EMAIL PROTECTED] (Tom Maki) Hi Paul, All that is missing for compilation is the the junit.jar. Do you want me to post that? Probably easier to download from sourceforge: http://prdownloads.sourceforge.net/junit/junit3.8.1.zip?download Thanks for your comments. Tom Paul Lutus <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > Tom Maki wrote: > > > Hi, > > > > I have to admit I have never been good at regular expressions and I > > have a piece of code that I want to write using the java.util.regex > > package. It is quite simple -- it is for a compression filter. Once > > thing that is a bit different is that I want to compress all web pages > > that don't have the subsequence 'admin' in them (these pages all go > > over a LAN so compression would be counterproductive. I can't just > > invert the find () boolean since the client will be changing the reg. > > exp. over time. Anyway, here is the test case I have been using. You > > notice is fails on assertFalse(pattern.matcher(adminUri).find()) > > statement: > > How would we notice that? You are not providing a complete, compilable > example. > > > > > import java.util.regex.Pattern; > > import junit.framework.TestCase; > > > > public class RegularExpressionTest extends TestCase { > > > > public void testRexEx() { > > String adminUri = "/rss/admin_product_types_start.do"; > > String reportUri = "/rss/price_change_report_start.do"; > > > > String regEx = "[^a][^d][^m][^i][^n]"; > > Pattern pattern = Pattern.compile(regEx); > > assertTrue(pattern.matcher(reportUri).find()); > > assertFalse(pattern.matcher(adminUri).find()); > > > > } > > } > > > > Any help would be greatly appreciated! > > Please post a complete, compilable example, and say exactly what you are > doing and how it fails. == 2 of 2 == Date: Tues, Oct 26 2004 1:22 pm From: [EMAIL PROTECTED] (Tom Maki) Thanks Oscar, doing a ! on pattern.matcher(adminUri).find() was my first thought. I guess I will just have to make it clear to the client that all web pages will be compressed except for those that match the regular expression given. Thanks again, Tom Oscar kind <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > Tom Maki <[EMAIL PROTECTED]> wrote: > > I have to admit I have never been good at regular expressions and I > > have a piece of code that I want to write using the java.util.regex > > package. It is quite simple -- it is for a compression filter. Once > > thing that is a bit different is that I want to compress all web pages > > that don't have the subsequence 'admin' in them (these pages all go > > over a LAN so compression would be counterproductive. I can't just > > invert the find () boolean since the client will be changing the reg. > > exp. over time. Anyway, here is the test case I have been using. You > > notice is fails on assertFalse(pattern.matcher(adminUri).find()) > > statement: > > > > import java.util.regex.Pattern; > > import junit.framework.TestCase; > > > > public class RegularExpressionTest extends TestCase { > > > > public void testRexEx() { > > String adminUri = "/rss/admin_product_types_start.do"; > > String reportUri = "/rss/price_change_report_start.do"; > > > > String regEx = "[^a][^d][^m][^i][^n]"; > > Pattern pattern = Pattern.compile(regEx); > > assertTrue(pattern.matcher(reportUri).find()); > > assertFalse(pattern.matcher(adminUri).find()); > > > > } > > } > > The assertion on the String adminUrio fails, because there is a substring > in it that doesn't start with an 'a', doesn't have 'd' as second > character, etc. The first 5 characters match. > > Why not try to match "admin" (or "[Aa][Dd][Mm][Ii][Nn]" for > case-insensitivity)? If it doesn't match, compress. You can even use the > boolean inversion operator (!) for this... > > > Sorry for the sarcasm, but the first thing I was told about regular > expressions was to make sure what to match; especially as complicated > regular expressions are often WORN (written: once, read: never). Or at > least they are as I write them... ========================================================================== TOPIC: Problem in XJC with recognizing jaxb: prefix http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/9f1c47a74f32a804 ========================================================================== == 1 of 1 == Date: Tues, Oct 26 2004 1:10 pm From: Sudsy <[EMAIL PROTECTED]> Asra wrote: <snip> > It says that wherever I use jaxb, whether in jaxb:property or > anything. > Can anybody point out what I'm missing? > Thanks, > Asra Baig Missing namespace declaration. There should be something like this: xmlns:jaxb="URI" Just look for the other namespace definitions (i.e. xmlns:xs) and add the above attribute to the end. -- Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development. ========================================================================== TOPIC: Can these two statements be made into one statement? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b46830783d9cc8b0 ========================================================================== == 1 of 1 == Date: Tues, Oct 26 2004 1:53 pm From: Joona I Palaste <[EMAIL PROTECTED]> Oxnard <[EMAIL PROTECTED]> scribbled the following: > I'm still trying to beome a bit more comfortable with abstract classes. Here > are the statements: > FontMetrics fm = c.getFontMetrics(c.getFont()); > int i = 2 * (fm.getMaxAscent() + fm.getMaxDescent()); This is really as close as you're going to get. If you can guarantee c.getFontMetrics(c.getFount()) will always return the same instance of FontMetrics for the same c.getFount() you can try: int i = 2 * (c.getFontMetrics(c.getFont()).getMaxAcent() + c.getFontMetrics(c.getFont()).getMaxDescent()))); But I have to agree with the other replies, your code is fine as it is. Brevity is not an end-in-itself, only combined with clarity. Note that this has nothing to do with abstract classes. Your question, and its answers, would remain the same even with concrete classes. I've myself often wished for temporary variables in Java, though... so I could do something like this: int i = 2 * (FontMetrics fm = c.getFontMetrics(c.getFont()).getMaxAscent() + fm.getMaxDescent()); However, I don't think that's going to be pretty easy to implement in the compiler. I know a little about compiler theory so I know something about what compilers can easily do and what they can't. -- /-- Joona Palaste ([EMAIL PROTECTED]) ------------- Finland --------\ \-------------------------------------------------------- rules! --------/ "You can pick your friends, you can pick your nose, but you can't pick your relatives." - MAD Magazine ========================================================================== TOPIC: How tom create a NEW class online http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/1552191b47783f48 ========================================================================== == 1 of 1 == Date: Tues, Oct 26 2004 2:10 pm From: [EMAIL PROTECTED] (Alexander) I think this is the one , thank you very much! If someone knows something else , please inform me! Thomas Weidenfeller <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > Tor Iver Wilhelmsen wrote: > > Reflection is for analysing and using existing classes. You want to > > synthesize a class, there are tools/APIs for that, though I cannot > > remember any at the moment. > > http://jakarta.apache.org/bcel/ > > /Thomas ========================================================================== TOPIC: HOW-TO: Create Servlets http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/91304bc9c8f8d361 ========================================================================== == 1 of 1 == Date: Tues, Oct 26 2004 2:11 pm From: [EMAIL PROTECTED] (Justin L. Davidson) HOW-TO: Create Servlets Step 1: (add servlet mapping in web.xml to class) --- /usr/local/jakarta-tomcat-4.0.4/webapps/ROOT/WEB-INF/web.xml -- <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <servlet> <servlet-name>HelloWorld</servlet-name> <servlet-class>hall.HelloWorld</servlet-class> </servlet> </web-app> Step 2: (create and compile java class) -- /usr/local/jakarta-tomcat-4.0.4/webapps/ROOT/WEB-INF/classes/HelloWorld.class -- import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("Hello World"); } } Step 3: (restart servlet container) /usr/local/jakarta-tomcat-4.0.4/bin/shutdown.sh /usr/local/jakarta-tomcat-4.0.4/bin/startup.sh Step 4: (test application in browser) http://justin.ctcnet.com:8080/servlet/HelloWorld Good Luck! [EMAIL PROTECTED] ========================================================================== TOPIC: newbie question http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/abba4305d2a3593 ========================================================================== == 1 of 2 == Date: Tues, Oct 26 2004 2:26 pm From: "<$bracket$>" <[EMAIL PROTECTED]> hi there! i've just started my adventure with JAVA. Can anyone tell me when can I find descrption of JAVA libraries?? == 2 of 2 == Date: Tues, Oct 26 2004 4:24 pm From: Dustin Aleksiuk <[EMAIL PROTECTED]> <$bracket$> wrote: > hi there! > i've just started my adventure with JAVA. Can anyone tell me when can I > find descrption of JAVA libraries?? These area all the standard libraries for 1.5, the newest release. Should provide plenty of reading: http://java.sun.com/j2se/1.5.0/docs/api/index.html Good luck. It's hard being new. Spend some time at java.sun.com. There are plenty of tutorials and forums. Regards, Dustin Aleksiuk ========================================================================== TOPIC: Java application developped under Linux running ridiculously slow under Windows http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/accd6c66f1db2bc9 ========================================================================== == 1 of 1 == Date: Tues, Oct 26 2004 2:32 pm From: [EMAIL PROTECTED] (Tim Jowers) [EMAIL PROTECTED] (Matthias Ernst) wrote in message news:<[EMAIL PROTECTED]>... > "hshdude" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > > "Michael Borgwardt" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > > > > There are programs called profilers that tell you exactly where an > application > > > spends its time. Get one of these and use it. > > > > Thanks, I'll look into that! > > While in the end the output may be very nice, I always find profilers > a little difficult to set up. I mostly use poor man's sampling: hit > CTRL-break (Windows) / CTRL-Backslash (UNIX) repeatedly to get some > thread dumps (with many threads, these will be long). Often it's easy > to tell where the bottleneck is. If you still have no idea after a > minute, then go get a profiler ... > > Matthias bongo, please let us know what you find out. The Java app I use at work on Windows runs unacceptably slow. Pretty sure it is Windows as the CPU sits pegged (dual 2.8GHz Dell). Windows seems to have become slower and slower over the last several years. ========================================================================== TOPIC: How to get server name within applet? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6f7650fa9e13c3b9 ========================================================================== == 1 of 2 == Date: Tues, Oct 26 2004 2:35 pm From: [EMAIL PROTECTED] (Manoj Nair) I want the server name ( from where the applet was downloaded) within the applet. How do i get it? == 2 of 2 == Date: Tues, Oct 26 2004 2:40 pm From: "Matt Humphrey" <[EMAIL PROTECTED]> "Manoj Nair" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I want the server name ( from where the applet was downloaded) within > the applet. How do i get it? Check out getCodeBase (). Now's a good time to learn to read the API. Cheers, Matt Humphrey [EMAIL PROTECTED] http://www.iviz.com/ ========================================================================== TOPIC: GridBagConstrainst fill error http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a5a41fc0e3ce41f ========================================================================== == 1 of 1 == Date: Tues, Oct 26 2004 2:44 pm From: [EMAIL PROTECTED] (Asra) Hello, I'm using a JPanel and putting a component in it with GridBagConstraints' fill value set to BOTH. However, the component doesn't fill the entire Panel and remains in the center. Where should I check for errors? -Asra ========================================================================== TOPIC: how my Database can send me a message? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/96ee48d269aefeb4 ========================================================================== == 1 of 1 == Date: Tues, Oct 26 2004 2:54 pm From: [EMAIL PROTECTED] (Shrish) Hi Everybody, I have a Database and two hosts- host1 and host2. When host1 makes a change in Database, I want Database to send a message to host2. I am wondering how can I make it possible. One way is to have an application runing in Database and host2 whicuh talk through sockets, and I assume there would be a way for database to launch that application. Is there some other way too? I am using Java, and JDBC for database connectivity. I am using PostGRESQL database. Thanks, Shrish ========================================================================== TOPIC: Enums in inner classes http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7ecb6f0754c4b0df ========================================================================== == 1 of 1 == Date: Tues, Oct 26 2004 3:23 pm From: G Winstanley <[EMAIL PROTECTED]> On Tue, 26 Oct 2004 16:07:13 GMT, the cup of "xarax" <[EMAIL PROTECTED]> overfloweth with the following: > "G Winstanley" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > Jus a quick one...now I've finally got hold of v1.5 I'm trying to use an > > enum in a private final inner class, but I get the following message from > > the compiler in NetBeans 4.0b2: > > > > init: > > deps-jar: > > Compiling 1 source file to P:\NetBeans Projects\ProjectX\build\classes > > P:\NetBeans Projects\ProjectX\src\Foo.java:7: modifier not allowed here > > private enum Status{ONE, TWO, THREE, FOUR} > > 1 error > > BUILD FAILED (total time: 0 seconds) > > > > > > The class is defined as: > > > > public class Foo > > { > > private final class Bar > > { > > private enum Status {ONE, TWO, THREE, FOUR} > > // ...etc... > > } > > } > > > > > > Any ideas which modifier it's got a problem with? I've tried removing the > > private modifier and that has no effect. It seems that it's just not happy > > having an enum within an inner class, but I can't find reference to this in > > the enum documentation that comes with JDK1.5. > > Did you specify the -source 1.5 on the compiler command line? > How about specify "static" on the "private enum" declaration > (I don't know whether an enum can be an inner class; likely > not.) > Yes, it's all setup for 1.5 compilation, but still does this! Stan ======================================================================= 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
