java

How can I invert the case of a String in Java?

I want to change a String so that all the uppercase characters become lowercase, and all the lower case characters become uppercase. Number characters are just ignored. so "AbCdE123" becomes "aBcDe123" I guess there must be a way to iterate through the String and flip each character, or perhaps some regular expression that could do it....

Is JDBC a big memory hog?

I need to access (read in) data repeatedly from a database in my java codes, and therefore adopted JDBC. However, it seems to me that using JDBC takes up a lot of memory. I tried to be careful about closing the objects created for JDBC (ResultSet, Statemenet), but still it seems to hog a lot of memeory especially compared to reading in i...

JSP exception - class not found (tomcat)

I'm setting up an existing application on a new Tomcat 5.5 server connecting to a Postgres database (running on Debian Lenny). When I access it I get a series of stack traces with the following root cause: java.lang.ClassNotFoundException: java.sql.SQLClientInfoException org.apache.catalina.loader.WebappClassLoader.loadClass(WebappC...

Switching J2SE versions on Mac OS (SnowLeopard)

My current JDK on Mac OS (10.6) is set to 1.6 and I'd like to switch to 1.5. A listing of '/System/Library/Frameworks/JavaVM.framework/Versions/' shows: lrwxr-xr-x 1 root wheel 10 Nov 3 18:34 1.5 -> CurrentJDK lrwxr-xr-x 1 root wheel 10 Nov 3 18:34 1.5.0 -> CurrentJDK lrwxr-xr-x 1 root wheel 5 Nov 3 18:34 1.6 -> 1.6.0 ...

Simple JAVA: Password Verifier problem

I have a simple problem that says: A password for xyz corporation is supposed to be 6 characters long and made up of a combination of letters and digits. Write a program fragment to read in a string and print out a message as to whether or not the string entered would be considered a valid password. I need help on completing this code....

Is there a central javadoc repository online?

I found some sample code that uses an interface named com.sun.jersey.spi.container.ContainerRequestFilter. Someone was nice enough to post the javadoc here, but it just looks like it was some university professor who also couldn't find the javadocs. I know I can build it myself, but would rather not go through the work. Is there a cen...

Are javax.persistence.Query objects cachable?

I'm writing a stateless EJB. I had methods like: public String getXxx(final String userId) throws ... { final Query query = em.createNativeQuery(...); query.setParameter(1, userId); return (String)query.getSingleResult(); } Can I cache the Query object instantiating it at load time and using it in a multi-thread environmen...

is there a way to both catch and throw an exception

I have a method that is going to the DB so all our JDBC stuff in the DAO method is inside a try/catch block. It is catching SQLException When I write a test case against this method and if a SqlException occurs then my testcase does not say 'caused an error'. it just goes on its merry way. However, If I dont catch the SqlException i...

How to Pack/Encrypt/Unpack/Decrypt a bunch of files in Java?

I'm essentially trying to do the following on a Java/JSP-driven web site: User supplies a password Password is used to build a strongly-encrypted archive file (zip, or anything else) containing a text file as well as a number of binary files that are stored on the server. It's essentially a backup of the user's files and settings. Lat...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that are stored in the collection (primarily their IDs, and not the remaining contents of each element). Anyone have an idea of how I might go...

Should Java programs compiled with debugging information not be used in a production system?

Is there any reason I should avoid compiling in debugging information with Javac in my Java classes for use in a production server? Are there any speed or security concerns I should be aware of? Please note that I am referring to debugging information like line numbers in stack traces, not the debug level of loggers. Related Questio...

Eclipse: Hover broken in debug perspective

Since upgrading Eclipse (Galileo build 20090920-1017), hover in debug no longer displays a variable's value. Instead, hover behaves as if I were in normal Java perspective: I've tried cleaning the project, re-importing it, etc., all to no avail. Anything I'm missing here? ...

XPath: Is there a way to set a default namespace for queries?

Is there a way to set Java's XPath to have a default namespace prefix for expressons? For example, instead of: /html:html/html:head/html:title/text()", the query could be: /html/head/title/text() While using the namespace prefix works, there has to be a more elegant way. Sample code snippet of what I'm doing now: Node node = ... // DO...

Advantages of using a Dynamic Client with JAX-WS

What are the advantages of using a dynamic client with JAX-WS services as opposed to just using generated client classes? What are the disadvantages? **For my particular case I am using Apache CXF, I'm not sure what other libraries allow "dynamic" clients. -I thought I didn't need to add this, but... I'm looking for non-obvious(I know....

Grails 1.1 and JDK 1.5/1.6 "Bad version number in .class file"

My development environment (Mac OS 10.6) uses JDK 1.6 while production relies on 1.5. Upgrading the prod to 1.6 isn't an option at the moment so I followed the steps to install 1.5 on my machine. However, after I set the correct JAVA_HOME version to 1.5 with Grails 1.1, I get the error message: 2009-11-12 09:20:34,881 INFO [STDOUT] 09:...

Is there an easy way to get characters from the keyboard without hitting enter in Java?

I'd like to know if there is an easy way to get character input from a JTextField in Java as they happen, not after an enter keystroke. In my case I want the characters (text) to be read in, and when the enter key is hit, do something with the characters already collected. ...

Convert a 2D array index into a 1D index

I have two arrays for a chess variant I am coding in java...I have a console version so far which represents the board as a 1D array (size is 32) but I am working on making a GUI for it and I want it to appear as a 4x8 grid, so I have a 2-dimensional array of JPanels... Question is, is there any formula that can convert the array[i][j] ...

In Eclipse, why doesn't "Show In" appear for non-Java files?

If I have a *java file open, I can right click on the source, scroll down to "Show In (Alt-Shift-W)", and select Navigator. If I have an *xml, *jsp, or pretty much anything besides a Java source file, that option doesn't appear. Is there any way to get it to appear, or any similar functionality that will let me jump immediately to th...

Where should I put this configuration setting?

I'm designing a fairly small web application which will run on a Sun application server (v9.1). It only has a few pages, no database of its own, and will retrieve/update data via web services. There's one block of text on one of the pages which we anticipate will need to be updated occasionally (a few times a year?) by a system admin. Wh...

Putting the contents of a JTextField into a Variable - Java & Swing

So i creating a little java app and am just wondering how i can get the contents of a JTextField and then assign the value into a String variable, I thought below would work: JTextField txt_cust_Name = new JTextField(); String cust_Name; txt_cust_Name.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ...