|
Sereri posted:
I suppose that works for this case (I used toLowerCase() instead), but I'd like it to add the word in it's original (first instance) form. If I had: al1: "Cat" "is" "the" "cat" "in" "Breakfast" "at" Tiffany's" I'd like to have "Cat", not "cat" or "CAT" in al2 such that: al2: "Cat" "is" "the" "in" "Breakfast" "at" Tiffany's" Since I'd actually be reading the Strings from a file, I'm experimenting with using two Scanner objects instead of just one... but so far I haven't figured it out.
|
# ? Oct 28, 2010 19:58 |
|
|
# ? May 9, 2024 10:12 |
|
You could use a HashSet on the side (or, possibly better, a TreeSet with a case-insensitive comparator).
|
# ? Oct 28, 2010 21:21 |
|
Here's how to do it the wrong way:code:
|
# ? Oct 28, 2010 22:05 |
|
I am in posted:Maybe it's just your JPA Provider. Which one do you use? OpenJPA 2.0
|
# ? Oct 29, 2010 04:59 |
|
magicalblender posted:Is it possible to make a decorator class that doesn't call super() on its superclass? While you've received other responses, I am going to throw out these two questions: 1) do you need to use a decorator pattern here? 2) does the base Widget class need to be doing all of that work?
|
# ? Oct 29, 2010 20:21 |
|
hayden. posted:If anyone has some websites/resources that explain why I need the MySQL Connector, I'd appreciate it. I don't really understand how all this stuff interacts. Java provides an abstract layer for dealing with databases and database objects (tables, result sets, etc) in the javax.sql package. The idea is to use the same set of classes for all databases, so your code is portable. This is good if you might ever want to switch out MySQL for some other database at some point in the future without worrying about rewriting your code too much. The purpose of MySQL Connector is to translate operations on javax.sql objects in your code to the right commands to the MySQL server to make it do what you want. If you switch to MSSQL or something else, you would rebuild with a different connector, but keep your code (more or less) the same. Let the connector deal with the peculiarities of each individual database and focus on managing your data. Note this bit: Class.forName ("com.mysql.jdbc.Driver").newInstance (); On the surface it is kind of strange, as the new object that gets created doesn't get assigned to anything, you might think it will just get garbage collected without actually doing anything. But it has the side effect of registering the class "com.mysql.jdbc.Driver" with the JDBC driver manager, and when you request a connection with the URL "jdbc:mysql://somedomain.com" the driver manager knows to use this class to handle the connection.
|
# ? Oct 29, 2010 21:44 |
|
I have a project in Eclipse with a handwritten GUI but I'd like to switch to using my IDE to build it. What's the best plugin for this? Should I move it to Netbeans instead? (and I assume that I'll have to delete the GUI class and built it in the tool from scratch?)
|
# ? Oct 30, 2010 02:43 |
|
dividertabs posted:I have a project in Eclipse with a handwritten GUI but I'd like to switch to using my IDE to build it. What's the best plugin for this? Should I move it to Netbeans instead? I'd like to know about this as well. I switched to Netbeans because I just couldn't get Eclipse to do it nicely, while Netbeans was very easy to use. Now I use Netbeans for everything, but I sorta liked Eclipse v v
|
# ? Oct 30, 2010 10:57 |
|
I'm pretty sure that NetBeans is king of the hill with Java GUI building, but if you want to use Eclipse there is the Visual Editor Project which can help you build GUI apps from a variety of frameworks (including Swing). Its a bit clunky but it has alot of functionality.
|
# ? Oct 30, 2010 18:12 |
|
Out of curiosity, why are you going from hand-coded to IDE-generated? I've poked around with Netbeans' editor before, but it takes so much fiddling around to make certain things work correctly (window resizing, font size changing, etc) that it isn't worth the time for me.
|
# ? Oct 31, 2010 22:16 |
|
if I have a switch where several of the cases do the same thing, is there some nifty way to avoid duplicate code? EDIT: VVVVV Cool, thanks Boz0r fucked around with this message at 22:45 on Oct 31, 2010 |
# ? Oct 31, 2010 22:27 |
|
As with other languages, a case will fall-through if there is not an explicit break. So what you want to do looks like:code:
|
# ? Oct 31, 2010 22:31 |
|
Paolomania posted:As with other languages ... C# has no fallthrough, and requires an explicit break, even for the default case. However, you can goto another case.
|
# ? Nov 1, 2010 05:16 |
|
Kilson posted:C# has no fallthrough, and requires an explicit break, even for the default case. However, you can goto another case. Its this way in Ada as well, except the compiler just about comes out and kicks you in the balls if you use a goto.
|
# ? Nov 1, 2010 05:31 |
|
Shavnir posted:Its this way in Ada as well, except the compiler just about comes out and kicks you in the balls if you use a goto. That's probably good. Everyone knows COME FROM is way better than silly goto anyway.
|
# ? Nov 1, 2010 06:40 |
|
Kilson posted:C# has no fallthrough, and requires an explicit break, even for the default case. However, you can goto another case.
|
# ? Nov 1, 2010 13:19 |
|
If you guys want to pedantic, LISP cond and case statements have no fall-through, but in those situations you can use more complicated predicates for your conditions and lists of values for your cases, respectively.
|
# ? Nov 1, 2010 17:38 |
|
TagUrIt posted:Out of curiosity, why are you going from hand-coded to IDE-generated? I've poked around with Netbeans' editor before, but it takes so much fiddling around to make certain things work correctly (window resizing, font size changing, etc) that it isn't worth the time for me. It seemed easier to just design a GUI with a GUI, but after making a toy app in NetBeans and being unable to set a JSplitPanel the way I wanted, I think I'm going to stay with Eclipse and hand-coding. I had assumed most people used software to design GUIs; do most people actually do it by hand?
|
# ? Nov 1, 2010 19:45 |
|
I do. I used to use JDeveloper (*shudder*) to do Swing editing using a GUI-based designer, and it...wasn't the best.
|
# ? Nov 2, 2010 00:21 |
|
Hi, was wondering if any of you could help me with a bit of a problem. I've got an array of 10 ints, lets say 0000000001. I want to take that array, turn it into a normal int and increment it. Then I want to convert that back into an array. My array would then be 0000000002. I'm struggling to work out a way of doing it. Heres what I have so far, code:
Riff fucked around with this message at 13:57 on Nov 4, 2010 |
# ? Nov 4, 2010 13:44 |
|
Riff: so, what you want is to take an array of ints, sum it, increment the sum and produce a new array of the same size with that sum as the last value? This doesn't require any string manipulation.code:
Internet Janitor fucked around with this message at 14:00 on Nov 4, 2010 |
# ? Nov 4, 2010 13:57 |
|
Riff posted:Hi, was wondering if any of you could help me with a bit of a problem. Derail: By the way, Strings are immutable. Don't assign a string like that in a for loop, it's exceptionally slow. As in: See: FindBugs#Method concatenates strings using + in a loop
|
# ? Nov 4, 2010 14:04 |
|
Aleksei Vasiliev posted:Could you post why you want to do it like this? I assume you have a reason for wanting "0000000002" instead of "2". It'll be easier to help you find a solution if we know why you're doing what you're doing. I thought javac was smart enough to recognize this and fix it, however: code:
code:
|
# ? Nov 4, 2010 14:36 |
|
TRex EaterofCars posted:I thought javac was smart enough to recognize this and fix it, however: Escape analysis is an interesting point, since all those strings wouldn't end up on the heap which might make it work -- good point. That feature helps with a few common patterns in Scala that I've seen as well.
|
# ? Nov 4, 2010 15:25 |
|
Hi thanks for the replies, sorry if I haven't been very clear. I'm working on generating error correcting codes (specifically BCH). I want to generate a series of codes based on a user input. If the first number entered is 000000009 then this number goes into the system, the generated code comes out and this original number is incremented by 1 (so it is now 0000000010) this is then looped back into the system to generate another code and so on. It has to be in this format because some of the code includes things like d[6] = ((4 * d[0]) + (10 * d[1]) + (9 * d[2]) + (2 * d[3]) + d[4] + (7 * d[5])) % 11; As far as I can see the only way to do it is going to be to create a set of IF statements that checks to see if the point being incremented is 9 if it is then set that one to zero and increment the next array point along. Riff fucked around with this message at 15:30 on Nov 4, 2010 |
# ? Nov 4, 2010 15:27 |
|
Riff posted:Hi thanks for the replies, sorry if I haven't been very clear. I'm working on generating error correcting codes (specifically BCH). I want to generate a series of codes based on a user input. There might be a more efficient way, but i'd just loop through the list multiplying every number by successive powers of ten and adding them to the number variable, increment the number variable, and convert it back. EDIT: or, loop through the array from the small end until you find a nonzero number. If it's less than 9, increment it. If it's a 9, change it to a 0, change the previous number to a 1 and continue to to loop through the array, changing 9s to 0s, until you find a number that isn't a 9. Jonnty fucked around with this message at 15:46 on Nov 4, 2010 |
# ? Nov 4, 2010 15:42 |
|
Use a string, parse it into an integer, increase it by one, convert it back into a String ( = ""+ number;) check length and fill the missing digits with zeros.
|
# ? Nov 4, 2010 16:04 |
|
Sereri posted:Use a string, parse it into an integer, increase it by one, convert it back into a String ( = ""+ number;) check length and fill the missing digits with zeros. If you do it this way, you can use String.format() or something similar for the padding.
|
# ? Nov 4, 2010 16:09 |
|
Thanks everyone, these all seem like much neater solutions than this monstrosity.code:
|
# ? Nov 4, 2010 17:42 |
|
nooooooooooooooooooooooooooooooooooooo gonna go find some code of mine to refactor to get that out of my head
|
# ? Nov 4, 2010 17:43 |
|
gently caress me, I wasn't expecting that.
|
# ? Nov 4, 2010 17:55 |
|
BigInteger will probably do what you want, it is backed by a byte array and does all the fun math bullshit for you. It'll even give you the byte array when you're done so you can do your wizardry on it.
|
# ? Nov 4, 2010 17:55 |
|
Can anyone give me some suggestions for good resources to learn how to program GUI apps with Java using a text editor and command line compiler? I find diving into an IDE overwhelming. In case it helps your suggestion, here's a summary of my programming experience:
I've already looked over the "Trail: Learning the Java Language" guide at oracle.com and I feel like I have a handle on the language. However, I find if I read the Swing guide there, I get lost in a sea of unfamiliar classes and terminology. Thanks for any help!
|
# ? Nov 5, 2010 02:01 |
|
Step 1 would be to not use a text editor and use an IDE. There are so many different objects you'll use in GUI programming that it'll be more of a headache than it's worth to manage your imports, not to mention other benefits of using an IDE. Trust me - when I studied Java in college, my TAs and professor were adamantly opposed to using IDEs, and I hate them every day for it. This article[1] seems to have a good intro to Swing. As for IDEs, I use Eclipse. I can't speak to other IDEs, but Eclipse does what I need to do and it does it well enough, from what I can tell. You mentioned that diving into an IDE can be overwhelming; that's true of Eclipse. The first thing you do when you start up Eclipse is to close the drat welcome screen, because that thing's useless. This PDF[2] speaks to an old version of the IDE, but it looks like most of the workflows are still applicable. If you're feeling adventurous, I'd recommend also looking into Maven[3]. If anyone tells you to bypass Swing and use something like RCP, politely tell them that you're just starting to learn how to program in Java and that trying to wrap your head around OSGI, classloaders, fragments, and bundling would just be a total mindrape. 1. http://www.javabeginner.com/java-swing/java-swing-tutorial 2. http://cs.armstrong.edu/liang/intro5e/SupplementJEclipse.pdf 3. http://maven.apache.org/
|
# ? Nov 5, 2010 02:42 |
|
Anyone take the IKM tests for Java? Reasonable or should I brush up on obscure stuff?
|
# ? Nov 5, 2010 04:51 |
|
Riff posted:Hi, was wondering if any of you could help me with a bit of a problem. Hurp a durp a durp Is counting really this hard? Seriously? you call incrementArray(new int[] {0,0,0,1}, 10, 1) to add 1 to this array in base 10. code:
this is completely untested but it should work better than adding one to a number by converting it to a string. durp if you said 'convert it to a string' you should be ashamed of yourself. :ugh: pps it works for any increment >=0 tef fucked around with this message at 05:27 on Nov 5, 2010 |
# ? Nov 5, 2010 05:21 |
|
Mr. DNA posted:Can anyone give me some suggestions for good resources to learn how to program GUI apps with Java using a text editor and command line compiler? I find diving into an IDE overwhelming.
|
# ? Nov 5, 2010 05:28 |
|
Mr. DNA posted:Can anyone give me some suggestions for good resources to learn how to program GUI apps with Java using a text editor and command line compiler? I find diving into an IDE overwhelming. (Java) gui toolkits are a miriad of pain and suffering. I can't recommend SWT to anyone, not even the brain damaged (Another cross platform library that needs to be wrapped to be cross platform, for example: tooltips and sliders work significantly differently). quote:Thanks for any help! Writing Java demands an IDE to deal with the level of complexity in modern frameworks and toolkits. Writing java in a barebones environment will drive you insane. (much, much quicker than working in eclipse will) You might find it easier to start with something simpler and pedagogical to learn GUI programming, like Tcl/Tk, or writing a web app in one of the myriad frameworks (i'd recommend python+django fwiw).
|
# ? Nov 5, 2010 05:49 |
|
Aleksei Vasiliev posted:use an IDE like Eclipse. i handcode SWT GUIs in it. I treat it like a text editor that can compile, tell me of my errors while I'm making them, and other stuff. You don't really need to know much to use Eclipse. just do File > New > Java Project, then File > New > Class. Also, File > Restart Eclipse. Although I never get to use it because it just seizes up and locks.
|
# ? Nov 5, 2010 05:50 |
|
|
# ? May 9, 2024 10:12 |
|
tef posted:(Java) gui toolkits are a miriad of pain and suffering. I can't recommend SWT to anyone, not even the brain damaged (Another cross platform library that needs to be wrapped to be cross platform, for example: tooltips and sliders work significantly differently). thus defeating the point of java
|
# ? Nov 5, 2010 05:56 |