java

How do you ensure multiple threads can safely access a class field?

When a class field is accessed via a getter method by multiple threads, how do you maintain thread safety? Is the synchronized keyword sufficient? Is this safe: public class SomeClass { private int val; public synchronized int getVal() { return val; } private void setVal(int val) { this.val = val; ...

Preferred way to do logging in the SpringFrame work

I have done some searches looking for information about how to do logging with the Spring Framework. We currently have an application that has no logging in it except for system.out statements (very bad way). What I would like to do, is add logging, but also want to be able to control the logging at run time, with say JMX. We are usin...

How can I generically detect if a database is 'empty' from Java

Can anyone suggest a good way of detecting if a database is empty from Java (needs to support at least Microsoft SQL Server, Derby and Oracle)? By empty I mean in the state it would be if the database were freshly created with a new create database statement, though the check need not be 100% perfect if covers 99% of cases. My first th...

Can you suggest something a little more advanced than java.util.Properties?

Do you know any libraries similar to java.util.Properties that support more advanced features like grouping properties, storing arrays, etc? I am not looking for some heavy super-advanced solution, just something light and useful for any project. Thanks. ...

How do I truncate a java string to fit in a given number of bytes, once UTF-8 encoded?

How do I truncate a java String so that I know it will fit in a given number of bytes storage once it is UTF-8 encoded? ...

Generate Dynamic Excel from Java

We've pre-defined Excel document structure with lots of formulas and macros written. During download of Excel, thru Java application we populate certain cells in Excel with data. After download when user open Excel, macros & formulas embedded in it will read the pre-populated data and behave accordingly. We are rightnow using ExtenXLS ...

Jar file naming conventions

Are there any industry standard conventions for naming jar files? ...

Vista skin l&f

is there anywhere on the web free vista look and feel theme pack for java? ...

How to initialize Hibernate entities fetched by a remote method call?

When calling a remote service (e.g. over RMI) to load a list of entities from a database using Hibernate, how do you manage it to initialize all the fields and references the client needs? Example: The client calls a remote method to load all customers. With each customer the client wants the reference to the customer's list of bought a...

I am losing periods in an email sent using Java Mail

I am sending newsletters from a Java server and one of the hyperlinks is arriving missing a period, rendering it useless: Please print your <a href=3D"http://xxxxxxx.xxx.xx.edu= au//newsletter2/3/InnovExpoInviteVIP.pdf"> VIP invitation</a> for future re= ference and check the Innovation Expo website <a href=3D"http://xxxxxxx.xx= xx.xx.e...

Transform .HBM model to annotated pojos

We have our domain model declared in rusty old hbm files, we wish to move to POJOs annotated with the javax.persistence.* annotations. Has anyone had experience doing so? Are there tools that we could employ? ...

How to default the working directory for JUnit launch configurations in Eclipse?

Our Java code (not the test code) reads files from the current directory, which means the working directory needs to be set properly whenever we run the code. When launching a JUnit test from within Eclipse, a launch configuration automatically gets created. The problem is, that the working directory in that launch configuration is alwa...

How to learn Java Webservices

Please suggest some good resources to start writing Java Web services. ...

How do you read an image in Java when Toolkit.getDefaultToolkit() throws an AWTError?

I am reading image files in Java using java.awt.Image img = Toolkit.getDefaultToolkit().createImage(filePath); On some systems this doesn't work, it instead throws an AWTError complaining about sun/awt/motif/MToolkit. How else can you create a java.awt.Image object from an image file? ...

j_security_check and JAAS

I have been given the task of implementing a login handler. The only detail the handler captures is username and password. Initially I was going to use a JSP that posted to a servlet. Where the servlet carried out a db lookup and also validated the user credentials. Upon successful login you are redirected but unsuccessful takes you ...

Design Problem with VetoableChangeListener

Hello i have a problem with the design of a VetoableChangeListener: I implement the VetoableChangeListener interface to listen changes of a property in a model class, when the model fires the vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException i try to save the change in a DB, which could fail (by a SQLException,...

Working with latitude/longitude values in Java

Does anyone know of any free utility jars for java that assist with longitude/latitude manipulation in Java? I am wanting to find the distance between two different points. This I know can be accomplished with the great circle distance. http://www.meridianworlddata.com/Distance-calculation.asp Also, given a point and a distance I would...

Performance Profiling Tips Netbeans for client applications

Do you have any tips for effective profiling using Netbeans? The profiler is quite nice and powerful. I've used it to find problems in some of my Eclipse RCP client applications. However, I get the feeling that I could get some more value out of it. Normally I set it to profile either all my classes (starting with xxx.mydomain) using...

JUnit can't find my class

I am running JUnit through TextMate, and when I try to run my test cases I get this error JUnit version 4.5 Could not find class: ProgTest Time: 0.001 OK (0 tests) Progtest.java can be found here ...

Irretrievably destroying data in Java

Is there anyway in Java to delete data (e.g., a variable value, object) and be sure it can't be recovered from memory? Does assigning null to a variable in Java delete the value from memory? Any ideas? Answers applicable to other languages are also acceptable. ...