java

Method to find Key in HashTable

I'm trying to create a method which iterates through a hashtable and returns the key as a string, whats the best way to go about this? EDIT: copied from comment Sorry if I didn't make it more clear, I'm trying to do this in Java. I've created a test class public void runprog() { hashMap.put("Butter", 50); hashMap.put("Beans", ...

Java/Swing stack overflow in preferenceChanged method

I'm currently working on a Java project and was having a problem with a stack overflow error. What happens is first the program reads in a file of about 1,500,000 words and adds it to an array. It then reads in a small file of about 600 words and adds it to an array. It checks how many words in the 600 word file occur in the other file. ...

How to get all dates of sundays in a particular year in Java

am seriously looking for this code...am now to programing actually i want to make all dates with flag,which all are sunday in a particulr year.plz am eagarly waiting for ur response.... ...

Generic method in Java without generic argument

In C# I can do actually this: //This is C# static T SomeMethod<T>() where T:new() { Console.WriteLine("Typeof T: "+typeof(T)); return new T(); } //And call the method here SomeMethod<SomeClassName>(); But for some reason I can't get it to work in Java. The thing I want to do is, to create a static method on a superclass, so the...

Java JLabel - add a unique identifier

Hello all, Is there anyway to add an ID or a unique identifier to a JLabel? Thanks all ...

Java TCP Socket Sniffing

I am using TCP sockets to communicate data between a server and client program using a specific port number on the same computer (localhost). I need a software that can capture the data being sent/received through that socket? (or) What's the simplest way of sniffing packets from a specified port in Java? ...

Netbeans and .NET web services

Hi, I'm not an experienced java developer so any comment will be welcomed ... I've written a web service using c# and I wanted to consume this service from java - used Netbeans for this task. All methods works well beside one: the method expecting a type called BusinessDataField2 - this type contains 2 fields: name(string) and value(o...

How can I access preferred applications from Java running on Linux?

We have a multi-platform Java-based system that spawns Robohelp for its online user guide information. It runs on a variety of Windows and Linux flavors. The default Robohelp code that is relevant to our Linux-based systems has a hard-coded link to "netscape" in the command line that it builds to spawn a web browser to view the help fi...

Why aren't op-assign operators type safe in java?

I'm not sure the question is clearly worded, but an example will be clearer. I found out that will not work in Java: int a = ...; a = 5.0; but this will: int a = ...; a += 5.0; I.e., it seems that the = operator is type safe but += isn't. Is there any deep reason for this or is it just another arbitrary decision language designer...

Handling abnormal Java program exits

Hello all, Suppose I have a Java application that opens a database connection. Normally I would add a connection.close() in a finally block, but this block wouldn't be executed in the case of a kill operation, or any other abnormal termination, would it? Are there any other precautions that I, as a programmer, can make in order to close...

Getting the removed text from a Java text component

A JTextComponent allows you to add a DocumentListener to its Document, which will tell you when text was added or removed, and the offset and length of the change. It will not, however, tell you what the text of the change was. This is not much of a problem for text addition, as you can use the offset and the length to find the added t...

Generics..? Super T

A) List<? super Shape> shapeSuper = new ArrayList<Shape>(); shapeSuper.add(new Square()); //extends from SHAP shapeSuper.add(new DoubleSquare()); //extends from SQ shapeSuper.add(new TripleSquare()); //extends from DS shapeSuper.add(new Rectangle()); //extends from SHAP shapeSuper.add(new Circle()); //extends f...

Is there a basic Java Set implementation that does not permit nulls?

The API for the Java Set interface states: For example, some implementations prohibit null elements, and some have restrictions on the types of their elements I am looking for a basic Set implementation that does not require ordering (as ArrayList provides for the List interface) and that does not permit null. TreeSet, HashSet, and...

delete a line in Eclipse

In a visual studio, you would use Ctrl-x, where is in eclipse I am force to select a line or if it is empty, go the beginning of the line before clicking delete/backspace. Is there a quick shortcut? Thanks ...

Automatically refactor a loop into a recursive method?

Do you know a tool that automatically refactors a method with a single loop into a recursive method, preferably in Java? This is for teaching purposes. ...

Button text disappearing with 4Gb Ram and IBM Java 1.5

We have a very strange error occurring at a developer site which we are unable to replicate ourselves. A developer in Poland has recently upgraded his Windows XP Service Pack 3 machine to 4Gb of Ram When he did so he started experiencing graphical errors in java programs using IBM JDK 1.5 This errors only occur in IBM JDK 1.5 and not in...

Java error: Found interface ... but class was expected

I am getting a strange runtime error from my code: "Found interface [SomeInterface] but class was expected" How can this happen? How can an interface get instantiated? Update: (In response to some answers) I am compiling and running against the same set of libraries, but I am using Guice to inject a Provider for this particular Inter...

Can you mix the JVM languages? ie: Groovy & Clojure

I understand that you can easily mix groovy&java, clojure&java, whateverJvmLang&java. Does this also mean I can have clojure and groovy code interact as well? If I use Grails or jRoR, can I also make use of clojure in that environment? ...

Convert Excel 2003 XML file to Excel 2003 XLS format

Is there a way to convert Excel 2003 XML file to Excel 2003 XLS format with Java? Or at least any open source framework that can do this? Thanks, Matthew Huang ...

JTable sorting rows in Java 1.5

Is there a simple way to sort rows in a JTable with Java 1.5 (setAutoCreateRowSorter and TableRowSorter appear to be Java 1.6 features)? ...