|
Blacknose posted:You could just catch a generic Exception. Would printing the stack trace on a generic exception still tell me the specific exception/error that occurred?
|
# ? Jul 15, 2011 13:30 |
|
|
# ? May 26, 2024 05:04 |
|
code:
|
# ? Jul 15, 2011 13:44 |
|
Anyway, I added a catch statement for a generic exception, and then added code which basically makes a TextArea in my program into the Java console. I got the code here: http://stackoverflow.com/questions/342990/create-java-console-inside-the-panel I just tested it and it worked great. Hopefully this will at least give me some insight into why my program is locking up.
|
# ? Jul 15, 2011 16:31 |
|
Blacknose posted:You could just catch a generic Exception. Best to catch Throwable. Exception will not catch Errors (Out of memory, etc).
|
# ? Jul 15, 2011 17:07 |
|
You're absolutely right, in this case catching Throwable would be the correct thing to do.
|
# ? Jul 15, 2011 17:12 |
|
HFX posted:Best to catch Throwable. Exception will not catch Errors (Out of memory, etc). If it does end up being OOM, the flag code:
|
# ? Jul 16, 2011 15:00 |
|
narbsy posted:If it does end up being OOM, the flag Can you go into a little more detail about this and how to use it? I think the issue with my program locking up may be due to out of memory but I'm not sure. I'm using JFreeChart and have several graphs worth of data plotted every 1-5 minutes for several days.
|
# ? Jul 16, 2011 16:10 |
|
java -XX:+HeapDumpOnOutOfMemoryError YourProgram I think. I generally launch through Eclipse, which makes options a bit easier to set.
|
# ? Jul 16, 2011 16:56 |
|
Hidden Under a Hat posted:Can you go into a little more detail about this and how to use it? I think the issue with my program locking up may be due to out of memory but I'm not sure. I'm using JFreeChart and have several graphs worth of data plotted every 1-5 minutes for several days. You can use the heapdump with something like http://www.eclipse.org/mat/ to see what your application has been up to and then beat it over its head until it behaves like you want.
|
# ? Jul 16, 2011 18:42 |
|
Hidden Under a Hat posted:Can you go into a little more detail about this and how to use it? I think the issue with my program locking up may be due to out of memory but I'm not sure. I'm using JFreeChart and have several graphs worth of data plotted every 1-5 minutes for several days. That option causes the JVM to dump its heap to disk when an OutOfMemoryError is thrown. Any objects present in the heap at the time can then be viewed by a heap analysis tool. I personally like Netbean's build in heap analyzer, but there are quite a few of them out there.
|
# ? Jul 16, 2011 19:18 |
|
If you use Eclipse, you can use Eclipse Memory Analyzer: http://www.eclipse.org/mat/ [ edit: hey, what's that two posts above mine? Why, look, it's the same link! ]
|
# ? Jul 17, 2011 23:21 |
|
Harvard CTO, Jim Waldo is coming in to speak to my intro java class tomorrow. He was on the team that developed the Java programming language at Sun back in the day. What question, if anything at all, should I ask him? Is there anything you guys want to know about Java or Sun?
|
# ? Jul 19, 2011 03:56 |
|
Jam2 posted:Harvard CTO, Jim Waldo is coming in to speak to my intro java class tomorrow. He was on the team that developed the Java programming language at Sun back in the day. "What on god's green earth were you guys thinking when you wrote the Calendar class?"
|
# ? Jul 19, 2011 04:13 |
|
"why did you let a giant committee of morons create the CORBA package"
|
# ? Jul 19, 2011 04:15 |
|
Why is every single Swing component designed in the most obtuse way possible?
|
# ? Jul 19, 2011 04:18 |
|
Aleksei Vasiliev posted:"why did you let a giant committee of morons create the CORBA package" how would you convince any competent person to write a corba package
|
# ? Jul 19, 2011 05:04 |
|
What feature does most he wish had been left out of the Java language? Optional bitchy question: Why the gently caress do Swing and AWT classes implement Serializable?
|
# ? Jul 19, 2011 05:20 |
|
Internet Janitor posted:What feature does most he wish had been left out of the Java language? So you can send them over the wire and have a truly networked application!
|
# ? Jul 19, 2011 15:08 |
|
Why does Java not have unsigned types?
|
# ? Jul 19, 2011 23:56 |
|
crazyfish posted:Why does Java not have unsigned types? also it has one: char
|
# ? Jul 20, 2011 00:36 |
|
crazyfish posted:Why does Java not have unsigned types? Java has had byte and Byte since 1.1 (1997)
|
# ? Jul 20, 2011 03:30 |
|
Paolomania: both byte and its wrapper type are signed, dude. AV is correct, char is the only unsigned primitive.
|
# ? Jul 20, 2011 03:36 |
|
Well drat.
|
# ? Jul 20, 2011 03:44 |
|
Incidentally this is part of why InputStream.read() returns an int, even though it reads a 'byte' at a time.
|
# ? Jul 20, 2011 03:59 |
|
What a gross kludgy language
|
# ? Jul 20, 2011 04:28 |
|
Internet Janitor posted:Incidentally this is part of why InputStream.read() returns an int, even though it reads a 'byte' at a time. My brain is muddled from looking at too much Tomcat code. Before nio was around they basically implemented a bunch of nio-like classes backed by byte arrays to optimize IO. I guess it works because they are not doing any ordering comparisons or arithmetic with those bytes before they are decoded into the proper character set. Paolomania fucked around with this message at 06:50 on Jul 20, 2011 |
# ? Jul 20, 2011 06:48 |
|
quote:getLength e: quote:public int indexOf(char c, Malloc Voidstar fucked around with this message at 06:56 on Jul 20, 2011 |
# ? Jul 20, 2011 06:54 |
|
Internet Janitor posted:Incidentally this is part of why InputStream.read() returns an int, even though it reads a 'byte' at a time. Let's not forget that InputStream.read() can return 257 different values, which can't fit in a byte. So, the options are: hasByte(),-128..127 hasByte(),0..255 -128..127,wasLastReadByteActuallyValid() 0..255,wasLastReadByteActuallyValid() null,-128..127 Integer.MIN_VALUE,-128..127 -1,0..255 The last option is the most elegant, because it avoids an extra fuction that might throw, boxing and unboxing and it gives out the bits in a format ready to be bit-shifted. Because let's be honest, when you read a byte, you rarely actually want a byte (signed or unsigned), you want 8 bits of data. Max Facetime fucked around with this message at 10:19 on Jul 20, 2011 |
# ? Jul 20, 2011 10:14 |
|
why doesn't it just return a short
|
# ? Jul 20, 2011 12:08 |
|
Aleksei Vasiliev posted:why doesn't it just return a short Java does a widening conversion to ints when operating on shorts and under the hood the JVM handles primitive values as ints anyway, so there's no advantage.
|
# ? Jul 20, 2011 14:38 |
|
I am in posted:Java does a widening conversion to ints when operating on shorts and under the hood the JVM handles primitive values as ints anyway, so there's no advantage. Is that actually the spec, or just an implementation detail?
|
# ? Jul 21, 2011 13:32 |
|
Jabor posted:Is that actually the spec, or just an implementation detail? Spec. The JVM integer math operations act on 32-bit numbers or 64-bit numbers. Stuff gets sign extended when pushed on the stack and truncated when popped IIRC.
|
# ? Jul 21, 2011 14:02 |
|
Man, I really hate Rational Software Architect. 7.0 was fine 7.5 was a sluggish mess 8.0 has that annoying "kind of the same but not" feel to it but breaks everything that worked in 7.0 so when you upgrade everything breaks. Woe is me.
|
# ? Jul 21, 2011 18:35 |
|
1337JiveTurkey posted:Spec. The JVM integer math operations act on 32-bit numbers or 64-bit numbers. Stuff gets sign extended when pushed on the stack and truncated when popped IIRC. Right, so the spec is that the result is the same as if the math was performed on a 32-bit sign-extended version. But there's no requirement that a conforming implementation actually do this, is there?
|
# ? Jul 22, 2011 00:05 |
|
Jam2 posted:Harvard CTO, Jim Waldo is coming in to speak to my intro java class tomorrow. He was on the team that developed the Java programming language at Sun back in the day. So what did you ask?
|
# ? Jul 22, 2011 01:11 |
|
Jabor posted:Right, so the spec is that the result is the same as if the math was performed on a 32-bit sign-extended version. Due to the rules of mathematics they act the same. Try it using 2 and 4 digit numbers and base 10 arithmetic rather than 8 bit or 32 bit numbers and you'll see that when you chop the first 2 digits off a 4 digit number it acts identically to the 2 digit number. Specs in general only define behavior, so as long as an implementation behaves identically, it's perfectly fine. You could write a stackless C implementation that uses garbage collected activation records instead and it'd be perfectly legal, if a bit perverse. Most RISC processors just have one add instruction since it acts identically for all widths both as 2's complement as well as unsigned so they have to implement it in that manner. An IA-32 processor could treat a push of a byte onto the stack as loading into one of the byte-sized registers but you wouldn't be able to tell the difference.
|
# ? Jul 22, 2011 02:24 |
|
I'm trying to write a class of objects that has ArrayLists as fields. It isn't going so well.code:
|
# ? Jul 22, 2011 03:10 |
|
Newf posted:I'm trying to write a class of objects that has ArrayLists as fields. It isn't going so well. Can't have a primitive type as the generic. Use ArrayList<Double>
|
# ? Jul 22, 2011 03:17 |
|
Well I've done that and it works, but I'm completely confused. Isn't the "thing" that you put in theses <> doodads the 'type' of object that the arraylist will store/retrieve? aren't 'double's a thing in java, while 'Double's aren't a thing? Anyway thanks If I wanted an ArrayList of integers, would it be ArrayList<Integer> or ...?
|
# ? Jul 22, 2011 03:23 |
|
|
# ? May 26, 2024 05:04 |
|
"double" and "int" are primitive types, and "Double" and "Integer" are classes which box those primitive types - an Integer object is just a wrapper around a single immutable int value. Why does Java have both of these? Because of stupid language semantics, type parameters for Generic classes like ArrayList have to be classes, not primitive data types. Integer and Double are classes, so you can use those; int and double aren't, so you can't. Since you generally want to actually use the normal primitive data types, not their boxed versions, modern versions of Java implement a feature called "auto-boxing", where you can basically use primitive values and boxed versions of them interchangeably when you're working with actual values and Java will convert between them as necessary. There's exceptions and caveats to this behavior, but basically, all you need to do is: code:
|
# ? Jul 22, 2011 03:32 |