java

How to divide a large Java project into smaller components

We've trying to separate a big code base into logical modules. I would like some recommendations for tools as well as whatever experiences you might have had with this sort of thing. The application consists of a server WAR and several rich-clients distributed in JARs. The trouble is that it's all in one big, hairy code base, one sourc...

Positive lookahead for exclamation mark

I'm trying to build a Java regular expression to match ".jar!" The catch is that I don't want the matcher to consume the exclamation mark. I tried using Pattern.compile("\\.jar(?=!)") but that failed. As did escaping the exclamation mark. Can anyone get this to work or is this a JDK bug? UPDATE: I feel like an idiot, Pattern.compile("...

Java 2D Game Frameworks

I have been looking at frameworks for writing 2D games in Java - part of a growing desire to rediscover my roots in writing those simple but addictive video games. I have googled and found some possibilities, but it's hard to judge which is best without investing significant time in each. Does anyone out there have any recommendations ...

Java Command Line Trouble with Reading a Class from a Jar Archive

I am trying to run a java based tool using a command line syntax as the following: java -cp archive.jar archiveFolder.theMainClassName.Although the class I am searching for, a main class, "theMainClassName" is in the archive.jar and in the archiveFolder given at input, I keep getting the error that my class is not seen. Does anybody have...

Disable JSP extension processing

I have a JavaEE 1.4 web application running on WebSphere Application Server 6.0. In web.xml, there is a servlet configured to intercept all server requests: <servlet-mapping> <servlet-name>name</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> This works fine until I try to request something ending with *.jsp. In this ...

What is the best approach to handling exceptions thrown in a separate thread?

I am working on a J2ME project that spawns worker threads for numerous tasks such as downloading HTTP content. The basic thread layout is similar to most java apps--there is a main UI thread and worker threads spawned to do stuff behind the scenes. My question is what is the best way to handle exceptions that occur in the worker threads?...

Decimal DateTime formatter in Java or Joda

I'm writing a file that requires dates to be in decimal format: 2007-04-24T13:18:09 becomes 39196.554270833331000 Does anyone have a time formatter that will do this (Decimal time is what VB/Office, etc. use)? Basic code goes like follows: final DateTime date = new DateTime(2007, 04, 24, 13, 18, 9, 0, DateTimeZone.UTC); double ...

é is not correctly parsed

My application will read xml from urlconnection. The xml encoding is ISO-8859-1, it contains é character. I use xerces saxparser to parse received xml content. However, é can not be parsed correctly while running application under lunix OS. Everything works fine in Windows. Could you guys please give me some hints? Thanks a lot ...

How to add ChartFrame (JFreeChart library) to JFrame(javax.swing library)?

I can't directly add ChartFrame object to my Jframe object with .add(Component) method. And it's not possible to cast from ChartFrame to JComponent. Casting ChartFrame to Component from java.awt library is also impossible. How can I add ChartFrame to JFrame the other way? ...

Program to simulate vehicles at an intersection using queues

HI I got this coursework question to solve. This is the question: Design a program to simulate vehicles at an intersection. Assume that there is one lane going in each of four directions, with stoplights facing each direction. Vary the arrival time of vehicles randomly in each direction and set up a regular frequency of the light cha...

Hibernate: Avoiding reading all the records to memory at once

I have a large amount of rows in the database from which I need to create an XML document. I am using hibernate 3. The basic list() method in Criteria and Query interfaces looks dangerous: I quess it pretty much has to read all the records into memory even if I only iterate over them. Or is there some lazy loading magic? If not, I seem t...

Inserting a node into a linked list in constant-time?

I'm working on an assignment that is telling me to assume that I have a singly linked list with a header and tail nodes. It wants me to insert an item y before position p. Can anybody please look over my code and tell me if I'm on the right track? If not, can you provide me with any tips or pointers (no pun intended)? tmp = new Nod...

Add Java Libraries to a Groovy on Grails Project.

I am just getting started with Groovy on Grails. How do I add Java libraries to my Grails project? I added the Smack library jar to the lib folder of my Grails project, but I still cannot import any of its packages into my Java or Groovy classes. I am using the Netbeans IDE. Any help would be appreciated.. Buzzy ...

Java: CharBuffer vs. char[]

Is there any reason to prefer a CharBuffer to a char[] in the following: CharBuffer buf = CharBuffer.allocate(DEFAULT_BUFFER_SIZE); while( in.read(buf) >= 0 ) { out.append( buf.flip() ); buf.clear(); } vs. char[] buf = new char[DEFAULT_BUFFER_SIZE]; int n; while( (n = in.read(buf)) >= 0 ) { out.write( buf, 0, n ); } (where in...

From Java to .Net

These are some questions for any developer whose made the jump from Java to .Net: If you could go back to the start of your switched, what would you do to make the transition easier? Any books you would recommend? How is .Net compared to JEE? Anything that totally bugs you? And the most important, do you regret making the jump? ...

Strip Images, CSS and JS from servlet-mapping

I am using the following servlet-mapping in my web.xml file: <servlet> <servlet-name>PostController</servlet-name> <servlet-class>com.webcodei.controller.PostController</servlet-class> </servlet> <servlet-mapping> <servlet-name>PostController</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> To do some ki...

Does anyone know of an Eclipse(WSAD/RAD) plugin for a Maven2 POM classpath container

I am trying to find a simple single purpose plugin that will maintain the Eclipse classpath based on the Maven2 POM dependencies. I know about m2eclipse and q4e. Unfortunately, I'm currently using RAD (Rational Application Developer - IBM's commercial version of Eclipse) and it is not fully compatible with m2eclipse, and I can't use q4e...

Embedding web browser window in Java

Does anyone know a way to open up an instance of the platform's (Windows/Linux/Mac) browser within a Swing window that is integrated into a Java application. No other actions would be preformed other than opening a given URL. Currently, we open a new browser window because the Java embedded browsers have been insufficient. However, from ...

How to use print when expression in Jasper

Hi, Can somebody tell me how to use the printwhenexpression of jasper? Regds, malathi ...

protobuf serialization of language specific data structures

Using google's Protocul Buffers, I have a service already written in Java which has its own data structures already. I'd like to use pb to delivering messages and I'm looking for a way to serialize the existing data structures that I have in Java to pb. I can start by defining all the data structures in pb from scratch, which is probably...