|
fletcher posted:Ok cool, that led me to this What type is name in the Product class? If it's a String already, you don't need those casts to String. It's only a minor issue, but every time I see stuff like that at work I die a little. Along these lines, is all programming in a corporate environment completely soul crushing, or is there hope?
|
# ¿ Mar 5, 2008 11:43 |
|
|
# ¿ Apr 27, 2024 13:31 |
|
FearIt posted:Is it more complicated if my class serves as a ArrayList container for sub classes? Probably; as you'll need to manually copy any data you require in the copy-contructor. If you're not concerned with performance you could use the apache commons SerializationUtils; as mentioned in the javadoc, all objects you want cloned must implement Serializable (which ArrayList implements already). vvv I agree 100%, I was considering adding a disclaimer to that effect. vvv the onion wizard fucked around with this message at 22:51 on Mar 25, 2008 |
# ¿ Mar 25, 2008 10:28 |
|
Anphear posted:The problem that I'm currently having is the scanner class isn't 'working right' and that my array remains empty. With the toString method simply printing [] and if I remove the isEmpty() method I get a NaN return. First, you're only ever reading in one number. To read in more than one number you'll need to loop on the input. Something like this: code:
Anphear posted:
Edit: I'm going to bed, but I wrote this while looking at Scanner; it might help, or it may just confuse matters further. the onion wizard fucked around with this message at 14:44 on Mar 27, 2008 |
# ¿ Mar 27, 2008 14:26 |
|
fletcher posted:Is there a way to do this without int count? How's that? epswing & Brain Candy: I was under the impression that the compiler will take care of substituting StringBuilder during string concatenation? http://java.sun.com/developer/technicalArticles/Interviews/community/kabutz_qa.html posted:When Strings are added using the + operator, the compiler in J2SE 5.0 and Java SE 6 will automatically use StringBuilder
|
# ¿ Apr 8, 2008 14:07 |
|
Whilst farting I posted:I'm writing an applet which plays a card game... [list=1] [*]Display 2 cards [*]Accept user's bet [*]Final card and winnings calculation [/list] Now, #1 is triggered by "startround", #2 by "bet", and #3 by #2?
|
# ¿ Apr 9, 2008 13:29 |
|
Whilst farting I posted:Out of curiousity for the future, though, does anyone know a better way for making a program wait on a non-input dialog basis besides the sleep method BELL END mentioned? The technique BELL END mentioned is called polling, and is usually a bad idea. If you've got an event driven UI (which is the case here), then you don't need to poll; actions are triggered by events. An alternative to this is to use queues, and when attempting to read from a queue the consumer will be blocked until something is available (same goes for the producer putting stuff into the queue if the queue is full). Once a message becomes available in the queue, the consumer will be awoken and handed the message. I used the above a couple of times in Uni assignments, rolling my own queue in Java 4. Java 5 includes BlockingQueue, which probably would have saved me a bit of time. Also, TRex EaterofCars and epswing thanks for the clarification on StringBuilder.
|
# ¿ Apr 9, 2008 23:53 |
|
setTimeout is a bit weird, I believe it always executes in global scope or something to that effect. Someone else can probably give you a proper explanation.
|
# ¿ Apr 23, 2008 00:36 |
|
CrusaderSean posted:The temperature model does not call hasChanged() at all and it works just fine. No, but is does call setChanged(), which means that any subsequent calls to hasChanged() will return true until clearChanged() is called. Observable API posted:public void notifyObservers(Object arg) Edit: To clarify, for now, you probably want to call setChanged before every call to notifyObservers. the onion wizard fucked around with this message at 10:09 on Apr 29, 2008 |
# ¿ Apr 29, 2008 10:02 |
|
I'm not entirely clear on what you're trying to do, is that part of a JSP? You should probably throw some apostrophes or quotes around your attributes, and the parameters for your form don't look right at all ('ACTION= METHOD=GET'). Edit: and your semicolon's inside the bracket in the onclick.
|
# ¿ May 21, 2008 09:46 |
|
drunkill posted:I'm stupid aren't I? Don't worry, it'll all come together and start making sense pretty quickly. drunkill posted:edit: I'm also JCreator to compile the code, but since I installed it at home today, when I run the program or file, I don't get the black box which I got at uni wehn using it. I get the build output so I can view any errors, but when at Uni the black box would pop-up and display the errors as well, if the program worked it'd be where you input stuff to make the program run etc. But for some reason it's not working at home. I'm not familiar with JCreator, but are you able to compile and run your code from the command line? eg: javac Exercise1.java java Exercise1
|
# ¿ Aug 6, 2008 11:00 |
|
adante, I'm fairly sure you'll need to create M readers, however you can service them with less than M threads. I whipped this up for my own understanding, it might help point you in the right direction.
|
# ¿ Aug 25, 2008 12:40 |
|
adante posted:if you mean I'll need to create M reader threads, then yes I agree. Otherwise.. well I still agree but you are reiterating the problem spec No, that's not what I meant, in the example I gave earlier I had three threads servicing 15 objects. I got bored and whipped this up. There's 5 threads servicing brs.length BufferedReaders.
|
# ¿ Aug 26, 2008 12:27 |
|
adante posted:looks like 5 threads performing a SINGLE service of 15 BufferedReaders, once each. It also looks like if the first 5 BufferedReaders are not written to, but the remainder are, nothing will ever happen. I just took your original example and the code from the ExecutorService api and mashed them together. I didn't realise each reader needed to call service() more than once If it's possible/likely for the readers to block forever, I agree that this solution isn't going to work. But, to be fair, your original solution with N threads will never terminate either. Edit: I was pondering this further today, and I'm positive a thread pool won't work if the threads never terminate. the onion wizard fucked around with this message at 12:39 on Aug 27, 2008 |
# ¿ Aug 27, 2008 00:08 |
|
The Coordinate class should probably implement Comparable<Coordinate>, or throw a ClassCastException if the supplied object isn't a Coordinate. However, I don't think compareTo is the cause of your issue, as the worst that would do is overwrite existing keys when it's not supposed to (or vice versa). You must be calling put with a null value at some point; I can't see any other way that there would be a null value for a key present in the map.
|
# ¿ Aug 30, 2008 07:42 |
|
Boz0r posted:Ok, but when I've used wrap and gotten a ByteBuffer with the bytes in it, how do I get it out in the different types, as I still can't use the getLong(), getShort()... methods? wrap and allocate appear to actually return an instance of HeapByteBuffer, which presumably implements those abstract methods.
|
# ¿ Sep 21, 2008 15:30 |
|
Sarah Sherman posted:Also, did you guys ever have a teacher who forced you to code in a certain style? My Java teacher is forcing us to use Allman indenting (which I use anyway so it doesn't really matter), and having us put those large comments before each method or class. I was surprised that he is making us do this; I thought that an important aspect of programming was being able to code in your own style. Yep, in one of my earlier classes we could lose up to 20% per assignment for incorrect formatting, and every class except the earliest couple would dock marks for missing or poor javadoc.
|
# ¿ Sep 30, 2008 00:16 |
|
MEAT TREAT posted:My only counter argument to this, how often do you go back and look at your own code from semesters past? These things don't really pay off while you're still at uni. But they're very important skills once in the workforce.
|
# ¿ Sep 30, 2008 15:42 |
|
sonic bed head posted:I know that I can send a parameter using the include, but I don't know how best to use that parameter to control "text-decoration:underline." Thanks. Your best bet would probably be to add a css class of some sort.
|
# ¿ Oct 16, 2008 23:37 |
|
I'm assuming printPoly() prints all of the Polynomial's nodes each time it is called? How many times is printPoly() being called in your example?
|
# ¿ Oct 31, 2008 10:26 |
|
Sarah Sherman posted:however, for some reason it doesn't delete the node. This is how my teacher told the class to delete a node, but I guess it's not working. Any help? MEAT TREAT posted:You shouldn't compare objects with ==. Trying using the .equals method of the string.
|
# ¿ Nov 2, 2008 02:21 |
|
Clanpot Shake posted:Is there a way to force the queue to reorder itself, or is it decided what item to pop off when poll() is called? Clanpot Shake posted:Is it okay to dynamically add and remove items from a PQ and have it maintain order? It might be time to post more code...
|
# ¿ Dec 2, 2008 09:47 |
|
karuna posted:The output of the whole thread is 2 but it is only meant to apply to the first 50 elements? code:
|
# ¿ Oct 16, 2009 11:21 |
|
osama bin diesel posted:why? that is fine, it is printing out the same number 50 times because he is passing an int as x and only gets set once per thread He's gotten his loops confused. He probably wants either: code:
code:
the onion wizard fucked around with this message at 11:30 on Oct 17, 2009 |
# ¿ Oct 17, 2009 05:20 |
|
|
# ¿ Apr 27, 2024 13:31 |
|
SortedMap perhaps? edit: oh, sorting on value, nevermind.
|
# ¿ Dec 12, 2010 14:27 |