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
tef
May 30, 2004

-> some l-system crap ->
Cool, I didn't see those.

Adbot
ADBOT LOVES YOU

Chairman Steve
Mar 9, 2007
Whiter than sour cream
Yeah, Guava and Apache Commons are pretty useful. I like to use Guava when I get to use Java 6 (we frequently do Java 5 at work) because it uses generics, where as Commons does not, either by lack of maintenance or intentional support of Java 4.

zootm
Aug 8, 2006

We used to be better friends.

Chairman Steve posted:

Yeah, Guava and Apache Commons are pretty useful. I like to use Guava when I get to use Java 6 (we frequently do Java 5 at work) because it uses generics, where as Commons does not, either by lack of maintenance or intentional support of Java 4.
I think it's intentional backwards compatibility, although for the Collections part of Commons, a port does exist. I have less experience with the Google libraries but that which I do have makes me think it's the superior choice if it's available to you, though.

Kaltag
Jul 29, 2003

WHAT HOMIE? I know dis ain't be all of it. How much of dat sweet crude you be holdin' out on me?
I am only researching the feasibility of this idea.

I know that this is ridiculously low level stuff for Java and I'll probably get laughed out of here but has anyone here ever heard of using Java to bit-bang a SPI interface or interfaced with a USB to SPI adapter? Would it be possible to control single I/O pins in a serial port or other general I/O pin? Could Java supply an appropriate clock of ~48kHz?

From my research the best bet would be to use a C or assembly library wrapped in JNI to do the dirty stuff.

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

Kaltag posted:

I am only researching the feasibility of this idea.

I know that this is ridiculously low level stuff for Java and I'll probably get laughed out of here but has anyone here ever heard of using Java to bit-bang a SPI interface or interfaced with a USB to SPI adapter? Would it be possible to control single I/O pins in a serial port or other general I/O pin? Could Java supply an appropriate clock of ~48kHz?

From my research the best bet would be to use a C or assembly library wrapped in JNI to do the dirty stuff.

We did something like this recently, using RXTX (new version/info here). It uses JNI internally, but it's pretty easy for the programmer. We used it for both direct serial connections and serial/USB adapters, and it worked fine for both. We probably used an older version too, but I don't remember for sure.

I can't say it has exactly what you want, because it seems like you want something possibly even more low level.

Kilson fucked around with this message at 21:33 on Aug 30, 2010

Calef
Aug 21, 2007

I want to write a program that will allow users to "code" while running the program, perhaps in java, perhaps in a scripting language that I create (whatever language they end up using will have to be robust enough to allow all of the basic functionality of your everyday programming language, i.e. loops, data structures etc.).

Is there an easy way to implement this in java?

epswing
Nov 4, 2003

Soiled Meat
To clarify: you want to write a java program which will evaluate code (written in some language) which is intended to manipulate the already-running program?

Calef
Aug 21, 2007

Yes =D

baquerd
Jul 2, 2007

by FactsAreUseless

Calef posted:

Yes =D

One way to do this is to take the user's code, interpolate that with your program's code, save to file and compile, then run the new program sending in your current settings to load in some fashion, then terminating while the new program continues.

Another way is to write your own run time compiler and integrate.

Unless you're doing it for academic reasons, I don't see why though.

Shavnir
Apr 5, 2005

A MAN'S DREAM CAN NEVER DIE
First cardinal rule of Java : There's probably a library for that .

As for injecting the logic back into your code you'll want to look up dependency injection for a good start.

EDIT : I dug up some stuff from my undergrad. Please be kind, I haven't even thought about this for years so its pretty ugly

Shavnir fucked around with this message at 06:35 on Aug 31, 2010

ssergE
Sep 10, 2001

No longer a stupid baby. Now a stupid teenager.
Maybe something like http://java.sun.com/developer/technicalArticles/J2SE/Desktop/scripting/ or Groovy will work for you.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

Shavnir posted:

First cardinal rule of Java : There's probably a library for that .

It's worth noting that, despite appearances, this API is a thin wrapper that calls javac and leaves compiled .class files sitting around as if you'd called it from a shell.

fart factory
Sep 28, 2006

SHREK IS COOL
Is there a way to access system commands on a JFrame from another JFrame? I've currently got a method that is called when one frame is closed/the cancel button is pressed that I want to close both the current frame, and another associated frame. Right now the method is:

code:
  private void cancelRequest()
    {
    	owner.dispose();
    	dispose();
		
    }
This closes the frame fine, but although the owner frame is no longer displayed, the thread continues to run. I wanted to use System.exit(0) on the owner frame, but don't know if this is possible.

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

quote:

I want to write a program that will allow users to "code" while running the program, perhaps in java, perhaps in a scripting language that I create (whatever language they end up using will have to be robust enough to allow all of the basic functionality of your everyday programming language, i.e. loops, data structures etc.).

JSR-223

http://today.java.net/pub/a/today/2006/09/21/making-scripting-languages-jsr-223-aware.html

It is pretty trivial to make this go. There are many scripting languages available, Python, Ruby, Groovy, Javascript.

Calef
Aug 21, 2007

Awesome, thanks a bunch guys

I think JSR-223 is exactly what I need

Calef fucked around with this message at 15:26 on Aug 31, 2010

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Which profiler do you guys recommend for remote J2EE applications?

I'm really interested in viewing which queries are taking the longest to return when the system is under heavy load. I have a few stress tests setup that I'm going to run from like 10 machines and each one is going to simulate like 50 clients. I know it's not enough to kill the server, but I hope to see some interesting data.

I also need to be able to save the data that it generates to later review it.

Chairman Steve
Mar 9, 2007
Whiter than sour cream

fart factory posted:

This closes the frame fine, but although the owner frame is no longer displayed, the thread continues to run. I wanted to use System.exit(0) on the owner frame, but don't know if this is possible.

System.exit(0) is very, very rarely a workable solution. I try to avoid it whenever possible.

That said, would this:

http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JFrame.html#setDefaultCloseOperation(int)

...plus this:

http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JFrame.html#EXIT_ON_CLOSE

...do the trick?

Calef
Aug 21, 2007

I've been playing around with JSR233 and I have one quick questions.

I would like to be able to run a script and have it augment a variable in my main java class without having to do something like:

class main{

oldvariable = blah;

script = "oldvariable = oldvariable + foo;";

scriptengine.eval(script);

oldvariable = scriptengine.get(augmentedoldvariable);***

}

In other words, I want to tie in the ***'d line into the evaluation of the script somehow so that a user doesn't have to rely on methods I've created to alter variables not-in-the-user-scripted program.

I don't know if that made any sense. It wouldn't actually be difficult at all to write those methods, but I'd still like to know if it's possible.

Calef fucked around with this message at 06:25 on Sep 1, 2010

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
Have you looked into the SimpleBindings class?

You can bind variables from the running program into your scripts and pass them in.

http://download.oracle.com/javase/6/docs/api/javax/script/SimpleBindings.html

Lysandus
Jun 21, 2010

Shavnir posted:

First cardinal rule of Java : There's probably a library for that .


Unless you're writing Blackberry apps. Then you're hosed.

fart factory
Sep 28, 2006

SHREK IS COOL

Chairman Steve posted:

System.exit(0) is very, very rarely a workable solution. I try to avoid it whenever possible.

That said, would this:

http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JFrame.html#setDefaultCloseOperation(int)

...plus this:

http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JFrame.html#EXIT_ON_CLOSE

...do the trick?

Yeah, I was only intending to use it to try and kill the process, turns out I don't need to. Just set the parent window to hidden when the dialog was closed or cancelled. Thanks

Sweaty IT Nerd
Jul 13, 2007

1k pardons if this question has been answered to death.

Can anyone recommend to me a good, free pdf writing library?

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

The Sphinxster posted:

1k pardons if this question has been answered to death.

Can anyone recommend to me a good, free pdf writing library?

I use Flying Saucer. Works great, just make sure your HTML is perfect or it will throw a fit.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
I also use Flying Saucer (as a Grails plugin, but it's still Flying Saucer under the covers) and I will also recommend it.

I did have some issues with its ability to handle certain types of CSS but it's better than writing postscript.

epswing
Nov 4, 2003

Soiled Meat
Anyone recently been wondering what the hell happened to itext? It used to be great.

Fly
Nov 3, 2002

moral compass

epswing posted:

Anyone recently been wondering what the hell happened to itext? It used to be great.

Didn't Lowagie make the license burdensome? I won't be able to upgrade to the latest for work stuff.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
How do I get a proper mod operator in Java?
I had a piece of code that I think did it, but I saved it in one of my 200 random text files and lost it.

Proper being:

Python
>>> print -13 % 64
51

Java
System.out.println(-13 % 64);
-13

I want Python's mod.

Edit: Of course I find a page solving it right after I post.
This works:
code:
public int mod(int a, int b) {
	return ((a % b) + b) % b;
}

Malloc Voidstar fucked around with this message at 18:13 on Sep 6, 2010

shrughes
Oct 11, 2008

(call/cc call/cc)

Aleksei Vasiliev posted:

code:
public int mod(int a, int b) {
	return ((a % b) + b) % b;
}

That doesn't work if (a % b) + b overflows.

You can always cast to long and do (a + 0x100000000l * b) % b.

Chairman Steve
Mar 9, 2007
Whiter than sour cream
If you're worried about overflow, you might as well just accept two longs and return a long, unless you're worried about memory consumption.

Fly
Nov 3, 2002

moral compass

Chairman Steve posted:

If you're worried about overflow, you might as well just accept two longs and return a long, unless you're worried about memory consumption.
That would reintroduce the possible overflow condition.

Parantumaton
Jan 29, 2009


The OnLy ThInG
i LoVe MoRe
ThAn ChUgGiNg SeMeN
iS gEtTiNg PaId To Be A
sOcIaL MeDiA sHiLl
FoR mIcRoSoFt
AnD nOkIa

Fly posted:

That would reintroduce the possible overflow condition.

BigInteger, then? You can still overflow that, however your number will be ridiculously large at that point anyway.

crazyfish
Sep 19, 2002

Parantumaton posted:

BigInteger, then? You can still overflow that, however your number will be ridiculously large at that point anyway.

BigInteger never overflows. Not to mention that you can't use Java's % operator anyway, you would have to write a custom method or hope that BigInteger.mod() behaves the way you want.

quote:

Semantics of arithmetic operations exactly mimic those of Java's integer arithmetic operators, as defined in The Java Language Specification. For example, division by zero throws an ArithmeticException, and division of a negative by a positive yields a negative (or zero) remainder. All of the details in the Spec concerning overflow are ignored, as BigIntegers are made as large as necessary to accommodate the results of an operation.

http://download.oracle.com/javase/1.4.2/docs/api/java/math/BigInteger.html

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

Chairman Steve posted:

If you're worried about overflow
Thankfully I'm not; my dividend is small and my divisor is 64.

crazyfish posted:

BigInteger never overflows. Not to mention that you can't use Java's % operator anyway, you would have to write a custom method or hope that BigInteger.mod() behaves the way you want.
System.out.println(-13 % 64);
System.out.println(properMod(-13, 64));
System.out.println(modBig(-13, 64)); // Uses standard a.mod(b);

-13
51
51

Looks like BigInteger uses a real modulus, not Java's weird remainder thing.

Max Facetime
Apr 18, 2009

BigInteger has also a remainder method, which is defined in terms of the %-operator.

mister_gosh
May 24, 2002

I have a "Connection" class which connects to an application and then maintains information about the connection with getters and setters and other useful bits.

This connection class lives in a tomcat application. Each user that uses this needs to use the Connection class.

I initially set this up as a singleton class, but that meant only one connection could occur in the jvm.

I set it up then as a plain class but now the connections are getting trampled by eachother. The last user to connect is now the sole connection, essentially.

This is bad (software design on my part)!

What is the answer here? Is making this serializable the easy answer? Would I be required to store that connection data to a stream? Or is this a deeper issue or some other easy solution?

derdewey
Dec 3, 2004
I have a JTable which is bound to my EventTracker bean, essentially a wrapper around a list which I will use as append/clear only (i.e., a simple log). Problem is, when I add entries to the list and try to fire an event I don't see any changes. I'm using the NetBeans IDE.

The EventTracker bean is added to the view and instantiated as eventTracker1. From there, I right click on the table and choose 'Table Contents...'. Table model is bound to eventTracker1, binding expression is '${eventList}'. The columns are set up properly to operate on the entries in eventList.

code:
    // From inside EventTracker.java
    public static final String EVENT_LIST_PROPERTY = "eventList"; 
    public List getEventList() {
        System.out.println("Handing out eventList with size: " + Integer.toString(eventList.size()));
        return eventList;
    }
    
    public void setEventList(List incomingList) {
        List oldList = eventList;
        eventList = new ArrayList(incomingList);
        propertySupport.firePropertyChange(EVENT_LIST_PROPERTY, oldList, eventList);
    }
The method firePropertyChange seems to fit the spec (non-null values which don't equal eachother). So when my outside code operates on setEventList, it seems to fire off the event because then getEventList is called and the list size is going up as expected. It's just that the table isn't rendering. What can I do to make this work?

Chairman Steve
Mar 9, 2007
Whiter than sour cream

mister_gosh posted:

What is the answer here? Is making this serializable the easy answer? Would I be required to store that connection data to a stream? Or is this a deeper issue or some other easy solution?

Why not use connection pooling? You can potentially take a page from the JDBC API - they have a DataSource object which may (or may not) be used to represent a connection pool from which Connection[2] objects are either checked out or created (as needed). When a consumer invokes the close method on the Connection object, it's not physically closed - it's checked back into the connection pool, where it waits to either be checked out by another consumer or physically closed by the connection pool per whatever eviction policy it follows.

1. http://download.oracle.com/javase/6/docs/api/javax/sql/DataSource.html
2. http://download.oracle.com/javase/6/docs/api/java/sql/Connection.html

FrenchConnection
Aug 27, 2007

"I'm the hand up Mona Lisa's skirt. I'm a surprise, Kevin. They don't see me coming: that's what you're missing."
Why do people use arrays? This might sound stupid but it seems to me that ArrayLists are better in pretty much every way.

Fly
Nov 3, 2002

moral compass

Chinapwns posted:

Why do people use arrays? This might sound stupid but it seems to me that ArrayLists are better in pretty much every way.
Back when you were a kid, ArrayLists were always untyped, and that kind of sucked.

Also, arrays are still cheap, and if you're encapsulating them, and you don't need them to change, they're still a great way to hold data sometimes. Also, the Java language has a syntax for array literals, but not so for any of the collections, yet.

Adbot
ADBOT LOVES YOU

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

Fly posted:

Also, the Java language has a syntax for array literals, but not so for any of the collections, yet.

Arrays.asList() to the rescue!

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