|
TRex EaterofCars posted:I'm curious what that client's excuse for sticking with Java 1.3 is. Did they use some Sun internal API that got removed? We only guarantee certain versions of our software against certain JVMs, and nobody wants to do the full testing process against 1.4.2 even though in principle it shouldn't break anything. Moving them up to a newer version would be tough since they've got lots of bugfixes by the custom development team (my group) which should have been backports by the core development team. Since there have been a huge number of bugfixes and tweaks in the years between releases, there's a lot of risk that the two sets of bugfixes would be incompatible. Since there's a major release that will break compatibility with most of our older code coming around the corner next week, the hope is that we can leapfrog the previous versions and go straight to Java 1.5. It's an improvement at least.
|
# ? Mar 22, 2008 19:48 |
|
|
# ? Mar 29, 2024 09:51 |
|
Edit2: I've ran in to this and have given up for the night. code:
Here's the full code to this if it helps you help me: http://www.undergallows.com/Employee.java http://www.undergallows.com/Company.java -- end of edit -- the rest is old stuff that I figured out Hey guys. So I'm working on a java homework project and I've come to a stop because I can't quite figure something out. Why does this work (wage is set correctly) code:
code:
Edit: A little more thought and I solved my problem. I wasn't calling the computeWage method anywhere vv I'm a terrible terrible programmer Foodchain fucked around with this message at 07:00 on Mar 24, 2008 |
# ? Mar 24, 2008 00:55 |
|
How do I pass objects to a method in another class so that when I manipulate the values in the method the original object isn't modified? My example code would be far too long to post but it's basically something like: ObjectA A = new ObjectA(blah, blah blah); ObjectB B = new ObjectB(); int crazyCalculations = B.doSomeCalculationsWithA(A); Is there a quick way to make it so the original A won't be changed by B's method? Hopefully some sort of way that won't make me rewrite all my methods completely but simply just kinda add a keyword or something..
|
# ? Mar 25, 2008 02:43 |
|
X.clone() creates a copy of the object, and you can pass it to your destructive methods.
|
# ? Mar 25, 2008 02:51 |
|
I'm typing 'objectsName.' in my IDE (eclipse) and when the list of methods comes up none of them are clone(). The object is a class I defined myself, would I need it to implement something for .clone() to work? Or alter my class in someway?
|
# ? Mar 25, 2008 02:59 |
|
FearIt posted:I'm typing 'objectsName.' in my IDE (eclipse) and when the list of methods comes up none of them are clone(). The object is a class I defined myself, would I need it to implement something for .clone() to work? Or alter my class in someway? clone() is protected in Object, you need to open it up yourself in the class you want to clone.
|
# ? Mar 25, 2008 03:25 |
|
FearIt posted:I'm typing 'objectsName.' in my IDE (eclipse) and when the list of methods comes up none of them are clone(). The object is a class I defined myself, would I need it to implement something for .clone() to work? Or alter my class in someway? You want to implement the java.lang.Cloneable interface. That's enough to clone() an object without any work on your part. Many people dislike it because they feel that it allows you to gloss over the implications of clone() with regards to how your objects behave. In particular a shallow copy of the fields might not be what you wanted. There are a couple of alternatives which work: Creating a constructor which takes another instance of the object (or even an implemented interface) offers you the chance to make it a deep copy if you want to as well as share any immutable data. Immutable objects are also a possible alternative. If you're not constantly modifying a class of objects, you can get around all of that by just creating a new object for every change. Immutable objects work well with each other because any two objects can share a third object without needing to worry if the third object will change underneath them. This reduces memory usage requirements and makes it easier to turn other objects immutable if all of their fields are immutable.
|
# ? Mar 25, 2008 03:44 |
|
I like this constructor idea, it seems to be the neatest codewise and would require the least amount of revision of my broken code. In the constructor how would I go about creating a copy if everything is passed by reference still? Is it more complicated if my class serves as a ArrayList container for sub classes?
|
# ? Mar 25, 2008 03:57 |
|
FearIt posted:Is it more complicated if my class serves as a ArrayList container for sub classes? Probably; as you'll need to manually copy any data you require in the copy-contructor. If you're not concerned with performance you could use the apache commons SerializationUtils; as mentioned in the javadoc, all objects you want cloned must implement Serializable (which ArrayList implements already). vvv I agree 100%, I was considering adding a disclaimer to that effect. vvv the onion wizard fucked around with this message at 22:51 on Mar 25, 2008 |
# ? Mar 25, 2008 10:28 |
|
triplekungfu posted:If you're not concerned with performance you could use the apache commons SerializationUtils; as mentioned in the javadoc, all objects you want cloned must implement Serializable (which ArrayList implements already). Use it if you aren't concerned about good programming or sanity either. This seems like a horrible abuse of Serialization, which is supposed be about passing objects across a network. ArrayList also has a copy-constructor so if the data is immutable its very easy, otherwise use foreach loops. Manually copying data from one instance to another is not going to be that bad. There is an problem with marker interfaces (interfaces that don't actually require methods, including Cloneable and Serializable) in that you can't get rid of them in subclasses. 1337JiveTurkey posted:Immutable objects are also a possible alternative. If you're not constantly modifying a class of objects, you can get around all of that by just creating a new object for every change. Immutable objects work well with each other because any two objects can share a third object without needing to worry if the third object will change underneath them. This reduces memory usage requirements and makes it easier to turn other objects immutable if all of their fields are immutable. Immutable objects definitely nice for many things, but they come at a price. Strings, for example are immutable and the JVM does all sorts of optimization with them. But you'll also notice that there are special helper classes, StringBuilder and StringBuffer, just to create new Strings. In general, every time you change an immutable field you have to create a new object. Brain Candy fucked around with this message at 12:05 on Mar 25, 2008 |
# ? Mar 25, 2008 12:02 |
|
Brain Candy posted:Immutable objects definitely nice for many things, but they come at a price. Strings, for example are immutable and the JVM does all sorts of optimization with them. But you'll also notice that there are special helper classes, StringBuilder and StringBuffer, just to create new Strings. In general, every time you change an immutable field you have to create a new object.
|
# ? Mar 25, 2008 14:20 |
|
What is the best way to go about parsing XML in Java? I've been going about rewriting a project I have written, and it uses the org.w3c.dom.* classes to do so. This was mainly because I found information on it, but with all things Java it seems like there is a lot of outdated information out there. Basically, whats the best API for doing this, since any way I can simplify the code for this project would be extremely helpful.
|
# ? Mar 26, 2008 14:16 |
|
It entirely depends on what you want to do, and what your requirements are. Java has support for pretty much every method of parsing XML out there. DOM allows you to traverse and manipulate an XML document as an object representing its structure. SAX and StAX are stream parsers which scale well but essentially mean you have to maintain any state that you need yourself. StAX is a more modern "pull" parser which is a lot easier to use. JAXB allows you to bind structured XML documents to and from corresponding basic "bean" objects automatically. XPath allows you to query a loaded XML document for a given "path" allowing you to quickly query parts of the document.
|
# ? Mar 26, 2008 14:56 |
|
zootm posted:It entirely depends on what you want to do, and what your requirements are. Java has support for pretty much every method of parsing XML out there. Thanks for the information. This really helps me out, since I have been having difficulties locating the information I needed. It looks like I will be sticking with DOM, since my documents will never be excessively large and I am going to be parsing the XML generated from a program that makes a simple task extremely difficult due to it creating two separate nodes that contain slightly overlapping information by using reference IDs to identify the correlation.
|
# ? Mar 26, 2008 15:00 |
|
If you are just rewriting the output of a program from xml to xml, there are other options like xpath+xsl. Although xsl is pretty useful it can be quite awkward being declarative.
|
# ? Mar 26, 2008 16:38 |
|
I'm horribly confused with Calendar objects in java. At the minute I'm parsing a file off the internet which has a couple of fields like: "2/6/2008","4:00pm" to represent times. I think pick these out into a set of fields, year, month, day, hour and minutes with a parser. I get a new instance of Calendar. (calendar = calendar.getCalendar()); clear it (calendar.clear()) and set it calendar.set(year, month, day, hour, minutes); However, when I attempt to get the millisecond value, it appears to be wrong by about a month. To check I used the calendar.toString(); method, and got this: java.util.GregorianCalendar[time=1209221820000,areFieldsSet=true,areAllFieldsSet=false, lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/London",offset=0,dstSavings=3600000, useDaylight=true,transitions=242,lastRule=java.util.SimpleTimeZone[id=Europe/London,offset=0 ,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]],firstDayOfWeek=1,minimalDaysInFirstWeek=1, ERA=?,YEAR=2008,MONTH=3,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=26,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=?,HOUR=?,HOUR_OF_DAY=15,MINUTE=57,SECOND=?,MILLISECOND=?,ZONE_OFFSET=?,DST_OFFSET=?] 1209221820000 as a millisecond time is Sat, 26 Apr 2008 14:57:00 GMT, but the toString method also gives the correct time, the 26th of March 2008 at 15:57 GMT. I'm sure I can solve the hour (BST or DST or something) but the entire month off is stumping me. Any have any ideas?
|
# ? Mar 27, 2008 01:42 |
|
January is month zero, so you'll need to subtract one from the months before setting the calendar.
|
# ? Mar 27, 2008 01:55 |
|
So I have a minor test tomorrow that require me to write a memorised piece of code in 25 minutes, which I'm finishing now. How ever I cannot for the life of me remember how to get my dam scanner class working. NB programming is not my strong point, which leads me to missing out the most simple things... Code; code:
code:
|
# ? Mar 27, 2008 09:35 |
|
tef posted:If you are just rewriting the output of a program from xml to xml, there are other options like xpath+xsl. I'm not sure, the way this works is fairly obtuse, such as code:
|
# ? Mar 27, 2008 12:50 |
|
10011 posted:January is month zero, so you'll need to subtract one from the months before setting the calendar. :facepalm: I've spent far too long looking at this, thank you!
|
# ? Mar 27, 2008 13:08 |
|
Anphear posted:The problem that I'm currently having is the scanner class isn't 'working right' and that my array remains empty. With the toString method simply printing [] and if I remove the isEmpty() method I get a NaN return. First, you're only ever reading in one number. To read in more than one number you'll need to loop on the input. Something like this: code:
Anphear posted:
Edit: I'm going to bed, but I wrote this while looking at Scanner; it might help, or it may just confuse matters further. the onion wizard fucked around with this message at 14:44 on Mar 27, 2008 |
# ? Mar 27, 2008 14:26 |
|
CRIP EATIN BREAD posted:I'm not sure, the way this works is fairly obtuse, such as What is it meant to look like in the output? If you can paste them into a paste bin I can either knock up an xsl attempt or tell you it's impossible.
|
# ? Mar 27, 2008 15:22 |
|
triplekungfu posted:
Thanks Triple, With the while loop and a pastbin code I got mine working. Also when I visually compared, my getAv and add methods they were pretty much the same.
|
# ? Mar 27, 2008 20:45 |
|
I'm working on my first Java GUI application with SWT right now, so please excuse the presumably stupid questions. 1) I need to create dialogs from a thread and handle the return values. I think I can use Display.getDefault().syncExec(new Runnable() {...}); for that, but how would I get the dialog's return value from the Runnable? 2) Are there premade functions for displaying dialogs and message boxes or do I have to write them myself? 3) Would users just need the JRE to run my program or does SWT require additional software to be installed?
|
# ? Mar 30, 2008 16:06 |
|
2) The JOptionPane class should be what you want. [link] 3) The users will just need the JRE to run your program. SWT does not require additional software to be installed.
|
# ? Mar 30, 2008 16:48 |
|
Thanks, but I thought Swing and SWT were different things. Can I actually use Swing classes together with SWT?
|
# ? Mar 30, 2008 16:56 |
|
Fehler posted:Thanks, but I thought Swing and SWT were different things. Can I actually use Swing classes together with SWT? As regards the SWT-and-extra-software thing, SWT does require extra stuff to be bundled per-platform since it has native components. Swing does not because it comes with the JRE.
|
# ? Mar 30, 2008 22:43 |
|
Aw crumbs, sorry abut it Fehler, I shouldn't have skimmed your post. zootm is correct.
|
# ? Mar 30, 2008 22:44 |
|
It seems like the whole bundling of native software for SWT would be a bit annoying, so do you think I should just move to Swing? It's not like I put much thought into what to use when I started... Are there any good Swing tutorials out there that explain the basics for somebody who knows nothing about Java GUIs? Also, is it correct that Swing is the one with that ugly blue-silverish GUI? Any way around that?
|
# ? Mar 30, 2008 22:58 |
|
Fehler posted:It seems like the whole bundling of native software for SWT would be a bit annoying, so do you think I should just move to Swing? It's not like I put much thought into what to use when I started... Fehler posted:Are there any good Swing tutorials out there that explain the basics for somebody who knows nothing about Java GUIs? Fehler posted:Also, is it correct that Swing is the one with that ugly blue-silverish GUI? Any way around that?
|
# ? Mar 30, 2008 23:25 |
|
Fehler posted:Also, is it correct that Swing is the one with that ugly blue-silverish GUI? Any way around that? Edit: beaten
|
# ? Mar 30, 2008 23:26 |
|
The scenario: MyApp (console application) would like to run another program (SomeProgram, but this can really be any program which works with stdin and cmd-line args) in a new console window. My current platform is Windows XP and java version "1.6.0_03". MyApp uses Runtime.getRuntime().exec to launch the other program. Assuming the other program is a java program SomeProgram, I'd want to execute the command "cmd /C java SomeProgram arg1 arg2 arg3", send some stdin data, and this works great with my current code. To launch the other program in a new console window, I'd want to execute the command "cmd /C start java SomeProgram", note the 'start'. You can try this yourself by opening a console and typing "cmd /C start echo hi there" or "cmd /C start pause". The trouble is, when using cmd's "start", the stdin I send never makes it to the launched program. Save the following to MyApp.java code:
code:
SomeProgram could really be any program that deals with stdin. I happen to be launching TCL scripts, so my command looks more like "cmd /C start tclsh SomeScript.tcl arg1 arg2 arg3". Any other comments would be appreciated, for example I'm not sure if I need to be sending stdin like I am, considering it'll always be string data. Edit: What I'm suspecting is that "start" is cockblocking the program I wish to execute out of the stdin I want to pass it. There's no way to pass the stdin through start? epswing fucked around with this message at 15:41 on Apr 2, 2008 |
# ? Apr 2, 2008 15:25 |
|
"start" ignores input. Your Java code is working fine, but start spawns and starts a new console window for you and that's all it does. What is it you're trying to do? There's bound to be a better way to do this?
|
# ? Apr 2, 2008 16:03 |
|
zootm posted:"start" ignores input. Your Java code is working fine, but start spawns and starts a new console window for you and that's all it does. In short (really short), MyApp is a server which schedules and launches scripts. MyApp, among other places, logs to the console, so it would be nice to pop up a new console window to allow visual monitoring of currently-executing scripts without polluting the main console window. One solution would be to launch a JFrame with the process and dump stdout/stderr to a textarea as it rolls out. I didn't want to use Swing in this piece of my puzzle, but it would probably work well, now that I think about it. I'm betting I could make the JFrame look pretty close to a real console too...
|
# ? Apr 2, 2008 16:14 |
|
That would be a better idea, yeah. If you could invoke something like tail -f (I realise that's not a Windows program) it'd also follow the output of a log file. If you're just wanting to catch logging, however, use a standard logging toolkit like log4j or java.util.logging or Commons Logging or whatever and write a log "target" for that which just outputs the logging information to a window or whatever you like. There's no good reason not to use "proper" logging and doing this right will give you a lot more freedom if this is important to you. Popping up an "echo" window natively doesn't seem like a good solution. zootm fucked around with this message at 17:45 on Apr 2, 2008 |
# ? Apr 2, 2008 17:43 |
|
zootm posted:If you're just wanting to catch logging, however, use a standard logging toolkit like log4j or java.util.logging or Commons Logging or whatever and... Yep, I'm using log4j extensively, this is just to present the user with some visual feedback that what MyApp is running is actually running.
|
# ? Apr 2, 2008 20:33 |
|
epswing posted:Yep, I'm using log4j extensively, this is just to present the user with some visual feedback that what MyApp is running is actually running.
|
# ? Apr 2, 2008 22:02 |
|
What do you mean by "Just capture the logging information directly"? I'm spawning a process, how else do you propose I capture it's stdout/err?
|
# ? Apr 3, 2008 04:14 |
|
epswing posted:What do you mean by "Just capture the logging information directly"? I'm spawning a process, how else do you propose I capture it's stdout/err? Ah, I had thought you were running it in the same JVM, presumably you've a reason for not doing so. Just capture in and out, yeah.
|
# ? Apr 3, 2008 07:34 |
|
|
# ? Mar 29, 2024 09:51 |
|
Ok, let's see if I can actually phrase this question... I have 3 comboboxes, each of them with the same options, let's say they're "name", "surname", "address", "age", "country". Now, I need those 3 boxes to filter each other out. For example, if on the first combo box I choose "name", the second and third should not display the "name" option, and so on. Any ideas? Thanks.
|
# ? Apr 7, 2008 15:26 |