|
Internet Janitor posted:Aafter: Could you explain why you want to do that? If you want a nestable container for other components you probably want to put a series of JPanels in your JFrame. I just figured it would be simpler. I initialize the first JFrame in main, the second in my JPanel on button press.
|
# ? Jun 5, 2011 01:27 |
|
|
# ? Jun 11, 2024 21:10 |
|
So I have a library question for anyone up to the challenge. I'm looking to deserialize a stream of JSON objects coming in over a network connection. I'd like to find a JSON library capable of deserializing these objects, but in a non-blocking fashion: i.e. I feed the library bits of data, and it gives me back complete objects when they're done. The API I kinda imagine would be similar to this: code:
At this point I'm pretty much resigned to just making something myself, but if there is something that can do this that'd be awesome.
|
# ? Jun 8, 2011 04:53 |
|
Is there a reason you need to do this drip-feeding instead of, say,code:
|
# ? Jun 8, 2011 06:24 |
|
Jabor posted:Is there a reason you need to do this drip-feeding instead of, say, My end goal is to have a single server, many client setup, where creating a thread on the server for each client just wouldn't scale. I'm basically building baby's first networked game, figured I'd use JSON as a transport mechanism because it's fairly easy to understand and I don't care much about the overhead (not much being transmitted anyway).
|
# ? Jun 8, 2011 06:40 |
|
Cubiks posted:My end goal is to have a single server, many client setup, where creating a thread on the server for each client just wouldn't scale. This is a solved problem. Deal in work items, not threads, and use callbacks instead of synchronous IO.
|
# ? Jun 8, 2011 09:02 |
|
Jabor posted:This is a solved problem. Deal in work items, not threads, and use callbacks instead of synchronous IO. Where are these callback mechanisms for non blocking i/o. Specifically, is there a way I could use them with stuff from concurrent and maybe show an example / tutorial? All the tutorials I looked at seemed rather basic. So I ended up doing what I always do in low level languages, and implemented the items to do them myself. Which is painful of course.
|
# ? Jun 8, 2011 15:27 |
|
HFX posted:Where are these callback mechanisms for non blocking i/o. Specifically, is there a way I could use them with stuff from concurrent and maybe show an example / tutorial? Look at http://java.sun.com/developer/technicalArticles/releases/nio/, use the links at the bottom if you need more.
|
# ? Jun 11, 2011 00:11 |
|
Since NIO was just brought up and I'm an idiot, is there anything wrong with this code? It reads a file into memory.code:
|
# ? Jun 11, 2011 11:19 |
|
Aleksei Vasiliev posted:Since NIO was just brought up and I'm an idiot, is there anything wrong with this code? It reads a file into memory. It should work fine. Though honestly if you're just looking to slurp the whole file into memory there are easier ways: code:
|
# ? Jun 11, 2011 11:58 |
|
Brain Candy posted:Look at http://java.sun.com/developer/technicalArticles/releases/nio/, use the links at the bottom if you need more. Those parts I know and can do well. It appears the features I want are being added in Java 7. That will save me time in the future from having to write callback mechanisms for nio.
|
# ? Jun 13, 2011 12:44 |
|
Aleksei Vasiliev posted:Since NIO was just brought up and I'm an idiot, is there anything wrong with this code? It reads a file into memory. You want to close your resources in a finally block in case read throws an exception. code:
|
# ? Jun 13, 2011 17:42 |
|
crazyfish posted:Of course you'll probably have to handle the case where fc.close() throws an exception too but I don't feel like writing that out. I usually write some sort of static 'silent close' method like... code:
code:
|
# ? Jun 13, 2011 17:52 |
|
I have a similar method for closing SQL connections, statements and result sets.
|
# ? Jun 13, 2011 18:13 |
|
epswing posted:I usually write some sort of static 'silent close' method like... crazyfish posted:You want to close your resources in a finally block in case read throws an exception. I really want Java 7's try-with-resources thing.
|
# ? Jun 13, 2011 18:21 |
|
Aleksei Vasiliev posted:You can change that to public static silentClose(Closeable... cs) and add a for-loop to save on lines where it's used. What is this called? Everytime I want to google some more information about it, I get stumped because I don't know what to call it.
|
# ? Jun 13, 2011 19:59 |
|
Thermopyle posted:What is this called? varargs
|
# ? Jun 13, 2011 20:01 |
|
Thermopyle posted:What is this called? Everytime I want to google some more information about it, I get stumped because I don't know what to call it. "java ellipsis" on Google finds varargs, "python asterisk" finds Python's varargs, etc Now if it doesn't use any symbols then it's a bit harder
|
# ? Jun 13, 2011 20:05 |
|
epswing posted:I think there's an apache library that contains something similar. IOUtils.
|
# ? Jun 14, 2011 03:59 |
|
I just started getting this error when I try to run a program in Netbeans IDE: Exception in thread "main" java.lang.NoClassDefFoundError: LabRX/GUI Caused by: java.lang.ClassNotFoundException: LabRX.GUI at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) I ran this file literally 15 minutes ago and now all of the sudden I get this poo poo. Anyway know how to fix this? The only thing I can think of that may have caused this was I ran the refractor on a field, but that field was only referenced a couple times and it was successfully changed. Edit: I was able to Clean and Build and run the .jar file, however now when I try to run it in Netbeans I get this: Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - missing method body, or declare abstract at LabRX.GUI.main(GUI.java:7420) Edit2: So I found the problem. I had accidentally created an ActionPerformed event from a ComboBox, so I had tried to delete the action but it must have left some actionlistener somewhere, I'm not totally clear on what happened. I fixed it by deleting the combobox entirely then making a new one. Hidden Under a Hat fucked around with this message at 02:47 on Jun 16, 2011 |
# ? Jun 16, 2011 00:42 |
|
Is there a quick simple way of doing modular subtraction in Java? For example, if I want an int to go from 0..9 and then "wrap" back to 0 when incremented from 9 it's easy to do with ++i % 10. Is there a quick way of doing it if I want to go the other way, i.e. when i is 0 and is decremented, it goes back to 9? Obviously there are easy ways of doing it with if statements and the like but I'm looking for a one statement/line solution, more for my own interest than anything. I'm sure the answer is blindingly obvious but I'm having trouble figuring it out. chippy fucked around with this message at 13:34 on Jun 16, 2011 |
# ? Jun 16, 2011 13:32 |
|
The simplest approach to your example I can think of would be using the ternary operator: x = (x > 0) ? x-1 : 9;. Normally when I need to take a modulus I do something like this: code:
|
# ? Jun 16, 2011 13:45 |
|
chippy posted:Is there a quick simple way of doing modular subtraction in Java? The conditional operator makes if-else logic basically a one-liner: code:
code:
|
# ? Jun 16, 2011 13:49 |
|
Jabor posted:The conditional operator makes if-else logic basically a one-liner: Thanks, I guess something like the second way was what I was trying to figure out, but I was looking for something nicely elegant and the logic was making my head explode. Looking at that I guess I may as well just use the ternary operator.
|
# ? Jun 16, 2011 14:03 |
|
The ternary operator way to do it would be quite a bit faster, too. Modulus is a pretty long operation for the CPU.
|
# ? Jun 16, 2011 14:37 |
|
Oh cool, I figured the ternary would be slower for some reason.
|
# ? Jun 16, 2011 16:12 |
|
Ensign Expendable posted:The ternary operator way to do it would be quite a bit faster, too. Modulus is a pretty long operation for the CPU. While your intuition is basically good, I'd be hesitant to choose one over the other without numbers (consider the branch penalty on some hypothetical processor with a fuckoff-huge pipeline)
|
# ? Jun 16, 2011 18:26 |
|
A somewhat philosophical question: For Maps, why are they both untyped and typed? e.g. for a Map<String, Integer>, the methods are: get(Object) put(String, Integer) putAll(Map<String, Integer>) containsKey(Object) etc. Is there some benefit to having Objects instead of typed parameters? Asking because I have a dumb tendency to accidentally do containsKey with the wrong type.
|
# ? Jun 16, 2011 18:37 |
|
Aleksei Vasiliev posted:A somewhat philosophical question: Because object.equals takes type Object. Also, consider the case when dealing with super classes of the key type and comparing them. Despite two keys being equal, they would get flagged as an error at compile time because the type is wrong (superclass and not defined class). The second line includes the problem of backwards compatibility. HFX fucked around with this message at 19:05 on Jun 16, 2011 |
# ? Jun 16, 2011 19:03 |
|
Otto Skorzeny posted:While your intuition is basically good, I'd be hesitant to choose one over the other without numbers (consider the branch penalty on some hypothetical processor with a fuckoff-huge pipeline) It's deeper than that. The actually interesting questions here are (1) will the optimizer notice that you're using mod just to get wraparound and convert that automatically to control flow and (2) will the code generator be clever enough to do it with a conditional move instead of a branch. The answer to (2) is very likely to be yes, especially if you write it with a ternary.
|
# ? Jun 16, 2011 19:29 |
|
Wow, way over my head. I just really like elegant solutions to things. I used a wraparound in a program I wrote to transpose guitar chords and did a really clumsy job of it with if statements, then I spotted i = ++i % 4 in some code involved with rotating a Tetris piece and it took me ages to figure out what it was actually for. It blew my mind when I realised it was just a really simple way of doing what I'd done with several lines of code. My coding is really clumsy and hacky at the moment but I'm starting a computing degree in October via the Open University and I'm planning to specialise in software engineering so hopefully this will improve matters.
|
# ? Jun 17, 2011 15:09 |
|
HFX posted:Also, consider the case when dealing with super classes of the key type and comparing them. Despite two keys being equal, they would get flagged as an error at compile time because the type is wrong (superclass and not defined class).
|
# ? Jun 18, 2011 17:18 |
|
Mustach posted:Why would you want an instance of a superclass to be equivalent to an instance of a subclass? A canonical implementation of equals() will always return false for such a comparison. Yes, you would get told "yep, these two objects aren't equal" at runtime when you compared them. As opposed to you getting a compile error because you're passing a Foo to a method that only accepts a FooImpl.
|
# ? Jun 18, 2011 22:13 |
|
Mustach posted:Why would you want an instance of a superclass to be equivalent to an instance of a subclass? A canonical implementation of equals() will always return false for such a comparison. But I'm not seeing why Object makes sense. A Collection isn't going to accept superclasses of its declared type, only subclasses. e: I mean, unless you're for some utterly bizarre reason upcasting your keys to Object before you check if they are in the Map, it provides absolutely no benefit, because it will never contain something that isn't of the right type. And if you're doing that then what the gently caress man And I'm definitely not seeing the "backwards compatibility" issue. Malloc Voidstar fucked around with this message at 23:44 on Jun 18, 2011 |
# ? Jun 18, 2011 23:32 |
|
Jabor posted:Yes, you would get told "yep, these two objects aren't equal" at runtime when you compared them.
|
# ? Jun 18, 2011 23:39 |
|
Part of it is the diagonal inheritance issue with interfaces. Suppose I have two collections, one containing IFoos and the other containing IBars. Part of the contract of my class is that a given object should only be in one of those sets, even if it implements both interfaces. Should I go around checking types and casting things myself? Or should we just allow the collection methods to take an Object and if it's not present ... act like it's not present? What does having looser type constraints on those methods actually cost?
|
# ? Jun 19, 2011 01:03 |
|
I have a question regarding using my main class with all the GUI swing components as a superclass, and a subclass which gets information from all the swing components to perform functions. Basically, my main GUI class seems way too big compared to my other classes, because not only does it have all the swing layout component initializations, declarations, and actionperformed methods, is also has all the other methods which manipulate the information I get from doing actions. I basically want to use my main GUI class as a superclass for a new subclass, so the subclass can have access to all the swing components without having to pass them to the class through a constructor. However, since the superclass is the one with the actionPerformed methods, and the subclass has all the other methods that use the information, I run into the problem of trying to call subclass methods from the superclass. What would be the best way to handle this or a better way to design this?
|
# ? Jun 22, 2011 18:30 |
|
Edit: Double Post
maskenfreiheit fucked around with this message at 21:33 on Mar 13, 2017 |
# ? Jun 22, 2011 20:07 |
|
GregNorc posted:What's a good library to create a 3D histogram? http://www.jfree.org/jfreechart/ e: Doesn't look to be active anymore, might be better stuff out there now but JFreeChart is pretty good. I use to abuse the hell out of it for some charting things.
|
# ? Jun 22, 2011 22:38 |
|
How do I add an object to an array inside an object?
|
# ? Jun 23, 2011 01:54 |
|
|
# ? Jun 11, 2024 21:10 |
|
code:
|
# ? Jun 23, 2011 02:35 |