java

Best way to store Country codes, names, and Continent in Java

I want to have a List or Array of some sort, storing this information about each country: 2 letter code Country name such as Brazil Continent/region of the world such as Eastern Europe, North America, etc. I will classify each country into the region/continent manually (but if there exists a way to do this automatically, do let me k...

Preserving the Java-type of an object when passing it from Java to Jython

I wonder if it possible to not have jython automagicaly transform java objects to python types when you put them in a Java ArrayList. Example copied from a jython-console: >>> b = java.lang.Boolean("True"); >>> type(b) <type 'javainstance'> >>> isinstance(b, java.lang.Boolean); 1 So far, everything is fine but if I put the object in ...

Joining Information Across DB2 and Oracle Databases Best Practices

We are designing a fairly large brownfield application, and run into a bit of a issue. We have a fairly large amount of information in a DB2 database from a legacy application that is still loading data. We also have information in an Oracle database that we control. We have to do a 'JOIN' type of operation on the tables. Right now,...

SWT Syntax highlighting widget

Anyone know of an SWT widget that can be a text editor with support for syntax highlighting? I'm aware of the StyledText widget but I'm hoping that somebody has already written some libraries so one can just specify the keywords that should be highlighted. ...

Java XML parsing.

Whats the quickest way to convert a doc like: <customermodel:Customer> <creditCards> <cardNumber>@0</cardNumber> <provider>@HSBC</provider> <xsi:type>@customermodel:CreditCard</xsi:type> 23242552 </creditCards> . . So that the elements with @ become attributes for the parent element. ie get...

Cartesian product of arbitrary sets in Java

Do you know some neat Java libaries that allow you to make cartesian product of two (or more) sets? For example: I have tree sets. One with objects of class Person, second with objects of class Gift and third with objects of class GiftExtension. I want to generate one set containing all possible triples Person-Gift-GiftExtension. The...

POI: Using Excel templates.

Basic question: How do I load an Excel template for use with POI and then save it to an XLS file? Edit: The answer is: FileInputStream inputStream = new FileInputStream(new File(templateFile)); Workbook workbook = new HSSFWorkbook(inputStream); (Just load the template as a workbook and then write the workbook as an XLS file elsewher...

"SAX2 driver class org.apache.crimson.parser.XMLReaderImpl not found" when using Batik in a webapp on Tomcat

This is possibly related to a classpath problem, but I'm really not sure at this point, since I don't get this error on some machines. The error at the top of the stack is SAX2 driver class org.apache.crimson.parser.XMLReaderImpl not found. Why would I get this error only in some environments, but not others? How can I further investi...

Is a Java socket's PrintWriter thread safe?

So, I have two threads. Thread one manages the client connections. (There is only one client and one server) I call it my server thread. Thread two manages sending messages to the client. I call it my message processor thread. Thread one is responsible, among other things sending a heartbeat to the client periodically. When progr...

What is the best way to screen scrape poorly formed XHTML pages for a java app

I want to be able to grab content from web pages, especially the tags and the content within them. I have tried XQuery and XPath but they don't seem to work for malformed XHTML and REGEX is just a pain. Is there a better solution. Ideally I would like to be able to ask for all the links and get back an array of URLs, or ask for the text...

UTF-8 and Servlets on Tomcat/Linux

I've had some problems with reading and writing UTF-8 from servlets on Tomcat 6 / Linux. request and response were utf-8, browser was utf-8, URIEncoding was set in server.xml on both connectors and hosts. Ins short, every known thing for me in code itself, and server configuration was utf-8. When reading request, I've had to take byte ...

Anonymous vs named inner classes? - best practices?

I have a class, let's call it LineGraph, that renders a line graph. I need to subclass it, but the derived class is only used in one place and is coupled to the class that uses it. So I am using an inner class. I see two ways to do this: Anonymous inner class public class Gui { LineGraph graph = new LineGraph() { // extra ...

in Java: programmatically determining addresses of C/C++ variables given a COFF/ELF/DWARF executable

This is a situation I run into now and then: For an embedded system which does not use virtual addressing, I have an executable file that was compiled from C or C++ code with debugging information included. It's usually in COFF or ELF/DWARF (I get those two mixed up) format. At runtime, on a PC, I would like to determine the address of...

How to capture the result of a system call in a shell variable?

We want to build a script that run every night (kills and restart a java process). For that we need to capture the process number (since there could be more than one java process running). The command below is basically what we will use to obtain the processes number, probably with a regexp at the end of the grep. Unless any better su...

What is the default scope of a method in Java?

It's a crazy question because it seems simple. I cannot find anywhere that blatantly states the answer. If I type: void doThis(){ System.out.println("Hello Stackoverflow."); } what is the default scope of doThis()? Public? Protected? Private? Thanks in advance. ...

PriorityQueue/Heap Update

Does Java have an easy way to reevaluate a heap once the priority of an object in a PriorityQueue has changed? I can't find any sign of it in Javadoc, but there has to be a way to do it somehow, right? I'm currently removing the object then re-adding it but that's obviously slower than running update on the heap. ...

hex viewer/editor GUI component for Java Swing?

I'm looking for a decent hex viewer (read-only; I don't need an editor) GUI component that I can use within my Swing GUI. Is there anything out there? I suppose I could write my own, but am hoping to avoid doing this. (also it would be nice to be able to render certain bytes as colorized/bold to highlight particular bytes in question.) ...

add xml:base to xml file in java

I want to add an xml:base declaration to an xml file in java. I currently have the xml output in an OutputStream that was generated by some third party code. The file starts out like this: <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns="http://www.mycompany...

How to share log4j library most effectively

i have a few batch java command-line applications which are planned to be deployed as: batch_apps app_1 batch1.jar run_batch1.sh app_2 batch2.jar run_batch3.sh {...etc...} what would be the best practice on organizing a shared library pool - for example log4j: batch_apps app_1 batch1.jar run_batch1.sh ...

JTable - drag and drop

OK, this problem is out of my league. I'm trying to implement a GUI widget in swing that allows files to be dropped onto a JTable, and allows the rows of the JTable to be dragged for re-sorting. Think VLC's playlists or the one in iTunes. I got dropping files from the OS (Explorer, Finder, etc.) working just fine, but I'm having an impo...