While working on a larger project, a few lines of code using java.net.Socket failed to compile. This is on a Mac 10.5.8 with Java for Mac OS X 10.5 Update 4 (java version "1.5.0_20"). Other things (awt, ssl factories, treads, etc) still compile and run. I pulled the offending code down into a small class Fake.java:
import java.net.Sock...
An existing web application is running on Tomcat 4.1. There is an XSS issue with a page, but I can't modify the source. I've decided to write a servlet filter to sanitize the parameter before it is seen by the page.
I would like to write a Filter class like this:
import java.io.*;
import javax.servlet.*;
public final class XssFilter...
Here is my eclipse.ini file:
-startup
plugins/org.eclipse.equinox.launcher_1.0.200.v20090520.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.0.200.v20090519
-product
org.eclipse.epp.package.java.product
--launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
-vmargs
-Dos...
How would I go about getting the Windows user credentials from a Swing application?
I am working on an internal (corporate) Swing application. Currently the user has to login to the application using a login screen, which then connects to an app server which authenticates the user against the company LDAP server.
Since the user has alr...
I'm using Hibernate Annotations.
In all my model classes I annotate like this:
@Entity
@Table
public class SomeModelClass {
//
}
My hibernate.cfg.xml is
<hibernate-configuration>
<session-factory>
<!-- some properties -->
<mapping package="com.fooPackage" />
<mapping class="com.fooPackage.SomeModelClass" />
...
Is this statement true, false, or poorly formulated:
"In Java, memory leaks must always be related somehow to a long-lived object."
In this context, I am referring simply to regular objects, and not to system resources in general (file descriptors, and so on).
An example of a long-lived object might be a singleton (as typically imple...
How can I change the session timeout for the OC4J Enterprise Manager console?
It times out too quickly between deployments in our development environment.
...
I keep hearing the statement on most programming related sites:
Program to an interface and not to an
Implementation
However I don't understand the implications?
Examples would help.
EDIT: I have received a lot of good answers even so could you'll supplement it with some snippets of code for a better understanding of the sub...
I am indexing a class whose superclass has the following annotations:
@Indexed
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
The same @Inheritance annotation is on the subclass. The annotations of the superclass are all on methods. The field I want indexed on the superclass is ignored:
@Field(index=Index.UN_TOKENIZED,st...
I'm trying to port a library from Java into AS3, and I'm down to the MD5 function. I'm using the MD5 library found as part of the project here: http://code.google.com/p/as3crypto/.
I'm getting the length correct, and about half of the values are correct. The ironic thing is the correct values are in the correct spot as well. Only the ne...
I have a text file that I want to send over the network, this file could vary in size from as low as 1KB to 500KB.
What algorithms/techniques could I use to tightly compress this file before sending it such that the least amount of bytes are send over the network and compression ratio is high?
...
I'm not really sure what the best approach is for designing what I would call a "parametric" search or rule engine. I have a Java object which has several fields. I will run the java object against several queries in order to see if it meets certain criteria.
An example i can think of is the bug search feature in bugzilla. In the UI ...
I work with a propriety client/server message format that restricts what I can send over the wire. I can't send a serialized object, I have to store the data in the message as a String. The data I am sending are large comma-separated values, and I want to compress the data before I pack it into the message as a String.
I attempted to us...
Hello all,
I need to create project in which there are two databases local and remote. Remote database needs to be synchronized daily with local database reflecting changes made in local database.
I am using JAVA. Database is ORACLE. I have JAVA/JPA code that does CRUD operations on local database.
How to synchronize changes to remote da...
I am new to JAX-RPC. I tried creating a simple Java bean in RAD 7.0, and went through the options to create a JAX-RPC webservice. My method is as below.
public byte[] getData(byte[] argument) {
<Customclass> proxy = new <Customclass>();
List outputList = new ArrayList();
try {
// Call a method on proxy
} catch ...
Hi,
I am designing an application that needs to load HTML content from a specific URL on server side by using Java. How can i solve it ?
regards,
...
I need to use a LinkedList to add cells of a prison with the cell numbers 1.1, 1.2, 1.3, 1.4 etc. There are two levels and odd numbered cells have 1 bunk whereas even numbered cells have 2 bunks. How can I do this?
I did this to create a linkedlist. That is in my Cells class and I have 2 child classes which inherit from the Cells class ...
Hi,
as far as I understand, getters/setters should always make copies, in order to protect the data.
However, for many of my classes, it is safe to have the getter return a reference to the property asked for, so that the following code
b = a.getB();
b.setC(someValue);
actually changes the state of object a. If I can prove that it is...
What is the best way to test value visibility between threads?
class X {
private volatile Object ref;
public Object getRef() {
return ref;
}
public void setRef(Object newRef) {
this.ref = newRef;
}
}
The class X exposes a reference to the ref object. If concurrent threads read and and write the object reference every Thread...
Suppose my input file contains:
3 4 5 6 7 8
9
10
I want to run a while loop and read integers, so that I will get 3,4,5,6,7,8 and 10 respectively after each iteration of the loop.
This is really simple to do in C/C++ but not in Java...
I tried this code:
try {
DataInputStream out2 = new DataInputStream(new Buff...