|
I'd like to post that everyone who uses Java to make money should know how both .equals() and .hashCode() work. You can find numerous guides online, plus Joshua Bloch's Effective Java goes into great detail about these methods. I won't get into it here to avoid a huge poo poo post, but here are some links: http://www.geocities.com/technofundo/tech/java/equalhash.html http://www.ibm.com/developerworks/java/library/j-jtp05273.html a good reason why you should know your poo poo: http://www.hibernate.org/109.html Also, understand the ramifications of having immutable Strings. A lot of people I've worked with don't understand the concept of immutable Strings and don't know a reason for using StringBuilder other than "you just do." What the gently caress. Also available in numerous online resources or by reading Effective Java. IntelliJ is really nice. Eclipse is ok if you are willing to put up with its poo poo. Someone likened it to Mac vs PC. If you want something that just works, use IntelliJ, if you like to tinker, go with Eclipse. I haven't used NetBeans enough to say if it's good or bad, all I'm sure of is that Sun is really pushing JRuby so their ruby support is very good.
|
# ¿ Feb 24, 2008 00:12 |
|
|
# ¿ Apr 26, 2024 11:32 |
|
csammis posted:Can one use IntelliJ or Netbeans if they're developing Java RCP applications that target the Eclipse framework itself, or does that lock one into having to use Eclipse? I'm doing this at work, but I can't friggin' stand Eclipse. It's slower than an rear end in a hat. I don't know how well it'll work, though. It'd be wise to not wipe Eclipse before you try it out for a week or so, despite how tempting it is.
|
# ¿ Feb 25, 2008 04:14 |
|
Fly posted:Most people must readjust their expectations when using fixed precision floating point numbers, such as the IEEE 754 implementation Java has. There are rounding issues because it is impossible to represent some decimal values exactly in such floating point representations. You can also try BigDecimal if you don't need balls to the wall arithmetic performance.
|
# ¿ Feb 26, 2008 21:54 |
|
compare should return an int, not a String. Try: code:
|
# ¿ Mar 5, 2008 04:52 |
|
rotor posted:If I understand you correctly (never a safe bet) it seems that html has nothing do do with this. You have some string data you want formatted nicely on fixed-width font printers, and you're trying to abuse an html layout engine to do this. There is a mature Java curses lib, and it's pretty awesome. A guy at work popped out a tabular pgsql database stats browser with it in a day. I'm curious why roadheads' implementation has to be in java and not something like LaTeX or PS. Those languages are made for type-setting.
|
# ¿ Mar 9, 2008 05:10 |
|
BELL END posted:I've never understood the big hullabaloo about this. Depending on the size of the method, having just one exit point can definitely be helpful. That said, you shouldn't have monolithic methods that can't fit on a screen if you can help it.
|
# ¿ Mar 18, 2008 23:50 |
|
zootm posted:Maven's always a point of contention; a lot of people don't like it. I'm not personally a fan myself, I find its behaviour a little too opaque and wide-ranging. It's respected by a lot of other people too, though, it's just a bit of a "love it or hate it" thing. I'm in the Ant + Ivy camp myself. Maven is really a bitch to get going.
|
# ¿ Mar 21, 2008 20:17 |
|
1337JiveTurkey posted:In 2002, it'd be talking about Java 1.3 or 1.4 (both are pretty drat old). I wouldn't look at anything which talks about Java before 1.5 except for purposes of maintaining legacy code. Even with legacy code 1.4.2 is as old as I'd venture and I'm hoping to avoid having much to do with my company's clients still stuck on 1.3.1. It's still important to know when certain things came into being or became usable (Ask me about JAXB 1.0), but new code should be predominantly written with the newer versions of the language. I'm curious what that client's excuse for sticking with Java 1.3 is. Did they use some Sun internal API that got removed?
|
# ¿ Mar 22, 2008 13:57 |
|
epswing posted:Sounds like this will create a new StringBuilder instance per iteration, in which case the extra append calls would be better.
|
# ¿ Apr 8, 2008 16:22 |
|
epswing posted:I don't know anything about the java compiler. From my lofty perch, far from such low-level details, it sounds like I just decompiled this code (All code generated using JDK6_u3, should probably upgrade): code:
code:
|
# ¿ Apr 8, 2008 17:31 |
|
epswing posted:That's exactly what I was concerned with: does the following mean 5 instances of StringBuilder?
|
# ¿ Apr 8, 2008 17:55 |
|
epswing posted:Ok, which brings me back to http://forums.somethingawful.com/showthread.php?threadid=2780384&pagenumber=5#post342041228 Yeah, I misread your post. I actually copied that code straight now and disassembled it and it's definitely creating 2 new StringBuilder instances for every loop. I wonder if HotSpot would be able to optimize this further and move the allocation if it unrolled the loop. This bugged the poo poo out of me so I benchmarked it. You're right, the overhead of allocating those StringBuilders is significant for even modest numbers of iterations. I'll post the code if anyone wants, but for 1000 keys of random size, it took anywhere from 875-1000ms to run the naive method, and from 0-3ms for the explicit append() method. I run under linux so the JVM uses the server VM by default. I tried this under -client and got FAR worse performance for the naive method, even after HotSpot dealt with it.
|
# ¿ Apr 8, 2008 21:11 |
|
epswing posted:I'd love to see it firsthand. code:
|
# ¿ Apr 8, 2008 21:59 |
|
Brain Candy posted:Inheritance and/or enums. Its hard to say exactly without any idea of why you want to use bit flags. Yeah, please let us know a bit more about your problem. There is almost always a more elegant way of handling that sort of multiplexing.
|
# ¿ Apr 9, 2008 02:13 |
|
^^ You need to look up the javax.script.Bindings class. That is how you pass variables back and forth between a script and the host java program.
|
# ¿ Apr 15, 2008 04:57 |
|
adante posted:sorry, but can you give me a concrete example of what you mean? As far as I can tell getting the Bindings will allow me to get a java reference to the javascript object - but I already do this using the jsEngine.get("foo"). What I want to know is how do I manipulate it? For instance, how would I get a value given a key, or list the keys? Bindings implements Map, so you'll be able to iterate over the entries just like Map: code:
|
# ¿ Apr 17, 2008 21:42 |
|
Leehro posted:Coming from a C/C++ background on pointers and references, that was a very helpful discussion. I was always suspicious of java's magic when it comes to passing around objects. The VM will mark it collectible after its containing block's scope ends unless it's referenced somewhere else currently in scope or static, like a Map or a List of some kind. Note that it's just marked for collection, the actual collection happens at some other point. Like you said, you can set it to null manually and call System.gc(); but absolutely no guarantees are made about when the memory consumed by that class will be reclaimed, if ever.
|
# ¿ Apr 19, 2008 20:21 |
|
hey wiz posted:Let me see if I'm on the same page with you I think I get his point now. There's no good way to get the entries from the internal JS map in the Java host. I hosed with this in Groovy because it allows for much easier class introspection, and you can basically call .get() thusly: code:
The problem comes when you try to do this poo poo in Java, because you can't even import sun.org.mozilla.javascript.internal.ScriptableObject, at least not with my JDK. You could probably get rhino and cast to whatever ScriptableObject Rhino provides and get() from there. It's a mess and you might want to write a wrapper class for it that implements Map, because honestly this is pretty worthless as it is.
|
# ¿ Apr 19, 2008 22:35 |
|
triplekungfu posted: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. setTimeout()/setInterval() can take a closure as well as a string: code:
|
# ¿ Apr 23, 2008 02:14 |
|
^ goddamn youclayburn posted:It looks like I have another problem with my HashMap involving collisions. Looking at my data set, I know for a fact that collisions are happening, and this is causing problems for me. Every time that I search for a value at a specific key, I only get one of the values, where sometimes I may want the other value. For example, if "foo" and "bar" are stored at the same key, I will only ever get "foo" even though sometimes I may want to find any string that is not "foo." Is there any way to go about this? I have read the API entry for HashMaps over and over and cannot seem to find a solution to this. So wait, are you trying to store multiple objects under the same key?
|
# ¿ Apr 23, 2008 17:07 |
|
clayburn posted:Yes, and I'm starting to get the impression that it was a really bad idea. I thought that it would simply handle that as a collision and store the object somewhere else that would still be accessible. If you want to store multiple items under a unique hash, you should make the value a Collection: code:
|
# ¿ Apr 23, 2008 17:21 |
|
zootm posted:The Commons Collections (I link to collections15 since it's the "generic" version) contains a MultiMap collection type for these sorts of semantics. Well I'll be goddamned. It must be a side effect of working in an environment devoid of intellectual curiosity but I never even bothered to check Commons for something like this. Thanks.
|
# ¿ Apr 23, 2008 18:09 |
|
FYI, the JVM has no such restriction on overloaded return types. Only the JLS does. You can do this in Jaskell and possilby Scala, IIRC.
|
# ¿ Apr 30, 2008 15:28 |
|
zootm posted:I'm fairly sure you cannot do this in Scala, for what it's worth. I'll have a look tonight if I remember though. I understand what you mean, but the JVM docs specifically state that it does not restrict overloaded method returns.
|
# ¿ Apr 30, 2008 18:46 |
|
zootm posted:Cool, just checking. Is that how Jaskell works? It seems strange to have a JVM language that Java can't call. I actually do not know how Jaskell is implemented. I kinda wrote that post quickly and should have put the word "also" in there somewhere. :p
|
# ¿ Apr 30, 2008 20:36 |
|
zootm posted:Sorry I don't want to seem like I'm digging in at you, I'm just interested! Heh, it's cool. Jaskell is open source, you can always take a look I've honsetly spent most of my "programmer education time" following Groovy, since it interfaces so well with Java. And learning Haskell as well as I can, but that's a bit off-topic.
|
# ¿ Apr 30, 2008 21:27 |
|
Alan Greenspan posted:Is there an easy way to put breakpoints on Java library functions? Let's say I want to put a breakpoint on one of the constructors of java.io.File. Yeah, in Eclipse your java source should already be linked to the rt.jar file. Just ctrl+click on a new File() statement and it'll take you right to the constructor. If that doesn't work, you probably have to link the source. I can tell you how to do that if you need.
|
# ¿ May 8, 2008 20:44 |
|
Alan Greenspan posted:Thanks for the reply but apparently this is tricky because when I set a breakpoint into the rt.jar source ... What versions of Eclipse and Java are you running?
|
# ¿ May 8, 2008 20:58 |
|
ColdPie posted:This should be super easy, but I'm just having a dog of a time figuring this out. You want to do bitwise and'ing on it and store it in a type that is larger than necesary. In your example, you want to put those bytes in an int after you & 0xFF them to yank the sign extension.
|
# ¿ Jul 7, 2008 03:51 |
|
IntelliJ has the most mature Groovy and Grails plugins available, from what I've been able to tell. I write most of my Groovy in vim so I'm pretty much ignorant beyond what I can read online.
|
# ¿ Sep 2, 2008 17:38 |
|
Flamadiddle posted:Yeah, I figured as much. I'm new to Java anyway, and so far have had to learn HTTP pushes and JDBC connections. I guess I'll need to learn about opening socket connections and such? This is pretty much exactly what web services are meant to do. Secure, abstracted, simple (for various values of simple).
|
# ¿ Sep 17, 2008 17:02 |
|
1337JiveTurkey posted:If it's some practice toy app for fun running on a local network, there's nothing wrong with just opening a socket to the server and passing serialized objects for messages. I agree. Maybe I misunderstood but he used the word "staff" so I figured this would be production.
|
# ¿ Sep 17, 2008 18:57 |
|
Do you need the radix? I wrote this in like 10s and it works well:code:
|
# ¿ Sep 23, 2008 20:07 |
|
Boz0r posted:I don't really know, actually. I guess it doesn't really matter, but my problem right now is, if I use the method TRex EaterofCars wrote before with {00, 60, ff, ff} and {0, 96, -1, -1} I get two different results, with the {0, 96, -1, -1} result being wrong. Yes because -1 is represented as 0xffffffff, bit shifting with that number will obviously produce wrong results. Try this instead: code:
|
# ¿ Sep 23, 2008 20:58 |
|
rjmccall posted:Copy and paste, do some ridiculously inefficient things with reflection, or switch programming languages. Sorry. If you can use the Apache Commons Collection library, they have a method in CollectionUtils called reverseArray. http://commons.apache.org/collections/index.html
|
# ¿ Sep 24, 2008 16:35 |
|
pogothemonkey0 posted:This is difficult to explain, so bear with me. I'd personally just use a HashMap and depending on the amount of comparisons, I'd maybe make a Map<String, Map <String, Integer>> so a map that holds a map of strings to comparisons. That said, bookkeeping would be a pain in the rear end unless you know the order of string comparisons would remain the same.
|
# ¿ Sep 27, 2008 22:33 |
|
LakeMalcom posted:just use a hashmap with the strings concatenated as your key? if order matters, then roll your own little map to put and get the reverse order string. Concatenation is dangerous because you can end up with collisions. What I was suggesting is a map system like this (in Groovy syntax cause I'm lazy): code:
|
# ¿ Sep 28, 2008 02:22 |
|
pearofducks posted:Quick concurrency question (I'm new to threads). I've got a homemade generic linked list, most of the operations on it take place inside a loop, and only one operation actually uses the list. So I'm wondering if its possible to have the linked list operation run in its own thread, and the loop to keep going. I've read up on it some and it seems like it just provides the ability to override the run method, but I'd like to have any of the linked list actions be in their own thread. Is this possible? If so can someone just give me a brief idea of what to do? Why'd you roll your own linked list when the JDK provides you with one (java.util.LinkedList) that has built-in concurrency support (using the Collections class) already? That said, you probably could do what you want to do but you're being pretty vague about what "operations" and "actions" you need to perform. Can you be a little more precise?
|
# ¿ Sep 28, 2008 20:56 |
|
Without putting to fine a point on it, you will have tremendous problems if you think that you'll have "enough time" to modify a list before some other thread can access it. To answer your question, check out the synchronized keyword and the Collections.synchronizedList() method, if you implement List then that will basically solve it for you. Also, there are a few books on Java concurrency that are pretty good: specifically Java Concurrency in Practice and Concurrent Programming in Java: Design Principles and Patterns if you are interested. Concurrency is frighteningly difficult to do correctly, especially with some of Java's more quirky semantics and rules involving synchronization.
|
# ¿ Sep 28, 2008 22:01 |
|
|
# ¿ Apr 26, 2024 11:32 |
|
triplekungfu posted: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. I had a drat S/390 Assembler professor knock of 67% of an assignment because of lack of comments. That might sound acceptable until I mention that the uncommented lines were printlines. Goddamn that guy.
|
# ¿ Sep 30, 2008 00:42 |