java

Does a cache need to synchronized?

This seems like perhaps a naive question, but I got into a discussion with a co-worker where I argued that there is no real need for a cache to be thread-safe/synchronized as I would assume that it does not matter who is putting in a value, as the value for a given key should be "constant" (in that it is coming from the same source ultim...

Best technology for Java based simple CRUD web site

I want to create a CRUD (create, retrieve, update, delete) web site using the simplest Java tools. This site will allow users to manage four tables, two of which are reference tables used to build menus and two of which will undergo CRUD activity. I'm leaning toward Stripes but I would like to hear the opinions of experience developers...

Difference between '.' and "." in java

Hi Is there a difference between concatenating strings with '' and ""? For example, what is the difference between: String s = "hello" + "/" + "world"; and String s = "hello" + '/' + "world"; Thanks in advance. ...

Can classes in java that implement runnable have methods other than run()?

I'm trying to implement a simple class like this: public static void main(String args[]) { try { myClass test = new Thread(new myClass(stuff)); test.start(); test.join(); } catch (Throwable t) { } } When I try to include a print() method in myClass and use it, I get a "cannot find symbol" in class java.l...

Obtain timestamp of items from FTP file list

In Java, I'm trying to log into an FTP server and find all the files newer than x for retrieval. Currently I have an input stream that's reading in the directory contents and printing them out, line by line, which is all well and good, but the output is fairly vague... it looks like this... -rw------- 1 vuser 4773 Jun 10 2008 .b...

Share static singletons through EJB's

I'm trying to create a cache in a webservice. For this I've created a new Stateless Bean to provide this cache to other Stateless beans. This cache is simply a static ConcurrentMap where MyObject is a POJO. The problem is that it seems as there are different cache objects. One for the client beans, and another locally. -CacheService -Ca...

Return to a specific dialog

I'm writing a very simple text editor and have run into a somewhat minor problem. Code below Saving a file, when a file exists, the user will be prompted to overwrite, cancel, or not overwrite (having the option to try again). So I have a JFileChooser that will prompt the user to overwrite: yes, no, cancel In the case of no being sele...

Casting reference variable in Java

Hello, I have something unclear concerning casting reference variable in Java. I have two classes A and B. A is the super class of B. If I have the two objects, and then the print statement: A a = new A(); //superclass B b = new B(); //subclass System.out.println ((A)b); then what exactly is happening when the println method is e...

Quicksort slower than Mergesort??

I was working on implementing a quicksort yesterday, and then I ran it, expecting a faster runtime than the Mergesort (which I had also implemented). I ran the two, and while the quicksort was faster for smaller data sets <100 elements (and I did verify that it works), the mergesort became the quicker algorithm fairly quickly. I had been...

How can I make Tomcat pre-compile JSPs on startup?

We're using both Apache Tomcat 6.0 and Jetty 6 where I work. We mostly use Jetty for testing (it's great for running embedded in JUnit tests) and Tomcat for production. By default, Tomcat compiles JSPs on-the-fly as users request them. But this results in degraded performance for the first hit. It also highlights bizarre bugs in Tomc...

Learning Clojure without Java Knowledge

Ok, so I'm psyched about another list. I got myself a copy of the beta Clojure programming book... And the one thing I'm noticing most is that it's assumed I know... like all the major java classes. Except, generally, I don't really care about Java. I just want enough knowledge of it for Clojure to be an option for me. Any suggestio...

ResultSet -> XLS

I have to run few SQL queries and put the results into a spreadsheet. Since I am on a Spring/Java environment, I was about to run the queries using JDBC, iterate through the ResultSet, and use Jakarta POI to create a simple XLS. This looks like a very common requirement, so I was wondering if there is something already available - a pac...

What is the currently popular Java SIP library?

I'm working on developing a SIP application in Java and wondering what is the most used SIP library currently. MJSIP? ...

When should Throwable be used instead of new Exception?

Given: Throwable is Exception's superclass. When I read tests on writing your own 'exceptions', I see examples of Throwable being used in the catch block and other text's show new Exception() being used in the catch block. I have yet to see an explanation of when one should use each. My question is this, When should Throwable be used an...

Asynchronous processing in Java from a servlet

I currently have a tomcat container -- servlet running on it listening for requests. I need the result of an HTTP request to be a submission to a job queue which will then be processed asynchronously. I want each "job" to be persisted in a row in a DB for tracking and for recovery in case of failure. I've been doing a lot of reading. Her...

Is MVC good for mobile device?

Is it good for develop MVC Framework by using J2ME (Resource,Speed,Performance,...)? ...

Java App : Unable to read iso-8859-1 encoded file correctly.

I have a file which is encoded as iso-8859-1, and contains characters such as ô . I am reading this file with java code, something like: File in = new File("myfile.csv"); InputStream fr = new FileInputStream(in); byte[] buffer = new byte[4096]; while (true) { int byteCount = fr.read(buffer, 0, buffer.leng...

How easy is it to set up JBoss Seam to run on GlassFish with JPA instead of Hibernate?

Question pretty much says it all - I'm interested to find out about how to set up JBoss Seam on a GlassFish (v3 prelude) application server rather than JBoss. Also, I prefer JPA over Hibernate for persistance but it looks as though Seam has dependencies on Hibernate (or at least parts of it), has anyone got any experience with a stack li...

Java, pass-by-value, reference variables

Hello, I have a problem with understanding the "pass-by-value" action of Java in the following example: public class Numbers { static int[] s_ccc = {7}; static int[] t_ccc = {7}; public static void calculate(int[] b, int[] c) { System.out.println("s_ccc[0] = " + s_ccc[0]); // 7 System.out.println("t_ccc[0] = " ...

Java, infinite while loop, incrementation

Hello, in the following example program in Java, I get infinite loop, and I cannot understand why: public class Time { public static int next(int v) { return v++; } public static void main(String[] args) { int[] z = {3, 2, 1, 0}; int i = 1; while(i < 4) { System.out.println(z[i]/z[i]); i...