java

django-like frameworks?

Hi I've been working with django for some months and find it really helpful, is there alike frameworks for other programming languages such as java or c#? The problem I suffer by using django is finding a server to host the proyect because supporting servers are more expensive and harder to find. From django I find useful: the object-re...

How can I describe a bug as a feature?

I often hear of situations where a bug in a program is passed off as a feature. This seems like a useful skill to have. Please describe a technique for doing this - preferably with specific examples. ...

Java reflection: How do I override or generate methods at runtime?

Hello! It is possible in plain Java to override a method of a class programmatically at runtime (or even create a new method)? I want to be able to do this even if I don't know the classes at compile time. What I mean exactly by overriding at runtime: abstract class MyClass{ public void myMethod(); } class Overrider extends MyCla...

How do Datastore and App versions work on GAE/J

One can deploy several versions of the same application on GAE/J, but how does GAE/J deal with the fact that different versions can use different Datastore (and possibly incompatible) schemes? Example: Suppose that on version 1 of my application I have a POJO like (I've left out the several details for sake of simplicity): public cla...

Is a Java hashmap really O(1)?

I've seen some interesting claims on SO re Java hashmaps and their O(1) lookup time. Can someone explain why this is so? Unless these hashmaps are vastly different from any of the hashing algorithms I was bought up on, there must always exist a dataset that contains collisions. In which case, the lookup would be O(n), not O(1). Can so...

Retaining the submitted JSP form data

I am having a web form(JSP) which submits the data to different application, hosted on different server. After submitting the form data, that application redirect back to same JSP page. Now, I want to save the entered the data. What are the different approaches to retain the submitted data in web form. I would not prefer to store the dat...

Using command-line argument for passing files to a program

How can I receive a file as a command-line argument? ...

Is there anyway to display a custom form in Java that acts similar to TrayIcon.displayMessage()?

Using Java is there anyway to display a custom form/image that behaves similar to TrayIcon.displayMessage() function in that it displays just above the system tray for a while then disappears? I am also looking for a way to display multiple notifications at the same time by having them display above each other. If not, how do I find th...

What are the advantages of chain-of-responsibility vs. lists of classes?

Recently, I was discussing with another programmer the best way to refactor a huge(1000 lines) method full of "if" statements. The code is written in Java, but I guess this issue could happen in other languages such as C# as well. To solve this problem, he suggested using a chain-of-responsibility pattern. He proposed having a base "Ha...

Sending a Java UUID to C++ as bytes and back over TCP

I'm trying to send a Java UUID to C++, where it will be used as a GUID, then send it back and see it as a UUID, and I'm hoping to send it across as just 16 bytes. Any suggestions on an easy way to do this? I've got a complicated way of doing it, sending from Java to C++, where I ask the UUID for its least and most significant bits, wri...

How to design a server with many persistent connections

Hello, I am designing a application where many clients connect to a central server. This server keeps these connections, sending keep-alives every half-hour. The server has a embedded HTTP server, which provides a interface to the client connections (ex. http://server/isClientConnected?id=id). I was wondering what is the best way to go a...

What are attributes?

Hi, Could anyone please clarify the defination of attribute? for example, in the following code, what is an attribute: request.setAttribute("ja",new foo.Employee()); Is the attribute in the above code an object of type foo.Employee(), or it is key/value pair, or it is actually "ja"? ...

Netbeans IDE (full) 6.5.1 just hangs when clicking on Services Tab

Hi I am using Netbeans IDE 6.5.1. I have made projects in netbeans. My pc configuration is :RAM : 1 GB, HD: 160 GB, Processor: AMD, OS: Window Xp Sp2. Netbeans IDE takes around 2 hrs time to load at my pc (too much time), i had read somewhere that for improving netbeans performance you can remove extra modules which are not required. SO ...

Search an attribute inside a Vector on Java

I've a Vector of objects, and have to search inside for a random attribute of those objects (For example, a Plane class, a Vector containing Plane; and I've to search sometimes for destination, and others to pilotName). I know I can traverse the Vector using an Iterator, but I've got stuck at how do I change the comparison made between ...

K- Means algorithm

Hi, I'm trying to programm a k-means algorithm in Java. I have calculated a number of arrays, each of them containing a number of coeficients. I need to use a k-means algorithm in order to group all this data. Do you know any implementation of this algorithm? Thanks ...

Need citation for Extension Interface pattern in Java

The following Java design allows an object to be extended without changing its interface to clients. The object can implement additional extension interfaces. Clients can ask the object for extension interfaces that it implements. I read about it in a blog post, but my Google skills failed to find the blog post again. I'm not advocat...

How do you draw a string centered vertically in Java?

I know it's a simple concept but I'm struggling with the font metrics. Centering horizontally isn't too hard but vertically seems a bit difficult. I've tried using the FontMetrics getAscent, getLeading, getXXXX methods in various combinations but no matter what I've tried the text is always off by a few pixels. Is there a way to measur...

Concurrent directory traversal algorithm hang problem

I have created a concurrent, recursive directory traversal and file processing program, which sometimes hangs after all parallel computations have finished but the 'primary' thread never continues with other tasks. The code is basically a fork-join style concurrent aggregator, and after the parallel aggregation completes, it should dis...

ClassCastException when trying to add child to parent in owned one to many. (using jdo on google appengine)

I need some help figuring out what I'm doing wrong here. I am trying to master one to many relationships and running into a roadblock. I tried to modify the Employee and ContactInfo example to do one to many mappings: Everything works if I create both the parent (employee) and child (Contact) and then call makePersistent. But if I try ...

How to change JTree view dynamically when a nodes object's state changes?

I'm implementing a Java JTree panel. This panel holds a TreeModel build from a set ofdatastructures that are treelike (a list of lists of composites - different classes). I get these datastructure from external jar implementations based on a set of interfaces I defined. The treenodes contain a checkbox that the user may check to indicat...