|
I hear good things about Google Guice. Spring is also OK, but if you're not using any of their IOP stuff the standard way of using it will drown you in unnecessary XML, whereas the annotation version buys you very little over standard good programming practice. I've not used Guice, either, though, so no guarantees it's actually any better. For what it's worth I'm of the opinion that Scala (another JVM language) would make an excellent, type-safe configuration language for Java. With type-inference it's considerably terser than Java or XML, the very basic language features which you need to construct the items are no more complex than learning a set of annotations, and it'll enforce all (I think) of Java's type constraints so you don't get the exciting runtime problems due to erasure that you get with Spring XML.
|
# ? Jan 29, 2009 10:23 |
|
|
# ? May 25, 2024 14:05 |
|
TRex EaterofCars posted:Spring has a DI framework and I've found it decently powerful. With annotations it's not too bad to use, and configuration with Groovy is pretty easy. TRex EaterofCars posted:To answer your last question, do you have an example of what you're trying to do? If I understand you correctly, you want to do something similar to what Grails does. Grails (uses Spring) will load (and reload) arbitrary classes based on className by introspecting all classes in a given location. The "rules" are basically that the classes have to exist in a certain location. I'm sure you could do something similar. ==Scenario== We have N classes with some similar looking method signatures: pre:package foo1; public class A { public foo1.TypeA method1(..){..} public foo1.TypeB method2(..){..} } package foo2; public class B { public foo2.TypeA method1(..){..} // method2 from A is not here } We (try to) generate an interface with an offline code generator: pre:public interface IAB { public ITypeA method1(..){..} // invokes either A or B's method1 and returns an object that implements ITypeA, namely foo1.TypeA or foo2.TypeB public ITypeB fromA_method2(..){..} // } pre:public class AB { public IAB newInstance(int version){ switch (version){ case VERSION_A: return newInstanceof_A_via_reflection(); case VERSION_B: return newInstanceof_B_via_reflection(); default: throw new FuckinNoobException(); } } } pre:public static void main(String[] args) { int version = Integer.parseInt(args[0]); IAB foo = AB.newInstance(version); foo.method1(..); if (version == WEIRD_VERSION) foo.fromA_method2(..); } } We're currently running a reflection service that resolves type references across multiple packages, resolves dependencies, creates interfaces to union them per roughly congruent class (we supply corresponding classes via canonical names), and generates factory classes and methods that have the sort of usage (poorly) shown above. I'm looking for something more elegant, documented, and flexible than what we have. If you're curious about what beast might warrant all this, I'm trying to wrap an API that is evolving and I can never get rid of old versions nor their previous behaviors but somehow must provide access to all of them from a single API without incurring massive maintenance problems and to provide something concrete to quantify to other API developers how unstable their APIs are for their customers (political leverage on top of technical reasons - what's not to gain?). As new versions come up, we'd like to make adding support for the new API version's methods easier and to minimize memory footprint that would come with statically loading all the classes. So during runtime I pass the version number to be used to a factory that classloads the appropriate version of the library from disk and runs the underlying method or screams "not available in this version" if it's been idiotically removed. We'd like to have some compile-time verification of our unified API as well. Furthermore, I have maybe 10 or so of these API petting zoo collections to maintain... and growing. zootm posted:it'll enforce all (I think) of Java's type constraints so you don't get the exciting runtime problems due to erasure that you get with Spring XML
|
# ? Jan 29, 2009 19:49 |
|
necrobobsledder posted:Crazy poo poo. Holy poo poo... Well, you *can* pull Spring apart, it's pretty modular.... but I don't think I'd try to do what you are doing with it. Is there any reason you can't just bundle revisions of the APIs in individual jars and dynamically classload them depending on the version? You could then introspect the classes made available by that classloader (I found a particulary neat way of doing this just now), and make your interfaces that way. Then you don't have to play traffic cop. Or perhaps I still don't get it
|
# ? Jan 29, 2009 22:09 |
|
TRex EaterofCars posted:Is there any reason you can't just bundle revisions of the APIs in individual jars and dynamically classload them depending on the version? You could then introspect the classes made available by that classloader (I found a particulary neat way of doing this just now), and make your interfaces that way. Then you don't have to play traffic cop. Or perhaps I still don't get it My job is to review APIs, package them into a unified API convention system, test the bejesus out of them, and play traffic cop among the different API versions and for different API categories. Imagine you're trying to keep every copy of PHP since 2.0, remove / delegate away redundant functions, and make a single API that you call the "golden version" of PHP that's distributed to PHP developers. Given how lovely PHP's APIs are, this has some value to anyone that must use PHP but hates its APIs. Oh, I took a look at Spring and it won't suffice for what we're trying to do - we'd have to generate XML instead of Java code like we do now basically. We're too far in the realm of "Java sucks for us, let's rewrite it" territory for it to work probably anyway.
|
# ? Jan 30, 2009 01:40 |
|
I'm implementing a database based on the functional data model and I've got a Map which contains an attribute as it's key, and a List of Objects as it's value (representing a table). I'm trying to get constraints working and am completely stuck on checking that attributes are unique when more than 1 attribute map key is involved. Constraints can be added after settings up the tables etc. so the current data needs to be validated before the constraint is accepted. For example I might have an entity (basically a table) with 2 attributes Forename and Lastname, which will have keys and a List of the values. code:
code:
Edit: gently caress this makes no sense, basically if you have 2 or more Lists which have Objects related by their insertion order (forename, surname etc) what's the best way to see if there are any duplicates across the lists? Twitchy fucked around with this message at 22:12 on Feb 2, 2009 |
# ? Feb 2, 2009 21:43 |
|
I'm trying to get the length of 3 characters on 3 seperate strings. But I can't figure out how to use the .length after declaring a string.
|
# ? Feb 3, 2009 18:12 |
|
Logostomp posted:I'm trying to get the length of 3 characters on 3 seperate strings. What do you mean by "the length of 3 characters"? Do you mean the "graphical width", i.e. the amount of horizontal space the characters take up when rendered in a particular font?
|
# ? Feb 3, 2009 18:24 |
|
rjmccall posted:What do you mean by "the length of 3 characters"? Do you mean the "graphical width", i.e. the amount of horizontal space the characters take up when rendered in a particular font? Length of 3 seperate words. The amount of characters in each word.
|
# ? Feb 3, 2009 18:35 |
|
Logostomp posted:Length of 3 seperate words. The amount of characters in each word. Use string.split to split the string into a list of words, the loop through the list of words and get the length of each string. e: of Mill Town fucked around with this message at 18:55 on Feb 3, 2009 |
# ? Feb 3, 2009 18:48 |
|
Twitchy posted:I'm implementing a database based on the functional data model and I've got a Map which contains an attribute as it's key, and a List of Objects as it's value (representing a table). Something like this would work, although it's pretty horrible (it'd be easier if you had closures and stuff but let's not dwell on that, it's a horrible solution regardless): code:
code:
|
# ? Feb 3, 2009 21:14 |
|
Mill Town posted:Use string.split to split the string into a list of words, the loop through the list of words and get the length of each string. Need to use a if else statement. The question states, "Write a program that reads three strings from the keyboard. Although the strings are in no particiular order, display the string that would be second if they were arranged lexicographically. I don't need somebody to give me the answer, but give me some sort of idea where to go with this. Here's what I have so far. package project5; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String s1, s2, s3; System.out.println("Please enter 3 words"); s1 = keyboard.nextLine(); s2 = keyboard.nextLine(); s3 = keyboard.nextLine(); System.out.println("Now I will show you the second longest string"); } }
|
# ? Feb 3, 2009 21:54 |
|
Logostomp posted:Although the strings are in no particiular order, display the string that would be second if they were arranged lexicographically. I'm not sure what you think length has to do with lexicographic ordering — to the extent it matters here, "lexicographic" is just a fancy word for "alphabetical". Unless you've been asked to do something fancier, just use the compareTo method.
|
# ? Feb 3, 2009 22:22 |
|
Logostomp posted:...unformatted code... Use the code tags to format your code: code:
|
# ? Feb 3, 2009 22:29 |
|
rjmccall posted:I'm not sure what you think length has to do with lexicographic ordering — to the extent it matters here, "lexicographic" is just a fancy word for "alphabetical". Unless you've been asked to do something fancier, just use the compareTo method. So the word would have to be arranged from A to Z. Like a word hot would be before the word not?
|
# ? Feb 4, 2009 05:00 |
|
Logostomp posted:So the word would have to be arranged from A to Z. Like a word hot would be before the word not? Right, and "hop" before "hot", and "hot" before "hottentot". Something worth noting: compareTo's algorithm is based purely on the numeric values of characters, and the capital (English) letters happen to all be numerically less than the lowercase letters, so it will also put "Hot" before "abracadabra" — but chances are good that your professor will be overjoyed if you can manage the if statements and certainly will not quibble over case-sensitivity.
|
# ? Feb 4, 2009 05:30 |
|
rjmccall posted:Right, and "hop" before "hot", and "hot" before "hottentot". Something worth noting: compareTo's algorithm is based purely on the numeric values of characters, and the capital (English) letters happen to all be numerically less than the lowercase letters, so it will also put "Hot" before "abracadabra" — but chances are good that your professor will be overjoyed if you can manage the if statements and certainly will not quibble over case-sensitivity. compareToIgnoreCase() exists for that reason
|
# ? Feb 4, 2009 05:37 |
|
Another alternative is to call java.text.Collator.getInstance() to get a Collator object which you can call myCollator.compare(string1, string2) and get the correct behavior for where you live.
|
# ? Feb 4, 2009 06:03 |
|
That inspired me to look at the javadoc for compareToIgnoreCase(), which says this:quote:where case differences have been eliminated by calling Character.toLowerCase(Character.toUpperCase(character)) on each character
|
# ? Feb 4, 2009 16:05 |
|
rjmccall posted:Right, and "hop" before "hot", and "hot" before "hottentot". Something worth noting: compareTo's algorithm is based purely on the numeric values of characters, and the capital (English) letters happen to all be numerically less than the lowercase letters, so it will also put "Hot" before "abracadabra" — but chances are good that your professor will be overjoyed if you can manage the if statements and certainly will not quibble over case-sensitivity. Sounds good. I will try this out. Thanks for the help.
|
# ? Feb 4, 2009 17:10 |
|
Mustach posted:That inspired me to look at the javadoc for compareToIgnoreCase(), which says this:
|
# ? Feb 4, 2009 19:46 |
|
zootm posted:It'll be an internationalisation thing. I imagine the case conversion is not necessarily reflexive. Yeah. It handles the German esszett, or ß character. When capitalized, it turns into SS, which then lowercases back to ss, the equivalent without the ligature. So Straße becomes STRASSE becomes strasse. Note that not only is this irreflexive, it gets longer in the process, potentially overflowing buffers for the unwary.
|
# ? Feb 5, 2009 01:29 |
|
...
maskenfreiheit fucked around with this message at 03:43 on Sep 29, 2010 |
# ? Feb 5, 2009 04:18 |
|
Another question. I'm almost done with this other Java question. I need to know how to do multiples of numbers. Like the input has to be a multiple of 5, the rest would be an error, like a 3, 1, 6, ect. Also has to be greater than or equal to 25 and less than or equal to 100 and a multiple of 5. I've got 2 out of 3 done. Boo This Man fucked around with this message at 06:20 on Feb 5, 2009 |
# ? Feb 5, 2009 06:17 |
|
It uses an operator, I can tell you that much. It also doesn't use the result of the operator directly, but compares it to another number. If they're equal, it's divisible.
|
# ? Feb 5, 2009 07:11 |
|
Nevermind, I figured it out.
|
# ? Feb 5, 2009 07:18 |
|
GregNorc posted:I'm reading head first java... they had this optional exercise messing around with the sound API... it's a really basic program, it's supposed to just play 1 note, to get used to the commands needed. Apparently MIDI just doesn't work in Java in later versions of OS X. Here's a piece of software that's supposed to fix that: http://www.humatic.de/htools/mmj.htm However, I tried installing this on my computer and running your program, and it didn't help. I think this software is mostly used for attaching hardware MIDI devices, and I can't find a software MIDI synth on my system at all. I was sure there used to be one in older versions of OS X.
|
# ? Feb 5, 2009 10:21 |
|
1337JiveTurkey posted:Yeah. It handles the German esszett, or ß character. When capitalized, it turns into SS, which then lowercases back to ss, the equivalent without the ligature. So Straße becomes STRASSE becomes strasse. Note that not only is this irreflexive, it gets longer in the process, potentially overflowing buffers for the unwary.
|
# ? Feb 5, 2009 16:37 |
|
...
maskenfreiheit fucked around with this message at 03:44 on Sep 29, 2010 |
# ? Feb 5, 2009 21:18 |
|
GregNorc posted:poo poo. Pretty much the final three chapters, which deal with socket programming, swing, all the good stuff... they center around this beatbox app you make that keeps getting functionality on (like streaming over a network with sockets, or a GUI w/ swing) This is just me talking out of my rear end here after some cursory googling, so don't get too discouraged yet. You could replace the javax bits with calls to the equivalent bits of mmj, or something like that. Edit: and the software synth IS still in OSX, I just checked. I don't know how to call it from Java, though.
|
# ? Feb 5, 2009 22:30 |
|
Mustach posted:Those are the String methods you're talking about, though. compareToIgnoreCase uses the Character ones, which don't do those kinds of conversions. OK, there's gotta be something really subtle going on there but at least in the case of Turkish, it'd map small i (no dot) to large I (no dot) back to small i (dot) and large I (dot) to large I (dot) to small I (dot) instead of the locale-specific way. Lots of programs break when run in the Turkish locale because they assume that every language with I and i map between the cases the same way as English.
|
# ? Feb 6, 2009 00:39 |
|
I have a null pointer exception and can't for the life of me figure out what is wrong, could someone please help? Exception in thread "main" java.lang.NullPointerException at quiz.answers(quiz.java:77) at quiz.main(quiz.java:20) http://pastebin.com/m23bd1221
|
# ? Feb 6, 2009 01:31 |
|
I'm starting a simple project in Java (actually it's in clojure, but Java+swing libs will be used) to enter recipes and save them in a database, for the gui part, what would be the best widget to handle it? I was just reading over the docs and my head is spinning a bit. It should be simple, just adding/removing lines of text (ingredients) and being able to access them easily by line is my only concern. Would JTextArea suffice?
|
# ? Feb 6, 2009 01:46 |
|
Sour Fish posted:I have a null pointer exception and can't for the life of me figure out what is wrong, could someone please help? line is the only thing you dereference on line 77. readLine() returns null at end of stream.
|
# ? Feb 6, 2009 01:51 |
|
Sour Fish posted:I have a null pointer exception and can't for the life of me figure out what is wrong, could someone please help? Sysout the string 'line' or something. It is probally null or ""
|
# ? Feb 6, 2009 01:53 |
|
Ah I needed to add inFile.close(); initFile(); in the previous method that referenced line. Thank you.
|
# ? Feb 6, 2009 02:02 |
|
Without Pants posted:I'm starting a simple project in Java (actually it's in clojure, but Java+swing libs will be used) to enter recipes and save them in a database, for the gui part, what would be the best widget to handle it? I was just reading over the docs and my head is spinning a bit. Yeah. If you're really only looking for something simple for entering individual lines of text, you could just use a JList with some sort of customization for in-place editing. Using a single selection model and a JTextField for rendering on top of the active cell seems like a horrible hack but it should work in theory.
|
# ? Feb 6, 2009 02:35 |
|
JList looks like just what I'm looking for. Thanks!
|
# ? Feb 6, 2009 03:34 |
|
Retarded CS major here. Is there anyway to use the JTextField class and Scanner class together? I'm looking at the API and I can't find a method to use here.
|
# ? Feb 6, 2009 04:19 |
|
Trifling Fox posted:Retarded CS major here. Sorry for such a long post, but just knowing there isn't a way is only half the story. JTextField and other GUI objects work under a completely different principle than you're used to from writing apps that use Scanner and System.in. The way you're used to is you write a program that starts from the beginning of main() and you trace the flow of control all the way to the end. If the user hasn't entered a line on the console, the Scanner blocks (waits) until something happens and the flow of control stops. Intuitively it feels like we should be able to make a program with a GUI which acts the same way but then the question arises: If I'm waiting for one thing but the user does something else, how can I react? There are three solutions: The first was making a seperate flow of control (thread) for everything. It sounds good in theory, but what happens if you press on one button before another's done processing? Very bad things, that's what. The only use of that solution was BeOS which had a reputation for being quick, responsive and buggy as gently caress. The second option is to have one flow of control which doesn't wait for something to happen, it just loops over everything in the GUI to see if something changed (polling) but never waits for anything to happen. Embedded computers like in cars use this because it doesn't take a lot of elaborate software or specialized hardware to make it work. Finally, we can have one flow of control which waits for anything to happen at all, figures out what to do based on what happened, and then waits for the next event. It sounds painful to write code which can handle anything that a user can do in a GUI considering that there's gotta be hundreds of possibilities. Most modern OSes as well as Swing use this method, but they don't force you to write one big loop that does it all. Instead, they have what's called the event dispatch loop or event dispatch thread. You create event listeners and register them with this loop. Event listeners have code that you want performed when some event happens, like when the user presses enter on a JTextField. code:
|
# ? Feb 6, 2009 06:05 |
|
|
# ? May 25, 2024 14:05 |
|
Excellent post, 1337JiveTurkey! It should also be noted that there is a nasty consequence to letting just this one thread handle all the events in Swing: if your event handling includes a lengthy operation (say, getting a file from a network location or calculating something that takes a while), that means that you have effectively prohibited the GUI from being responsive during that time. To avoid this problem, you must perform lengthy tasks in the background using another thread. Thankfully, there is a class for making this easy, called SwingWorker. Read up on Concurrency in Swing, and really get comfortable with the concepts presented there. Obeying the rules there is crucial to making usable programs.
|
# ? Feb 7, 2009 16:35 |