|
Mustach posted:The lesson is that everything that depends on input should be in the try block: There's two other problems here though - the compiler may not recognise that System.exit terminates control flow (although really avoiding that function is the best solution for that). The other problem is that FindBugs may not think that 'readLine' returns a non-null value.
|
# ? Aug 29, 2008 07:59 |
|
|
# ? May 9, 2024 14:18 |
|
zootm posted:I'd consider this pretty bad style - it's usually best to avoid putting code that doesn't throw a given exception in a 'try' block which catches it. Removing the '= null' from the variable declaration will cause the compiler to check that any control flow to a line where you use the variable definitely assigns it. What would be another way to terminate flow? Just a simple return?
|
# ? Aug 29, 2008 13:15 |
|
zootm posted:I'd consider this pretty bad style - it's usually best to avoid putting code that doesn't throw a given exception in a 'try' block which catches it. Removing the '= null' from the variable declaration will cause the compiler to check that any control flow to a line where you use the variable definitely assigns it. code:
code:
edit: I got the semantics of readLine() wrong again; just pretends it's some other readLine(). Mustach fucked around with this message at 13:31 on Aug 29, 2008 |
# ? Aug 29, 2008 13:18 |
|
Mustach posted:
code:
zootm fucked around with this message at 13:50 on Aug 29, 2008 |
# ? Aug 29, 2008 13:40 |
|
What makes that superior tocode:
|
# ? Aug 29, 2008 14:10 |
|
Mustach posted:What makes that superior to
|
# ? Aug 29, 2008 15:17 |
|
I have class Coordinate which contains 3 doubles x,y,z. I have coordinates_triangles = TreeMap< Coordinate, Vector< Triangle > > there is problem with following code code:
here is code for it code:
Entheogen fucked around with this message at 00:47 on Aug 30, 2008 |
# ? Aug 30, 2008 00:45 |
|
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 |
|
Make sure that a.equals( b ) iff a.compareTo( b ) == 0. The first condition needs to be true for 'get' to yield a value, but the second is the case where keys will overwrite elements, I think.
|
# ? Aug 30, 2008 09:48 |
|
I'm creating a jsp powered booking system and I'm not sure how I should be doing the controller classes. I have a jsp (view) that displays all the bookings, and on that page, users can add or delete them. Currently I'm using a addBooking servlet, should I be creating a delBooking Servlet, or is there a better way to do this (MVC)?
|
# ? Aug 30, 2008 16:10 |
|
I have a bunch of mailing list data in an Excel file that I want to put in an Access file (I would prefer/it would be easier to use mySQL, but I'm doing this pro bono for a non-profit and they want it in an Access DB). Ideally I could just import the data into Access using the import wizard, but I need to do some processing on the data before I can import it, and I want to split it into 2 files. I was hoping to do this with Java, because that's the language I'm most familiar with. I was hoping to just export the Excel file as CSV data, and then write a Java program to process the data and insert it into my Access database. If there's a better way to do this, I'm open to suggestions, but I'd like to use Java and I'm just having trouble interfacing with Access. How can I use an Access database from Java?
|
# ? Sep 1, 2008 15:28 |
|
invid posted:I'm creating a jsp powered booking system and I'm not sure how I should be doing the controller classes. I have a jsp (view) that displays all the bookings, and on that page, users can add or delete them. Currently I'm using a addBooking servlet, should I be creating a delBooking Servlet, or is there a better way to do this (MVC)? dancavallaro posted:I have a bunch of mailing list data in an Excel file that I want to put in an Access file (I would prefer/it would be easier to use mySQL, but I'm doing this pro bono for a non-profit and they want it in an Access DB). Ideally I could just import the data into Access using the import wizard, but I need to do some processing on the data before I can import it, and I want to split it into 2 files. I was hoping to do this with Java, because that's the language I'm most familiar with. I was hoping to just export the Excel file as CSV data, and then write a Java program to process the data and insert it into my Access database. If there's a better way to do this, I'm open to suggestions, but I'd like to use Java and I'm just having trouble interfacing with Access. How can I use an Access database from Java? zootm fucked around with this message at 16:10 on Sep 1, 2008 |
# ? Sep 1, 2008 16:06 |
|
zootm posted:You can access Excel documents using Apache POI (this was pretty bad for a while but I hear it's a lot better now), and I'm led to believe that you can access Access databases from Java using the JDBC-ODBC bridge driver. This claims to work. Hmm.. after looking at all that, I think I'm just gonna try C# - it seems like it's better-supported and will be much easier. I don't need this to be cross platform, I'm only writing a program to put initial data into an Access database and then the program will never be used again.
|
# ? Sep 1, 2008 19:48 |
|
off the topic but for lack of better place to put it: anybody know of any good editors out there for groovy? Preferably with code complete/assist*, auto formatting, fix imports and the other shiny stuff that eclipse has. Too long with eclipse has made me soft and I cannot code without these functions anymore! I have tried the eclipse plugin but it leaves a lot to be desired. *Obviously this is much harder to do for groovy, but I'm not a details man.
|
# ? Sep 1, 2008 23:31 |
|
I think that the NetBeans 6.5 beta may have Groovy support, they've added a ton of dynamic language support in there recently and it works pretty well. Failing that some nerd may well have made nice Vim or Emacs bindings.
|
# ? Sep 2, 2008 00: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 |
|
I never hear anything but glowing reviews about everything IntelliJ IDEA does so yeah, if willing to fork out the cash it's likely a good call.
|
# ? Sep 2, 2008 18:07 |
|
Edit - double post
|
# ? Sep 2, 2008 18:07 |
|
I've a problem. I'm using OpenCSV to parse some data into my script that will insert it into an SQL database. But I'm having some problems handling escape characters. Here's my code: code:
code:
I suspect that it is still to the "/" between the words "School of Accountancy and School of Law" that is breaking the Preparedstatement. Is there anyone who have encountered something similar before? Edit: I realised that if I try to hardcode the query directly into mySQL query browser: code:
Something is wrong. invid fucked around with this message at 12:40 on Sep 3, 2008 |
# ? Sep 3, 2008 12:11 |
|
Could be a shaky JDBC driver I guess. Without the actual error this'll be basically impossible to diagnose though.
|
# ? Sep 3, 2008 14:08 |
|
How can I check the error?
|
# ? Sep 3, 2008 14:31 |
|
If you're having problems, surely an exception was thrown? Also I've noticed that in your SQL statement you pass the last argument as a string, whereas in your Java code you set it as a number. Depending on your database this could cause a problem.
|
# ? Sep 3, 2008 14:34 |
|
hi zoot, the order was changed during the parsing, I ignored the last value from the csv file. The type is confirmed to be correct. As for the exceptions, none were thrown for some weird reason. It just that it never made it into the database. I did a small script to debug. Here's the script in action: code:
code:
code:
|
# ? Sep 3, 2008 14:55 |
|
You're catching the SQLException and not using its value. Try at least printing it out.
|
# ? Sep 3, 2008 15:10 |
|
Library choosing question: having made the jump from C++, I'll be doing some numerical computation work (multidimensional arrays, stats etc.) with Java. Which leads to the problem: what library do I use? For example, in Python, while there are a number of packages, there's really only one that anyone uses (Numpy). In C, the choice is less clear but there's a big community / lot of users for LAPACK and GSL. What's the Java equivalent if any? Is there an undisputed leader in numerical computation? And is there a similar leader for graphing and visualization?
|
# ? Sep 4, 2008 13:16 |
|
Quick Java NullPointerException question... I just started learning Java (making the jump from C++), and I still don't fully understand some of the nuances of the new language. Anyways, I'm currently working on a homework assignment in which I have to implement a dorm/student registration and selection tool. When I try to compile my project, I receive the following error: code:
Application.java //has a menu() method that controls everything Dorm.java //comprised of Floors Floor.java //comprised of Students Student.java Thanks in advance for your time and any help you may give me, it is much appreciated!
|
# ? Sep 6, 2008 20:37 |
|
ignorant slut posted:
The "dorms" HashMap is null. Initialize it... HashMap<Integer, Dorm> dorms = new HashMap<Integer,Dorm>();
|
# ? Sep 6, 2008 20:57 |
|
ignorant slut posted:Quick Java NullPointerException question... Use debug mode and breakpoints in whatever IDE you are running and you should be able to work out any NullPointer. Anyway... I've not ran your code but after a quick look it looks like you've not instantiated your HashMaps. HashMap<Integer, Dorm> dorms; should be Map<Integer, Dorm> dorms = new HashMap<Integer, Dorm>(); You've done this with the other Maps in other classes as as well. Anyway I think you've misunderstood what HashMaps are for here. They are like a dictionary, IE store Key Value pairs. From your code, it looks like you don't want to do this as you are just using sequential numbers as keys. In this instance just use an ArrayList for holding your dorms, floors and students: List<Dorm> dorms = new ArrayList<Dorm>(); standard fucked around with this message at 21:19 on Sep 6, 2008 |
# ? Sep 6, 2008 20:59 |
|
Minus Pants posted:The "dorms" HashMap is null. Initialize it... standard posted:I've not ran your code but after a quick look it looks like you've not instantiated your HashMaps. That was it, thank you much guys! standard posted:Anyway I think you've misunderstood what HashMaps are for here. They are like a dictionary, IE store Key Value pairs. From your code, it looks like you don't want to do this as you are just using sequential numbers as keys. Ah, that makes a lot more sense. Thanks for the tip ignorant slut fucked around with this message at 21:27 on Sep 6, 2008 |
# ? Sep 6, 2008 21:22 |
|
Repeating this because your quoted me before I edited: Anyway I think you've misunderstood what HashMaps are for here. They are like a dictionary, IE store Key Value pairs. From your code, it looks like you don't want to do this as you are just using sequential numbers as keys. In this instance just use an ArrayList for holding your dorms, floors and students: List<Dorm> dorms = new ArrayList<Dorm>(); It looks like you are making a decent stab at this so I don't mind chatting to you on MSN (Sorry I'm from the UK and no one uses AIM) if you have any more questions. I won't do your homework for you mind... Email me your MSN from my profile if you want.
|
# ? Sep 6, 2008 21:26 |
|
what is the fastest way to merge 2 binary files into one?
|
# ? Sep 9, 2008 02:03 |
|
Entheogen posted:what is the fastest way to merge 2 binary files into one? Define "merge."
|
# ? Sep 9, 2008 02:55 |
|
edit: Could someone tell me how to perform an HTTP POST operation from Java? I have all the code in place, but am getting "AccessControlException: access denied" errors. I guess that the issue is down to permissions as I'm trying to access an external URL, but I don't get how to grant all permissions for testing. Anyone got any experience with this sort of thing? edit2: Is HTTP POST even restricted in this way? I can get a Java application to do the exact thing I want, but I need to distribute it on our intranet, so I'd like to make it an applet. I've tried self-signing the applet, but it still won't allow me to make a call in the same way as the application..... Flamadiddle fucked around with this message at 20:44 on Sep 9, 2008 |
# ? Sep 9, 2008 13:06 |
|
I want to... send a [method/closure/function/some computation sequence] that has been defined at runtime over the network Is it possible in java? For instance if I have some method wrapped in a class: code:
is it possible for me to send this to another completely seperate java runtime which has no prior knowledge of the class? I was thinking of trying to serialize the class (as in, the actual MethodWrap.class) into byte form, send it over network, unpack is and then somehow call ClassLoader#defineClass() to obtain a Class type, and use reflection to call the myMethod. Problem is: 1. Don't know how to serialize MethodWrap.class. If I try something like Object o = MethodWrap.class and then serialize object o as I normally would, it creates a tiny byte[] array which obviously doesn't represent the full class. 2. Don't know how I would call defineClass() as it is a protected method. Are there other accessor/helper methods I should be using? This is annoying hard to google as well. Anybody have any ideas?
|
# ? Sep 9, 2008 16:19 |
|
If you create an interface which defines your expected method call, you can avoid using reflection (build the class and then just newInstance it then cast to MyInterface or Callable<T> or whatever). As for your "deeper" problem, I really don't know why serialising a Class instance doesn't work - it may "just work" unless the byte array is really tiny. Also, to load your own classes in a custom way, you probably want your own ClassLoader implementation - try subclassing ClassLoader (I don't think you need the extra gubbins that SecureClassLoader buys you but I could easily be wrong). Of course the "outside the box" solution would be to use javax.script and define the function to be called in Javascript (comes with SE6) or any one of these languages (requires bundling the runtime for the language, which can get large). Then you just need to pass the string of the source. Probably completely over the top for any reasonable use-case though. zootm fucked around with this message at 17:33 on Sep 9, 2008 |
# ? Sep 9, 2008 17:30 |
|
I did a search and didn't find anything, but I can't work out what's wrong with my applet that talks to a database. It works fine as an applet, but it uses a 3rd party driver (jtds), which is fine for the application, as I've happily added it to my CLASSPATH. My problem comes in running as an applet. The applet can't find the .jar that holds the Driver class file, for obvious reasons. I've also had to compile the .class file into a .jar due to the security issues with applets. When I try to run the applet, I get a code:
My question is, how do I include the Driver.class file in my compiled .jar file so that it knows where to find it? The internet is fruitless with this. Edit: I've managed to get it to work by adding the .jar to the .html file as so: code:
Flamadiddle fucked around with this message at 16:25 on Sep 16, 2008 |
# ? Sep 16, 2008 16:15 |
|
Flamadiddle posted:is this the proper solution? It's a good solution for your immediate problem. I'm really worried about the fact that you want to open an external database connection from an applet, though. Is this for use purely behind a firewall?
|
# ? Sep 16, 2008 19:31 |
|
Flamadiddle posted:is this the proper solution?
|
# ? Sep 16, 2008 19:32 |
|
rjmccall posted:It's a good solution for your immediate problem. I'm really worried about the fact that you want to open an external database connection from an applet, though. Is this for use purely behind a firewall? Not necessarily, no. Some staff may need to use the system from home. If there are major security issues with it, then I'll have to bring it up with the boss... It's just that the use of the database makes what we want to do much simpler. Would it make more sense to make a call to a server side application or something to seperate the user from the database? zootm posted:With applets, I think it is. Executable JAR files can specify their dependencies in their manifest, so that might work too. Also Java Web Start has a magic dependency mechanism of some kind as well. Actually if you're accessing a database through an applet, maybe a full-blown Web Start app is a better fit for your use-case. Thanks for that. Do you have any decent sources on Web Start apps? I've not heard of them before.
|
# ? Sep 17, 2008 12:05 |
|
|
# ? May 9, 2024 14:18 |
|
Flamadiddle posted:It's just that the use of the database makes what we want to do much simpler. Would it make more sense to make a call to a server side application or something to seperate the user from the database? This is the correct way to do it, you don't want random people on the internet to have direct access to your database.
|
# ? Sep 17, 2008 15:16 |