Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Hidden Under a Hat
May 21, 2003

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?

Adbot
ADBOT LOVES YOU

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
code:
import java.sql.*;

try {
	throw new SQLException("Oh noes my database");
}
catch(Exception e) {
	e.printStackTrace();
}
There's an easy way to find out. Try it.

Hidden Under a Hat
May 21, 2003
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.

HFX
Nov 29, 2004

Blacknose posted:

You could just catch a generic Exception.

Best to catch Throwable. Exception will not catch Errors (Out of memory, etc).

Blacknose
Jul 28, 2006

Meet frustration face to face
A point of view creates more waves
So lose some sleep and say you tried
You're absolutely right, in this case catching Throwable would be the correct thing to do.

narbsy
Jun 2, 2007

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:
-XX:+HeapDumpOnOutOfMemoryError
will probably be useful.

Hidden Under a Hat
May 21, 2003

narbsy posted:

If it does end up being OOM, the flag
code:
-XX:+HeapDumpOnOutOfMemoryError
will probably be useful.

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.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
java -XX:+HeapDumpOnOutOfMemoryError YourProgram
I think. I generally launch through Eclipse, which makes options a bit easier to set.

Luminous
May 19, 2004

Girls
Games
Gains

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.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

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.

Chairman Steve
Mar 9, 2007
Whiter than sour cream
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! ]

Jam2
Jan 15, 2008

With Energy For Mayhem
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?

No Safe Word
Feb 26, 2005

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 question, if anything at all, should I ask him? Is there anything you guys want to know about Java or Sun?

"What on god's green earth were you guys thinking when you wrote the Calendar class?"

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
"why did you let a giant committee of morons create the CORBA package"

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
Why is every single Swing component designed in the most obtuse way possible?

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

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

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
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?

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Internet Janitor posted:

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?

So you can send them over the wire and have a truly networked application! :pseudo:

crazyfish
Sep 19, 2002

Why does Java not have unsigned types?

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

crazyfish posted:

Why does Java not have unsigned types?
"too confusing for programmers"

also it has one: char

Paolomania
Apr 26, 2006

crazyfish posted:

Why does Java not have unsigned types?

Java has had byte and Byte since 1.1 (1997)

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Paolomania: both byte and its wrapper type are signed, dude. AV is correct, char is the only unsigned primitive.

Paolomania
Apr 26, 2006

Well drat.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Incidentally this is part of why InputStream.read() returns an int, even though it reads a 'byte' at a time.

tripwire
Nov 19, 2004

        ghost flow
What a gross kludgy language :(

Paolomania
Apr 26, 2006

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

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

quote:

getLength

public int getLength()

    Returns the length of the bytes. XXX need to clean this up
top quality docs right here

e:

quote:

public int indexOf(char c,
                   int starting)


Returns the first instance of the given character in this ByteChunk starting at the specified byte. If the character is not found, -1 is returned.
NOTE: This only works for characters in the range 0-127.
why even add this if you aren't going to bother to properly implement it

Malloc Voidstar fucked around with this message at 06:56 on Jul 20, 2011

Max Facetime
Apr 18, 2009

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

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
why doesn't it just return a short :(

Max Facetime
Apr 18, 2009

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.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

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?

1337JiveTurkey
Feb 17, 2005

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.

notMordecai
Mar 4, 2007

Gay Boy Suicide Pact?
Sucking Dick For Satan??

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. :(

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

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?

epswing
Nov 4, 2003

Soiled Meat

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 question, if anything at all, should I ask him? Is there anything you guys want to know about Java or Sun?

So what did you ask?

1337JiveTurkey
Feb 17, 2005

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.

But there's no requirement that a conforming implementation actually do this, is there?

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.

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.
I'm trying to write a class of objects that has ArrayLists as fields. It isn't going so well.

code:
import java.util.ArrayList;
public class GradeList{
	private ArrayList<double> tests;
}
When I try to compile this, it gives an error on line 3: Unexpected Type. What's the deal?

lamentable dustman
Apr 13, 2007

ðŸÂ†ðŸÂ†ðŸÂ†

Newf posted:

I'm trying to write a class of objects that has ArrayLists as fields. It isn't going so well.

code:
import java.util.ArrayList;
public class GradeList{
	private ArrayList<double> tests;
}
When I try to compile this, it gives an error on line 3: Unexpected Type. What's the deal?

Can't have a primitive type as the generic. Use ArrayList<Double>

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.
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 ...?

Adbot
ADBOT LOVES YOU

brosmike
Jun 26, 2009
"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:
ArrayList<Integer> myIntList = new ArrayList<Integer>();
myIntList.add(new Integer(1)); // This works but it looks unpleasant
myIntList.add(2); // this works because of auto-boxing - behind the scenes, Java basically does the same thing as the previous line

Integer myBoxedInt = myIntList.get(0); // This works like you'd expect, but usually you don't really want to deal with an Integer yourself if you don't have to
int myAutoUnboxedInt = myIntList.get(1); // This is probably what you actually want in most cases

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply