java

Sorting matched arrays in Java

Let's say that I have two arrays (in Java), int[] numbers; and int[] colors; Each ith element of numbers corresponds to its ith element in colors. Ex, numbers = {4,2,1} colors = {0x11, 0x24, 0x01}; Means that number 4 is color 0x11, number 2 is 0x24, etc. I want to sort the numbers array, but then still have it so each element ma...

Is static metaprogramming possible in Java?

I am a fan of static metaprogramming in C++. I know Java now has generics. Does this mean that static metaprogramming (i.e., compile-time program execution) is possible in Java? If so, can anyone recommend any good resources where one can learn more about it? ...

Is it possible to have one appBase served by multiple context paths in Tomcat?

Is it possible to have one appBase served up by multiple context paths in Tomcat? I have an application base that recently replaced a second application base. My problem is a number of users still access the old context. I would like to serve the, now common, application from a single appBase yet accessed via either context. I took a...

How do I remove objects from an Array in java?

Given an Array of n Objects, let's say is an Array of Strings, and it has the following values: foo[0]="a"; foo[1]="cc"; foo[2]="a"; foo[3]="dd"; What do I have to do to delete/remove all the Strings/Objects equal to "a" in the Array? Thanks! ...

How to build interface for such enum

I have the following enum: public enum Status implements StringEnum{ ONLINE("on"),OFFLINE("off"); private String status = null; private Status(String status) { this.status = status; } public String toString() { return this.status; } public static Status find(String value) { for(Status status : Status.values()) { if...

What is 'JNI Global reference'

I am using jProfiler to find memory leaks in a Java swing application. I have identified instances of a JFrame which keeps growing in count. This frame is opened, and then closed. Using jProfiler, and viewing the Paths to GC Root there is only one reference, 'JNI Global reference'. What does this mean? Why is it hanging on to each ins...

What does either Java GUI editor offer for rapid development and maintainability (i.e., Eclipse/SWT and Netbeans/Matisse)?

Between Eclipse/SWT or Netbeans/Matisse, what does either Java GUI editor give you in terms of rapid development and maintainability? ...

Java RSS library

Hi, I'm looking for a Java library for generating RSS feeds, any recommendations? Cheers, Don ...

Java User Interface Specification

Java supplies standard User Interface guidelines for applications built using Java Swing. The basic guidelines are good, but I really feel the look and feel is really boring and outdated. Is anyone aware of a publicly available Java User Interface Guide that has better look & feel guidelines than the Sun provided guidelines? ...

Hash Code implementation

How do we decide on the best implementation of hashcode method for a collection?(assuming that equals method has been overridden correctly) ...

how to workaround a java image scaling bug

I've got a java servlet which is hitting this bug when down-scaling images... http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5101502 I'm trying to work out the best way to work around it and would appreciate any ideas from the community. Thanks, Steve ...

How do I get the image paint/paintComponent generates?

Hey guys. I have a quick question. How do I get the image generated by a JComponent.paint or paintComponent? I have a JComponent which I use as a 'workspace' and where I have overwritten the paintComponent method to my own. The thing is that my workspace JComponent also has children which has their own paintComponent methods. So when ...

Getting java.lang.ClassCastException: javax.swing.KeyStroke when creating a JSplitPane

I'm getting a random unreproducible Error when initializing a JSplitPane in with JDK 1.5.0_08. Note that this does not occur every time, but about 80% of the time: Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.KeyStroke at java.util.TreeMap.compare(TreeMap.java:1093) at java.util.TreeMap.put(TreeMap.ja...

Considering object encapsulation, should getters return an immutable property?

When a getter returns a property, such as returning a List of other related objects, should that list and it's objects be immutable to prevent code outside of the class, changing the state of those objects, without the main parent object knowing? For example if a Contact object, has a getDetails getter, which returns a List of ContactDe...

Using JET with EMF

Hi! I need to run JET templates on a EMF model metadata - i.e. the model itself (not data) is input to my JET template. More practically - I want generate non java code, based on EMF templates. How I do it? Thank you ...

Consequences of running a Java Class file on different JREs?

What are the consequences of running a Java class file compiled in JDK 1.4.2 on JRE 1.6 or 1.5? ...

Serializing Date in Java

I'm passing around some objects through web service and some of them contain java.sql.Date. Because Date doesn't have empty constructor it doesn't want to get serialized. First part of a question is easy: what is the best way to pass a date between client and service? Second part is bit trickier: Once I decide how to pass dates aroun...

[Eclipse] Toggling the state of a menu item

Hi there, I have an Eclipse RCP app I'm working on. It has some view-specific menus and one of the menu items is an item which I would like to display a tick next to when the corresponding functionality is enabled. Similarly, the next time the item is selected, the item should become unticked to reflect that the corresponding functional...

How do you fix "Too many open files" problem in Hudson?

We use Hudson as a continuous integration system to execute automated builds (nightly and based on CVS polling) of a lot of our projects. Some projects poll CVS every 15 minutes, some others poll every 5 minutes and some poll every hour. Every few weeks we'll get a build that fails with the following output: FATAL: java.io.IOException...

How can we print line numbers to the log in java

How to print line numbers to the log. Say when outputting some information to the log, I also want to print the line number where that output is in the source code. As we can see in the stack trace, it displays the line number where the exception has occurred. Stack trace is available on the exception object. Other alternative could be ...