java

Java Performance Testing

I want to do some timing tests on a Java application. This is what I am currently doing: long startTime = System.currentTimeMillis(); doSomething(); long finishTime = System.currentTimeMillis(); System.out.println("That took: "+(finishTime-startTime)+ " ms"); Is there anything "wrong" with performance testing like this? What is a...

What is object serialization?

What is meant by "object serialization"? Can you please explain it with some examples? ...

Using JDBC, how can I substitute multiple IDs into "DELETE FROM T WHERE id IN (?)"

I have some code that produces a set of primary key values that I want to delete from a database table. long[] keysToDelete = { 0, 1, 2, 3 }; and I'd like to use a PreparedStatement to execute the equivalent of DELETE FROM MyTable WHERE myPrimaryKey IN (0, 1, 2, 3); Any idea how? ...

Porting library from Java to Python

I'm about to port a smallish library from Java to Python and wanted some advice (smallish ~ a few thousand lines of code). I've studied the Java code a little, and noticed some design patterns that are common in both languages. However, there were definitely some Java-only idioms (singletons, etc) present that are generally not-well-re...

How do I use a foreach loop in Java to loop through the values in a HashMap?

I am trying to compile the following code: private String dataToString(){ Map data = (HashMap<MyClass.Key, String>) getData(); String toString = ""; for( MyClass.Key key: data.keySet() ){ toString += key.toString() + ": " + data.get( key ); return toString; } I get an error in the for line that says: incompati...

Organizing Actions in a Swing Application?

My current application has a JFrame with about 15 actions stored as fields within the JFrame. Each of the actions is an anonymous class and some of them are pretty long. Is it common to break actions into their own classes possibly within a sub-package called actions? If not, how's this complexity usually tamed? Thanks ...

Batch inserts with JPA/EJB3

Does JPA/EJB3 framework provide standard way to do batch insert operation...? We use hibernate for persistence framework, So I can fall back to Hibernate Session and use combination session.save()/session.flush() achieve batch insert. But would like to know if EJB3 have a support for this... ...

What caching model/framework with Websphere Spring Hibernate Oracle?

We are looking at implementing a caching framework for our application to help improve the overall performance of our site. We are running on Websphere 6.1, Spring, Hibernate and Oracle. The focus currently is on the static data or data that changes very little through out the day but is used a lot. So any info would be great. I ha...

How do I push an update to a war file to clients?

Assuming my clients are running my J2EE WAR application on their intranet, and I have an update for them... how do I push the updated war file to them? I'd like it to be automatic and require no human interaction on the client's side. Can this be done? Any help would be appreciated. ...

Calling virtual method in base class constructor

I know that calling a virtual method from a base class constructor can be dangerous since the child class might not be in a valid state. (at least in C#) My question is what if the virtual method is the one who initializes the state of the object ? Is it good practice or should it be a two step process, first to create the object and th...

How do I append a newline character for all lines except the last one?

I'm iterating through a HashMap (see my earlier question for more detail) and building a string consisting of the data contained in the Map. For each item, I will have a new line, but for the very last item, I don't want the new line. How can I achieve this? I was thinking I could so some kind of check to see if the entry is the last o...

Projects with browsable source using dependency injection w/ guice?

I often read about dependency injection and I did research on google and I understand in theory what it can do and how it works, but I'd like to see an actual code base using it (Java/guice would be preferred). Can anyone point me to an open source project, where I can see, how it's really used? I think browsing the code and seeing the...

From Java Application to Flex Application

Has anyone had experience taking a full-fledged Java desktop application and replicating the functionality using Flex? If you have, what are some of the biggest things to watch out for or pay attention to? What are some recommendations you can make based on your experience? ...

Statistical library for Java

I was wondering if there is a good statistical library for Java. I used to use colt from CERN but it does not provide a good weighted sampling. So I usually use MATLAB Java Builder and export everything to Java afterward. Any thoughts or insights? ...

JScrollPane now showing its viewport

I am making an application with Java Swing and i have a problem. I have made a Tabbed Panel, which need to hold a simple panel, and a scroll-panel. The simple panel is working fine but in my scroll-panel i can only see the scrollbars, but not the viewport, my code is as follows: ContentPane public class ContentPane extends JTabbedPane ...

Free / OpenSource Java Rules / Workflow engine

I am looking for a Java Rules / Workflow engine. Something similar to Microsoft Workflow Engine. Can someone recommend a product? ...

Non-generic reference to generic class results in non-generic return types

I have a legacy class that the class itself is not a generic but one of its methods return type uses generics: public class Thing { public Collection<String> getStuff() { ... } } getStuff() uses generics to return a collection of strings. Therefore I can iterate over getStuff() and there's no need to cast the elements to a String:...

What Java Technologies Should College Grad Should Focus On?

I'm going to be graduating shortly, and I was wondering if there were any Java technologies that I should take the time and learn before I enter the job market. I have no real java enterprise experience (all my internships involved C development on Linux) however, I have worked extensively with it in a large number of my classes. So is...

Experiences With Active Objects ORM for Java?

I'm looking at ORMs for Java and Active Objects caught my eye. Apparently, it was inspired by Rails' ActiveRecord. Based on what I've read, this approach seems to solve a lot of problems with existing Java ORMs by embracing convention over configuration. What's been your experience with it? ...

Does assigning objects to null in Java impact garbage collection?

Does assigning an unused object to null in Java improve the garbage collection process in any measurable way? My experience with Java (and C#) has taught me that is often counter intuitive to try and outsmart the virtual machine or JIT, but I've seen co-workers use this method and I am curious if this is a good practice to pick up or on...