java

Java Concurrency Techniques

Here are two chunks of code that accomplish (what I think is) the same thing. I basically am trying to learn how to use Java 1.5's concurrency to get away from Thread.sleep(long). The first example uses ReentrantLock, and the second example uses CountDownLatch. The jist of what I am trying to do is put one thread to sleep until a cond...

Updating from Java VM 5 to 6 gave a really big increase of memory consumption

Hi, I've be working with a Java application run through the command-line. It deals with XML files, specially the dblp.xml database which has more than 400MB. I was using JVM 5 and my app needed sort of 600-700MB of memory to processe the dblp.xml. After updating to JVM 6, it starting needing more than 1gb of memory (something I don't h...

Can you figure out why this program is triggering a IllegalStateException?

all files in ~/Cipher/nsdl/crypto can be found here java files compiled with gcj, see compile.sh nmint@nqmk-mint ~/Cipher/nsdl/crypto $ echo test | ./cryptTest encrypt deadbeefdeadbeefdeadbeefdeadbeef deadbeef Blowfish CBC > test null Exception in thread "main" java.lang.IllegalStateException: cipher is not for encrypting or decrypting ...

Extending enum

public enum myEnum { VAL1(10), VAL2(20), VAL3("hai") { public Object getValue() { return this.strVal; } public String showMsg() { return "This is your msg!"; } }; String strVal; Integer intVal; public Object getValue() { return this.intVal; } private myEnum(int i) { th...

Accessing inner anonymous class members

Is there any way other than using reflection to access the members of a anonymous inner class? ...

Connect to database using jsf

How do I connect to the database(MYSQL) in connection bean using JSF to retrieve its contents. Also please let me know how do I configure the web.xml file? ...

C#, hexadecimal notation and signed integers

This is a follow up question. So, Java store's integers in two's-complements and you can do the following: int ALPHA_MASK = 0xff000000; In c# this requires the use of an unsigned integer, uint, because it interprets this to be 4278190080 instead of -16777216. My question, how do declare negative values in hexadecimal notation in c#,...

Gui - Best way to navigate between windows?

Hi, I try to build a gui (Swing) for a simple java application. The application should have a start window like a menu. From there I would like to navigate to several other windows. My question is what is the best-practice to achieve such a navigation? Should I build several JFrames and switch the visibility of them on/off when navig...

Struts 2 + tiles + velocity interoperability?

Has anyone been able to get velocity + tiles working with struts 2? I am having some problem finding examples or tutorials online and from what I have gathered from mailing lists it seems it might not even be possible at all (but the mails were quite old). ...

Howto synchronize file access in a shared folder using Java (OR: ReadWriteLock on network level)

I have multiple applications running in one virtual machine. I have multiple virtual machines running on one server. And I have multiple servers. They all share a file using a shared folder on linux. The file is read and written by all applications. During the write process no application is allowed to read this file. The same for writin...

How do I divide an ordered list of integers into evenly sized sublists?

Does anyone have a good algorithm for taking an ordered list of integers, i.e.: [1, 3, 6, 7, 8, 10, 11, 13, 14, 17, 19, 23, 25, 27, 28] into a given number of evenly sized ordered sublists, i.e. for 4 it will be: [1, 3, 6] [7, 8, 10, 11] [13, 14, 17, 19] [23, 25, 27, 28] The requirement being that each of the sublists are ordered and a...

What's the minimum classpath for an Axis2 client?

I want to build an Axis2 client (I'm only accessing a remote web service, I'm not implementing one!) with Maven2 and I don't want to add 21MB of JARs to my project. What do I have to put in my pom.xml to compile the code when I've converted the WSDL with ADB? ...

How to access multiple JPanels inside JFrame?

I have a JFrame that contains a "display" JPanel with JTextField and a "control" JPanel with buttons that should access the contents of the display JPanel. I think my problem is related on how to use the observer pattern, which in principle I understand. You need to place listeners and update messages, but I don't have a clue where to pu...

is combined generic bounds an anti pattern?

as a follow up on my previous question Having a function with combined generic bounds such as: <T extends Foo & Bar> void doStuff(T argument) { //do stuff wich should only be done if arguments is both foo and bar } Because this is not castable from a unspecified object, you need to have knowledge of some object which actually implem...

How to limit number of rows returned from oracle at the jdbc data source level?

Hi, Is there a way to limit the rows returned at the oracle datasource level in a tomcat application? It seems maxRows is only available if you set it on the datasource in the java code. Putting maxRows="2" on the datasource doesnt apply. Is there any other way limit the rows returned? without a code change? Thanks, Dan ...

Can NovellAuthenticators (LDAP) be add to Weblogic using WLST Offline?

I would like to create a WLST script to create my Weblogic domain. However I'm having problems adding the LDAP config. cd("/SecurityConfiguration/myDomain") cmo.createRealm("myrealm") cd("/SecurityConfiguration/myDomain/Realms/myrealm") cmo.createAuthenticationProvider("myLDAP", "weblogic.security.providers.authentication.NovellAuthent...

What is the best cross-browser solution for browser based document signing (w/ digital signature)?

I need to implement a browser based component (most likely java applet since it needs to be cross-browser) that will allow us to digitally sign and verify data in the XadES format. What options are available and what is the best solution? ...

Viewing contents of a .jar file

What would be the easiest way to view classes, methods, properties, etc. inside a jar file? I'm looking for something equivalent to the very useful Lutz Roeder .NET Reflector - for Java ...

How to get the path of a running jar file?

My code runs inside a jar file, say foo.jar, and I need to know, in the code, in which folder the running foo.jar is. So, if foo.jar is in C:\FOO\, I want to get that path no matter what my current working directory is. ...

Interfaces with static fields in java for sharing 'constants'

I'm looking at some open source Java projects to get into Java and notice a lot of them have some sort of 'constants' interface. For instance, processing.org has an interface called PConstants.java, and most other core classes implement this interface. The interface is riddled with static members. Is there a reason for this approach, or...