java

How to get the present working directory on linux in java

I am invoking the command using a bash shell in linux. This command completes its operation using java class. I want to retrieve the present working directory from where the command is invoked. When I am using System.getProperty("user.dir") I am getting the path from where the java class is invoked. Can anyone help in this. ...

Can generics allow the Java compiler to check the type of keys and values in a map?

I am in a situation where I want to have a map where the keys are an interface class, and the corresponding value is a class which implements that interface. In other words the key and value type is related. My current implementation of the method which adds to the map, and gets an instance of the implementation class looks like: // s...

General strategy to resolve Java memory leak?

I have a standalone program that I run locally, it is meant to be a server type program running 24/7. Recently I found that it has a memory leak, right now our only solution is to restart it every 4 hours. What is the best way to go about finding this memory leak? Which tool and method should we use? ...

Configuring servlet to connect to Gmail server

Hi, I'm trying to configure servlet to send a message to Gmail, but I'm getting waiting for reply message down my browser window. Here's the servlet code: import javax.mail.*; import javax.mail.internet.*; import javax.servlet.http.*; import javax.servlet.*; import java.io.*; public class JavaMailServlet extends HttpServlet { pu...

oracle add_months function differs from Java

I recently discovered a difference between Oracle adds months to a given date (using ADD_MONTHS function) and the way Java adds months to a Calendar object. For instance in oracle: select add_months('2009-02-28', +1) from dual; produced the result: "09-03-31" And the query: select add_months('2009-02-28', -1) from dual; Produces...

Child process stops when Thread.sleep() is called (in Java under Windows)

I have a Java application that launches an external process (Internet Explorer) using ProcessBuilder. Strangely enough, this child process freezes when the parent Java thread calls Thread.sleep. It does not happen with all processes, for instance Firefox, but with IE it happens all the time. Any ideas ? P.S. I tried Robot.delay() with...

Formating MySQL date string in JSP using JSTL formatDate

I'm having a problem with JSTL formatDate when displaying dates from MySQL database. I am using DAO layer for communication with database and in beans, dates are stored in java.util.Date objects. In JSP the code looks like this: <fmt:parseDate value="${season.startDate}" pattern="dd.MM.yyyy."/> When I try to run this page I get java.te...

How do I enforce a timeout on a webservice call using ksoap 2?

I need to add a timeout to a J2ME application that uses ksoap 2 to connect to a web service. I've tried the method described as a possible pseudo timeout at http://ksoap2.sourceforge.net/doc/api/org/ksoap2/transport/HttpTransport.html, but it doesn't seem to function on this device. I'd run the connection on another thread and kill it ...

accessing parameters when writing a scripted BIRT data source in java

Hi everyone, I am using BIRT reporting with a scripted POJO data source and am having trouble accessing report parameters. I am scripting everything in Java, rather than javascript. The code is below: public class StockDataSetHandler extends ScriptedDataSetEventAdapter { ... @Override public void open(IDataSetInstance dataSet) { ...

Why can't I create a new Java array inline?

Why does the first one work and the second not work? 1) OK String[] foo = {"foo"}; bar.setArray(foo); 2) BAD bar.setArray({"foo"}); Is there a quick way to create a String[] on a single line? ...

ejb lookup failing with NamingException

I've added the following in my web.xml: <ejb-ref> <ejb-ref-name>ejb/userManagerBean</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <home>gha.ywk.name.entry.ejb.usermanager.UserManagerHome</home> <remote>what should go here??</remote> </ejb-ref> The following java code is giving me NamingException: ...

Form based login while also applying REST principles

I am a Spring/JavaEE web programmer and am starting to investigate the principles of REST for future web applications, but I can't figure out how to do usable logins. For a Web API it makes sense, but what about end user facing web applications? I have looked into the HTTP Basic/Digest Authentication but that only produces an ugly dialog...

Version control to manage club project?

At my school, we're starting a coding competition for our CS club to help out our freshmen learn the practices of fast turn around times, due dates, code comparison, and API documentation using Robocode. I was wondering if there was a way to allow each member to work on their own packages/robots and pull them into a central location for...

Is the Hessian class SerializerFactory thread-safe?

I'd like to use the Hessian (Java) serialization and need to create a SerializerFactory with custom serializers (to handle BigInteger). Can I create one of these and share it among threads? ...

Java: Automatic cookie handling in HttpClient?

In Java HttpClient feature list it says: Automatic Cookie handling for reading Set-Cookie: headers from the server and sending them back out in a Cookie: header when appropriate. But I can't figure out how to use this feature. I just need to open a web page, let it set all the cookies, then refresh the same page with received...

How to include external configuration for webstart application

I have webstart application that needs external configuration. Configuration must be external, because it will be changed manually by our customer. I considered adding another jar with this configuration. Application is signed and giving our keys to customer is not a option. I'm leaning towards placing this file to be accessible from web...

How do I sign a Java midlet?

How do I sign a Java midlet? ...

Batch Downloader- Flash, Java, Air?

I have a store that I maintain and we sell CD's. When customers purchase an album, they have to go through and then click to download each and every song (zipping the files is not an option). Needless to say, this is a pain. Does anyone know of a solution to use iTunes-style downloading (will download a few at a time, and once those a...

How to add a JLabel on the DRAG_LAYER under the mouseDragged event

Hi everyone, I am currently working on a drag n drop application and I would really like to know what's happening inside the JLayeredPane and I get a particular program behaviour... Here's the deal: I have a chessboard placed on the DEFAULT_LAYER. I also have a chessPiece which I'd like to be added to the DRAG_LAYER when I move it. B...

Forcing a JFrame to refresh

I have a UI built inside a JFrame. One of the buttons starts a long running call (still within the same java process), and during it's execution, the UI is frozen. I figured, to make it clear that things are still running, I can display a progress bar, perhaps in a popup, so that the user can be kept up-to-date as to what the program ...