java

Scala doesn't have enums - what to use instead of an enum

Scala doesn't have type-safe enums like Java has. If I have a set of related constants then what is the best way in Scala to represent those constants? ...

Java Synchronization

What is this: synchronized (this) { // ...some code... } good for? (Could you write an example?) ...

How do I set Tomcat Manager Application User Name and Password for NetBeans?

I'm trying to follow a tutorial to make an extremely basic Java web application in NetBeans. When I try to run it, a dialogue box appears title "Authentication Required". Inside the dialogue box there the heading "Tomcat Manager Application" and fields for "User Name" and "Password." Investigating this, I've come to understand that I ...

Finding serialVersionUID of serialized object

Is there a way to determine the generated serialVersionUID of a serialized Java object? The problem is that I serialized an object without explicitely specifying the serialVersionUID. Now the deserialization process complains about class incompatibilities. However I didn't change the class in a way which would make it incompatible. So I...

I want to use Robot class in java applet for web browser. will it move and click mouse

I have created this applet, It moves mouse to 1000 pos on screen.It works as application but it does not work in applet. I have created signed applet but still it wont move mouse. What should i do to make my robot class work from browser . import java.applet.Applet; import java.awt.Graphics; import java.awt.Robot; import java.awt.AWTEx...

Link between two JFrames...

link between two JFrame using JMenu i have an application where i have to move to another frame by clicking a menu. for example, on a file menu, i click on add which will bring out a new frame where operations can be carried out. what code(s) can i use in Netbeans? i used it to open another jframe but when i exit the new jframe both fra...

How to efficiently parse concatenated XML documents from a file

I have a file that consists of concatenated valid XML documents. I'd like to separate individual XML documents efficiently. Contents of the concatenated file will look like this, thus the concatenated file is not itself a valid XML document. <?xml version="1.0" encoding="UTF-8"?> <someData>...</someData> <?xml version="1.0" encoding="...

Help with java executors: wait for task termination.

I need to submit a number of task and then wait for them until all results are available. Each of them adds a String to a Vector (that is synchronized by default). Then I need to start a new task for each result in the Vector but I need to do this only when all the previous tasks have stopped doing their job. I want to use Java Executor...

How to pass Map to Oracle PL/SQL function?

Hi, I would like to create an equivalent if this Java method as PL/SQL function in Oracle 10g: String myMethod(int par1, Map<String, Object> par2); Is it possible to pass a Map (or some simillar structure) to Oracle PL/SQL function? I have to be able to call this function from Java somehow. ...

Best practice for java web services and remote exception

I am writing a web service. So I have: public interface MyService extends Remote { public void service1(); } public class MyServiceImpl implements MyService { public void service1() { /* do something that sometimes throws an exception */ } } I was reading about RemoteException. Should I wrap all the code in service1() in a try..c...

What is the best Java library to use for HTTP POST, GET etc.?

What is the best Java library to use for HTTP POST, GET etc. in terms of performance, stability, maturity etc.? Is there one particular library that is used more than others? My requirements are submitting HTTPS POST requests to a remote server. I have used the java.net.* package in the past as well as org.apache.commons.httpclient.* pa...

How to implement Singleton-like EJB3.0 bean?

I need to implement a simple DAO bean, which also caches data read from the database. This DAO bean is used by stateless beans. Because EJB3.0 doesn't support singleton beans, what would be the correct way to implement such a DAO bean? Is it ok to just use static variable to keep the cache? We are using Oracle AS and not going to use c...

How can I make the display of a line in my command-line java program change without displaying a new line?

I'm making a java command line program. How can I change the contents of a line I've already displayed? So, for example I could display: Status: 0% Status: 2% ... Status: 50% Except, rather than continuing to push down each new line, I simply change the contents of the existing line, so the % done changes in place. I've seen some ...

HSQLDB - hiding database structure/contents from users

I'm considering using HSQLDB in a desktop app for storing local data. From what I can see, the database is stored on disk as a number of SQL statements to create the tables, insert the data, etc. Is there a simple way I can hide this from users? I'm don't necessarily need it to be completely encrypted, etc - I'd just like to prevent th...

Web Service Client Deployment

I have a web service client (JAX-WS) and the stubs have been created using the wsimport tool. Now once the client is packaged as an application, the location of the service (and only the location )changes. Do I have to re run the whole ws-import tool once again to create new stubs for the new location. Is it possible to move the WSD...

What is the difference between a Java API and a library?

I know that an API is called a set of functions used to call something, and a library is a collection of classes, but what is actually API in package like Java.lang? I can connect to a class like System without using any API here, so why we say as J2SE API rather than J2SE packages? ...

converting an int[] to byte[] without creating new objects

I have an int[] in java which i want to convert to a byte[]. Now the usual way to do this would be to create a new byte[] 4 times the size of the int array and copy all the ints byte by byte into the new byte array. However the only reason to do this is because of java's type safety rules. An int array is already a byte array. Its just...

read xml file using http

Hi Is anyone aware of a quick way of reading in an xml file over http? (e.g. i have a file located in http://www.abc.com/file.xml). How can i read this file from a java app All help is greatly appreciated Thanks Damien ...

Is doFilter() executed before or after the Servlet's work is done?

The javax.servlet.Filter object can be used both for authentication (where the Filter needs to catch the request before any servlet work needs to be done) and for XSLT translation (where the servlet needs to be completely finished generating content). When does it actually get executed? I know this is implementation dependent (on the we...

Can I get the response server name/ip using Apache HttpClient?

I'm using Apache HttpClient 3.x for contacting a Big IP that will then redirect my request to one of 1-N machines. We have the need to know which of the N machines actually picked up the request though, and I'm not sure how to get this information. I looked through the Response headers with no luck, so I'm wondering if this information...