java

Extract words out of a text file

Let's say you have a text file like this one: http://www.gutenberg.org/files/17921/17921-8.txt Does anyone has a good algorithm, or open-source code, to extract words from a text file? How to get all the words, while avoiding special characters, and keeping things like "it's", etc... I'm working in Java. Thanks ...

Setting variables by name in Java

I'm looking to implement something in Java along the lines of: class Foo{ private int lorem; // private int ipsum; public setAttribute(String attr, int val){ //sets attribute based on name } public static void main(String [] args){ Foo f = new Foo(); f.setAttribute("lorem",1); f.setAttribute("ipsum",2); } public ...

Tracking Java versions using Google Analytics

I am tracking the Java versions being used by web visitors: http://cowwoc.blogspot.com/2008/12/tracking-java-versions-using-google.html Unfortunately, the integration level is skin deep. I would like Google Analytics to tell me what percentage of visitors ran what version, and drill down further to find out what sub-attributes each vers...

Book/Resource about setting up load balancing and fail over for Servlet based Java web application

Hi, We're creating a web system using Java and Servlet technology (actually Wicket for the presentation layer) and we need our system to be available nearly always as our customers will be quite dependent on it. This has lead us to look for a good book focusing on the subject or another resource which explains how to set up a more redu...

How to test if an array contains a pair of numbers whose product is odd?

How can I write a function that takes an array of integers and returns true if their exists a pair of numbers whose product is odd? What are the properties of odd integers? And of course, how do you write this function in Java? Also, maybe a short explanation of how you went about formulating an algorithm for the actual implementation. ...

Java: Scanner

Scanner can only get input from system console? not be able to get from any dialog window? Thanks. ...

How to use JProgressBar?

I need to load a bunch of words (about 70,000) from a text file, add it to a hashtable (using soundex as a key) and sort the values. While doing all these I want to show a progress bar using JProgressBar. Articles such as this and this, only gives a non-real example (a while loop). Can anyone suggest me how should I proceed. How can I ge...

Do I need to store the salt with bcrypt?

bCrypt's javadoc has this code for how to encrypt a password: String pw_hash = BCrypt.hashpw(plain_password, BCrypt.gensalt()); To check whether a plaintext password matches one that has been hashed previously, use the checkpw method: if (BCrypt.checkpw(candidate_password, stored_hash)) System.out.println("It matches"); else ...

How to refer a custom function in xml

How can I refer a custom function in xml? Suppose that I have a function written in Java and want it to refer by the xml tag, how is this possible? Current senario: I am using XACML2.0 which contains xml tags and I want to refer some function in Java that will talk to the backend data, I'm unable to refer a function in xacml. Could yo...

AccessControlException when attempting to delete a file

We have a java web service application that uses log4j to do logging. An exception gets thrown when log4j tries to delete its rolling log files Exception:java.security.AccessControlException: access denied (java.io.FilePermission /var/opt/SUNWappserver/domains/domain1/ applications/j2ee-modules/ourwebservice/WEB-INF/logs/IMWrapper.log....

What's the best way to determine the total number of words of a file in Java?

What is the best way to find the total number of words in a text file in Java? I'm thinking Perl is the best on finding things such as this. If this is true then calling a Perl function from within Java would be the best? What would you have done in condition such as this? Any better ideas? ...

What is the best way to transfer a file using Java?

I am writing code for uploading a file from a client to my server and the performance isn't as fast as I think it should be. I have the current code snippet that is doing the file transfer and I was wondering how I could speed up the transfer. Sorry about all of the code: InputStream fileItemInputStream ; OutputStream saveFileStream; ...

Eclipse RCP: Where should I keep my model objects and how do they talk to the views?

In Eclipse RCP way of doing things, where should I keep my model objects? And when they are loaded or changed, how should they talk to the views? I am attempting to port my existing application to Eclipse RCP. It could be viewed as an IDE-like application: I open a file, which contains links to source files. The source files are display...

Java floating point high precision library

Which libraries for Java are there that have a fast implementation for floating point or fixed point operations with a precision of several thousands of digits? How performant are they? A requirement for me is that it implements a multiplication algorithm that is better than the naive multiplication algorithm that takes 4 times as much ...

Java: `enum` vs `String` as Parameters

I've been reading through the details of the System libraries set and get methods yet the parameters are usually Strings. Would you consider the use of String as parameters bad practise since the inclusion of enum? A better alternative at minimum might be public final String, No? ...

Euler Project Help (Problem 12) - Prime Factors and the like

I hate to have to ask, but I'm pretty stuck here. I need to test a sequence of numbers to find the first which has over 500 factors: http://projecteuler.net/index.php?section=problems&id=12 -At first I attempted to brute force the answer (finding a number with 480 after a LONG time) -I am now looking at determining the prime facto...

html to jsp email form post - null parameters

I have a simple form form action="email.jsp" method="post" <label for="firstname">Your Name: </label> input type="text" id="name"<br/> <label for="email">Your Email: </label> input type="text" id="address"<br/> <label for="message">Message: </label> textarea size="30" rows=...

Spring @Autowiring, how to use an object factory to choose implementation ?

I am trying to let a piece of runtime state decide WHICH implementation of an interface to use, preferably solely by autowiring. I have tried making an object factory for the interface thet uses dynamic proxies, and I used qualifiers to coerce the @Autowired injections to use the factory. The qualifiers are necessary because both the f...

JAXB: How to ignore namespace during unmarshalling XML document?

My schema specifies a namespace, but the documents don't. What's the simplest way to ignore namespace during JAXB unmarshalling (XML -> object)? In other words, I have <foo><bar></bar></foo> instead of, <foo xmlns="http://tempuri.org/"&gt;&lt;bar&gt;&lt;/bar&gt;&lt;/foo&gt; ...

Would you, at present date, use JBoss or Glassfish (or another) as Java EE server for a new project?

If you started a new Java EE project today which is to be finished in about a year, which application server would you choose and why? Part of your answer should include your arguments for your decision. And also how much experience you have with the Java EE server you choose and with the other available servers on the market. These are...