java

How to handle OutOfMemoryError in Java?

I have to serialize around a million items and I get the following exception when I run my code: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOfRange(Unknown Source) at java.lang.String.<init>(Unknown Source) at java.io.BufferedReader.readLine(Unknown Source) at java.io.B...

Why do we need JavaFX though we have Swing?

Swing is good in many ways, then why do we need JavaFX? ...

How to diagnose an Invalid thread access SWTException?

We're customizing an Eclipse RCP based tool for a client. They have trouble loading it on one of their computers (it works on others) and have provided the following error log. !SESSION 2009-01-23 12:09:05.593 ----------------------------------------------- eclipse.buildId=unknown java.version=1.5.0_12 java.vendor=Sun Microsys...

Simplest way to expose a given method as a web service - result must be runnable in web container under Java 5

I am in a situation where I need to expose a Java method as a web service, and I need to choose the technology to do so and I am basically a bit bewildered. The requirements are: Must be runnable in an IBM Java 5. Must be deployable as a web application inside an embedded Jetty (currently version 6) Must be detachable from an IDE (has...

Reading from a socket not waiting for input?

I'm trying to do some Socket programming in Java, and I'm using the BufferedStreamReader.read(char[]) method. the java doc states: Reads characters into an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached. Only it's not blocking on input. can somone point ...

Best way to measure execution time in automated regression tests

I have some code that I want to measure the speed of while it runs continuously in automated regression tests. The purpose of this would be to alert me to changes made to the code which have had a negative impact on performance. In pseudo-code, I want something like this: cpuTimer.start runTest cpuTimer.stop diff = cpuTimer.getDuratio...

3rd party jars creating log files

So we ran into an interesting issue today. We have a JEE (J2EE) web app that uses a bunch of 3rd party jars. This includes Hibernate. We use the java logging api that comes with the SDK for logging purposes. Typically we are pretty thin on logging but we ran into this issue with one of our 3rd party jars using log4j to create it's own l...

Progress Dialog in Swing

How can I make a modal JDialog without buttons appear for the duration it takes a Runnable instance to complete and have that instance update a progress bar/message on that Dialog. Clearly spaghetti code might be this working, but I'm looking for a clean design if one exists. Thanks. ...

Why does Math.floor return a double?

I was just wondering...official javadoc says that it returns a double that is "equal to a mathematical integer", but then why shouldn't it return an int? ...

To use the Gears WorkerPool in GWT do I have to write the same code in Java and Javascript?

In order to use the WorkerPool (Javascript Threads) class and functionality in GWT/Gears, do I need to write my code in both Java and Javascript? Upon inspection of WorkerPool - Getting Started and the sample WorkerPool application in the GWT-Gears-1.1 download package it seems that I need to. It seems that the Java code is used to dem...

Use a .jar java library API in C#?

Hello, I'm an entry level programmer so please bear with me and be descriptive in your responses. I am trying to use a Java API given as a .jar file in my C# .net application. I don't know much Java, but this .jar file says "no main-class manifest attribute" when I try to run it so this means its a library? This Java API also comes w...

How do I disable the Cancel Button when using javax.swing.ProgressMonitor?

I'd like to make use of ProgressMonitor's functionality but I don't want to give the user the option of canceling the action. I know if I don't call isCanceled() then the button press has no effect, but I'd prefer not to have the user believe the program is unresponsive. How shall I go about doing this? ...

Best Practice: Initialize JUnit class fields in setUp() or at declaration?

Should I initialize class fields at declaration like this? public class SomeTest extends TestCase { private final List list = new ArrayList(); public void testPopulateList() { // Add stuff to the list // Assert the list contains what I expect } } Or in setUp() like this? public class SomeTest extends ...

Changing TODO in Eclipse

In a eclipse a "//TODO" marks an area in code as a task for later consideration. Is there a way to add other expressions that will do the same. For example if i want to use "//myprojectname". ...

Use Mockito to verify that nothing is called after a method

I'm using Mockito to write a unit test in Java, and I'd like to verify that a certain method is the last one called on an object. I'm doing something like this in the code under test: row.setSomething(value); row.setSomethingElse(anotherValue); row.editABunchMoreStuff(); row.saveToDatabase(); In my mock, I don't care about the order ...

Java multiply operation behavior

I wrote a method to convert a given number from days to milliseconds: private long expireTimeInMilliseconds; ... public void setExpireTimeInDays(int expireTimeInDays) { expireTimeInMilliseconds = expireTimeInDays * 24 * 60 * 60 * 1000; } I had a hard time to figure out what I did wrong. Now my question: Is that error so obvious ? ...

How to avoid the form being submitted after displaying alert?

If the user name and password does not match it displays a alert but if i click ok to the alert the form is logged in.Can any one tell me how to avoid it?Thanks. <html> <f:view> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <h:form id="loginForm"> <h1><cen...

Custom serialization in JAXB

Hi, Is there a way to customize XML serialization in JAXB, in the same way that it's possible using IXmlSerializable in .NET? (i.e. the ability to directly control serialization of an object using the equivalent of an XmlReader/Writer). I've taken a look at XmlAdapter and @XmlJavaTypeAdapter, but they just seem to be used to transform ...

Regex in Java, finding start and end tag

I am trying to find data within a HTML document. I don't need a full blown parser as it is just the data between one tag. But, I want to detect the 'select' tag and the data in between. return Pattern.compile(pattern, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL); /// E...

Java: Playing WAV sounds

Hi, I am trying to build a java drum machine that needs to play WAV sound samples of the various drum parts (bass drum, snare, etc). Because I need to play the sounds in a tight sequence, I need high performance. Currently I'm using: import sun.audio.*; import java.io.*; public class MusicPlayer { private String filename; pu...