java

How can I cause a child process to exit when the parent does?

I am launching a child process with ProcessBuilder, and need the child process to exit if the parent process does. Under normal circumstances, my code is stopping the child properly. However, if I cause the OS to kill the parent, the child will continue running. Is there any way to "tie" the child process to the parent, such that it'l...

Rename file onto another in java

I have a file I need to rename to that of an existing file. This is a copy, modify, replace original operation on an existing JAR file. I've got the first two steps done, I just need help with the replace original bit. What's the best way to rename the new version of the JAR to that of the old. The old JAR doesn't need preserving and I d...

How to make a noise on the PC speaker with Java

I want to alert the user in a Swing application of certain events with an old fashioned PC Speaker beep, since not on every PC there is a soundcard with an attached speaker. (At least on my work PC there is no speaker, with a reason. :-) How can I do this? UPDATE: java.awt.Toolkit.getDefaultToolkit().beep() seems usually to generate a s...

Is there a difference between BigDecimal("0") and BigDecimal.ZERO?

Either for comparisons or initialization of a new variable, does it make a difference which one of these you use? I know that BigDecimal.ZERO is a 1.5 feature, so that's a concern, but assuming I'm using 1.5 does it matter? Thanks. ...

Kill Derby DB Network Server on background

I'm looking for a good way to run a Apache Derby server in network mode. I'm using the NetworkServerControl to start the server and it's working great. I start the server like this: /** * starts the network server * @return true if sucessfull */ public boolean start() { try { // just to be sure that we don't start tw...

Rounding negative numbers in Java

According to Wikipedia when rounding a negative number, you round the absolute number. So by that reasoning, -3.5 would be rounded to -4. But when I use java.lang.Math.round(-3.5) returns -3. Can someone please explain this? ...

How do I approach debugging starting from a Java exception log entry?

I have been trying to parse Java exceptions that appear in a log for some code I'm working with. My question is, do you parse the exception trace from the top down, or the bottom up? It looks something like this: ERROR [main]</b> Nov/04 11:03:19,440 [localhost].[/BookmarksPortlet].[] - Exception sending context... org.springframework.be...

Free java 3d engine

Whats the best 3D game engine available for java? I am looking for something that has a good set visual development tools. I have checked out the list available on wikipedia: http://en.wikipedia.org/wiki/List_of_game_engines But I can't figure out the tool set provided by each engine and which free java 3d engine has the best toolset....

How to count open db connections ?

I'm developing a web app using Java servlet to access Mysql db, how can I get the number of connections to my DB that is currently open ? Edit : I tried "show processlist", it showed me : 2695159, but that's not right, I'm just developing this new project, I'm the only user, couldn't have that many processes running, what I want is the...

How do I make log4j clear a log at startup?

I want the log to roll over as long as the application is running, but I want the log to start fresh when the application is restarted. Updated: Based on erickson's feedback, my appender looks like this: <appender name="myRFA" class="org.apache.log4j.RollingFileAppender"> <param name="File" value="my-server.log"/> <param...

Java resource files

I'm writing a small GUI app that contains some "editor" functionality, and something that I'd like to let users open a few sample text files to test things out quickly. The easiest way of doing this would be to package a separate zip with the appropriate sample files, and have them open them manually; I'd like to make things a little mor...

Hibernate/JPA Annotations -- Unknown Entity

An application that has been working well for months has stopped picking up the JPA @Entity annotations that have been a part of it for months. As my integration tests run I see dozens of "org.hibernate.MappingException: Unknown entity: com.whatever.OrderSystem" type errors. It isn't clear to me what's gone wrong here. I have no hiber...

Which is faster for a small amount of information, java file i/o or derby?

I'm writing a small agent in java that will play a game against other agents. I want to keep a small amount of state (probably approx. 1kb at most) around between runs of the program so that I can try to tweak the performance of the agent based upon past successes. Essentially, I will be reading a small amount of data at the beginning of...

Java in Eclipse: Where do I put the images (on the filesystem) that I want to load into an ImageIcon

I know the image file needs to be where the getClass().getResource(filename) can find it, but I don't know where that is. I'm interested both in where to put the images on the filesystem itself, and how to go about using Eclipse's functionality to set up the resources. ...

How to decompress a gzipped data in a byte array?

I have a class which has a method that is receiving an object as a parameter. This method is invoked via RMI. public RMIClass extends Serializable { public RMIMethod(MyFile file){ // do stuff } } MyFile has a property called "body", which is a byte array. public final class MyFile implements Serializable { priv...

Updating from Jaxb 1 to Jaxb 2

I'm looking to update our project's jaxb version from 1 to 2. Has anyone tried doing this on their projects and are there any tips that anyone wanting to do this? I understand that each project is unique, I'm just looking for general tips. ...

What have you used Object.clone() for?

A colleague recently asked me how to deep-clone a Map and I realized that I probably have never used the clone() method- which worries me. What are the most common scenarios you have found where you need to clone an object? ...

Any lightweight templating solutions in Java with support for conditional formatting?

I'm using MessageFormat to format some addresses with a template like this: "{0}\n{1}\n{2}\n{3}, {4} {5}" where 0 = street 1 1 = street 2 2 = street 3 3 = city 4 = state 5 = zip Most of these fields are optional when captured. How do I avoid having an empty line when for instance, there is not street 3? I could use a template lik...

SQL Deletion Cascading Help (Specific Question)

I have two tables (renamed/refactored for illustrative purposes) with a Many-To-Many relationship in an HSQL database. I want everything to be wiped out when I delete from one side of a Many-to-Many relationship (without querying the table; this is performance critical) Here are my main tables: CREATE TABLE PERSON ( PERSON_ID INTE...

jsp servlet exception: bean not found within scope.

I'm getting this error: javax.servlet.ServletException: bean givingFormBean not found within scope on a page with this at the top. <jsp:useBean id="givingFormBean" scope="request" type="olc.onlinegiving.servlets.BuiltForm"/> The class exists in the classpath, it worked this morning, and I don't get what not found within scope means...