|
zootm posted:A lot of thought seems to have gone into making enums "work right". If only they could have applied the same amount of thought to other parts of Java, like generics.
|
# ? Feb 9, 2010 20:35 |
|
|
# ? May 11, 2024 19:46 |
|
Flobbster posted:If only they could have applied the same amount of thought to other parts of Java, like generics. I don't like the failied auto-unboxing of nulls though. It seems that if the default value of an Integer is null, and the default value of int is zero, then auto-unboxing a null Integer reference should return zero instead of allow for a new type of semi-obscure NullPointerException bug. It just seems unexpected for the default value not to unbox to the default value. FindBugs can help location those.
|
# ? Feb 9, 2010 20:41 |
|
Fly posted:Generics are okay-ish if a bit lame. Null isn't the default value of an Integer, it's the default value of a reference to an Integer, which is a different thing. Integer doesn't have a default value because it doesn't have a
|
# ? Feb 9, 2010 22:46 |
|
Flobbster posted:If only they could have applied the same amount of thought to other parts of Java, like generics. Of course that was a stupid restriction, which has saddled us with the pain we have now.
|
# ? Feb 9, 2010 23:07 |
|
The funny part is that the bytecode changed in other areas anyway, which means they might as well have let them change it. I've always thought the worst thing about Java isn't the language but the JSR and JCP.
|
# ? Feb 10, 2010 00:05 |
|
Mill Town posted:Null isn't the default value of an Integer, it's the default value of a reference to an Integer, which is a different thing. Integer doesn't have a default value because it doesn't have a
|
# ? Feb 10, 2010 00:11 |
|
Fly posted:That's a good point. The failure on auto-unboxing the default reference value still introduces a new type of bug that I would rather not have to deal with. I simply stopped using primitives due to this. I didn't want the issues to ever come up again. I almost never use arrays any more either.
|
# ? Feb 10, 2010 02:48 |
|
necrobobsledder posted:I've always thought the worst thing about Java isn't the language but the JSR and JCP. I agree, and the entire web part is a mess. The worst part is that when you start out doing web development in Java everything you read is like "Hey JSF + EJB is the reference, its the way to go!" so you start learning and developing in JSF only to find out its a huge clunky piece of poo poo. Then 8 months in you realize that all the cool kids are using Struts2 or Spring or anything but JSF and pairing it with Hibernate or iBatis and you feel like a big dick for wasting a ton of time.
|
# ? Feb 10, 2010 13:15 |
|
I'm building the GUI for a program I'm working on and I've hit a bit of a problem. My GUI is arranged in the following way: a 'main' JFrame that is always open, a JTree in the JFrame (on the left), and a large JPanel taking up the rest of the JFrame. I'm swapping panels in and out of that JPanel, depending on what the user wants to do. The problem I have is I'm not sure how to assemble my JTree and for it to load new instances of my the JPanels. Any ideas? Edit: I can do the actual swapping, I've written a setPanel() method for the main window. I basically need to call setPanel(new NameOfNewPanel()); when a user clicks on an item in the JTree.
|
# ? Feb 11, 2010 13:45 |
|
amr posted:I'm building the GUI for a program I'm working on and I've hit a bit of a problem. CardLayout on the right hand side to swap things, then put a TreeSelectionListener on the tree to be informed whenever the user picks something different. Usually you'd make or extend your own tree model to store the information about the editor that should be shown for that tree node.
|
# ? Feb 11, 2010 14:53 |
|
That's what I'm doing currently. CardLayout to swap the panels, and extending my own tree, the problem is I'm not sure how to store nodes in the JTree and then how I should load the correct panel. Currently I've got a big switch statement and I'm swapping based on the node's toString() (not the best idea, I know, that's what I'm wanting to change it)
|
# ? Feb 11, 2010 15:51 |
|
So I haven't touched Java since college and I'm diving back in for an Android project that is coming up for work. Being that this is my first time doing legit Java work (and since Java 1.4) can anybody explain to me the proper naming conventions for packages? Here's my setup: I've got the Android app frontend, a set of classes that define the backend logic (interfacing with a web service), and then a series of utilities. Ballparking it, I figured I'd use this convention: com.myapp.frontend com.myapp.backend com.myapp.utilities
|
# ? Feb 11, 2010 16:07 |
|
I've got an applet that needs to connect to a MYSQL database that's sitting behind a firewall, maybe two. What is the best, and/or easiest, way to get this done? e: for reference, the method the network admin. suggested was to use a set of PHP pages to query the database indirectly, but I'm not completely sure how that would work? Azerban fucked around with this message at 17:14 on Feb 11, 2010 |
# ? Feb 11, 2010 17:03 |
|
Ferg posted:So I haven't touched Java since college and I'm diving back in for an Android project that is coming up for work. Being that this is my first time doing legit Java work (and since Java 1.4) can anybody explain to me the proper naming conventions for packages? doesn't really matter as long as it meets your companies guidelines. Just make sure it is logically placed
|
# ? Feb 11, 2010 17:52 |
|
Azerban posted:I've got an applet that needs to connect to a MYSQL database that's sitting behind a firewall, maybe two. What is the best, and/or easiest, way to get this done? Is the server that is serving the applet able to reach the database? If so you can use a servlet to do connect to the database. If they aren't on the same server then the applet has to be signed. In the applet you would do something similar to: code:
code:
e: A couple things, you probably need a time out in the applet in case the servlet is down as it won't do anything till it gets a response from the servlet. If you need to pass a primitive to the servlet just use one of the wrapper classes. You can also only pass serializable objects back and forth. lamentable dustman fucked around with this message at 18:17 on Feb 11, 2010 |
# ? Feb 11, 2010 18:13 |
|
Okay, I give up. I'm not sure if my problem belongs in this thread or should be in its own thread (the preview looks long). Here is my situation: I am hosting my application in Tomcat 6 in a windows XP environment. I am connecting to a MySQL database (5.1.39) via JDBC (mysql-connector-java-5.1.11-bin.jar) and pooling it through JNDI datasource explained here: http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html. I have the needed jar files in my tomcat/lib folder. I am having a connection issue where a db connection closes and it seems to close all db connections. This is causing slightly longer running ResultSets from closing in the middle of their reading, but only when the queries are executed at practically the same time (I am using two windows and submitting a form at the same time). Now, I'm sure what is wrong is something simple and I have just overlooked it or don't know what exactly to google. Any help would be greatly appreciated. Below is some code examples: Connection Management: code:
code:
Addition to web.xml: code:
code:
code:
code:
Kanen fucked around with this message at 21:07 on Feb 11, 2010 |
# ? Feb 11, 2010 21:02 |
|
I don't see APPartsConn defined anywhere. If it's shared by multiple threads of execution, which it may well be since the scope of APPartsConn is not evident from the code you posted, then that would be the problem.
|
# ? Feb 11, 2010 22:03 |
|
Fly posted:I don't see APPartsConn defined anywhere. If it's shared by multiple threads of execution, which it may well be since the scope of APPartsConn is not evident from the code you posted, then that would be the problem. Sorry, it is defined at the top of the class: code:
|
# ? Feb 11, 2010 22:06 |
|
Kanen posted:Sorry, it is defined at the top of the class: edit: rephrased Fly fucked around with this message at 23:59 on Feb 11, 2010 |
# ? Feb 11, 2010 22:10 |
|
Fly posted:Yes, it does. Each thread needs its own Connection. You're getting who-knows-what data mixups using a global Connection. I just ran a few tests, that seems to have fixed it. I knew it was something simple I was overlooking. Thanks a ton.
|
# ? Feb 11, 2010 22:23 |
|
If you need speed, why not use a DB Connection Pool? It'll handle all the thread safety issues you're having now plus give you better query latency.
|
# ? Feb 11, 2010 22:33 |
|
TRex EaterofCars posted:If you need speed, why not use a DB Connection Pool? It'll handle all the thread safety issues you're having now plus give you better query latency.
|
# ? Feb 11, 2010 22:38 |
|
Fly posted:I do not think a connection pool would solve the thread safety issue above, but it might be less likely to lead one to want a singleton connection. You're right. However, I do think that having to allocate the pool then having the connection manager act as your singleton would help in making it more clear how to handle database connections. Maybe I'm wrong.
|
# ? Feb 12, 2010 01:07 |
|
TRex EaterofCars posted:You're right. However, I do think that having to allocate the pool then having the connection manager act as your singleton would help in making it more clear how to handle database connections. Maybe I'm wrong.
|
# ? Feb 12, 2010 02:40 |
Looking for a way to generate some charts in Java and output to an image. JFreeChart looks pretty sweet, anything else I should check out before diving in?
|
|
# ? Feb 12, 2010 02:42 |
|
fletcher posted:Looking for a way to generate some charts in Java and output to an image. JFree looks pretty sweet, anything else I should check out before diving in? Used it before, it works really well but the documentation sucks and is built around buying his book. Probably worth it but if you're cheap like me (or rather my company...) use a recompiled to look around the source of his demo app to learn alot lamentable dustman fucked around with this message at 02:47 on Feb 12, 2010 |
# ? Feb 12, 2010 02:44 |
|
amr posted:That's what I'm doing currently. CardLayout to swap the panels, and extending my own tree, the problem is I'm not sure how to store nodes in the JTree and then how I should load the correct panel. Currently I've got a big switch statement and I'm swapping based on the node's toString() (not the best idea, I know, that's what I'm wanting to change it) Swing is MVC-oriented, so the idea is that your data should either implement the TreeModel or TreeNode interfaces or have that as a front end that ultimately manipulates them. Then it's not really a question of how you store the nodes because then the JTree is just a window (the View) onto your Model. The tree then by default displays the toString() of the nodes themselves and you can have all the data you need inside of the nodes. To pick what to display there's a few ways. The most straightforward method of just having a method that gets the panel itself on the node has the problem that it sticks a dependency on your View in the Model when generally it should always be in the other direction. Using a map of node classes to right hand panels could also work. The selection listener would then get the selected node and look up its class to find the correct right hand panel, then pass the node to the panel in some initialize method. That can be made as simple or as complex as you like.
|
# ? Feb 12, 2010 07:02 |
|
fletcher posted:Looking for a way to generate some charts in Java and output to an image. JFreeChart looks pretty sweet, anything else I should check out before diving in? Is pure image a necessity or are you doing a Web UI?
|
# ? Feb 12, 2010 18:51 |
|
fletcher posted:Looking for a way to generate some charts in Java and output to an image. JFreeChart looks pretty sweet, anything else I should check out before diving in?
|
# ? Feb 12, 2010 19:09 |
|
fletcher posted:Looking for a way to generate some charts in Java and output to an image. JFreeChart looks pretty sweet, anything else I should check out before diving in?
|
# ? Feb 12, 2010 23:34 |
Parantumaton posted:Is pure image a necessity or are you doing a Web UI? Just need a static image for this one. Already using Open Flash Chart for the web stuff. necrobobsledder posted:It doesn't actually fit your requirements, but if it has anything to do with showing a chart on a web page, you should probably look at Google Charts. The caveat is that it does require the user have some access to the Internet, so it breaks if they're in, say, a closed off datacenter. That's what I used for the proof of concept. Google Charts are pretty neat, but it seems a bit limited in what you can do. Plus passing everything into the URL is a bit of a pain. Fly posted:We've been using http://jcharts.sourceforge.net/ for nearly a decade. It seems to work quite well. I saw that one but I wasn't really impressed with their samples. They look so...Excel 97. I've been playing around some more with JFreeChart. The amount of customization you can do seems to be very thorough. I think this might be the right engine. JFreeChart + data URI scheme = fletcher fucked around with this message at 00:04 on Feb 13, 2010 |
|
# ? Feb 13, 2010 00:01 |
|
fletcher posted:JFreeChart + data URI scheme = This is so you don't have to save the image to a web-accessible folder? You just send the contents as base64 and the browser renders it? Neato. Guess the downside is you have to generate the image every time, but I suppose that's fine if it changes often enough.
|
# ? Feb 13, 2010 00:28 |
|
fletcher posted:I saw that one but I wasn't really impressed with their samples. They look so...Excel 97.
|
# ? Feb 13, 2010 01:10 |
|
1337JiveTurkey posted:Swing is MVC-oriented, *snip* That can be made as simple or as complex as you like. Thanks for your advice, although some of that went way over my head :P This is my first time actually doing a proper user interface for my program. I'm still not quite sure how to do it. I was thinking of trying to use reflection or having a static getInstance() method. Do you know of any material I can read so I know what I'm doing? Cheers
|
# ? Feb 13, 2010 14:45 |
|
amr posted:Thanks for your advice, although some of that went way over my head :P This is my first time actually doing a proper user interface for my program. I'm still not quite sure how to do it. I was thinking of trying to use reflection or having a static getInstance() method. Do you know of any material I can read so I know what I'm doing? Cheers These two articles give a 10,000 foot overview of Swing and MVC: http://en.wikipedia.org/wiki/Swing_(Java) http://en.wikipedia.org/wiki/Model%96view%96controller Here's the standard tutorial which covers how to use Swing in depth: http://java.sun.com/docs/books/tutorial/uiswing/ To answer your question, it really depends on what your requirements are. For the one-off utilities that I've worked on, just slapping a getPanel() method on the node itself is often perfectly adequate even if it tightly couples some aspects of the program. For the flagship application I work on, it's a full-fledged subsystem with dozens of pluggable editors available for various combinations of nodes along with stuff like dynamic per-seat licensing. If I were to remove the huge amount of legacy cruft on it and pare it down to its core, that'd be basically the controller for the right hand panel asking all of the editors "can you edit this set of nodes?" and then adding a tab for each one that returns true. It works well with plugins and is pretty much instantaneous even with well over 100 different possible tabs since they're just looking at the number of nodes as well as their class.
|
# ? Feb 13, 2010 22:21 |
|
Is there a way to write a for loop that will make create new arraylist with the number fed into? I'm trying something like this:code:
|
# ? Feb 14, 2010 08:58 |
|
If you mean literally creating variables named al1, al2, etc, then nothing will do that other than declaring them yourself. If you need a variable number of ArrayList, you can use an array of ArrayList or an ArrayList of ArrayList. What do you need it for exactly?
|
# ? Feb 14, 2010 09:41 |
|
The way you're thinking about it, you'd create them but wouldn't be able to use them (you wouldn't magically be able to utilize al1, al2, etc). You have to put them somewhere. If the number of lists you want to create is variable, use an ArrayList instead of an array (like Psychorider suggests):code:
|
# ? Feb 14, 2010 11:05 |
|
I thought I was using Arraylist. The idea is I want to make a loop where I feed in a number and it spits out the number of arraylist for me. The program I'm working on is supposed to let someone enter in a bunch of names and specify a number of groups. Then the program is supposed to randomly take the names from the big list and stick them evenly into the number of list the user specifies. The idea is this program will be used in a situation where a teacher needs to split up everyone in class into even random groups. So far my line of thinking was to stick all the names into an arraylist and use collections.shuffle to randomize the big list of arrays. Then I wanted to make a for loop to make the number of arraylist the user specifies. Then make some kind of loop that just goes through my big arraylist and copies, or moves the names into the newly created list.
|
# ? Feb 14, 2010 20:44 |
|
|
# ? May 11, 2024 19:46 |
Coredump posted:I thought I was using Arraylist. The idea is I want to make a loop where I feed in a number and it spits out the number of arraylist for me. The program I'm working on is supposed to let someone enter in a bunch of names and specify a number of groups. Then the program is supposed to randomly take the names from the big list and stick them evenly into the number of list the user specifies. The idea is this program will be used in a situation where a teacher needs to split up everyone in class into even random groups. Why do you need more than 1 ArrayList for this? Load all the names in a single ArrayList. Use Collections.shuffle to randomize the order. Then just loop through it and after x names, increase the group #.
|
|
# ? Feb 15, 2010 07:40 |