java

Does it help GC to null local variables in Java

I was 'forced' to add myLocalVar = null; statement into finally clause just before leaving method. Reason is to help GC. I was told I will get SMS's during night when server crashes next time, so I better did it :-). I think this is pointless, as myLocalVar is scoped to method, and will be 'lost' as soon as method exits. Extra nulling j...

Data Exchange Design Proposal

Basically the situation we have is we need to be able to take data from an arbitrary data source (database, flat file, it could be anything really), morph the data so it maps to the schema we have, and then send us the data so we can store it. The data will be coming from ~200 different physical locations around the country and we'd lik...

Is there a Many to Many Collection in Java using Generics (Domain Model, not Persistence Layer)?

I seem to be using the wrong search terms for this in Google... I have written a Generic Class for Many-To-Many Associations, but I'm guessing this has already been done. It is highly likely that it exists in an implementation much better than my own. This is my first foray into writing a generic class. For a better idea of what I'm ...

Hibernate second level cache with Spring

I'm using Spring + JPA + Hibernate. I'm trying to enable Hibernate's second level cache. In my Spring's applicationContext.xml I have: <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop> <prop key="hibernate.cache.provider_configuration_file_resource_path">/ehcache.xml</prop> When I run ...

Command to give a list of JREs installed on the system

Is there any command which would list down all the JRE versions and releases installed on a system? ...

In Java, how can I construct a "proxy wrapper" around an object which invokes a method upon changing a property?

I'm looking for something similar to the Proxy pattern or the Dynamic Proxy Classes, only that I don't want to intercept method calls before they are invoked on the real object, but rather I'd like to intercept properties that are being changed. I'd like the proxy to be able to represent multiple objects with different sets of properties...

Oracle ADF Gantt chart

I am just starting to learn ADF and I am tasked with examining how ADF's gantt chart works. I have completed Oracle's tutorial of it, however I feel that all the tutorial teaches is how to use the tutorial. Basically I am looking for a good tutorial to show how from an empty project: create a collection of dummy data [ not from a data...

Java int[][] array - iterating and finding value

Hi I have an array in the form of 'int[][]' that represents the co-ordinates of a small grid. Each co-ordinate has been assigned its own value. eg array[0][4] = 28...... I have two questions. Firstly, how do I iterate through all the stored values. Secondly, I want to be able to input a value and have its specific co-ordinates in the g...

Best way to represent a fraction in Java?

I'm trying to work with fractions in Java. I want to implement arithmetic functions. For this, I will first require a way to normalize the functions. I know I can't add 1/6 and 1/2 until I have a common denominator. I will have to add 1/6 and 3/6. A naive approach would have me add 2/12 and 6/12 and then reduce. How can I achieve a...

Connect to a Read Only database

While trying to connect to a database that's set to read only, the connection cannot be made. I get the following error: Cannot create PoolableConnectionFactory (Io exception: The Network Adapter could not establish the connection) The application needs to run in read-write mode and then automatically handle the switch to read-only ...

Generating a Maven POM from an existing project?

Do any of the IDEs (or any other tool for that matter) have the ability to generate a POM based on an existing project? ...

Is Object constructor called when creating an array in Java?

In Java, an array IS AN Object. My question is... is an Object constructor called when new arrays is being created? We would like to use this fact to instrument Object constructor with some extra bytecode which checks length of array being constructed. Would that work? ...

Is there a rule of thumb for when to code a static method vs an instance method?

I'm learning Java (and OOP) and although it might irrelevant for where I'm at right now, I was wondering if SO could share some common pitfalls or good design practices. ...

How can I learn Android?

I am a freshman in college which has been Java programming for over a year. I haven taken a couple of programming courses, both of which were with Java. And I have done web development for several years. So overall, I would't say that I am a complete beginner in programming. Recently, I have developed a strong interest in developing fo...

Best Tools for 2D Constructive Area Geometry

What are the best tools/libraries (in any language) for working with 2D constructive area geometry? That is, a library working with more or less arbitrary two dimensional shapes and supplying union, intersection, difference and XOR. My baseline is the java.awt.geom.Area class, and that's serviceable if slow. What's out there that's ...

How do you turn a FileSet into a list of Files in a Mojo

I'm writing my first Maven Mojo, in it I'm wanting to take a file set and process all the files it refers to. In pseudo code what I'd like to do... void myCode(org.apache.maven.model.FileSet fileSet) { List<java.io.File> files = FileSetTransformer.toFileList(fileSet); for (File f : files) { doSomething(f); } } So ...

Maven Embedded Jetty Container fails to load Taglibs: Unable to initialize TldLocationsCache

Hi all, I'm using the Maven Cargo Plugin to startup a Jetty web container for running some integration tests in a separate project module. The problem i'm battling with occurs when i added taglibs into the jsp pages and tried hitting them from the integration tests. When jetty tries to compile the pages it fails with this error: org....

How to determine which classes are used by a Java program?

Is there any tool that lists which and when some classes are effectively used by an app or, even-better, automatically trims JAR libraries to only provide classes that are both referenced and used? ...

First Java program (calculator) problems

I'm in the process of learning Java and my first project is a calculator, however I've run into a snag. I'm trying to get my calculator to let me enter a number then click an operator (+, -, x, /), enter another number then hit an operator again and have the display update and be able to keep this going. Example, I would like to be abl...

Is there a way for reading/writing serializable objects to a RandomAccesFile?

How can I read/write serializable object instances to a RandomAccessFile in Java? I want to be able to do this the same way you do it in c++ through structs. In java only ObjectInputStreams/ObjectOutputStreamscan can read/Write objects. I am amazed Java does not have something already implemented. ...